From 310efb978155689ad0a53b8c3b90ed713b2c18fd Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Tue, 4 Mar 2014 06:41:36 -0400 Subject: [PATCH] Changes to Rift Regeneration Moved a little of the regeneration code to BlockRift to reduce duplicate code. Changed RiftRegenerator to iterate over loaded worlds instead of all worlds. Removed forced rift generation call in EventHookContainer.onWorldLoad() - I feel it would have minimal benefits. Rifts now drop World Thread upon regeneration. Generally cleaned up the code in FastRiftRegenerator and RiftRegenerator. --- .../mod_pocketDim/EventHookContainer.java | 5 --- .../mod_pocketDim/blocks/BlockRift.java | 38 +++++++++++-------- .../ticking/FastRiftRegenerator.java | 30 +++++++-------- .../ticking/RiftRegenerator.java | 24 ++++++------ 4 files changed, 48 insertions(+), 49 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/EventHookContainer.java b/src/main/java/StevenDimDoors/mod_pocketDim/EventHookContainer.java index d9e957d..dab79f3 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/EventHookContainer.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/EventHookContainer.java @@ -135,11 +135,6 @@ public class EventHookContainer PocketManager.load(); } - if (PocketManager.isLoaded()) - { - RiftRegenerator.regenerateRiftsInAllWorlds(); - } - if (event.world != null) { this.playMusicForDim(event.world); diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java index eeda361..5f6f896 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java @@ -43,7 +43,8 @@ public class BlockRift extends Block implements ITileEntityProvider private static final int BLOCK_SEARCH_CHANCE = 50; private static final int MAX_BLOCK_DESTRUCTION_CHANCE = 100; private static final int BLOCK_DESTRUCTION_CHANCE = 50; - private static final int WORLD_THREAD_PROBABILITY = 10; + private static final int WORLD_THREAD_CHANCE = 5; + private static final int MAX_WORLD_THREAD_CHANCE = 100; private final DDProperties properties; private final ArrayList blocksImmuneToRift; @@ -191,30 +192,25 @@ public class BlockRift extends Block implements ITileEntityProvider if (!isBlockImmune(world, current.getX(), current.getY(), current.getZ()) && random.nextInt(MAX_BLOCK_DESTRUCTION_CHANCE) < BLOCK_DESTRUCTION_CHANCE) { - this.spawnWorldThread(world.getBlockId(current.getX(), current.getY(), current.getZ()), world, x, y, z); + this.spawnWorldThread(world.getBlockId(current.getX(), current.getY(), current.getZ()), world, x, y, z, random); world.destroyBlock(current.getX(), current.getY(), current.getZ(), false); } } } } - private void spawnWorldThread(int blockID,World worldObj,int x,int y,int z ) + + private void spawnWorldThread(int blockID, World world, int x, int y, int z, Random random) { - if(blockID == 0||!(worldObj.rand.nextInt(100) pointDistances, Queue points) { Point3D[] neighbors = new Point3D[] { @@ -234,6 +230,16 @@ public class BlockRift extends Block implements ITileEntityProvider } } } + + public void regenerateRift(World world, int x, int y, int z, Random random) + { + if (!this.isBlockImmune(world, x, y, z) && world.getChunkProvider().chunkExists(x >> 4, z >> 4)) + { + int blockID = world.getBlockId(x, y, z); + world.setBlock(x, y, z, properties.RiftBlockID); + this.spawnWorldThread(blockID, world, x, y, z, random); + } + } /** * Lets pistons push through rifts, destroying them diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/ticking/FastRiftRegenerator.java b/src/main/java/StevenDimDoors/mod_pocketDim/ticking/FastRiftRegenerator.java index 95af20c..b0f203f 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/ticking/FastRiftRegenerator.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/ticking/FastRiftRegenerator.java @@ -3,6 +3,7 @@ package StevenDimDoors.mod_pocketDim.ticking; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Random; import net.minecraft.world.World; import net.minecraftforge.common.DimensionManager; @@ -12,7 +13,9 @@ import StevenDimDoors.mod_pocketDim.util.Point4D; public class FastRiftRegenerator implements IRegularTickReceiver { - private static final int RIFT_REGENERATION_INTERVAL = 10; //Regenerate random rifts every 10 ticks + private static final int RIFT_REGENERATION_INTERVAL = 10; //Regenerate scheduled rifts every 10 ticks + private static Random random = new Random(); + private ArrayList locationsToRegen = new ArrayList(); public FastRiftRegenerator(IRegularTickSender sender) @@ -23,31 +26,24 @@ public class FastRiftRegenerator implements IRegularTickReceiver { @Override public void notifyTick() { - regenerateRiftsInAllWorlds(); + regenerateScheduledRifts(); } - public void regenerateRiftsInAllWorlds() + public void regenerateScheduledRifts() { - if (this.locationsToRegen.isEmpty()) + if (!locationsToRegen.isEmpty()) { - return; - } - List loadedWorlds = (List) Arrays.asList(DimensionManager.getIDs()); - - for (Point4D point: this.locationsToRegen) - { - if (loadedWorlds.contains(point.getDimension()) && PocketManager.getLink(point) != null) + List loadedWorlds = (List) Arrays.asList(DimensionManager.getIDs()); + for (Point4D point: locationsToRegen) { - World world = DimensionManager.getWorld(point.getDimension()); - - if (!mod_pocketDim.blockRift.isBlockImmune(world, point.getX(), point.getY(), point.getZ()) - && world.getChunkProvider().chunkExists(point.getX() >> 4, point.getZ() >> 4)) + if (loadedWorlds.contains(point.getDimension()) && PocketManager.getLink(point) != null) { - world.setBlock(point.getX(), point.getY(), point.getZ(), mod_pocketDim.blockRift.blockID); + World world = DimensionManager.getWorld(point.getDimension()); + mod_pocketDim.blockRift.regenerateRift(world, point.getX(), point.getY(), point.getZ(), random); } } + locationsToRegen.clear(); } - this.locationsToRegen.clear(); } public void registerRiftForRegen(int x, int y, int z, int dimID) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java b/src/main/java/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java index 7187c9d..a50907b 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java @@ -1,8 +1,11 @@ package StevenDimDoors.mod_pocketDim.ticking; +import java.util.Arrays; +import java.util.List; +import java.util.Random; + import net.minecraft.world.World; import net.minecraftforge.common.DimensionManager; -import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.core.DimLink; import StevenDimDoors.mod_pocketDim.core.NewDimData; @@ -13,6 +16,7 @@ public class RiftRegenerator implements IRegularTickReceiver { private static final int RIFT_REGENERATION_INTERVAL = 200; //Regenerate random rifts every 200 ticks private static final int RIFTS_REGENERATED_PER_DIMENSION = 5; + private static Random random = new Random(); public RiftRegenerator(IRegularTickSender sender) { @@ -22,16 +26,17 @@ public class RiftRegenerator implements IRegularTickReceiver { @Override public void notifyTick() { - regenerateRiftsInAllWorlds(); + regenerateRiftsInLoadedWorlds(); } - public static void regenerateRiftsInAllWorlds() + private static void regenerateRiftsInLoadedWorlds() { - //Regenerate rifts that have been replaced (not permanently removed) by players - DDProperties properties = DDProperties.instance(); - - for (NewDimData dimension : PocketManager.getDimensions()) + // Regenerate rifts that have been replaced (not permanently removed) by players + // Only do this in dimensions that are currently loaded + List loadedWorlds = (List) Arrays.asList(DimensionManager.getIDs()); + for (Integer dimensionID : loadedWorlds) { + NewDimData dimension = PocketManager.getDimensionData(dimensionID); if (dimension.linkCount() > 0) { World world = DimensionManager.getWorld(dimension.id()); @@ -42,10 +47,7 @@ public class RiftRegenerator implements IRegularTickReceiver { { DimLink link = dimension.getRandomLink(); Point4D source = link.source(); - if (!mod_pocketDim.blockRift.isBlockImmune(world, source.getX(), source.getY(), source.getZ())&& world.getChunkProvider().chunkExists(source.getX() >> 4, source.getZ() >> 4)) - { - world.setBlock(source.getX(), source.getY(), source.getZ(), properties.RiftBlockID); - } + mod_pocketDim.blockRift.regenerateRift(world, source.getX(), source.getY(), source.getZ(), random); } } }