From 0c7da8a54c097493e291f2420f308e7429e2d192 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Fri, 2 Aug 2013 04:54:24 -0400 Subject: [PATCH 01/12] Minor Improvements to DungeonHelper Minor improvements to DungeonHelper. Cleaned up constants a bit and added a new constant. --- .../mod_pocketDim/helpers/DungeonHelper.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index 0a280db..a99d503 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -35,17 +35,15 @@ public class DungeonHelper private static final String DEFAULT_DOWN_SCHEMATIC_PATH = "/schematics/core/simpleStairsDown.schematic"; private static final String DEFAULT_ERROR_SCHEMATIC_PATH = "/schematics/core/somethingBroke.schematic"; private static final String BUNDLED_DUNGEONS_LIST_PATH = "/schematics/schematics.txt"; + private static final String DUNGEON_CREATION_GUIDE_SOURCE_PATH = "/mods/DimDoors/text/How_to_add_dungeons.txt"; public static final String SCHEMATIC_FILE_EXTENSION = ".schematic"; private static final int DEFAULT_DUNGEON_WEIGHT = 100; public static final int MAX_DUNGEON_WEIGHT = 10000; //Used to prevent overflows and math breaking down private static final int MAX_EXPORT_RADIUS = 50; public static final short MAX_DUNGEON_WIDTH = 2 * MAX_EXPORT_RADIUS + 1; - public static final short MAX_DUNGEON_HEIGHT = 2 * MAX_EXPORT_RADIUS + 1; - public static final short MAX_DUNGEON_LENGTH = 2 * MAX_EXPORT_RADIUS + 1; - - public static final int FABRIC_OF_REALITY_EXPORT_ID = 1973; - public static final int PERMAFABRIC_EXPORT_ID = 220; + public static final short MAX_DUNGEON_HEIGHT = MAX_DUNGEON_WIDTH; + public static final short MAX_DUNGEON_LENGTH = MAX_DUNGEON_WIDTH; private static final String HUB_DUNGEON_TYPE = "Hub"; private static final String TRAP_DUNGEON_TYPE = "Trap"; @@ -145,7 +143,7 @@ public class DungeonHelper File file = new File(properties.CustomSchematicDirectory); if (file.exists() || file.mkdir()) { - copyfile.copyFile("/mods/DimDoors/text/How_to_add_dungeons.txt", file.getAbsolutePath() + "/How_to_add_dungeons.txt"); + copyfile.copyFile(DUNGEON_CREATION_GUIDE_SOURCE_PATH, file.getAbsolutePath() + "/How_to_add_dungeons.txt"); } registerBundledDungeons(); importCustomDungeons(properties.CustomSchematicDirectory); -- 2.39.5 From b050c6c61be571706ed0d57be5fc6b6a9af96c09 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Fri, 2 Aug 2013 07:48:44 -0400 Subject: [PATCH 02/12] Improved Metadata Rotation Code Simplified metadata rotation code by only having a single function that rotates metadata by 90 degrees clockwise and applying it repeatedly for 180 and 270 degree rotations. Removed flipDoorMetadata() from dimHelper and replaced all references to it with references to BlockRotator. This makes all our rotations reference a single function. Replaced hardcoded rotation in DungeonSchematic. Added support for wood (tree trunk) and quartz pillar metadata rotations. --- .../mod_pocketDim/blocks/ExitDoor.java | 5 +- .../mod_pocketDim/blocks/dimDoor.java | 5 +- .../dungeon/DungeonSchematic.java | 8 +- .../mod_pocketDim/helpers/dimHelper.java | 41 +- .../mod_pocketDim/schematic/BlockRotator.java | 951 +++++------------- 5 files changed, 263 insertions(+), 747 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/blocks/ExitDoor.java b/StevenDimDoors/mod_pocketDim/blocks/ExitDoor.java index b2d8833..1c95062 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/ExitDoor.java +++ b/StevenDimDoors/mod_pocketDim/blocks/ExitDoor.java @@ -7,12 +7,14 @@ import StevenDimDoors.mod_pocketDim.LinkData; import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.helpers.dimHelper; import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper; +import StevenDimDoors.mod_pocketDim.schematic.BlockRotator; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.creativetab.CreativeTabs; @@ -67,7 +69,8 @@ public class ExitDoor extends dimDoor dimHelper.instance.createLink(locDimID, ExitDimID, par2, par3, par4, par2, yCoord, par4,par1World.getBlockMetadata(par2, par3-1, par4)); - dimHelper.instance.createLink(ExitDimID, locDimID, par2, yCoord, par4, par2, par3, par4,dimHelper.instance.flipDoorMetadata(par1World.getBlockMetadata(par2, par3-1, par4))); + dimHelper.instance.createLink(ExitDimID, locDimID, par2, yCoord, par4, par2, par3, par4, + BlockRotator.transformMetadata(par1World.getBlockMetadata(par2, par3 - 1, par4), 2, Block.doorWood.blockID)); } diff --git a/StevenDimDoors/mod_pocketDim/blocks/dimDoor.java b/StevenDimDoors/mod_pocketDim/blocks/dimDoor.java index e05ba82..c172c67 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/dimDoor.java +++ b/StevenDimDoors/mod_pocketDim/blocks/dimDoor.java @@ -7,6 +7,7 @@ import StevenDimDoors.mod_pocketDim.LinkData; import StevenDimDoors.mod_pocketDim.TileEntityDimDoor; import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.helpers.dimHelper; +import StevenDimDoors.mod_pocketDim.schematic.BlockRotator; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; @@ -150,7 +151,7 @@ public class dimDoor extends BlockContainer if(par1World.getBlockMetadata(par2, par3-1, par4)==var12) { - var12=dimHelper.instance.flipDoorMetadata(var12); + var12 = BlockRotator.transformMetadata(var12, 2, Block.doorWood.blockID); } par1World.setBlockMetadataWithNotify(par2, par3-1, par4, var12,2); @@ -165,7 +166,7 @@ public class dimDoor extends BlockContainer int var12 = (int) (MathHelper.floor_double((double)((par5EntityPlayer.rotationYaw+90) * 4.0F / 360.0F) + 0.5D) & 3); if(par1World.getBlockMetadata(par2, par3, par4)==var12) { - var12=dimHelper.instance.flipDoorMetadata(var12); + var12 = BlockRotator.transformMetadata(var12, 2, Block.doorWood.blockID); } par1World.setBlockMetadataWithNotify(par2, par3, par4, var12,2); diff --git a/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java b/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java index 4247b39..a870785 100644 --- a/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java +++ b/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java @@ -102,7 +102,9 @@ public class DungeonSchematic extends Schematic { MONOLITH_SPAWN_MARKER_ID, EXIT_DOOR_MARKER_ID); applyFilter(finder); - orientation = (finder.getEntranceOrientation() + 2) & 3; //Flip the entrance's orientation to get the dungeon's orientation + //Flip the entrance's orientation to get the dungeon's orientation + orientation = BlockRotator.transformMetadata(finder.getEntranceOrientation(), 2, Block.doorWood.blockID); + entranceDoorLocation = finder.getEntranceDoorLocation(); exitDoorLocations = finder.getExitDoorLocations(); dimensionalDoorLocations = finder.getDimensionalDoorLocations(); @@ -195,7 +197,7 @@ public class DungeonSchematic extends Schematic { pocketPoint.setZ(dz); blockID = blocks[index]; BlockRotator.transformPoint(pocketPoint, entranceDoorLocation, turnAngle, pocketCenter); - blockMeta = BlockRotator.transformMetadata(metadata[index], turnAngle + BlockRotator.NORTH_DOOR_METADATA, blockID); + blockMeta = BlockRotator.transformMetadata(metadata[index], turnAngle, blockID); //In the future, we might want to make this more efficient by building whole chunks at a time setBlockDirectly(world, pocketPoint.getX(), pocketPoint.getY(), pocketPoint.getZ(), blockID, blockMeta); @@ -353,7 +355,7 @@ public class DungeonSchematic extends Schematic { sideLink.locXCoord, sideLink.locYCoord, sideLink.locZCoord, - dimHelper.instance.flipDoorMetadata(sideLink.linkOrientation)); + BlockRotator.transformMetadata(sideLink.linkOrientation, 2, Block.doorWood.blockID)); if (world.getBlockId(linkDestination.getX(), linkDestination.getY() - 3, linkDestination.getZ()) == properties.FabricBlockID) { diff --git a/StevenDimDoors/mod_pocketDim/helpers/dimHelper.java b/StevenDimDoors/mod_pocketDim/helpers/dimHelper.java index 62ca080..1cdf6be 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/dimHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/dimHelper.java @@ -43,6 +43,7 @@ import StevenDimDoors.mod_pocketDim.SchematicLoader; import StevenDimDoors.mod_pocketDim.TileEntityRift; import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.dungeon.DungeonSchematic; +import StevenDimDoors.mod_pocketDim.schematic.BlockRotator; import StevenDimDoors.mod_pocketDim.world.LimboProvider; import StevenDimDoors.mod_pocketDim.world.PocketProvider; import cpw.mods.fml.common.FMLCommonHandler; @@ -92,44 +93,6 @@ public class dimHelper extends DimensionManager public static final int DEFAULT_POCKET_SIZE = 39; public static final int DEFAULT_POCKET_WALL_THICKNESS = 5; public static final int MAX_WORLD_HEIGHT = 254; - //Stupid function I use because I don't understand bitwise operations yet. Used in door orientation - //TODO get rid of this - public int flipDoorMetadata(int data) - { - if(data==0) - { - return 2; - } - if(data==1) - { - return 3; - } - if(data==2) - { - return 0; - } - if(data==3) - { - return 1; - } - if(data==4) - { - return 6; - } - if(data==5) - { - return 7; - } - if(data==6) - { - return 4; - } - if(data==7) - { - return 5; - } - else return -10; - } public int getDimDepth(int DimID) { @@ -849,7 +812,7 @@ public class dimHelper extends DimensionManager PacketHandler.onDimCreatedPacket(destDimData); } link = this.createLink(DimensionManager.getWorld(link.locDimID).provider.dimensionId,dimensionID,link.locXCoord,link.locYCoord,link.locZCoord, link.destXCoord,constrainPocketY(link.destYCoord),link.destZCoord,link.linkOrientation); //creates and registers the two rifts that link the parent and pocket dim. - this.createLink(dimensionID,DimensionManager.getWorld(link.locDimID).provider.dimensionId, link.destXCoord,constrainPocketY(link.destYCoord),link.destZCoord, link.locXCoord,link.locYCoord,link.locZCoord, this.flipDoorMetadata(link.linkOrientation)); + this.createLink(dimensionID,DimensionManager.getWorld(link.locDimID).provider.dimensionId, link.destXCoord,constrainPocketY(link.destYCoord),link.destZCoord, link.locXCoord,link.locYCoord,link.locZCoord, BlockRotator.transformMetadata(link.linkOrientation, 2, Block.doorWood.blockID)); return link; } diff --git a/StevenDimDoors/mod_pocketDim/schematic/BlockRotator.java b/StevenDimDoors/mod_pocketDim/schematic/BlockRotator.java index fded0a4..18b0ee1 100644 --- a/StevenDimDoors/mod_pocketDim/schematic/BlockRotator.java +++ b/StevenDimDoors/mod_pocketDim/schematic/BlockRotator.java @@ -1,7 +1,5 @@ package StevenDimDoors.mod_pocketDim.schematic; -import java.util.ArrayList; - import net.minecraft.block.Block; import net.minecraft.block.BlockComparator; import net.minecraft.block.BlockDoor; @@ -17,720 +15,269 @@ public class BlockRotator //until we can rewrite it. public final static int EAST_DOOR_METADATA = 0; - private final static int SOUTH_DOOR_METADATA = 1; - private final static int WEST_DOOR_METADATA = 2; - public final static int NORTH_DOOR_METADATA = 3; + private final static int BLOCK_ID_COUNT = 4096; - private final static ArrayList metadataFlipList = new ArrayList(); + //Provides a fast lookup table for whether blocks have orientations + private final static boolean[] hasOrientations = new boolean[BLOCK_ID_COUNT]; static { - metadataFlipList.add(Block.dispenser.blockID); - metadataFlipList.add(Block.stairsStoneBrick.blockID); - metadataFlipList.add(Block.lever.blockID); - metadataFlipList.add(Block.stoneButton.blockID); - metadataFlipList.add(Block.redstoneRepeaterIdle.blockID); - metadataFlipList.add(Block.redstoneRepeaterActive.blockID); - metadataFlipList.add(Block.tripWireSource.blockID); - metadataFlipList.add(Block.torchWood.blockID); - metadataFlipList.add(Block.torchRedstoneIdle.blockID); - metadataFlipList.add(Block.torchRedstoneActive.blockID); - metadataFlipList.add(Block.doorIron.blockID); - metadataFlipList.add(Block.doorWood.blockID); - metadataFlipList.add(Block.pistonBase.blockID); - metadataFlipList.add(Block.pistonStickyBase.blockID); - metadataFlipList.add(Block.pistonExtension.blockID); - metadataFlipList.add(Block.redstoneComparatorIdle.blockID); - metadataFlipList.add(Block.redstoneComparatorActive.blockID); - metadataFlipList.add(Block.signPost.blockID); - metadataFlipList.add(Block.signWall.blockID); - metadataFlipList.add(Block.skull.blockID); - metadataFlipList.add(Block.ladder.blockID); - metadataFlipList.add(Block.vine.blockID); - metadataFlipList.add(Block.anvil.blockID); - metadataFlipList.add(Block.chest.blockID); - metadataFlipList.add(Block.chestTrapped.blockID); - metadataFlipList.add(Block.hopperBlock.blockID); - metadataFlipList.add(Block.stairsNetherBrick.blockID); - metadataFlipList.add(Block.stairsCobblestone.blockID); - metadataFlipList.add(Block.stairsNetherBrick.blockID); - metadataFlipList.add(Block.stairsNetherQuartz.blockID); - metadataFlipList.add(Block.stairsSandStone.blockID); - metadataFlipList.add(mod_pocketDim.dimDoor.blockID); - metadataFlipList.add(mod_pocketDim.ExitDoor.blockID); + hasOrientations[Block.dispenser.blockID] = true; + hasOrientations[Block.stairsStoneBrick.blockID] = true; + hasOrientations[Block.lever.blockID] = true; + hasOrientations[Block.stoneButton.blockID] = true; + hasOrientations[Block.redstoneRepeaterIdle.blockID] = true; + hasOrientations[Block.redstoneRepeaterActive.blockID] = true; + hasOrientations[Block.tripWireSource.blockID] = true; + hasOrientations[Block.torchWood.blockID] = true; + hasOrientations[Block.torchRedstoneIdle.blockID] = true; + hasOrientations[Block.torchRedstoneActive.blockID] = true; + hasOrientations[Block.doorIron.blockID] = true; + hasOrientations[Block.doorWood.blockID] = true; + hasOrientations[Block.pistonBase.blockID] = true; + hasOrientations[Block.pistonStickyBase.blockID] = true; + hasOrientations[Block.pistonExtension.blockID] = true; + hasOrientations[Block.redstoneComparatorIdle.blockID] = true; + hasOrientations[Block.redstoneComparatorActive.blockID] = true; + hasOrientations[Block.signPost.blockID] = true; + hasOrientations[Block.signWall.blockID] = true; + hasOrientations[Block.skull.blockID] = true; + hasOrientations[Block.ladder.blockID] = true; + hasOrientations[Block.vine.blockID] = true; + hasOrientations[Block.anvil.blockID] = true; + hasOrientations[Block.chest.blockID] = true; + hasOrientations[Block.chestTrapped.blockID] = true; + hasOrientations[Block.hopperBlock.blockID] = true; + hasOrientations[Block.stairsNetherBrick.blockID] = true; + hasOrientations[Block.stairsCobblestone.blockID] = true; + hasOrientations[Block.stairsNetherBrick.blockID] = true; + hasOrientations[Block.stairsNetherQuartz.blockID] = true; + hasOrientations[Block.stairsSandStone.blockID] = true; + hasOrientations[Block.wood.blockID] = true; + hasOrientations[Block.blockNetherQuartz.blockID] = true; + hasOrientations[mod_pocketDim.dimDoor.blockID] = true; + hasOrientations[mod_pocketDim.ExitDoor.blockID] = true; } - public static int transformMetadata(int metadata, int orientation, int blockID) + public static int transformMetadata(int metadata, int turns, int blockID) + { + //I changed rotations to reduce the monstrous code we had. It might be + //slightly less efficient, but it's easier to maintain for now. ~SenseiKiwi + + //Correct negative turns and get the minimum number of rotations needed + turns += 1 << 16; + turns %= 4; + + if (hasOrientations[blockID]) + { + while (turns > 0) + { + metadata = rotateMetadataBy90(metadata, blockID); + turns--; + } + } + return metadata; + } + + private static int rotateMetadataBy90(int metadata, int blockID) { //TODO: Replace this horrible function with something prettier. We promise we will for the next version, - //after switching to MC 1.6. PADRE, PLEASE FORGIVE ME. - - //Hax to fix negative orientations - orientation += 1 << 16; - orientation %= 4; - - if (metadataFlipList.contains(blockID)) + //after switching to MC 1.6. PADRE, PLEASE FORGIVE OUR SINS. + + if (blockID == Block.wood.blockID) { - switch (orientation) + if (metadata >= 4 && metadata < 12) { - case EAST_DOOR_METADATA: + return (metadata % 8) + 4; + } + } + else if (blockID == Block.blockNetherQuartz.blockID) + { + if (metadata == 3 || metadata == 4) + { + return (metadata - 2) % 2 + 3; + } + } + else if (Block.blocksList[blockID] instanceof BlockStairs) + { - if (blockID == Block.hopperBlock.blockID) - { - switch (metadata) - { - case 2: - metadata = 5; - break; - case 3: - metadata = 4; - break; - case 4: - metadata = 2; - break; - case 5: - metadata = 3; - break; - } - } - if(Block.blocksList[blockID] instanceof BlockStairs) - { - - switch (metadata) - { - case 0: - metadata = 2; - break; - case 1: - metadata = 3; - break; - case 2: - metadata = 1; - break; - case 3: - metadata = 0; - break; - case 7: - metadata = 4; - break; - case 6: - metadata = 5; - break; - case 5: - metadata = 7; - break; - case 4: - metadata = 6; - break; - - } - } - - else if(blockID== Block.chest.blockID||blockID== Block.chestTrapped.blockID||blockID== Block.ladder.blockID) - { - switch (metadata) - { - - case 2: - metadata = 5; - break; - case 3: - metadata = 4; - break; - case 4: - metadata = 2; - break; - case 5: - metadata = 3; - break; - } - - } - else if (blockID==Block.vine.blockID) - { - switch (metadata) - { - - case 1: - metadata = 2; - break; - case 2: - metadata = 4; - break; - case 4: - metadata = 8; - break; - case 8: - metadata = 1; - break; - } - } - else if(blockID== Block.lever.blockID||blockID== Block.stoneButton.blockID||blockID== Block.woodenButton.blockID||blockID== Block.torchWood.blockID||blockID== Block.torchRedstoneIdle.blockID||blockID== Block.torchRedstoneActive.blockID) - { - switch (metadata) - { - case 12: - metadata = 9; - break; - case 11: - metadata = 10; - break; - case 10: - metadata = 12; - break; - case 9: - metadata = 11; - break; - case 2: - metadata = 4; - break; - case 3: - metadata = 2; - break; - case 1: - metadata = 3; - break; - case 4: - metadata = 1; - break; - } - } - else if(blockID== Block.pistonBase.blockID||blockID==Block.pistonExtension.blockID||blockID==Block.pistonStickyBase.blockID||blockID==Block.dispenser.blockID||blockID==Block.dropper.blockID) - { - switch (metadata) - { - case 4: - metadata = 2; - break; - case 5: - metadata = 3; - break; - case 13: - metadata = 11; - break; - case 12: - metadata = 10; - break; - case 3: - metadata = 4; - break; - case 2: - metadata = 5; - break; - case 11: - metadata = 12; - break; - case 10: - metadata = 13; - break; - } - } - else if(Block.blocksList[blockID] instanceof BlockRedstoneRepeater || Block.blocksList[blockID] instanceof BlockDoor || Block.blocksList[blockID] instanceof dimDoor || blockID== Block.tripWireSource.blockID || Block.blocksList[blockID] instanceof BlockComparator) - { - switch (metadata) - { - case 0: - metadata = 1; - break; - case 1: - metadata = 2; - break; - case 2: - metadata = 3; - break; - case 3: - metadata = 0; - break; - case 4: - metadata = 5; - break; - case 5: - metadata = 6; - break; - case 6: - metadata = 7; - break; - case 7: - metadata = 4; - break; - case 8: - metadata = 9; - break; - case 9: - metadata = 10; - break; - case 10: - metadata = 11; - break; - case 11: - metadata = 8; - break; - case 12: - metadata = 13; - break; - case 13: - metadata = 14; - break; - case 14: - metadata = 15; - break; - case 15: - metadata = 12; - break; - } - } + switch (metadata) + { + case 0: + metadata = 2; break; - case SOUTH_DOOR_METADATA: - - if (blockID == Block.hopperBlock.blockID) - { - switch (metadata) - { - case 2: - metadata = 3; - break; - case 3: - metadata = 2; - break; - case 4: - metadata = 5; - break; - case 5: - metadata = 4; - break; - } - } - - if(Block.blocksList[blockID] instanceof BlockStairs) - { - switch (metadata) - { - case 0: - metadata = 1; - break; - case 1: - metadata = 0; - break; - case 2: - metadata = 3; - break; - case 3: - metadata = 2; - break; - case 7: - metadata = 6; - break; - case 6: - metadata = 7; - break; - case 5: - metadata = 4; - break; - case 4: - metadata = 5; - break; - } - } - - else if(blockID== Block.chest.blockID||blockID== Block.chestTrapped.blockID||blockID==Block.ladder.blockID) - { - switch (metadata) - { - case 2: - metadata = 3; - break; - case 3: - metadata = 2; - break; - case 4: - metadata = 5; - break; - case 5: - metadata = 4; - break; - } - - } - - else if(blockID==Block.vine.blockID) - { - switch (metadata) - { - - case 1: - metadata = 4; - break; - case 2: - metadata = 8; - break; - case 4: - metadata = 1; - break; - case 8: - metadata = 2; - break; - } - } - - - - - else if(blockID== Block.lever.blockID||blockID== Block.torchWood.blockID||blockID== Block.torchRedstoneIdle.blockID||blockID== Block.torchRedstoneActive.blockID) - { - switch (metadata) - { - case 12: - metadata = 11; - break; - case 11: - metadata = 12; - break; - case 10: - metadata = 9; - break; - case 9: - metadata = 10; - break; - case 2: - metadata = 1; - break; - case 3: - metadata = 4; - break; - case 1: - metadata = 2; - break; - case 4: - metadata = 3; - - break; - - } - - } - - else if(blockID== Block.pistonBase.blockID||blockID==Block.pistonStickyBase.blockID||blockID==Block.dispenser.blockID||blockID==Block.dropper.blockID) - { - switch (metadata) - { - case 4: - metadata = 5; - break; - case 5: - metadata = 4; - break; - case 13: - metadata = 12; - break; - case 12: - metadata = 13; - break; - case 3: - metadata = 2; - break; - case 2: - metadata = 3; - break; - case 11: - metadata = 10; - break; - case 10: - metadata = 11; - break; - - } - - - - } - - else if(Block.blocksList[blockID] instanceof BlockRedstoneRepeater ||Block.blocksList[blockID] instanceof BlockDoor || Block.blocksList[blockID] instanceof dimDoor || blockID== Block.tripWireSource.blockID||Block.blocksList[blockID] instanceof BlockComparator) - { - switch (metadata) - { - case 0: - metadata = 2; - break; - case 1: - metadata = 3; - break; - case 2: - metadata = 0; - break; - case 3: - metadata = 1; - break; - case 4: - metadata = 6; - break; - case 5: - metadata = 7; - break; - case 6: - metadata = 4; - break; - case 7: - metadata = 5; - break; - case 8: - metadata = 10; - break; - case 9: - metadata = 11; - break; - case 10: - metadata = 8; - break; - case 11: - metadata = 9; - break; - case 12: - metadata = 14; - break; - case 13: - metadata = 15; - break; - case 14: - metadata = 12; - break; - case 15: - metadata = 13; - break; - - - } - - - - } - + case 1: + metadata = 3; break; - case WEST_DOOR_METADATA: - - if (blockID == Block.hopperBlock.blockID) - { - switch (metadata) - { - case 2: - metadata = 4; - break; - case 3: - metadata = 5; - break; - case 4: - metadata = 3; - break; - case 5: - metadata = 2; - break; - } - } - - if(Block.blocksList[blockID] instanceof BlockStairs) - { - - switch (metadata) - { - case 2: - metadata = 0; - break; - case 3: - metadata = 1; - break; - case 1: - metadata = 2; - break; - case 0: - metadata = 3; - break; - case 4: - metadata = 7; - break; - case 5: - metadata = 6; - break; - case 7: - metadata = 5; - break; - case 6: - metadata = 4; - break; - - } - } - - else if(blockID== Block.chest.blockID||blockID== Block.chestTrapped.blockID||blockID==Block.ladder.blockID) - { - switch (metadata) - { - - case 2: - metadata = 4; - break; - case 3: - metadata = 5; - break; - case 4: - metadata = 3; - break; - case 5: - metadata = 2; - break; - - - - } - - } - - else if(blockID==Block.vine.blockID) - { - switch (metadata) - { - - case 1: - metadata = 8; - break; - case 2: - metadata = 1; - break; - case 4: - metadata = 2; - break; - case 8: - metadata = 4; - break; - } - } - - - - - else if(blockID== Block.lever.blockID||blockID== Block.torchWood.blockID||blockID== Block.torchRedstoneIdle.blockID||blockID== Block.torchRedstoneActive.blockID) - { - switch (metadata) - { - case 9: - metadata = 12; - break; - case 10: - metadata = 11; - break; - case 12: - metadata = 10; - break; - case 11: - metadata = 9; - break; - case 4: - metadata = 2; - break; - case 2: - metadata = 3; - break; - case 3: - metadata = 1; - break; - case 1: - metadata = 4; - - break; - - } - - } - - else if(blockID== Block.pistonBase.blockID||blockID==Block.pistonStickyBase.blockID||blockID==Block.dispenser.blockID||blockID==Block.dropper.blockID) - - { - switch (metadata) - { - case 2: - metadata = 4; - break; - case 3: - metadata = 5; - break; - case 11: - metadata = 13; - break; - case 10: - metadata = 12; - break; - case 4: - metadata = 3; - break; - case 5: - metadata = 2; - break; - case 12: - metadata = 11; - break; - case 13: - metadata = 10; - break; - } - } - else if(Block.blocksList[blockID] instanceof BlockRedstoneRepeater ||Block.blocksList[blockID] instanceof BlockDoor || Block.blocksList[blockID] instanceof dimDoor || blockID== Block.tripWireSource.blockID||Block.blocksList[blockID] instanceof BlockComparator) - { - switch (metadata) - { - case 1: - metadata = 0; - break; - case 2: - metadata = 1; - break; - case 3: - metadata = 2; - break; - case 0: - metadata = 3; - break; - case 5: - metadata = 4; - break; - case 6: - metadata = 5; - break; - case 7: - metadata = 6; - break; - case 4: - metadata = 7; - break; - case 9: - metadata = 8; - break; - case 10: - metadata = 9; - break; - case 11: - metadata = 10; - break; - case 8: - metadata = 11; - break; - case 13: - metadata = 12; - break; - case 14: - metadata = 13; - break; - case 15: - metadata = 14; - break; - case 12: - metadata = 15; - break; - } - } + case 2: + metadata = 1; break; - case NORTH_DOOR_METADATA: - /** - * this is the default case- never need to change anything here - * - */ + case 3: + metadata = 0; + break; + case 7: + metadata = 4; + break; + case 6: + metadata = 5; + break; + case 5: + metadata = 7; + break; + case 4: + metadata = 6; + break; + } + } + else if (blockID == Block.chest.blockID || blockID == Block.chestTrapped.blockID || blockID == Block.ladder.blockID || blockID == Block.hopperBlock.blockID) + { + switch (metadata) + { + case 2: + metadata = 5; + break; + case 3: + metadata = 4; + break; + case 4: + metadata = 2; + break; + case 5: + metadata = 3; + break; + } + + } + else if (blockID==Block.vine.blockID) + { + switch (metadata) + { + + case 1: + metadata = 2; + break; + case 2: + metadata = 4; + break; + case 4: + metadata = 8; + break; + case 8: + metadata = 1; + break; + } + } + else if(blockID== Block.lever.blockID||blockID== Block.stoneButton.blockID||blockID== Block.woodenButton.blockID||blockID== Block.torchWood.blockID||blockID== Block.torchRedstoneIdle.blockID||blockID== Block.torchRedstoneActive.blockID) + { + switch (metadata) + { + case 12: + metadata = 9; + break; + case 11: + metadata = 10; + break; + case 10: + metadata = 12; + break; + case 9: + metadata = 11; + break; + case 2: + metadata = 4; + break; + case 3: + metadata = 2; + break; + case 1: + metadata = 3; + break; + case 4: + metadata = 1; + break; + } + } + else if(blockID== Block.pistonBase.blockID||blockID==Block.pistonExtension.blockID||blockID==Block.pistonStickyBase.blockID||blockID==Block.dispenser.blockID||blockID==Block.dropper.blockID) + { + switch (metadata) + { + case 4: + metadata = 2; + break; + case 5: + metadata = 3; + break; + case 13: + metadata = 11; + break; + case 12: + metadata = 10; + break; + case 3: + metadata = 4; + break; + case 2: + metadata = 5; + break; + case 11: + metadata = 12; + break; + case 10: + metadata = 13; + break; + } + } + else if(Block.blocksList[blockID] instanceof BlockRedstoneRepeater || Block.blocksList[blockID] instanceof BlockDoor || Block.blocksList[blockID] instanceof dimDoor || blockID== Block.tripWireSource.blockID || Block.blocksList[blockID] instanceof BlockComparator) + { + switch (metadata) + { + case 0: + metadata = 1; + break; + case 1: + metadata = 2; + break; + case 2: + metadata = 3; + break; + case 3: + metadata = 0; + break; + case 4: + metadata = 5; + break; + case 5: + metadata = 6; + break; + case 6: + metadata = 7; + break; + case 7: + metadata = 4; + break; + case 8: + metadata = 9; + break; + case 9: + metadata = 10; + break; + case 10: + metadata = 11; + break; + case 11: + metadata = 8; + break; + case 12: + metadata = 13; + break; + case 13: + metadata = 14; + break; + case 14: + metadata = 15; + break; + case 15: + metadata = 12; break; } } -- 2.39.5 From 7b315149ed278ac5d714a6b4ddc588bad69af1a8 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Fri, 2 Aug 2013 08:04:07 -0400 Subject: [PATCH 03/12] Test Commit Making a commit to test whether Jenkins is building my latest commits... --- schematics/testing | 1 + 1 file changed, 1 insertion(+) create mode 100644 schematics/testing diff --git a/schematics/testing b/schematics/testing new file mode 100644 index 0000000..4c4b46f --- /dev/null +++ b/schematics/testing @@ -0,0 +1 @@ +testing jenkins... \ No newline at end of file -- 2.39.5 From 350b2e2e2c701d0c8d1c6ad90fcbece8638dc299 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Fri, 2 Aug 2013 08:06:58 -0400 Subject: [PATCH 04/12] Removing Test File Removed the test file from the previous commit --- schematics/testing | 1 - 1 file changed, 1 deletion(-) delete mode 100644 schematics/testing diff --git a/schematics/testing b/schematics/testing deleted file mode 100644 index 4c4b46f..0000000 --- a/schematics/testing +++ /dev/null @@ -1 +0,0 @@ -testing jenkins... \ No newline at end of file -- 2.39.5 From 62b1629a8a289962ce696ac74c133e6f2b085fb0 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Fri, 2 Aug 2013 13:49:24 -0400 Subject: [PATCH 05/12] Fixed Metadata Rotation for Stairs Changed BlockRotator so that missing stair types are recognized for applying rotations. The general code for all stairs was there but the block IDs for wooden and brick stairs weren't recognized. Also removed a duplicate reference to nether brick stairs. --- StevenDimDoors/mod_pocketDim/schematic/BlockRotator.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/StevenDimDoors/mod_pocketDim/schematic/BlockRotator.java b/StevenDimDoors/mod_pocketDim/schematic/BlockRotator.java index 18b0ee1..533b7c2 100644 --- a/StevenDimDoors/mod_pocketDim/schematic/BlockRotator.java +++ b/StevenDimDoors/mod_pocketDim/schematic/BlockRotator.java @@ -50,13 +50,18 @@ public class BlockRotator hasOrientations[Block.hopperBlock.blockID] = true; hasOrientations[Block.stairsNetherBrick.blockID] = true; hasOrientations[Block.stairsCobblestone.blockID] = true; - hasOrientations[Block.stairsNetherBrick.blockID] = true; hasOrientations[Block.stairsNetherQuartz.blockID] = true; hasOrientations[Block.stairsSandStone.blockID] = true; + hasOrientations[Block.stairsBrick.blockID] = true; + hasOrientations[Block.stairsWoodBirch.blockID] = true; + hasOrientations[Block.stairsWoodOak.blockID] = true; + hasOrientations[Block.stairsWoodJungle.blockID] = true; + hasOrientations[Block.stairsWoodSpruce.blockID] = true; hasOrientations[Block.wood.blockID] = true; hasOrientations[Block.blockNetherQuartz.blockID] = true; hasOrientations[mod_pocketDim.dimDoor.blockID] = true; hasOrientations[mod_pocketDim.ExitDoor.blockID] = true; + } public static int transformMetadata(int metadata, int turns, int blockID) -- 2.39.5 From 81bac7b7ff32fa93779ba13fec8e4b097140ba09 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Fri, 2 Aug 2013 14:46:47 -0400 Subject: [PATCH 06/12] Added Support for More Metadata Rotations Added support for rotating the metadata of powered tracks and detector tracks. Also made a minor change to DungeonSchematic to protect its internal state. --- .../dungeon/DungeonSchematic.java | 2 +- .../mod_pocketDim/schematic/BlockRotator.java | 52 ++++++++++++++++++- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java b/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java index a870785..8792eae 100644 --- a/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java +++ b/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java @@ -63,7 +63,7 @@ public class DungeonSchematic extends Schematic { public Point3D getEntranceDoorLocation() { - return entranceDoorLocation; + return entranceDoorLocation.clone(); } private DungeonSchematic() diff --git a/StevenDimDoors/mod_pocketDim/schematic/BlockRotator.java b/StevenDimDoors/mod_pocketDim/schematic/BlockRotator.java index 533b7c2..75a6e7b 100644 --- a/StevenDimDoors/mod_pocketDim/schematic/BlockRotator.java +++ b/StevenDimDoors/mod_pocketDim/schematic/BlockRotator.java @@ -59,6 +59,9 @@ public class BlockRotator hasOrientations[Block.stairsWoodSpruce.blockID] = true; hasOrientations[Block.wood.blockID] = true; hasOrientations[Block.blockNetherQuartz.blockID] = true; + hasOrientations[Block.railPowered.blockID] = true; + hasOrientations[Block.railDetector.blockID] = true; + hasOrientations[mod_pocketDim.dimDoor.blockID] = true; hasOrientations[mod_pocketDim.ExitDoor.blockID] = true; @@ -93,14 +96,59 @@ public class BlockRotator { if (metadata >= 4 && metadata < 12) { - return (metadata % 8) + 4; + metadata = (metadata % 8) + 4; } } else if (blockID == Block.blockNetherQuartz.blockID) { if (metadata == 3 || metadata == 4) { - return (metadata - 2) % 2 + 3; + metadata = (metadata - 2) % 2 + 3; + } + } + else if (blockID == Block.railPowered.blockID || blockID == Block.railDetector.blockID) + { + switch (metadata) + { + //Powered Track/Detector Track (off) + case 0: + metadata = 1; + break; + case 1: + metadata = 0; + break; + case 2: + metadata = 5; + break; + case 3: + metadata = 4; + break; + case 4: + metadata = 2; + break; + case 5: + metadata = 3; + break; + + //Powered Track/Detector Track (on) + case 8: + metadata = 9; + break; + case 9: + metadata = 8; + break; + case 10: + metadata = 13; + break; + case 11: + metadata = 12; + break; + case 12: + metadata = 10; + break; + case 13: + metadata = 11; + break; } } else if (Block.blocksList[blockID] instanceof BlockStairs) -- 2.39.5 From 84872acb9728e024f0b4764691f4c18f09f1382e Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Fri, 2 Aug 2013 15:15:45 -0400 Subject: [PATCH 07/12] Added Support for Activator Track Added support for rotating the metadata of activator tracks. --- StevenDimDoors/mod_pocketDim/schematic/BlockRotator.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/schematic/BlockRotator.java b/StevenDimDoors/mod_pocketDim/schematic/BlockRotator.java index 75a6e7b..5997c35 100644 --- a/StevenDimDoors/mod_pocketDim/schematic/BlockRotator.java +++ b/StevenDimDoors/mod_pocketDim/schematic/BlockRotator.java @@ -61,6 +61,7 @@ public class BlockRotator hasOrientations[Block.blockNetherQuartz.blockID] = true; hasOrientations[Block.railPowered.blockID] = true; hasOrientations[Block.railDetector.blockID] = true; + hasOrientations[Block.railActivator.blockID] = true; hasOrientations[mod_pocketDim.dimDoor.blockID] = true; hasOrientations[mod_pocketDim.ExitDoor.blockID] = true; @@ -106,11 +107,11 @@ public class BlockRotator metadata = (metadata - 2) % 2 + 3; } } - else if (blockID == Block.railPowered.blockID || blockID == Block.railDetector.blockID) + else if (blockID == Block.railPowered.blockID || blockID == Block.railDetector.blockID || blockID == Block.railActivator.blockID) { switch (metadata) { - //Powered Track/Detector Track (off) + //Powered Track/Detector Track/Activator Track (off) case 0: metadata = 1; break; @@ -130,7 +131,7 @@ public class BlockRotator metadata = 3; break; - //Powered Track/Detector Track (on) + //Powered Track/Detector Track/Activator Track (on) case 8: metadata = 9; break; -- 2.39.5 From 3d04e9b9ccfbf4f0fd9510bbb48b2922bcde218a Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sat, 3 Aug 2013 06:12:56 -0400 Subject: [PATCH 08/12] Made Rifts Check Block Hardness Made rifts check block hardness while replacing blocks so that we can avoid destroying strong or indestructible blocks from other mods. Updated references throughout the code to use a function in BlockRift for this purpose. --- .../mod_pocketDim/EventHookContainer.java | 13 ++- .../mod_pocketDim/blocks/BlockRift.java | 94 ++++++++++++------- .../mod_pocketDim/helpers/dimHelper.java | 19 ++-- .../mod_pocketDim/mod_pocketDim.java | 26 +---- .../ticking/RiftRegenerator.java | 26 ++--- 5 files changed, 92 insertions(+), 86 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/EventHookContainer.java b/StevenDimDoors/mod_pocketDim/EventHookContainer.java index aa41b8a..95742f3 100644 --- a/StevenDimDoors/mod_pocketDim/EventHookContainer.java +++ b/StevenDimDoors/mod_pocketDim/EventHookContainer.java @@ -58,16 +58,15 @@ public class EventHookContainer { for (LinkData link:dimHelper.instance.getDimData(world.provider.dimensionId).getLinksInDim()) { - if(linkCount>100) //TODO: Wtf? wouldn't this cause some links to not load on servers with several links? Not sure what's going on here. ~SenseiKiwi - { - break; - } - linkCount++; - int blocktoReplace = world.getBlockId(link.locXCoord, link.locYCoord, link.locZCoord); - if (!mod_pocketDim.blocksImmuneToRift.contains(blocktoReplace)) + if (!mod_pocketDim.blockRift.isBlockImmune(world, link.locXCoord, link.locYCoord, link.locZCoord)) { dimHelper.getWorld(link.locDimID).setBlock(link.locXCoord, link.locYCoord, link.locZCoord, properties.RiftBlockID); } + linkCount++; + if (linkCount >= 100) + { + break; + } } } catch(Exception e) diff --git a/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java b/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java index bad02c5..ac34bf2 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java +++ b/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java @@ -1,7 +1,9 @@ package StevenDimDoors.mod_pocketDim.blocks; +import java.util.ArrayList; import java.util.Random; +import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; @@ -11,7 +13,6 @@ import net.minecraft.util.MathHelper; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; -import StevenDimDoors.mod_pocketDim.PacketHandler; import StevenDimDoors.mod_pocketDim.TileEntityRift; import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.helpers.dimHelper; @@ -24,24 +25,41 @@ import cpw.mods.fml.relauncher.SideOnly; public class BlockRift extends BlockContainer { - private static DDProperties properties = null; + private static final float MIN_IMMUNE_HARDNESS = 200.0F; - public BlockRift(int i, int j, Material par2Material) + private final DDProperties properties; + private final ArrayList blocksImmuneToRift; + + public BlockRift(int i, int j, Material par2Material, DDProperties properties) { super(i, Material.air); - setTickRandomly(true); - // this.setCreativeTab(CreativeTabs.tabBlock); + this.setTickRandomly(true); this.setLightOpacity(14); - if (properties == null) - properties = DDProperties.instance(); + this.properties = properties; + 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(Block.blockIron.blockID); + this.blocksImmuneToRift.add(Block.blockDiamond.blockID); + this.blocksImmuneToRift.add(Block.blockEmerald.blockID); + this.blocksImmuneToRift.add(Block.blockGold.blockID); + this.blocksImmuneToRift.add(Block.blockLapis.blockID); } + @Override public void registerIcons(IconRegister par1IconRegister) { this.blockIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName2()); } //sends a packet informing the client that there is a link present so it renders properly. (when placed) + @Override public void onBlockAdded(World par1World, int par2, int par3, int par4) { try @@ -53,16 +71,18 @@ public class BlockRift extends BlockContainer e.printStackTrace(); } // this.updateTick(par1World, par2, par3, par4, new Random()); - } + + @Override public boolean isCollidable() { return false; } - + + @Override public void onBlockDestroyedByPlayer(World par1World, int par2, int par3, int par4, int par5) {} - + @Override public boolean isOpaqueCube() { return false; @@ -71,6 +91,7 @@ public class BlockRift extends BlockContainer /** * Returns whether this block is collideable based on the arguments passed in Args: blockMetaData, unknownFlag */ + @Override public boolean canCollideCheck(int par1, boolean par2) { @@ -81,11 +102,14 @@ public class BlockRift extends BlockContainer * Returns Returns true if the given side of this block type should be rendered (if it's solid or not), if the * adjacent block is at the given coordinates. Args: blockAccess, x, y, z, side */ + @Override public boolean isBlockSolid(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) { return true; } + //this doesnt do anything yet. + @Override public int getRenderType() { if(mod_pocketDim.isPlayerWearingGoogles) @@ -96,12 +120,12 @@ public class BlockRift extends BlockContainer return 8; } - @SideOnly(Side.CLIENT) - /** * Returns true if the given side of this block type should be rendered, if the adjacent block is at the given * coordinates. Args: blockAccess, x, y, z, side */ + @Override + @SideOnly(Side.CLIENT) public boolean shouldSideBeRendered(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) { return true; @@ -111,21 +135,23 @@ public class BlockRift extends BlockContainer * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been * cleared to be reused) */ + @Override public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4) { return null; } + //function that regulates how many blocks it eats/ how fast it eates them. + @Override public void updateTick(World world, int x, int y, int z, Random random) { if(!world.isRemote&&dimHelper.instance.getLinkDataFromCoords(x, y, z, world.provider.dimensionId)!=null && properties.RiftGriefingEnabled) { TileEntityRift rift = (TileEntityRift) world.getBlockTileEntity(x, y, z); - if(rift.isNearRift) + if (rift.isNearRift) { - + //TODO: Fix this. Make it pretty. õ_õ ~SenseiKiwi int range=4; - float distance=range+range/4; int i=-range; int j=-range; @@ -137,7 +163,8 @@ public class BlockRift extends BlockContainer { while (k= MIN_IMMUNE_HARDNESS || blocksImmuneToRift.contains(block.blockID)); + } + return false; + } + + @Override public int idPicked(World par1World, int par2, int par3, int par4) { return 0; } + @Override public int idDropped(int par1, Random par2Random, int par3) { return 0; @@ -290,12 +323,7 @@ public class BlockRift extends BlockContainer @Override public TileEntity createNewTileEntity(World var1) - { - // TODO Auto-generated method stub return new TileEntityRift(); } - - - -} +} \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/helpers/dimHelper.java b/StevenDimDoors/mod_pocketDim/helpers/dimHelper.java index 1cdf6be..9f82048 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/dimHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/dimHelper.java @@ -42,7 +42,6 @@ import StevenDimDoors.mod_pocketDim.Point3D; import StevenDimDoors.mod_pocketDim.SchematicLoader; import StevenDimDoors.mod_pocketDim.TileEntityRift; import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.dungeon.DungeonSchematic; import StevenDimDoors.mod_pocketDim.schematic.BlockRotator; import StevenDimDoors.mod_pocketDim.world.LimboProvider; import StevenDimDoors.mod_pocketDim.world.PocketProvider; @@ -272,16 +271,20 @@ public class dimHelper extends DimensionManager } this.generateDoor(world,linkData); + //FIXME: Why are we checking blockList.length? Not necessary. getBlockId() can't return an ID past the end of the block list. + //Plus even if the check is necessary, it's still wrong since it should be less than, not less than or equal to. if(Block.blocksList.length>=entity.worldObj.getBlockId(playerXCoord,playerYCoord+1,playerZCoord)&&!entity.worldObj.isAirBlock(playerXCoord,playerYCoord+1,playerZCoord)) { - if(Block.blocksList[entity.worldObj.getBlockId(playerXCoord,playerYCoord+1,playerZCoord)].isOpaqueCube()&&!mod_pocketDim.blocksImmuneToRift.contains(entity.worldObj.getBlockId(playerXCoord,playerYCoord+1,playerZCoord))) + if(Block.blocksList[entity.worldObj.getBlockId(playerXCoord,playerYCoord+1,playerZCoord)].isOpaqueCube() && + !mod_pocketDim.blockRift.isBlockImmune(entity.worldObj, playerXCoord+1,playerYCoord,playerZCoord)) { entity.worldObj.setBlock(playerXCoord,playerYCoord+1,playerZCoord,0); } } - if(Block.blocksList.length>=entity.worldObj.getBlockId(playerXCoord,playerYCoord,playerZCoord)&&!entity.worldObj.isAirBlock(playerXCoord,playerYCoord,playerZCoord)) + if (Block.blocksList.length >= entity.worldObj.getBlockId(playerXCoord,playerYCoord,playerZCoord)&&!entity.worldObj.isAirBlock(playerXCoord,playerYCoord,playerZCoord)) { - if(Block.blocksList[entity.worldObj.getBlockId(playerXCoord,playerYCoord,playerZCoord)].isOpaqueCube()&&!mod_pocketDim.blocksImmuneToRift.contains(entity.worldObj.getBlockId(playerXCoord,playerYCoord,playerZCoord))) + if(Block.blocksList[entity.worldObj.getBlockId(playerXCoord,playerYCoord,playerZCoord)].isOpaqueCube() && + !mod_pocketDim.blockRift.isBlockImmune(entity.worldObj, playerXCoord,playerYCoord,playerZCoord)) { entity.worldObj.setBlock(playerXCoord,playerYCoord,playerZCoord,0); } @@ -362,12 +365,12 @@ public class dimHelper extends DimensionManager link.isLocPocket=locationDimData.isPocket; locationDimData.addLinkToDim(link); - if(dimHelper.getWorld(link.locDimID)!=null) + World world = dimHelper.getWorld(link.locDimID); + if (world != null) { - int blocktoReplace = dimHelper.getWorld(link.locDimID).getBlockId(link.locXCoord, link.locYCoord, link.locZCoord); - if(!mod_pocketDim.blocksImmuneToRift.contains(blocktoReplace)) + if (!mod_pocketDim.blockRift.isBlockImmune(world, link.locXCoord, link.locYCoord, link.locZCoord)) { - dimHelper.getWorld(link.locDimID).setBlock(link.locXCoord, link.locYCoord, link.locZCoord, properties.RiftBlockID); + world.setBlock(link.locXCoord, link.locYCoord, link.locZCoord, properties.RiftBlockID); } } //Notifies other players that a link has been created. diff --git a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java index 253ae39..b2ca95a 100644 --- a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java +++ b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java @@ -33,7 +33,6 @@ import StevenDimDoors.mod_pocketDim.commands.CommandPrintDimensionData; import StevenDimDoors.mod_pocketDim.commands.CommandPruneDimensions; import StevenDimDoors.mod_pocketDim.commands.CommandResetDungeons; import StevenDimDoors.mod_pocketDim.commands.CommandTeleportPlayer; -import StevenDimDoors.mod_pocketDim.helpers.BlockRotationHelper; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; import StevenDimDoors.mod_pocketDim.helpers.dimHelper; import StevenDimDoors.mod_pocketDim.items.ItemBlockDimWall; @@ -104,12 +103,12 @@ public class mod_pocketDim public static Block transientDoor; public static Block ExitDoor; public static Block chaosDoor; - public static Block blockRift; public static Block blockLimbo; public static Block dimDoor; public static Block blockDimWall; public static Block dimHatch; public static Block blockDimWallPerm; + public static BlockRift blockRift; public static Item itemRiftBlade; public static Item itemDimDoor; @@ -126,9 +125,7 @@ public class mod_pocketDim public static PlayerRespawnTracker tracker; public static HashMap> limboSpawnInventory = new HashMap>(); - - public static ArrayList blocksImmuneToRift = new ArrayList(); - + public static boolean hasInitDims = false; public static boolean isPlayerWearingGoogles = false; @@ -191,7 +188,7 @@ public class mod_pocketDim blockDimWall = (new BlockDimWall(properties.FabricBlockID, 0, Material.iron)).setLightValue(1.0F).setHardness(0.1F).setUnlocalizedName("blockDimWall"); blockDimWallPerm = (new BlockDimWallPerm(properties.PermaFabricBlockID, 0, Material.iron)).setLightValue(1.0F).setBlockUnbreakable().setResistance(6000000.0F).setUnlocalizedName("blockDimWallPerm"); ExitDoor = (new ExitDoor(properties.WarpDoorID, Material.wood)).setHardness(1.0F) .setUnlocalizedName("dimDoorWarp"); - blockRift = (new BlockRift(properties.RiftBlockID, 0, Material.air).setHardness(1.0F) .setUnlocalizedName("rift")); + 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)); chaosDoor = (new ChaosDoor(properties.UnstableDoorID, Material.iron).setHardness(.2F).setUnlocalizedName("chaosDoor").setLightValue(.0F) ); dimDoor = (new dimDoor(properties.DimensionalDoorID, Material.iron)).setHardness(1.0F).setResistance(2000.0F) .setUnlocalizedName("dimDoor"); @@ -378,22 +375,7 @@ public class mod_pocketDim " y ", "yxy", " y ", 'x', mod_pocketDim.itemLinkSignature, 'y', mod_pocketDim.itemStableFabric }); } - - mod_pocketDim.blocksImmuneToRift.add(properties.FabricBlockID); - mod_pocketDim.blocksImmuneToRift.add(properties.PermaFabricBlockID); - mod_pocketDim.blocksImmuneToRift.add(properties.DimensionalDoorID); - mod_pocketDim.blocksImmuneToRift.add(properties.WarpDoorID); - mod_pocketDim.blocksImmuneToRift.add(properties.TransTrapdoorID); - mod_pocketDim.blocksImmuneToRift.add(properties.UnstableDoorID); - mod_pocketDim.blocksImmuneToRift.add(properties.RiftBlockID); - mod_pocketDim.blocksImmuneToRift.add(properties.TransientDoorID); - mod_pocketDim.blocksImmuneToRift.add(Block.blockIron.blockID); - mod_pocketDim.blocksImmuneToRift.add(Block.blockDiamond.blockID); - mod_pocketDim.blocksImmuneToRift.add(Block.blockEmerald.blockID); - mod_pocketDim.blocksImmuneToRift.add(Block.blockGold.blockID); - mod_pocketDim.blocksImmuneToRift.add(Block.blockLapis.blockID); - mod_pocketDim.blocksImmuneToRift.add(Block.bedrock.blockID); - + DungeonHelper.initialize(); proxy.loadTextures(); diff --git a/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java b/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java index c358dd1..386c73b 100644 --- a/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java +++ b/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java @@ -43,27 +43,21 @@ public class RiftRegenerator implements IRegularTickReceiver { //actually gets the random rift based on the size of the list link = (LinkData) dimHelper.instance.getRandomLinkData(true); - if(link!=null) + if (link != null) { + World world = dimHelper.getWorld(link.locDimID); - if (dimHelper.getWorld(link.locDimID)!=null) + if (world != null && !mod_pocketDim.blockRift.isBlockImmune(world, link.locXCoord, link.locYCoord, link.locZCoord)) { - World world = dimHelper.getWorld(link.locDimID); - - int blocktoReplace = world.getBlockId(link.locXCoord, link.locYCoord, link.locZCoord); - - if(!mod_pocketDim.blocksImmuneToRift.contains(blocktoReplace))//makes sure the rift doesn't replace a door or something + if (dimHelper.instance.getLinkDataFromCoords(link.locXCoord, link.locYCoord, link.locZCoord, link.locDimID) != null) { - if(dimHelper.instance.getLinkDataFromCoords(link.locXCoord, link.locYCoord, link.locZCoord, link.locDimID) != null) + world.setBlock(link.locXCoord, link.locYCoord, link.locZCoord, properties.RiftBlockID); + TileEntityRift rift = (TileEntityRift) world.getBlockTileEntity(link.locXCoord, link.locYCoord, link.locZCoord); + if (rift == null) { - dimHelper.getWorld(link.locDimID).setBlock(link.locXCoord, link.locYCoord, link.locZCoord, properties.RiftBlockID); - TileEntityRift rift = TileEntityRift.class.cast(dimHelper.getWorld(link.locDimID).getBlockTileEntity(link.locXCoord, link.locYCoord, link.locZCoord)); - if(rift == null) - { - dimHelper.getWorld(link.locDimID).setBlockTileEntity(link.locXCoord, link.locYCoord, link.locZCoord, new TileEntityRift()); - } - rift.hasGrownRifts=true; + dimHelper.getWorld(link.locDimID).setBlockTileEntity(link.locXCoord, link.locYCoord, link.locZCoord, new TileEntityRift()); } + rift.hasGrownRifts = true; } } } @@ -71,7 +65,7 @@ public class RiftRegenerator implements IRegularTickReceiver { } catch (Exception e) { - System.out.println("An exception occurred in RiftRegenerator.regenerate():"); + System.err.println("An exception occurred in RiftRegenerator.regenerate():"); e.printStackTrace(); } } -- 2.39.5 From 3ef7630f2c8f0a0a7c7993b09a1824e2d28cce73 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sat, 3 Aug 2013 13:56:48 -0400 Subject: [PATCH 09/12] Made Rifts Destroy Blocks in Layers Made it so rifts destroy blocks in layers rather than destroying random surrounding blocks, even through indestructible blocks. This resolves issue #24. --- StevenDimDoors/mod_pocketDim/Point3D.java | 2 +- .../mod_pocketDim/blocks/BlockRift.java | 110 ++++++++++++------ 2 files changed, 75 insertions(+), 37 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/Point3D.java b/StevenDimDoors/mod_pocketDim/Point3D.java index 2fd653e..4a8e72a 100644 --- a/StevenDimDoors/mod_pocketDim/Point3D.java +++ b/StevenDimDoors/mod_pocketDim/Point3D.java @@ -105,6 +105,6 @@ public class Point3D implements Serializable { @Override public String toString() { - return "(" + x + ", " + "y" + ", " + z + ")"; + return "(" + x + ", " + y + ", " + z + ")"; } } \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java b/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java index ac34bf2..e5b6f1e 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java +++ b/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java @@ -1,6 +1,9 @@ package StevenDimDoors.mod_pocketDim.blocks; import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Queue; import java.util.Random; import net.minecraft.block.Block; @@ -9,10 +12,10 @@ import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; -import net.minecraft.util.MathHelper; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; +import StevenDimDoors.mod_pocketDim.Point3D; import StevenDimDoors.mod_pocketDim.TileEntityRift; import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.helpers.dimHelper; @@ -26,13 +29,19 @@ import cpw.mods.fml.relauncher.SideOnly; public class BlockRift extends BlockContainer { private static final float MIN_IMMUNE_HARDNESS = 200.0F; + private static final int BLOCK_DESTRUCTION_RANGE = 4; + private static final int BLOCK_DESTRUCTION_VOLUME = (int) Math.pow(2 * BLOCK_DESTRUCTION_RANGE + 1, 3); + private static final int MAX_BLOCK_SEARCH_CHANCE = 100; + private static final int BLOCK_SEARCH_CHANCE = 50; + private static final int MAX_BLOCK_DESTRUCTION_CHANCE = 100; + private static final int BLOCK_DESTRUCTION_CHANCE = 50; private final DDProperties properties; private final ArrayList blocksImmuneToRift; public BlockRift(int i, int j, Material par2Material, DDProperties properties) { - super(i, Material.air); + super(i, par2Material); this.setTickRandomly(true); this.setLightOpacity(14); this.properties = properties; @@ -50,6 +59,7 @@ public class BlockRift extends BlockContainer this.blocksImmuneToRift.add(Block.blockEmerald.blockID); this.blocksImmuneToRift.add(Block.blockGold.blockID); this.blocksImmuneToRift.add(Block.blockLapis.blockID); + this.blocksImmuneToRift.add(Block.glass.blockID); } @Override @@ -141,48 +151,76 @@ public class BlockRift extends BlockContainer return null; } - //function that regulates how many blocks it eats/ how fast it eates them. + //function that regulates how many blocks it eats/ how fast it eats them. @Override public void updateTick(World world, int x, int y, int z, Random random) { - if(!world.isRemote&&dimHelper.instance.getLinkDataFromCoords(x, y, z, world.provider.dimensionId)!=null && properties.RiftGriefingEnabled) + if (properties.RiftGriefingEnabled && !world.isRemote && + dimHelper.instance.getLinkDataFromCoords(x, y, z, world.provider.dimensionId) != null) { - TileEntityRift rift = (TileEntityRift) world.getBlockTileEntity(x, y, z); - if (rift.isNearRift) + //Randomly decide whether to search for blocks to destroy. This reduces the frequency of search operations, + //moderates performance impact, and controls the apparent speed of block destruction. + if (random.nextInt(MAX_BLOCK_SEARCH_CHANCE) < BLOCK_SEARCH_CHANCE && + ((TileEntityRift) world.getBlockTileEntity(x, y, z)).isNearRift ) { - //TODO: Fix this. Make it pretty. õ_õ ~SenseiKiwi - int range=4; - float distance=range+range/4; - int i=-range; - int j=-range; - int k=-range; - boolean flag=true; - while (i pointDistances = new HashMap(BLOCK_DESTRUCTION_VOLUME); + Queue points = new LinkedList(); + + //Perform a breadth-first search outwards from the point at which the rift is located. Record the distances + //of the points we visit to stop the search at its maximum range. + pointDistances.put(new Point3D(x, y, z), 0); + AddSurroundingBlocks(x, y, z, 1, pointDistances, points); + while (!points.isEmpty()) + { + Point3D current = points.remove(); + int distance = pointDistances.get(current); + + //If the current block is air, continue searching. Otherwise, try destroying the block. + if (world.isAirBlock(current.getX(), current.getY(), current.getZ())) + { + //Make sure we stay within the search range + if (distance < BLOCK_DESTRUCTION_RANGE) { - while (j pointDistances, Queue points) + { + Point3D[] neighbors = new Point3D[] { + new Point3D(x - 1, y, z), + new Point3D(x + 1, y, z), + new Point3D(x, y - 1, z), + new Point3D(x, y + 1, z), + new Point3D(x, y, z - 1), + new Point3D(x, y, z + 1) + }; + for (int index = 0; index < neighbors.length; index++) + { + if (!pointDistances.containsKey(neighbors[index])) + { + pointDistances.put(neighbors[index], distance); + points.add(neighbors[index]); + } } } -- 2.39.5 From 82c6e214b0ce8da184a2872a6f14641e8355d840 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sat, 3 Aug 2013 15:05:46 -0400 Subject: [PATCH 10/12] Fixed Glass Immunity to Rifts Removed glass from the list of blocks immune to rifts. That was just a temporary change so that I could check how rifts were destroying blocks in a controlled manner. --- StevenDimDoors/mod_pocketDim/blocks/BlockRift.java | 1 - 1 file changed, 1 deletion(-) diff --git a/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java b/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java index e5b6f1e..a8d5874 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java +++ b/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java @@ -59,7 +59,6 @@ public class BlockRift extends BlockContainer this.blocksImmuneToRift.add(Block.blockEmerald.blockID); this.blocksImmuneToRift.add(Block.blockGold.blockID); this.blocksImmuneToRift.add(Block.blockLapis.blockID); - this.blocksImmuneToRift.add(Block.glass.blockID); } @Override -- 2.39.5 From b7327b2bf6ba6420fcf0c4b910af8b12f01a6900 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sat, 3 Aug 2013 16:26:22 -0400 Subject: [PATCH 11/12] Minor Change Minor changes to make the rift block-eating code meet our coding conventions and to make it more intuitive. --- StevenDimDoors/mod_pocketDim/blocks/BlockRift.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java b/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java index a8d5874..fc05b9b 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java +++ b/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java @@ -162,12 +162,12 @@ public class BlockRift extends BlockContainer if (random.nextInt(MAX_BLOCK_SEARCH_CHANCE) < BLOCK_SEARCH_CHANCE && ((TileEntityRift) world.getBlockTileEntity(x, y, z)).isNearRift ) { - DestroyNearbyBlocks(world, x, y, z, random); + destroyNearbyBlocks(world, x, y, z, random); } } } - private void DestroyNearbyBlocks(World world, int x, int y, int z, Random random) + private void destroyNearbyBlocks(World world, int x, int y, int z, Random random) { HashMap pointDistances = new HashMap(BLOCK_DESTRUCTION_VOLUME); Queue points = new LinkedList(); @@ -175,7 +175,7 @@ public class BlockRift extends BlockContainer //Perform a breadth-first search outwards from the point at which the rift is located. Record the distances //of the points we visit to stop the search at its maximum range. pointDistances.put(new Point3D(x, y, z), 0); - AddSurroundingBlocks(x, y, z, 1, pointDistances, points); + AddSurroundingBlocks(x, y, z, 0, pointDistances, points); while (!points.isEmpty()) { Point3D current = points.remove(); @@ -187,7 +187,7 @@ public class BlockRift extends BlockContainer //Make sure we stay within the search range if (distance < BLOCK_DESTRUCTION_RANGE) { - AddSurroundingBlocks(current.getX(), current.getY(), current.getZ(), distance + 1, pointDistances, points); + addSurroundingBlocks(current.getX(), current.getY(), current.getZ(), distance, pointDistances, points); } } else @@ -203,7 +203,7 @@ public class BlockRift extends BlockContainer } } - private void AddSurroundingBlocks(int x, int y, int z, int distance, HashMap pointDistances, Queue points) + private void addSurroundingBlocks(int x, int y, int z, int distance, HashMap pointDistances, Queue points) { Point3D[] neighbors = new Point3D[] { new Point3D(x - 1, y, z), @@ -217,7 +217,7 @@ public class BlockRift extends BlockContainer { if (!pointDistances.containsKey(neighbors[index])) { - pointDistances.put(neighbors[index], distance); + pointDistances.put(neighbors[index], distance + 1); points.add(neighbors[index]); } } -- 2.39.5 From 2dfabccaa9219a1bfb35a53e3a5afe5f18027658 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sat, 3 Aug 2013 16:29:05 -0400 Subject: [PATCH 12/12] Minor Change Overlooked a spelling mistake that would cause compilation errors. --- StevenDimDoors/mod_pocketDim/blocks/BlockRift.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java b/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java index fc05b9b..7b10a63 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java +++ b/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java @@ -175,7 +175,7 @@ public class BlockRift extends BlockContainer //Perform a breadth-first search outwards from the point at which the rift is located. Record the distances //of the points we visit to stop the search at its maximum range. pointDistances.put(new Point3D(x, y, z), 0); - AddSurroundingBlocks(x, y, z, 0, pointDistances, points); + addAdjacentBlocks(x, y, z, 0, pointDistances, points); while (!points.isEmpty()) { Point3D current = points.remove(); @@ -187,7 +187,7 @@ public class BlockRift extends BlockContainer //Make sure we stay within the search range if (distance < BLOCK_DESTRUCTION_RANGE) { - addSurroundingBlocks(current.getX(), current.getY(), current.getZ(), distance, pointDistances, points); + addAdjacentBlocks(current.getX(), current.getY(), current.getZ(), distance, pointDistances, points); } } else @@ -203,7 +203,7 @@ public class BlockRift extends BlockContainer } } - private void addSurroundingBlocks(int x, int y, int z, int distance, HashMap pointDistances, Queue points) + private void addAdjacentBlocks(int x, int y, int z, int distance, HashMap pointDistances, Queue points) { Point3D[] neighbors = new Point3D[] { new Point3D(x - 1, y, z), -- 2.39.5