From e3665c09dd4521e24c8b4b1528e448b1023ca936 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sat, 28 Jun 2014 13:06:22 -0400 Subject: [PATCH 01/47] Added Hunger Restoration on Limbo Respawn Added code to EventHookContainer.revivePlayerInLimbo() so that the player's food level is restored upon respawning in Limbo. Apparently it was possible for players to have death loops from starving to death in Hardcore Limbo. --- .../java/StevenDimDoors/mod_pocketDim/EventHookContainer.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/EventHookContainer.java b/src/main/java/StevenDimDoors/mod_pocketDim/EventHookContainer.java index 4130aaf..4a5fef3 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/EventHookContainer.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/EventHookContainer.java @@ -30,6 +30,8 @@ import cpw.mods.fml.relauncher.SideOnly; public class EventHookContainer { + private static final int MAX_FOOD_LEVEL = 20; + private final DDProperties properties; public EventHookContainer(DDProperties properties) @@ -175,6 +177,7 @@ public class EventHookContainer player.extinguish(); player.clearActivePotions(); player.setHealth(player.getMaxHealth()); + player.getFoodStats().addStats(MAX_FOOD_LEVEL, 0); Point4D destination = LimboProvider.getLimboSkySpawn(player, properties); DDTeleporter.teleportEntity(player, destination, false); } From b2e086e7c1a07c24187b8f2c04116250c2d82a06 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Tue, 1 Jul 2014 21:55:57 -0400 Subject: [PATCH 02/47] Added the Universal Limbo Setting Added the Universal Limbo config option to the world config settings. When enabled, it causes players to get teleported to Limbo if they die in any dimension except Limbo. It's disabled by default. This feature was requested by Mr_Turing. --- .../mod_pocketDim/EventHookContainer.java | 26 +++++++++++++++++-- .../config/DDWorldProperties.java | 9 +++++-- .../mod_pocketDim/mod_pocketDim.java | 5 ++-- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/EventHookContainer.java b/src/main/java/StevenDimDoors/mod_pocketDim/EventHookContainer.java index 4a5fef3..1855963 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/EventHookContainer.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/EventHookContainer.java @@ -7,6 +7,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemDoor; import net.minecraft.item.ItemStack; import net.minecraft.world.World; +import net.minecraft.world.WorldProvider; import net.minecraftforge.client.event.sound.PlayBackgroundMusicEvent; import net.minecraftforge.client.event.sound.SoundLoadEvent; import net.minecraftforge.event.EventPriority; @@ -18,6 +19,7 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action; import net.minecraftforge.event.terraingen.InitMapGenEvent; import net.minecraftforge.event.world.WorldEvent; import StevenDimDoors.mod_pocketDim.config.DDProperties; +import StevenDimDoors.mod_pocketDim.config.DDWorldProperties; import StevenDimDoors.mod_pocketDim.core.DDTeleporter; import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.items.BaseItemDoor; @@ -33,11 +35,20 @@ public class EventHookContainer private static final int MAX_FOOD_LEVEL = 20; private final DDProperties properties; + private DDWorldProperties worldProperties; public EventHookContainer(DDProperties properties) { this.properties = properties; } + + public void setWorldProperties(DDWorldProperties worldProperties) + { + // SenseiKiwi: + // Why have a setter rather than accessing mod_pocketDim.worldProperties? + // I want to make this dependency explicit in our code. + this.worldProperties = worldProperties; + } @ForgeSubscribe(priority = EventPriority.LOW) public void onInitMapGen(InitMapGenEvent event) @@ -134,7 +145,7 @@ public class EventHookContainer Entity entity = event.entity; if (properties.LimboEnabled && properties.LimboReturnsInventoryEnabled && - entity instanceof EntityPlayer && entity.worldObj.provider instanceof PocketProvider) + entity instanceof EntityPlayer && isValidSourceForLimbo(entity.worldObj.provider)) { EntityPlayer player = (EntityPlayer) entity; mod_pocketDim.deathTracker.addUsername(player.username); @@ -156,7 +167,7 @@ public class EventHookContainer Entity entity = event.entity; - if (entity instanceof EntityPlayer && entity.worldObj.provider instanceof PocketProvider) + if (entity instanceof EntityPlayer && isValidSourceForLimbo(entity.worldObj.provider)) { EntityPlayer player = (EntityPlayer) entity; mod_pocketDim.deathTracker.addUsername(player.username); @@ -171,6 +182,17 @@ public class EventHookContainer } return true; } + + private boolean isValidSourceForLimbo(WorldProvider provider) + { + // Returns whether a given world is a valid place for sending a player + // to Limbo. We can send someone to Limbo from a certain dimension if + // Universal Limbo is enabled and the source dimension is not Limbo, or + // if the source dimension is a pocket dimension. + + return (worldProperties.UniversalLimboEnabled && provider.dimensionId != properties.LimboDimensionID) || + (provider instanceof PocketProvider); + } private void revivePlayerInLimbo(EntityPlayer player) { diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/config/DDWorldProperties.java b/src/main/java/StevenDimDoors/mod_pocketDim/config/DDWorldProperties.java index db2a498..b2a4569 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/config/DDWorldProperties.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/config/DDWorldProperties.java @@ -9,7 +9,6 @@ public class DDWorldProperties /** * World Generation Settings */ - public final DimensionFilter RiftClusterDimensions; public final DimensionFilter RiftGatewayDimensions; @@ -17,7 +16,7 @@ public class DDWorldProperties * General Flags */ public final boolean LimboEscapeEnabled; - + public final boolean UniversalLimboEnabled; //Names of categories private static final String CATEGORY_WORLD_GENERATION = "world generation"; @@ -44,6 +43,12 @@ public class DDWorldProperties "generates near the bottom of the dimension. If disabled, players could still leave through " + "dungeons in Limbo or by dying (if Hardcore Limbo is disabled). The default value is true.").getBoolean(true); + UniversalLimboEnabled = config.get(Configuration.CATEGORY_GENERAL, "Enable Universal Limbo", false, + "Sets whether players are teleported to Limbo when they die in any dimension (except Limbo). " + + "Normally, players only go to Limbo if they die in a pocket dimension. This setting will not " + + "affect deaths in Limbo, which can be set with the Hardcore Limbo option. " + + "The default value is false.").getBoolean(false); + config.save(); } diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java b/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java index 6554a6a..5512e67 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java @@ -63,7 +63,6 @@ import StevenDimDoors.mod_pocketDim.tileentities.TileEntityDimDoor; import StevenDimDoors.mod_pocketDim.tileentities.TileEntityDimDoorGold; import StevenDimDoors.mod_pocketDim.tileentities.TileEntityRift; import StevenDimDoors.mod_pocketDim.tileentities.TileEntityTransTrapdoor; -import StevenDimDoors.mod_pocketDim.util.DDLogger; import StevenDimDoors.mod_pocketDim.world.BiomeGenLimbo; import StevenDimDoors.mod_pocketDim.world.BiomeGenPocket; import StevenDimDoors.mod_pocketDim.world.DDBiomeGenBase; @@ -148,6 +147,7 @@ public class mod_pocketDim public static FastRiftRegenerator fastRiftRegenerator; public static GatewayGenerator gatewayGenerator; public static DeathTracker deathTracker; + private static EventHookContainer hooks; //TODO this is a temporary workaround for saving data private String currrentSaveRootDirectory; @@ -177,7 +177,7 @@ public class mod_pocketDim properties = DDProperties.initialize(new File(path)); //Now do other stuff - EventHookContainer hooks = new EventHookContainer(properties); + hooks = new EventHookContainer(properties); MinecraftForge.EVENT_BUS.register(hooks); MinecraftForge.TERRAIN_GEN_BUS.register(hooks); } @@ -336,6 +336,7 @@ public class mod_pocketDim // Load the config file that's specific to this world worldProperties = new DDWorldProperties(new File(currrentSaveRootDirectory + "/DimensionalDoors/DimDoorsWorld.cfg")); + hooks.setWorldProperties(worldProperties); // Initialize a new DeathTracker deathTracker = new DeathTracker(currrentSaveRootDirectory + "/DimensionalDoors/data/deaths.txt"); From 3d88e72ecbeb2ef3ab862d3c2920281dc3083f36 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Wed, 2 Jul 2014 13:38:57 -0400 Subject: [PATCH 03/47] Fixed Bugs in Golden Dimensional Doors 1. We weren't giving old tickets to the doors that owned them. That would result in doors requesting new tickets and the old ones wouldn't be released. Each time a server rebooted, a new ticket would be created. Then Opis would report that many chunks were forcefully loaded in a pocket because it doesn't consider overlapping tickets. We now give doors their old tickets when they're reloaded and we release extra tickets referring to the same door. That will also deal with the excess tickets that already exist on servers. 2. Rewrote the logic for checking if a Golden Dimensional Door is allowed to force-load a pocket. We now check if the door is within the horizontal bounds of the pocket. This prevents the confusing scenario where someone places a door far away from the pocket but the only chunks affected are in the pocket. 3. Fixed the calculation for determining which chunks must be force-loaded to cover a pocket. This has the benefit that fewer chunks should need to be loaded. It should be enough to load 16 chunks. We previously loaded 25 chunks just to err on the side of caution. 4. Golden Dimensional Doors only try to initialize as chunk loaders once. We previously allowed them to keep trying every tick until they could get a ticket. --- .../mod_pocketDim/IChunkLoader.java | 3 +- .../helpers/ChunkLoaderHelper.java | 82 +++++++++--- .../tileentities/TileEntityDimDoorGold.java | 118 ++++++++++-------- .../mod_pocketDim/world/PocketBuilder.java | 41 +++++- 4 files changed, 166 insertions(+), 78 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/IChunkLoader.java b/src/main/java/StevenDimDoors/mod_pocketDim/IChunkLoader.java index bbe989e..06f0059 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/IChunkLoader.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/IChunkLoader.java @@ -4,5 +4,6 @@ import net.minecraftforge.common.ForgeChunkManager.Ticket; public interface IChunkLoader { - public void forceChunkLoading(Ticket ticket,int x, int z); + public boolean isInitialized(); + public void initialize(Ticket ticket); } diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/helpers/ChunkLoaderHelper.java b/src/main/java/StevenDimDoors/mod_pocketDim/helpers/ChunkLoaderHelper.java index 06d22d5..e866ec4 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/helpers/ChunkLoaderHelper.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/helpers/ChunkLoaderHelper.java @@ -1,54 +1,98 @@ package StevenDimDoors.mod_pocketDim.helpers; -import StevenDimDoors.mod_pocketDim.IChunkLoader; -import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.core.NewDimData; -import StevenDimDoors.mod_pocketDim.core.PocketManager; - -import cpw.mods.fml.common.event.FMLServerStartingEvent; - import java.io.File; import java.util.List; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.ChunkCoordIntPair; import net.minecraft.world.World; import net.minecraftforge.common.DimensionManager; import net.minecraftforge.common.ForgeChunkManager; import net.minecraftforge.common.ForgeChunkManager.LoadingCallback; import net.minecraftforge.common.ForgeChunkManager.Ticket; +import net.minecraftforge.common.ForgeChunkManager.Type; +import StevenDimDoors.experimental.BoundingBox; +import StevenDimDoors.mod_pocketDim.IChunkLoader; +import StevenDimDoors.mod_pocketDim.Point3D; +import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.core.NewDimData; +import StevenDimDoors.mod_pocketDim.core.PocketManager; +import StevenDimDoors.mod_pocketDim.world.PocketBuilder; +import cpw.mods.fml.common.event.FMLServerStartingEvent; public class ChunkLoaderHelper implements LoadingCallback { - @Override public void ticketsLoaded(List tickets, World world) { for (Ticket ticket : tickets) { - int goldDimDoorX = ticket.getModData().getInteger("goldDimDoorX"); - int goldDimDoorY = ticket.getModData().getInteger("goldDimDoorY"); - int goldDimDoorZ = ticket.getModData().getInteger("goldDimDoorZ"); - if(world.getBlockId(goldDimDoorX, goldDimDoorY, goldDimDoorZ) != mod_pocketDim.properties.GoldenDimensionalDoorID) + boolean loaded = false; + int x = ticket.getModData().getInteger("goldDimDoorX"); + int y = ticket.getModData().getInteger("goldDimDoorY"); + int z = ticket.getModData().getInteger("goldDimDoorZ"); + + if (world.getBlockId(x, y, z) == mod_pocketDim.properties.GoldenDimensionalDoorID) + { + IChunkLoader loader = (IChunkLoader) world.getBlockTileEntity(x, y, z); + if (!loader.isInitialized()) + { + loader.initialize(ticket); + loaded = true; + } + } + if (!loaded) { ForgeChunkManager.releaseTicket(ticket); } - else + } + } + + public static Ticket createTicket(int x, int y, int z, World world) + { + NBTTagCompound data; + Ticket ticket = ForgeChunkManager.requestTicket(mod_pocketDim.instance, world, Type.NORMAL); + if (ticket != null) + { + data = ticket.getModData(); + data.setInteger("goldDimDoorX", x); + data.setInteger("goldDimDoorY", y); + data.setInteger("goldDimDoorZ", z); + } + return ticket; + } + + public static void forcePocketChunks(NewDimData pocket, Ticket ticket) + { + BoundingBox bounds = PocketBuilder.calculateDefaultBounds(pocket); + Point3D minCorner = bounds.minCorner(); + Point3D maxCorner = bounds.maxCorner(); + int minX = minCorner.getX() >> 4; + int minZ = minCorner.getZ() >> 4; + int maxX = maxCorner.getX() >> 4; + int maxZ = maxCorner.getZ() >> 4; + int chunkX; + int chunkZ; + + for (chunkX = minX; chunkX <= maxX; chunkX++) + { + for (chunkZ = minZ; chunkZ <= maxZ; chunkZ++) { - IChunkLoader tile = (IChunkLoader) world.getBlockTileEntity(goldDimDoorX, goldDimDoorY, goldDimDoorZ); - tile.forceChunkLoading(ticket,goldDimDoorX,goldDimDoorZ); - } + ForgeChunkManager.forceChunk(ticket, new ChunkCoordIntPair(chunkX, chunkZ)); + } } } public static void loadChunkForcedWorlds(FMLServerStartingEvent event) { - for(NewDimData data : PocketManager.getDimensions()) + for (NewDimData data : PocketManager.getDimensions()) { if(data.isPocketDimension()) { String chunkDir = DimensionManager.getCurrentSaveRootDirectory()+"/DimensionalDoors/pocketDimID" + data.id(); - + File file = new File(chunkDir); - + if(file.exists()) { if(ForgeChunkManager.savedWorldHasForcedChunkTickets(file)) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityDimDoorGold.java b/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityDimDoorGold.java index 7dc1c64..093c1e8 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityDimDoorGold.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityDimDoorGold.java @@ -1,85 +1,93 @@ package StevenDimDoors.mod_pocketDim.tileentities; -import net.minecraft.world.ChunkCoordIntPair; import net.minecraftforge.common.ForgeChunkManager; import net.minecraftforge.common.ForgeChunkManager.Ticket; -import net.minecraftforge.common.ForgeChunkManager.Type; import StevenDimDoors.mod_pocketDim.IChunkLoader; -import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; -import StevenDimDoors.mod_pocketDim.util.Point4D; +import StevenDimDoors.mod_pocketDim.helpers.ChunkLoaderHelper; import StevenDimDoors.mod_pocketDim.world.PocketBuilder; public class TileEntityDimDoorGold extends TileEntityDimDoor implements IChunkLoader { private Ticket chunkTicket; + private boolean initialized = false; @Override public boolean canUpdate() { - return true; + return !initialized; + } + + @Override + public boolean isInitialized() + { + return initialized; } @Override public void updateEntity() - { // every tick? - if (PocketManager.getDimensionData(this.worldObj) != null && - PocketManager.getDimensionData(this.worldObj).isPocketDimension() && - !this.worldObj.isRemote) - { - if(PocketManager.getLink(this.xCoord,this.yCoord,this.zCoord,this.worldObj)==null) + { + if (!initialized) + { + initialize(null); + } + } + + @Override + public void initialize(Ticket ticket) + { + initialized = true; + chunkTicket = ticket; + + // Only do anything if this function is running on the server side + // NOTE: We don't have to check whether this block is the upper door + // block or the lower one because only one of them should have a + // link associated with it. + if (!worldObj.isRemote) + { + NewDimData dimension = PocketManager.getDimensionData(worldObj); + + // Check whether a ticket has already been assigned to this door + if (chunkTicket == null) { - return; - } - if (this.chunkTicket == null) - { - chunkTicket = ForgeChunkManager.requestTicket(mod_pocketDim.instance, worldObj, Type.NORMAL); - if(chunkTicket == null) + // No ticket yet. + // Check if this area should be loaded and request a new ticket. + if (isValidChunkLoaderSetup(dimension)) { - return; + chunkTicket = ChunkLoaderHelper.createTicket(xCoord, yCoord, zCoord, worldObj); } - chunkTicket.getModData().setInteger("goldDimDoorX", xCoord); - chunkTicket.getModData().setInteger("goldDimDoorY", yCoord); - chunkTicket.getModData().setInteger("goldDimDoorZ", zCoord); - forceChunkLoading(chunkTicket,this.xCoord,this.zCoord); + } + else + { + // A ticket has already been provided. + // Check if this area should be loaded. If not, release the ticket. + if (!isValidChunkLoaderSetup(dimension)) + { + ForgeChunkManager.releaseTicket(chunkTicket); + chunkTicket = null; + } + } + + // If chunkTicket isn't null at this point, then this is a valid door setup. + // The last step is to request force loading of the pocket's chunks. + if (chunkTicket != null) + { + ChunkLoaderHelper.forcePocketChunks(dimension, chunkTicket); } } } - - @Override - public void forceChunkLoading(Ticket chunkTicket,int x,int z) + + private boolean isValidChunkLoaderSetup(NewDimData dimension) { - Point4D origin = PocketManager.getDimensionData(this.worldObj).origin(); - int orientation = PocketManager.getDimensionData(this.worldObj).orientation(); + // Check the various conditions that make this a valid door setup. + // 1. The door must be inside the pocket's XZ boundaries, + // to prevent loading of chunks with a distant door + // 2. The dimension must be a pocket dimension + // 3. The door must be linked so that it's clear that it's not a normal door - int xOffset=0; - int zOffset=0; - - switch(orientation) - { - case 0: - xOffset = PocketBuilder.DEFAULT_POCKET_SIZE/2; - break; - case 1: - zOffset = PocketBuilder.DEFAULT_POCKET_SIZE/2; - - break; - case 2: - xOffset = -PocketBuilder.DEFAULT_POCKET_SIZE/2; - - break; - case 3: - zOffset = -PocketBuilder.DEFAULT_POCKET_SIZE/2; - - break; - } - for(int chunkX = -2; chunkX<3;chunkX++) - { - for(int chunkZ = -2; chunkZ<3;chunkZ++) - { - ForgeChunkManager.forceChunk(chunkTicket, new ChunkCoordIntPair((origin.getX()+xOffset >> 4)+chunkX, (origin.getZ()+zOffset >> 4)+chunkZ)); - } - } + return (dimension.isPocketDimension() && dimension.getLink(xCoord, yCoord, zCoord) != null && + PocketBuilder.calculateDefaultBounds(dimension).contains(xCoord, yCoord, zCoord)); } @Override diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java b/src/main/java/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java index 15ddecc..515fbee 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java @@ -8,7 +8,7 @@ import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.storage.ExtendedBlockStorage; import net.minecraftforge.common.DimensionManager; -import StevenDimDoors.experimental.MazeBuilder; +import StevenDimDoors.experimental.BoundingBox; import StevenDimDoors.mod_pocketDim.Point3D; import StevenDimDoors.mod_pocketDim.blocks.IDimDoor; import StevenDimDoors.mod_pocketDim.config.DDProperties; @@ -21,13 +21,13 @@ import StevenDimDoors.mod_pocketDim.dungeon.DungeonSchematic; import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonPackConfig; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper; +import StevenDimDoors.mod_pocketDim.items.ItemDimensionalDoor; import StevenDimDoors.mod_pocketDim.schematic.BlockRotator; import StevenDimDoors.mod_pocketDim.util.Pair; import StevenDimDoors.mod_pocketDim.util.Point4D; -import StevenDimDoors.mod_pocketDim.items.ItemDimensionalDoor; public class PocketBuilder -{ +{ public static final int MIN_POCKET_SIZE = 5; public static final int MAX_POCKET_SIZE = 51; public static final int DEFAULT_POCKET_SIZE = 39; @@ -559,4 +559,39 @@ public class PocketBuilder extBlockStorage.setExtBlockMetadata(localX, y & 15, localZ, metadata); chunk.setChunkModified(); } + + public static BoundingBox calculateDefaultBounds(NewDimData pocket) + { + // Calculate the XZ bounds of this pocket assuming that it has the default size + // The Y bounds will be set to encompass the height of a chunk. + + int minX = 0; + int minZ = 0; + Point4D origin = pocket.origin(); + int orientation = pocket.orientation(); + if (orientation < 0 || orientation > 3) + { + throw new IllegalArgumentException("pocket has an invalid orientation value."); + } + switch (orientation) + { + case 0: + minX = origin.getX() - DEFAULT_POCKET_WALL_THICKNESS + 1; + minZ = origin.getZ() - DEFAULT_POCKET_SIZE / 2; + break; + case 1: + minX = origin.getX() - DEFAULT_POCKET_SIZE / 2; + minZ = origin.getZ() - DEFAULT_POCKET_WALL_THICKNESS + 1; + break; + case 2: + minX = origin.getX() + DEFAULT_POCKET_WALL_THICKNESS - DEFAULT_POCKET_SIZE; + minZ = origin.getZ() - DEFAULT_POCKET_SIZE / 2; + break; + case 3: + minX = origin.getX() - DEFAULT_POCKET_SIZE / 2; + minZ = origin.getZ() + DEFAULT_POCKET_WALL_THICKNESS - DEFAULT_POCKET_SIZE; + break; + } + return new BoundingBox(minX, 0, minZ, DEFAULT_POCKET_SIZE, 255, DEFAULT_POCKET_SIZE); + } } From ec290b0dc15a757823d3647eeb2be1c959c05b88 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Wed, 2 Jul 2014 13:59:55 -0400 Subject: [PATCH 04/47] Increased Version Number Increased the mod's version number to account for recent fixes and small features. --- build.gradle | 2 +- src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java | 2 +- src/main/resources/mcmod.info | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 2cbcf59..6d68944 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ apply plugin: 'forge' -version = "2.2.3-" + System.getenv("BUILD_NUMBER") +version = "2.2.4-" + System.getenv("BUILD_NUMBER") group= "com.stevenrs11.dimdoors" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "DimensionalDoors" diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java b/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java index 5512e67..cf281e8 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java @@ -98,7 +98,7 @@ serverPacketHandlerSpec = @SidedPacketHandler(channels = {PacketConstants.CHANNEL_NAME}, packetHandler = ServerPacketHandler.class)) public class mod_pocketDim { - public static final String version = "1.6.4-R2.2.3"; + public static final String version = "1.6.4-R2.2.4"; public static final String modid = "dimdoors"; //TODO need a place to stick all these constants diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index 4687d32..92ac4ad 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -6,7 +6,7 @@ "modid": "dimdoors", "name": "Dimensional Doors", "description": "Bend and twist reality itself, creating pocket dimensions, rifts, and much more", -"version": "1.6.4-R2.2.3", +"version": "1.6.4-R2.2.4", "credits": "Created by StevenRS11, Coded by StevenRS11 and SenseiKiwi, Logo and Testing by Jaitsu", "logoFile": "/dimdoors_logo.png", "mcversion": "", From c29db9b7295e3051bc26caba74958a97f92f1e6b Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 3 Jul 2014 12:02:36 -0400 Subject: [PATCH 05/47] Minor Changes Cleaned up the code in DDCommandBase a little. --- .../mod_pocketDim/commands/DDCommandBase.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/DDCommandBase.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/DDCommandBase.java index b62cc86..badb0a2 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/DDCommandBase.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/DDCommandBase.java @@ -5,7 +5,6 @@ import net.minecraft.command.ICommand; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ChatMessageComponent; -import cpw.mods.fml.common.event.FMLServerStartingEvent; /* * An abstract base class for our Dimensional Doors commands. This cleans up the code a little and provides @@ -96,13 +95,15 @@ public abstract class DDCommandBase extends CommandBase * that Dryware and Technic Jenkins don't have those functions defined. How in the world? * I have no idea. But it's breaking our builds. -_- ~SenseiKiwi */ - public int compareTo(ICommand par1ICommand) + @Override + public int compareTo(ICommand command) { - return this.getCommandName().compareTo(par1ICommand.getCommandName()); + return this.getCommandName().compareTo(command.getCommandName()); } - public int compareTo(Object par1Obj) + @Override + public int compareTo(Object other) { - return this.compareTo((ICommand)par1Obj); + return this.compareTo((ICommand) other); } } From 262595ff4d5555212943252b9b079a2774109cd8 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 3 Jul 2014 12:25:00 -0400 Subject: [PATCH 06/47] Changes to Commands 1. Fixed some warnings in the affected commands. 2. Removed checks for whether a command is running on the server or client side. We have performed those checks inconsistently throughout our commands without problems. I assume that they must be running on the server side only. If I'm wrong, we can add a check to DDCommandBase. 3. Minor punctuation change in DDCommandResult --- .../commands/CommandCreateDungeonRift.java | 14 +-- .../commands/CommandCreatePocket.java | 32 +++--- .../commands/CommandCreateRandomRift.java | 11 +-- .../commands/CommandDeleteAllLinks.java | 11 +-- .../commands/CommandDeleteRifts.java | 2 - .../commands/CommandExportDungeon.java | 97 ++++++++----------- .../commands/CommandResetDungeons.java | 2 - .../commands/CommandTeleportPlayer.java | 11 +-- .../commands/DDCommandResult.java | 2 +- 9 files changed, 66 insertions(+), 116 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java index b1512e3..686b5d3 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java @@ -1,5 +1,9 @@ package StevenDimDoors.mod_pocketDim.commands; +import java.util.Collection; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.MathHelper; import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.core.DimLink; import StevenDimDoors.mod_pocketDim.core.LinkTypes; @@ -9,12 +13,6 @@ import StevenDimDoors.mod_pocketDim.dungeon.DungeonData; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; import StevenDimDoors.mod_pocketDim.world.PocketBuilder; -import java.util.Collection; - -import net.minecraft.command.ICommandSender; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.MathHelper; - public class CommandCreateDungeonRift extends DDCommandBase { private static CommandCreateDungeonRift instance = null; @@ -38,10 +36,6 @@ public class CommandCreateDungeonRift extends DDCommandBase NewDimData dimension; DungeonHelper dungeonHelper = DungeonHelper.instance(); - if (sender.worldObj.isRemote) - { - return DDCommandResult.SUCCESS; - } if (command.length == 0) { return DDCommandResult.TOO_FEW_ARGUMENTS; diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreatePocket.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreatePocket.java index b2843a6..9de7a3a 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreatePocket.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreatePocket.java @@ -1,6 +1,5 @@ package StevenDimDoors.mod_pocketDim.commands; -import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; @@ -24,26 +23,21 @@ public class CommandCreatePocket extends DDCommandBase @Override protected DDCommandResult processCommand(EntityPlayer sender, String[] command) { - //TODO: Some commands have isRemote checks, some do not. Why? Can commands even run locally anyway? - //What does it mean when you run a command locally? ~SenseiKiwi - - if (!sender.worldObj.isRemote) + if (command.length > 0) { - if (command.length > 0) - { - return DDCommandResult.TOO_MANY_ARGUMENTS; - } - - //Place a door leading to a pocket dimension where the player is standing. - //The pocket dimension will serve as a room for the player to build a dungeon. - int x = (int) sender.posX; - int y = (int) sender.posY; - int z = (int) sender.posZ; - DungeonHelper.instance().createCustomDungeonDoor(sender.worldObj, x, y, z); - - //Notify the player - sendChat(sender,("Created a door to a pocket dimension. Please build your dungeon there.")); + return DDCommandResult.TOO_MANY_ARGUMENTS; } + + //Place a door leading to a pocket dimension where the player is standing. + //The pocket dimension will serve as a room for the player to build a dungeon. + int x = (int) sender.posX; + int y = (int) sender.posY; + int z = (int) sender.posZ; + DungeonHelper.instance().createCustomDungeonDoor(sender.worldObj, x, y, z); + + //Notify the player + sendChat(sender, "Created a door to a pocket dimension. Please build your dungeon there."); + return DDCommandResult.SUCCESS; } } \ No newline at end of file diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreateRandomRift.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreateRandomRift.java index 97cc1a5..646fda3 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreateRandomRift.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreateRandomRift.java @@ -38,11 +38,7 @@ public class CommandCreateRandomRift extends DDCommandBase { NewDimData dimension; DungeonHelper dungeonHelper = DungeonHelper.instance(); - - if (sender.worldObj.isRemote) - { - return DDCommandResult.SUCCESS; - } + if (command.length > 1) { return DDCommandResult.TOO_MANY_ARGUMENTS; @@ -118,9 +114,6 @@ public class CommandCreateRandomRift extends DDCommandBase { return null; } - else - { - return matches.get( random.nextInt(matches.size()) ); - } + return matches.get( random.nextInt(matches.size()) ); } } \ No newline at end of file diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandDeleteAllLinks.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandDeleteAllLinks.java index 317b101..af9f915 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandDeleteAllLinks.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandDeleteAllLinks.java @@ -1,16 +1,13 @@ package StevenDimDoors.mod_pocketDim.commands; +import java.util.ArrayList; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.core.DimLink; import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; -import java.util.ArrayList; - -import net.minecraft.command.ICommandSender; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.world.World; - -@SuppressWarnings("deprecation") public class CommandDeleteAllLinks extends DDCommandBase { private static CommandDeleteAllLinks instance = null; diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java index 328576c..a2aac97 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java @@ -2,7 +2,6 @@ package StevenDimDoors.mod_pocketDim.commands; import java.util.ArrayList; -import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.mod_pocketDim; @@ -10,7 +9,6 @@ import StevenDimDoors.mod_pocketDim.core.DimLink; import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; -@SuppressWarnings("deprecation") public class CommandDeleteRifts extends DDCommandBase { private static CommandDeleteRifts instance = null; diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandExportDungeon.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandExportDungeon.java index 4c0ad4d..84b9584 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandExportDungeon.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandExportDungeon.java @@ -2,7 +2,6 @@ package StevenDimDoors.mod_pocketDim.commands; import java.io.File; -import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; import StevenDimDoors.mod_pocketDim.config.DDProperties; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; @@ -60,66 +59,51 @@ public class CommandExportDungeon extends DDCommandBase //Export the schematic return exportDungeon(sender, command[0]); } - else - { - //The schematic name contains illegal characters. Inform the user. - return new DDCommandResult("Error: Invalid schematic name. Please use only letters, numbers, dashes, and underscores."); - } - } - else - { - //The command is malformed in some way. Assume that the user meant to use - //the 3-argument version and report an error. - return DDCommandResult.TOO_FEW_ARGUMENTS; + //The schematic name contains illegal characters. Inform the user. + return new DDCommandResult("Error: Invalid schematic name. Please use only letters, numbers, dashes, and underscores."); } + //The command is malformed in some way. Assume that the user meant to use + //the 3-argument version and report an error. + return DDCommandResult.TOO_FEW_ARGUMENTS; } //The user must have used the 3-argument version of this command - //TODO: Why do we check remoteness here but not before? And why not for the other export case? - //Something feels wrong... ~SenseiKiwi - if (!sender.worldObj.isRemote) + //TODO: This validation should be in DungeonHelper or in another class. We should move it + //during the save file format rewrite. ~SenseiKiwi + + if (!dungeonHelper.validateDungeonType(command[0], dungeonHelper.getDungeonPack("ruins"))) { - //TODO: This validation should be in DungeonHelper or in another class. We should move it - //during the save file format rewrite. ~SenseiKiwi - - if (!dungeonHelper.validateDungeonType(command[0], dungeonHelper.getDungeonPack("ruins"))) - { - return new DDCommandResult("Error: Invalid dungeon type. Please use one of the existing types."); - } - if (!DungeonHelper.DUNGEON_NAME_PATTERN.matcher(command[1]).matches()) - { - return new DDCommandResult("Error: Invalid dungeon name. Please use only letters, numbers, and dashes."); - } - if (!command[2].equalsIgnoreCase("open") && !command[2].equalsIgnoreCase("closed")) - { - return new DDCommandResult("Error: Please specify whether the dungeon is 'open' or 'closed'."); - } - - //If there are no more arguments, export the dungeon. - if (command.length == 3) - { - return exportDungeon(sender, join(command, "_", 0, 3)); - } - else - { - //Validate the weight argument - try - { - int weight = Integer.parseInt(command[3]); - if (weight >= DungeonHelper.MIN_DUNGEON_WEIGHT && weight <= DungeonHelper.MAX_DUNGEON_WEIGHT) - { - return exportDungeon(sender, join(command, "_", 0, 4)); - } - } - catch (Exception e) { } - } - - //If we've reached this point, then we must have an invalid weight. - return new DDCommandResult("Invalid dungeon weight. Please specify a weight between " - + DungeonHelper.MIN_DUNGEON_WEIGHT + " and " + DungeonHelper.MAX_DUNGEON_WEIGHT + ", inclusive."); + return new DDCommandResult("Error: Invalid dungeon type. Please use one of the existing types."); + } + if (!DungeonHelper.DUNGEON_NAME_PATTERN.matcher(command[1]).matches()) + { + return new DDCommandResult("Error: Invalid dungeon name. Please use only letters, numbers, and dashes."); + } + if (!command[2].equalsIgnoreCase("open") && !command[2].equalsIgnoreCase("closed")) + { + return new DDCommandResult("Error: Please specify whether the dungeon is 'open' or 'closed'."); } - return DDCommandResult.SUCCESS; + //If there are no more arguments, export the dungeon. + if (command.length == 3) + { + return exportDungeon(sender, join(command, "_", 0, 3)); + } + + //Validate the weight argument + try + { + int weight = Integer.parseInt(command[3]); + if (weight >= DungeonHelper.MIN_DUNGEON_WEIGHT && weight <= DungeonHelper.MAX_DUNGEON_WEIGHT) + { + return exportDungeon(sender, join(command, "_", 0, 4)); + } + } + catch (Exception e) { } + + //If we've reached this point, then we must have an invalid weight. + return new DDCommandResult("Invalid dungeon weight. Please specify a weight between " + + DungeonHelper.MIN_DUNGEON_WEIGHT + " and " + DungeonHelper.MAX_DUNGEON_WEIGHT + ", inclusive."); } private static DDCommandResult exportDungeon(EntityPlayer player, String name) @@ -137,10 +121,7 @@ public class CommandExportDungeon extends DDCommandBase dungeonHelper.registerDungeon(exportPath, dungeonHelper.getDungeonPack("ruins"), false, true); return DDCommandResult.SUCCESS; } - else - { - return new DDCommandResult("Error: Failed to save dungeon schematic!"); - } + return new DDCommandResult("Error: Failed to save dungeon schematic!"); } private static String join(String[] source, String delimiter, int start, int end) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java index f9ed088..b3535cf 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java @@ -2,7 +2,6 @@ package StevenDimDoors.mod_pocketDim.commands; import java.util.ArrayList; -import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; import net.minecraftforge.common.DimensionManager; import StevenDimDoors.mod_pocketDim.core.DimLink; @@ -10,7 +9,6 @@ import StevenDimDoors.mod_pocketDim.core.LinkTypes; import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; -@SuppressWarnings("deprecation") public class CommandResetDungeons extends DDCommandBase { private static CommandResetDungeons instance = null; diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandTeleportPlayer.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandTeleportPlayer.java index 1b29999..93b4d3f 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandTeleportPlayer.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandTeleportPlayer.java @@ -1,16 +1,11 @@ package StevenDimDoors.mod_pocketDim.commands; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraftforge.common.DimensionManager; import StevenDimDoors.mod_pocketDim.core.DDTeleporter; import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.util.Point4D; -import java.util.Arrays; -import java.util.List; - -import net.minecraft.command.ICommandSender; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraftforge.common.DimensionManager; - public class CommandTeleportPlayer extends DDCommandBase { private static CommandTeleportPlayer instance = null; @@ -121,7 +116,7 @@ public class CommandTeleportPlayer extends DDCommandBase return DDCommandResult.SUCCESS; } - public boolean isInteger( String input ) + public static boolean isInteger( String input ) { try { diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/DDCommandResult.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/DDCommandResult.java index 9ec0cf7..f34b282 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/DDCommandResult.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/DDCommandResult.java @@ -8,7 +8,7 @@ public class DDCommandResult { public static final DDCommandResult TOO_MANY_ARGUMENTS = new DDCommandResult(2, "Error: Too many arguments passed to the command", true); public static final DDCommandResult INVALID_DIMENSION_ID = new DDCommandResult(3, "Error: Invalid dimension ID", true); public static final DDCommandResult UNREGISTERED_DIMENSION = new DDCommandResult(4, "Error: Dimension is not registered", false); - public static final DDCommandResult INVALID_ARGUMENTS = new DDCommandResult(5, "Error: Invalid arguments passed to the command.", true); + public static final DDCommandResult INVALID_ARGUMENTS = new DDCommandResult(5, "Error: Invalid arguments passed to the command", true); public static final int CUSTOM_ERROR_CODE = -1; From c5a77268fc6be470c5e06a0731b17081d8c20591 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 3 Jul 2014 14:08:51 -0400 Subject: [PATCH 07/47] Changes to Commands Removed a few server-side checks that I missed on the previous commit. --- .../mod_pocketDim/commands/CommandListDungeons.java | 4 ---- .../mod_pocketDim/commands/CommandResetDungeons.java | 4 ---- src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java | 4 ---- 3 files changed, 12 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandListDungeons.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandListDungeons.java index 043d0fd..222b481 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandListDungeons.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandListDungeons.java @@ -31,10 +31,6 @@ public class CommandListDungeons extends DDCommandBase int pageCount; ArrayList dungeonNames; - if (sender.worldObj.isRemote) - { - return DDCommandResult.SUCCESS; - } if (command.length > 1) { return DDCommandResult.TOO_MANY_ARGUMENTS; diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java index b3535cf..aad0671 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java @@ -29,10 +29,6 @@ public class CommandResetDungeons extends DDCommandBase @Override protected DDCommandResult processCommand(EntityPlayer sender, String[] command) { - if(sender.worldObj.isRemote) - { - return DDCommandResult.SUCCESS; - } if (command.length > 0) { return DDCommandResult.TOO_FEW_ARGUMENTS; diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java b/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java index cf281e8..a1a93e6 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java @@ -351,15 +351,11 @@ public class mod_pocketDim event.registerServerCommand( CommandListDungeons.instance() ); event.registerServerCommand( CommandCreateRandomRift.instance() ); event.registerServerCommand( CommandDeleteAllLinks.instance() ); - //CommandDeleteDimensionData.instance().register(event); event.registerServerCommand( CommandDeleteRifts.instance() ); event.registerServerCommand( CommandExportDungeon.instance() ); - //CommandPrintDimensionData.instance().register(event); - //CommandPruneDimensions.instance().register(event); event.registerServerCommand( CommandCreatePocket.instance() ); event.registerServerCommand( CommandTeleportPlayer.instance() ); - try { ChunkLoaderHelper.loadChunkForcedWorlds(event); From 80bb87dac66c0c87024e399721e1c9b2148577ca Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 3 Jul 2014 14:19:08 -0400 Subject: [PATCH 08/47] Rewrote CommandDeleteRifts Rewrote CommandDeleteRifts for clarity and to remove several flaws. Previously, the command would have removed non-immune blocks that were in the same location as a rift. It also set blocks in the command sender's dimension rather than the target dimension, so blocks would have potentially disappeared from the wrong world. --- .../commands/CommandDeleteRifts.java | 86 +++++++++++-------- 1 file changed, 52 insertions(+), 34 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java index a2aac97..cc1a1a1 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java @@ -8,6 +8,7 @@ import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.core.DimLink; import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; +import StevenDimDoors.mod_pocketDim.util.Point4D; public class CommandDeleteRifts extends DDCommandBase { @@ -15,7 +16,7 @@ public class CommandDeleteRifts extends DDCommandBase private CommandDeleteRifts() { - super("dd-???", "???"); + super("dd-deleterifts", "[dimension number]"); } public static CommandDeleteRifts instance() @@ -29,47 +30,64 @@ public class CommandDeleteRifts extends DDCommandBase @Override protected DDCommandResult processCommand(EntityPlayer sender, String[] command) { - int linksRemoved=0; - int targetDim; - boolean shouldGo= true; + int linksRemoved = 0; + int targetDimension; - if(command.length==1) + if (command.length > 1) { - targetDim = parseInt(sender, command[0]); + return DDCommandResult.TOO_MANY_ARGUMENTS; + } + if (command.length == 0) + { + targetDimension = sender.worldObj.provider.dimensionId; } else { - targetDim=0; - shouldGo=false; - sendChat(sender,("Error-Invalid argument, delete_all_links ")); + try + { + targetDimension = Integer.parseInt(command[0]); + } + catch (NumberFormatException e) + { + return DDCommandResult.INVALID_DIMENSION_ID; + } } - if(shouldGo) + World world = PocketManager.loadDimension(targetDimension); + if (world == null) { - - NewDimData dim = PocketManager.getDimensionData(targetDim); - ArrayList linksInDim = dim.getAllLinks(); - - for (DimLink link : linksInDim) - { - World targetWorld = PocketManager.loadDimension(targetDim); - - if(!mod_pocketDim.blockRift.isBlockImmune(sender.worldObj,link.source().getX(), link.source().getY(), link.source().getZ())|| - (targetWorld.getBlockId(link.source().getX(), link.source().getY(), link.source().getZ())==mod_pocketDim.blockRift.blockID)) - { - linksRemoved++; - targetWorld.setBlock(link.source().getX(), link.source().getY(), link.source().getZ(), 0); - dim.deleteLink(link); - - - } - //TODO Probably should check what the block is, but thats annoying so Ill do it later. - - - } - sendChat(sender,("Removed " + linksRemoved + " links.")); - + return DDCommandResult.UNREGISTERED_DIMENSION; } - return DDCommandResult.SUCCESS; //TEMPORARY HACK + + int x; + int y; + int z; + Point4D location; + NewDimData dimension = PocketManager.getDimensionData(targetDimension); + ArrayList links = dimension.getAllLinks(); + for (DimLink link : links) + { + location = link.source(); + x = location.getX(); + y = location.getY(); + z = location.getZ(); + if (world.getBlockId(x, y, z) == mod_pocketDim.blockRift.blockID) + { + // Remove the rift and its link + world.setBlockToAir(x, y, z); + dimension.deleteLink(link); + linksRemoved++; + } + else if (!mod_pocketDim.blockRift.isBlockImmune(world, x, y, z)) + { + // If a block is not immune, then it must not be a DD block. + // The link would regenerate into a rift eventually. + // We only need to remove the link. + dimension.deleteLink(link); + linksRemoved++; + } + } + sendChat(sender, "Removed " + linksRemoved + " links."); + return DDCommandResult.SUCCESS; } } \ No newline at end of file From b4a58f5c884e4ea40082412eb6e1c16dc5a2f530 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 3 Jul 2014 17:20:59 -0400 Subject: [PATCH 09/47] Simplified PocketManager 1. Rewrote or removed a few bits that were causing minor warnings. 2. Rewrote deleteDimensionFiles() and deleteDimensionData() to remove unnecessary casts and checks. We can confirm that those checks are unnecessary because those functions are only used inside PocketManager. If they were ever exposed externally, then we would need to add checks again. --- .../mod_pocketDim/core/PocketManager.java | 51 ++++++++----------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java b/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java index 1882bba..acb6ed9 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java @@ -315,44 +315,43 @@ public class PocketManager { if (deleteFolder) { - deleteDimensionFiles(target); + deleteDimensionFiles(dimension); } dimensionIDBlackList.add(dimension.id); - deleteDimensionData(dimension.id); + deleteDimensionData(dimension); return true; } return false; } - private static boolean deleteDimensionFiles(NewDimData target) + private static void deleteDimensionFiles(InnerDimData dimension) { - InnerDimData dimension = (InnerDimData) target; - if (dimension.isPocketDimension() && DimensionManager.getWorld(dimension.id()) == null) - { - String saveRootPath = DimensionManager.getCurrentSaveRootDirectory().getAbsolutePath(); - File saveDirectory = new File(saveRootPath + "/DimensionalDoors/pocketDimID" + dimension.id()); - DeleteFolder.deleteFolder(saveDirectory); - File dataFile = new File(saveRootPath + "/DimensionalDoors/data/dim_" + dimension.id() + ".txt"); - dataFile.delete(); - return true; - } - return false; + // We assume that the caller checks if the dimension is loaded, for the + // sake of efficiency. Don't call this on a loaded dimension or bad + // things will happen! + String saveRootPath = DimensionManager.getCurrentSaveRootDirectory().getAbsolutePath(); + File saveDirectory = new File(saveRootPath + "/DimensionalDoors/pocketDimID" + dimension.id()); + DeleteFolder.deleteFolder(saveDirectory); + File dataFile = new File(saveRootPath + "/DimensionalDoors/data/dim_" + dimension.id() + ".txt"); + dataFile.delete(); } - private static boolean deleteDimensionData(int dimensionID) + private static void deleteDimensionData(InnerDimData dimension) { - if (dimensionData.containsKey(dimensionID) && DimensionManager.getWorld(dimensionID) == null) + // We assume that the caller checks if the dimension is loaded, for the + // sake of efficiency. Don't call this on a loaded dimension or bad + // things will happen! + if (dimensionData.remove(dimension.id()) != null) { - NewDimData target = PocketManager.getDimensionData(dimensionID); - InnerDimData dimension = (InnerDimData) target; - - dimensionData.remove(dimensionID); // Raise the dim deleted event getDimwatcher().onDeleted(new ClientDimData(dimension)); dimension.clear(); - return true; } - return false; + else + { + // This should never happen. A simple sanity check. + throw new IllegalArgumentException("The specified dimension is not listed with PocketManager."); + } } private static void registerPockets(DDProperties properties) @@ -647,10 +646,7 @@ public class PocketManager { return dimension.getLink(x, y, z); } - else - { - return null; - } + return null; } public static boolean isBlackListed(int dimensionID) @@ -715,9 +711,6 @@ public class PocketManager // Load compacted client-side dimension data load(); Compactor.readDimensions(input, new DimRegistrationCallback()); - - // Register pocket dimensions - DDProperties properties = DDProperties.instance(); isLoaded = true; isLoading = false; From 592aabf62771e4da08b7118c4fefe3960822de94 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 3 Jul 2014 17:32:40 -0400 Subject: [PATCH 10/47] Minor Change Added a comment in PocketManager to explain why we don't unregister pocket dimensions with Forge when we delete them. --- .../StevenDimDoors/mod_pocketDim/core/PocketManager.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java b/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java index acb6ed9..7c7c3e0 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java @@ -317,6 +317,11 @@ public class PocketManager { deleteDimensionFiles(dimension); } + // Note: We INTENTIONALLY don't unregister the dimensions that we + // delete with Forge. Instead, we keep them registered to stop Forge + // from reallocating those IDs to other mods such as Mystcraft. This + // is to prevent bugs. Blacklisted dimensions are still properly + // unregistered when the server shuts down. dimensionIDBlackList.add(dimension.id); deleteDimensionData(dimension); return true; From 972a67de766ec5784b92a337e8006ff160b1596a Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 3 Jul 2014 22:46:31 -0400 Subject: [PATCH 11/47] Rewrote CommandResetDungeons 1. Rewrote CommandResetDungeons to improve clarity and remove bugs. This version of the command preserves valid links. Those were previously removed, which would break some dungeons unnecessarily. 2. Fixed NewDimData.setParentToRoot(). The function did not account for the possibility that the target's parent might still exist and would need to be updated, leading to conflicting data. It also did not reset pack depth. We now correctly update a dimension and all its descendants. --- .../commands/CommandResetDungeons.java | 93 +++++++++++-------- .../mod_pocketDim/core/NewDimData.java | 32 +++++++ 2 files changed, 88 insertions(+), 37 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java index aad0671..69eaace 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java @@ -1,9 +1,10 @@ package StevenDimDoors.mod_pocketDim.commands; import java.util.ArrayList; +import java.util.HashSet; +import java.util.Stack; import net.minecraft.entity.player.EntityPlayer; -import net.minecraftforge.common.DimensionManager; import StevenDimDoors.mod_pocketDim.core.DimLink; import StevenDimDoors.mod_pocketDim.core.LinkTypes; import StevenDimDoors.mod_pocketDim.core.NewDimData; @@ -31,55 +32,73 @@ public class CommandResetDungeons extends DDCommandBase { if (command.length > 0) { - return DDCommandResult.TOO_FEW_ARGUMENTS; + return DDCommandResult.TOO_MANY_ARGUMENTS; + } + + int id; + int resetCount = 0; + int dungeonCount = 0; + HashSet deletedDimensions = new HashSet(); + ArrayList loadedDungeons = new ArrayList(); + + // Copy the list of dimensions to iterate over the copy. Otherwise, + // we would trigger an exception by modifying the original list. + ArrayList dimensions = new ArrayList(); + for (NewDimData dimension : PocketManager.getDimensions()) + { + dimensions.add(dimension); } - int dungeonCount = 0; - int resetCount = 0; - ArrayList dimsToDelete = new ArrayList(); - ArrayList dimsToFix = new ArrayList(); - - for (NewDimData data : PocketManager.getDimensions()) + // Iterate over the list of dimensions. Check which ones are dungeons. + // If a dungeon is found, try to delete it. If it can't be deleted, + // then it must be loaded and needs to be updated to prevent bugs. + for (NewDimData dimension : dimensions) { - - if(DimensionManager.getWorld(data.id())==null&&data.isDungeon()) + if (dimension.isDungeon()) { - resetCount++; dungeonCount++; - dimsToDelete.add(data.id()); - } - else if(data.isDungeon()) - { - dimsToFix.add(data.id()); - dungeonCount++; - for(DimLink link : data.links()) + id = dimension.id(); + if (PocketManager.deletePocket(dimension, true)) { - if(link.linkType()==LinkTypes.REVERSE) + resetCount++; + deletedDimensions.add(id); + } + else + { + loadedDungeons.add(dimension); + } + } + } + + // Modify the loaded dungeons to prevent bugs + for (NewDimData dungeon : loadedDungeons) + { + // Find top-most loaded dungeons and update their parents. + // They will automatically update their children. + // Dungeons with non-dungeon parents don't need to be fixed. + if (dungeon.parent() == null) + { + dungeon.setParentToRoot(); + } + + // Links to any deleted dungeons must be replaced + for (DimLink link : dungeon.links()) + { + if (link.hasDestination() && deletedDimensions.contains(link.destination().getDimension())) + { + if (link.linkType() == LinkTypes.DUNGEON) { - data.createLink(link.source(), LinkTypes.DUNGEON_EXIT, link.orientation()); + dungeon.createLink(link.source(), LinkTypes.DUNGEON, link.orientation()); } - if(link.linkType()==LinkTypes.DUNGEON) + else if (link.linkType() == LinkTypes.REVERSE) { - data.createLink(link.source(), LinkTypes.DUNGEON, link.orientation()); + dungeon.createLink(link.source(), LinkTypes.DUNGEON_EXIT, link.orientation()); } } } } - - for(Integer dimID:dimsToDelete) - { - PocketManager.deletePocket(PocketManager.getDimensionData(dimID), true); - } - /** - * temporary workaround - */ - for(Integer dimID: dimsToFix) - { - PocketManager.getDimensionData(dimID).setParentToRoot(); - } - //TODO- for some reason the parent field of loaded dimenions get reset to null if I call .setParentToRoot() before I delete the pockets. - //TODO implement blackList - //Notify the user of the results + + // Notify the user of the results sendChat(sender,("Reset complete. " + resetCount + " out of " + dungeonCount + " dungeons were reset.")); return DDCommandResult.SUCCESS; } diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/core/NewDimData.java b/src/main/java/StevenDimDoors/mod_pocketDim/core/NewDimData.java index 15182ed..8ed8d83 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/core/NewDimData.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/core/NewDimData.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Random; +import java.util.Stack; import java.util.TreeMap; import StevenDimDoors.mod_pocketDim.watcher.ClientLinkData; @@ -516,11 +517,42 @@ public abstract class NewDimData */ public void setParentToRoot() { + // Update this dimension's information + if (parent != null) + { + parent.children.remove(this); + } this.depth = 1; this.parent = this.root; this.root.children.add(this); this.root.modified = true; this.modified = true; + if (this.isDungeon) + { + this.packDepth = calculatePackDepth(this.parent, this.dungeon); + } + + // Update the depths for child dimensions using a depth-first traversal + Stack ordering = new Stack(); + ordering.addAll(this.children); + + while (!ordering.isEmpty()) + { + NewDimData current = ordering.pop(); + current.resetDepth(); + ordering.addAll(current.children); + } + } + + private void resetDepth() + { + // We assume that this is only applied to dimensions with parents + this.depth = this.parent.depth + 1; + if (this.isDungeon) + { + this.packDepth = calculatePackDepth(this.parent, this.dungeon); + } + this.modified = true; } public static int calculatePackDepth(NewDimData parent, DungeonData current) From 805e9dd040e8ec5a27f737e926832f5845d4117b Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 3 Jul 2014 22:49:15 -0400 Subject: [PATCH 12/47] Minor Changes Fixed up a few spots to clear some warnings. --- .../mod_pocketDim/commands/CommandResetDungeons.java | 1 - .../StevenDimDoors/mod_pocketDim/core/NewDimData.java | 11 +++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java index 69eaace..074124e 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java @@ -2,7 +2,6 @@ package StevenDimDoors.mod_pocketDim.commands; import java.util.ArrayList; import java.util.HashSet; -import java.util.Stack; import net.minecraft.entity.player.EntityPlayer; import StevenDimDoors.mod_pocketDim.core.DimLink; diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/core/NewDimData.java b/src/main/java/StevenDimDoors/mod_pocketDim/core/NewDimData.java index 8ed8d83..326b7d4 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/core/NewDimData.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/core/NewDimData.java @@ -581,10 +581,7 @@ public abstract class NewDimData { return parent.packDepth + 1; } - else - { - return 1; - } + return 1; } public void initializePocket(int originX, int originY, int originZ, int orientation, DimLink incoming) @@ -621,10 +618,7 @@ public abstract class NewDimData { return linkList.get(random.nextInt(linkList.size())); } - else - { - return linkList.get(0); - } + return linkList.get(0); } public boolean isModified() @@ -637,6 +631,7 @@ public abstract class NewDimData this.modified = false; } + @Override public String toString() { return "DimID= " + this.id; From c1e58c25cc1fcb301a4128d59a0a35df99181cf5 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Fri, 4 Jul 2014 01:17:25 -0400 Subject: [PATCH 13/47] Increased Max Monolith Aggro Increased the maximum Monolith aggro level and the cap range values by a factor of 1.25. The max aggro increase is to slow down how long it takes Monoliths to max out because they're just a little too fast right now. The cap adjustments will preserve the range of texture states they can have while idling. --- .../StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java b/src/main/java/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java index f54f515..279c123 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java @@ -21,9 +21,9 @@ import StevenDimDoors.mod_pocketDim.world.PocketProvider; public class MobMonolith extends EntityFlying implements IMob { - private static final short MAX_AGGRO = 200; - private static final short MAX_AGGRO_CAP = 80; - private static final short MIN_AGGRO_CAP = 20; + private static final short MAX_AGGRO = 250; + private static final short MAX_AGGRO_CAP = 100; + private static final short MIN_AGGRO_CAP = 25; private static final int MAX_TEXTURE_STATE = 18; private static final int MAX_SOUND_COOLDOWN = 200; private static final int MAX_AGGRO_RANGE = 35; From f64768ed1631762f334b90a4a10fb897cee80305 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Fri, 4 Jul 2014 02:14:24 -0400 Subject: [PATCH 14/47] Rewrote DeleteFolder Rewrote the helper class DeleteFolder. It was leaving behind empty directories when pockets were deleted. --- .../mod_pocketDim/helpers/DeleteFolder.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/helpers/DeleteFolder.java b/src/main/java/StevenDimDoors/mod_pocketDim/helpers/DeleteFolder.java index 3f835be..495ca6b 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/helpers/DeleteFolder.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/helpers/DeleteFolder.java @@ -2,31 +2,33 @@ package StevenDimDoors.mod_pocketDim.helpers; import java.io.File; - public class DeleteFolder { - public static boolean deleteFolder(File file) + public static boolean deleteFolder(File directory) { try { - File[] files = file.listFiles(); - - if(files==null) + File[] contents = directory.listFiles(); + if (contents != null) { - file.delete(); - return true; + for (File entry : contents) + { + if (entry.isDirectory()) + { + deleteFolder(entry); + } + else + { + entry.delete(); + } + } } - for(File inFile : files) - { - DeleteFolder.deleteFolder(inFile); - } - + return directory.delete(); } catch (Exception e) { e.printStackTrace(); return false; } - return true; } } \ No newline at end of file From d3860119e9c5b569ac6b38194f8248b3bbd5ad13 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Fri, 4 Jul 2014 13:05:08 -0400 Subject: [PATCH 15/47] Minor Change to PocketManager Added a minor check to PocketManager.loadDimension() so that an attempt to load an unregistered dimension won't be passed on to Forge where it would cause an exception - which is then caught by Forge before it can cause problems. This isn't strictly necessary, but it's a nice consideration. --- .../StevenDimDoors/mod_pocketDim/core/PocketManager.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java b/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java index 7c7c3e0..5a1f1d6 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java @@ -483,6 +483,11 @@ public class PocketManager public static WorldServer loadDimension(int id) { + if (!DimensionManager.isDimensionRegistered(id)) + { + return null; + } + WorldServer world = DimensionManager.getWorld(id); if (world == null) { From 4d53ae5f6a38ccd9f54a8aed74f62cb7b23ad5b1 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Fri, 4 Jul 2014 13:53:44 -0400 Subject: [PATCH 16/47] Removed CommandDeleteAllLinks I removed CommandDeleteAllLinks because of the significant risk that it would harm a server. It's possible that someone could run this by accident instead of CommandDeleteRifts. It takes the same arguments or even no arguments and it would immediately wipe all links in a dimension. We can restore it later if it's really needed. --- .../commands/CommandDeleteAllLinks.java | 66 ------------------- .../mod_pocketDim/mod_pocketDim.java | 1 - 2 files changed, 67 deletions(-) delete mode 100644 src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandDeleteAllLinks.java diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandDeleteAllLinks.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandDeleteAllLinks.java deleted file mode 100644 index af9f915..0000000 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandDeleteAllLinks.java +++ /dev/null @@ -1,66 +0,0 @@ -package StevenDimDoors.mod_pocketDim.commands; - -import java.util.ArrayList; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.world.World; -import StevenDimDoors.mod_pocketDim.core.DimLink; -import StevenDimDoors.mod_pocketDim.core.NewDimData; -import StevenDimDoors.mod_pocketDim.core.PocketManager; - -public class CommandDeleteAllLinks extends DDCommandBase -{ - private static CommandDeleteAllLinks instance = null; - - private CommandDeleteAllLinks() - { - super("dd-deletelinks", "???"); - } - - public static CommandDeleteAllLinks instance() - { - if (instance == null) - instance = new CommandDeleteAllLinks(); - - return instance; - } - - @Override - protected DDCommandResult processCommand(EntityPlayer sender, String[] command) - { - int linksRemoved=0; - int targetDim; - boolean shouldGo= true; - - if(command.length==1) - { - targetDim = parseInt(sender, command[0]); - } - else - { - targetDim=0; - shouldGo=false; - sendChat(sender, ("Error-Invalid argument, delete_all_links ")); - } - - if(shouldGo) - { - - NewDimData dim = PocketManager.getDimensionData(targetDim); - ArrayList linksInDim = dim.getAllLinks(); - - for (DimLink link : linksInDim) - { - World targetWorld = PocketManager.loadDimension(targetDim); - targetWorld.setBlock(link.source().getX(), link.source().getY(), link.source().getZ(), 0); - dim.deleteLink(link); - //TODO Probably should check what the block is, but thats annoying so Ill do it later. - - linksRemoved++; - } - sendChat(sender,("Removed " + linksRemoved + " links.")); - - } - return DDCommandResult.SUCCESS; //TEMPORARY HACK - } -} \ No newline at end of file diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java b/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java index a1a93e6..9130a86 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java @@ -350,7 +350,6 @@ public class mod_pocketDim event.registerServerCommand( CommandCreateDungeonRift.instance() ); event.registerServerCommand( CommandListDungeons.instance() ); event.registerServerCommand( CommandCreateRandomRift.instance() ); - event.registerServerCommand( CommandDeleteAllLinks.instance() ); event.registerServerCommand( CommandDeleteRifts.instance() ); event.registerServerCommand( CommandExportDungeon.instance() ); event.registerServerCommand( CommandCreatePocket.instance() ); From 1e3b32a15ca7d6c6b18852e8852d81a67e8d767c Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Fri, 4 Jul 2014 14:06:41 -0400 Subject: [PATCH 17/47] Minor Change Removed a reference to CommandDeleteAllLinks from mod_pocketDim. --- src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java b/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java index 9130a86..62dd845 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java @@ -30,7 +30,6 @@ import StevenDimDoors.mod_pocketDim.blocks.WarpDoor; import StevenDimDoors.mod_pocketDim.commands.CommandCreateDungeonRift; import StevenDimDoors.mod_pocketDim.commands.CommandCreatePocket; import StevenDimDoors.mod_pocketDim.commands.CommandCreateRandomRift; -import StevenDimDoors.mod_pocketDim.commands.CommandDeleteAllLinks; import StevenDimDoors.mod_pocketDim.commands.CommandDeleteRifts; import StevenDimDoors.mod_pocketDim.commands.CommandExportDungeon; import StevenDimDoors.mod_pocketDim.commands.CommandListDungeons; From 16f0a8303aca16a799f12cfc5c81b53e51083f0d Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Fri, 4 Jul 2014 20:20:46 -0400 Subject: [PATCH 18/47] Rewrote CommandTeleportPlayer Rewrote CommandTeleportPlayer for the same reason as usual. There were a few bugs before, such as that lookups for players were limited to within the world from which the command sender was using the command. Players in other dimensions could not be teleported. The command would also place people in the ground because it did not adjust its coordinates for the way that DDTeleporter interprets them - as the location of the top block of a door and the player's head. --- .../commands/CommandTeleportPlayer.java | 203 ++++++++++-------- .../commands/DDCommandResult.java | 1 + 2 files changed, 110 insertions(+), 94 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandTeleportPlayer.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandTeleportPlayer.java index 93b4d3f..83bf268 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandTeleportPlayer.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandTeleportPlayer.java @@ -1,8 +1,10 @@ package StevenDimDoors.mod_pocketDim.commands; import net.minecraft.entity.player.EntityPlayer; -import net.minecraftforge.common.DimensionManager; +import net.minecraft.server.MinecraftServer; +import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.core.DDTeleporter; +import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.util.Point4D; @@ -12,7 +14,10 @@ public class CommandTeleportPlayer extends DDCommandBase private CommandTeleportPlayer() { - super("dd-tp", new String[] {" "," "} ); + super("dd-tp", new String[] { + " ", + " ", + " "} ); } public static CommandTeleportPlayer instance() @@ -23,110 +28,120 @@ public class CommandTeleportPlayer extends DDCommandBase return instance; } - /** - * TODO- Change to accept variety of input, like just coords, just dim ID, or two player names. - */ @Override protected DDCommandResult processCommand(EntityPlayer sender, String[] command) { - EntityPlayer targetPlayer = sender; - int dimDestinationID = sender.worldObj.provider.dimensionId; + int x; + int y; + int z; + World world; + int dimensionID; + Point4D destination; + NewDimData dimension; + boolean checkOrientation; + EntityPlayer targetPlayer; - if(command.length == 5) + if (command.length < 2) { - for(int i= 1; i <5;i++) - { - if(!isInteger(command[i])) - { - return DDCommandResult.INVALID_ARGUMENTS; - } - } - if(sender.worldObj.getPlayerEntityByName(command[0])!=null) //Gets the targeted player - { - targetPlayer = sender.worldObj.getPlayerEntityByName(command[0]); - } - else - { - return DDCommandResult.INVALID_ARGUMENTS; - } - dimDestinationID=Integer.parseInt(command[1]);//gets the target dim ID from the command string - - if(!DimensionManager.isDimensionRegistered(dimDestinationID)) - { - return DDCommandResult.INVALID_DIMENSION_ID; - } - - PocketManager.loadDimension(dimDestinationID); - Point4D destination = new Point4D(Integer.parseInt(command[2]),Integer.parseInt(command[3]),Integer.parseInt(command[4]),dimDestinationID); - DDTeleporter.teleportEntity(targetPlayer, destination, false); + return DDCommandResult.TOO_FEW_ARGUMENTS; } - else if(command.length == 2 && isInteger(command[1])) + if (command.length > 5) { - if(sender.worldObj.getPlayerEntityByName(command[0])!=null) //Gets the targeted player - { - targetPlayer = sender.worldObj.getPlayerEntityByName(command[0]); - } - else - { - return DDCommandResult.INVALID_ARGUMENTS; - } - dimDestinationID=Integer.parseInt(command[1]);//gets the target dim ID from the command string - - if(!DimensionManager.isDimensionRegistered(dimDestinationID)) - { - return DDCommandResult.INVALID_DIMENSION_ID; - } - - - Point4D destination = PocketManager.getDimensionData(dimDestinationID).origin(); - if(!PocketManager.getDimensionData(dimDestinationID).isPocketDimension()) - { - destination = new Point4D(destination.getX(),PocketManager.loadDimension(dimDestinationID).getTopSolidOrLiquidBlock( - destination.getX(), destination.getZ()), - destination.getZ(),destination.getDimension()); - } - DDTeleporter.teleportEntity(targetPlayer, destination, false); + return DDCommandResult.TOO_MANY_ARGUMENTS; } - else if(command.length == 1 && isInteger(command[0])) - { - - targetPlayer = sender; - - dimDestinationID=Integer.parseInt(command[0]);//gets the target dim ID from the command string - - if(!DimensionManager.isDimensionRegistered(dimDestinationID)) - { - return DDCommandResult.INVALID_DIMENSION_ID; - } - - - Point4D destination = PocketManager.getDimensionData(dimDestinationID).origin(); - if(!PocketManager.getDimensionData(dimDestinationID).isPocketDimension()) - { - destination = new Point4D(destination.getX(),PocketManager.loadDimension(dimDestinationID).getTopSolidOrLiquidBlock( - destination.getX(), destination.getZ()), - destination.getZ(),destination.getDimension()); - } - DDTeleporter.teleportEntity(targetPlayer, destination, false); - } - else + if (command.length == 3) { return DDCommandResult.INVALID_ARGUMENTS; } + // Check that all arguments after the username are integers + for (int k = 1; k < command.length; k++) + { + if (!isInteger(command[k])) + { + return DDCommandResult.INVALID_ARGUMENTS; + } + } + // Check if the target player is logged in + targetPlayer = MinecraftServer.getServer().getConfigurationManager().getPlayerForUsername(command[0]); + if (targetPlayer == null) + { + return DDCommandResult.PLAYER_OFFLINE; + } + // If a dimension ID was provided, try to load it + if (command.length != 4) + { + dimensionID = Integer.parseInt(command[1]); + world = PocketManager.loadDimension(dimensionID); + if (world == null) + { + return DDCommandResult.UNREGISTERED_DIMENSION; + } + } + else + { + dimensionID = targetPlayer.worldObj.provider.dimensionId; + // SenseiKiwi: Will not be used, but I prefer not to leave 'world' as null + world = targetPlayer.worldObj; + } + + // If we teleport to a pocket dimension, set checkOrientation to true + // so the player is placed correctly relative to the entrance door. + checkOrientation = false; + + // Parse or calculate the destination as necessary + // The Y coordinate must be increased by 1 because of the way that + // DDTeleporter considers destination points. It assumes that the + // point provided is the upper block of a door. + if (command.length == 2) + { + // Check if the destination is a pocket dimension + dimension = PocketManager.getDimensionData(dimensionID); + if (dimension.isPocketDimension()) + { + // The destination is a pocket dimension. + // Teleport the player to its original entrance (the origin). + destination = dimension.origin(); + checkOrientation = true; + } + else + { + // The destination is not a pocket dimension, which means we + // don't automatically know a safe location where we can send + // the player. Send the player to (0, Y, 0), where Y is chosen + // by searching. Add 2 to place the player ABOVE the top block. + y = world.getTopSolidOrLiquidBlock(0, 0) + 2; + destination = new Point4D(0, y, 0, dimensionID); + } + } + else if (command.length == 4) + { + x = Integer.parseInt(command[1]); + y = Integer.parseInt(command[2]) + 1; + z = Integer.parseInt(command[3]); + destination = new Point4D(x, y, z, dimensionID); + } + else + { + x = Integer.parseInt(command[2]); + y = Integer.parseInt(command[3]) + 1; + z = Integer.parseInt(command[4]); + destination = new Point4D(x, y, z, dimensionID); + } + // Teleport! + DDTeleporter.teleportEntity(targetPlayer, destination, checkOrientation); return DDCommandResult.SUCCESS; } - public static boolean isInteger( String input ) - { - try - { - Integer.parseInt( input ); - return true; - } - catch(Exception e ) - { - return false; - } - } - + private static boolean isInteger(String input) + { + try + { + Integer.parseInt(input); + return true; + } + catch(Exception e) + { + return false; + } + } } \ No newline at end of file diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/DDCommandResult.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/DDCommandResult.java index f34b282..b6a31b9 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/DDCommandResult.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/DDCommandResult.java @@ -9,6 +9,7 @@ public class DDCommandResult { public static final DDCommandResult INVALID_DIMENSION_ID = new DDCommandResult(3, "Error: Invalid dimension ID", true); public static final DDCommandResult UNREGISTERED_DIMENSION = new DDCommandResult(4, "Error: Dimension is not registered", false); public static final DDCommandResult INVALID_ARGUMENTS = new DDCommandResult(5, "Error: Invalid arguments passed to the command", true); + public static final DDCommandResult PLAYER_OFFLINE = new DDCommandResult(6, "Error: Player is not online", false); public static final int CUSTOM_ERROR_CODE = -1; From 17a770eaf0b02858a3b9cc5d0e855d48cb140043 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Fri, 4 Jul 2014 20:55:57 -0400 Subject: [PATCH 19/47] Minor Change Added two comments to CommandTeleportPlayer --- .../mod_pocketDim/commands/CommandTeleportPlayer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandTeleportPlayer.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandTeleportPlayer.java index 83bf268..b02222f 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandTeleportPlayer.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandTeleportPlayer.java @@ -116,14 +116,14 @@ public class CommandTeleportPlayer extends DDCommandBase else if (command.length == 4) { x = Integer.parseInt(command[1]); - y = Integer.parseInt(command[2]) + 1; + y = Integer.parseInt(command[2]) + 1; // Correct the Y value z = Integer.parseInt(command[3]); destination = new Point4D(x, y, z, dimensionID); } else { x = Integer.parseInt(command[2]); - y = Integer.parseInt(command[3]) + 1; + y = Integer.parseInt(command[3]) + 1; // Correct the Y value z = Integer.parseInt(command[4]); destination = new Point4D(x, y, z, dimensionID); } From 100fa38c52b67f31ac4e7343bd7beff5ea722be6 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sat, 5 Jul 2014 14:18:18 -0400 Subject: [PATCH 20/47] Minor Changes to DDTeleporter Made some minor changes to DDTeleporter to get rid of a few warnings. Also tweaked and commented DDTeleporter.initializeDestination(). There were inappropriate references to a link's internal variables instead of using its getters and there was a subtle link overwrite for blacklist destinations. Without comments, it would probably be unclear that overwriting that link is safe. This changes are in preparation for fixing issues with blacklisted destination redirection. --- .../mod_pocketDim/core/DDTeleporter.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java b/src/main/java/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java index c7d0c2b..fc793e5 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java @@ -25,7 +25,6 @@ import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.blocks.BaseDimDoor; import StevenDimDoors.mod_pocketDim.config.DDProperties; import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper; -import StevenDimDoors.mod_pocketDim.items.ItemDimensionalDoor; import StevenDimDoors.mod_pocketDim.schematic.BlockRotator; import StevenDimDoors.mod_pocketDim.tileentities.TileEntityDimDoor; import StevenDimDoors.mod_pocketDim.util.Point4D; @@ -483,9 +482,12 @@ public class DDTeleporter { if (link.hasDestination()) { - if(PocketManager.isBlackListed(link.destination().getDimension())) + if (PocketManager.isBlackListed(link.destination().getDimension())) { - link=PocketManager.getDimensionData(link.source().getDimension()).createLink(link.link.point,LinkTypes.SAFE_EXIT,link.link.orientation); + // Overwrite this link to a blacklisted destination with a safe exit link + // We don't need to change 'link' to a different reference. + // NewDimData will overwrite the existing link in-place. + PocketManager.getDimensionData(link.source().getDimension()).createLink(link.source(), LinkTypes.SAFE_EXIT, link.orientation()); } else { @@ -499,7 +501,7 @@ public class DDTeleporter case LinkTypes.DUNGEON: return PocketBuilder.generateNewDungeonPocket(link, properties); case LinkTypes.POCKET: - return PocketBuilder.generateNewPocket(link, properties,door); + return PocketBuilder.generateNewPocket(link, properties, door); case LinkTypes.SAFE_EXIT: return generateSafeExit(link, properties); case LinkTypes.DUNGEON_EXIT: @@ -544,10 +546,7 @@ public class DDTeleporter { return matches.get( random.nextInt(matches.size()) ); } - else - { - return null; - } + return null; } private static boolean generateUnsafeExit(DimLink link) @@ -749,7 +748,7 @@ public class DDTeleporter // Set up the warp door at the destination orientation = BlockRotator.transformMetadata(orientation, 2, properties.WarpDoorID); - ItemDimensionalDoor.placeDoorBlock(world, x, y + 1, z, orientation, mod_pocketDim.warpDoor); + ItemDoor.placeDoorBlock(world, x, y + 1, z, orientation, mod_pocketDim.warpDoor); // Complete the link to the destination // This comes last so the destination isn't set unless everything else works first From 06cf72f9f73fd058099e63a589d13ff72a74ede9 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sat, 5 Jul 2014 21:28:10 -0400 Subject: [PATCH 21/47] Fixed Flawed Link Redirection Fixed the way in which we handle redirecting links to blacklisted dimensions. The previous method always converted links into safe exits. This lead to strange situations that could be seen as bugs. For instance, using a dungeon entrance in a root dimension would generate an exit door and a supporting platform directly above the entrance door. That also meant that any visited dungeons would be unusable if they were reset. We now do different things depending on the location of the link and its type. If the link is a dungeon link, then its destination is reset to allow a new dungeon to form. For other link types, if the link is in a pocket dimension, then it becomes a safe exit link, because it could be the only way out. If it's in a root dimension, then there are no reasonable destinations, so the teleport request is cancelled. --- .../mod_pocketDim/core/DDTeleporter.java | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java b/src/main/java/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java index fc793e5..f8f7bc1 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java @@ -484,10 +484,31 @@ public class DDTeleporter { if (PocketManager.isBlackListed(link.destination().getDimension())) { - // Overwrite this link to a blacklisted destination with a safe exit link - // We don't need to change 'link' to a different reference. - // NewDimData will overwrite the existing link in-place. - PocketManager.getDimensionData(link.source().getDimension()).createLink(link.source(), LinkTypes.SAFE_EXIT, link.orientation()); + // This link leads to a dimension that has been blacklisted. + // That means that it was a pocket and it was deleted. + // Depending on the link type, we must overwrite it or cancel + // the teleport operation. We don't need to assign 'link' with + // a different value. NewDimData will overwrite it in-place. + NewDimData start = PocketManager.getDimensionData(link.source().getDimension()); + if (link.linkType() == LinkTypes.DUNGEON) + { + // Ovewrite the link into a dungeon link with no destination + start.createLink(link.source(), LinkTypes.DUNGEON, link.orientation()); + } + else + { + if (start.isPocketDimension()) + { + // Ovewrite the link into a safe exit link, because + // this could be the only way out from a pocket. + start.createLink(link.source(), LinkTypes.SAFE_EXIT, link.orientation()); + } + else + { + // Cancel the teleport attempt + return false; + } + } } else { From 58d5f6dd146f353b697a98f2e3b6bee5b26976ef Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Mon, 7 Jul 2014 01:59:26 -0400 Subject: [PATCH 22/47] Minor Changes Minor annotation changes to remove some warnings... and keep up my GitHub spree. --- .../mod_pocketDim/world/fortresses/ComponentNetherGateway.java | 3 ++- .../world/fortresses/DDNetherFortressGenerator.java | 3 ++- .../world/fortresses/DDStructureNetherBridgeStart.java | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/world/fortresses/ComponentNetherGateway.java b/src/main/java/StevenDimDoors/mod_pocketDim/world/fortresses/ComponentNetherGateway.java index 8b05b39..db6ef44 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/world/fortresses/ComponentNetherGateway.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/world/fortresses/ComponentNetherGateway.java @@ -66,7 +66,8 @@ public class ComponentNetherGateway extends StructureComponent * second Part of Structure generating, this for example places Spiderwebs, Mob Spawners, it closes Mineshafts at * the end, it adds Fences... */ - public boolean addComponentParts(World world, Random random, StructureBoundingBox bounds) + @Override + public boolean addComponentParts(World world, Random random, StructureBoundingBox bounds) { int NETHER_SLAB_METADATA = 6; diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/world/fortresses/DDNetherFortressGenerator.java b/src/main/java/StevenDimDoors/mod_pocketDim/world/fortresses/DDNetherFortressGenerator.java index 644a5c1..9531939 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/world/fortresses/DDNetherFortressGenerator.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/world/fortresses/DDNetherFortressGenerator.java @@ -18,7 +18,8 @@ public class DDNetherFortressGenerator extends MapGenNetherBridge MapGenStructureIO.func_143034_b(DDStructureNetherBridgeStart.class, "Fortress"); } - protected StructureStart getStructureStart(int chunkX, int chunkZ) + @Override + protected StructureStart getStructureStart(int chunkX, int chunkZ) { return new DDStructureNetherBridgeStart(this.worldObj, this.rand, chunkX, chunkZ, DDProperties.instance()); } diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/world/fortresses/DDStructureNetherBridgeStart.java b/src/main/java/StevenDimDoors/mod_pocketDim/world/fortresses/DDStructureNetherBridgeStart.java index bc7cc06..2778197 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/world/fortresses/DDStructureNetherBridgeStart.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/world/fortresses/DDStructureNetherBridgeStart.java @@ -105,7 +105,8 @@ public class DDStructureNetherBridgeStart extends StructureNetherBridgeStart /** * Keeps iterating Structure Pieces and spawning them until the checks tell it to stop */ - public void generateStructure(World world, Random random, StructureBoundingBox generationBounds) + @Override + public void generateStructure(World world, Random random, StructureBoundingBox generationBounds) { if (hasGateway) { From dc55359aaf37e69de39a96d41766d238d5c42cbc Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Mon, 7 Jul 2014 03:56:47 -0400 Subject: [PATCH 23/47] Minor Changes Made various minor changes to eliminate warnings or to improve clarity. --- .../mod_pocketDim/blocks/BaseDimDoor.java | 40 +++++++------------ .../mod_pocketDim/blocks/BlockDimWall.java | 1 + .../mod_pocketDim/blocks/BlockDoorGold.java | 19 ++++----- .../mod_pocketDim/blocks/DimensionalDoor.java | 5 +-- .../mod_pocketDim/blocks/TransTrapdoor.java | 7 ++-- .../mod_pocketDim/blocks/WarpDoor.java | 1 - 6 files changed, 28 insertions(+), 45 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BaseDimDoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BaseDimDoor.java index 3b94723..f8bd4e1 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BaseDimDoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BaseDimDoor.java @@ -11,7 +11,6 @@ import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Icon; import net.minecraft.util.MathHelper; @@ -22,7 +21,6 @@ import StevenDimDoors.mod_pocketDim.config.DDProperties; import StevenDimDoors.mod_pocketDim.core.DDTeleporter; import StevenDimDoors.mod_pocketDim.core.DimLink; import StevenDimDoors.mod_pocketDim.core.PocketManager; -import StevenDimDoors.mod_pocketDim.schematic.BlockRotator; import StevenDimDoors.mod_pocketDim.tileentities.TileEntityDimDoor; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -159,16 +157,13 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn reversed = !reversed; } } - if (isUpperDoorBlock(fullMetadata)) + { return this.upperTextures[reversed ? 1 : 0]; - else - return this.lowerTextures[reversed ? 1 : 0]; - } - else - { - return this.lowerTextures[0]; + } + return this.lowerTextures[reversed ? 1 : 0]; } + return this.lowerTextures[0]; } //Called to update the render information on the tile entity. Could probably implement a data watcher, @@ -180,29 +175,23 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn { int metadata = world.getBlockMetadata(x, y, z); TileEntityDimDoor dimTile = (TileEntityDimDoor) tile; - dimTile.openOrClosed = this.isDoorOnRift(world, x, y, z)&&this.isUpperDoorBlock(metadata); + dimTile.openOrClosed = isDoorOnRift(world, x, y, z) && isUpperDoorBlock(metadata); dimTile.orientation = this.getFullMetadata(world, x, y, z) & 7; } return this; } - public boolean isDoorOnRift(World world, int x, int y, int z) + public static boolean isDoorOnRift(World world, int x, int y, int z) { - if(this.isUpperDoorBlock( world.getBlockMetadata(x, y, z))) + if (isUpperDoorBlock(world.getBlockMetadata(x, y, z))) { - if(PocketManager.getLink(x, y, z, world.provider.dimensionId) != null||PocketManager.getLink(x, y-1, z, world.provider.dimensionId) != null) - { - return true; - } + // Target block is the upper block + return (PocketManager.getLink(x, y, z, world.provider.dimensionId) != null || + PocketManager.getLink(x, y - 1, z, world.provider.dimensionId) != null); } - else - { - if(PocketManager.getLink(x, y, z, world.provider.dimensionId) != null||PocketManager.getLink(x, y+1, z, world.provider.dimensionId) != null) - { - return true; - } - } - return false; + // Target block is the lower block + return (PocketManager.getLink(x, y, z, world.provider.dimensionId) != null || + PocketManager.getLink(x, y + 1, z, world.provider.dimensionId) != null); } /** @@ -359,7 +348,8 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn /** * Returns the ID of the items to drop on destruction. */ - public int idDropped(int metadata, Random random, int fortune) + @Override + public int idDropped(int metadata, Random random, int fortune) { return isUpperDoorBlock(metadata) ? 0 : this.getDrops(); } diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockDimWall.java b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockDimWall.java index 82e451a..fd1b46c 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockDimWall.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockDimWall.java @@ -88,6 +88,7 @@ public class BlockDimWall extends Block subItems.add(new ItemStack(this, 1, ix)); } } + @Override public void onBlockDestroyedByPlayer(World par1World, int par2, int par3, int par4, int par5) {} diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockDoorGold.java b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockDoorGold.java index 1e8f91e..2d3ac30 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockDoorGold.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockDoorGold.java @@ -2,17 +2,15 @@ package StevenDimDoors.mod_pocketDim.blocks; import java.util.Random; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.config.DDProperties; import net.minecraft.block.BlockDoor; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.IconFlipped; import net.minecraft.client.renderer.texture.IconRegister; -import net.minecraft.item.Item; import net.minecraft.util.Icon; import net.minecraft.world.IBlockAccess; +import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; public class BlockDoorGold extends BlockDoor { @@ -110,15 +108,12 @@ public class BlockDoorGold extends BlockDoor reversed = !reversed; } } - if (BaseDimDoor.isUpperDoorBlock(fullMetadata)) + { return this.upperTextures[reversed ? 1 : 0]; - else - return this.lowerTextures[reversed ? 1 : 0]; - } - else - { - return this.lowerTextures[0]; + } + return this.lowerTextures[reversed ? 1 : 0]; } + return this.lowerTextures[0]; } } diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/DimensionalDoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/DimensionalDoor.java index 42d25f6..2d9eef5 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/DimensionalDoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/DimensionalDoor.java @@ -9,10 +9,8 @@ import StevenDimDoors.mod_pocketDim.core.LinkTypes; import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; -@SuppressWarnings("deprecation") public class DimensionalDoor extends BaseDimDoor { - public DimensionalDoor(int blockID, Material material, DDProperties properties) { super(blockID, material, properties); @@ -27,10 +25,11 @@ public class DimensionalDoor extends BaseDimDoor DimLink link = dimension.getLink(x, y, z); if (link == null) { - dimension.createLink(x, y, z, LinkTypes.POCKET,world.getBlockMetadata(x, y - 1, z)); + dimension.createLink(x, y, z, LinkTypes.POCKET, world.getBlockMetadata(x, y - 1, z)); } } } + @Override public int getDrops() { diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/TransTrapdoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/TransTrapdoor.java index d1b7fd4..aa4d4bc 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/TransTrapdoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/TransTrapdoor.java @@ -18,7 +18,6 @@ import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.tileentities.TileEntityTransTrapdoor; -@SuppressWarnings("deprecation") public class TransTrapdoor extends BlockTrapDoor implements IDimDoor, ITileEntityProvider { @@ -61,7 +60,7 @@ public class TransTrapdoor extends BlockTrapDoor implements IDimDoor, ITileEntit { this.placeLink(world, x, y, z); world.setBlockTileEntity(x, y, z, this.createNewTileEntity(world)); - this.updateAttachedTile(world, x, y, z); + updateAttachedTile(world, x, y, z); } @Override @@ -76,8 +75,8 @@ public class TransTrapdoor extends BlockTrapDoor implements IDimDoor, ITileEntit { return new TileEntityTransTrapdoor(); } - - public void updateAttachedTile(World world, int x, int y, int z) + + public static void updateAttachedTile(World world, int x, int y, int z) { TileEntity tile = world.getBlockTileEntity(x, y, z); if (tile instanceof TileEntityTransTrapdoor) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/WarpDoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/WarpDoor.java index 6f7d881..58cfd05 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/WarpDoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/WarpDoor.java @@ -9,7 +9,6 @@ import StevenDimDoors.mod_pocketDim.core.LinkTypes; import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; -@SuppressWarnings("deprecation") public class WarpDoor extends BaseDimDoor { public WarpDoor(int blockID, Material material, DDProperties properties) From 52bae00dc6e0c01fd24857ba594c397c066fd791 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sun, 6 Jul 2014 04:01:07 -0400 Subject: [PATCH 24/47] Minor Change Minor change to remove a warning --- .../StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java b/src/main/java/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java index e978832..7a443fc 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java @@ -162,7 +162,7 @@ public class DungeonSchematic extends Schematic { applyFilter(standardizer); } - private Map getAssignedToStandardIDMapping(DDProperties properties) + private static Map getAssignedToStandardIDMapping(DDProperties properties) { //If we ever need this broadly or support other mods, this should be moved to a separate class TreeMap mapping = new TreeMap(); From 7d840ff895d2494197c2fb3b1bd5f9ce2a25d491 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sun, 6 Jul 2014 04:31:42 -0400 Subject: [PATCH 25/47] Fixed Pick Block Results We previously returned the Vanilla counterparts to our doors as the items to be used by the pick block button - used in Creative mode for replicating nearby blocks. This was incorrect because we would want to return the actual door item needed to place the particular door in question. More importantly, this might solve our issues with WAILA reporting the wrong information when players look at our doors. I read the code for the most recent version of WAILA and it uses various functions to choose how to identify a block. The result of Block.idPicked() is probably used as the main source for the identities of our blocks. --- .../mod_pocketDim/blocks/BaseDimDoor.java | 4 ++-- .../mod_pocketDim/blocks/BlockDoorGold.java | 8 +++++++ .../blocks/BlockGoldDimDoor.java | 6 ++++++ .../mod_pocketDim/blocks/DimensionalDoor.java | 7 +++++++ .../mod_pocketDim/blocks/IDimDoor.java | 2 ++ .../mod_pocketDim/blocks/TransTrapdoor.java | 21 ++++++++++++++++--- .../mod_pocketDim/blocks/TransientDoor.java | 6 ++++++ .../mod_pocketDim/blocks/UnstableDoor.java | 8 +++++++ .../mod_pocketDim/blocks/WarpDoor.java | 7 +++++++ 9 files changed, 64 insertions(+), 5 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BaseDimDoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BaseDimDoor.java index f8bd4e1..d26a0e3 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BaseDimDoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BaseDimDoor.java @@ -340,9 +340,9 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn */ @Override @SideOnly(Side.CLIENT) - public int idPicked(World par1World, int par2, int par3, int par4) + public int idPicked(World world, int x, int y, int z) { - return this.getDrops(); + return this.getDoorItem(); } /** diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockDoorGold.java b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockDoorGold.java index 2d3ac30..d3e703d 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockDoorGold.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockDoorGold.java @@ -8,6 +8,7 @@ import net.minecraft.client.renderer.IconFlipped; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.util.Icon; import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.mod_pocketDim; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -35,6 +36,13 @@ public class BlockDoorGold extends BlockDoor upperTextures[1] = new IconFlipped(upperTextures[0], true, false); lowerTextures[1] = new IconFlipped(lowerTextures[0], true, false); } + + @Override + @SideOnly(Side.CLIENT) + public int idPicked(World world, int x, int y, int z) + { + return mod_pocketDim.itemGoldenDoor.itemID; + } @Override public int idDropped(int par1, Random par2Random, int par3) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockGoldDimDoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockGoldDimDoor.java index 5a788db..3feb075 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockGoldDimDoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockGoldDimDoor.java @@ -34,6 +34,12 @@ public class BlockGoldDimDoor extends BaseDimDoor } } + @Override + public int getDoorItem() + { + return mod_pocketDim.itemGoldenDimensionalDoor.itemID; + } + @Override public int getDrops() { diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/DimensionalDoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/DimensionalDoor.java index 2d9eef5..3537a77 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/DimensionalDoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/DimensionalDoor.java @@ -3,6 +3,7 @@ package StevenDimDoors.mod_pocketDim.blocks; import net.minecraft.block.material.Material; import net.minecraft.item.Item; import net.minecraft.world.World; +import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.config.DDProperties; import StevenDimDoors.mod_pocketDim.core.DimLink; import StevenDimDoors.mod_pocketDim.core.LinkTypes; @@ -30,6 +31,12 @@ public class DimensionalDoor extends BaseDimDoor } } + @Override + public int getDoorItem() + { + return mod_pocketDim.itemDimensionalDoor.itemID; + } + @Override public int getDrops() { diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/IDimDoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/IDimDoor.java index b3884dc..82b4562 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/IDimDoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/IDimDoor.java @@ -12,5 +12,7 @@ public interface IDimDoor public int getDrops(); + public int getDoorItem(); + public TileEntity initDoorTE(World world, int x, int y, int z); } diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/TransTrapdoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/TransTrapdoor.java index aa4d4bc..4a1df0d 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/TransTrapdoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/TransTrapdoor.java @@ -2,6 +2,9 @@ package StevenDimDoors.mod_pocketDim.blocks; import java.util.Random; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + import net.minecraft.block.Block; import net.minecraft.block.BlockTrapDoor; import net.minecraft.block.ITileEntityProvider; @@ -99,18 +102,30 @@ public class TransTrapdoor extends BlockTrapDoor implements IDimDoor, ITileEntit } } } - + + @Override + @SideOnly(Side.CLIENT) + public int idPicked(World world, int x, int y, int z) + { + return this.getDoorItem(); + } @Override public int idDropped(int metadata, Random random, int fortuneLevel) { - return getDrops(); + return this.getDrops(); } + + @Override + public int getDoorItem() + { + return mod_pocketDim.transTrapdoor.blockID; + } @Override public int getDrops() { - return Block.trapdoor.blockID; + return Block.trapdoor.blockID; } public static boolean isTrapdoorSetLow(int metadata) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/TransientDoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/TransientDoor.java index fb0a187..0eac631 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/TransientDoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/TransientDoor.java @@ -72,6 +72,12 @@ public class TransientDoor extends BaseDimDoor } } } + + @Override + public int getDoorItem() + { + return 0; + } @Override public int getDrops() diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/UnstableDoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/UnstableDoor.java index e59a94c..6f14c66 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/UnstableDoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/UnstableDoor.java @@ -3,6 +3,7 @@ package StevenDimDoors.mod_pocketDim.blocks; import net.minecraft.block.material.Material; import net.minecraft.item.Item; import net.minecraft.world.World; +import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.config.DDProperties; import StevenDimDoors.mod_pocketDim.core.LinkTypes; import StevenDimDoors.mod_pocketDim.core.NewDimData; @@ -24,6 +25,13 @@ public class UnstableDoor extends BaseDimDoor dimension.createLink(x, y, z, LinkTypes.RANDOM,world.getBlockMetadata(x, y - 1, z)); } } + + @Override + public int getDoorItem() + { + return mod_pocketDim.itemUnstableDoor.itemID; + } + @Override public int getDrops() { diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/WarpDoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/WarpDoor.java index 58cfd05..f860f6e 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/WarpDoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/WarpDoor.java @@ -3,6 +3,7 @@ package StevenDimDoors.mod_pocketDim.blocks; import net.minecraft.block.material.Material; import net.minecraft.item.Item; import net.minecraft.world.World; +import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.config.DDProperties; import StevenDimDoors.mod_pocketDim.core.DimLink; import StevenDimDoors.mod_pocketDim.core.LinkTypes; @@ -30,6 +31,12 @@ public class WarpDoor extends BaseDimDoor } } + @Override + public int getDoorItem() + { + return mod_pocketDim.itemWarpDoor.itemID; + } + @Override public int getDrops() { From 2904ec146d241273f38738cc081a983167b3ae5e Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Wed, 9 Jul 2014 04:01:37 -0400 Subject: [PATCH 26/47] Implemented Automatic Versioning in Build Script 1. Changed build.gradle so that it edits the version numbers in mod_pocketDim.java and mcmod.info. 2. Changed mod_pocketDim to use a placeholder for its version number and fixed an annotation that was wrong. It would cause our mod_pocketDim instance to not initialize properly. I removed what seemed to be workarounds that were hiding the problem. 3. Fixed space in TileEntityDimDoor.invalidate() and corrected a non-static access to a static field in mod_pocketDim. 4. Changed mcmod.info so that it users placeholders for the mod version and MC version values. --- build.gradle | 12 ++++----- .../mod_pocketDim/mod_pocketDim.java | 7 +++-- .../tileentities/TileEntityDimDoor.java | 27 ++++++++++--------- src/main/resources/mcmod.info | 4 +-- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/build.gradle b/build.gradle index 6d68944..abc1771 100644 --- a/build.gradle +++ b/build.gradle @@ -13,10 +13,8 @@ buildscript { apply plugin: 'forge' - - version = "2.2.4-" + System.getenv("BUILD_NUMBER") -group= "com.stevenrs11.dimdoors" // http://maven.apache.org/guides/mini/guide-naming-conventions.html +group = "com.stevenrs11.dimdoors" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "DimensionalDoors" minecraft { @@ -28,17 +26,19 @@ sourceCompatibility = '1.6' processResources { - // replace stuff in mcmod.info, nothing else + // Replace stuff $version and $mcversion in mcmod.info and mod_pocketDim.java from(sourceSets.main.resources.srcDirs) { include 'mcmod.info' + include 'mod_pocketDim.java' - // replace version and mcversion + // Replace version and mcversion expand 'version':project.version, 'mcversion':project.minecraft.version } - // copy everything else, thats not the mcmod.info + // Copy everything else from(sourceSets.main.resources.srcDirs) { exclude 'mcmod.info' + exclude 'mod_pocketDim.java' } } diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java b/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java index 62dd845..95dce46 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java @@ -97,7 +97,7 @@ serverPacketHandlerSpec = @SidedPacketHandler(channels = {PacketConstants.CHANNEL_NAME}, packetHandler = ServerPacketHandler.class)) public class mod_pocketDim { - public static final String version = "1.6.4-R2.2.4"; + public static final String version = "$version"; public static final String modid = "dimdoors"; //TODO need a place to stick all these constants @@ -107,8 +107,8 @@ public class mod_pocketDim @SidedProxy(clientSide = "StevenDimDoors.mod_pocketDimClient.ClientProxy", serverSide = "StevenDimDoors.mod_pocketDim.CommonProxy") public static CommonProxy proxy; - @Instance("PocketDimensions") - public static mod_pocketDim instance = new mod_pocketDim(); + @Instance(mod_pocketDim.modid) + public static mod_pocketDim instance; public static Block transientDoor; public static Block warpDoor; @@ -169,7 +169,6 @@ public class mod_pocketDim @EventHandler public void onPreInitialization(FMLPreInitializationEvent event) { - instance = this; //This should be the FIRST thing that gets done. String path = event.getSuggestedConfigurationFile().getAbsolutePath().replace(modid, "DimDoors"); diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityDimDoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityDimDoor.java index 115aa64..fe478b6 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityDimDoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityDimDoor.java @@ -36,19 +36,20 @@ public class TileEntityDimDoor extends DDTileEntityBase } return null; } - - public void invalidate() - { - this.tileEntityInvalid = true; - - if(this.worldObj.getBlockId(xCoord, yCoord, zCoord)==0&&!this.worldObj.isRemote) - { - if(PocketManager.getLink(xCoord, yCoord, zCoord, worldObj)!=null) - { - mod_pocketDim.instance.fastRiftRegenerator.registerRiftForRegen(xCoord, yCoord, zCoord, this.worldObj.provider.dimensionId); - } - } - } + + @Override + public void invalidate() + { + this.tileEntityInvalid = true; + + if(this.worldObj.getBlockId(xCoord, yCoord, zCoord)==0&&!this.worldObj.isRemote) + { + if(PocketManager.getLink(xCoord, yCoord, zCoord, worldObj)!=null) + { + mod_pocketDim.fastRiftRegenerator.registerRiftForRegen(xCoord, yCoord, zCoord, this.worldObj.provider.dimensionId); + } + } + } @Override public void readFromNBT(NBTTagCompound nbt) diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index 92ac4ad..7a43be9 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -6,10 +6,10 @@ "modid": "dimdoors", "name": "Dimensional Doors", "description": "Bend and twist reality itself, creating pocket dimensions, rifts, and much more", -"version": "1.6.4-R2.2.4", +"version": "$version", "credits": "Created by StevenRS11, Coded by StevenRS11 and SenseiKiwi, Logo and Testing by Jaitsu", "logoFile": "/dimdoors_logo.png", -"mcversion": "", +"mcversion": "$mcversion", "url": "http://www.minecraftforum.net/topic/1650007-147smpssplan-dimensional-doors-v110-physics-what-physics-updated-with-fancy-opengl/", "updateUrl": "", "authors": [ "StevenRS11", "SenseiKiwi" ], From 1106319f8ca2b9c5d3accc2345b10d390b5d6b31 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Wed, 9 Jul 2014 04:15:37 -0400 Subject: [PATCH 27/47] Fixed build.gradle Fixed a mistake in specifying the path for mod_pocketDim.java. --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index abc1771..1dc1451 100644 --- a/build.gradle +++ b/build.gradle @@ -29,7 +29,7 @@ processResources // Replace stuff $version and $mcversion in mcmod.info and mod_pocketDim.java from(sourceSets.main.resources.srcDirs) { include 'mcmod.info' - include 'mod_pocketDim.java' + include 'StevenDimDoors/mod_pocketDim/mod_pocketDim.java' // Replace version and mcversion expand 'version':project.version, 'mcversion':project.minecraft.version @@ -38,7 +38,7 @@ processResources // Copy everything else from(sourceSets.main.resources.srcDirs) { exclude 'mcmod.info' - exclude 'mod_pocketDim.java' + exclude 'StevenDimDoors/mod_pocketDim/mod_pocketDim.java' } } From c4abae8fdd658567729a57ea940955c56abbeaca Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Wed, 9 Jul 2014 15:11:16 -0400 Subject: [PATCH 28/47] Fixed build.gradle (again) Made some more changes to build.gradle in the hopes that the version information will automatically update in mod_pocketDim.java. It has only worked on mcmod.info in previous attempts. --- build.gradle | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 1dc1451..1555934 100644 --- a/build.gradle +++ b/build.gradle @@ -18,7 +18,10 @@ group = "com.stevenrs11.dimdoors" // http://maven.apache.org/guides/mini/guide-n archivesBaseName = "DimensionalDoors" minecraft { - version = "1.6.4-9.11.1.964" + version = "1.6.4-9.11.1.964" + + replaceIn "mod_pocketDim.java" + replace "@VERSION@", project.version } targetCompatibility = '1.6' @@ -26,11 +29,10 @@ sourceCompatibility = '1.6' processResources { - // Replace stuff $version and $mcversion in mcmod.info and mod_pocketDim.java + // Replace stuff $version and $mcversion in mcmod.info from(sourceSets.main.resources.srcDirs) { include 'mcmod.info' - include 'StevenDimDoors/mod_pocketDim/mod_pocketDim.java' - + // Replace version and mcversion expand 'version':project.version, 'mcversion':project.minecraft.version } @@ -38,7 +40,6 @@ processResources // Copy everything else from(sourceSets.main.resources.srcDirs) { exclude 'mcmod.info' - exclude 'StevenDimDoors/mod_pocketDim/mod_pocketDim.java' } } From 83998969f623063c929ca4e2c5e143bc10e760b5 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Wed, 9 Jul 2014 15:14:56 -0400 Subject: [PATCH 29/47] Fixed Version in mod_pocketDim Forgot to change the placeholder in mod_pocketDim --- src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java b/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java index 95dce46..a044a06 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java @@ -97,7 +97,7 @@ serverPacketHandlerSpec = @SidedPacketHandler(channels = {PacketConstants.CHANNEL_NAME}, packetHandler = ServerPacketHandler.class)) public class mod_pocketDim { - public static final String version = "$version"; + public static final String version = "@VERSION@"; public static final String modid = "dimdoors"; //TODO need a place to stick all these constants From 8da0339c78a1d7b0198afd59557251a3121fa73f Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Wed, 9 Jul 2014 23:44:49 -0400 Subject: [PATCH 30/47] Improved DDTeleporter Made various changes to clarify code in DDTeleporter. For instance, we had a whole switch block that was used to give the same outcome on every case except the default. I rewrote the code there to remove the block. Also changed DDTeleporter.checkDestination() since it was redoing the destination orientation checks unnecessarily, changing the entity's yaw when it shouldn't have side effects, and some other little things. --- .../mod_pocketDim/core/DDTeleporter.java | 103 +++++++----------- 1 file changed, 37 insertions(+), 66 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java b/src/main/java/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java index f8f7bc1..debd31a 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java @@ -51,59 +51,49 @@ public class DDTeleporter private DDTeleporter() { } - /**Checks if the destination supplied is valid, ie, filled by any non-replaceable block. - * - * @param entity - * @param world - * @param destination - * @param properties - * @return + /** + * Checks if the destination supplied is safe (i.e. filled by any replaceable or non-opaque blocks) */ - private static boolean checkDestination(Entity entity, WorldServer world, Point4D destination,DDProperties properties) + private static boolean checkDestination(WorldServer world, Point4D destination, int orientation) { int x = destination.getX(); int y = destination.getY(); int z = destination.getZ(); int blockIDTop; - int blockIDBottom; - + int blockIDBottom; Point3D point; - - int orientation; - orientation = getDestinationOrientation(destination, properties); - entity.rotationYaw = (orientation * 90) + 90; switch (orientation) { case 0: - point = new Point3D(MathHelper.floor_double(x - 0.5), y - 1, MathHelper.floor_double(z + 0.5)); + point = new Point3D(x - 1, y - 1, z); break; case 1: - point = new Point3D(MathHelper.floor_double(x + 0.5), y - 1, MathHelper.floor_double(z - 0.5)); + point = new Point3D(x, y - 1, z - 1); break; case 2: - point = new Point3D(MathHelper.floor_double(x + 1.5), y - 1, MathHelper.floor_double(z + 0.5)); + point = new Point3D(x + 1, y - 1, z); break; case 3: - point = new Point3D(MathHelper.floor_double(x + 0.5), y - 1, MathHelper.floor_double(z + 1.5)); + point = new Point3D(x, y - 1, z + 1); break; default: point = new Point3D(x, y - 1, z); break; } blockIDBottom = world.getBlockId(point.getX(), point.getY(), point.getZ()); - blockIDTop = world.getBlockId(point.getX(), point.getY()+1, point.getZ()); + blockIDTop = world.getBlockId(point.getX(), point.getY() + 1, point.getZ()); if (Block.blocksList[blockIDBottom] != null) { - if(!Block.blocksList[blockIDBottom].isBlockReplaceable(world, point.getX(), point.getY(), point.getZ())&&world.isBlockOpaqueCube(point.getX(), point.getY(), point.getZ())) + if (!Block.blocksList[blockIDBottom].isBlockReplaceable(world, point.getX(), point.getY(), point.getZ()) && world.isBlockOpaqueCube(point.getX(), point.getY(), point.getZ())) { return false; } } if (Block.blocksList[blockIDTop] != null) { - if (!Block.blocksList[blockIDTop].isBlockReplaceable(world, point.getX(), point.getY()+1, point.getZ())) + if (!Block.blocksList[blockIDTop].isBlockReplaceable(world, point.getX(), point.getY() + 1, point.getZ())) { return false; } @@ -125,56 +115,37 @@ public class DDTeleporter } else { - //Teleport the entity to the precise destination point + // Teleport the entity to the precise destination point orientation = -1; } - if (!checkDestination(entity, world, destination, properties)) - { - if (entity instanceof EntityPlayerMP) - { - EntityPlayer player = (EntityPlayer) entity; - player.rotationYaw = (orientation * 90) + 90; - switch (orientation) - { - case 0: - player.setPositionAndUpdate(x + 0.5, y - 1, z + 0.5); - break; - case 1: - player.setPositionAndUpdate(x + 0.5, y - 1, z + 0.5); - break; - case 2: - player.setPositionAndUpdate(x + 0.5, y - 1, z + 0.5); - break; - case 3: - player.setPositionAndUpdate(x + 0.5, y - 1, z + 0.5); - break; - default: - player.setPositionAndUpdate(x, y - 1, z); - break; - } - } - } - else if (entity instanceof EntityPlayer) + if (entity instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) entity; - switch (orientation) + if (checkDestination(world, destination, orientation)) { - case 0: - player.setPositionAndUpdate(x - 0.5, y - 1, z + 0.5); - break; - case 1: - player.setPositionAndUpdate(x + 0.5, y - 1, z - 0.5); - break; - case 2: - player.setPositionAndUpdate(x + 1.5, y - 1, z + 0.5); - break; - case 3: - player.setPositionAndUpdate(x + 0.5, y - 1, z + 1.5); - break; - default: - player.setPositionAndUpdate(x + 0.5, y - 1, z + 0.5); - break; + switch (orientation) + { + case 0: + player.setPositionAndUpdate(x - 0.5, y - 1, z + 0.5); + break; + case 1: + player.setPositionAndUpdate(x + 0.5, y - 1, z - 0.5); + break; + case 2: + player.setPositionAndUpdate(x + 1.5, y - 1, z + 0.5); + break; + case 3: + player.setPositionAndUpdate(x + 0.5, y - 1, z + 1.5); + break; + default: + player.setPositionAndUpdate(x + 0.5, y - 1, z + 0.5); + break; + } + } + else + { + player.setPositionAndUpdate(x + 0.5, y - 1, z + 0.5); } } else if (entity instanceof EntityMinecart) @@ -200,7 +171,7 @@ public class DDTeleporter entity.worldObj.updateEntityWithOptionalForce(entity, false); break; case 3: - DDTeleporter.setEntityPosition(entity, x + 0.5, y, z + 1.5 ); + DDTeleporter.setEntityPosition(entity, x + 0.5, y, z + 1.5); entity.motionZ = 0.39; entity.worldObj.updateEntityWithOptionalForce(entity, false); break; From c22479c0e885dd1d02d3304289b1d0eb6b449f44 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 10 Jul 2014 08:28:42 -0400 Subject: [PATCH 31/47] Tick Handler Changes 1. Renamed CommonTickHandler to ServerTickHandler. Given that it only handles server ticks, this seems like a reasonable name. Also changed its profiler label to the new name. 2. Deleted ClientTickHandler and removed any references to it in mod_pocketDim. It was never used for anything. --- .../mod_pocketDim/mod_pocketDim.java | 6 +- ...ickHandler.java => ServerTickHandler.java} | 6 +- .../ClientTickHandler.java | 65 ------------------- 3 files changed, 5 insertions(+), 72 deletions(-) rename src/main/java/StevenDimDoors/mod_pocketDim/ticking/{CommonTickHandler.java => ServerTickHandler.java} (94%) delete mode 100644 src/main/java/StevenDimDoors/mod_pocketDimClient/ClientTickHandler.java diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java b/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java index a044a06..9468678 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java @@ -52,12 +52,12 @@ import StevenDimDoors.mod_pocketDim.items.ItemUnstableDoor; import StevenDimDoors.mod_pocketDim.items.ItemWarpDoor; import StevenDimDoors.mod_pocketDim.items.ItemWorldThread; import StevenDimDoors.mod_pocketDim.items.itemRiftRemover; -import StevenDimDoors.mod_pocketDim.ticking.CommonTickHandler; import StevenDimDoors.mod_pocketDim.ticking.CustomLimboPopulator; import StevenDimDoors.mod_pocketDim.ticking.FastRiftRegenerator; import StevenDimDoors.mod_pocketDim.ticking.LimboDecay; import StevenDimDoors.mod_pocketDim.ticking.MobMonolith; import StevenDimDoors.mod_pocketDim.ticking.RiftRegenerator; +import StevenDimDoors.mod_pocketDim.ticking.ServerTickHandler; import StevenDimDoors.mod_pocketDim.tileentities.TileEntityDimDoor; import StevenDimDoors.mod_pocketDim.tileentities.TileEntityDimDoorGold; import StevenDimDoors.mod_pocketDim.tileentities.TileEntityRift; @@ -69,7 +69,6 @@ import StevenDimDoors.mod_pocketDim.world.LimboProvider; import StevenDimDoors.mod_pocketDim.world.PocketProvider; import StevenDimDoors.mod_pocketDim.world.gateways.GatewayGenerator; import StevenDimDoors.mod_pocketDimClient.ClientPacketHandler; -import StevenDimDoors.mod_pocketDimClient.ClientTickHandler; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Instance; @@ -183,8 +182,7 @@ public class mod_pocketDim @EventHandler public void onInitialization(FMLInitializationEvent event) { - CommonTickHandler commonTickHandler = new CommonTickHandler(); - TickRegistry.registerTickHandler(new ClientTickHandler(), Side.CLIENT); + ServerTickHandler commonTickHandler = new ServerTickHandler(); TickRegistry.registerTickHandler(commonTickHandler, Side.SERVER); //MonolithSpawner should be initialized before any provider instances are created diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/ticking/CommonTickHandler.java b/src/main/java/StevenDimDoors/mod_pocketDim/ticking/ServerTickHandler.java similarity index 94% rename from src/main/java/StevenDimDoors/mod_pocketDim/ticking/CommonTickHandler.java rename to src/main/java/StevenDimDoors/mod_pocketDim/ticking/ServerTickHandler.java index 26057b4..2e2ccb1 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/ticking/CommonTickHandler.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/ticking/ServerTickHandler.java @@ -7,15 +7,15 @@ import StevenDimDoors.mod_pocketDim.core.DDTeleporter; import cpw.mods.fml.common.ITickHandler; import cpw.mods.fml.common.TickType; -public class CommonTickHandler implements ITickHandler, IRegularTickSender +public class ServerTickHandler implements ITickHandler, IRegularTickSender { - private static final String PROFILING_LABEL = "Dimensional Doors: Common Tick"; + private static final String PROFILING_LABEL = "Dimensional Doors: Server Tick"; private int tickCount = 0; private ArrayList receivers; - public CommonTickHandler() + public ServerTickHandler() { this.receivers = new ArrayList(); } diff --git a/src/main/java/StevenDimDoors/mod_pocketDimClient/ClientTickHandler.java b/src/main/java/StevenDimDoors/mod_pocketDimClient/ClientTickHandler.java deleted file mode 100644 index cece273..0000000 --- a/src/main/java/StevenDimDoors/mod_pocketDimClient/ClientTickHandler.java +++ /dev/null @@ -1,65 +0,0 @@ -package StevenDimDoors.mod_pocketDimClient; -import java.util.EnumSet; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiScreen; -import cpw.mods.fml.common.ITickHandler; -import cpw.mods.fml.common.TickType; - -public class ClientTickHandler implements ITickHandler -{ - - @Override - public void tickStart(EnumSet type, Object... tickData) {} - - @Override - public void tickEnd(EnumSet type, Object... tickData) - { - if (type.equals(EnumSet.of(TickType.RENDER))) - { - onRenderTick(); - } - else if (type.equals(EnumSet.of(TickType.CLIENT))) - { - GuiScreen guiscreen = Minecraft.getMinecraft().currentScreen; - if (guiscreen != null) - { - onTickInGUI(guiscreen); - } else { - onTickInGame(); - } - } - } - - @Override - public EnumSet ticks() - { - return EnumSet.of(TickType.RENDER, TickType.CLIENT); - // In my testing only RENDER, CLIENT, & PLAYER did anything on the client side. - // Read 'cpw.mods.fml.common.TickType.java' for a full list and description of available types - } - - @Override - public String getLabel() { return null; } - - - public void onRenderTick() - { - //System.out.println("onRenderTick"); - //TODO: Your Code Here - } - - public void onTickInGUI(GuiScreen guiscreen) - { - //System.out.println("onTickInGUI"); - //TODO: Your Code Here - } - - public void onTickInGame() - { - - - //System.out.println("onTickInGame"); - //TODO: Your Code Here - } -} \ No newline at end of file From c00c65eeee2493c1fe47bd8cdedbddb7a042526e Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 10 Jul 2014 15:11:44 -0400 Subject: [PATCH 32/47] Reorganized Tick Receivers 1. Reorganized our code to initialize tick receivers each time the server starts rather than once when the mod is initialized. This is needed because reusing a single instance of each class across different single-player sessions could cause scheduled events for one world to leak into another world. This approach ensures that we discard all pending events. 2. Separated the implementation of Limbo decay from a tick receiver that periodically triggers fast decay. All of the decay code has been kept in LimboDecay, while the ticking is handled by LimboDecayScheduler. This change separates some functionality that should be independent, but also, it's needed so that BlockLimbo can have access to LimboDecay's methods without holding on to a tick receiver instance. 3. Minor change: renamed ChunkLoaderHelper.loadChunkForcedWorlds() to loadForcedChunkWorlds(). --- .../mod_pocketDim/blocks/BlockLimbo.java | 2 +- .../helpers/ChunkLoaderHelper.java | 2 +- .../mod_pocketDim/mod_pocketDim.java | 42 ++++++++++++------- .../ticking/CustomLimboPopulator.java | 2 +- .../ticking/FastRiftRegenerator.java | 3 +- .../ticking/IRegularTickSender.java | 3 +- .../ticking/LimboDecayScheduler.java | 28 +++++++++++++ .../ticking/RiftRegenerator.java | 2 +- .../ticking/ServerTickHandler.java | 9 +++- .../{ticking => world}/LimboDecay.java | 19 ++------- 10 files changed, 75 insertions(+), 37 deletions(-) create mode 100644 src/main/java/StevenDimDoors/mod_pocketDim/ticking/LimboDecayScheduler.java rename src/main/java/StevenDimDoors/mod_pocketDim/{ticking => world}/LimboDecay.java (91%) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockLimbo.java b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockLimbo.java index 8da0dfe..07f1247 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockLimbo.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockLimbo.java @@ -9,7 +9,7 @@ import net.minecraft.util.Icon; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.ticking.LimboDecay; +import StevenDimDoors.mod_pocketDim.world.LimboDecay; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/helpers/ChunkLoaderHelper.java b/src/main/java/StevenDimDoors/mod_pocketDim/helpers/ChunkLoaderHelper.java index e866ec4..6483afd 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/helpers/ChunkLoaderHelper.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/helpers/ChunkLoaderHelper.java @@ -83,7 +83,7 @@ public class ChunkLoaderHelper implements LoadingCallback } } - public static void loadChunkForcedWorlds(FMLServerStartingEvent event) + public static void loadForcedChunkWorlds(FMLServerStartingEvent event) { for (NewDimData data : PocketManager.getDimensions()) { diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java b/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java index 9468678..8329d25 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java @@ -54,7 +54,7 @@ import StevenDimDoors.mod_pocketDim.items.ItemWorldThread; import StevenDimDoors.mod_pocketDim.items.itemRiftRemover; import StevenDimDoors.mod_pocketDim.ticking.CustomLimboPopulator; import StevenDimDoors.mod_pocketDim.ticking.FastRiftRegenerator; -import StevenDimDoors.mod_pocketDim.ticking.LimboDecay; +import StevenDimDoors.mod_pocketDim.ticking.LimboDecayScheduler; import StevenDimDoors.mod_pocketDim.ticking.MobMonolith; import StevenDimDoors.mod_pocketDim.ticking.RiftRegenerator; import StevenDimDoors.mod_pocketDim.ticking.ServerTickHandler; @@ -65,6 +65,7 @@ import StevenDimDoors.mod_pocketDim.tileentities.TileEntityTransTrapdoor; import StevenDimDoors.mod_pocketDim.world.BiomeGenLimbo; import StevenDimDoors.mod_pocketDim.world.BiomeGenPocket; import StevenDimDoors.mod_pocketDim.world.DDBiomeGenBase; +import StevenDimDoors.mod_pocketDim.world.LimboDecay; import StevenDimDoors.mod_pocketDim.world.LimboProvider; import StevenDimDoors.mod_pocketDim.world.PocketProvider; import StevenDimDoors.mod_pocketDim.world.gateways.GatewayGenerator; @@ -142,9 +143,13 @@ public class mod_pocketDim public static DDProperties properties; public static DDWorldProperties worldProperties; public static CustomLimboPopulator spawner; //Added this field temporarily. Will be refactored out later. + private static RiftRegenerator riftRegenerator; public static FastRiftRegenerator fastRiftRegenerator; public static GatewayGenerator gatewayGenerator; public static DeathTracker deathTracker; + private static ServerTickHandler serverTickHandler; + private static LimboDecayScheduler limboDecayScheduler; + private static LimboDecay limboDecay; private static EventHookContainer hooks; //TODO this is a temporary workaround for saving data @@ -182,16 +187,14 @@ public class mod_pocketDim @EventHandler public void onInitialization(FMLInitializationEvent event) { - ServerTickHandler commonTickHandler = new ServerTickHandler(); - TickRegistry.registerTickHandler(commonTickHandler, Side.SERVER); - - //MonolithSpawner should be initialized before any provider instances are created - //Register the other regular tick receivers as well - spawner = new CustomLimboPopulator(commonTickHandler, properties); - new RiftRegenerator(commonTickHandler); //No need to store the reference - LimboDecay decay = new LimboDecay(commonTickHandler, properties); - fastRiftRegenerator = new FastRiftRegenerator(commonTickHandler); + // Initialize ServerTickHandler instance + serverTickHandler = new ServerTickHandler(); + TickRegistry.registerTickHandler(serverTickHandler, Side.SERVER); + + // Initialize LimboDecay instance: required for BlockLimbo + limboDecay = new LimboDecay(properties); + // Initialize blocks and items transientDoor = new TransientDoor(properties.TransientDoorID, Material.iron, properties).setHardness(1.0F) .setUnlocalizedName("transientDoor"); goldenDimensionalDoor = new BlockGoldDimDoor(properties.GoldenDimensionalDoorID, Material.iron, properties).setHardness(1.0F) .setUnlocalizedName("dimDoorGold"); @@ -200,7 +203,7 @@ public class mod_pocketDim blockDimWallPerm = (new BlockDimWallPerm(properties.PermaFabricBlockID, 0, Material.iron)).setLightValue(1.0F).setBlockUnbreakable().setResistance(6000000.0F).setUnlocalizedName("blockDimWallPerm"); warpDoor = new WarpDoor(properties.WarpDoorID, Material.wood, properties).setHardness(1.0F) .setUnlocalizedName("dimDoorWarp"); blockRift = (BlockRift) (new BlockRift(properties.RiftBlockID, 0, Material.air, properties).setHardness(1.0F) .setUnlocalizedName("rift")); - blockLimbo = new BlockLimbo(properties.LimboBlockID, 15, Material.iron, properties.LimboDimensionID, decay).setHardness(.2F).setUnlocalizedName("BlockLimbo").setLightValue(.0F); + blockLimbo = new BlockLimbo(properties.LimboBlockID, 15, Material.iron, properties.LimboDimensionID, limboDecay).setHardness(.2F).setUnlocalizedName("BlockLimbo").setLightValue(.0F); unstableDoor = (new UnstableDoor(properties.UnstableDoorID, Material.iron, properties).setHardness(.2F).setUnlocalizedName("chaosDoor").setLightValue(.0F) ); dimensionalDoor = (DimensionalDoor) (new DimensionalDoor(properties.DimensionalDoorID, Material.iron, properties).setHardness(1.0F).setResistance(2000.0F) .setUnlocalizedName("dimDoor")); transTrapdoor = (TransTrapdoor) (new TransTrapdoor(properties.TransTrapdoorID, Material.wood).setHardness(1.0F) .setUnlocalizedName("dimHatch")); @@ -317,7 +320,11 @@ public class mod_pocketDim deathTracker.writeToFile(); deathTracker = null; worldProperties = null; - this.currrentSaveRootDirectory=null; + currrentSaveRootDirectory = null; + + // Unregister all tick receivers from serverTickHandler to avoid leaking + // scheduled tasks between single-player game sessions + serverTickHandler.unregisterReceivers(); } catch (Exception e) { @@ -333,9 +340,16 @@ public class mod_pocketDim // Load the config file that's specific to this world worldProperties = new DDWorldProperties(new File(currrentSaveRootDirectory + "/DimensionalDoors/DimDoorsWorld.cfg")); hooks.setWorldProperties(worldProperties); - + // Initialize a new DeathTracker deathTracker = new DeathTracker(currrentSaveRootDirectory + "/DimensionalDoors/data/deaths.txt"); + + // Register regular tick receivers + // CustomLimboPopulator should be initialized before any provider instances are created + spawner = new CustomLimboPopulator(serverTickHandler, properties); + riftRegenerator = new RiftRegenerator(serverTickHandler); + limboDecayScheduler = new LimboDecayScheduler(serverTickHandler, limboDecay); + fastRiftRegenerator = new FastRiftRegenerator(serverTickHandler); } @EventHandler @@ -353,7 +367,7 @@ public class mod_pocketDim try { - ChunkLoaderHelper.loadChunkForcedWorlds(event); + ChunkLoaderHelper.loadForcedChunkWorlds(event); } catch (Exception e) { diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/ticking/CustomLimboPopulator.java b/src/main/java/StevenDimDoors/mod_pocketDim/ticking/CustomLimboPopulator.java index ddc018c..231eec2 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/ticking/CustomLimboPopulator.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/ticking/CustomLimboPopulator.java @@ -30,7 +30,7 @@ public class CustomLimboPopulator implements IRegularTickReceiver { { this.properties = properties; this.locations = new ConcurrentLinkedQueue(); - sender.registerForTicking(this, MONOLITH_SPAWNING_INTERVAL, false); + sender.registerReceiver(this, MONOLITH_SPAWNING_INTERVAL, false); } @Override diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/ticking/FastRiftRegenerator.java b/src/main/java/StevenDimDoors/mod_pocketDim/ticking/FastRiftRegenerator.java index b0f203f..e680b2a 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/ticking/FastRiftRegenerator.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/ticking/FastRiftRegenerator.java @@ -20,7 +20,7 @@ public class FastRiftRegenerator implements IRegularTickReceiver { public FastRiftRegenerator(IRegularTickSender sender) { - sender.registerForTicking(this, RIFT_REGENERATION_INTERVAL, false); + sender.registerReceiver(this, RIFT_REGENERATION_INTERVAL, false); } @Override @@ -33,6 +33,7 @@ public class FastRiftRegenerator implements IRegularTickReceiver { { if (!locationsToRegen.isEmpty()) { + @SuppressWarnings("cast") List loadedWorlds = (List) Arrays.asList(DimensionManager.getIDs()); for (Point4D point: locationsToRegen) { diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/ticking/IRegularTickSender.java b/src/main/java/StevenDimDoors/mod_pocketDim/ticking/IRegularTickSender.java index 6ed2dca..7b5502c 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/ticking/IRegularTickSender.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/ticking/IRegularTickSender.java @@ -3,6 +3,7 @@ package StevenDimDoors.mod_pocketDim.ticking; public interface IRegularTickSender { - public void registerForTicking(IRegularTickReceiver receiver, int interval, boolean onTickStart); + public void registerReceiver(IRegularTickReceiver receiver, int interval, boolean onTickStart); + public void unregisterReceivers(); } diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/ticking/LimboDecayScheduler.java b/src/main/java/StevenDimDoors/mod_pocketDim/ticking/LimboDecayScheduler.java new file mode 100644 index 0000000..73f275c --- /dev/null +++ b/src/main/java/StevenDimDoors/mod_pocketDim/ticking/LimboDecayScheduler.java @@ -0,0 +1,28 @@ +package StevenDimDoors.mod_pocketDim.ticking; + +import StevenDimDoors.mod_pocketDim.world.LimboDecay; + +/** + * Handles scheduling of periodic fast Limbo decay operations. + */ +public class LimboDecayScheduler implements IRegularTickReceiver { + + private static final int LIMBO_DECAY_INTERVAL = 10; //Apply fast decay every 10 ticks + + private LimboDecay decay; + + public LimboDecayScheduler(IRegularTickSender tickSender, LimboDecay decay) + { + this.decay = decay; + tickSender.registerReceiver(this, LIMBO_DECAY_INTERVAL, false); + } + + /** + * Applies fast Limbo decay periodically. + */ + @Override + public void notifyTick() + { + decay.applyRandomFastDecay(); + } +} diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java b/src/main/java/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java index 192669c..23b0f9b 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java @@ -20,7 +20,7 @@ public class RiftRegenerator implements IRegularTickReceiver { public RiftRegenerator(IRegularTickSender sender) { - sender.registerForTicking(this, RIFT_REGENERATION_INTERVAL, false); + sender.registerReceiver(this, RIFT_REGENERATION_INTERVAL, false); } @Override diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/ticking/ServerTickHandler.java b/src/main/java/StevenDimDoors/mod_pocketDim/ticking/ServerTickHandler.java index 2e2ccb1..58da365 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/ticking/ServerTickHandler.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/ticking/ServerTickHandler.java @@ -14,18 +14,23 @@ public class ServerTickHandler implements ITickHandler, IRegularTickSender private int tickCount = 0; private ArrayList receivers; - public ServerTickHandler() { this.receivers = new ArrayList(); } @Override - public void registerForTicking(IRegularTickReceiver receiver, int interval, boolean onTickStart) + public void registerReceiver(IRegularTickReceiver receiver, int interval, boolean onTickStart) { RegularTickReceiverInfo info = new RegularTickReceiverInfo(receiver, interval, onTickStart); receivers.add(info); } + + @Override + public void unregisterReceivers() + { + receivers.clear(); + } @Override public void tickStart(EnumSet type, Object... tickData) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/ticking/LimboDecay.java b/src/main/java/StevenDimDoors/mod_pocketDim/world/LimboDecay.java similarity index 91% rename from src/main/java/StevenDimDoors/mod_pocketDim/ticking/LimboDecay.java rename to src/main/java/StevenDimDoors/mod_pocketDim/world/LimboDecay.java index e5c9420..13edb19 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/ticking/LimboDecay.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/world/LimboDecay.java @@ -1,4 +1,4 @@ -package StevenDimDoors.mod_pocketDim.ticking; +package StevenDimDoors.mod_pocketDim.world; import java.util.Random; @@ -13,13 +13,12 @@ import StevenDimDoors.mod_pocketDim.config.DDProperties; * Provides methods for applying Limbo decay. Limbo decay refers to the effect that most blocks placed in Limbo * naturally change into stone, then cobble, then gravel, and finally Unraveled Fabric as time passes. */ -public class LimboDecay implements IRegularTickReceiver { +public class LimboDecay { private static final int MAX_DECAY_SPREAD_CHANCE = 100; private static final int DECAY_SPREAD_CHANCE = 50; private static final int CHUNK_SIZE = 16; private static final int SECTION_HEIGHT = 16; - private static final int LIMBO_DECAY_INTERVAL = 10; //Apply spread decay every 10 ticks //Provides a reversed list of the block IDs that blocks cycle through during decay. private final int[] decaySequence; @@ -28,7 +27,7 @@ public class LimboDecay implements IRegularTickReceiver { private final DDProperties properties; private final int[] blocksImmuneToDecay; - public LimboDecay(IRegularTickSender tickSender, DDProperties properties) + public LimboDecay(DDProperties properties) { decaySequence = new int[] { properties.LimboBlockID, @@ -51,16 +50,6 @@ public class LimboDecay implements IRegularTickReceiver { this.properties = properties; this.random = new Random(); - tickSender.registerForTicking(this, LIMBO_DECAY_INTERVAL, false); - } - - /** - * Applies fast Limbo decay periodically. - */ - @Override - public void notifyTick() - { - applyRandomFastDecay(); } /** @@ -88,7 +77,7 @@ public class LimboDecay implements IRegularTickReceiver { * Picks random blocks from each active chunk in Limbo and, if decay is applicable, converts them directly to Unraveled Fabric. * This decay method is designed to stop players from avoiding Limbo decay by building floating structures. */ - private void applyRandomFastDecay() + public void applyRandomFastDecay() { int x, y, z; int sectionY; From 782c6d5e50f18b07abaeb2ae1b8547c923bf5b7c Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 10 Jul 2014 17:13:10 -0400 Subject: [PATCH 33/47] Minor Changes to NewDimData Made some minor changes to NewDimData. Fixed some comments for the rift search functions that incorrectly indicated the search would not detect rifts adjacent to the center of the search range. That behavior changed some time ago. Also added an unused field called "chunkMapping" for associating chunks with lists of links. It'll be used for implementing queuing of rift regeneration when chunks load. --- .../mod_pocketDim/core/NewDimData.java | 47 +++++++++---------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/core/NewDimData.java b/src/main/java/StevenDimDoors/mod_pocketDim/core/NewDimData.java index 326b7d4..5d7e50a 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/core/NewDimData.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/core/NewDimData.java @@ -7,13 +7,14 @@ import java.util.Random; import java.util.Stack; import java.util.TreeMap; -import StevenDimDoors.mod_pocketDim.watcher.ClientLinkData; +import net.minecraft.world.ChunkCoordIntPair; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.Point3D; import StevenDimDoors.mod_pocketDim.config.DDProperties; import StevenDimDoors.mod_pocketDim.dungeon.DungeonData; import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonPack; import StevenDimDoors.mod_pocketDim.util.Point4D; +import StevenDimDoors.mod_pocketDim.watcher.ClientLinkData; import StevenDimDoors.mod_pocketDim.watcher.IUpdateWatcher; public abstract class NewDimData @@ -134,6 +135,9 @@ public abstract class NewDimData protected boolean modified; public IUpdateWatcher linkWatcher; + // Don't write this field to a file - it should be recreated on startup + private Map> chunkMapping; + protected NewDimData(int id, NewDimData parent, boolean isPocket, boolean isDungeon, IUpdateWatcher linkWatcher) { @@ -204,23 +208,20 @@ public abstract class NewDimData public DimLink findNearestRift(World world, int range, int x, int y, int z) { - //TODO: Rewrite this later to use an octtree - - //Sanity check... + // Sanity check... if (world.provider.dimensionId != id) { throw new IllegalArgumentException("Attempted to search for links in a World instance for a different dimension!"); } - //Note: Only detect rifts at a distance > 1, so we ignore the rift - //that called this function and any adjacent rifts. - - DimLink nearest = null; + // Note: Only detect rifts at a distance > 0, so we ignore the rift + // at the center of the search space. DimLink link; - + DimLink nearest = null; + + int i, j, k; int distance; int minDistance = Integer.MAX_VALUE; - int i, j, k; DDProperties properties = DDProperties.instance(); for (i = -range; i <= range; i++) @@ -232,7 +233,7 @@ public abstract class NewDimData distance = getAbsoluteSum(i, j, k); if (distance > 0 && distance < minDistance && world.getBlockId(x + i, y + j, z + k) == properties.RiftBlockID) { - link = getLink(x+i, y+j, z+k); + link = getLink(x + i, y + j, z + k); if (link != null) { nearest = link; @@ -248,24 +249,20 @@ public abstract class NewDimData public ArrayList findRiftsInRange(World world, int range, int x, int y, int z) { - ArrayList links = new ArrayList(); - //TODO: Rewrite this later to use an octtree - - //Sanity check... + // Sanity check... if (world.provider.dimensionId != id) { throw new IllegalArgumentException("Attempted to search for links in a World instance for a different dimension!"); } - - //Note: Only detect rifts at a distance > 1, so we ignore the rift - //that called this function and any adjacent rifts. - - DimLink link; - - int distance; - int i, j, k; - DDProperties properties = DDProperties.instance(); + // Note: Only detect rifts at a distance > 0, so we ignore the rift + // at the center of the search space. + int i, j, k; + int distance; + DimLink link; + DDProperties properties = DDProperties.instance(); + ArrayList links = new ArrayList(); + for (i = -range; i <= range; i++) { for (j = -range; j <= range; j++) @@ -275,7 +272,7 @@ public abstract class NewDimData distance = getAbsoluteSum(i, j, k); if (distance > 0 && world.getBlockId(x + i, y + j, z + k) == properties.RiftBlockID) { - link = getLink(x+i, y+j, z+k); + link = getLink(x + i, y + j, z + k); if (link != null) { links.add(link); From 85ff28298ebddd8a9e2bc003ba3838f788d0cc40 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 10 Jul 2014 18:21:10 -0400 Subject: [PATCH 34/47] Implemented Chunk-Links Mapping Implemented support for tracking the list of links in each chunk in a dimension. This will be used for scheduling rift regeneration when chunks load. --- .../mod_pocketDim/core/DimLink.java | 7 +- .../mod_pocketDim/core/NewDimData.java | 70 ++++++++++++++++--- 2 files changed, 68 insertions(+), 9 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/core/DimLink.java b/src/main/java/StevenDimDoors/mod_pocketDim/core/DimLink.java index 8b0e3d8..409b815 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/core/DimLink.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/core/DimLink.java @@ -3,6 +3,7 @@ package StevenDimDoors.mod_pocketDim.core; import java.util.LinkedList; import java.util.List; +import net.minecraft.world.ChunkCoordIntPair; import StevenDimDoors.mod_pocketDim.util.Point4D; import StevenDimDoors.mod_pocketDim.watcher.ClientLinkData; @@ -15,7 +16,6 @@ public abstract class DimLink protected DimLink(ClientLinkData link, DimLink parent) { - if (parent.link.point.getDimension() != link.point.getDimension()) { // Ban having children in other dimensions to avoid serialization issues with cross-dimensional tails @@ -95,6 +95,11 @@ public abstract class DimLink { return tail.getLinkType(); } + + public ChunkCoordIntPair getChunkCoordinates() + { + return new ChunkCoordIntPair(link.point.getX() >> 4, link.point.getZ() >> 4); + } @Override public String toString() diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/core/NewDimData.java b/src/main/java/StevenDimDoors/mod_pocketDim/core/NewDimData.java index 5d7e50a..5045b9d 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/core/NewDimData.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/core/NewDimData.java @@ -1,6 +1,7 @@ package StevenDimDoors.mod_pocketDim.core; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Random; @@ -117,6 +118,8 @@ public abstract class NewDimData } } + private static int EXPECTED_LINKS_PER_CHUNK = 2; + protected static Random random = new Random(); protected int id; @@ -163,6 +166,7 @@ public abstract class NewDimData this.origin = null; this.dungeon = null; this.linkWatcher = linkWatcher; + this.chunkMapping = new HashMap>(); this.modified = true; //Register with parent @@ -203,6 +207,7 @@ public abstract class NewDimData this.linkWatcher = null; this.depth = 0; this.root = root; + this.chunkMapping = null; } @@ -297,13 +302,26 @@ public abstract class NewDimData public DimLink createLink(Point4D source, int linkType, int orientation) { - //Return an existing link if there is one to avoid creating multiple links starting at the same point. + // Return an existing link if there is one to avoid creating multiple links starting at the same point. InnerDimLink link = linkMapping.get(source); if (link == null) { link = new InnerDimLink(source, linkType, orientation); linkMapping.put(source, link); linkList.add(link); + + // If this code is running on the server side, add this link to chunkMapping. + if (linkType != LinkTypes.CLIENT_SIDE) + { + ChunkCoordIntPair chunk = link.getChunkCoordinates(); + List chunkLinks = chunkMapping.get(chunk); + if (chunkLinks == null) + { + chunkLinks = new ArrayList(EXPECTED_LINKS_PER_CHUNK); + chunkMapping.put(chunk, chunkLinks); + } + chunkLinks.add(link); + } } else { @@ -311,7 +329,7 @@ public abstract class NewDimData } modified = true; - //Link created! + // Link created! if (linkType != LinkTypes.CLIENT_SIDE) { linkWatcher.onCreated(link.link); @@ -331,8 +349,8 @@ public abstract class NewDimData private DimLink createChildLink(Point4D source, InnerDimLink parent) { - //To avoid having multiple links at a single point, if we find an existing link then we overwrite - //its destination data instead of creating a new instance. + // To avoid having multiple links at a single point, if we find an existing link then we overwrite + // its destination data instead of creating a new instance. InnerDimLink link = linkMapping.get(source); if (link == null) @@ -341,14 +359,28 @@ public abstract class NewDimData linkMapping.put(source, link); linkList.add(link); - //Link created! + // If this code is running on the server side, add this link to chunkMapping. + // Granted, the client side code should never create child links anyway... + if (link.linkType() != LinkTypes.CLIENT_SIDE) + { + ChunkCoordIntPair chunk = link.getChunkCoordinates(); + List chunkLinks = chunkMapping.get(chunk); + if (chunkLinks == null) + { + chunkLinks = new ArrayList(EXPECTED_LINKS_PER_CHUNK); + chunkMapping.put(chunk, chunkLinks); + } + chunkLinks.add(link); + } + + // Link created! linkWatcher.onCreated(link.link); } else { if (link.overwrite(parent, parent.link.orientation)) { - //Link created! + // Link created! linkWatcher.onCreated(link.link); } } @@ -366,7 +398,19 @@ public abstract class NewDimData if (target != null) { linkList.remove(target); - //Raise deletion event + + // If this code is running on the server side, remove this link to chunkMapping. + if (link.linkType() != LinkTypes.CLIENT_SIDE) + { + ChunkCoordIntPair chunk = target.getChunkCoordinates(); + List chunkLinks = chunkMapping.get(chunk); + if (chunkLinks != null) + { + chunkLinks.remove(target); + } + } + + // Raise deletion event linkWatcher.onDeleted(target.link); target.clear(); modified = true; @@ -388,7 +432,7 @@ public abstract class NewDimData public DimLink getLink(Point3D location) { - return linkMapping.get(new Point4D(location.getX(),location.getY(),location.getZ(),this.id)); + return linkMapping.get(new Point4D(location.getX(), location.getY(), location.getZ(), this.id)); } public DimLink getLink(Point4D location) @@ -618,6 +662,16 @@ public abstract class NewDimData return linkList.get(0); } + public Iterable getChunkLinks(int chunkX, int chunkZ) + { + List chunkLinks = chunkMapping.get(new ChunkCoordIntPair(chunkX, chunkZ)); + if (chunkLinks != null) + { + return chunkLinks; + } + return new ArrayList(0); + } + public boolean isModified() { return modified; From b197237dfd3fb82a2c57bdbe3b27e3cc7511ee60 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 10 Jul 2014 18:25:41 -0400 Subject: [PATCH 35/47] Minor Change Rewrote the NewDimData.deleteLink() version that would accept x, y, and z as parameters. There was some redundant code for getting the parameters from a Point4D instance just to create another one to find the target link. Now we pass the source point in directly. --- .../java/StevenDimDoors/mod_pocketDim/core/NewDimData.java | 3 +-- .../StevenDimDoors/mod_pocketDim/core/PocketManager.java | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/core/NewDimData.java b/src/main/java/StevenDimDoors/mod_pocketDim/core/NewDimData.java index 5045b9d..9a8a0b5 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/core/NewDimData.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/core/NewDimData.java @@ -418,9 +418,8 @@ public abstract class NewDimData return (target != null); } - public boolean deleteLink(int x, int y, int z) + public boolean deleteLink(Point4D location) { - Point4D location = new Point4D(x, y, z, id); return this.deleteLink(this.getLink(location)); } diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java b/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java index 5a1f1d6..1939e1d 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java @@ -171,9 +171,8 @@ public class PocketManager public void onDeleted(ClientLinkData link) { Point4D source = link.point; - NewDimData dimension = getDimensionData(source.getDimension()); - dimension.deleteLink(source.getX(), source.getY(), source.getZ()); - } + getDimensionData(source.getDimension()).deleteLink(source); + } } private static class ClientDimWatcher implements IUpdateWatcher From 79bd5102bad6ea88a5b92f5d166b8f4f3a4748a0 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 10 Jul 2014 18:29:48 -0400 Subject: [PATCH 36/47] Minor Changes Minor changes to DimLink to simplify DimLink.getDestinationOrientation() and to clarify the output of DimLink.toString() when no destination is available. --- .../StevenDimDoors/mod_pocketDim/core/DimLink.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/core/DimLink.java b/src/main/java/StevenDimDoors/mod_pocketDim/core/DimLink.java index 409b815..abfed4d 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/core/DimLink.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/core/DimLink.java @@ -63,12 +63,12 @@ public abstract class DimLink public int getDestinationOrientation() { - DimLink link = PocketManager.getLink(this.destination().getX(), this.destination().getY(), this.destination().getZ(), this.destination().getDimension()); - if(link !=null) + DimLink destinationLink = PocketManager.getLink(tail.getDestination()); + if (destinationLink != null) { - return link.orientation(); + return destinationLink.orientation(); } - return (this.orientation()+2)%4; + return (link.orientation + 2) % 4; } public boolean hasDestination() @@ -104,6 +104,6 @@ public abstract class DimLink @Override public String toString() { - return link.point + " -> " + (hasDestination() ? destination() : ""); + return link.point + " -> " + (hasDestination() ? destination() : "()"); } } From 1f59dc17d9b8e3f383f006c4a4493c1af0041b1d Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Fri, 11 Jul 2014 01:21:43 -0400 Subject: [PATCH 37/47] Implemented Scheduled Rift Regeneration 1. Implemented scheduled rift regeneration in RiftRegenerator. The previous randomized selection algorithm has been removed completely. All regeneration is scheduled now. We perform numerous checks to make sure that regenerating a rift is safe. 2. Removed FastRiftRegenerator as RiftRegenerator performs roughly the same task but with more flexibility. Updated TileEntityDimDoor to use RiftRegenerator instead for creating rifts when doors are broken. 3. Modified EventHookContainer to receive the chunk loaded event. We iterate over the list of links in a loaded chunk and schedule them for regeneration. 4. Reorganized the code in BlockRift. Divided the list of immune blocks into two lists - one for DD blocks and one for regular MC blocks. RiftRegenerator has to be able to distinguish between the two types. 5. Factored out some duplicate code from ItemRiftSignature and ItemStabilizedRiftSignature. Most of the block immunity checks were used to check if it would be safe to spawn a rift when using one of those items. BlockRift.tryPlacingRift() covers all that logic in a single function and makes the item code a little simpler. --- .../mod_pocketDim/EventHookContainer.java | 27 +++- .../mod_pocketDim/blocks/BlockRift.java | 64 ++++++---- .../items/ItemRiftSignature.java | 23 ++-- .../items/ItemStabilizedRiftSignature.java | 31 ++--- .../mod_pocketDim/mod_pocketDim.java | 13 +- .../ticking/FastRiftRegenerator.java | 54 -------- .../ticking/RiftRegenerator.java | 117 +++++++++++++----- .../mod_pocketDim/ticking/RiftTicket.java | 40 ++++++ .../tileentities/TileEntityDimDoor.java | 43 +++---- 9 files changed, 239 insertions(+), 173 deletions(-) delete mode 100644 src/main/java/StevenDimDoors/mod_pocketDim/ticking/FastRiftRegenerator.java create mode 100644 src/main/java/StevenDimDoors/mod_pocketDim/ticking/RiftTicket.java diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/EventHookContainer.java b/src/main/java/StevenDimDoors/mod_pocketDim/EventHookContainer.java index 1855963..9fd2d41 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/EventHookContainer.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/EventHookContainer.java @@ -8,6 +8,7 @@ import net.minecraft.item.ItemDoor; import net.minecraft.item.ItemStack; import net.minecraft.world.World; import net.minecraft.world.WorldProvider; +import net.minecraft.world.chunk.Chunk; import net.minecraftforge.client.event.sound.PlayBackgroundMusicEvent; import net.minecraftforge.client.event.sound.SoundLoadEvent; import net.minecraftforge.event.EventPriority; @@ -17,12 +18,16 @@ import net.minecraftforge.event.entity.living.LivingFallEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action; import net.minecraftforge.event.terraingen.InitMapGenEvent; +import net.minecraftforge.event.world.ChunkEvent; import net.minecraftforge.event.world.WorldEvent; import StevenDimDoors.mod_pocketDim.config.DDProperties; import StevenDimDoors.mod_pocketDim.config.DDWorldProperties; import StevenDimDoors.mod_pocketDim.core.DDTeleporter; +import StevenDimDoors.mod_pocketDim.core.DimLink; +import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.items.BaseItemDoor; +import StevenDimDoors.mod_pocketDim.ticking.RiftRegenerator; import StevenDimDoors.mod_pocketDim.util.Point4D; import StevenDimDoors.mod_pocketDim.world.LimboProvider; import StevenDimDoors.mod_pocketDim.world.PocketProvider; @@ -36,18 +41,20 @@ public class EventHookContainer private final DDProperties properties; private DDWorldProperties worldProperties; + private RiftRegenerator regenerator; public EventHookContainer(DDProperties properties) { this.properties = properties; } - public void setWorldProperties(DDWorldProperties worldProperties) + public void setSessionFields(DDWorldProperties worldProperties, RiftRegenerator regenerator) { // SenseiKiwi: - // Why have a setter rather than accessing mod_pocketDim.worldProperties? + // Why have a setter rather than accessing mod_pocketDim directly? // I want to make this dependency explicit in our code. this.worldProperties = worldProperties; + this.regenerator = regenerator; } @ForgeSubscribe(priority = EventPriority.LOW) @@ -217,6 +224,22 @@ public class EventHookContainer } } } + + @ForgeSubscribe + public void onChunkLoad(ChunkEvent.Load event) + { + // Schedule rift regeneration for any links located in this chunk. + // This event runs on both the client and server. Allow server only. + Chunk chunk = event.getChunk(); + if (!chunk.worldObj.isRemote) + { + NewDimData dimension = PocketManager.getDimensionData(chunk.worldObj); + for (DimLink link : dimension.getChunkLinks(chunk.xPosition, chunk.zPosition)) + { + regenerator.scheduleSlowRegeneration(link); + } + } + } public void playMusicForDim(World world) { diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java index ada00b6..78f666a 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java @@ -7,6 +7,7 @@ import java.util.Queue; import java.util.Random; import net.minecraft.block.Block; +import net.minecraft.block.BlockContainer; import net.minecraft.block.BlockFlowing; import net.minecraft.block.BlockFluid; import net.minecraft.block.ITileEntityProvider; @@ -47,25 +48,27 @@ public class BlockRift extends Block implements ITileEntityProvider public static final int MAX_WORLD_THREAD_DROP_CHANCE = 1000; private final DDProperties properties; - private final ArrayList blocksImmuneToRift; + private final ArrayList blocksImmuneToRift; // List of Vanilla blocks immune to rifts + private final ArrayList modBlocksImmuneToRift; // List of DD blocks immune to rifts public BlockRift(int i, int j, Material par2Material, DDProperties properties) { super(i, par2Material); this.setTickRandomly(true); this.properties = properties; + this.modBlocksImmuneToRift = new ArrayList(); + this.modBlocksImmuneToRift.add(properties.FabricBlockID); + this.modBlocksImmuneToRift.add(properties.PermaFabricBlockID); + this.modBlocksImmuneToRift.add(properties.DimensionalDoorID); + this.modBlocksImmuneToRift.add(properties.WarpDoorID); + this.modBlocksImmuneToRift.add(properties.TransTrapdoorID); + this.modBlocksImmuneToRift.add(properties.UnstableDoorID); + this.modBlocksImmuneToRift.add(properties.RiftBlockID); + this.modBlocksImmuneToRift.add(properties.TransientDoorID); + this.modBlocksImmuneToRift.add(properties.GoldenDimensionalDoorID); + this.modBlocksImmuneToRift.add(properties.GoldenDoorID); + this.blocksImmuneToRift = new ArrayList(); - this.blocksImmuneToRift.add(properties.FabricBlockID); - this.blocksImmuneToRift.add(properties.PermaFabricBlockID); - this.blocksImmuneToRift.add(properties.DimensionalDoorID); - this.blocksImmuneToRift.add(properties.WarpDoorID); - this.blocksImmuneToRift.add(properties.TransTrapdoorID); - this.blocksImmuneToRift.add(properties.UnstableDoorID); - this.blocksImmuneToRift.add(properties.RiftBlockID); - this.blocksImmuneToRift.add(properties.TransientDoorID); - this.blocksImmuneToRift.add(properties.GoldenDimensionalDoorID); - this.blocksImmuneToRift.add(properties.GoldenDoorID); - this.blocksImmuneToRift.add(Block.blockLapis.blockID); this.blocksImmuneToRift.add(Block.blockIron.blockID); this.blocksImmuneToRift.add(Block.blockGold.blockID); @@ -220,7 +223,7 @@ public class BlockRift extends Block implements ITileEntityProvider return targets; } - private void dropWorldThread(int blockID, World world, int x, int y, int z, Random random) + public void dropWorldThread(int blockID, World world, int x, int y, int z, Random random) { if (blockID != 0 && (random.nextInt(MAX_WORLD_THREAD_DROP_CHANCE) < properties.WorldThreadDropChance) && !(Block.blocksList[blockID] instanceof BlockFlowing || @@ -251,16 +254,6 @@ 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); - if (world.setBlock(x, y, z, properties.RiftBlockID)) - dropWorldThread(blockID, world, x, y, z, random); - } - } public boolean spreadRift(NewDimData dimension, DimLink parent, World world, Random random) { @@ -412,6 +405,15 @@ public class BlockRift extends Block implements ITileEntityProvider } } } + + public boolean tryPlacingRift(World world, int x, int y, int z) + { + if (world != null && !isBlockImmune(world, x, y, z)) + { + return world.setBlock(x, y, z, mod_pocketDim.blockRift.blockID); + } + return false; + } public boolean isBlockImmune(World world, int x, int y, int z) { @@ -424,7 +426,21 @@ public class BlockRift extends Block implements ITileEntityProvider // is designed to receive an entity, the source of the blast. We have no entity so // I've set this to access blockResistance directly. Might need changing later. - return (block.blockResistance >= MIN_IMMUNE_RESISTANCE || blocksImmuneToRift.contains(block.blockID)); + return (block.blockResistance >= MIN_IMMUNE_RESISTANCE || + modBlocksImmuneToRift.contains(block.blockID) || + blocksImmuneToRift.contains(block.blockID)); + } + return false; + } + + public boolean isModBlockImmune(World world, int x, int y, int z) + { + // Check whether the block at the specified location is one of the + // rift-resistant blocks from DD. + Block block = Block.blocksList[world.getBlockId(x, y, z)]; + if (block != null) + { + return modBlocksImmuneToRift.contains(block.blockID); } return false; } diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java index 9cc5053..84dbde6 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java @@ -71,7 +71,8 @@ public class ItemRiftSignature extends Item int orientation = MathHelper.floor_double(((player.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3; if (source != null) { - //The link was used before and already has an endpoint stored. Create links connecting the two endpoints. + // The link was used before and already has an endpoint stored. + // Create links connecting the two endpoints. NewDimData sourceDimension = PocketManager.getDimensionData(source.getDimension()); NewDimData destinationDimension = PocketManager.getDimensionData(world); DimLink link = sourceDimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.NORMAL,source.getOrientation()); @@ -79,27 +80,21 @@ public class ItemRiftSignature extends Item destinationDimension.setLinkDestination(link, x, adjustedY, z); sourceDimension.setLinkDestination(reverse, source.getX(), source.getY(), source.getZ()); - //Try placing a rift at the destination point - if (!mod_pocketDim.blockRift.isBlockImmune(world, x, adjustedY, z)) - { - world.setBlock(x, adjustedY, z, mod_pocketDim.blockRift.blockID); - } + // Try placing a rift at the destination point + mod_pocketDim.blockRift.tryPlacingRift(world, x, adjustedY, z); - //Try placing a rift at the source point, but check if its world is loaded first + // Try placing a rift at the source point + // We don't need to check if sourceWorld is null - that's already handled. World sourceWorld = DimensionManager.getWorld(sourceDimension.id()); - if (sourceWorld != null && - !mod_pocketDim.blockRift.isBlockImmune(sourceWorld, source.getX(), source.getY(), source.getZ())) - { - sourceWorld.setBlock(source.getX(), source.getY(), source.getZ(), mod_pocketDim.blockRift.blockID); - } + mod_pocketDim.blockRift.tryPlacingRift(sourceWorld, source.getX(), source.getY(), source.getZ()); if (!player.capabilities.isCreativeMode) { stack.stackSize--; } clearSource(stack); - mod_pocketDim.sendChat(player,("Rift Created")); - world.playSoundAtEntity(player,mod_pocketDim.modid+":riftEnd", 0.6f, 1); + mod_pocketDim.sendChat(player, "Rift Created"); + world.playSoundAtEntity(player, mod_pocketDim.modid + ":riftEnd", 0.6f, 1); } else { diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java index b47bff6..c06d598 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java @@ -90,19 +90,13 @@ public class ItemStabilizedRiftSignature extends ItemRiftSignature sourceDimension.setLinkDestination(reverse, source.getX(), source.getY(), source.getZ()); // Try placing a rift at the destination point - if (!mod_pocketDim.blockRift.isBlockImmune(world, x, adjustedY, z)) - { - world.setBlock(x, adjustedY, z, mod_pocketDim.blockRift.blockID); - } + mod_pocketDim.blockRift.tryPlacingRift(world, x, adjustedY, z); } - - // Try placing a rift at the source point, but check if its world is loaded first + + // Try placing a rift at the source point + // We don't need to check if sourceWorld is null - that's already handled. World sourceWorld = DimensionManager.getWorld(sourceDimension.id()); - if (sourceWorld != null && - !mod_pocketDim.blockRift.isBlockImmune(sourceWorld, source.getX(), source.getY(), source.getZ())) - { - sourceWorld.setBlock(source.getX(), source.getY(), source.getZ(), mod_pocketDim.blockRift.blockID); - } + mod_pocketDim.blockRift.tryPlacingRift(sourceWorld, source.getX(), source.getY(), source.getZ()); mod_pocketDim.sendChat(player, "Rift Created"); world.playSoundAtEntity(player, "mods.DimDoors.sfx.riftEnd", 0.6f, 1); @@ -111,8 +105,8 @@ public class ItemStabilizedRiftSignature extends ItemRiftSignature { // The link signature has not been used. Store its current target as the first location. setSource(stack, x, adjustedY, z, orientation, PocketManager.getDimensionData(world)); - mod_pocketDim.sendChat(player,"Location Stored in Stabilized Rift Signature"); - world.playSoundAtEntity(player,"mods.DimDoors.sfx.riftStart", 0.6f, 1); + mod_pocketDim.sendChat(player, "Location Stored in Stabilized Rift Signature"); + world.playSoundAtEntity(player, "mods.DimDoors.sfx.riftStart", 0.6f, 1); } return true; } @@ -148,14 +142,11 @@ public class ItemStabilizedRiftSignature extends ItemRiftSignature // Only the source-to-destination link is needed. link = sourceDimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.NORMAL, source.getOrientation()); destinationDimension.setLinkDestination(link, x, adjustedY, z); - - // Try placing a rift at the source point, but check if its world is loaded first + + // Try placing a rift at the source point + // We don't need to check if sourceWorld is null - that's already handled. World sourceWorld = DimensionManager.getWorld(sourceDimension.id()); - if (sourceWorld != null && - !mod_pocketDim.blockRift.isBlockImmune(sourceWorld, source.getX(), source.getY(), source.getZ())) - { - sourceWorld.setBlock(source.getX(), source.getY(), source.getZ(), mod_pocketDim.blockRift.blockID); - } + mod_pocketDim.blockRift.tryPlacingRift(sourceWorld, source.getX(), source.getY(), source.getZ()); // This call doesn't seem to be working... world.playSoundEffect(x + 0.5, adjustedY + 0.5, z + 0.5, "mods.DimDoors.sfx.riftEnd", 0.6f, 1); diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java b/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java index 8329d25..a8633d9 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java @@ -53,7 +53,6 @@ import StevenDimDoors.mod_pocketDim.items.ItemWarpDoor; import StevenDimDoors.mod_pocketDim.items.ItemWorldThread; import StevenDimDoors.mod_pocketDim.items.itemRiftRemover; import StevenDimDoors.mod_pocketDim.ticking.CustomLimboPopulator; -import StevenDimDoors.mod_pocketDim.ticking.FastRiftRegenerator; import StevenDimDoors.mod_pocketDim.ticking.LimboDecayScheduler; import StevenDimDoors.mod_pocketDim.ticking.MobMonolith; import StevenDimDoors.mod_pocketDim.ticking.RiftRegenerator; @@ -143,8 +142,7 @@ public class mod_pocketDim public static DDProperties properties; public static DDWorldProperties worldProperties; public static CustomLimboPopulator spawner; //Added this field temporarily. Will be refactored out later. - private static RiftRegenerator riftRegenerator; - public static FastRiftRegenerator fastRiftRegenerator; + public static RiftRegenerator riftRegenerator; public static GatewayGenerator gatewayGenerator; public static DeathTracker deathTracker; private static ServerTickHandler serverTickHandler; @@ -325,6 +323,9 @@ public class mod_pocketDim // Unregister all tick receivers from serverTickHandler to avoid leaking // scheduled tasks between single-player game sessions serverTickHandler.unregisterReceivers(); + spawner = null; + riftRegenerator = null; + limboDecayScheduler = null; } catch (Exception e) { @@ -339,7 +340,6 @@ public class mod_pocketDim // Load the config file that's specific to this world worldProperties = new DDWorldProperties(new File(currrentSaveRootDirectory + "/DimensionalDoors/DimDoorsWorld.cfg")); - hooks.setWorldProperties(worldProperties); // Initialize a new DeathTracker deathTracker = new DeathTracker(currrentSaveRootDirectory + "/DimensionalDoors/data/deaths.txt"); @@ -347,9 +347,10 @@ public class mod_pocketDim // Register regular tick receivers // CustomLimboPopulator should be initialized before any provider instances are created spawner = new CustomLimboPopulator(serverTickHandler, properties); - riftRegenerator = new RiftRegenerator(serverTickHandler); + riftRegenerator = new RiftRegenerator(serverTickHandler, blockRift); limboDecayScheduler = new LimboDecayScheduler(serverTickHandler, limboDecay); - fastRiftRegenerator = new FastRiftRegenerator(serverTickHandler); + + hooks.setSessionFields(worldProperties, riftRegenerator); } @EventHandler diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/ticking/FastRiftRegenerator.java b/src/main/java/StevenDimDoors/mod_pocketDim/ticking/FastRiftRegenerator.java deleted file mode 100644 index e680b2a..0000000 --- a/src/main/java/StevenDimDoors/mod_pocketDim/ticking/FastRiftRegenerator.java +++ /dev/null @@ -1,54 +0,0 @@ -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; -import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.core.PocketManager; -import StevenDimDoors.mod_pocketDim.util.Point4D; - -public class FastRiftRegenerator implements IRegularTickReceiver { - - 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) - { - sender.registerReceiver(this, RIFT_REGENERATION_INTERVAL, false); - } - - @Override - public void notifyTick() - { - regenerateScheduledRifts(); - } - - public void regenerateScheduledRifts() - { - if (!locationsToRegen.isEmpty()) - { - @SuppressWarnings("cast") - List loadedWorlds = (List) Arrays.asList(DimensionManager.getIDs()); - for (Point4D point: locationsToRegen) - { - if (loadedWorlds.contains(point.getDimension()) && PocketManager.getLink(point) != null) - { - World world = DimensionManager.getWorld(point.getDimension()); - mod_pocketDim.blockRift.regenerateRift(world, point.getX(), point.getY(), point.getZ(), random); - } - } - locationsToRegen.clear(); - } - } - - public void registerRiftForRegen(int x, int y, int z, int dimID) - { - this.locationsToRegen.add(new Point4D(x, y, z, dimID)); - } -} diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java b/src/main/java/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java index 23b0f9b..0b957da 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java @@ -1,56 +1,113 @@ package StevenDimDoors.mod_pocketDim.ticking; -import java.util.Arrays; -import java.util.List; +import java.util.PriorityQueue; import java.util.Random; +import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraftforge.common.DimensionManager; -import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.blocks.BlockRift; import StevenDimDoors.mod_pocketDim.core.DimLink; -import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.util.Point4D; 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; + // Ranges of regeneration delays, in seconds + private static final int MIN_FAST_DELAY = 1; + private static final int MAX_FAST_DELAY = 3; + private static final int MIN_SLOW_DELAY = 5; + private static final int MAX_SLOW_DELAY = 15; + private static final int MIN_RESCHEDULE_DELAY = 4 * 60; + private static final int MAX_RESCHEDULE_DELAY = 6 * 60; + + private static final int TICKS_PER_SECOND = 20; + private static final int RIFT_REGENERATION_INTERVAL = 1; // Check the regeneration queue every tick private static Random random = new Random(); - public RiftRegenerator(IRegularTickSender sender) + private long tickCount = 0; + private PriorityQueue ticketQueue; + private BlockRift blockRift; + + public RiftRegenerator(IRegularTickSender sender, BlockRift blockRift) { + this.ticketQueue = new PriorityQueue(); + this.blockRift = blockRift; sender.registerReceiver(this, RIFT_REGENERATION_INTERVAL, false); } @Override public void notifyTick() { - regenerateRiftsInLoadedWorlds(); + processTicketQueue(); + tickCount++; } - private static void regenerateRiftsInLoadedWorlds() + public void scheduleSlowRegeneration(DimLink link) { - // Regenerate rifts that have been replaced (not permanently removed) by players - // Only do this in dimensions that are currently loaded - List loadedWorlds = Arrays.asList(DimensionManager.getIDs()); - for (Integer dimensionID : loadedWorlds) - { - NewDimData dimension = PocketManager.getDimensionData(dimensionID); - if (dimension.linkCount() > 0) - { - World world = DimensionManager.getWorld(dimension.id()); - - if (world != null) - { - for (int count = 0; count < RIFTS_REGENERATED_PER_DIMENSION; count++) - { - DimLink link = dimension.getRandomLink(); - Point4D source = link.source(); - mod_pocketDim.blockRift.regenerateRift(world, source.getX(), source.getY(), source.getZ(), random); - } - } - } - } + scheduleRegeneration(link, MIN_SLOW_DELAY, MAX_SLOW_DELAY); } + + public void scheduleFastRegeneration(DimLink link) + { + scheduleRegeneration(link, MIN_FAST_DELAY, MAX_FAST_DELAY); + } + + private void scheduleRegeneration(DimLink link, int minDelay, int maxDelay) + { + int tickDelay = MathHelper.getRandomIntegerInRange(random, minDelay * TICKS_PER_SECOND, maxDelay * TICKS_PER_SECOND); + ticketQueue.add(new RiftTicket(link.source(), tickCount + tickDelay)); + } + + private void processTicketQueue() + { + RiftTicket ticket; + while (!ticketQueue.isEmpty() && ticketQueue.peek().timestamp() <= tickCount) + { + ticket = ticketQueue.remove(); + regenerateRift(ticket.location()); + } + } + + private void regenerateRift(Point4D location) + { + int x = location.getX(); + int y = location.getY(); + int z = location.getZ(); + + // Try to regenerate a rift, or possibly reschedule its regeneration. + // The world for the given location must be loaded. + World world = DimensionManager.getWorld(location.getDimension()); + if (world == null) + return; + + // There must be a link at the given location. + DimLink link = PocketManager.getLink(location); + if (link == null) + return; + + // The chunk at the given location must be loaded. + // FIXME: I can't figure out how to check if a chunk is loaded. + // Will only check if the chunk exists for now. This isn't a big deal. --SenseiKiwi + if (!world.getChunkProvider().chunkExists(x >> 4, z >> 4)) + return; + + // If the location is occupied by an immune DD block, then don't regenerate. + if (blockRift.isModBlockImmune(world, x, y, z)) + return; + + // If the location is occupied by an immune block, then reschedule. + if (blockRift.isBlockImmune(world, x, y, z)) + { + scheduleRegeneration(link, MIN_RESCHEDULE_DELAY, MAX_RESCHEDULE_DELAY); + } + else + { + // All of the necessary conditions have been met. Restore the rift! + int blockID = world.getBlockId(x, y, z); + if (world.setBlock(x, y, z, blockRift.blockID)) + blockRift.dropWorldThread(blockID, world, x, y, z, random); + } + } + } diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/ticking/RiftTicket.java b/src/main/java/StevenDimDoors/mod_pocketDim/ticking/RiftTicket.java new file mode 100644 index 0000000..d618a51 --- /dev/null +++ b/src/main/java/StevenDimDoors/mod_pocketDim/ticking/RiftTicket.java @@ -0,0 +1,40 @@ +package StevenDimDoors.mod_pocketDim.ticking; + +import StevenDimDoors.mod_pocketDim.util.Point4D; + +public class RiftTicket implements Comparable { + + private long timestamp; + private Point4D location; + + public RiftTicket(Point4D location, long timestamp) + { + this.timestamp = timestamp; + this.location = location; + } + + @Override + public int compareTo(RiftTicket other) + { + if (this.timestamp < other.timestamp) + { + return -1; + } + else if (this.timestamp > other.timestamp) + { + return 1; + } + return 0; + } + + public long timestamp() + { + return timestamp; + } + + public Point4D location() + { + return location; + } + +} diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityDimDoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityDimDoor.java index fe478b6..9703ae1 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityDimDoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityDimDoor.java @@ -1,17 +1,13 @@ package StevenDimDoors.mod_pocketDim.tileentities; import java.util.Random; -import StevenDimDoors.mod_pocketDim.ServerPacketHandler; -import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.blocks.IDimDoor; -import StevenDimDoors.mod_pocketDim.core.NewDimData; -import StevenDimDoors.mod_pocketDim.core.PocketManager; -import net.minecraft.block.Block; + import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.packet.Packet; -import net.minecraft.network.packet.Packet130UpdateSign; -import net.minecraft.network.packet.Packet250CustomPayload; -import net.minecraft.tileentity.TileEntity; +import StevenDimDoors.mod_pocketDim.ServerPacketHandler; +import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.core.DimLink; +import StevenDimDoors.mod_pocketDim.core.PocketManager; public class TileEntityDimDoor extends DDTileEntityBase { @@ -28,25 +24,26 @@ public class TileEntityDimDoor extends DDTileEntityBase } @Override - public Packet getDescriptionPacket() - { - if(PocketManager.getLink(xCoord, yCoord, zCoord, worldObj)!=null) - { - return ServerPacketHandler.createLinkPacket(PocketManager.getLink(xCoord, yCoord, zCoord, worldObj).link()); - } - return null; - } + public Packet getDescriptionPacket() + { + DimLink link = PocketManager.getLink(xCoord, yCoord, zCoord, worldObj); + if (link != null) + { + return ServerPacketHandler.createLinkPacket(link.link()); + } + return null; + } @Override public void invalidate() { - this.tileEntityInvalid = true; - - if(this.worldObj.getBlockId(xCoord, yCoord, zCoord)==0&&!this.worldObj.isRemote) + super.invalidate(); + if (!worldObj.isRemote && worldObj.getBlockId(xCoord, yCoord, zCoord) == 0) { - if(PocketManager.getLink(xCoord, yCoord, zCoord, worldObj)!=null) + DimLink link = PocketManager.getLink(xCoord, yCoord, zCoord, worldObj); + if (link != null) { - mod_pocketDim.fastRiftRegenerator.registerRiftForRegen(xCoord, yCoord, zCoord, this.worldObj.provider.dimensionId); + mod_pocketDim.riftRegenerator.scheduleFastRegeneration(link); } } } @@ -74,7 +71,7 @@ public class TileEntityDimDoor extends DDTileEntityBase public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); - + nbt.setBoolean("openOrClosed", this.openOrClosed); nbt.setBoolean("hasExit", this.hasExit); nbt.setInteger("orientation", this.orientation); From 71e7fdaafce55ba5ff4ac9932d4bd644dc8b95a2 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Fri, 11 Jul 2014 03:26:40 -0400 Subject: [PATCH 38/47] Implemented Regeneration for BlockRift 1. Made it so that rifts regenerate when rift blocks are replaced by other blocks. 2. Changed the rift regeneration scheduling functions to streamline their use in other classes. Common code that was needed to validate links before calling those functions has been moved into them so that the checks are always performed internally. --- .../mod_pocketDim/blocks/BlockRift.java | 19 +++++++++++++------ .../ticking/RiftRegenerator.java | 16 ++++++++++++---- .../tileentities/TileEntityDimDoor.java | 6 +----- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java index 78f666a..c7f8508 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java @@ -7,7 +7,6 @@ import java.util.Queue; import java.util.Random; import net.minecraft.block.Block; -import net.minecraft.block.BlockContainer; import net.minecraft.block.BlockFlowing; import net.minecraft.block.BlockFluid; import net.minecraft.block.ITileEntityProvider; @@ -87,9 +86,6 @@ public class BlockRift extends Block implements ITileEntityProvider { return false; } - - @Override - public void onBlockDestroyedByPlayer(World par1World, int par2, int par3, int par4, int par5) {} @Override public boolean isOpaqueCube() @@ -116,10 +112,10 @@ public class BlockRift extends Block implements ITileEntityProvider return true; } - //this doesnt do anything yet. @Override public int getRenderType() { + // This doesn't do anything yet if (mod_pocketDim.isPlayerWearingGoogles) { return 0; @@ -235,7 +231,7 @@ public class BlockRift extends Block implements ITileEntityProvider } } - private void addAdjacentBlocks(int x, int y, int z, int distance, HashMap pointDistances, Queue points) + private static void addAdjacentBlocks(int x, int y, int z, int distance, HashMap pointDistances, Queue points) { Point3D[] neighbors = new Point3D[] { new Point3D(x - 1, y, z), @@ -462,4 +458,15 @@ public class BlockRift extends Block implements ITileEntityProvider { return new TileEntityRift(); } + + @Override + public void breakBlock(World world, int x, int y, int z, int oldBlockID, int oldMeta) + { + // This function runs on the server side after a block is replaced + // We MUST call super.breakBlock() since it involves removing tile entities + super.breakBlock(world, x, y, z, oldBlockID, oldMeta); + + // Schedule rift regeneration for this block + mod_pocketDim.riftRegenerator.scheduleSlowRegeneration(x, y, z, world); + } } \ No newline at end of file diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java b/src/main/java/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java index 0b957da..66bdd1d 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java @@ -48,15 +48,23 @@ public class RiftRegenerator implements IRegularTickReceiver { scheduleRegeneration(link, MIN_SLOW_DELAY, MAX_SLOW_DELAY); } - public void scheduleFastRegeneration(DimLink link) + public void scheduleSlowRegeneration(int x, int y, int z, World world) { - scheduleRegeneration(link, MIN_FAST_DELAY, MAX_FAST_DELAY); + scheduleRegeneration(PocketManager.getLink(x, y, z, world), MIN_SLOW_DELAY, MAX_SLOW_DELAY); + } + + public void scheduleFastRegeneration(int x, int y, int z, World world) + { + scheduleRegeneration(PocketManager.getLink(x, y, z, world), MIN_FAST_DELAY, MAX_FAST_DELAY); } private void scheduleRegeneration(DimLink link, int minDelay, int maxDelay) { - int tickDelay = MathHelper.getRandomIntegerInRange(random, minDelay * TICKS_PER_SECOND, maxDelay * TICKS_PER_SECOND); - ticketQueue.add(new RiftTicket(link.source(), tickCount + tickDelay)); + if (link != null) + { + int tickDelay = MathHelper.getRandomIntegerInRange(random, minDelay * TICKS_PER_SECOND, maxDelay * TICKS_PER_SECOND); + ticketQueue.add(new RiftTicket(link.source(), tickCount + tickDelay)); + } } private void processTicketQueue() diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityDimDoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityDimDoor.java index 9703ae1..781427b 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityDimDoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityDimDoor.java @@ -40,11 +40,7 @@ public class TileEntityDimDoor extends DDTileEntityBase super.invalidate(); if (!worldObj.isRemote && worldObj.getBlockId(xCoord, yCoord, zCoord) == 0) { - DimLink link = PocketManager.getLink(xCoord, yCoord, zCoord, worldObj); - if (link != null) - { - mod_pocketDim.riftRegenerator.scheduleFastRegeneration(link); - } + mod_pocketDim.riftRegenerator.scheduleFastRegeneration(xCoord, yCoord, zCoord, worldObj); } } From 29c8a09218cdb4281ca29d1342cb928417a118b0 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Fri, 11 Jul 2014 03:44:26 -0400 Subject: [PATCH 39/47] Improved Door Code 1. Removed code from BaseDimDoor that was already implemented almost identically in BlockDoor. Clarified some uses of setBlock() by changing them to setBlockToAir() instead. 2. Removed TileEntityDimDoor.invalidate() and moved the regeneration scheduling code to BaseDimDoor.breakBlock(). I would prefer to move away from overriding the invalidate() method. This also simplifies the code since we don't need to perform some of the checks we had in breakBlock(). --- .../mod_pocketDim/blocks/BaseDimDoor.java | 27 +++++++++---------- .../tileentities/TileEntityDimDoor.java | 10 ------- 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BaseDimDoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BaseDimDoor.java index d26a0e3..782acfa 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BaseDimDoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BaseDimDoor.java @@ -306,7 +306,7 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn { if (world.getBlockId(x, y - 1, z) != this.blockID) { - world.setBlock(x, y, z, 0); + world.setBlockToAir(x, y, z); } if (neighborID > 0 && neighborID != this.blockID) @@ -318,7 +318,7 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn { if (world.getBlockId(x, y + 1, z) != this.blockID) { - world.setBlock(x, y, z, 0); + world.setBlockToAir(x, y, z); if (!world.isRemote) { this.dropBlockAsItem(world, x, y, z, metadata, 0); @@ -354,18 +354,6 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn return isUpperDoorBlock(metadata) ? 0 : this.getDrops(); } - /** - * Called when the block is attempted to be harvested - */ - @Override - public void onBlockHarvested(World par1World, int par2, int par3, int par4, int par5, EntityPlayer par6EntityPlayer) - { - if (par6EntityPlayer.capabilities.isCreativeMode && (par5 & 8) != 0 && par1World.getBlockId(par2, par3 - 1, par4) == this.blockID) - { - par1World.setBlock(par2, par3 - 1, par4, 0); - } - } - @Override public TileEntity createNewTileEntity(World world) { @@ -445,4 +433,15 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn world.setBlockTileEntity(x, y, z, te); return te; } + + @Override + public void breakBlock(World world, int x, int y, int z, int oldBlockID, int oldMeta) + { + // This function runs on the server side after a block is replaced + // We MUST call super.breakBlock() since it involves removing tile entities + super.breakBlock(world, x, y, z, oldBlockID, oldMeta); + + // Schedule rift regeneration for this block + mod_pocketDim.riftRegenerator.scheduleFastRegeneration(x, y, z, world); + } } \ No newline at end of file diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityDimDoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityDimDoor.java index 781427b..881577c 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityDimDoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityDimDoor.java @@ -34,16 +34,6 @@ public class TileEntityDimDoor extends DDTileEntityBase return null; } - @Override - public void invalidate() - { - super.invalidate(); - if (!worldObj.isRemote && worldObj.getBlockId(xCoord, yCoord, zCoord) == 0) - { - mod_pocketDim.riftRegenerator.scheduleFastRegeneration(xCoord, yCoord, zCoord, worldObj); - } - } - @Override public void readFromNBT(NBTTagCompound nbt) { From 1bf1f4f78c7db0e410dec147bedb0b50780af138 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Fri, 11 Jul 2014 04:10:12 -0400 Subject: [PATCH 40/47] Improved Regeneration Code 1. Added code so that Transdimensional Trapdoors detect that they have been broken and schedule rift regeneration at their location. This had previously been neglected. Trapdoors deserve a little more attention. 2. Tweaked the breakBlock() code for BlockRift and BaseDimDoor so that rift regeneration is only scheduled if the underlying block was removed. We don't want that to happen if the only change was for metadata. --- .../mod_pocketDim/blocks/BaseDimDoor.java | 7 +++++-- .../mod_pocketDim/blocks/BlockRift.java | 7 +++++-- .../mod_pocketDim/blocks/TransTrapdoor.java | 14 ++++++++++++++ .../tileentities/TileEntityTransTrapdoor.java | 3 +-- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BaseDimDoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BaseDimDoor.java index 782acfa..de8db5b 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BaseDimDoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BaseDimDoor.java @@ -441,7 +441,10 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn // We MUST call super.breakBlock() since it involves removing tile entities super.breakBlock(world, x, y, z, oldBlockID, oldMeta); - // Schedule rift regeneration for this block - mod_pocketDim.riftRegenerator.scheduleFastRegeneration(x, y, z, world); + // Schedule rift regeneration for this block if it was replaced + if (world.getBlockId(x, y, z) != oldBlockID) + { + mod_pocketDim.riftRegenerator.scheduleFastRegeneration(x, y, z, world); + } } } \ No newline at end of file diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java index c7f8508..6400978 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java @@ -466,7 +466,10 @@ public class BlockRift extends Block implements ITileEntityProvider // We MUST call super.breakBlock() since it involves removing tile entities super.breakBlock(world, x, y, z, oldBlockID, oldMeta); - // Schedule rift regeneration for this block - mod_pocketDim.riftRegenerator.scheduleSlowRegeneration(x, y, z, world); + // Schedule rift regeneration for this block if it was changed + if (world.getBlockId(x, y, z) != oldBlockID) + { + mod_pocketDim.riftRegenerator.scheduleSlowRegeneration(x, y, z, world); + } } } \ No newline at end of file diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/TransTrapdoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/TransTrapdoor.java index 4a1df0d..aefb277 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/TransTrapdoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/TransTrapdoor.java @@ -140,4 +140,18 @@ public class TransTrapdoor extends BlockTrapDoor implements IDimDoor, ITileEntit world.setBlockTileEntity(x, y, z, te); return te; } + + @Override + public void breakBlock(World world, int x, int y, int z, int oldBlockID, int oldMeta) + { + // This function runs on the server side after a block is replaced + // We MUST call super.breakBlock() since it involves removing tile entities + super.breakBlock(world, x, y, z, oldBlockID, oldMeta); + + // Schedule rift regeneration for this block if it was replaced + if (world.getBlockId(x, y, z) != oldBlockID) + { + mod_pocketDim.riftRegenerator.scheduleFastRegeneration(x, y, z, world); + } + } } \ No newline at end of file diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityTransTrapdoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityTransTrapdoor.java index d26b46f..25cc3b4 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityTransTrapdoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityTransTrapdoor.java @@ -1,9 +1,8 @@ package StevenDimDoors.mod_pocketDim.tileentities; import java.util.Random; + import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; public class TileEntityTransTrapdoor extends DDTileEntityBase { From 107aa4b7f24c90b24ffca64a93b3f118b2253543 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Fri, 11 Jul 2014 04:33:19 -0400 Subject: [PATCH 41/47] Cleaned up Transdimensional Trapdoor Code Removed unnecessary code for the Transdimensional Trapdoor. Most of it was code dedicated to updating TileEntityTransTrapdoor.hasRift. That flag was never used for anything. --- .../mod_pocketDim/blocks/TransTrapdoor.java | 20 +--------------- .../tileentities/TileEntityTransTrapdoor.java | 2 -- .../RenderTransTrapdoor.java | 24 ++++--------------- 3 files changed, 6 insertions(+), 40 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/TransTrapdoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/TransTrapdoor.java index aefb277..d2eda14 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/TransTrapdoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/TransTrapdoor.java @@ -63,14 +63,6 @@ public class TransTrapdoor extends BlockTrapDoor implements IDimDoor, ITileEntit { this.placeLink(world, x, y, z); world.setBlockTileEntity(x, y, z, this.createNewTileEntity(world)); - updateAttachedTile(world, x, y, z); - } - - @Override - public void updateTick(World world, int x, int y, int z, Random random) - { - TileEntityTransTrapdoor tile = (TileEntityTransTrapdoor) world.getBlockTileEntity(x, y, z); - tile.hasRift = PocketManager.getLink(x, y, z, world) != null; } @Override @@ -79,16 +71,6 @@ public class TransTrapdoor extends BlockTrapDoor implements IDimDoor, ITileEntit return new TileEntityTransTrapdoor(); } - public static void updateAttachedTile(World world, int x, int y, int z) - { - TileEntity tile = world.getBlockTileEntity(x, y, z); - if (tile instanceof TileEntityTransTrapdoor) - { - TileEntityTransTrapdoor trapdoorTile = (TileEntityTransTrapdoor) tile; - trapdoorTile.hasRift = (PocketManager.getLink(x, y, z, world) != null); - } - } - @Override public void placeLink(World world, int x, int y, int z) { @@ -98,7 +80,7 @@ public class TransTrapdoor extends BlockTrapDoor implements IDimDoor, ITileEntit DimLink link = dimension.getLink(x, y, z); if (link == null && dimension.isPocketDimension()) { - dimension.createLink(x, y, z, LinkTypes.UNSAFE_EXIT,0); + dimension.createLink(x, y, z, LinkTypes.UNSAFE_EXIT, 0); } } } diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityTransTrapdoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityTransTrapdoor.java index 25cc3b4..3df7f6c 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityTransTrapdoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityTransTrapdoor.java @@ -6,8 +6,6 @@ import StevenDimDoors.mod_pocketDim.mod_pocketDim; public class TileEntityTransTrapdoor extends DDTileEntityBase { - public boolean hasRift; - @Override public boolean canUpdate() { diff --git a/src/main/java/StevenDimDoors/mod_pocketDimClient/RenderTransTrapdoor.java b/src/main/java/StevenDimDoors/mod_pocketDimClient/RenderTransTrapdoor.java index 0f3ea97..98f8e88 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDimClient/RenderTransTrapdoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDimClient/RenderTransTrapdoor.java @@ -3,6 +3,7 @@ package StevenDimDoors.mod_pocketDimClient; import java.nio.FloatBuffer; import java.util.Random; +import net.minecraft.block.BlockTrapDoor; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GLAllocation; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; @@ -38,21 +39,6 @@ public class RenderTransTrapdoor extends TileEntitySpecialRenderer */ public void renderTransTrapdoorTileEntity(TileEntityTransTrapdoor tile, double x, double y, double z, float par8) { - try - { - mod_pocketDim.transTrapdoor.updateAttachedTile(tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord); - } - catch(Exception e) - { - e.printStackTrace(); - } - - - // float playerX = (float)this.tileEntityRenderer.playerX; - // float playerY = (float)this.tileEntityRenderer.playerY; - // float playerZ = (float)this.tileEntityRenderer.playerZ; - - //float distance = (float) tile.getDistanceFrom(playerX, playerY, playerZ); GL11.glDisable(GL11.GL_LIGHTING); Random random = new Random(31100L); int metadata = tile.worldObj.getBlockMetadata(tile.xCoord, tile.yCoord, tile.zCoord); @@ -77,7 +63,6 @@ public class RenderTransTrapdoor extends TileEntitySpecialRenderer if (count == 1) { this.bindTexture(warpPath); - // move files into assets/modid and change to new ResourceLocation(modid:/WARP.png) GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE); var16 = .5F; @@ -127,7 +112,7 @@ public class RenderTransTrapdoor extends TileEntitySpecialRenderer GL11.glColor4d(var21 * var17, var22 * var17, var23 * var17, 1.0F); if (TransTrapdoor.isTrapdoorSetLow(metadata)) { - if (TransTrapdoor.isTrapdoorOpen(metadata)) + if (BlockTrapDoor.isTrapdoorOpen(metadata)) { GL11.glVertex3d(x, y+0.2, z); GL11.glVertex3d(x, y+0.2, z+1); @@ -144,7 +129,7 @@ public class RenderTransTrapdoor extends TileEntitySpecialRenderer } else { - if (TransTrapdoor.isTrapdoorOpen(metadata)) + if (BlockTrapDoor.isTrapdoorOpen(metadata)) { GL11.glVertex3d(x, y+0.95, z); GL11.glVertex3d(x, y+0.95, z+1); @@ -180,7 +165,8 @@ public class RenderTransTrapdoor extends TileEntitySpecialRenderer return this.field_76908_a; } - public void renderTileEntityAt(TileEntity par1TileEntity, double par2, double par4, double par6, float par8) + @Override + public void renderTileEntityAt(TileEntity par1TileEntity, double par2, double par4, double par6, float par8) { if (properties.DoorRenderingEnabled) { From 2c7435585d08147a806ca5c3307eaf8b0e775c17 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Fri, 11 Jul 2014 15:44:01 -0400 Subject: [PATCH 42/47] Minor Changes Removed a pointless check in yCoordHelper and corrected some comments in RiftRegenerator. It turns out that ChunkProviderServer.chunkExists() returns whether a chunk is loaded, not whether it has already been created. --- .../StevenDimDoors/mod_pocketDim/helpers/yCoordHelper.java | 5 +---- .../mod_pocketDim/ticking/RiftRegenerator.java | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/helpers/yCoordHelper.java b/src/main/java/StevenDimDoors/mod_pocketDim/helpers/yCoordHelper.java index 3810c8b..26aa178 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/helpers/yCoordHelper.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/helpers/yCoordHelper.java @@ -215,10 +215,7 @@ public class yCoordHelper { for (int dz = -1; dz <= 1; dz++) { - if (!provider.chunkExists(chunkX + dx, chunkZ + dz)) - { - provider.loadChunk(chunkX, chunkZ); - } + provider.loadChunk(chunkX, chunkZ); } } return target; diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java b/src/main/java/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java index 66bdd1d..f23c38c 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java @@ -95,8 +95,8 @@ public class RiftRegenerator implements IRegularTickReceiver { return; // The chunk at the given location must be loaded. - // FIXME: I can't figure out how to check if a chunk is loaded. - // Will only check if the chunk exists for now. This isn't a big deal. --SenseiKiwi + // Note: ChunkProviderServer.chunkExists() returns whether a chunk is + // loaded, not whether it has already been created. if (!world.getChunkProvider().chunkExists(x >> 4, z >> 4)) return; From fb1713ae0e665acc2a48611db1a99548949c6f26 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sat, 12 Jul 2014 03:36:56 -0400 Subject: [PATCH 43/47] Improvements to TileEntityRift Made some improvements to TileEntityRift. The main reason for these changes was to remove the field nearestRift - we should not hold on to references to links. Now we simply track the location of the nearest rift. I also confirmed that closeRift() and updateNearestRift() must be allowed to run on both the client and the server. If the client doesn't run those functions, then adjacent rifts don't connect as expected and the rift removal animation doesn't work. --- .../tileentities/TileEntityRift.java | 77 ++++++++++--------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityRift.java b/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityRift.java index 13f9f96..62bb62b 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityRift.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityRift.java @@ -1,6 +1,5 @@ package StevenDimDoors.mod_pocketDim.tileentities; -import java.util.ArrayList; import java.util.List; import java.util.Random; @@ -42,8 +41,7 @@ public class TileEntityRift extends DDTileEntityBase public int yOffset = 0; public int zOffset = 0; public boolean shouldClose = false; - - public DimLink nearestRiftData; + public Point4D nearestRiftLocation = null; public int spawnedEndermenID = 0; public TileEntityRift() @@ -64,20 +62,20 @@ public class TileEntityRift extends DDTileEntityBase } else { - this.invalidate(); + invalidate(); } return; } if (worldObj.getBlockId(xCoord, yCoord, zCoord) != mod_pocketDim.blockRift.blockID) { - this.invalidate(); + invalidate(); return; } // Check if this rift should render white closing particles and // spread the closing effect to other rifts nearby. - if (this.shouldClose) + if (shouldClose) { closeRift(); return; @@ -85,13 +83,13 @@ public class TileEntityRift extends DDTileEntityBase if (updateTimer >= UPDATE_PERIOD) { - this.spawnEndermen(mod_pocketDim.properties); + spawnEndermen(mod_pocketDim.properties); updateTimer = 0; } else if (updateTimer == UPDATE_PERIOD / 2) { - this.calculateParticleOffsets(); - this.spread(mod_pocketDim.properties); + updateNearestRift(); + spread(mod_pocketDim.properties); } updateTimer++; } @@ -136,57 +134,60 @@ public class TileEntityRift extends DDTileEntityBase } } } - - public boolean updateNearestRift() - { - nearestRiftData = PocketManager.getDimensionData(worldObj).findNearestRift(this.worldObj, 5, xCoord, yCoord, zCoord); - return (nearestRiftData != null); - } private void closeRift() { NewDimData dimension = PocketManager.getDimensionData(worldObj); if (closeTimer == CLOSING_PERIOD / 2) { - ArrayList riftLinks = dimension.findRiftsInRange(worldObj, 6, xCoord, yCoord, zCoord); - if (riftLinks.size() > 0) + for (DimLink riftLink : dimension.findRiftsInRange(worldObj, 6, xCoord, yCoord, zCoord)) { - for (DimLink riftLink : riftLinks) + Point4D location = riftLink.source(); + TileEntityRift rift = (TileEntityRift) worldObj.getBlockTileEntity(location.getX(), location.getY(), location.getZ()); + if (rift != null && !rift.shouldClose) { - Point4D location = riftLink.source(); - TileEntityRift rift = (TileEntityRift) worldObj.getBlockTileEntity(location.getX(), location.getY(), location.getZ()); - if (rift != null) - { - rift.shouldClose = true; - rift.onInventoryChanged(); - } + rift.shouldClose = true; + rift.onInventoryChanged(); } } } if (closeTimer >= CLOSING_PERIOD) { - if (!this.worldObj.isRemote) + DimLink link = PocketManager.getLink(this.xCoord, this.yCoord, this.zCoord, worldObj); + if (link != null) { - DimLink link = PocketManager.getLink(this.xCoord, this.yCoord, this.zCoord, worldObj); - if (link != null) - { - dimension.deleteLink(link); - } + dimension.deleteLink(link); } worldObj.setBlockToAir(xCoord, yCoord, zCoord); worldObj.playSound(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, "mods.DimDoors.sfx.riftClose", 0.7f, 1, false); } closeTimer++; } - - private void calculateParticleOffsets() + + public boolean updateNearestRift() { - if (updateNearestRift()) + Point4D previousNearest = nearestRiftLocation; + DimLink nearestRiftLink = PocketManager.getDimensionData(worldObj).findNearestRift( + worldObj, RIFT_INTERACTION_RANGE, xCoord, yCoord, zCoord); + + nearestRiftLocation = (nearestRiftLink == null) ? null : nearestRiftLink.source(); + + // If the nearest rift location changed, then update particle offsets + if (previousNearest != nearestRiftLocation && + (previousNearest == null || nearestRiftLocation == null || !previousNearest.equals(nearestRiftLocation))) { - Point4D location = nearestRiftData.source(); - this.xOffset = this.xCoord - location.getX(); - this.yOffset = this.yCoord - location.getY(); - this.zOffset = this.zCoord - location.getZ(); + updateParticleOffsets(); + } + return (nearestRiftLocation != null); + } + + private void updateParticleOffsets() + { + if (nearestRiftLocation != null) + { + this.xOffset = this.xCoord - nearestRiftLocation.getX(); + this.yOffset = this.yCoord - nearestRiftLocation.getY(); + this.zOffset = this.zCoord - nearestRiftLocation.getZ(); } else { From b20a0a74d2e2c14cdba06885ed73df06cb7b6c9e Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sun, 13 Jul 2014 07:17:30 -0400 Subject: [PATCH 44/47] Minor Change Autocorrected indentation in PocketManager. I'll be working on changing PocketManager to prevent the risk of creating data for a non-existent dimension through a bad call to getDimensionData(). --- .../mod_pocketDim/core/PocketManager.java | 128 +++++++++--------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java b/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java index 1939e1d..a509c38 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java @@ -49,17 +49,17 @@ public class PocketManager // that any link destinations must be real dimensions controlled by PocketManager. public InnerDimData(int id, InnerDimData parent, boolean isPocket, boolean isDungeon, - IUpdateWatcher linkWatcher) + IUpdateWatcher linkWatcher) { super(id, parent, isPocket, isDungeon, linkWatcher); } - + public InnerDimData(int id, InnerDimData root) { // This constructor is meant for client-side code only super(id, root); } - + public void clear() { // If this dimension has a parent, remove it from its parent's list of children @@ -103,7 +103,7 @@ public class PocketManager ArrayList Links = new ArrayList(); ArrayList Tails = new ArrayList(); PackedDungeonData packedDungeon=null; - + if(this.dungeon!=null) { packedDungeon= new PackedDungeonData(dungeon.weight(), dungeon.isOpen(), dungeon.isInternal(), @@ -123,22 +123,22 @@ public class PocketManager { parentPoint=link.parent.link.point.toPoint3D(); } - + for(DimLink childLink : link.children) { children.add(childLink.source().toPoint3D()); } PackedLinkTail tail = new PackedLinkTail(link.tail.getDestination(),link.tail.getLinkType()); Links.add(new PackedLinkData(link.link.point,parentPoint,tail,link.link.orientation,children)); - + PackedLinkTail tempTail = new PackedLinkTail(link.tail.getDestination(),link.tail.getLinkType()); if(Tails.contains(tempTail)) { Tails.add(tempTail); } - - + + } int parentID=this.id; Point3D originPoint=new Point3D(0,0,0); @@ -151,30 +151,30 @@ public class PocketManager originPoint=this.origin.toPoint3D(); } return new PackedDimData(this.id, depth, this.packDepth, parentID, this.root().id(), orientation, - isDungeon, isFilled,packedDungeon, originPoint, ChildIDs, Links, Tails); + isDungeon, isFilled,packedDungeon, originPoint, ChildIDs, Links, Tails); // FIXME: IMPLEMENTATION PLZTHX //I tried } } - - private static class ClientLinkWatcher implements IUpdateWatcher - { - @Override - public void onCreated(ClientLinkData link) - { - Point4D source = link.point; - NewDimData dimension = getDimensionData(source.getDimension()); - dimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.CLIENT_SIDE,link.orientation); - } - @Override - public void onDeleted(ClientLinkData link) - { - Point4D source = link.point; - getDimensionData(source.getDimension()).deleteLink(source); - } - } - + private static class ClientLinkWatcher implements IUpdateWatcher + { + @Override + public void onCreated(ClientLinkData link) + { + Point4D source = link.point; + NewDimData dimension = getDimensionData(source.getDimension()); + dimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.CLIENT_SIDE,link.orientation); + } + + @Override + public void onDeleted(ClientLinkData link) + { + Point4D source = link.point; + getDimensionData(source.getDimension()).deleteLink(source); + } + } + private static class ClientDimWatcher implements IUpdateWatcher { @Override @@ -196,14 +196,14 @@ public class PocketManager // having to instantiate a bunch of data containers and without exposing an "unsafe" // creation method for anyone to call. Integrity protection for the win! It's like // exposing a private constructor ONLY to a very specific trusted class. - + @Override public NewDimData registerDimension(int dimensionID, int rootID) { return registerClientDimension(dimensionID, rootID); } } - + private static int OVERWORLD_DIMENSION_ID = 0; private static volatile boolean isLoading = false; @@ -242,11 +242,11 @@ public class PocketManager return; } isLoading = true; - + dimensionData = new HashMap(); rootDimensions = new ArrayList(); dimensionIDBlackList = new ArrayList(); - + if(FMLCommonHandler.instance().getEffectiveSide().isClient()) { //Shouldnt try to load everything if we are a client @@ -258,19 +258,19 @@ public class PocketManager //Register Limbo DDProperties properties = DDProperties.instance(); registerDimension(properties.LimboDimensionID, null, false, false); - + loadInternal(); - + //Register pocket dimensions registerPockets(properties); - + isLoaded = true; isLoading = false; } - + public static boolean registerPackedDimData(PackedDimData packedData) { - + InnerDimData dimData; //register roots if(packedData.ID==packedData.ParentID) @@ -291,7 +291,7 @@ public class PocketManager dimData.isFilled=packedData.IsFilled; dimData.origin = new Point4D(packedData.Origin.getX(),packedData.Origin.getY(),packedData.Origin.getZ(),packedData.ID); dimData.root=PocketManager.getDimensionData(packedData.RootID); - + if(packedData.DungeonData!=null) { dimData.dungeon=DDSaveHandler.unpackDungeonData(packedData.DungeonData); @@ -303,7 +303,7 @@ public class PocketManager return true; } - + public static boolean deletePocket(NewDimData target, boolean deleteFolder) { // We can't delete the dimension if it's currently loaded or if it's not actually a pocket. @@ -327,7 +327,7 @@ public class PocketManager } return false; } - + private static void deleteDimensionFiles(InnerDimData dimension) { // We assume that the caller checks if the dimension is loaded, for the @@ -339,7 +339,7 @@ public class PocketManager File dataFile = new File(saveRootPath + "/DimensionalDoors/data/dim_" + dimension.id() + ".txt"); dataFile.delete(); } - + private static void deleteDimensionData(InnerDimData dimension) { // We assume that the caller checks if the dimension is loaded, for the @@ -357,7 +357,7 @@ public class PocketManager throw new IllegalArgumentException("The specified dimension is not listed with PocketManager."); } } - + private static void registerPockets(DDProperties properties) { for (NewDimData dimension : dimensionData.values()) @@ -427,7 +427,7 @@ public class PocketManager { System.out.println("Importing old DD save data..."); OldSaveImporter.importOldSave(oldSaveData); - + oldSaveData.renameTo(new File(oldSaveData.getAbsolutePath()+"_IMPORTED")); System.out.println("Import Succesful!"); @@ -440,7 +440,7 @@ public class PocketManager } return; } - + // Load save data System.out.println("Loading Dimensional Doors save data..."); if (DDSaveHandler.loadAll()) @@ -449,7 +449,7 @@ public class PocketManager } } } - + public static void save(boolean checkModified) { if (!isLoaded) @@ -462,7 +462,7 @@ public class PocketManager return; } isSaving = true; - + try { DDSaveHandler.saveAll(dimensionData.values(), dimensionIDBlackList, checkModified); @@ -479,14 +479,14 @@ public class PocketManager isSaving = false; } } - + public static WorldServer loadDimension(int id) { if (!DimensionManager.isDimensionRegistered(id)) { return null; } - + WorldServer world = DimensionManager.getWorld(id); if (world == null) { @@ -512,7 +512,7 @@ public class PocketManager { throw new IllegalArgumentException("parent cannot be null. A pocket dimension must always have a parent dimension."); } - + DDProperties properties = DDProperties.instance(); int dimensionID = DimensionManager.getNextFreeDimId(); DimensionManager.registerDimension(dimensionID, properties.PocketProviderID); @@ -543,10 +543,10 @@ public class PocketManager rootDimensions.add(dimension); } getDimwatcher().onCreated(new ClientDimData(dimension)); - + return dimension; } - + @SideOnly(Side.CLIENT) private static NewDimData registerClientDimension(int dimensionID, int rootID) { @@ -556,7 +556,7 @@ public class PocketManager // SenseiKiwi: I'm a little worried about how getDimensionData will raise // an event when it creates any root dimensions... Needs checking later. - + InnerDimData root = (InnerDimData) getDimensionData(rootID); InnerDimData dimension; @@ -577,12 +577,12 @@ public class PocketManager { //Im registering pocket dims here. I *think* we can assume that if its a pocket and we are //registering its dim data, we also need to register it with forge. - + //New packet stuff prevents this from always being true, unfortuantly. I send the dimdata to the client when they teleport. //Steven DimensionManager.registerDimension(dimensionID, mod_pocketDim.properties.PocketProviderID); } - return dimension; + return dimension; } public static NewDimData getDimensionData(World world) @@ -597,7 +597,7 @@ public class PocketManager //and create a NewDimData instance for it. //Any pocket dimension must be listed with PocketManager to have a dimension ID //assigned, so it's safe to assume that any unknown dimensions don't belong to us. - + //FIXME: What's the point of this condition? Most calls to this function will crash anyway! ~SenseiKiwi if(PocketManager.dimensionData == null) { @@ -630,14 +630,14 @@ public class PocketManager { throw new IllegalStateException("Pocket dimensions have already been unloaded!"); } - + unregisterPockets(); dimensionData = null; rootDimensions = null; isLoaded = false; isConnected = false; } - + public static DimLink getLink(int x, int y, int z, World world) { return getLink(x, y, z, world.provider.dimensionId); @@ -647,7 +647,7 @@ public class PocketManager { return getLink(point.getX(), point.getY(), point.getZ(), point.getDimension()); } - + public static DimLink getLink(int x, int y, int z, int dimensionID) { NewDimData dimension = dimensionData.get(dimensionID); @@ -657,7 +657,7 @@ public class PocketManager } return null; } - + public static boolean isBlackListed(int dimensionID) { return PocketManager.dimensionIDBlackList.contains(dimensionID); @@ -670,12 +670,12 @@ public class PocketManager { return getDimwatcher().unregisterReceiver(watcher); } - + public static void registerLinkWatcher(IUpdateWatcher watcher) { linkWatcher.registerReceiver(watcher); } - + public static boolean unregisterLinkWatcher(IUpdateWatcher watcher) { return linkWatcher.unregisterReceiver(watcher); @@ -685,18 +685,18 @@ public class PocketManager { updateSource.registerWatchers(new ClientDimWatcher(), new ClientLinkWatcher()); } - + public static void writePacket(DataOutputStream output) throws IOException { // Write a very compact description of our dimensions and links to be sent to a client Compactor.write(dimensionData.values(), output); } - + public static boolean isRegisteredInternally(int dimensionID) { return dimensionData.containsKey(dimensionID); } - + public static void createAndRegisterBlacklist(List blacklist) { //TODO - create a special blacklist provider @@ -720,7 +720,7 @@ public class PocketManager // Load compacted client-side dimension data load(); Compactor.readDimensions(input, new DimRegistrationCallback()); - + isLoaded = true; isLoading = false; isConnected = true; From 8544aa17eea214363bb441f86215a2080ab05c11 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sun, 13 Jul 2014 14:22:23 -0400 Subject: [PATCH 45/47] Fixed Crash on World Creation Fixed an issue. DD would crash when MC created a completely new world because onChunkLoad() would be called before onWorldLoad(). That's not the usual order. PocketManager would be unloaded at that point and would return a null dimension. --- .../StevenDimDoors/mod_pocketDim/EventHookContainer.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/EventHookContainer.java b/src/main/java/StevenDimDoors/mod_pocketDim/EventHookContainer.java index 9fd2d41..e40d7c2 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/EventHookContainer.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/EventHookContainer.java @@ -230,8 +230,11 @@ public class EventHookContainer { // Schedule rift regeneration for any links located in this chunk. // This event runs on both the client and server. Allow server only. + // Also, check that PocketManager is loaded, because onChunkLoad() can + // fire while chunks are being initialized in a new world, before + // onWorldLoad() fires. Chunk chunk = event.getChunk(); - if (!chunk.worldObj.isRemote) + if (!chunk.worldObj.isRemote && PocketManager.isLoaded()) { NewDimData dimension = PocketManager.getDimensionData(chunk.worldObj); for (DimLink link : dimension.getChunkLinks(chunk.xPosition, chunk.zPosition)) From e7934933313e576228cac652ab06730d7f12e9c9 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sun, 13 Jul 2014 20:03:00 -0400 Subject: [PATCH 46/47] Fixed Eager Dimension Data Creation 1. Fixed a design flaw in PocketManager. We originally assumed that all requests to PocketManager.getDimensionData() had to be legitimate requests for dimensions that existed. That was true in most cases, but for things like processing user commands, it was dangerously optimistic. It was possible that a flaw in DD's usage of that function could be exploited by a player to trick the mod into pre-registering dimension data for a non-existent dimension. That would declare the dimension as a root. DD would crash later if Forge ever allocated that ID for a pocket dimension. The new implementation is almost the same as the old one, but allows us to differentiate between cases when we can eagerly create dimension data, and cases in which the absence of a dimension should cause a crash to alert us of a design flaw. 2. Remove the pocket regeneration code from PocketBuilder. We simply don't support pocket regeneration and it's unlikely it'll ever be implemented because it's a difficult issue. Wiping out pockets completely is easier. We can always recover the code from this commit if it's needed later. 3. Minor changes: removed some debug prints from PocketManager and changed some static accesses in PocketBuilder. --- .../mod_pocketDim/ConnectionHandler.java | 9 +- .../mod_pocketDim/EventHookContainer.java | 2 +- .../blocks/BlockGoldDimDoor.java | 2 +- .../mod_pocketDim/blocks/DimensionalDoor.java | 2 +- .../mod_pocketDim/blocks/TransTrapdoor.java | 2 +- .../mod_pocketDim/blocks/TransientDoor.java | 2 +- .../mod_pocketDim/blocks/UnstableDoor.java | 2 +- .../mod_pocketDim/blocks/WarpDoor.java | 2 +- .../commands/CommandCreateDungeonRift.java | 2 +- .../commands/CommandCreateRandomRift.java | 4 +- .../commands/CommandDeleteRifts.java | 2 +- .../commands/CommandTeleportPlayer.java | 3 +- .../mod_pocketDim/core/DDTeleporter.java | 17 ++-- .../mod_pocketDim/core/PocketManager.java | 72 ++++++++-------- .../dungeon/DungeonSchematic.java | 2 +- .../mod_pocketDim/helpers/DungeonHelper.java | 2 +- .../items/ItemRiftSignature.java | 4 +- .../items/ItemStabilizedRiftSignature.java | 6 +- .../mod_pocketDim/items/itemRiftRemover.java | 4 +- .../mod_pocketDim/saving/DDSaveHandler.java | 6 +- .../tileentities/TileEntityDimDoorGold.java | 2 +- .../tileentities/TileEntityRift.java | 6 +- .../mod_pocketDim/world/PocketBuilder.java | 85 +------------------ .../mod_pocketDim/world/PocketGenerator.java | 2 +- .../mod_pocketDim/world/PocketProvider.java | 8 +- .../fortresses/ComponentNetherGateway.java | 2 +- .../world/gateways/BaseSchematicGateway.java | 2 +- .../world/gateways/GatewayGenerator.java | 2 +- .../world/gateways/GatewayLimbo.java | 2 +- .../mod_pocketDimClient/ClosingRiftFX.java | 2 +- .../mod_pocketDimClient/GoggleRiftFX.java | 2 +- .../mod_pocketDimClient/RiftFX.java | 2 +- 32 files changed, 85 insertions(+), 179 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/ConnectionHandler.java b/src/main/java/StevenDimDoors/mod_pocketDim/ConnectionHandler.java index 9a8a17a..156ecce 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/ConnectionHandler.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/ConnectionHandler.java @@ -1,17 +1,11 @@ package StevenDimDoors.mod_pocketDim; -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.network.INetworkManager; import net.minecraft.network.NetLoginHandler; import net.minecraft.network.packet.NetHandler; import net.minecraft.network.packet.Packet1Login; import net.minecraft.network.packet.Packet250CustomPayload; import net.minecraft.server.MinecraftServer; -import net.minecraft.server.integrated.IntegratedServer; import net.minecraftforge.common.DimensionManager; import net.minecraftforge.common.network.ForgePacket; import net.minecraftforge.common.network.packet.DimensionRegisterPacket; @@ -65,7 +59,8 @@ public class ConnectionHandler implements IConnectionHandler @Override public void playerLoggedIn(Player player, NetHandler netHandler, INetworkManager manager) { - PocketManager.getDimwatcher().onCreated(new ClientDimData(PocketManager.getDimensionData(0))); + // Hax... please don't do this! >_< + PocketManager.getDimwatcher().onCreated(new ClientDimData(PocketManager.createDimensionDataDangerously(0))); } } \ No newline at end of file diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/EventHookContainer.java b/src/main/java/StevenDimDoors/mod_pocketDim/EventHookContainer.java index e40d7c2..1f91b95 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/EventHookContainer.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/EventHookContainer.java @@ -236,7 +236,7 @@ public class EventHookContainer Chunk chunk = event.getChunk(); if (!chunk.worldObj.isRemote && PocketManager.isLoaded()) { - NewDimData dimension = PocketManager.getDimensionData(chunk.worldObj); + NewDimData dimension = PocketManager.createDimensionData(chunk.worldObj); for (DimLink link : dimension.getChunkLinks(chunk.xPosition, chunk.zPosition)) { regenerator.scheduleSlowRegeneration(link); diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockGoldDimDoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockGoldDimDoor.java index 3feb075..d9ca897 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockGoldDimDoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/BlockGoldDimDoor.java @@ -25,7 +25,7 @@ public class BlockGoldDimDoor extends BaseDimDoor { if (!world.isRemote && world.getBlockId(x, y - 1, z) == this.blockID) { - NewDimData dimension = PocketManager.getDimensionData(world); + NewDimData dimension = PocketManager.createDimensionData(world); DimLink link = dimension.getLink(x, y, z); if (link == null) { diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/DimensionalDoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/DimensionalDoor.java index 3537a77..fc4f709 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/DimensionalDoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/DimensionalDoor.java @@ -22,7 +22,7 @@ public class DimensionalDoor extends BaseDimDoor { if (!world.isRemote && world.getBlockId(x, y - 1, z) == this.blockID) { - NewDimData dimension = PocketManager.getDimensionData(world); + NewDimData dimension = PocketManager.createDimensionData(world); DimLink link = dimension.getLink(x, y, z); if (link == null) { diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/TransTrapdoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/TransTrapdoor.java index d2eda14..52be329 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/TransTrapdoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/TransTrapdoor.java @@ -76,7 +76,7 @@ public class TransTrapdoor extends BlockTrapDoor implements IDimDoor, ITileEntit { if (!world.isRemote) { - NewDimData dimension = PocketManager.getDimensionData(world); + NewDimData dimension = PocketManager.createDimensionData(world); DimLink link = dimension.getLink(x, y, z); if (link == null && dimension.isPocketDimension()) { diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/TransientDoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/TransientDoor.java index 0eac631..9f56a63 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/TransientDoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/TransientDoor.java @@ -64,7 +64,7 @@ public class TransientDoor extends BaseDimDoor { if (!world.isRemote && world.getBlockId(x, y - 1, z) == this.blockID) { - NewDimData dimension = PocketManager.getDimensionData(world); + NewDimData dimension = PocketManager.createDimensionData(world); DimLink link = dimension.getLink(x, y, z); if (link == null && dimension.isPocketDimension()) { diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/UnstableDoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/UnstableDoor.java index 6f14c66..3a82941 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/UnstableDoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/UnstableDoor.java @@ -21,7 +21,7 @@ public class UnstableDoor extends BaseDimDoor { if (!world.isRemote && world.getBlockId(x, y - 1, z) == this.blockID) { - NewDimData dimension = PocketManager.getDimensionData(world); + NewDimData dimension = PocketManager.createDimensionData(world); dimension.createLink(x, y, z, LinkTypes.RANDOM,world.getBlockMetadata(x, y - 1, z)); } } diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/WarpDoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/WarpDoor.java index f860f6e..c9ed904 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/blocks/WarpDoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/blocks/WarpDoor.java @@ -22,7 +22,7 @@ public class WarpDoor extends BaseDimDoor { if (!world.isRemote && world.getBlockId(x, y - 1, z) == this.blockID) { - NewDimData dimension = PocketManager.getDimensionData(world); + NewDimData dimension = PocketManager.createDimensionData(world); DimLink link = dimension.getLink(x, y, z); if (link == null && dimension.isPocketDimension()) { diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java index 686b5d3..588457e 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java @@ -61,7 +61,7 @@ public class CommandCreateDungeonRift extends DDCommandBase // Check if we found any matches if (result != null) { - dimension = PocketManager.getDimensionData(sender.worldObj); + dimension = PocketManager.createDimensionData(sender.worldObj); link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON, orientation); if (PocketBuilder.generateSelectedDungeonPocket(link, mod_pocketDim.properties, result)) { diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreateRandomRift.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreateRandomRift.java index 646fda3..201279b 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreateRandomRift.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandCreateRandomRift.java @@ -53,7 +53,7 @@ public class CommandCreateRandomRift extends DDCommandBase if (command.length == 0) { - dimension = PocketManager.getDimensionData(sender.worldObj); + dimension = PocketManager.createDimensionData(sender.worldObj); link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON, orientation); sender.worldObj.setBlock(x, y + 1, z,mod_pocketDim.blockRift.blockID, 0, 3); sendChat(sender, "Created a rift to a random dungeon."); @@ -69,7 +69,7 @@ public class CommandCreateRandomRift extends DDCommandBase // Check if we found any matches if (result != null) { - dimension = PocketManager.getDimensionData(sender.worldObj); + dimension = PocketManager.createDimensionData(sender.worldObj); link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON, orientation); if (PocketBuilder.generateSelectedDungeonPocket(link, mod_pocketDim.properties, result)) { diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java index cc1a1a1..9a50857 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java @@ -63,7 +63,7 @@ public class CommandDeleteRifts extends DDCommandBase int y; int z; Point4D location; - NewDimData dimension = PocketManager.getDimensionData(targetDimension); + NewDimData dimension = PocketManager.createDimensionData(world); ArrayList links = dimension.getAllLinks(); for (DimLink link : links) { diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandTeleportPlayer.java b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandTeleportPlayer.java index b02222f..b001c7a 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandTeleportPlayer.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/commands/CommandTeleportPlayer.java @@ -80,7 +80,6 @@ public class CommandTeleportPlayer extends DDCommandBase else { dimensionID = targetPlayer.worldObj.provider.dimensionId; - // SenseiKiwi: Will not be used, but I prefer not to leave 'world' as null world = targetPlayer.worldObj; } @@ -95,7 +94,7 @@ public class CommandTeleportPlayer extends DDCommandBase if (command.length == 2) { // Check if the destination is a pocket dimension - dimension = PocketManager.getDimensionData(dimensionID); + dimension = PocketManager.createDimensionData(world); if (dimension.isPocketDimension()) { // The destination is a pocket dimension. diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java b/src/main/java/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java index debd31a..0c29491 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java @@ -227,7 +227,7 @@ public class DDTeleporter && blockID != properties.GoldenDimensionalDoorID) { //Return the pocket's orientation instead - return PocketManager.getDimensionData(door.getDimension()).orientation(); + return PocketManager.createDimensionData(world).orientation(); } //Return the orientation portion of its metadata @@ -294,7 +294,7 @@ public class DDTeleporter // to prevent us from doing bad things. Moreover, no dimension is being created, so if we ever // tie code to that, it could cause confusing bugs. // No hacky for you! ~SenseiKiwi - PocketManager.getDimwatcher().onCreated(new ClientDimData(PocketManager.getDimensionData(destination.getDimension()))); + PocketManager.getDimwatcher().onCreated(new ClientDimData(PocketManager.createDimensionData(newWorld))); // Set the new dimension and inform the client that it's moving to a new world. player.dimension = destination.getDimension(); @@ -552,7 +552,7 @@ public class DDTeleporter // To avoid loops, don't generate a destination if the player is // already in a non-pocket dimension. - NewDimData current = PocketManager.getDimensionData(link.link.point.getDimension()); + NewDimData current = PocketManager.getDimensionData(link.source().getDimension()); if (current.isPocketDimension()) { Point4D source = link.source(); @@ -606,9 +606,10 @@ public class DDTeleporter } } } + private static boolean generateSafeExit(DimLink link, DDProperties properties) { - NewDimData current = PocketManager.getDimensionData(link.link.point.getDimension()); + NewDimData current = PocketManager.getDimensionData(link.source().getDimension()); return generateSafeExit(current.root(), link, properties); } @@ -619,7 +620,7 @@ public class DDTeleporter // There is a chance of choosing the Nether first before other root dimensions // to compensate for servers with many Mystcraft ages or other worlds. - NewDimData current = PocketManager.getDimensionData(link.link.point.getDimension()); + NewDimData current = PocketManager.getDimensionData(link.source().getDimension()); ArrayList roots = PocketManager.getRootDimensions(); int shiftChance = START_ROOT_SHIFT_CHANCE + ROOT_SHIFT_CHANCE_PER_LEVEL * (current.packDepth() - 1); @@ -627,11 +628,11 @@ public class DDTeleporter { if (current.root().id() != OVERWORLD_DIMENSION_ID && random.nextInt(MAX_OVERWORLD_EXIT_CHANCE) < OVERWORLD_EXIT_CHANCE) { - return generateSafeExit(PocketManager.getDimensionData(OVERWORLD_DIMENSION_ID), link, properties); + return generateSafeExit(PocketManager.createDimensionDataDangerously(OVERWORLD_DIMENSION_ID), link, properties); } if (current.root().id() != NETHER_DIMENSION_ID && random.nextInt(MAX_NETHER_EXIT_CHANCE) < NETHER_EXIT_CHANCE) { - return generateSafeExit(PocketManager.getDimensionData(NETHER_DIMENSION_ID), link, properties); + return generateSafeExit(PocketManager.createDimensionDataDangerously(NETHER_DIMENSION_ID), link, properties); } for (int attempts = 0; attempts < 10; attempts++) { @@ -735,7 +736,7 @@ public class DDTeleporter // Create a reverse link for returning int orientation = getDestinationOrientation(source, properties); NewDimData sourceDim = PocketManager.getDimensionData(link.source().getDimension()); - DimLink reverse = destinationDim.createLink(x, y + 2, z, LinkTypes.REVERSE,orientation); + DimLink reverse = destinationDim.createLink(x, y + 2, z, LinkTypes.REVERSE, orientation); sourceDim.setLinkDestination(reverse, source.getX(), source.getY(), source.getZ()); // Set up the warp door at the destination diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java b/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java index a509c38..39d5cf3 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/core/PocketManager.java @@ -163,15 +163,15 @@ public class PocketManager public void onCreated(ClientLinkData link) { Point4D source = link.point; - NewDimData dimension = getDimensionData(source.getDimension()); - dimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.CLIENT_SIDE,link.orientation); + NewDimData dimension = createDimensionData(source.getDimension()); + dimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.CLIENT_SIDE, link.orientation); } @Override public void onDeleted(ClientLinkData link) { Point4D source = link.point; - getDimensionData(source.getDimension()).deleteLink(source); + createDimensionData(source.getDimension()).deleteLink(source); } } @@ -270,7 +270,6 @@ public class PocketManager public static boolean registerPackedDimData(PackedDimData packedData) { - InnerDimData dimData; //register roots if(packedData.ID==packedData.ParentID) @@ -290,7 +289,7 @@ public class PocketManager dimData = new InnerDimData(packedData.ID, test,true, packedData.IsDungeon, linkWatcher); dimData.isFilled=packedData.IsFilled; dimData.origin = new Point4D(packedData.Origin.getX(),packedData.Origin.getY(),packedData.Origin.getZ(),packedData.ID); - dimData.root=PocketManager.getDimensionData(packedData.RootID); + dimData.root = PocketManager.createDimensionData(packedData.RootID); if(packedData.DungeonData!=null) { @@ -412,9 +411,7 @@ public class PocketManager * loads the dim data from the saved hashMap. Also handles compatibility with old saves, see OldSaveHandler */ private static void loadInternal() - { - //System.out.println(!FMLCommonHandler.instance().getSide().isClient()); - + { File saveDir = DimensionManager.getCurrentSaveRootDirectory(); if (saveDir != null) { @@ -501,23 +498,19 @@ public class PocketManager return world; } - public static NewDimData registerDimension(World world) - { - return registerDimension(world.provider.dimensionId, null, false, false); - } - public static NewDimData registerPocket(NewDimData parent, boolean isDungeon) { if (parent == null) { throw new IllegalArgumentException("parent cannot be null. A pocket dimension must always have a parent dimension."); } - + DDProperties properties = DDProperties.instance(); int dimensionID = DimensionManager.getNextFreeDimId(); DimensionManager.registerDimension(dimensionID, properties.PocketProviderID); return registerDimension(dimensionID, (InnerDimData) parent, true, isDungeon); } + /** * Registers a dimension with DD but NOT with forge. * @param dimensionID @@ -548,16 +541,16 @@ public class PocketManager } @SideOnly(Side.CLIENT) - private static NewDimData registerClientDimension(int dimensionID, int rootID) + protected static NewDimData registerClientDimension(int dimensionID, int rootID) { - System.out.println("Registered dim "+dimensionID+" on the client."); - // No need to raise events heres since this code should only run on the client side - // getDimensionData() always handles root dimensions properly, even if the weren't defined before + // No need to raise events heres since this code should only run on the + // client side. createDimensionData() always handles root dimensions + // properly, even if they weren't defined before. - // SenseiKiwi: I'm a little worried about how getDimensionData will raise + // SenseiKiwi: I'm a little worried about how createDimensionData will raise // an event when it creates any root dimensions... Needs checking later. - InnerDimData root = (InnerDimData) getDimensionData(rootID); + InnerDimData root = (InnerDimData) createDimensionData(rootID); InnerDimData dimension; if (rootID != dimensionID) @@ -573,7 +566,7 @@ public class PocketManager { dimension = root; } - if(dimension.isPocketDimension()&&!DimensionManager.isDimensionRegistered(dimension.id())) + if (dimension.isPocketDimension() && !DimensionManager.isDimensionRegistered(dimension.id())) { //Im registering pocket dims here. I *think* we can assume that if its a pocket and we are //registering its dim data, we also need to register it with forge. @@ -584,26 +577,29 @@ public class PocketManager } return dimension; } - - public static NewDimData getDimensionData(World world) - { - return getDimensionData(world.provider.dimensionId); - } - + public static NewDimData getDimensionData(int dimensionID) { - //Retrieve the data for a dimension. If we don't have a record for that dimension, - //assume it's a non-pocket dimension that hasn't been initialized with us before - //and create a NewDimData instance for it. - //Any pocket dimension must be listed with PocketManager to have a dimension ID - //assigned, so it's safe to assume that any unknown dimensions don't belong to us. + return PocketManager.dimensionData.get(dimensionID); + } - //FIXME: What's the point of this condition? Most calls to this function will crash anyway! ~SenseiKiwi - if(PocketManager.dimensionData == null) - { - System.out.println("Something odd happend during shutdown"); - return null; - } + public static NewDimData createDimensionData(World world) + { + return createDimensionData(world.provider.dimensionId); + } + + public static NewDimData createDimensionDataDangerously(int dimensionID) + { + // Same as createDimensionData(int), but public. Meant to discourage anyone from + // using it unless absolutely needed! We'll probably phase this out eventually. + return createDimensionData(dimensionID); + } + + protected static NewDimData createDimensionData(int dimensionID) + { + // Retrieve the data for a dimension. If we don't have a record for that dimension, + // assume it's a non-pocket dimension that hasn't been initialized with us before + // and create a NewDimData instance for it. NewDimData dimension = PocketManager.dimensionData.get(dimensionID); if (dimension == null) { diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java b/src/main/java/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java index 7a443fc..07231c5 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java @@ -247,7 +247,7 @@ public class DungeonSchematic extends Schematic { world.setBlockTileEntity(pocketPoint.getX(), pocketPoint.getY(), pocketPoint.getZ(), TileEntity.createAndLoadEntity(tileTag)); } - setUpDungeon(PocketManager.getDimensionData(world), world, pocketCenter, turnAngle, entryLink, random, properties, blockSetter); + setUpDungeon(PocketManager.createDimensionData(world), world, pocketCenter, turnAngle, entryLink, random, properties, blockSetter); } private void setUpDungeon(NewDimData dimension, World world, Point3D pocketCenter, int turnAngle, DimLink entryLink, Random random, DDProperties properties, IBlockSetter blockSetter) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/src/main/java/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index 1605202..a4aae50 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -263,7 +263,7 @@ public class DungeonHelper public DimLink createCustomDungeonDoor(World world, int x, int y, int z) { //Create a link above the specified position. Link to a new pocket dimension. - NewDimData dimension = PocketManager.getDimensionData(world); + NewDimData dimension = PocketManager.createDimensionData(world); DimLink link = dimension.createLink(x, y + 1, z, LinkTypes.POCKET, 3); //Place a Warp Door linked to that pocket diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java index 84dbde6..48121fd 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java @@ -74,7 +74,7 @@ public class ItemRiftSignature extends Item // The link was used before and already has an endpoint stored. // Create links connecting the two endpoints. NewDimData sourceDimension = PocketManager.getDimensionData(source.getDimension()); - NewDimData destinationDimension = PocketManager.getDimensionData(world); + NewDimData destinationDimension = PocketManager.createDimensionData(world); DimLink link = sourceDimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.NORMAL,source.getOrientation()); DimLink reverse = destinationDimension.createLink(x, adjustedY, z, LinkTypes.NORMAL,orientation); destinationDimension.setLinkDestination(link, x, adjustedY, z); @@ -99,7 +99,7 @@ public class ItemRiftSignature extends Item else { //The link signature has not been used. Store its current target as the first location. - setSource(stack, x, adjustedY, z,orientation, PocketManager.getDimensionData(world)); + setSource(stack, x, adjustedY, z, orientation, PocketManager.createDimensionData(world)); mod_pocketDim.sendChat(player,("Location Stored in Rift Signature")); world.playSoundAtEntity(player,mod_pocketDim.modid+":riftStart", 0.6f, 1); } diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java index c06d598..94f4acb 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java @@ -53,7 +53,7 @@ public class ItemStabilizedRiftSignature extends ItemRiftSignature { // Yes, it's initialized. NewDimData sourceDimension = PocketManager.getDimensionData(source.getDimension()); - NewDimData destinationDimension = PocketManager.getDimensionData(world); + NewDimData destinationDimension = PocketManager.createDimensionData(world); DimLink reverse = destinationDimension.getLink(x, adjustedY, z); DimLink link; @@ -104,7 +104,7 @@ public class ItemStabilizedRiftSignature extends ItemRiftSignature else { // The link signature has not been used. Store its current target as the first location. - setSource(stack, x, adjustedY, z, orientation, PocketManager.getDimensionData(world)); + setSource(stack, x, adjustedY, z, orientation, PocketManager.createDimensionData(world)); mod_pocketDim.sendChat(player, "Location Stored in Stabilized Rift Signature"); world.playSoundAtEntity(player, "mods.DimDoors.sfx.riftStart", 0.6f, 1); } @@ -129,7 +129,7 @@ public class ItemStabilizedRiftSignature extends ItemRiftSignature if (source != null) { NewDimData sourceDimension = PocketManager.getDimensionData(source.getDimension()); - NewDimData destinationDimension = PocketManager.getDimensionData(world); + NewDimData destinationDimension = PocketManager.createDimensionData(world); DimLink reverse = destinationDimension.getLink(x, adjustedY, z); DimLink link; diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/items/itemRiftRemover.java b/src/main/java/StevenDimDoors/mod_pocketDim/items/itemRiftRemover.java index c95b472..e1ecef9 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/items/itemRiftRemover.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/items/itemRiftRemover.java @@ -54,7 +54,7 @@ public class itemRiftRemover extends Item int hx = hit.blockX; int hy = hit.blockY; int hz = hit.blockZ; - NewDimData dimension = PocketManager.getDimensionData(world); + NewDimData dimension = PocketManager.createDimensionData(world); DimLink link = dimension.getLink(hx, hy, hz); if (world.getBlockId(hx, hy, hz) == mod_pocketDim.blockRift.blockID && link != null && player.canPlayerEdit(hx, hy, hz, hit.sideHit, stack)) @@ -85,7 +85,7 @@ public class itemRiftRemover extends Item y = hit.blockY; z = hit.blockZ; - NewDimData dimension = PocketManager.getDimensionData(world); + NewDimData dimension = PocketManager.createDimensionData(world); DimLink link = dimension.getLink(x, y, z); if (world.getBlockId(x, y, z) == mod_pocketDim.blockRift.blockID && link != null && player.canPlayerEdit(x, y, z, side, stack)) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/saving/DDSaveHandler.java b/src/main/java/StevenDimDoors/mod_pocketDim/saving/DDSaveHandler.java index 3a7bb70..a0d214c 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/saving/DDSaveHandler.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/saving/DDSaveHandler.java @@ -189,7 +189,7 @@ public class DDSaveHandler { if(packedLink.parent.equals(fakePoint)) { - NewDimData data = PocketManager.getDimensionData(packedLink.source.getDimension()); + NewDimData data = PocketManager.createDimensionDataDangerously(packedLink.source.getDimension()); int linkType = packedLink.tail.linkType; if((linkType < LinkTypes.ENUM_MIN || linkType > LinkTypes.ENUM_MAX) && linkType != LinkTypes.CLIENT_SIDE) @@ -201,7 +201,7 @@ public class DDSaveHandler Point4D destination = packedLink.tail.destination; if(destination!=null) { - PocketManager.getDimensionData(destination.getDimension()).setLinkDestination(link, destination.getX(),destination.getY(),destination.getZ()); + PocketManager.createDimensionDataDangerously(destination.getDimension()).setLinkDestination(link, destination.getX(),destination.getY(),destination.getZ()); } unpackedLinks.add(packedLink); } @@ -213,7 +213,7 @@ public class DDSaveHandler { for(PackedLinkData packedLink : linksToUnpack) { - NewDimData data = PocketManager.getDimensionData(packedLink.source.getDimension()); + NewDimData data = PocketManager.createDimensionDataDangerously(packedLink.source.getDimension()); if(data.getLink(packedLink.parent)!=null) { data.createChildLink(packedLink.source.getX(), packedLink.source.getY(), packedLink.source.getZ(), data.getLink(packedLink.parent)); diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityDimDoorGold.java b/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityDimDoorGold.java index 093c1e8..6b9696e 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityDimDoorGold.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityDimDoorGold.java @@ -46,7 +46,7 @@ public class TileEntityDimDoorGold extends TileEntityDimDoor implements IChunkLo // link associated with it. if (!worldObj.isRemote) { - NewDimData dimension = PocketManager.getDimensionData(worldObj); + NewDimData dimension = PocketManager.createDimensionData(worldObj); // Check whether a ticket has already been assigned to this door if (chunkTicket == null) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityRift.java b/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityRift.java index 62bb62b..cf6df98 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityRift.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityRift.java @@ -137,7 +137,7 @@ public class TileEntityRift extends DDTileEntityBase private void closeRift() { - NewDimData dimension = PocketManager.getDimensionData(worldObj); + NewDimData dimension = PocketManager.createDimensionData(worldObj); if (closeTimer == CLOSING_PERIOD / 2) { for (DimLink riftLink : dimension.findRiftsInRange(worldObj, 6, xCoord, yCoord, zCoord)) @@ -167,7 +167,7 @@ public class TileEntityRift extends DDTileEntityBase public boolean updateNearestRift() { Point4D previousNearest = nearestRiftLocation; - DimLink nearestRiftLink = PocketManager.getDimensionData(worldObj).findNearestRift( + DimLink nearestRiftLink = PocketManager.createDimensionData(worldObj).findNearestRift( worldObj, RIFT_INTERACTION_RANGE, xCoord, yCoord, zCoord); nearestRiftLocation = (nearestRiftLink == null) ? null : nearestRiftLink.source(); @@ -221,7 +221,7 @@ public class TileEntityRift extends DDTileEntityBase return; } - NewDimData dimension = PocketManager.getDimensionData(worldObj); + NewDimData dimension = PocketManager.createDimensionData(worldObj); DimLink link = dimension.getLink(xCoord, yCoord, zCoord); if (link.childCount() >= MAX_CHILD_LINKS || countAncestorLinks(link) >= MAX_ANCESTOR_LINKS) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java b/src/main/java/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java index 515fbee..fb29525 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java @@ -3,6 +3,7 @@ package StevenDimDoors.mod_pocketDim.world; import java.util.Random; import net.minecraft.block.Block; +import net.minecraft.item.ItemDoor; import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; @@ -21,7 +22,6 @@ import StevenDimDoors.mod_pocketDim.dungeon.DungeonSchematic; import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonPackConfig; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper; -import StevenDimDoors.mod_pocketDim.items.ItemDimensionalDoor; import StevenDimDoors.mod_pocketDim.schematic.BlockRotator; import StevenDimDoors.mod_pocketDim.util.Pair; import StevenDimDoors.mod_pocketDim.util.Point4D; @@ -40,87 +40,6 @@ public class PocketBuilder private PocketBuilder() { } - /** - * Method that takes an arbitrary link into a dungeon pocket and tries to regenerate it. First uses the origin to find that link, - * then uses that link to find the link that originally created the dungeon. If it cant find any of these, it - * instead makes the link that lead to this point into an exit door style link, sending the player to the overworld. - * @param dimension The dungeon to be regenerated - * @param linkIn The link leading somewhere into the dungeon. - * @param properties - * @return - */ - - public static boolean regenerateDungeonPocket(NewDimData dimension, DimLink linkIn, DDProperties properties) - { - if (linkIn == null) - { - throw new IllegalArgumentException("link cannot be null."); - } - if (properties == null) - { - throw new IllegalArgumentException("properties cannot be null."); - } - //The link that is at the origin of the dungeon - DimLink originLink = dimension.getLink(dimension.origin()); - Point4D oldLinkPos = linkIn.source(); - if(originLink==null) - { - int orientation = linkIn.orientation(); - originLink=dimension.createLink(oldLinkPos, LinkTypes.SAFE_EXIT, (orientation+2)%4); - return false; - } - //The link that originally created the dungeon on the way in - DimLink incomingLink = PocketManager.getLink(originLink.destination()); - if(incomingLink==null||incomingLink.linkType()!=LinkTypes.DUNGEON||!(originLink.linkType()==LinkTypes.REVERSE)) - { - int orientation = linkIn.orientation(); - dimension.deleteLink(originLink); - dimension.createLink(oldLinkPos, LinkTypes.SAFE_EXIT, (orientation+2)%4); - return false; - } - NewDimData parent = PocketManager.getDimensionData(incomingLink.source().getDimension()); - - if (!dimension.isDungeon()) - { - throw new IllegalArgumentException("destination must be dungeon"); - } - if (dimension.isFilled()) - { - throw new IllegalArgumentException("destination must be empty"); - } - if (!dimension.isInitialized()) - { - throw new IllegalArgumentException("destination must already exist"); - } - - try - { - //Load a world - World world = PocketManager.loadDimension(dimension.id()); - - if (world == null || world.provider == null) - { - System.err.println("Could not initialize dimension for a dungeon!"); - return false; - } - - DungeonSchematic schematic = loadAndValidateDungeon(dimension.dungeon(), properties); - if (schematic == null) - { - return false; - } - Point3D destination = new Point3D(incomingLink.destination()); - schematic.copyToWorld(world, destination, originLink.orientation(), incomingLink, random, properties, false); - dimension.setFilled(true); - return true; - } - catch (Exception e) - { - e.printStackTrace(); - return false; - } - } - private static boolean buildDungeonPocket(DungeonData dungeon, NewDimData dimension, DimLink link, DungeonSchematic schematic, World world, DDProperties properties) { //Calculate the destination point @@ -479,7 +398,7 @@ public class PocketBuilder //Build the door int doorOrientation = BlockRotator.transformMetadata(BlockRotator.EAST_DOOR_METADATA, orientation - BlockRotator.EAST_DOOR_METADATA + 2, properties.DimensionalDoorID); - ItemDimensionalDoor.placeDoorBlock(world, x, y - 1, z, doorOrientation, doorBlock); + ItemDoor.placeDoorBlock(world, x, y - 1, z, doorOrientation, doorBlock); } private static void buildBox(World world, int centerX, int centerY, int centerZ, int radius, int blockID, boolean placeTnt, int nonTntWeight) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/world/PocketGenerator.java b/src/main/java/StevenDimDoors/mod_pocketDim/world/PocketGenerator.java index 2299677..df99d03 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/world/PocketGenerator.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/world/PocketGenerator.java @@ -68,7 +68,7 @@ public class PocketGenerator extends ChunkProviderGenerate @Override public List getPossibleCreatures(EnumCreatureType var1, int var2, int var3, int var4) { - NewDimData dimension = PocketManager.getDimensionData(this.worldObj); + NewDimData dimension = PocketManager.createDimensionData(this.worldObj); if (dimension != null && dimension.dungeon() != null && !dimension.dungeon().isOpen()) { return this.worldObj.getBiomeGenForCoords(var2, var3).getSpawnableList(var1); diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/world/PocketProvider.java b/src/main/java/StevenDimDoors/mod_pocketDim/world/PocketProvider.java index 08924d8..910d0fb 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/world/PocketProvider.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/world/PocketProvider.java @@ -7,7 +7,6 @@ import net.minecraft.world.WorldProvider; import net.minecraft.world.biome.WorldChunkManagerHell; import net.minecraft.world.chunk.IChunkProvider; import net.minecraftforge.client.IRenderHandler; -import net.minecraftforge.common.DimensionManager; import StevenDimDoors.mod_pocketDim.CloudRenderBlank; import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.config.DDProperties; @@ -103,11 +102,8 @@ public class PocketProvider extends WorldProvider { respawnDim = PocketManager.getDimensionData(this.dimensionId).root().id(); } - - if (DimensionManager.getWorld(respawnDim) == null) - { - DimensionManager.initDimension(respawnDim); - } + // TODO: Are we sure we need to load the dimension as well? Why can't the game handle that? + PocketManager.loadDimension(respawnDim); return respawnDim; } diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/world/fortresses/ComponentNetherGateway.java b/src/main/java/StevenDimDoors/mod_pocketDim/world/fortresses/ComponentNetherGateway.java index db6ef44..8a63b40 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/world/fortresses/ComponentNetherGateway.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/world/fortresses/ComponentNetherGateway.java @@ -154,7 +154,7 @@ public class ComponentNetherGateway extends StructureComponent if (bounds.isVecInside(x, y, z) && bounds.isVecInside(x, y + 1, z)) { orientation = this.getMetadataWithOffset(Block.doorWood.blockID, 1); - dimension = PocketManager.getDimensionData(world); + dimension = PocketManager.createDimensionData(world); link = dimension.getLink(x, y + 1, z); if (link == null) { diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/world/gateways/BaseSchematicGateway.java b/src/main/java/StevenDimDoors/mod_pocketDim/world/gateways/BaseSchematicGateway.java index 6eaa0da..c94554d 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/world/gateways/BaseSchematicGateway.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/world/gateways/BaseSchematicGateway.java @@ -44,7 +44,7 @@ public abstract class BaseSchematicGateway extends BaseGateway this.generateRandomBits(world, x, y, z); // Generate a dungeon link in the door - PocketManager.getDimensionData(world).createLink(x, y + doorLocation.getY(), z, LinkTypes.DUNGEON, orientation); + PocketManager.createDimensionData(world).createLink(x, y + doorLocation.getY(), z, LinkTypes.DUNGEON, orientation); return true; } diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/world/gateways/GatewayGenerator.java b/src/main/java/StevenDimDoors/mod_pocketDim/world/gateways/GatewayGenerator.java index dfd855a..19b4ba4 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/world/gateways/GatewayGenerator.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/world/gateways/GatewayGenerator.java @@ -106,7 +106,7 @@ public class GatewayGenerator implements IWorldGenerator //Create a link. If this is not the first time, create a child link and connect it to the first link. if (link == null) { - dimension = PocketManager.getDimensionData(world); + dimension = PocketManager.createDimensionData(world); link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON,0); } else diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/world/gateways/GatewayLimbo.java b/src/main/java/StevenDimDoors/mod_pocketDim/world/gateways/GatewayLimbo.java index cb50437..665dbd8 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/world/gateways/GatewayLimbo.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/world/gateways/GatewayLimbo.java @@ -30,7 +30,7 @@ public class GatewayLimbo extends BaseGateway world.setBlock(x, y + 1, z - 1, blockID, 0, 3); world.setBlock(x, y + 1, z + 1, blockID, 0, 3); - PocketManager.getDimensionData(world).createLink(x, y + 2, z, LinkTypes.DUNGEON, 0); + PocketManager.createDimensionData(world).createLink(x, y + 2, z, LinkTypes.DUNGEON, 0); ItemDoor.placeDoorBlock(world, x, y + 1, z, 0, mod_pocketDim.transientDoor); return true; } diff --git a/src/main/java/StevenDimDoors/mod_pocketDimClient/ClosingRiftFX.java b/src/main/java/StevenDimDoors/mod_pocketDimClient/ClosingRiftFX.java index 2ea3239..a36d77c 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDimClient/ClosingRiftFX.java +++ b/src/main/java/StevenDimDoors/mod_pocketDimClient/ClosingRiftFX.java @@ -100,7 +100,7 @@ public class ClosingRiftFX extends EntityFX float var15 = (float)(this.prevPosZ + (this.posZ - this.prevPosZ) * par2 - interpPosZ); float var16 = 0.8F; - if (PocketManager.getDimensionData(worldObj).isPocketDimension()) + if (PocketManager.createDimensionData(worldObj).isPocketDimension()) { var16 = 0.4F; } diff --git a/src/main/java/StevenDimDoors/mod_pocketDimClient/GoggleRiftFX.java b/src/main/java/StevenDimDoors/mod_pocketDimClient/GoggleRiftFX.java index 069d58f..9845af8 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDimClient/GoggleRiftFX.java +++ b/src/main/java/StevenDimDoors/mod_pocketDimClient/GoggleRiftFX.java @@ -54,7 +54,7 @@ public class GoggleRiftFX extends EntityFireworkSparkFX float var15 = (float)(this.prevPosZ + (this.posZ - this.prevPosZ) * par2 - interpPosZ); float var16 = .0F; - if (PocketManager.getDimensionData(worldObj).isPocketDimension()) + if (PocketManager.createDimensionData(worldObj).isPocketDimension()) { var16 = .7F; } diff --git a/src/main/java/StevenDimDoors/mod_pocketDimClient/RiftFX.java b/src/main/java/StevenDimDoors/mod_pocketDimClient/RiftFX.java index 7f4dc94..f564180 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDimClient/RiftFX.java +++ b/src/main/java/StevenDimDoors/mod_pocketDimClient/RiftFX.java @@ -111,7 +111,7 @@ public class RiftFX extends EntityFX float f13 = (float)(this.prevPosZ + (this.posZ - this.prevPosZ) * par2 - interpPosZ); float f14 = 0F; - if (PocketManager.getDimensionData(worldObj).isPocketDimension()) + if (PocketManager.createDimensionData(worldObj).isPocketDimension()) { f14 = 0.7F; } From 20db828ac05577d7952c604a8f6731dc2eef18a0 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Tue, 15 Jul 2014 14:51:46 -0400 Subject: [PATCH 47/47] Fixed Crash on Rift Removal Fixed a crash from manipulating rift data on the client side. I let this happen because it seemed like TileEntityRift already did that before. This crash also exposed another issue: that server-side functions are being used on the client side. I'm not sure how pervasive this is but some client dimensions are being constructed with the server-side constructor. --- .../mod_pocketDim/tileentities/TileEntityRift.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityRift.java b/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityRift.java index cf6df98..5e8dd9c 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityRift.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityRift.java @@ -151,7 +151,7 @@ public class TileEntityRift extends DDTileEntityBase } } } - if (closeTimer >= CLOSING_PERIOD) + if (closeTimer >= CLOSING_PERIOD && !worldObj.isRemote) { DimLink link = PocketManager.getLink(this.xCoord, this.yCoord, this.zCoord, worldObj); if (link != null)