From c3c361176411e1f370af3e321fa12c269bab7106 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sun, 7 Jul 2013 19:59:04 -0400 Subject: [PATCH 1/3] Minor Improvements and Debugging Tweaks Minor improvements to the readability and performance of SchematicLoader. Added a little temporary code for debugging purposes. --- .../mod_pocketDim/SchematicLoader.java | 110 ++++++++---------- 1 file changed, 48 insertions(+), 62 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/SchematicLoader.java b/StevenDimDoors/mod_pocketDim/SchematicLoader.java index 3090f7f..e97c79e 100644 --- a/StevenDimDoors/mod_pocketDim/SchematicLoader.java +++ b/StevenDimDoors/mod_pocketDim/SchematicLoader.java @@ -101,13 +101,10 @@ public class SchematicLoader case 5: metadata = 3; break; - - - } } - else if(blockID==Block.vine.blockID) + else if (blockID==Block.vine.blockID) { switch (metadata) { @@ -184,18 +181,10 @@ public class SchematicLoader case 10: metadata = 13; break; - - } - - - } - - else if(Block.blocksList[blockID] instanceof BlockRedstoneRepeater ||Block.blocksList[blockID] instanceof BlockDoor ||blockID== Block.tripWireSource.blockID||Block.blocksList[blockID] instanceof BlockComparator) + else if(Block.blocksList[blockID] instanceof BlockRedstoneRepeater ||Block.blocksList[blockID] instanceof BlockDoor ||blockID== Block.tripWireSource.blockID||Block.blocksList[blockID] instanceof BlockComparator) { - - switch (metadata) { case 0: @@ -246,25 +235,12 @@ public class SchematicLoader case 15: metadata = 12; break; - - } - - - } - - - - - break; case 1: - - if(Block.blocksList[blockID] instanceof BlockStairs) { - switch (metadata) { case 0: @@ -291,15 +267,13 @@ public class SchematicLoader case 4: metadata = 5; break; - } } - else if(blockID== Block.chest.blockID||blockID== Block.chestTrapped.blockID||blockID==Block.ladder.blockID) + else if(blockID== Block.chest.blockID||blockID== Block.chestTrapped.blockID||blockID==Block.ladder.blockID) { switch (metadata) { - case 2: metadata = 3; break; @@ -312,9 +286,6 @@ public class SchematicLoader case 5: metadata = 4; break; - - - } } @@ -727,15 +698,12 @@ public class SchematicLoader //second 4 bytes of the block ID byte[] addId = new byte[0]; + NBTTagList tileEntities = null; NBTTagCompound[] tileEntityList; - - NBTTagList entities; - NBTTagList tileEntities=null; - //the wooden door leading into the pocket - Point3D entrance= new Point3D(0,0,0); + Point3D entrance = new Point3D(0,0,0); //the iron dim doors leading to more pockets ArrayList sideLinks = new ArrayList(); @@ -781,7 +749,7 @@ public class SchematicLoader //load ticking things tileEntities = nbtdata.getTagList("TileEntities"); - tileEntityList = new NBTTagCompound[width*height*length]; + //tileEntityList = new NBTTagCompound[width*height*length]; /** for(int count = 0; count= 0 && blocks[indexBelow] == Block.doorIron.blockID) { - sideLinks.add(new Point3D(x,y,z)); + sideLinks.add(new Point3D(x, y, z)); } - else if(blockToReplace==Block.doorWood.blockID) + else if (currentBlock == Block.doorWood.blockID) { - if( ((y-2) * width * length + z * width + x)>=0&&blocks[ (y-2) * width * length + z * width + x]==Block.sandStone.blockID&&blocks[ (y-1) * width * length + z * width + x]==Block.doorWood.blockID) + if (indexDoubleBelow >= 0 && blocks[indexDoubleBelow] == Block.sandStone.blockID && + blocks[indexBelow] == Block.doorWood.blockID) { - exitLinks.add(new Point3D(x,y,z)); + exitLinks.add(new Point3D(x, y, z)); } - else if(((y-1) * width * length + z * width + x)>=0&&blocks[ (y-1) * width * length + z * width + x]==Block.doorWood.blockID) + else if (indexBelow >= 0 && blocks[indexBelow] == Block.doorWood.blockID) { - entrance=(new Point3D(x,y,z)); - schematicDoorMeta=Math.abs(blockData[(y-1) * width * length + z * width + x]+2)%4; - + entrance = new Point3D(x, y, z); + schematicDoorMeta = Math.abs(blockData[indexBelow] + 2) % 4; //TODO: Write a function for extracting a door's orientation from its metadata or at least change this to use bitwise operations. } } - else if (blockToReplace == Block.endPortalFrame.blockID) + else if (currentBlock == Block.endPortalFrame.blockID) { - monolithSpawns.add(new Point3D(x,y,z)); + monolithSpawns.add(new Point3D(x, y, z)); } } } @@ -893,6 +860,26 @@ public class SchematicLoader //Compute the Y-axis translation that places our structure correctly int offsetY = riftY - entrance.getY(); + //TODO: HAX REMOVE THIS! + schematicDoorMeta = NORTH_DOOR_METADATA; + + if (orientation == schematicDoorMeta) + { + System.out.println("Intended Orientation: NORTH"); + } + else if (orientation == (schematicDoorMeta + 1) % 4) + { + System.out.println("Intended Orientation: EAST"); + } + else if (orientation == (schematicDoorMeta + 2) % 4) + { + System.out.println("Intended Orientation: SOUTH"); + } + else if (orientation == (schematicDoorMeta + 3) % 4) + { + System.out.println("Intended Orientation: WEST"); + } + //Loop to actually place the blocks for (x = 0; x < width; x++) { @@ -901,25 +888,24 @@ public class SchematicLoader //Compute the X-axis and Z-axis translations that will shift //and rotate our structure properly. - if(orientation == schematicDoorMeta) + if (orientation == schematicDoorMeta) { realX = (x - entrance.getX()) + riftX; realZ = (z - entrance.getZ()) + riftZ; - } - else if(orientation==(schematicDoorMeta + 1) % 4) + else if (orientation == (schematicDoorMeta + 1) % 4) { //270 degree CCW rotation realX = -(z - entrance.getZ()) + riftX; realZ = (x - entrance.getX()) + riftZ; } - else if(orientation== (schematicDoorMeta + 2) % 4) - { + else if (orientation == (schematicDoorMeta + 2) % 4) + { //180 degree rotation realX = -(x - entrance.getX()) + riftX; realZ = -(z - entrance.getZ()) + riftZ; } - else if(orientation==(schematicDoorMeta + 3) % 4) + else if (orientation == (schematicDoorMeta + 3) % 4) { //90 degree CCW rotation realX = (z - entrance.getZ()) + riftX; @@ -1196,7 +1182,7 @@ public class SchematicLoader String filePath=DungeonHelper.instance().defaultBreak.schematicPath; if(dimHelper.dimList.containsKey(link.destDimID)) { - if(dimHelper.dimList.get(link.destDimID).dungeonGenerator==null) + if(dimHelper.dimList.get(link.destDimID).dungeonGenerator == null) { DungeonHelper.instance().generateDungeonLink(link); } -- 2.39.5 From efe5da2604c86df5626c619c6f35e2e707bc26cf Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Tue, 9 Jul 2013 00:50:06 -0400 Subject: [PATCH 2/3] Overhauled SchematicLoader (again) Rotations in SchematicLoader are understandable now. I changed all the code to use transformPoint() and made sure that the rotations in there are correct. Testing shows that rooms are being generated correctly. I also edited portions of the code for clarity and removed some debug prints. The loading process now allows permafabric to generate - it was previously converted into regular fabric of reality. For the moment, the code is stuck to assume that the entry direction is North. I'll remove that constraint in the next commit. --- .../mod_pocketDim/SchematicLoader.java | 224 ++++++++---------- 1 file changed, 93 insertions(+), 131 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/SchematicLoader.java b/StevenDimDoors/mod_pocketDim/SchematicLoader.java index e97c79e..d4f4abe 100644 --- a/StevenDimDoors/mod_pocketDim/SchematicLoader.java +++ b/StevenDimDoors/mod_pocketDim/SchematicLoader.java @@ -37,8 +37,6 @@ public class SchematicLoader private final static int WEST_DOOR_METADATA = 2; private final static int NORTH_DOOR_METADATA = 3; - public int transMeta; - private DDProperties properties = DDProperties.instance(); public SchematicLoader() { } @@ -682,9 +680,9 @@ public class SchematicLoader public void generateSchematic(int riftX, int riftY, int riftZ, int orientation, int destDimID, int originDimID, String schematicPath) { - short width=0; - short height=0; - short length=0; + short width = 0; + short height = 0; + short length = 0; //list of combined blockIds short[] blocks = new short[0]; @@ -703,7 +701,7 @@ public class SchematicLoader NBTTagList entities; //the wooden door leading into the pocket - Point3D entrance = new Point3D(0,0,0); + Point3D schematicEntrance = new Point3D(0,0,0); //the iron dim doors leading to more pockets ArrayList sideLinks = new ArrayList(); @@ -717,9 +715,8 @@ public class SchematicLoader //load the schematic from disk try { - InputStream input; - String fname= schematicPath ; + String fname = schematicPath ; if(!(new File(fname).exists())) { @@ -745,7 +742,7 @@ public class SchematicLoader addId = nbtdata.getByteArray("AddBlocks"); //create combined block list - blocks=new short[blockId.length]; + blocks = new short[blockId.length]; //load ticking things tileEntities = nbtdata.getTagList("TileEntities"); @@ -804,15 +801,18 @@ public class SchematicLoader long factorB = rand.nextLong() / 2L * 2L + 1L; rand.setSeed((riftX >> 4) * factorA + (riftZ >> 4) * factorB ^ world.getSeed()); - //coords relative to the schematic, start at 0 and increase up to max height/width/length + //Coordinates relative to the schematic, start at 0 and increase up to max width/height/length int x, y, z; - //The real coordinates where a block will be placed - int realX = 0; - int realY = 0; - int realZ = 0; + //The real point where a block will be placed + int realX, realY, realZ; + Point3D pocketPoint = new Point3D(0, 0, 0); - int schematicDoorMeta=0; + //The central point of the pocket where we'll be placing the schematic + Point3D pocketCenter = new Point3D(riftX, riftY, riftZ); + Point3D zeroPoint = new Point3D(0, 0, 0); + + int schematicDoorMeta = 0; //first loop through the .schematic to load in all rift locations, and monolith spawn locations. //also finds the incomingLink location, which determines the final position and orientation of the dungeon @@ -831,7 +831,6 @@ public class SchematicLoader //NBTTagList tileEntity = tileEntities; //int size = tileEntity.tagCount(); - if (currentBlock == Block.doorIron.blockID && indexBelow >= 0 && blocks[indexBelow] == Block.doorIron.blockID) { sideLinks.add(new Point3D(x, y, z)); @@ -845,7 +844,7 @@ public class SchematicLoader } else if (indexBelow >= 0 && blocks[indexBelow] == Block.doorWood.blockID) { - entrance = new Point3D(x, y, z); + schematicEntrance = new Point3D(x, y, z); schematicDoorMeta = Math.abs(blockData[indexBelow] + 2) % 4; //TODO: Write a function for extracting a door's orientation from its metadata or at least change this to use bitwise operations. } } @@ -856,104 +855,66 @@ public class SchematicLoader } } } - - //Compute the Y-axis translation that places our structure correctly - int offsetY = riftY - entrance.getY(); //TODO: HAX REMOVE THIS! schematicDoorMeta = NORTH_DOOR_METADATA; - if (orientation == schematicDoorMeta) - { - System.out.println("Intended Orientation: NORTH"); - } - else if (orientation == (schematicDoorMeta + 1) % 4) - { - System.out.println("Intended Orientation: EAST"); - } - else if (orientation == (schematicDoorMeta + 2) % 4) - { - System.out.println("Intended Orientation: SOUTH"); - } - else if (orientation == (schematicDoorMeta + 3) % 4) - { - System.out.println("Intended Orientation: WEST"); - } - //Loop to actually place the blocks for (x = 0; x < width; x++) { for (z = 0; z < length; z++) { - //Compute the X-axis and Z-axis translations that will shift - //and rotate our structure properly. - - if (orientation == schematicDoorMeta) - { - realX = (x - entrance.getX()) + riftX; - realZ = (z - entrance.getZ()) + riftZ; - } - else if (orientation == (schematicDoorMeta + 1) % 4) - { - //270 degree CCW rotation - realX = -(z - entrance.getZ()) + riftX; - realZ = (x - entrance.getX()) + riftZ; - } - else if (orientation == (schematicDoorMeta + 2) % 4) - { - //180 degree rotation - realX = -(x - entrance.getX()) + riftX; - realZ = -(z - entrance.getZ()) + riftZ; - } - else if (orientation == (schematicDoorMeta + 3) % 4) - { - //90 degree CCW rotation - realX = (z - entrance.getZ()) + riftX; - realZ = -(x - entrance.getX()) + riftZ; - } - - for (y = 0; y < height; y++) { - int index = y * width * length + z * width + x; - realY = y + offsetY; + //Reinitialize pocketPoint with the current schematic coordinate system + pocketPoint.setX(x); + pocketPoint.setY(y); + pocketPoint.setZ(z); + //Transform pocketPoint into the pocket coordinate system + transformPoint(pocketPoint, schematicEntrance, orientation - schematicDoorMeta, pocketCenter); + //Store the transformed coordinates + realX = pocketPoint.getX(); + realY = pocketPoint.getY(); + realZ = pocketPoint.getZ(); - int blockToReplace=blocks[index]; - int blockMetaData=blockData[index]; + int index = y * width * length + z * width + x; + int currentBlock = blocks[index]; + int blockMetadata = blockData[index]; NBTTagList tileEntity = tileEntities; - //replace tagging blocks with air, and mob blocks with FoR - if(blockToReplace==Block.endPortalFrame.blockID) + //replace tagging blocks with air, and mod blocks with FoR + if (currentBlock == Block.endPortalFrame.blockID) { - blockToReplace=0; + currentBlock = 0; } - else if(Block.blocksList[blockToReplace]==null&&blockToReplace!=0||blockToReplace>158) //TODO- replace 158 with max vanilla block ID + else if ((Block.blocksList[currentBlock] == null && currentBlock != 0) || + (currentBlock > 158 && currentBlock != mod_pocketDim.blockDimWallPerm.blockID)) //TODO- replace 158 with max vanilla block ID { - blockToReplace=mod_pocketDim.blockDimWall.blockID; + currentBlock = mod_pocketDim.blockDimWall.blockID; } - //place blocks and metaData - if(blockToReplace>0) + //Place blocks and set metadata + if (currentBlock > 0) { - //rotate the metaData blocks - this.transMeta=this.transformMetadata(blockMetaData, orientation, blockToReplace); + //Calculate new metadata for blocks that have orientations (e.g. doors, pistons) + int fixedMetadata = transformMetadata(blockMetadata, orientation, currentBlock); - //convert vanilla doors to dim doors, then place vanilla blocks - if(blockToReplace==Block.doorIron.blockID) + //Convert vanilla doors to dim doors or place blocks + if (currentBlock == Block.doorIron.blockID) { - setBlockDirectly(world,realX, realY, realZ,properties.DimensionalDoorID, transMeta ); + setBlockDirectly(world, realX, realY, realZ, properties.DimensionalDoorID, fixedMetadata); } - else if(blockToReplace==Block.doorWood.blockID) + else if (currentBlock == Block.doorWood.blockID) { - setBlockDirectly(world,realX, realY, realZ,properties.WarpDoorID, transMeta ); + setBlockDirectly(world, realX, realY, realZ, properties.WarpDoorID, fixedMetadata); } else { - setBlockDirectly(world,realX, realY, realZ,blockToReplace, transMeta ); + setBlockDirectly(world, realX, realY, realZ, currentBlock, fixedMetadata); } - //generate container inventories - if(Block.blocksList[blockToReplace] instanceof BlockContainer) + //Fill containers (e.g. chests, dispensers) + if(Block.blocksList[currentBlock] instanceof BlockContainer) { /** TileEntity tile = world.getBlockTileEntity(i+xCooe, j+yCooe, k+zCooe); @@ -964,43 +925,55 @@ public class SchematicLoader } **/ - //fill chests - if(world.getBlockTileEntity(realX, realY, realZ) instanceof TileEntityChest) + //Fill chests + if (world.getBlockTileEntity(realX, realY, realZ) instanceof TileEntityChest) { TileEntityChest chest = (TileEntityChest) world.getBlockTileEntity(realX, realY, realZ); ChestGenHooks info = DDLoot.DungeonChestInfo; - WeightedRandomChestContent.generateChestContents(rand, info.getItems(rand), (TileEntityChest)world.getBlockTileEntity(realX, realY, realZ), info.getCount(rand)); + WeightedRandomChestContent.generateChestContents(rand, info.getItems(rand), chest, info.getCount(rand)); } - //fill dispensers - if(world.getBlockTileEntity(realX, realY, realZ) instanceof TileEntityDispenser) + //Fill dispensers + if (world.getBlockTileEntity(realX, realY, realZ) instanceof TileEntityDispenser) { TileEntityDispenser dispenser = (TileEntityDispenser) world.getBlockTileEntity(realX, realY, realZ); dispenser.addItem(new ItemStack(Item.arrow, 64)); - } } } } } } - - //Set up variables to use transformPoint() - Point3D pocketOrigin = new Point3D(riftX, riftY, riftZ); - Point3D zeroPoint = new Point3D(0, 0, 0); + + //We'll use an extra block here to restrict the scope of these variables to just inside the block + //This is to avoid conflicts with the loops below + { + //Set the orientation of the rift exit + Point3D entranceRiftLocation = schematicEntrance.clone(); + transformPoint(entranceRiftLocation, schematicEntrance, orientation - schematicDoorMeta, pocketCenter); + LinkData sideLink = dimHelper.instance.getLinkDataFromCoords( + entranceRiftLocation.getX(), + entranceRiftLocation.getY(), + entranceRiftLocation.getZ(), + world); + sideLink.linkOrientation = world.getBlockMetadata( + entranceRiftLocation.getX(), + entranceRiftLocation.getY() - 1, + entranceRiftLocation.getZ()); + } //Generate the LinkData defined by the door placement, Iron Dim doors first for(Point3D point : sideLinks) { - int depth = dimHelper.instance.getDimDepth(originDimID); - int forwardNoise = MathHelper.getRandomIntegerInRange(rand, -50 * (depth + 1), 150 * (depth + 1)); - int sidewaysNoise = MathHelper.getRandomIntegerInRange(rand, -10 * (depth + 1), 10 * (depth + 1)); + int depth = dimHelper.instance.getDimDepth(originDimID) + 1; + int forwardNoise = MathHelper.getRandomIntegerInRange(rand, -50 * depth, 150 * depth); + int sidewaysNoise = MathHelper.getRandomIntegerInRange(rand, -10 * depth, 10 * depth); - //Transform doorLocation to the pocket coordinate system. + //Transform doorLocation to the pocket coordinate system Point3D doorLocation = point.clone(); - transformPoint(doorLocation, entrance, orientation - schematicDoorMeta, pocketOrigin); + transformPoint(doorLocation, schematicEntrance, orientation - schematicDoorMeta, pocketCenter); int blockDirection = world.getBlockMetadata(doorLocation.getX(), doorLocation.getY() - 1, doorLocation.getZ()); - + //Rotate the link destination noise to point in the same direction as the door exit //and add it to the door's location. Use EAST as the reference orientation since linkDestination //is constructed as if pointing East. @@ -1019,24 +992,18 @@ public class SchematicLoader dimHelper.instance.createPocket(sideLink, true, true); } - //generate linkData for wooden dim doors leading to the overworld + //Generate linkData for wooden dim doors leading to the overworld for(Point3D point : exitLinks) { try { - //Transform doorLocation to the pocket coordinate system. Point3D doorLocation = point.clone(); - transformPoint(doorLocation, entrance, orientation - schematicDoorMeta, pocketOrigin); + transformPoint(doorLocation, schematicEntrance, orientation - schematicDoorMeta, pocketCenter); int blockDirection = world.getBlockMetadata(doorLocation.getX(), doorLocation.getY() - 1, doorLocation.getZ()); - - //Rotate the link destination noise to point in the same direction as the door exit - //and add it to the door's location. Use EAST as the reference orientation since linkDestination - //is constructed as if pointing East. - Point3D linkDestination = new Point3D(0, 0, 0); - transformPoint(linkDestination, zeroPoint, blockDirection - EAST_DOOR_METADATA, doorLocation); + Point3D linkDestination = doorLocation.clone(); - LinkData randomLink=dimHelper.instance.getRandomLinkData(false); + LinkData randomLink = dimHelper.instance.getRandomLinkData(false); LinkData sideLink = new LinkData(destDimID, dimHelper.dimList.get(originDimID).exitDimLink.destDimID, doorLocation.getX(), @@ -1047,22 +1014,21 @@ public class SchematicLoader linkDestination.getZ(), true, blockDirection); - if(sideLink.destDimID==properties.LimboDimensionID) + if (sideLink.destDimID == properties.LimboDimensionID) { - sideLink.destDimID=0; + sideLink.destDimID = 0; } - else if((rand.nextBoolean()&&randomLink!=null)) + else if ((rand.nextBoolean() && randomLink != null)) { - sideLink.destDimID=randomLink.locDimID; - // System.out.println("randomLink"); + sideLink.destDimID = randomLink.locDimID; } - sideLink.destYCoord=yCoordHelper.getFirstUncovered(sideLink.destDimID, linkDestination.getX(),10,linkDestination.getZ()); + sideLink.destYCoord = yCoordHelper.getFirstUncovered(sideLink.destDimID, linkDestination.getX(), 10, linkDestination.getZ()); - if(sideLink.destYCoord<5) + if (sideLink.destYCoord < 5) { - sideLink.destYCoord=70; + sideLink.destYCoord = 70; } - sideLink.linkOrientation=world.getBlockMetadata(linkDestination.getX(),linkDestination.getY()- 1,linkDestination.getZ()); + sideLink.linkOrientation = world.getBlockMetadata(linkDestination.getX(), linkDestination.getY() - 1, linkDestination.getZ()); dimHelper.instance.createLink(sideLink); dimHelper.instance.createLink(sideLink.destDimID , @@ -1075,7 +1041,7 @@ public class SchematicLoader sideLink.locZCoord, dimHelper.instance.flipDoorMetadata(sideLink.linkOrientation)); - if(world.getBlockId(linkDestination.getX(),linkDestination.getY() -3,linkDestination.getZ()) == properties.FabricBlockID) + if (world.getBlockId(linkDestination.getX(),linkDestination.getY() -3,linkDestination.getZ()) == properties.FabricBlockID) { setBlockDirectly(world,linkDestination.getX(),linkDestination.getY()-2,linkDestination.getZ(),Block.stoneBrick.blockID,0); } @@ -1092,27 +1058,23 @@ public class SchematicLoader linkDestination.getZ())); } } - catch(Exception E) + catch (Exception E) { E.printStackTrace(); } } - //spawn monoliths + //Spawn monoliths for(Point3D point : monolithSpawns) { //Transform the frame block's location to the pocket coordinate system Point3D frameLocation = point.clone(); - transformPoint(frameLocation, entrance, orientation - schematicDoorMeta, pocketOrigin); + transformPoint(frameLocation, schematicEntrance, orientation - schematicDoorMeta, pocketCenter); Entity mob = new MobObelisk(world); mob.setLocationAndAngles(frameLocation.getX(), frameLocation.getY(), frameLocation.getZ(), 1, 1); //TODO: Why not set the angles to 0? @.@ ~SenseiKiwi world.spawnEntityInWorld(mob); } - - Point3D entranceRiftLocation = entrance.clone(); - transformPoint(entranceRiftLocation, entrance, orientation - schematicDoorMeta, pocketOrigin); - dimHelper.instance.getLinkDataFromCoords(entranceRiftLocation.getX(), entranceRiftLocation.getY(), entranceRiftLocation.getZ(), world).linkOrientation=world.getBlockMetadata(entranceRiftLocation.getX(), entranceRiftLocation.getY()-1, entranceRiftLocation.getZ()); } private void transformPoint(Point3D position, Point3D srcOrigin, int angle, Point3D destOrigin) @@ -1155,7 +1117,7 @@ public class SchematicLoader rx = tx; rz = tz; break; - case 1: //270 degrees counterclockwise + case 1: //90 degrees clockwise rx = -tz; rz = tx; break; @@ -1163,7 +1125,7 @@ public class SchematicLoader rx = -tx; rz = -tz; break; - case 3: //90 degrees counterclockwise + case 3: //270 degrees clockwise rx = tz; rz = -tx; -- 2.39.5 From 63782c0fef7c806006b5aa06cdf106f24ed81d21 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Tue, 9 Jul 2013 03:47:28 -0400 Subject: [PATCH 3/3] Added Support for Arbitrary Entrance Directions Changed SchematicLoader so that schematics that have entrances that are not facing North will still be rotated properly. This involves a workaround for transformMetadata() since it assumes schematics are always saved "facing" North. I've tested this and it's working perfectly, with one exception. If you create a rift with dd-rift to a dungeon that wasn't saved pointing North, the rifts sometimes appear beside the player, instead of in the block where the player's head is. Sometimes you'll appear in the dungeon facing the right way. Other times, you'll appear inside a wall adjacent to the entrance or near the entrance facing the wrong way. I have not managed to narrow down why this happens. --- .../mod_pocketDim/SchematicLoader.java | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/SchematicLoader.java b/StevenDimDoors/mod_pocketDim/SchematicLoader.java index d4f4abe..bb78f83 100644 --- a/StevenDimDoors/mod_pocketDim/SchematicLoader.java +++ b/StevenDimDoors/mod_pocketDim/SchematicLoader.java @@ -33,8 +33,6 @@ import StevenDimDoors.mod_pocketDim.ticking.MobObelisk; public class SchematicLoader { private final static int EAST_DOOR_METADATA = 0; - private final static int SOUTH_DOOR_METADATA = 1; - private final static int WEST_DOOR_METADATA = 2; private final static int NORTH_DOOR_METADATA = 3; private DDProperties properties = DDProperties.instance(); @@ -812,10 +810,12 @@ public class SchematicLoader Point3D pocketCenter = new Point3D(riftX, riftY, riftZ); Point3D zeroPoint = new Point3D(0, 0, 0); - int schematicDoorMeta = 0; + //The direction in which the player will enter. Will be set below. The direction is encoded using + //the same values as door metadata. Those values are not the same as Minecraft's cardinal directions. + int entryDirection = 0; - //first loop through the .schematic to load in all rift locations, and monolith spawn locations. - //also finds the incomingLink location, which determines the final position and orientation of the dungeon + //First loop through the schematic to load in all rift locations and Monolith spawn locations. + //Also find the entry door, which determines the final position and orientation of the dungeon. for ( x = 0; x < width; ++x) { for ( y = 0; y < height; ++y) @@ -845,7 +845,7 @@ public class SchematicLoader else if (indexBelow >= 0 && blocks[indexBelow] == Block.doorWood.blockID) { schematicEntrance = new Point3D(x, y, z); - schematicDoorMeta = Math.abs(blockData[indexBelow] + 2) % 4; //TODO: Write a function for extracting a door's orientation from its metadata or at least change this to use bitwise operations. + entryDirection = Math.abs(blockData[indexBelow] + 2) % 4; //TODO: Write a function for extracting a door's orientation from its metadata or at least change this to use bitwise operations. } } else if (currentBlock == Block.endPortalFrame.blockID) @@ -856,9 +856,6 @@ public class SchematicLoader } } - //TODO: HAX REMOVE THIS! - schematicDoorMeta = NORTH_DOOR_METADATA; - //Loop to actually place the blocks for (x = 0; x < width; x++) { @@ -871,7 +868,7 @@ public class SchematicLoader pocketPoint.setY(y); pocketPoint.setZ(z); //Transform pocketPoint into the pocket coordinate system - transformPoint(pocketPoint, schematicEntrance, orientation - schematicDoorMeta, pocketCenter); + transformPoint(pocketPoint, schematicEntrance, orientation - entryDirection, pocketCenter); //Store the transformed coordinates realX = pocketPoint.getX(); realY = pocketPoint.getY(); @@ -897,7 +894,8 @@ public class SchematicLoader if (currentBlock > 0) { //Calculate new metadata for blocks that have orientations (e.g. doors, pistons) - int fixedMetadata = transformMetadata(blockMetadata, orientation, currentBlock); + //We're using a workaround to get the desired rotation relative to the schematic's entrance + int fixedMetadata = transformMetadata(blockMetadata, (orientation + NORTH_DOOR_METADATA - entryDirection + 16) % 4, currentBlock); //Convert vanilla doors to dim doors or place blocks if (currentBlock == Block.doorIron.blockID) @@ -946,11 +944,11 @@ public class SchematicLoader } //We'll use an extra block here to restrict the scope of these variables to just inside the block - //This is to avoid conflicts with the loops below + //This is to avoid declaration conflicts with the loops below { //Set the orientation of the rift exit Point3D entranceRiftLocation = schematicEntrance.clone(); - transformPoint(entranceRiftLocation, schematicEntrance, orientation - schematicDoorMeta, pocketCenter); + transformPoint(entranceRiftLocation, schematicEntrance, orientation - entryDirection, pocketCenter); LinkData sideLink = dimHelper.instance.getLinkDataFromCoords( entranceRiftLocation.getX(), entranceRiftLocation.getY(), @@ -960,6 +958,7 @@ public class SchematicLoader entranceRiftLocation.getX(), entranceRiftLocation.getY() - 1, entranceRiftLocation.getZ()); + System.out.println("Metadata Orientation: " + sideLink.linkOrientation); } //Generate the LinkData defined by the door placement, Iron Dim doors first @@ -971,7 +970,7 @@ public class SchematicLoader //Transform doorLocation to the pocket coordinate system Point3D doorLocation = point.clone(); - transformPoint(doorLocation, schematicEntrance, orientation - schematicDoorMeta, pocketCenter); + transformPoint(doorLocation, schematicEntrance, orientation - entryDirection, pocketCenter); int blockDirection = world.getBlockMetadata(doorLocation.getX(), doorLocation.getY() - 1, doorLocation.getZ()); //Rotate the link destination noise to point in the same direction as the door exit @@ -999,7 +998,7 @@ public class SchematicLoader { //Transform doorLocation to the pocket coordinate system. Point3D doorLocation = point.clone(); - transformPoint(doorLocation, schematicEntrance, orientation - schematicDoorMeta, pocketCenter); + transformPoint(doorLocation, schematicEntrance, orientation - entryDirection, pocketCenter); int blockDirection = world.getBlockMetadata(doorLocation.getX(), doorLocation.getY() - 1, doorLocation.getZ()); Point3D linkDestination = doorLocation.clone(); @@ -1069,7 +1068,7 @@ public class SchematicLoader { //Transform the frame block's location to the pocket coordinate system Point3D frameLocation = point.clone(); - transformPoint(frameLocation, schematicEntrance, orientation - schematicDoorMeta, pocketCenter); + transformPoint(frameLocation, schematicEntrance, orientation - entryDirection, pocketCenter); Entity mob = new MobObelisk(world); mob.setLocationAndAngles(frameLocation.getX(), frameLocation.getY(), frameLocation.getZ(), 1, 1); //TODO: Why not set the angles to 0? @.@ ~SenseiKiwi -- 2.39.5