From 4ceace1b470e9e58fee8cc139f86fdb89f8fdb30 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Mon, 17 Jun 2013 03:20:00 -0400 Subject: [PATCH 1/7] Added retrying on Rift Gateway generation Added a loop that allows RiftGenerator to retry generating a gateway if it picks an invalid location for it. It has a limited number of tries before it gives up and doesn't generate a gateway. I haven't added the logic for avoiding generating on top of trees, but that'll be easy to add now. --- .../mod_pocketDim/RiftGenerator.java | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/RiftGenerator.java b/StevenDimDoors/mod_pocketDim/RiftGenerator.java index 9eba0c1..da27ae5 100644 --- a/StevenDimDoors/mod_pocketDim/RiftGenerator.java +++ b/StevenDimDoors/mod_pocketDim/RiftGenerator.java @@ -20,6 +20,7 @@ public class RiftGenerator implements IWorldGenerator private static final int MAX_RIFT_Y = 250; private static final int CHUNK_LENGTH = 16; private static final int GATEWAY_RADIUS = 4; + private static final int MAX_GATEWAY_GENERATION_ATTEMPTS = 6; private static DDProperties properties = null; public RiftGenerator() @@ -39,7 +40,9 @@ public class RiftGenerator implements IWorldGenerator } int x, y, z; + int attempts; int blockID; + boolean valid; LinkData link; //Randomly decide whether to place a cluster of rifts here @@ -77,15 +80,22 @@ public class RiftGenerator implements IWorldGenerator //This only happens if a rift cluster was NOT generated. else if (random.nextInt(MAX_GATEWAY_GENERATION_CHANCE) < properties.GatewayGenerationChance) { - //Pick a random point on the surface of the chunk - x = chunkX * CHUNK_LENGTH - random.nextInt(CHUNK_LENGTH); - z = chunkZ * CHUNK_LENGTH - random.nextInt(CHUNK_LENGTH); - y = world.getHeightValue(x, z); + //Check locations for the gateway until we are satisfied or run out of attempts. + attempts = 0; + valid = false; + do + { + //Pick a random point on the surface of the chunk + x = chunkX * CHUNK_LENGTH - random.nextInt(CHUNK_LENGTH); + z = chunkZ * CHUNK_LENGTH - random.nextInt(CHUNK_LENGTH); + y = world.getHeightValue(x, z); + valid = checkGatewayLocation(world, x, y, z); + attempts++; + } + while (attempts < MAX_GATEWAY_GENERATION_ATTEMPTS && valid); - //Check if the point is within the acceptable altitude range, the block above that point is empty, - //and at least one of the two blocks under that point are opaque - if (y >= MIN_RIFT_Y && y <= MAX_RIFT_Y && world.isAirBlock(x, y + 1, z) && - world.isBlockOpaqueCube(x, y - 2, z) || world.isBlockOpaqueCube(x, y - 1, z)) + //Build the gateway if we found a valid location + if (valid) { //Create a two-way link between the upper block of the gateway and a pocket dimension //That pocket dimension is where we'll start a dungeon! @@ -147,4 +157,12 @@ public class RiftGenerator implements IWorldGenerator } } } + + private static boolean checkGatewayLocation(World world, int x, int y, int z) + { + //Check if the point is within the acceptable altitude range, the block above that point is empty, + //and at least one of the two blocks under that point are opaque + return (y >= MIN_RIFT_Y && y <= MAX_RIFT_Y && world.isAirBlock(x, y + 1, z) && + world.isBlockOpaqueCube(x, y - 2, z) || world.isBlockOpaqueCube(x, y - 1, z)); + } } From e7b064e3cbe3db98e58b22d2df0aa18ea9675f04 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Mon, 17 Jun 2013 03:38:10 -0400 Subject: [PATCH 2/7] Fixed Gen Directionality Bug and Minor Tweak I fixed a subtle bug in RiftGenerator. The code for picking random coordinates on the surface of a chunk would subtract a random amount from the coordinate of the chunk's corner. Unfortunately, subtracting meant that we would almost always generate coordinates OUTSIDE the intended chunk. The correct calculation was to add, not subtract. This meant that if you walked in a direction in which our gateways were generated outside of existing chunks, then their data would be lost and no gateways would generate! To reproduce this bug, max out the chance of generating gateways and fly in the direction that decreases X and Z. You must fly into new chunks. After passing the gateways produced when you spawn (if this is a new world) you'll see that gateways don't generate on the landscape. However, if you change directions, they'll begin generating again. In addition to fixing that bug, I also tweaked all the block setting calls in RiftGenerator so that they'll trigger block updates and send update packets to the client. I think triggering block updates will prevent unusual problems with floating sand, gravel, etc. --- .../mod_pocketDim/RiftGenerator.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/RiftGenerator.java b/StevenDimDoors/mod_pocketDim/RiftGenerator.java index da27ae5..6a72de7 100644 --- a/StevenDimDoors/mod_pocketDim/RiftGenerator.java +++ b/StevenDimDoors/mod_pocketDim/RiftGenerator.java @@ -52,8 +52,8 @@ public class RiftGenerator implements IWorldGenerator do { //Pick a random point on the surface of the chunk - x = chunkX * CHUNK_LENGTH - random.nextInt(CHUNK_LENGTH); - z = chunkZ * CHUNK_LENGTH - random.nextInt(CHUNK_LENGTH); + x = chunkX * CHUNK_LENGTH + random.nextInt(CHUNK_LENGTH); + z = chunkZ * CHUNK_LENGTH + random.nextInt(CHUNK_LENGTH); y = world.getHeightValue(x, z); //If the point is within the acceptable altitude range and the block above is empty, then place a rift @@ -86,8 +86,8 @@ public class RiftGenerator implements IWorldGenerator do { //Pick a random point on the surface of the chunk - x = chunkX * CHUNK_LENGTH - random.nextInt(CHUNK_LENGTH); - z = chunkZ * CHUNK_LENGTH - random.nextInt(CHUNK_LENGTH); + x = chunkX * CHUNK_LENGTH + random.nextInt(CHUNK_LENGTH); + z = chunkZ * CHUNK_LENGTH + random.nextInt(CHUNK_LENGTH); y = world.getHeightValue(x, z); valid = checkGatewayLocation(world, x, y, z); attempts++; @@ -122,38 +122,38 @@ public class RiftGenerator implements IWorldGenerator if (Math.abs(xc) + Math.abs(zc) < random.nextInt(2) + 3) { //Place Stone Bricks - world.setBlock(x + xc, y - 1, z + zc, blockID,0,2); + world.setBlock(x + xc, y - 1, z + zc, blockID, 0, 3); } else if (Math.abs(xc) + Math.abs(zc) < random.nextInt(3) + 3) { //Place Cracked Stone Bricks - world.setBlock(x + xc, y - 1, z + zc, blockID, 2, 2); + world.setBlock(x + xc, y - 1, z + zc, blockID, 2, 3); } } } } //Use Chiseled Stone Bricks to top off the pillars around the door - world.setBlock(x, y + 2, z + 1, blockID, 3, 2); - world.setBlock(x, y + 2, z - 1, blockID, 3, 2); + world.setBlock(x, y + 2, z + 1, blockID, 3, 3); + world.setBlock(x, y + 2, z - 1, blockID, 3, 3); } else { //Build the gateway out of Unraveled Fabric. Since nearly all the blocks in Limbo are of //that type, there is no point replacing the ground. Just build the tops of the columns here. blockID = properties.LimboBlockID; - world.setBlock(x, y + 2, z + 1, blockID, 0, 2); - world.setBlock(x, y + 2, z - 1, blockID, 0, 2); + world.setBlock(x, y + 2, z + 1, blockID, 0, 3); + world.setBlock(x, y + 2, z - 1, blockID, 0, 3); } //Place the shiny transient door into a dungeon ItemRiftBlade.placeDoorBlock(world, x, y + 1, z, 0, mod_pocketDim.transientDoor); //Build the columns around the door - world.setBlock(x, y + 1, z - 1, blockID, 0, 2); - world.setBlock(x, y + 1, z + 1, blockID, 0, 2); - world.setBlock(x, y, z - 1, blockID, 0, 2); - world.setBlock(x, y, z + 1, blockID, 0, 2); + world.setBlock(x, y + 1, z - 1, blockID, 0, 3); + world.setBlock(x, y + 1, z + 1, blockID, 0, 3); + world.setBlock(x, y, z - 1, blockID, 0, 3); + world.setBlock(x, y, z + 1, blockID, 0, 3); } } } From 654a47969292e0f8ae08718c99def6b64b476a39 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Mon, 17 Jun 2013 05:40:35 -0400 Subject: [PATCH 3/7] Improved Gateway and Rift Generation Added checks for the material that a gateway is being built upon. Now gateways no longer generate on top of trees. Combined with multiple generation attempts, there is a good chance that they will find a gap between trees to generate at ground level. I also added checks to stop gateways and rifts from generating on top of the Nether's bedrock. --- .../mod_pocketDim/RiftGenerator.java | 43 +++++++++++++------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/RiftGenerator.java b/StevenDimDoors/mod_pocketDim/RiftGenerator.java index 6a72de7..99d85f2 100644 --- a/StevenDimDoors/mod_pocketDim/RiftGenerator.java +++ b/StevenDimDoors/mod_pocketDim/RiftGenerator.java @@ -3,6 +3,7 @@ package StevenDimDoors.mod_pocketDim; import java.util.Random; import net.minecraft.block.Block; +import net.minecraft.block.material.Material; import net.minecraft.world.World; import net.minecraft.world.chunk.IChunkProvider; import StevenDimDoors.mod_pocketDim.helpers.dimHelper; @@ -20,7 +21,7 @@ public class RiftGenerator implements IWorldGenerator private static final int MAX_RIFT_Y = 250; private static final int CHUNK_LENGTH = 16; private static final int GATEWAY_RADIUS = 4; - private static final int MAX_GATEWAY_GENERATION_ATTEMPTS = 6; + private static final int MAX_GATEWAY_GENERATION_ATTEMPTS = 10; private static DDProperties properties = null; public RiftGenerator() @@ -56,8 +57,12 @@ public class RiftGenerator implements IWorldGenerator z = chunkZ * CHUNK_LENGTH + random.nextInt(CHUNK_LENGTH); y = world.getHeightValue(x, z); - //If the point is within the acceptable altitude range and the block above is empty, then place a rift - if (y >= MIN_RIFT_Y && y <= MAX_RIFT_Y && world.isAirBlock(x, y + 1, z)) + //If the point is within the acceptable altitude range, the block above is empty, and we're + //not building on bedrock, then generate a rift there + if (y >= MIN_RIFT_Y && y <= MAX_RIFT_Y && world.isAirBlock(x, y + 1, z) && + world.getBlockId(x, y, z) != Block.bedrock.blockID && //<-- Stops Nether roof spawning. DO NOT REMOVE! + world.getBlockId(x, y - 1, z) != Block.bedrock.blockID && + world.getBlockId(x, y - 2, z) != Block.bedrock.blockID) { //Create a link. If this is the first time, create a dungeon pocket and create a two-way link. //Otherwise, create a one-way link and connect to the destination of the first link. @@ -80,19 +85,18 @@ public class RiftGenerator implements IWorldGenerator //This only happens if a rift cluster was NOT generated. else if (random.nextInt(MAX_GATEWAY_GENERATION_CHANCE) < properties.GatewayGenerationChance) { - //Check locations for the gateway until we are satisfied or run out of attempts. - attempts = 0; valid = false; - do + x = y = z = 0; //Stop the compiler from freaking out + + //Check locations for the gateway until we are satisfied or run out of attempts. + for (attempts = 0; attempts < MAX_GATEWAY_GENERATION_ATTEMPTS && !valid; attempts++) { - //Pick a random point on the surface of the chunk + //Pick a random point on the surface of the chunk and check its materials x = chunkX * CHUNK_LENGTH + random.nextInt(CHUNK_LENGTH); z = chunkZ * CHUNK_LENGTH + random.nextInt(CHUNK_LENGTH); y = world.getHeightValue(x, z); valid = checkGatewayLocation(world, x, y, z); - attempts++; } - while (attempts < MAX_GATEWAY_GENERATION_ATTEMPTS && valid); //Build the gateway if we found a valid location if (valid) @@ -161,8 +165,23 @@ public class RiftGenerator implements IWorldGenerator private static boolean checkGatewayLocation(World world, int x, int y, int z) { //Check if the point is within the acceptable altitude range, the block above that point is empty, - //and at least one of the two blocks under that point are opaque - return (y >= MIN_RIFT_Y && y <= MAX_RIFT_Y && world.isAirBlock(x, y + 1, z) && - world.isBlockOpaqueCube(x, y - 2, z) || world.isBlockOpaqueCube(x, y - 1, z)); + //and the block two levels down is opaque and has a reasonable material. Plus that we're not building + //on top of bedrock. + return (y >= MIN_RIFT_Y && + y <= MAX_RIFT_Y && + world.isAirBlock(x, y + 1, z) && + world.getBlockId(x, y, z) != Block.bedrock.blockID && //<-- Stops Nether roof spawning. DO NOT REMOVE! + world.getBlockId(x, y - 1, z) != Block.bedrock.blockID && + checkFoundationMaterial(world, x, y - 2, z)); + } + + private static boolean checkFoundationMaterial(World world, int x, int y, int z) + { + //We check the material and opacity to prevent generating gateways on top of trees or houses, + //or on top of strange things like tall grass, water, slabs, or torches. + //We also want to avoid generating things on top of the Nether's bedrock! + Material material = world.getBlockMaterial(x, y, z); + return (material != Material.leaves && material != Material.wood && material != Material.pumpkin + && world.isBlockOpaqueCube(x, y, z) && world.getBlockId(x, y, z) != Block.bedrock.blockID); } } From 3b88d3a116e50536ba512029a069c5f820f2b5b5 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Mon, 17 Jun 2013 05:53:11 -0400 Subject: [PATCH 4/7] Cleaned up ItemStableFabric Cleaned up the indentation of ItemStableFabric and corrected some faulty String comparisons. --- .../mod_pocketDim/items/ItemStableFabric.java | 256 +++++++++--------- 1 file changed, 121 insertions(+), 135 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/items/ItemStableFabric.java b/StevenDimDoors/mod_pocketDim/items/ItemStableFabric.java index c152e66..a0d2ab7 100644 --- a/StevenDimDoors/mod_pocketDim/items/ItemStableFabric.java +++ b/StevenDimDoors/mod_pocketDim/items/ItemStableFabric.java @@ -27,85 +27,80 @@ import net.minecraftforge.common.RotationHelper; public class ItemStableFabric extends Item { - private Material doorMaterial; + private Material doorMaterial; - public ItemStableFabric(int par1, int par2) - { - super(par1); - // this.setitemIcon(Item.doorWood.getIconFromDamage(0)); - this.setCreativeTab(CreativeTabs.tabTransport); + public ItemStableFabric(int par1, int par2) + { + super(par1); + // this.setitemIcon(Item.doorWood.getIconFromDamage(0)); + this.setCreativeTab(CreativeTabs.tabTransport); - } - public void registerIcons(IconRegister par1IconRegister) - { - this.itemIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName().replace("item.", "")); + } + public void registerIcons(IconRegister par1IconRegister) + { + this.itemIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName().replace("item.", "")); - } - - public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) - { - - if(!par3World.isRemote) - { - System.out.println("Block metadata is "+par3World.getBlockMetadata(par4, par5, par6)); - System.out.println(par3World.getBiomeGenForCoords(par4, par6).biomeName); - + } - this.onItemRightClick(par1ItemStack, par3World, par2EntityPlayer); - - Block block = Block.blocksList[par3World.getBlockId(par4, par5, par6)]; - - - - - - } - //System.out.println("Block texture data is "+Block.blocksList[par3World.getBlockId(par4, par5, par6)].getBlockTexture(par3World,par4, par5, par6,par7).getIconName()); - //System.out.println("Block name is is "+Block.blocksList[par3World.getBlockId(par4, par5, par6)].getUnlocalizedName2()); + public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) + { - return true; - } - - - public MovingObjectPosition getMovingObjectPositionFromPlayer(World par1World, EntityPlayer par2EntityPlayer, boolean par3) - { - float var4 = 1.0F; - float var5 = par2EntityPlayer.prevRotationPitch + (par2EntityPlayer.rotationPitch - par2EntityPlayer.prevRotationPitch) * var4; - float var6 = par2EntityPlayer.prevRotationYaw + (par2EntityPlayer.rotationYaw - par2EntityPlayer.prevRotationYaw) * var4; - double var7 = par2EntityPlayer.prevPosX + (par2EntityPlayer.posX - par2EntityPlayer.prevPosX) * (double)var4; - double var9 = par2EntityPlayer.prevPosY + (par2EntityPlayer.posY - par2EntityPlayer.prevPosY) * (double)var4 + 1.62D - (double)par2EntityPlayer.yOffset; - double var11 = par2EntityPlayer.prevPosZ + (par2EntityPlayer.posZ - par2EntityPlayer.prevPosZ) * (double)var4; - Vec3 var13 = par1World.getWorldVec3Pool().getVecFromPool(var7, var9, var11); - float var14 = MathHelper.cos(-var6 * 0.017453292F - (float)Math.PI); - float var15 = MathHelper.sin(-var6 * 0.017453292F - (float)Math.PI); - float var16 = -MathHelper.cos(-var5 * 0.017453292F); - float var17 = MathHelper.sin(-var5 * 0.017453292F); - float var18 = var15 * var16; - float var20 = var14 * var16; - double var21 = 5.0D; - if (par2EntityPlayer instanceof EntityPlayerMP) - { - var21 = 4; - } - Vec3 var23 = var13.addVector((double)var18 * var21, (double)var17 * var21, (double)var20 * var21); - return par1World.rayTraceBlocks_do_do(var13, var23, true, false); - } - - public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) - { - - - if(this.isSteven(par3EntityPlayer)) - { - new Spells(par3EntityPlayer, par1ItemStack.stackSize).cast(); - //mod_pocketDim.proxy.startCasting(par3EntityPlayer, par1ItemStack.stackSize); + if(!par3World.isRemote) + { + System.out.println("Block metadata is "+par3World.getBlockMetadata(par4, par5, par6)); + System.out.println(par3World.getBiomeGenForCoords(par4, par6).biomeName); - - - - } - Boolean didFindThing=false; - MovingObjectPosition hit = this.getMovingObjectPositionFromPlayer(par3EntityPlayer.worldObj, par3EntityPlayer, false ); + + this.onItemRightClick(par1ItemStack, par3World, par2EntityPlayer); + + Block block = Block.blocksList[par3World.getBlockId(par4, par5, par6)]; + + + + + + } + //System.out.println("Block texture data is "+Block.blocksList[par3World.getBlockId(par4, par5, par6)].getBlockTexture(par3World,par4, par5, par6,par7).getIconName()); + //System.out.println("Block name is is "+Block.blocksList[par3World.getBlockId(par4, par5, par6)].getUnlocalizedName2()); + + return true; + } + + + public MovingObjectPosition getMovingObjectPositionFromPlayer(World par1World, EntityPlayer par2EntityPlayer, boolean par3) + { + float var4 = 1.0F; + float var5 = par2EntityPlayer.prevRotationPitch + (par2EntityPlayer.rotationPitch - par2EntityPlayer.prevRotationPitch) * var4; + float var6 = par2EntityPlayer.prevRotationYaw + (par2EntityPlayer.rotationYaw - par2EntityPlayer.prevRotationYaw) * var4; + double var7 = par2EntityPlayer.prevPosX + (par2EntityPlayer.posX - par2EntityPlayer.prevPosX) * (double)var4; + double var9 = par2EntityPlayer.prevPosY + (par2EntityPlayer.posY - par2EntityPlayer.prevPosY) * (double)var4 + 1.62D - (double)par2EntityPlayer.yOffset; + double var11 = par2EntityPlayer.prevPosZ + (par2EntityPlayer.posZ - par2EntityPlayer.prevPosZ) * (double)var4; + Vec3 var13 = par1World.getWorldVec3Pool().getVecFromPool(var7, var9, var11); + float var14 = MathHelper.cos(-var6 * 0.017453292F - (float)Math.PI); + float var15 = MathHelper.sin(-var6 * 0.017453292F - (float)Math.PI); + float var16 = -MathHelper.cos(-var5 * 0.017453292F); + float var17 = MathHelper.sin(-var5 * 0.017453292F); + float var18 = var15 * var16; + float var20 = var14 * var16; + double var21 = 5.0D; + if (par2EntityPlayer instanceof EntityPlayerMP) + { + var21 = 4; + } + Vec3 var23 = var13.addVector((double)var18 * var21, (double)var17 * var21, (double)var20 * var21); + return par1World.rayTraceBlocks_do_do(var13, var23, true, false); + } + + public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) + { + if (this.isSteven(par3EntityPlayer)) + { + new Spells(par3EntityPlayer, par1ItemStack.stackSize).cast(); + //mod_pocketDim.proxy.startCasting(par3EntityPlayer, par1ItemStack.stackSize); + } + + Boolean didFindThing=false; + MovingObjectPosition hit = this.getMovingObjectPositionFromPlayer(par3EntityPlayer.worldObj, par3EntityPlayer, false ); if(hit!=null&&!par2World.isRemote) { //if(par2World.getBlockId(hit.blockX, hit.blockY, hit.blockZ)==properties.RiftBlockID) @@ -113,74 +108,65 @@ public class ItemStableFabric extends Item LinkData link = dimHelper.instance.getLinkDataFromCoords(hit.blockX, hit.blockY, hit.blockZ, par2World); if(link!=null) { - Block var11; - if(par1ItemStack.getItem() instanceof itemExitDoor ) - { - var11 = mod_pocketDim.ExitDoor; - } - - else if(par1ItemStack.getItem() instanceof ItemChaosDoor ) - { - var11 = mod_pocketDim.chaosDoor; - } - else - { - var11 = mod_pocketDim.dimDoor; - } - - int par4 = hit.blockX; - int par5 = hit.blockY-1; - int par6 = hit.blockZ; - int par7 = 0 ; - - - + Block var11; + if(par1ItemStack.getItem() instanceof itemExitDoor ) + { + var11 = mod_pocketDim.ExitDoor; + } - if (par3EntityPlayer.canPlayerEdit(par4, par5, par6, par7, par1ItemStack) && par3EntityPlayer.canPlayerEdit(par4, par5 + 1, par6, par7, par1ItemStack)&&!par2World.isRemote) - { - int var12 = MathHelper.floor_double((double)((par3EntityPlayer.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3; - String cardinal= "default"; + else if(par1ItemStack.getItem() instanceof ItemChaosDoor ) + { + var11 = mod_pocketDim.chaosDoor; + } + else + { + var11 = mod_pocketDim.dimDoor; + } - switch(link.linkOrientation) - { - case 0: cardinal = "East"; - break; - case 1: cardinal = "South"; - break; - case 2: cardinal = "West"; - break; - case 3: cardinal = "North"; - break; - } - System.out.println("Link orientation is " + link.linkOrientation + "- "+cardinal); - } + int par4 = hit.blockX; + int par5 = hit.blockY-1; + int par6 = hit.blockZ; + int par7 = 0 ; + + + + + if (par3EntityPlayer.canPlayerEdit(par4, par5, par6, par7, par1ItemStack) && par3EntityPlayer.canPlayerEdit(par4, par5 + 1, par6, par7, par1ItemStack)&&!par2World.isRemote) + { + int var12 = MathHelper.floor_double((double)((par3EntityPlayer.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3; + String cardinal= "default"; + + switch(link.linkOrientation) + { + case 0: + cardinal = "East"; + break; + case 1: + cardinal = "South"; + break; + case 2: + cardinal = "West"; + break; + case 3: + cardinal = "North"; + break; + } + System.out.println("Link orientation is " + link.linkOrientation + " - " + cardinal); + } } } } - - return par1ItemStack; - - } - - - public boolean isSteven(EntityPlayer player) - { - if(player.username=="stevenrs11"||player.username=="Stevenrs11"||player.username=="StevenRS11") - { - return true; - } - return false; - } - public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) - { - - - - - + return par1ItemStack; + } + public boolean isSteven(EntityPlayer player) + { + return (player.username.equalsIgnoreCase("stevenrs11")); + } - - } + public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) + { + + } } From 17c911812627ac7463d95903420630417cab7631 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Mon, 17 Jun 2013 06:18:15 -0400 Subject: [PATCH 5/7] Fixed Dungeon Listing and Formatting Bugs Added a workaround so that the dungeon list produced by CommandAddDungeonRift does not have repeated names. Also cleaned up the code a bit - it's a mess in there. Part of the rewrite eliminated the bug that caused some dungeon names to be preceded by a backslash (or slash). I've noticed a different bug now - the dungeon tutorial file is being included in the list of dungeons. I'll be fixing that in the next commit. --- .../commands/CommandAddDungeonRift.java | 50 ++++--------------- .../mod_pocketDim/helpers/DungeonHelper.java | 27 ++++++++++ 2 files changed, 36 insertions(+), 41 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandAddDungeonRift.java b/StevenDimDoors/mod_pocketDim/commands/CommandAddDungeonRift.java index 517f780..e26b822 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandAddDungeonRift.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandAddDungeonRift.java @@ -1,20 +1,14 @@ package StevenDimDoors.mod_pocketDim.commands; -import java.util.ArrayList; +import java.util.Collection; -import cpw.mods.fml.common.FMLCommonHandler; - -import StevenDimDoors.mod_pocketDim.DimData; -import StevenDimDoors.mod_pocketDim.DungeonGenerator; -import StevenDimDoors.mod_pocketDim.LinkData; -import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; import net.minecraft.command.CommandBase; import net.minecraft.command.ICommandSender; import net.minecraft.util.MathHelper; -import net.minecraft.world.MinecraftException; -import net.minecraft.world.World; +import StevenDimDoors.mod_pocketDim.DungeonGenerator; +import StevenDimDoors.mod_pocketDim.LinkData; +import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; +import StevenDimDoors.mod_pocketDim.helpers.dimHelper; public class CommandAddDungeonRift extends CommandBase { @@ -54,39 +48,13 @@ public class CommandAddDungeonRift extends CommandBase link = dimHelper.instance.createPocket(link,true, true); } - else if(var2.length!=0&&var2[0].equals("list")) + else if (var2.length != 0 && var2[0].equals("list")) { - for(DungeonGenerator dungeonGen : dungeonHelper.registeredDungeons) + Collection dungeonNames = dungeonHelper.getDungeonNames(); + for (String name : dungeonNames) { - String dungeonName =dungeonGen.schematicPath; - if(dungeonName.contains("DimDoors_Custom_schematics")) - { - dungeonName= dungeonName.substring(dungeonName.indexOf("DimDoors_Custom_schematics")+26); - } - - dungeonName =dungeonName.replace("/", "").replace(".", "").replace("schematics", "").replace("schematic", ""); - - - this.getCommandSenderAsPlayer(var1).sendChatToPlayer(dungeonName); - + getCommandSenderAsPlayer(var1).sendChatToPlayer(name); } - - for(DungeonGenerator dungeonGen : dungeonHelper.customDungeons) - { - String dungeonName =dungeonGen.schematicPath; - if(dungeonName.contains("DimDoors_Custom_schematics")) - { - dungeonName= dungeonName.substring(dungeonName.indexOf("DimDoors_Custom_schematics")+26); - } - - dungeonName =dungeonName.replace("/", "").replace(".", "").replace("schematics", "").replace("schematic", ""); - - - this.getCommandSenderAsPlayer(var1).sendChatToPlayer(dungeonName); - - } - - } else if(var2.length!=0) diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index 98f80d1..ea8074b 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -3,6 +3,7 @@ package StevenDimDoors.mod_pocketDim.helpers; import java.io.File; import java.io.FileOutputStream; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Random; @@ -657,4 +658,30 @@ public class DungeonHelper } dimHelper.dimList.get(incoming.destDimID).dungeonGenerator = dungeon; } + + public Collection getDungeonNames() { + //Use a HashSet to guarantee that all dungeon names will be distinct. + //This shouldn't be necessary if we keep proper lists without repetitions, + //but it's a fool-proof workaround. + HashSet dungeonNames = new HashSet(); + dungeonNames.addAll( parseDungeonNames(registeredDungeons) ); + dungeonNames.addAll( parseDungeonNames(customDungeons) ); + return dungeonNames; + } + + private static ArrayList parseDungeonNames(ArrayList dungeons) + { + String name; + File schematic; + ArrayList names = new ArrayList(dungeons.size()); + + for (DungeonGenerator dungeon : dungeons) + { + schematic = new File(dungeon.schematicPath); + name = schematic.getName(); + name = name.substring(0, name.length() - SCHEMATIC_FILE_EXTENSION.length()); + names.add(name); + } + return names; + } } \ No newline at end of file From 30960acffa3fa8c33a2ae20750702d4ac87eefc4 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Mon, 17 Jun 2013 06:31:53 -0400 Subject: [PATCH 6/7] Fixed Tutorial Listing Bug and Improved Listing Fixed the bug that caused the dungeon creation tutorial to be listed as a schematic. We were listing all files in the custom schematic directory as a schematic, even though that file wasn't. I added filtering so that we only look at files that end with ".schematic". Also improved dungeon listing by sorting the name list in alphabetical order. That makes the list much easier to read through. --- .../mod_pocketDim/helpers/DungeonHelper.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index ea8074b..ad97297 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -4,6 +4,7 @@ import java.io.File; import java.io.FileOutputStream; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Random; @@ -217,16 +218,19 @@ public class DungeonHelper } } - public void importCustomDungeons(String dir) + public void importCustomDungeons(String path) { - File file = new File(dir); - File[] schematicNames = file.listFiles(); + File directory = new File(path); + File[] schematicNames = directory.listFiles(); - if (schematicNames!=null) + if (schematicNames != null) { - for(File schematicFile: schematicNames) + for (File schematicFile: schematicNames) { - this.registerCustomDungeon(schematicFile); + if (schematicFile.getName().endsWith(SCHEMATIC_FILE_EXTENSION)) + { + registerCustomDungeon(schematicFile); + } } } } @@ -660,13 +664,18 @@ public class DungeonHelper } public Collection getDungeonNames() { + //Use a HashSet to guarantee that all dungeon names will be distinct. //This shouldn't be necessary if we keep proper lists without repetitions, //but it's a fool-proof workaround. HashSet dungeonNames = new HashSet(); dungeonNames.addAll( parseDungeonNames(registeredDungeons) ); dungeonNames.addAll( parseDungeonNames(customDungeons) ); - return dungeonNames; + + //Sort dungeon names alphabetically + ArrayList sortedNames = new ArrayList(dungeonNames); + Collections.sort(sortedNames); + return sortedNames; } private static ArrayList parseDungeonNames(ArrayList dungeons) From b9f95a284a9256729d27519f0ec2fd3e7f676ca5 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Mon, 17 Jun 2013 06:34:35 -0400 Subject: [PATCH 7/7] Added a comment Just added a comment in DungeonHelper. --- StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java | 1 + 1 file changed, 1 insertion(+) diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index ad97297..80f9684 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -686,6 +686,7 @@ public class DungeonHelper for (DungeonGenerator dungeon : dungeons) { + //Retrieve the file name and strip off the file extension schematic = new File(dungeon.schematicPath); name = schematic.getName(); name = name.substring(0, name.length() - SCHEMATIC_FILE_EXTENSION.length());