From 1f4f38cfe39757006c444fcc8108ff70f8be3baf Mon Sep 17 00:00:00 2001 From: StevenRS11 Date: Sat, 15 Jun 2013 03:09:46 -0400 Subject: [PATCH 01/25] more monolith spawning --- .../mod_pocketDim/ticking/MobObelisk.java | 7 ++---- .../mod_pocketDim/world/pocketGenerator.java | 24 ++++++++++++++++--- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/ticking/MobObelisk.java b/StevenDimDoors/mod_pocketDim/ticking/MobObelisk.java index 6c3c044..8b7ca50 100644 --- a/StevenDimDoors/mod_pocketDim/ticking/MobObelisk.java +++ b/StevenDimDoors/mod_pocketDim/ticking/MobObelisk.java @@ -122,10 +122,7 @@ public class MobObelisk extends EntityFlying implements IMob if (this.isEntityAlive() && this.isEntityInsideOpaqueBlock()) { - this.pushOutOfBlocks(this.posX - (double)this.width * 0.35D, this.boundingBox.minY + 0.5D, this.posZ + (double)this.width * 0.35D); - this.pushOutOfBlocks(this.posX - (double)this.width * 0.35D, this.boundingBox.minY + 0.5D, this.posZ - (double)this.width * 0.35D); - this.pushOutOfBlocks(this.posX + (double)this.width * 0.35D, this.boundingBox.minY + 0.5D, this.posZ - (double)this.width * 0.35D); - this.pushOutOfBlocks(this.posX + (double)this.width * 0.35D, this.boundingBox.minY + 0.5D, this.posZ + (double)this.width * 0.35D); + this.setDead(); } @@ -137,7 +134,7 @@ public class MobObelisk extends EntityFlying implements IMob { if(this.soundTime<=0) { - this.playSound("mods.DimDoors.sfx.monk", 1.5F, 1F); + this.playSound("mods.DimDoors.sfx.monk", 1F, 1F); this.soundTime=100; } diff --git a/StevenDimDoors/mod_pocketDim/world/pocketGenerator.java b/StevenDimDoors/mod_pocketDim/world/pocketGenerator.java index ae37045..67a90e6 100644 --- a/StevenDimDoors/mod_pocketDim/world/pocketGenerator.java +++ b/StevenDimDoors/mod_pocketDim/world/pocketGenerator.java @@ -67,18 +67,26 @@ public class pocketGenerator extends ChunkProviderGenerate implements IChunkProv { if(dimHelper.dimList.containsKey(worldObj.provider.dimensionId)) { - if(!dimHelper.dimList.get(worldObj.provider.dimensionId).isDimRandomRift) + if(dimHelper.dimList.get(worldObj.provider.dimensionId).dungeonGenerator==null) { return; } + else + { + if(dimHelper.dimList.get(worldObj.provider.dimensionId).dungeonGenerator.isOpen) + { + return; + } + } } int y =0; int x = var2*16 + rand.nextInt(32)-8; int z = var3*16 + rand.nextInt(32)-8; + int yTest; do { - x = var2*16 + rand.nextInt(32-8); + x = var2*16 + rand.nextInt(32)-8; z = var3*16 + rand.nextInt(32)-8; while(this.worldObj.getBlockId(x, y, z)==0&&y<255) @@ -87,8 +95,18 @@ public class pocketGenerator extends ChunkProviderGenerate implements IChunkProv } y = yCoordHelper.getFirstUncovered(this.worldObj,x , y+2, z); + if(this.worldObj.getBlockId(x, y-1, z)!=mod_pocketDim.blockDimWall.blockID) + { + y= yCoordHelper.getFirstUncovered(this.worldObj,x , y+4+rand.nextInt(4), z); + } + + if(y>245) + { + return; + } + Entity mob = new MobObelisk(this.worldObj); - mob.setLocationAndAngles(x, y+rand.nextInt(4), z, 1, 1); + mob.setLocationAndAngles(x, y, z, 1, 1); this.worldObj.spawnEntityInWorld(mob); } From 9c33393d899448081676376f230aabd3b7f350ba Mon Sep 17 00:00:00 2001 From: StevenRS11 Date: Sat, 15 Jun 2013 04:19:08 -0400 Subject: [PATCH 02/25] release --- StevenDimDoors/mod_pocketDim/SchematicLoader.java | 2 +- StevenDimDoors/mod_pocketDim/blocks/BlockDimWallPerm.java | 1 + StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java | 3 +++ StevenDimDoors/mod_pocketDim/world/pocketGenerator.java | 2 +- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/SchematicLoader.java b/StevenDimDoors/mod_pocketDim/SchematicLoader.java index 96da6d8..1b4a5ee 100644 --- a/StevenDimDoors/mod_pocketDim/SchematicLoader.java +++ b/StevenDimDoors/mod_pocketDim/SchematicLoader.java @@ -287,7 +287,7 @@ public class SchematicLoader } - else if(blockID== Block.pistonBase.blockID||blockID==Block.pistonStickyBase.blockID||blockID==Block.dispenser.blockID||blockID==Block.dropper.blockID) + else if(blockID== Block.pistonBase.blockID||blockID==Block.pistonExtension.blockID||blockID==Block.pistonStickyBase.blockID||blockID==Block.dispenser.blockID||blockID==Block.dropper.blockID) { switch (metadata) { diff --git a/StevenDimDoors/mod_pocketDim/blocks/BlockDimWallPerm.java b/StevenDimDoors/mod_pocketDim/blocks/BlockDimWallPerm.java index 2668925..ba7c763 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/BlockDimWallPerm.java +++ b/StevenDimDoors/mod_pocketDim/blocks/BlockDimWallPerm.java @@ -119,6 +119,7 @@ public class BlockDimWallPerm extends Block { EntityPlayer.class.cast(par5Entity).setPositionAndUpdate( x, y, z ); + EntityPlayer.class.cast(par5Entity).fallDistance=0; } diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index 70ed9d7..1c915e9 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -221,6 +221,9 @@ public class DungeonHelper this.metadataFlipList.add(Block.pistonBase.blockID); this.metadataFlipList.add(Block.pistonStickyBase.blockID); + this.metadataFlipList.add(Block.pistonExtension.blockID); + + this.metadataFlipList.add(Block.redstoneComparatorIdle.blockID); this.metadataFlipList.add(Block.redstoneComparatorActive.blockID); this.metadataFlipList.add(Block.signPost.blockID); diff --git a/StevenDimDoors/mod_pocketDim/world/pocketGenerator.java b/StevenDimDoors/mod_pocketDim/world/pocketGenerator.java index 67a90e6..e3d80bd 100644 --- a/StevenDimDoors/mod_pocketDim/world/pocketGenerator.java +++ b/StevenDimDoors/mod_pocketDim/world/pocketGenerator.java @@ -97,7 +97,7 @@ public class pocketGenerator extends ChunkProviderGenerate implements IChunkProv if(this.worldObj.getBlockId(x, y-1, z)!=mod_pocketDim.blockDimWall.blockID) { - y= yCoordHelper.getFirstUncovered(this.worldObj,x , y+4+rand.nextInt(4), z); + y= y+rand.nextInt(4)+2; } if(y>245) From d75de7c2e0c295528f4a332ab87f196a77d26159 Mon Sep 17 00:00:00 2001 From: StevenRS11 Date: Sat, 15 Jun 2013 04:30:46 -0400 Subject: [PATCH 03/25] oknow --- StevenDimDoors/mod_pocketDim/world/pocketGenerator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/world/pocketGenerator.java b/StevenDimDoors/mod_pocketDim/world/pocketGenerator.java index e3d80bd..ced0c7f 100644 --- a/StevenDimDoors/mod_pocketDim/world/pocketGenerator.java +++ b/StevenDimDoors/mod_pocketDim/world/pocketGenerator.java @@ -80,8 +80,8 @@ public class pocketGenerator extends ChunkProviderGenerate implements IChunkProv } } int y =0; - int x = var2*16 + rand.nextInt(32)-8; - int z = var3*16 + rand.nextInt(32)-8; + int x = var2*16 + rand.nextInt(16); + int z = var3*16 + rand.nextInt(16); int yTest; do { From 21d94b7c6609bad4d6dcde1f2f6a6b141daaf565 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sat, 15 Jun 2013 06:32:30 -0400 Subject: [PATCH 04/25] Tweaked loot generation Decreased the weight of DD items very slightly to make them a little more rare. Added a section to DDLoot.mergeCategories() that searches for the enchanted book loot and fixes its weight to 3 (instead of the usual 1). This makes enchanted books slightly more common. I confirmed that books are actually spawning in loot chests. There is the possibility that there is a built-in chance of an enchanted book taking up a chest slot but not actually generating anything. --- StevenDimDoors/mod_pocketDim/DDLoot.java | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/DDLoot.java b/StevenDimDoors/mod_pocketDim/DDLoot.java index 7e7eadf..7e6c646 100644 --- a/StevenDimDoors/mod_pocketDim/DDLoot.java +++ b/StevenDimDoors/mod_pocketDim/DDLoot.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.Hashtable; import java.util.Random; +import net.minecraft.item.Item; import net.minecraft.util.WeightedRandomChestContent; import net.minecraftforge.common.ChestGenHooks; @@ -27,9 +28,9 @@ public class DDLoot { public static ChestGenHooks DungeonChestInfo = null; private static final int CHEST_SIZE = 5; - private static final int COMMON_LOOT_WEIGHT = 10; //As common as iron ingots - private static final int UNCOMMON_LOOT_WEIGHT = 5; //As common as iron armor loot - private static final int RARE_LOOT_WEIGHT = 3; //As common as diamonds + private static final int COMMON_LOOT_WEIGHT = 9; //1 less than weight of iron ingots + private static final int UNCOMMON_LOOT_WEIGHT = 4; //1 less than weight of iron armor + private static final int RARE_LOOT_WEIGHT = 1; //Same weight as music discs, golden apple private static final int DUNGEON_CHEST_WEIGHT_INFLATION = 10; // (weight of iron ingots in dungeon) / (weight of iron ingots in other chests) public static void registerInfo() @@ -113,6 +114,19 @@ public class DDLoot { } } + //I've added a minor hack here to make enchanted books more common + //If this is necessary for more items, create an override table and use that + //rather than hardcoding the changes below + final int enchantedBookID = Item.enchantedBook.itemID; + for (WeightedRandomChestContent item : container.values()) + { + if (item.theItemId.itemID == enchantedBookID) + { + item.itemWeight = 3; + break; + } + } + //Return merged list return new ArrayList( container.values() ); } From 4c23e5c7b8f267b4257e365f297afce7254d782c Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sat, 15 Jun 2013 07:24:28 -0400 Subject: [PATCH 05/25] Minor change to SchematicLoader Changed SchematicLoader to use DDLoot.DungeonChestInfo instead of requesting a reference to the same data through ChestGenHooks. Exactly the same data is being retrieved, but ChestGenHooks retrieves it by performing a lookup on a map relating loot categories to loot info, so it's slightly slower. No point in doing that if we have access to the reference directly. --- StevenDimDoors/mod_pocketDim/SchematicLoader.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/SchematicLoader.java b/StevenDimDoors/mod_pocketDim/SchematicLoader.java index 1b4a5ee..78f4c30 100644 --- a/StevenDimDoors/mod_pocketDim/SchematicLoader.java +++ b/StevenDimDoors/mod_pocketDim/SchematicLoader.java @@ -970,8 +970,7 @@ public class SchematicLoader if(world.getBlockTileEntity(i+xCooe, j+yCooe, k+zCooe) instanceof TileEntityChest) { TileEntityChest chest = (TileEntityChest) world.getBlockTileEntity(i+xCooe, j+yCooe, k+zCooe); - - ChestGenHooks info = ChestGenHooks.getInfo(DDLoot.DIMENSIONAL_DUNGEON_CHEST); + ChestGenHooks info = DDLoot.DungeonChestInfo; WeightedRandomChestContent.generateChestContents(rand, info.getItems(rand), (TileEntityChest)world.getBlockTileEntity(i+xCooe, j+yCooe, k+zCooe), info.getCount(rand)); } if(world.getBlockTileEntity(i+xCooe, j+yCooe, k+zCooe) instanceof TileEntityDispenser) From 4e8b8deab76ffe35333d3f8d075789981a2758e4 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sat, 15 Jun 2013 07:50:00 -0400 Subject: [PATCH 06/25] Formatted DungeonGenerator Changed the formatting in DungeonGenerator. Autocorrected indentation and removed extra empty lines to improve readability. None of the variables were changed since that would break compability with previous serialized instances. --- StevenDimDoors/mod_pocketDim/DungeonGenerator.java | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/DungeonGenerator.java b/StevenDimDoors/mod_pocketDim/DungeonGenerator.java index 5ea9872..906ade1 100644 --- a/StevenDimDoors/mod_pocketDim/DungeonGenerator.java +++ b/StevenDimDoors/mod_pocketDim/DungeonGenerator.java @@ -7,11 +7,8 @@ import java.util.Random; import net.minecraft.world.World; - - public class DungeonGenerator implements Serializable { - public int weight; public String schematicPath; public ArrayList sideRifts = new ArrayList(); @@ -22,21 +19,10 @@ public class DungeonGenerator implements Serializable public int exitDoorsSoFar=0; public int deadEndsSoFar=0; - - - - public DungeonGenerator(int weight, String schematicPath, Boolean isOpen) { this.weight=weight; this.schematicPath=schematicPath; this.isOpen=isOpen; - } - - - - - - } \ No newline at end of file From 172e3e3af140eeb2b7d3c3735e9d1845c678eaac Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sat, 15 Jun 2013 08:07:33 -0400 Subject: [PATCH 07/25] Cleaned up and tweaked DungeonHelper Cleaned up the indentation and empty lines in DungeonHelper. Set metadataFlipList and metadataNextList to have generic type Integer, since they're used to store block IDs. Whenever possible, we should always be using parameterized collections instead of leaving their types unspecified. I'd like to fix up the schematic HashMap in the future - unless it's necessary, we shouldn't be storing values of various types in that collection. Strongly typed variables or a class with the appropriate fields would be much cleaner. --- .../mod_pocketDim/helpers/DungeonHelper.java | 857 ++++++++---------- 1 file changed, 374 insertions(+), 483 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index 1c915e9..edbdc83 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -4,14 +4,10 @@ import java.io.File; import java.io.FileOutputStream; import java.util.ArrayList; import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; import java.util.Random; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.DungeonGenerator; @@ -19,190 +15,134 @@ import StevenDimDoors.mod_pocketDim.LinkData; import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.helpers.jnbt.ByteArrayTag; import StevenDimDoors.mod_pocketDim.helpers.jnbt.CompoundTag; -import StevenDimDoors.mod_pocketDim.helpers.jnbt.IntTag; import StevenDimDoors.mod_pocketDim.helpers.jnbt.ListTag; import StevenDimDoors.mod_pocketDim.helpers.jnbt.NBTOutputStream; import StevenDimDoors.mod_pocketDim.helpers.jnbt.ShortTag; -import StevenDimDoors.mod_pocketDim.helpers.jnbt.StringTag; import StevenDimDoors.mod_pocketDim.helpers.jnbt.Tag; -/** - - * @Return - */ - - - public class DungeonHelper { - - public DungeonHelper() - { - if (properties == null) - properties = DDProperties.instance(); - } - private static DDProperties properties = null; - + private Random rand = new Random(); - - public HashMap customDungeonStatus = new HashMap(); - public ArrayList customDungeons = new ArrayList(); - - public ArrayList registeredDungeons = new ArrayList(); - - public ArrayList weightedDungeonGenList = new ArrayList(); + public HashMap customDungeonStatus = new HashMap(); - - public ArrayList simpleHalls = new ArrayList(); + public ArrayList customDungeons = new ArrayList(); + public ArrayList registeredDungeons = new ArrayList(); + public ArrayList weightedDungeonGenList = new ArrayList(); + public ArrayList simpleHalls = new ArrayList(); + public ArrayList complexHalls = new ArrayList(); + public ArrayList deadEnds = new ArrayList(); + public ArrayList hubs = new ArrayList(); + public ArrayList mazes = new ArrayList(); + public ArrayList pistonTraps = new ArrayList(); + public ArrayList exits = new ArrayList(); - - public ArrayList complexHalls = new ArrayList(); - - - public ArrayList deadEnds = new ArrayList(); - - - public ArrayList hubs = new ArrayList(); - - - public ArrayList mazes = new ArrayList(); - - - public ArrayList pistonTraps = new ArrayList(); - - - public ArrayList exits = new ArrayList(); - public ArrayList tagList = new ArrayList(); + public ArrayList metadataFlipList = new ArrayList(); + public ArrayList metadataNextList = new ArrayList(); + + public DungeonGenerator defaultUp = new DungeonGenerator(0, "/schematic/simpleStairsUp.schematic", true); - - public ArrayList metadataFlipList = new ArrayList(); - - public ArrayList metadataNextList = new ArrayList(); - - public DungeonGenerator defaultUp = new DungeonGenerator(0, "/schematic/simpleStairsUp.schematic", true); - public void registerCustomDungeon(File schematicFile) { try - { - - if(schematicFile.getName().contains(".schematic")) { - String[] name = schematicFile.getName().split("_"); - - if(name.length<4) + if(schematicFile.getName().contains(".schematic")) { - System.out.println("Could not parse filename tags, not adding dungeon to generation lists"); - this.customDungeons.add(new DungeonGenerator(0,schematicFile.getAbsolutePath(),true)); - System.out.println("Imported "+schematicFile.getName()); + String[] name = schematicFile.getName().split("_"); - - } - else if(!(name[2].equals("open")||name[2].equals("closed"))||!this.tagList.contains(name[0])) - { - System.out.println("Could not parse filename tags, not adding dungeon to generation lists"); - this.customDungeons.add(new DungeonGenerator(0,schematicFile.getAbsolutePath(),true)); - System.out.println("Imported "+schematicFile.getName()); - - } - else - { - int count=0; - - boolean open= name[2].equals("open"); - - int weight = Integer.parseInt(name[3].replace(".schematic", "")); - - String path = schematicFile.getAbsolutePath(); - - while(count tileEntities = new ArrayList(); - - - ArrayList tileEntites= new ArrayList(); - byte[] blocks = new byte[width * height * length]; - byte[] addBlocks = null; - byte[] blockData = new byte[width * height * length]; - for (int x = 0; x < width; ++x) - { - for (int y = 0; y < height; ++y) - { - for (int z = 0; z < length; ++z) - { - int index = y * width * length + z * width + x; - int blockID = world.getBlockId(x+xMin, y+yMin, z+zMin); - int meta= world.getBlockMetadata(x+xMin, y+yMin, z+zMin); - - if(blockID==properties.DimensionalDoorID) - { - blockID=Block.doorIron.blockID; - } - if(blockID==properties.WarpDoorID) - { - blockID=Block.doorWood.blockID; + //ArrayList tileEntities = new ArrayList(); + ArrayList tileEntites = new ArrayList(); + byte[] blocks = new byte[width * height * length]; + byte[] addBlocks = null; + byte[] blockData = new byte[width * height * length]; - } - - // Save 4096 IDs in an AddBlocks section - if (blockID > 255) - { - if (addBlocks == null) - { // Lazily create section - addBlocks = new byte[(blocks.length >> 1) + 1]; - } + for (int x = 0; x < width; ++x) + { + for (int y = 0; y < height; ++y) + { + for (int z = 0; z < length; ++z) + { + int index = y * width * length + z * width + x; + int blockID = world.getBlockId(x+xMin, y+yMin, z+zMin); + int meta= world.getBlockMetadata(x+xMin, y+yMin, z+zMin); - addBlocks[index >> 1] = (byte) (((index & 1) == 0) ? - addBlocks[index >> 1] & 0xF0 | (blockID >> 8) & 0xF - : addBlocks[index >> 1] & 0xF | ((blockID >> 8) & 0xF) << 4); - } + if(blockID==properties.DimensionalDoorID) + { + blockID=Block.doorIron.blockID; + } + if(blockID==properties.WarpDoorID) + { + blockID=Block.doorWood.blockID; - blocks[index] = (byte) blockID; - blockData[index] = (byte) meta; - - if (Block.blocksList[blockID] instanceof BlockContainer) - { - //TODO fix this - /** + } + + // Save 4096 IDs in an AddBlocks section + if (blockID > 255) + { + if (addBlocks == null) + { // Lazily create section + addBlocks = new byte[(blocks.length >> 1) + 1]; + } + + addBlocks[index >> 1] = (byte) (((index & 1) == 0) ? + addBlocks[index >> 1] & 0xF0 | (blockID >> 8) & 0xF + : addBlocks[index >> 1] & 0xF | ((blockID >> 8) & 0xF) << 4); + } + + blocks[index] = (byte) blockID; + blockData[index] = (byte) meta; + + if (Block.blocksList[blockID] instanceof BlockContainer) + { + //TODO fix this + /** TileEntity tileEntityBlock = world.getBlockTileEntity(x+xMin, y+yMin, z+zMin); NBTTagCompound tag = new NBTTagCompound(); tileEntityBlock.writeToNBT(tag); - + CompoundTag tagC = new CompoundTag("TileEntity",Map.class.cast(tag.getTags())); - - + + // Get the list of key/values from the block - + if (tagC != null) { tileEntites.add(tagC); } - **/ - } - - - } - } - } - /** - * - * this.nbtdata.setShort("Width", width); + **/ + } + } + } + } + /** + * + * this.nbtdata.setShort("Width", width); this.nbtdata.setShort("Height", height); this.nbtdata.setShort("Length", length); - + this.nbtdata.setByteArray("Blocks", blocks); this.nbtdata.setByteArray("Data", blockData); - */ - - HashMap schematic = new HashMap(); - schematic.put("Blocks", new ByteArrayTag("Blocks", blocks)); - schematic.put("Data", new ByteArrayTag("Data", blockData)); - - schematic.put("Width", new ShortTag("Width", (short) width)); - schematic.put("Length", new ShortTag("Length", (short) length)); - schematic.put("Height", new ShortTag("Height", (short) height)); - schematic.put("TileEntites", new ListTag("TileEntities",CompoundTag.class,tileEntites)); - if (addBlocks != null) { - schematic.put("AddBlocks", new ByteArrayTag("AddBlocks", addBlocks)); - } - - CompoundTag schematicTag = new CompoundTag("Schematic", schematic); - try - { - - - NBTOutputStream stream = new NBTOutputStream(new FileOutputStream(file)); - stream.writeTag(schematicTag); - stream.close(); - } - catch(Exception e) - { - e.printStackTrace(); - } - this.registerCustomDungeon(new File(file)); - - return new DungeonGenerator(0,file,true); + */ + + HashMap schematic = new HashMap(); + schematic.put("Blocks", new ByteArrayTag("Blocks", blocks)); + schematic.put("Data", new ByteArrayTag("Data", blockData)); + + schematic.put("Width", new ShortTag("Width", (short) width)); + schematic.put("Length", new ShortTag("Length", (short) length)); + schematic.put("Height", new ShortTag("Height", (short) height)); + schematic.put("TileEntites", new ListTag("TileEntities",CompoundTag.class,tileEntites)); + if (addBlocks != null) { + schematic.put("AddBlocks", new ByteArrayTag("AddBlocks", addBlocks)); + } + + CompoundTag schematicTag = new CompoundTag("Schematic", schematic); + try + { + + + NBTOutputStream stream = new NBTOutputStream(new FileOutputStream(file)); + stream.writeTag(schematicTag); + stream.close(); + } + catch(Exception e) + { + e.printStackTrace(); + } + this.registerCustomDungeon(new File(file)); + + return new DungeonGenerator(0, file, true); } - - - + public void generateDungeonlink(LinkData incoming) { //DungeonGenerator dungeon = mod_pocketDim.registeredDungeons.get(new Random().nextInt(mod_pocketDim.registeredDungeons.size())); DungeonGenerator dungeon; int depth = dimHelper.instance.getDimDepth(incoming.locDimID)+2; - + int depthWeight = rand.nextInt(depth)+rand.nextInt(depth)-2; - + depth=depth-2; - // DungeonGenerator + // DungeonGenerator boolean flag = true; int count=10; try { - if(dimHelper.dimList.get(incoming.destDimID)!=null&&dimHelper.dimList.get(incoming.destDimID).dungeonGenerator!=null) { mod_pocketDim.loader.init(incoming); dimHelper.dimList.get(incoming.destDimID).dungeonGenerator=dimHelper.dimList.get(incoming.destDimID).dungeonGenerator; return; } - if(incoming.destYCoord>15) - { - do - { - count--; - flag = true; - dungeon = this.weightedDungeonGenList.get(rand.nextInt(weightedDungeonGenList.size())); - - if(depth<=1) + if(incoming.destYCoord>15) { - if(rand.nextBoolean()) + do { - dungeon = complexHalls.get(rand.nextInt(complexHalls.size())); + count--; + flag = true; + dungeon = this.weightedDungeonGenList.get(rand.nextInt(weightedDungeonGenList.size())); - } - else if(rand.nextBoolean()) - { - dungeon = hubs.get(rand.nextInt(hubs.size())); - - } - else if(rand.nextBoolean()) - { - dungeon = hubs.get(rand.nextInt(hubs.size())); - - } - else if(deadEnds.contains(dungeon)||exits.contains(dungeon)) + if(depth<=1) + { + if(rand.nextBoolean()) { - flag=false; + dungeon = complexHalls.get(rand.nextInt(complexHalls.size())); + } - - - - } - else if(depth<=3&&(deadEnds.contains(dungeon)||exits.contains(dungeon)||rand.nextBoolean())) - { - if(rand.nextBoolean()) - { - dungeon = hubs.get(rand.nextInt(hubs.size())); - - } - else if(rand.nextBoolean()) - { - dungeon = mazes.get(rand.nextInt(mazes.size())); - } - else if(rand.nextBoolean()) - { - dungeon = pistonTraps.get(rand.nextInt(pistonTraps.size())); + else if(rand.nextBoolean()) + { + dungeon = hubs.get(rand.nextInt(hubs.size())); - } - else - { - flag=false; - } - } - else if(rand.nextInt(3)==0&&!complexHalls.contains(dungeon)) - { - if(rand.nextInt(3)==0) - { - dungeon = simpleHalls.get(rand.nextInt(simpleHalls.size())); - } - else if(rand.nextBoolean()) - { - dungeon = pistonTraps.get(rand.nextInt(pistonTraps.size())); + } + else if(rand.nextBoolean()) + { + dungeon = hubs.get(rand.nextInt(hubs.size())); - } - else if(depth<4) - { - dungeon = hubs.get(rand.nextInt(hubs.size())); - - } - - } - else if(depthWeight-depthWeight/2>depth-4&&(deadEnds.contains(dungeon)||exits.contains(dungeon))) - { - if(rand.nextBoolean()) - { - dungeon = simpleHalls.get(rand.nextInt(simpleHalls.size())); - } - else if(rand.nextBoolean()) - { - dungeon = complexHalls.get(rand.nextInt(complexHalls.size())); - } - else if(rand.nextBoolean()) - { - dungeon = pistonTraps.get(rand.nextInt(pistonTraps.size())); - - } - else - { - flag=false; - } - } - else if(depthWeight>7&&hubs.contains(dungeon)) - { - if(rand.nextInt(12)+5depth-4&&(deadEnds.contains(dungeon)||exits.contains(dungeon))) + { + if(rand.nextBoolean()) + { + dungeon = simpleHalls.get(rand.nextInt(simpleHalls.size())); + } + else if(rand.nextBoolean()) + { + dungeon = complexHalls.get(rand.nextInt(complexHalls.size())); + } + else if(rand.nextBoolean()) + { + dungeon = pistonTraps.get(rand.nextInt(pistonTraps.size())); + + } + else + { + flag=false; + } + } + else if(depthWeight>7&&hubs.contains(dungeon)) + { + if(rand.nextInt(12)+510&&hubs.contains(dungeon)) + { + flag = false; } - - } - else - { - flag = false; } + while (!flag && count > 0); } - else if(depth>10&&hubs.contains(dungeon)) + else { - flag = false; + dungeon = defaultUp; } - } - while(!flag&&count>0); - } - else + catch (Exception e) { - dungeon= defaultUp; - } - } - catch(Exception e) - { - if(weightedDungeonGenList.size()>0) + if (weightedDungeonGenList.size() > 0) { dungeon = weightedDungeonGenList.get(rand.nextInt(weightedDungeonGenList.size())); } @@ -673,22 +580,6 @@ public class DungeonHelper return; } } - - - - dimHelper.dimList.get(incoming.destDimID).dungeonGenerator=dungeon; - //loader.generateSchematic(incoming,0,0,0); - - - - - - - - + dimHelper.dimList.get(incoming.destDimID).dungeonGenerator = dungeon; } - - - - } \ No newline at end of file From 84e430abfdd1700f63a95a259104ce1ad3614b9f Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sat, 15 Jun 2013 08:13:50 -0400 Subject: [PATCH 08/25] Improved DungeonHelper I was able to infer that HashMap schematic should have generic parameters and changed the declaration accordingly. All generic collections in DungeonHelper are now parameterized properly. --- .../mod_pocketDim/helpers/DungeonHelper.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index edbdc83..f2c4c2b 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -395,23 +395,24 @@ public class DungeonHelper this.nbtdata.setByteArray("Data", blockData); */ - HashMap schematic = new HashMap(); + HashMap schematic = new HashMap(); + schematic.put("Blocks", new ByteArrayTag("Blocks", blocks)); schematic.put("Data", new ByteArrayTag("Data", blockData)); - + schematic.put("Width", new ShortTag("Width", (short) width)); schematic.put("Length", new ShortTag("Length", (short) length)); schematic.put("Height", new ShortTag("Height", (short) height)); - schematic.put("TileEntites", new ListTag("TileEntities",CompoundTag.class,tileEntites)); - if (addBlocks != null) { + schematic.put("TileEntites", new ListTag("TileEntities", CompoundTag.class,tileEntites)); + + if (addBlocks != null) + { schematic.put("AddBlocks", new ByteArrayTag("AddBlocks", addBlocks)); } CompoundTag schematicTag = new CompoundTag("Schematic", schematic); try { - - NBTOutputStream stream = new NBTOutputStream(new FileOutputStream(file)); stream.writeTag(schematicTag); stream.close(); From 51969793a5e4777de517cdfcb30dd6d8bde0662f Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sat, 15 Jun 2013 08:46:28 -0400 Subject: [PATCH 09/25] Fixed minor bug and cleaned up DungeonHelper Set various lists of DungeonGenerators to private - there was no need to make them public fields. While cleaning up the code before, I accidentally erased the default constructor, which handled loading a reference to DDProperties. I've put the code back in so that the class works correctly. --- .../mod_pocketDim/helpers/DungeonHelper.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index f2c4c2b..9a8936d 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -30,14 +30,15 @@ public class DungeonHelper public ArrayList customDungeons = new ArrayList(); public ArrayList registeredDungeons = new ArrayList(); - public ArrayList weightedDungeonGenList = new ArrayList(); - public ArrayList simpleHalls = new ArrayList(); - public ArrayList complexHalls = new ArrayList(); - public ArrayList deadEnds = new ArrayList(); - public ArrayList hubs = new ArrayList(); - public ArrayList mazes = new ArrayList(); - public ArrayList pistonTraps = new ArrayList(); - public ArrayList exits = new ArrayList(); + + private ArrayList weightedDungeonGenList = new ArrayList(); + private ArrayList simpleHalls = new ArrayList(); + private ArrayList complexHalls = new ArrayList(); + private ArrayList deadEnds = new ArrayList(); + private ArrayList hubs = new ArrayList(); + private ArrayList mazes = new ArrayList(); + private ArrayList pistonTraps = new ArrayList(); + private ArrayList exits = new ArrayList(); public ArrayList tagList = new ArrayList(); @@ -46,6 +47,12 @@ public class DungeonHelper public DungeonGenerator defaultUp = new DungeonGenerator(0, "/schematic/simpleStairsUp.schematic", true); + public DungeonHelper() + { + if (properties == null) + properties = DDProperties.instance(); + } + public void registerCustomDungeon(File schematicFile) { try From 1e2dedaafe6d84e755c68aec8bed4c9e950c8a86 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sat, 15 Jun 2013 10:25:50 -0400 Subject: [PATCH 10/25] Overhauling DungeonHelper I changed the name filter for schematic names from CommandEndDungeonCreation to DungeonHelper, and renamed it to NamePattern. I also rewrote most of registerCustomDungeon() to be much more concise. The changes are incomplete but I'm making an intermediate commit. The aim is to change DungeonHelper into a proper singleton and to eliminate the clunky sections that manually map dungeon categories to their corresponding lists. Instead, I'll use data structures to implement that far more efficiently. --- .../commands/CommandEndDungeonCreation.java | 8 +- .../mod_pocketDim/helpers/DungeonHelper.java | 169 +++++++++++------- .../mod_pocketDim/mod_pocketDim.java | 2 +- 3 files changed, 105 insertions(+), 74 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandEndDungeonCreation.java b/StevenDimDoors/mod_pocketDim/commands/CommandEndDungeonCreation.java index 8c8971a..891155a 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandEndDungeonCreation.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandEndDungeonCreation.java @@ -8,11 +8,11 @@ import net.minecraft.entity.player.EntityPlayer; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.DungeonGenerator; import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; public class CommandEndDungeonCreation extends CommandBase { private static DDProperties properties = null; - private static Pattern nameFilter = Pattern.compile("[A-Za-z0-9_]+"); public CommandEndDungeonCreation() { @@ -59,13 +59,13 @@ public class CommandEndDungeonCreation extends CommandBase else if(!player.worldObj.isRemote) { //Check that the dungeon name is valid to prevent directory traversal and other forms of abuse - if (nameFilter.matcher(var2[0]).matches()) + if (DungeonHelper.NamePattern.matcher(var2[0]).matches()) { DungeonGenerator newDungeon = mod_pocketDim.dungeonHelper.exportDungeon(player.worldObj, x, y, z, properties.CustomSchematicDirectory + "/" + var2[0] + ".schematic"); - player.sendChatToPlayer("created dungeon schematic in " + properties.CustomSchematicDirectory +"/"+var2[0]+".schematic"); + player.sendChatToPlayer("created dungeon schematic in " + properties.CustomSchematicDirectory + "/" + var2[0]+".schematic"); mod_pocketDim.dungeonHelper.customDungeons.add(newDungeon); - if(mod_pocketDim.dungeonHelper.customDungeonStatus.containsKey(player.worldObj.provider.dimensionId)&&!player.worldObj.isRemote) + if (mod_pocketDim.dungeonHelper.customDungeonStatus.containsKey(player.worldObj.provider.dimensionId) && !player.worldObj.isRemote) { // mod_pocketDim.dungeonHelper.customDungeonStatus.remove(player.worldObj.provider.dimensionId); // dimHelper.instance.teleportToPocket(player.worldObj, mod_pocketDim.dungeonHelper.customDungeonStatus.get(player.worldObj.provider.dimensionId), player); diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index 9a8936d..f36c3b9 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -5,6 +5,7 @@ import java.io.FileOutputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.Random; +import java.util.regex.Pattern; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; @@ -25,7 +26,11 @@ public class DungeonHelper private static DDProperties properties = null; private Random rand = new Random(); + private static final String SCHEMATIC_FILE_EXTENSION = ".schematic"; + private static final int DEFAULT_DUNGEON_WEIGHT = 100; + public static Pattern NamePattern = Pattern.compile("[A-Za-z0-9_]+"); + public HashMap customDungeonStatus = new HashMap(); public ArrayList customDungeons = new ArrayList(); @@ -53,96 +58,122 @@ public class DungeonHelper properties = DDProperties.instance(); } + public boolean validateSchematicName(String name) + { + String[] dungeonData = name.split("_"); + + //Check for a valid number of parts + if (dungeonData.length < 3 || dungeonData.length > 4) + return false; + + //Check if the category is valid + if (!tagList.contains(dungeonData[0])) + return false; + + //Check if the name is valid + if (!NamePattern.matcher(dungeonData[1]).matches()) + return false; + + //Check if the open/closed flag is present + if (!dungeonData[2].equalsIgnoreCase("open") && !dungeonData[2].equalsIgnoreCase("closed")) + return false; + + //If the weight is present, check that it is valid + if (dungeonData.length == 4) + { + try + { + int weight = Integer.parseInt(dungeonData[3]); + if (weight < 0) + return false; + } + catch (NumberFormatException e) + { + //Not a number + return false; + } + } + return true; + } + public void registerCustomDungeon(File schematicFile) { + String name = schematicFile.getName(); try { - if(schematicFile.getName().contains(".schematic")) + if (name.endsWith(SCHEMATIC_FILE_EXTENSION) && validateSchematicName(name)) { - String[] name = schematicFile.getName().split("_"); + //Strip off the file extension while splitting the file name + String[] dungeonData = name.substring(0, name.length() - SCHEMATIC_FILE_EXTENSION.length()).split("_"); + + String path = schematicFile.getAbsolutePath(); + boolean open = dungeonData[2].equals("open"); + int weight = (dungeonData.length == 4) ? Integer.parseInt(dungeonData[3]) : DEFAULT_DUNGEON_WEIGHT; - if(name.length<4) + //Change this code so that instead of using IFs, we use a hash table mapping (category) -> (list) + /*while(count Date: Sat, 15 Jun 2013 11:21:49 -0400 Subject: [PATCH 11/25] Improved DungeonHelper.registerCustomDungeon() Changed the function to use a Hashtable mapping dungeon types to their respective lists so that it wouldn't be necessary to hardcode a condition for each type. The code is much shorter now and we can add new types with ease. The next stage will be to remove weightedDungeonGetList, if possible, so that we don't have to construct a list with duplicates just to have weights. The loop that repeatedly inserted dungeons into that list has been removed anyway, but it shouldn't affect anything since custom dungeon integration was broken and weights were being ignored. --- .../mod_pocketDim/helpers/DungeonHelper.java | 121 +++++++++--------- .../mod_pocketDim/mod_pocketDim.java | 1 - 2 files changed, 58 insertions(+), 64 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index f36c3b9..6711eba 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -4,6 +4,8 @@ import java.io.File; import java.io.FileOutputStream; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; +import java.util.Hashtable; import java.util.Random; import java.util.regex.Pattern; @@ -25,11 +27,32 @@ public class DungeonHelper { private static DDProperties properties = null; - private Random rand = new Random(); + public static final Pattern NamePattern = Pattern.compile("[A-Za-z0-9_]+"); + private static final String SCHEMATIC_FILE_EXTENSION = ".schematic"; private static final int DEFAULT_DUNGEON_WEIGHT = 100; - - public static Pattern NamePattern = Pattern.compile("[A-Za-z0-9_]+"); + + private static final String HUB_DUNGEON_TYPE = "Hub"; + private static final String TRAP_DUNGEON_TYPE = "Trap"; + private static final String SIMPLE_HALL_DUNGEON_TYPE = "SimpleHall"; + private static final String COMPLEX_HALL_DUNGEON_TYPE = "ComplexHall"; + private static final String EXIT_DUNGEON_TYPE = "Exit"; + private static final String DEAD_END_DUNGEON_TYPE = "DeadEnd"; + private static final String MAZE_DUNGEON_TYPE = "Maze"; + + //The list of dungeon types will be kept as an array for now. If we allow new + //dungeon types in the future, then this can be changed to an ArrayList. + private static final String[] DUNGEON_TYPES = new String[] { + HUB_DUNGEON_TYPE, + TRAP_DUNGEON_TYPE, + SIMPLE_HALL_DUNGEON_TYPE, + COMPLEX_HALL_DUNGEON_TYPE, + EXIT_DUNGEON_TYPE, + DEAD_END_DUNGEON_TYPE, + MAZE_DUNGEON_TYPE + }; + + private Random rand = new Random(); public HashMap customDungeonStatus = new HashMap(); @@ -45,15 +68,33 @@ public class DungeonHelper private ArrayList pistonTraps = new ArrayList(); private ArrayList exits = new ArrayList(); - public ArrayList tagList = new ArrayList(); - public ArrayList metadataFlipList = new ArrayList(); public ArrayList metadataNextList = new ArrayList(); public DungeonGenerator defaultUp = new DungeonGenerator(0, "/schematic/simpleStairsUp.schematic", true); - + private HashSet dungeonTypeChecker; + private Hashtable> dungeonTypeMapping; + public DungeonHelper() { + //Load the dungeon type checker with the list of all types in lowercase. + //Capitalization matters for matching in a hash set. + dungeonTypeChecker = new HashSet(); + for (String dungeonType : DUNGEON_TYPES) + { + dungeonTypeChecker.add(dungeonType.toLowerCase()); + } + + //Add all the basic dungeon types to dungeonTypeMapping + dungeonTypeMapping.put(SIMPLE_HALL_DUNGEON_TYPE, simpleHalls); + dungeonTypeMapping.put(COMPLEX_HALL_DUNGEON_TYPE, complexHalls); + dungeonTypeMapping.put(HUB_DUNGEON_TYPE, hubs); + dungeonTypeMapping.put(EXIT_DUNGEON_TYPE, exits); + dungeonTypeMapping.put(DEAD_END_DUNGEON_TYPE, deadEnds); + dungeonTypeMapping.put(MAZE_DUNGEON_TYPE, mazes); + dungeonTypeMapping.put(TRAP_DUNGEON_TYPE, pistonTraps); + + //Load our reference to the DDProperties singleton if (properties == null) properties = DDProperties.instance(); } @@ -66,8 +107,8 @@ public class DungeonHelper if (dungeonData.length < 3 || dungeonData.length > 4) return false; - //Check if the category is valid - if (!tagList.contains(dungeonData[0])) + //Check if the dungeon type is valid + if (!dungeonTypeChecker.contains(dungeonData[0].toLowerCase())) return false; //Check if the name is valid @@ -99,6 +140,7 @@ public class DungeonHelper public void registerCustomDungeon(File schematicFile) { String name = schematicFile.getName(); + String path = schematicFile.getAbsolutePath(); try { if (name.endsWith(SCHEMATIC_FILE_EXTENSION) && validateSchematicName(name)) @@ -106,58 +148,22 @@ public class DungeonHelper //Strip off the file extension while splitting the file name String[] dungeonData = name.substring(0, name.length() - SCHEMATIC_FILE_EXTENSION.length()).split("_"); - String path = schematicFile.getAbsolutePath(); + String dungeonType = dungeonData[0].toLowerCase(); boolean open = dungeonData[2].equals("open"); int weight = (dungeonData.length == 4) ? Integer.parseInt(dungeonData[3]) : DEFAULT_DUNGEON_WEIGHT; + + //Add this custom dungeon to the list corresponding to its type + DungeonGenerator generator = new DungeonGenerator(weight, path, open); - //Change this code so that instead of using IFs, we use a hash table mapping (category) -> (list) - /*while(count Date: Sat, 15 Jun 2013 11:30:05 -0400 Subject: [PATCH 12/25] Fixed duplicate custom dungeon listing Removed a line in CommandEndDungeonCreation that inserted a new dungeon directly into DungeonHelper.customDungeons. This had a chance of causing a duplicate listing. registerCustomDungeon() was already being invoked before and if reading tags from the file name failed, the dungeon would get added twice. This could explain some of the buggy dungeon listing that would appear during testing. --- .../mod_pocketDim/commands/CommandEndDungeonCreation.java | 1 - StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandEndDungeonCreation.java b/StevenDimDoors/mod_pocketDim/commands/CommandEndDungeonCreation.java index 891155a..37192c9 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandEndDungeonCreation.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandEndDungeonCreation.java @@ -63,7 +63,6 @@ public class CommandEndDungeonCreation extends CommandBase { DungeonGenerator newDungeon = mod_pocketDim.dungeonHelper.exportDungeon(player.worldObj, x, y, z, properties.CustomSchematicDirectory + "/" + var2[0] + ".schematic"); player.sendChatToPlayer("created dungeon schematic in " + properties.CustomSchematicDirectory + "/" + var2[0]+".schematic"); - mod_pocketDim.dungeonHelper.customDungeons.add(newDungeon); if (mod_pocketDim.dungeonHelper.customDungeonStatus.containsKey(player.worldObj.provider.dimensionId) && !player.worldObj.isRemote) { diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index 6711eba..5ab4174 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -31,6 +31,7 @@ public class DungeonHelper private static final String SCHEMATIC_FILE_EXTENSION = ".schematic"; private static final int DEFAULT_DUNGEON_WEIGHT = 100; + private static final int MAX_DUNGEON_WEIGHT = 10000; //Used to prevent overflows and math breaking down private static final String HUB_DUNGEON_TYPE = "Hub"; private static final String TRAP_DUNGEON_TYPE = "Trap"; @@ -125,7 +126,7 @@ public class DungeonHelper try { int weight = Integer.parseInt(dungeonData[3]); - if (weight < 0) + if (weight < 0 || weight > MAX_DUNGEON_WEIGHT) return false; } catch (NumberFormatException e) @@ -158,6 +159,7 @@ public class DungeonHelper dungeonTypeMapping.get(dungeonType).add(generator); weightedDungeonGenList.add(generator); registeredDungeons.add(generator); + customDungeons.add(generator); System.out.println("Imported " + name); } else From f56893018dd637533a990197b83dd62dd3592709 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sun, 16 Jun 2013 01:00:05 -0400 Subject: [PATCH 13/25] Changed DungeonHelper into a singleton Changed DungeonHelper into a singleton. Changed code in other classes to interface with it properly. --- .../mod_pocketDim/SchematicLoader.java | 2 +- .../commands/CommandAddDungeonRift.java | 12 ++++++---- .../commands/CommandEndDungeonCreation.java | 8 ++++--- .../commands/CommandStartDungeonCreation.java | 2 +- .../mod_pocketDim/helpers/DungeonHelper.java | 24 ++++++++++++++++++- .../mod_pocketDim/helpers/dimHelper.java | 2 +- .../mod_pocketDim/mod_pocketDim.java | 19 ++------------- 7 files changed, 40 insertions(+), 29 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/SchematicLoader.java b/StevenDimDoors/mod_pocketDim/SchematicLoader.java index 78f4c30..3ad7d5b 100644 --- a/StevenDimDoors/mod_pocketDim/SchematicLoader.java +++ b/StevenDimDoors/mod_pocketDim/SchematicLoader.java @@ -159,7 +159,7 @@ public class SchematicLoader } public int transformMetadata(int metadata, int orientation, int blockID) { - if(mod_pocketDim.dungeonHelper.metadataFlipList.contains(blockID)) + if (DungeonHelper.instance().metadataFlipList.contains(blockID)) { diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandAddDungeonRift.java b/StevenDimDoors/mod_pocketDim/commands/CommandAddDungeonRift.java index 9106680..517f780 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandAddDungeonRift.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandAddDungeonRift.java @@ -8,6 +8,7 @@ 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; @@ -27,8 +28,9 @@ public class CommandAddDungeonRift extends CommandBase @Override public void processCommand(ICommandSender var1, String[] var2) - { + DungeonHelper dungeonHelper = DungeonHelper.instance(); + if(var2==null||this.getCommandSenderAsPlayer(var1).worldObj.isRemote) { return; @@ -54,7 +56,7 @@ public class CommandAddDungeonRift extends CommandBase } else if(var2.length!=0&&var2[0].equals("list")) { - for(DungeonGenerator dungeonGen : mod_pocketDim.dungeonHelper.registeredDungeons) + for(DungeonGenerator dungeonGen : dungeonHelper.registeredDungeons) { String dungeonName =dungeonGen.schematicPath; if(dungeonName.contains("DimDoors_Custom_schematics")) @@ -69,7 +71,7 @@ public class CommandAddDungeonRift extends CommandBase } - for(DungeonGenerator dungeonGen : mod_pocketDim.dungeonHelper.customDungeons) + for(DungeonGenerator dungeonGen : dungeonHelper.customDungeons) { String dungeonName =dungeonGen.schematicPath; if(dungeonName.contains("DimDoors_Custom_schematics")) @@ -89,7 +91,7 @@ public class CommandAddDungeonRift extends CommandBase else if(var2.length!=0) { - for(DungeonGenerator dungeonGen : mod_pocketDim.dungeonHelper.registeredDungeons) + for(DungeonGenerator dungeonGen : dungeonHelper.registeredDungeons) { String dungeonName =dungeonGen.schematicPath.toLowerCase(); @@ -113,7 +115,7 @@ public class CommandAddDungeonRift extends CommandBase } - for(DungeonGenerator dungeonGen : mod_pocketDim.dungeonHelper.customDungeons) + for(DungeonGenerator dungeonGen : dungeonHelper.customDungeons) { String dungeonName =dungeonGen.schematicPath.toLowerCase(); diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandEndDungeonCreation.java b/StevenDimDoors/mod_pocketDim/commands/CommandEndDungeonCreation.java index 37192c9..d17ef4c 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandEndDungeonCreation.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandEndDungeonCreation.java @@ -28,9 +28,11 @@ public class CommandEndDungeonCreation extends CommandBase @Override public void processCommand(ICommandSender var1, String[] var2) { + DungeonHelper dungeonHelper = DungeonHelper.instance(); + EntityPlayer player = this.getCommandSenderAsPlayer(var1); - if(!mod_pocketDim.dungeonHelper.customDungeonStatus.containsKey(player.worldObj.provider.dimensionId)) + if (!dungeonHelper.customDungeonStatus.containsKey(player.worldObj.provider.dimensionId)) { if(var2.length<2) { @@ -61,10 +63,10 @@ public class CommandEndDungeonCreation extends CommandBase //Check that the dungeon name is valid to prevent directory traversal and other forms of abuse if (DungeonHelper.NamePattern.matcher(var2[0]).matches()) { - DungeonGenerator newDungeon = mod_pocketDim.dungeonHelper.exportDungeon(player.worldObj, x, y, z, properties.CustomSchematicDirectory + "/" + var2[0] + ".schematic"); + DungeonGenerator newDungeon = dungeonHelper.exportDungeon(player.worldObj, x, y, z, properties.CustomSchematicDirectory + "/" + var2[0] + ".schematic"); player.sendChatToPlayer("created dungeon schematic in " + properties.CustomSchematicDirectory + "/" + var2[0]+".schematic"); - if (mod_pocketDim.dungeonHelper.customDungeonStatus.containsKey(player.worldObj.provider.dimensionId) && !player.worldObj.isRemote) + if (dungeonHelper.customDungeonStatus.containsKey(player.worldObj.provider.dimensionId) && !player.worldObj.isRemote) { // mod_pocketDim.dungeonHelper.customDungeonStatus.remove(player.worldObj.provider.dimensionId); // dimHelper.instance.teleportToPocket(player.worldObj, mod_pocketDim.dungeonHelper.customDungeonStatus.get(player.worldObj.provider.dimensionId), player); diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandStartDungeonCreation.java b/StevenDimDoors/mod_pocketDim/commands/CommandStartDungeonCreation.java index 011bd6c..57aa12e 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandStartDungeonCreation.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandStartDungeonCreation.java @@ -53,7 +53,7 @@ public class CommandStartDungeonCreation extends CommandBase // dimHelper.instance.teleportToPocket(player.worldObj, link, player); - mod_pocketDim.dungeonHelper.customDungeonStatus.put(link.destDimID, dimHelper.instance.getLinkDataFromCoords(link.destXCoord, link.destYCoord, link.destZCoord, link.destDimID)); + DungeonHelper.instance().customDungeonStatus.put(link.destDimID, dimHelper.instance.getLinkDataFromCoords(link.destXCoord, link.destYCoord, link.destZCoord, link.destDimID)); this.getCommandSenderAsPlayer(var1).sendChatToPlayer("DimID = "+ link.destDimID); } diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index 5ab4174..74c510a 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -25,6 +25,7 @@ import StevenDimDoors.mod_pocketDim.helpers.jnbt.Tag; public class DungeonHelper { + private static DungeonHelper instance = null; private static DDProperties properties = null; public static final Pattern NamePattern = Pattern.compile("[A-Za-z0-9_]+"); @@ -76,7 +77,7 @@ public class DungeonHelper private HashSet dungeonTypeChecker; private Hashtable> dungeonTypeMapping; - public DungeonHelper() + private DungeonHelper() { //Load the dungeon type checker with the list of all types in lowercase. //Capitalization matters for matching in a hash set. @@ -100,6 +101,27 @@ public class DungeonHelper properties = DDProperties.instance(); } + public static DungeonHelper create() + { + if (instance == null) + instance = new DungeonHelper(); + else + throw new IllegalStateException("Cannot create DungeonHelper twice"); + + return instance; + } + + public static DungeonHelper instance() + { + if (instance == null) + { + //This is to prevent some frustrating bugs that could arise when classes + //are loaded in the wrong order. Trust me, I had to squash a few... + throw new IllegalStateException("Instance of DungeonHelper requested before creation"); + } + return instance; + } + public boolean validateSchematicName(String name) { String[] dungeonData = name.split("_"); diff --git a/StevenDimDoors/mod_pocketDim/helpers/dimHelper.java b/StevenDimDoors/mod_pocketDim/helpers/dimHelper.java index f0c2a11..df74200 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/dimHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/dimHelper.java @@ -978,7 +978,7 @@ public class dimHelper extends DimensionManager if(isRandomRift) { - mod_pocketDim.dungeonHelper.generateDungeonlink(link); + DungeonHelper.instance().generateDungeonlink(link); } diff --git a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java index aeef94a..6ebe0c7 100644 --- a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java +++ b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java @@ -96,7 +96,6 @@ public class mod_pocketDim public static SchematicLoader loader; public static pocketTeleporter teleporter; - public static DungeonHelper dungeonHelper; public static ICommand printDimData; public static ICommand removeRiftsCommand; @@ -158,7 +157,6 @@ public class mod_pocketDim loader = new SchematicLoader(); teleporter = new pocketTeleporter(); - dungeonHelper= new DungeonHelper(); printDimData = new CommandPrintDimData(); removeRiftsCommand = new CommandDeleteRifts(); @@ -170,18 +168,6 @@ public class mod_pocketDim startDungeonCreation = new CommandStartDungeonCreation(); tracker = new PlayerRespawnTracker(); riftGen = new RiftGenerator(); - - File file= new File(properties.CustomSchematicDirectory); - file.mkdir(); - - String helpFile = "/mods/DimDoors/How_to_add_dungeons.txt"; - if(new File(helpFile).exists()) - { - copyfile.copyFile(helpFile, file + "/How_to_add_dungeons.txt"); - } - - dungeonHelper.importCustomDungeons(properties.CustomSchematicDirectory); - dungeonHelper.registerBaseDungeons(); } @Init @@ -249,7 +235,6 @@ public class mod_pocketDim LanguageRegistry.addName(itemDimDoor, "Dimensional Door"); LanguageRegistry.addName(itemRiftBlade , "Rift Blade"); - TickRegistry.registerTickHandler(new ClientTickHandler(), Side.CLIENT); TickRegistry.registerTickHandler(new CommonTickHandler(), Side.SERVER); @@ -390,8 +375,8 @@ public class mod_pocketDim mod_pocketDim.blocksImmuneToRift.add(Block.blockLapis.blockID); mod_pocketDim.blocksImmuneToRift.add(Block.bedrock.blockID); - dungeonHelper.registerFlipBlocks(); - + DungeonHelper.create(); + proxy.loadTextures(); proxy.registerRenderers(); } From d2259c3f5d196ef58ccec54e7279e9f66422ec56 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sun, 16 Jun 2013 01:13:06 -0400 Subject: [PATCH 14/25] Reintegrated initialization code for DungeonHelper I had previously removed the function calls in mod_pocketDim to migrate them to DungeonHelper. Completed the migration now. --- .../mod_pocketDim/helpers/DungeonHelper.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index 74c510a..aebd014 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -99,14 +99,35 @@ public class DungeonHelper //Load our reference to the DDProperties singleton if (properties == null) properties = DDProperties.instance(); + + initializeDungeons(); + } + + private void initializeDungeons() + { + File file = new File(properties.CustomSchematicDirectory); + String helpFile = "/mods/DimDoors/How_to_add_dungeons.txt"; + if (new File(helpFile).exists()) + { + copyfile.copyFile(helpFile, file + "/How_to_add_dungeons.txt"); + } + file.mkdir(); + + registerFlipBlocks(); + importCustomDungeons(properties.CustomSchematicDirectory); + registerBaseDungeons(); } public static DungeonHelper create() { if (instance == null) + { instance = new DungeonHelper(); + } else + { throw new IllegalStateException("Cannot create DungeonHelper twice"); + } return instance; } From 8e200da01ba881e0555e76c08c315dda0c69d696 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sun, 16 Jun 2013 01:30:13 -0400 Subject: [PATCH 15/25] Fixed minor bug Fixed a bug with an uninitialized variable in DungeonHelper. Oops! --- 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 aebd014..fb02616 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -88,6 +88,7 @@ public class DungeonHelper } //Add all the basic dungeon types to dungeonTypeMapping + dungeonTypeMapping = new Hashtable>(); dungeonTypeMapping.put(SIMPLE_HALL_DUNGEON_TYPE, simpleHalls); dungeonTypeMapping.put(COMPLEX_HALL_DUNGEON_TYPE, complexHalls); dungeonTypeMapping.put(HUB_DUNGEON_TYPE, hubs); From 8cbccf328cf99130496cd8d69869291a51cfd4cc Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sun, 16 Jun 2013 05:15:59 -0400 Subject: [PATCH 16/25] Fixed mcmod.info Fixed problems in mcmod.info. Changed modid and version to match the @Mod Java annotations. If these annotations don't match the information in the file, the file is ignored! So previous versions did not have their mod info or logo appear under the mod menu in Minecraft. The credits line is too long, unfortunately. It runs off my screen and there is no attempt to wrap it back. Our best bet would be to place the credits in the description instead. I tried placing newlines but they're not rendered properly on the client. --- mcmod.info | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/mcmod.info b/mcmod.info index 09e49bf..f953784 100644 --- a/mcmod.info +++ b/mcmod.info @@ -1,19 +1,17 @@ [ { -"modid": "DimensionalDoors", +"modid": "DimDoors", "name": "Dimensional Doors", -"description": "Bend and twist reality itelf, creating pocket dimensions, rifts, and much more", -"version": "1.4.0", -"credits": "Created by StevenRS11, Coded by StevenRS11 and SenseiKiwi, logo and testing by Jaitsu", +"description": "Bend and twist reality itself, creating pocket dimensions, rifts, and much more", +"version": "1.5.2R1.4.0RC1", +"credits": "Created by StevenRS11, Coded by StevenRS11 and SenseiKiwi, Logo and Testing by Jaitsu", "logoFile": "/dimdoors_logo.png", "mcversion": "", "url": "http://www.minecraftforum.net/topic/1650007-147smpssplan-dimensional-doors-v110-physics-what-physics-updated-with-fancy-opengl/", "updateUrl": "", -"authors": [ "StevenRS11, SenseiKiwi" ], +"authors": [ "StevenRS11", "SenseiKiwi" ], "parent":"", "screenshots": [], -"dependencies": [ -"mod_MinecraftForge" -] +"dependencies": [ "mod_MinecraftForge" ] } ] From a95b2828144bd3b4aa292a59c517a9d7a696b022 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sun, 16 Jun 2013 05:18:17 -0400 Subject: [PATCH 17/25] Cleaned references in mod_pocketDim Cleaned references in mod_pocketDim --- StevenDimDoors/mod_pocketDim/mod_pocketDim.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java index 6ebe0c7..dab5560 100644 --- a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java +++ b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java @@ -1,7 +1,6 @@ package StevenDimDoors.mod_pocketDim; -import java.io.File; import java.util.ArrayList; import java.util.HashMap; @@ -33,7 +32,6 @@ import StevenDimDoors.mod_pocketDim.commands.CommandPrintDimData; import StevenDimDoors.mod_pocketDim.commands.CommandPruneDims; import StevenDimDoors.mod_pocketDim.commands.CommandStartDungeonCreation; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; -import StevenDimDoors.mod_pocketDim.helpers.copyfile; import StevenDimDoors.mod_pocketDim.helpers.dimHelper; import StevenDimDoors.mod_pocketDim.items.ItemChaosDoor; import StevenDimDoors.mod_pocketDim.items.ItemRiftBlade; From 61297c3a3aa927604c02649fd34e9bdd53b192a7 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sun, 16 Jun 2013 05:59:53 -0400 Subject: [PATCH 18/25] Improved DungeonHelper Separated exportDungeon() from registerCustomDungeon() - exporting a dungeon no longer automatically registers it. Also changed exportDungeon() so that it returns a boolean indicating success or failure, instead of an instance of DungeonGenerator that was never being used. I modified CommandEndDungeonCreation so that it can warn you if exporting the dungeon failed (if exportDungeon() returned false), and also, to register the dungeon after it's exported since it's no longer automatic. --- .../commands/CommandEndDungeonCreation.java | 30 +++++++++++-------- .../mod_pocketDim/helpers/DungeonHelper.java | 12 ++++---- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandEndDungeonCreation.java b/StevenDimDoors/mod_pocketDim/commands/CommandEndDungeonCreation.java index d17ef4c..584114f 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandEndDungeonCreation.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandEndDungeonCreation.java @@ -1,13 +1,11 @@ package StevenDimDoors.mod_pocketDim.commands; -import java.util.regex.Pattern; +import java.io.File; import net.minecraft.command.CommandBase; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; import StevenDimDoors.mod_pocketDim.DDProperties; -import StevenDimDoors.mod_pocketDim.DungeonGenerator; -import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; public class CommandEndDungeonCreation extends CommandBase @@ -34,14 +32,14 @@ public class CommandEndDungeonCreation extends CommandBase if (!dungeonHelper.customDungeonStatus.containsKey(player.worldObj.provider.dimensionId)) { - if(var2.length<2) + if (var2.length < 2) { player.sendChatToPlayer("Must have started dungeon creation, use argument OVERRIDE to export anyway"); return; } - else if(!var2[1].contains("OVERRIDE")) + else if (!var2[1].contains("OVERRIDE")) { player.sendChatToPlayer("Must have started dungeon creation, use argument OVERRIDE to export anyway"); return; @@ -63,14 +61,22 @@ public class CommandEndDungeonCreation extends CommandBase //Check that the dungeon name is valid to prevent directory traversal and other forms of abuse if (DungeonHelper.NamePattern.matcher(var2[0]).matches()) { - DungeonGenerator newDungeon = dungeonHelper.exportDungeon(player.worldObj, x, y, z, properties.CustomSchematicDirectory + "/" + var2[0] + ".schematic"); - player.sendChatToPlayer("created dungeon schematic in " + properties.CustomSchematicDirectory + "/" + var2[0]+".schematic"); - - if (dungeonHelper.customDungeonStatus.containsKey(player.worldObj.provider.dimensionId) && !player.worldObj.isRemote) + String exportPath = properties.CustomSchematicDirectory + "/" + var2[0] + ".schematic"; + if (dungeonHelper.exportDungeon(player.worldObj, x, y, z, exportPath)) { - // mod_pocketDim.dungeonHelper.customDungeonStatus.remove(player.worldObj.provider.dimensionId); - // dimHelper.instance.teleportToPocket(player.worldObj, mod_pocketDim.dungeonHelper.customDungeonStatus.get(player.worldObj.provider.dimensionId), player); - + player.sendChatToPlayer("Saved dungeon schematic in " + exportPath); + dungeonHelper.registerCustomDungeon(new File(exportPath)); + + if (dungeonHelper.customDungeonStatus.containsKey(player.worldObj.provider.dimensionId) && !player.worldObj.isRemote) + { + // mod_pocketDim.dungeonHelper.customDungeonStatus.remove(player.worldObj.provider.dimensionId); + // dimHelper.instance.teleportToPocket(player.worldObj, mod_pocketDim.dungeonHelper.customDungeonStatus.get(player.worldObj.provider.dimensionId), player); + + } + } + else + { + player.sendChatToPlayer("Failed to save dungeon schematic!"); } } else diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index 5f236d1..b05ed70 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -352,7 +352,7 @@ public class DungeonHelper } } - public DungeonGenerator exportDungeon(World world, int xI, int yI, int zI, String file) + public boolean exportDungeon(World world, int xI, int yI, int zI, String exportPath) { int xMin; int yMin; @@ -366,9 +366,8 @@ public class DungeonHelper yMin=yMax=yI; zMin=zMax=zI; - for(int count=0;count<50;count++) + for (int count = 0; count < 50; count++) { - if(world.getBlockId(xMin, yI, zI)!=properties.PermaFabricBlockID) { xMin--; @@ -492,17 +491,16 @@ public class DungeonHelper CompoundTag schematicTag = new CompoundTag("Schematic", schematic); try { - NBTOutputStream stream = new NBTOutputStream(new FileOutputStream(file)); + NBTOutputStream stream = new NBTOutputStream(new FileOutputStream(exportPath)); stream.writeTag(schematicTag); stream.close(); + return true; } catch(Exception e) { e.printStackTrace(); + return false; } - this.registerCustomDungeon(new File(file)); - - return new DungeonGenerator(0, file, true); } public void generateDungeonlink(LinkData incoming) From 328f7d7e845afe778aac49765bd8b46aa4d2ac9e Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sun, 16 Jun 2013 08:32:23 -0400 Subject: [PATCH 19/25] Fixed Mistakes in Dungeon Tutorial Fixed mistakes in the text file that explains how to add new dungeons. The example provided in the file was still wrong since the last time I posted about it. >_< I also noticed that since we only check if the file is present, and not if it's different from the one in our latest release, old copies with mistakes will stick around anyway. I'll tweak our code for that once other issues have been resolved. --- resources/mods/DimDoors/How_to_add_dungeons.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/resources/mods/DimDoors/How_to_add_dungeons.txt b/resources/mods/DimDoors/How_to_add_dungeons.txt index 7e214e3..39aee1a 100644 --- a/resources/mods/DimDoors/How_to_add_dungeons.txt +++ b/resources/mods/DimDoors/How_to_add_dungeons.txt @@ -24,11 +24,11 @@ To name it, use the following format- The dungeon types are ‘hub’, ‘simpleHall’, ‘complexHall’, ‘trap', ‘maze’, ‘exit’, and ‘deadEnd', see explanation further down. -isOpen determines if the dungeon is an open-air style pocket, or a closed in/walled it pocket that will spawn Monoliths. Correct arguments are 'open' or 'closed'. +isOpen determines if the dungeon is an open-air style pocket, or a closed in / walled in pocket that will spawn Monoliths. Correct arguments are 'open' or 'closed'. -Spawn weight determines how frequently you want it to appear. The default is one, and it will have the same relative weight as all the others. +Spawn weight determines how frequently you want it to appear. The default is 100, and it will have the same relative weight as all the others. -For example- hub_hallWith5Doors_1.schematic +For example- hub_hallWith5Doors_open_1.schematic Congratulations! You have added your own dungeon. You can use the command /dimdoors-genDungeonRift to gen it, or use /dimdoors-genDungeonRift list to list all avalible dungeons. @@ -37,9 +37,9 @@ Congratulations! You have added your own dungeon. You can use the command /dimdo These tags are just guidelines, feel free to do whatever you feel like, but the generation algorithm is set up with these in mind- -hub- Dungeons that have 4 or more iron doors in them should be labled as hubs, so they dont gen one after another. +hub- Dungeons that have 4 or more iron doors in them should be labeled as hubs, so they don't generate one after another. -simpleHall- this dungeons contain a single iron door, (possibly two, but not three) and dont contain redstone traps/etc. These are the halls that separate rooms, and should generally be tagged with 'closed' as well. +simpleHall - this dungeons contain a single iron door, (possibly two, but not three) and don't contain redstone traps/etc. These are the halls that separate rooms, and should generally be tagged with 'closed' as well. complexHall- these dungeons are more like rooms, and can be open. They can have piston puzzles/locks, and up to three iron doors. In addition, they can contain wooden doors to link to the surface. @@ -49,5 +49,5 @@ maze- can contain up to 3 iron dim doors. They can be simple labryinths, or full exit- primary purpose is to link back to overworld with a wooden door. Should never contain iron doors. -deadEnd- no doors, except enterace door. Usually contain some sort of treasure. +deadEnd - no doors, except entrance door. Usually contain some sort of treasure. From 697b0da59f314bbfd89b174a7ce3e912cca81fb4 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sun, 16 Jun 2013 09:57:51 -0400 Subject: [PATCH 20/25] Fixed Configuration and Rift Generation Bugs Although fields were created in DDProperties for Monolith spawning and Rift generation, they were mislabeled as reading the "World Rift Generation Enabled" property. I gave them proper names. I also changed the fields and names to be more intuitive and rewrote the descriptions. For instance, "MonolithSpawnDensity" is a misnomer because as density increases, there should be more Monoliths, not less. Now the properties clearly state how they affect a feature. I rewrote the conditions that used each property to correspond with those simplified descriptions and gave the properties default values that will match the generation rates seen before. I also made the rift generation code less cryptic and fixed a bug; there was a check that compared if a dimension was a pocket dimension by its name to prevent rift generation. That name check was wrong - it would never work. Now we check if the provider is an instance of pocketProvider. That will continue working even if we change the way that pocket dimensions are named. --- .../mod_pocketDim/DDProperties.java | 21 +- .../mod_pocketDim/RiftGenerator.java | 198 ++++-------------- .../mod_pocketDim/world/LimboGenerator.java | 35 ++-- .../mod_pocketDim/world/pocketProvider.java | 99 ++++----- 4 files changed, 123 insertions(+), 230 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/DDProperties.java b/StevenDimDoors/mod_pocketDim/DDProperties.java index 3d766c6..b895c10 100644 --- a/StevenDimDoors/mod_pocketDim/DDProperties.java +++ b/StevenDimDoors/mod_pocketDim/DDProperties.java @@ -2,6 +2,8 @@ package StevenDimDoors.mod_pocketDim; import java.io.File; +import StevenDimDoors.mod_pocketDim.world.LimboGenerator; + import net.minecraftforge.common.Configuration; public class DDProperties @@ -99,8 +101,9 @@ public class DDProperties public final int NonTntWeight; public final int RiftSpreadModifier; - public final int DungeonRiftGenDensity; - public final int MonolithSpawnDensity; + public final int ClusterGenerationChance; + public final int GatewayGenerationChance; + public final int MonolithSpawningChance; public final int LimboReturnRange; public final String CustomSchematicDirectory; @@ -200,12 +203,18 @@ public class DDProperties WorldRiftGenerationEnabled = config.get(Configuration.CATEGORY_GENERAL, "Enable Rift World Generation", true, "Sets whether dungeon rifts generate in dimensions other than Limbo").getBoolean(true); - MonolithSpawnDensity = config.get(Configuration.CATEGORY_GENERAL, "Enable Rift World Generation", 7, - "Sets the chance that monoliths will not spawn in a give Limbo chunk- higher values mean fewer monoliths, must be greater than 0, default is 7.").getInt(); + MonolithSpawningChance = config.get(Configuration.CATEGORY_GENERAL, "Monolith Spawning Chance", 28, + "Sets the chance (out of " + LimboGenerator.MAX_MONOLITH_SPAWNING_CHANCE + ") that Monoliths will " + + "spawn in a given Limbo chunk. The default chance is 28.").getInt(); - DungeonRiftGenDensity = config.get(Configuration.CATEGORY_GENERAL, "Enable Rift World Generation", 250, - "Sets the dungeon rift density in the overworld, higher values mean less rifts, must be greater than 0. Default is 250.").getInt(); + ClusterGenerationChance = config.get(Configuration.CATEGORY_GENERAL, "Cluster Generation Chance", 3, + "Sets the chance (out of " + RiftGenerator.MAX_CLUSTER_GENERATION_CHANCE + ") that a cluster of rifts will " + + "generate in a given chunk. The default chance is 3.").getInt(); + GatewayGenerationChance = config.get(Configuration.CATEGORY_GENERAL, "Gateway Generation Chance", 40, + "Sets the chance (out of " + RiftGenerator.MAX_GATEWAY_GENERATION_CHANCE + ") that a Rift Gateway will " + + "generate in a given chunk. The default chance is 40.").getInt(); + RiftSpreadModifier = config.get(Configuration.CATEGORY_GENERAL, "Rift Spread Modifier", 3, "Sets the number of times a rift can spread. 0 prevents rifts from spreading at all. " + "A value greater than 5 is not recommended as the growth is exponential.").getInt(); diff --git a/StevenDimDoors/mod_pocketDim/RiftGenerator.java b/StevenDimDoors/mod_pocketDim/RiftGenerator.java index 1f1fffe..c72a132 100644 --- a/StevenDimDoors/mod_pocketDim/RiftGenerator.java +++ b/StevenDimDoors/mod_pocketDim/RiftGenerator.java @@ -2,16 +2,24 @@ package StevenDimDoors.mod_pocketDim; import java.util.Random; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; -import StevenDimDoors.mod_pocketDim.items.ItemRiftBlade; - import net.minecraft.block.Block; import net.minecraft.world.World; import net.minecraft.world.chunk.IChunkProvider; +import StevenDimDoors.mod_pocketDim.helpers.dimHelper; +import StevenDimDoors.mod_pocketDim.items.ItemRiftBlade; +import StevenDimDoors.mod_pocketDim.world.pocketProvider; import cpw.mods.fml.common.IWorldGenerator; public class RiftGenerator implements IWorldGenerator { + //TODO: Stop the madness here... + //Based on reviewing the code in this mod, I believe that all IWorldGenerators + //must work as singletons. Given that each call that comes into them is independent, + //we shouldn't have ANY fields in here! At best they will end up causing bugs. + //In particular, using our own instance of Random instead of one derived from the world + //seed means that our chunk generation isn't linked to the world seed. Bad, very bad! + //I'm going to fix this later. <_<;; ~SenseiKiwi + private int minableBlockId; private int numberOfBlocks; int cycles=40; @@ -21,12 +29,16 @@ public class RiftGenerator implements IWorldGenerator int k; int j; Random rand = new Random(); - boolean shouldGenHere=true; + boolean shouldGenHere = true; LinkData link; DimData dimData; + public static final int MAX_GATEWAY_GENERATION_CHANCE = 10000; + public static final int MAX_CLUSTER_GENERATION_CHANCE = 10000; + private static final int CLUSTER_GROWTH_CHANCE = 80; + private static final int MAX_CLUSTER_GROWTH_CHANCE = 100; private static DDProperties properties = null; - + public RiftGenerator() { if (properties == null) @@ -36,145 +48,62 @@ public class RiftGenerator implements IWorldGenerator @Override public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) { - //Long ntime = System.nanoTime(); - shouldGenHere=true; + //TODO: This code could really use some cleaning up... ~SenseiKiwi - if (world.provider.getDimensionName()=="PocketDim"|| !properties.WorldRiftGenerationEnabled || world.isRemote) + shouldGenHere = properties.WorldRiftGenerationEnabled && !(world.provider instanceof pocketProvider) && !world.isRemote; + + if (shouldGenHere && random.nextInt(MAX_CLUSTER_GENERATION_CHANCE) < properties.ClusterGenerationChance) { + i = chunkX * 16 - random.nextInt(16); + k = chunkZ * 16 - random.nextInt(16); + j = world.getHeightValue(i, k); - this.shouldGenHere=false; - - - } - - - if(this.shouldGenHere) - { - - //TODO give this a clamp int type functionality - if(random.nextInt(3000+properties.DungeonRiftGenDensity*4)==0) + if (j > 20 && world.getBlockId(i, j, k) == 0) { - i=chunkX*16-random.nextInt(16); - k=chunkZ*16-random.nextInt(16); + // System.out.println(String.valueOf(i)+"x "+String.valueOf(j)+"y "+String.valueOf(k)+"z"+"Large gen"); - j= world.getHeightValue(i, k); + link = new LinkData(world.provider.dimensionId, 0, i, j+1, k, i, j+1, k, true,rand.nextInt(4)); + link = dimHelper.instance.createPocket(link,true, true); + this.shouldSave=true; - if(j>20&&world.getBlockId(i, j, k)==0) + // SchematicLoader loader = new SchematicLoader(); + // loader.init(link); + // loader.generateSchematic(link); + count = 0; + while (random.nextInt(MAX_CLUSTER_GROWTH_CHANCE) < CLUSTER_GROWTH_CHANCE) { - // System.out.println(String.valueOf(i)+"x "+String.valueOf(j)+"y "+String.valueOf(k)+"z"+"Large gen"); + i = chunkX * 16 - random.nextInt(16); + k = chunkZ * 16 - random.nextInt(16); - link = new LinkData(world.provider.dimensionId, 0, i, j+1, k, i, j+1, k, true,rand.nextInt(4)); - link = dimHelper.instance.createPocket(link,true, true); - this.shouldSave=true; + j = world.getHeightValue(i, k); - - // SchematicLoader loader = new SchematicLoader(); - // loader.init(link); - // loader.generateSchematic(link); - - - count=0; - while(random.nextInt(4)!=1) + if (world.isAirBlock(i, j + 1, k)) { - i=chunkX*16-random.nextInt(16); - k=chunkZ*16-random.nextInt(16); - - j= world.getHeightValue(i, k); - - if(world.isAirBlock(i, j+1, k)) - { - - - - link = dimHelper.instance.createLink(link.locDimID,link.destDimID, i, j+1, k,link.destXCoord,link.destYCoord,link.destZCoord); - - - - - - - - } - + link = dimHelper.instance.createLink(link.locDimID,link.destDimID, i, j+1, k,link.destXCoord,link.destYCoord,link.destZCoord); } - } } - /** - if(random.nextInt(540)==0) - { - i=chunkX*16-random.nextInt(16); - k=chunkZ*16-random.nextInt(16); - - j= world.getHeightValue(i, k); - if(j>20&&world.getBlockId(i, j, k)==0) - { - //System.out.println(String.valueOf(i)+"x "+String.valueOf(j)+"y "+String.valueOf(k)+"z"+"med gen"); - - link = new LinkData(world.provider.dimensionId, 0, i, j+1, k, i, j+1, k, true,rand.nextInt(4)); - link = dimHelper.instance.createPocket(link,true, true); - this.shouldSave=true; - - - // SchematicLoader loader = new SchematicLoader(); - // loader.init(link); - // loader.generateSchematic(link); - count=0; - - - while(random.nextInt(3)!=1) - { - i=chunkX*16-random.nextInt(16); - k=chunkZ*16-random.nextInt(16); - - j= world.getHeightValue(i, k); - - if(world.isAirBlock(i, j+1, k)) - { - - - - link = dimHelper.instance.createLink(link.locDimID,link.destDimID, i, j+1, k,link.destXCoord,link.destYCoord,link.destZCoord); - - - - - - } - - } - - } - } - **/ - } - if(random.nextInt(properties.DungeonRiftGenDensity)==0&&world.provider.getDimensionName()!="PocketDim"&&!world.isRemote && properties.WorldRiftGenerationEnabled) + if (shouldGenHere && random.nextInt(MAX_GATEWAY_GENERATION_CHANCE) < properties.GatewayGenerationChance) { // System.out.println("tryingToGen"); - int blockID=Block.stoneBrick.blockID; - if(world.provider.dimensionId==properties.LimboDimensionID) + int blockID = Block.stoneBrick.blockID; + if (world.provider.dimensionId == properties.LimboDimensionID) { - blockID= properties.LimboBlockID; + blockID = properties.LimboBlockID; } i=chunkX*16-random.nextInt(16); k=chunkZ*16-random.nextInt(16); j= world.getHeightValue(i, k); - if(j>20&&world.getBlockId(i, j, k)==0) + if(j>20 && world.getBlockId(i, j, k)==0) { //System.out.println(String.valueOf(i)+"x "+String.valueOf(j)+"y "+String.valueOf(k)+"z"+"small gen"); - count=0; - if(world.isAirBlock(i, j+1, k)) { - - - - if(world.isBlockOpaqueCube(i, j-2, k)||world.isBlockOpaqueCube(i, j-1, k)) { link = new LinkData(world.provider.dimensionId, 0, i, j+1, k, i, j+1, k, true,rand.nextInt(4)); @@ -216,47 +145,10 @@ public class RiftGenerator implements IWorldGenerator world.setBlock(i, j+2, k+1, blockID,3,1); world.setBlock(i, j+2, k-1, blockID,3,1); } - - - - - - - - this.shouldSave=true; - + this.shouldSave = true; } - - // dimData = dimHelper.instance.dimList.get(link.destDimID); - - - // SchematicLoader loader = new SchematicLoader(); - // loader.init(link); - // loader.generateSchematic(link); - - - - - - - - } - } } - if(this.shouldSave) - { - // dimHelper.instance.save(); - } - - // mod_pocketDim.genTime=((System.nanoTime()-ntime)+mod_pocketDim.genTime); - // System.out.println( mod_pocketDim.genTime); - // System.out.println( (System.nanoTime()-ntime)); - - // ntime=0L; - } - - } diff --git a/StevenDimDoors/mod_pocketDim/world/LimboGenerator.java b/StevenDimDoors/mod_pocketDim/world/LimboGenerator.java index 3c49827..583778b 100644 --- a/StevenDimDoors/mod_pocketDim/world/LimboGenerator.java +++ b/StevenDimDoors/mod_pocketDim/world/LimboGenerator.java @@ -33,6 +33,7 @@ import net.minecraftforge.event.terraingen.ChunkProviderEvent; public class LimboGenerator extends ChunkProviderGenerate implements IChunkProvider { + public static final int MAX_MONOLITH_SPAWNING_CHANCE = 100; private static Random rand; /** A NoiseGeneratorOctaves used in generating terrain */ @@ -108,7 +109,7 @@ public class LimboGenerator extends ChunkProviderGenerate implements IChunkProvi { // caveGenerator = TerrainGen.getModdedMapGen(caveGenerator, CAVE); } - + private static DDProperties properties = null; public LimboGenerator(World par1World, long par2) @@ -135,7 +136,7 @@ public class LimboGenerator extends ChunkProviderGenerate implements IChunkProvi this.mobSpawnerNoise = noiseGens[6]; // TODO Auto-generated constructor stub this.worldObj=par1World; - + if (properties == null) properties = DDProperties.instance(); } @@ -177,49 +178,37 @@ public class LimboGenerator extends ChunkProviderGenerate implements IChunkProvi @Override public void populate(IChunkProvider var1, int var2, int var3) { - - - - if(rand.nextInt(properties.MonolithSpawnDensity)>1) - { - return; - } + if (rand.nextInt(MAX_MONOLITH_SPAWNING_CHANCE) < properties.MonolithSpawningChance) + { int y =0; int x = var2*16 + rand.nextInt(16); int z = var3*16 + rand.nextInt(16); int yTest; do { - + x = var2*16 + rand.nextInt(16); z = var3*16 + rand.nextInt(16); - + while(this.worldObj.getBlockId(x, y, z)==0&&y<255) { y++; } y = yCoordHelper.getFirstUncovered(this.worldObj,x , y+2, z); - + Entity mob = new MobObelisk(this.worldObj); mob.setLocationAndAngles(x, y, z, 1, 1); - + yTest=yCoordHelper.getFirstUncovered(this.worldObj,x , y+5, z); if(yTest>245) { return; } this.worldObj.spawnEntityInWorld(mob); - + } - while(yTest >y); - - - - - // TODO Auto-generated method stub - - - + while (yTest > y); + } } @Override diff --git a/StevenDimDoors/mod_pocketDim/world/pocketProvider.java b/StevenDimDoors/mod_pocketDim/world/pocketProvider.java index 89a49e3..b72c720 100644 --- a/StevenDimDoors/mod_pocketDim/world/pocketProvider.java +++ b/StevenDimDoors/mod_pocketDim/world/pocketProvider.java @@ -15,112 +15,115 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class pocketProvider extends WorldProvider - { public int exitXCoord; public int exitYCoord; public int exitZCoord; public int exitDimID; public boolean hasNoSky = true; - + public boolean isSavingSchematic= false; public int dimToSave; private static DDProperties properties = null; - + public pocketProvider() { this.hasNoSky=true; if (properties == null) properties = DDProperties.instance(); } - + @Override - protected void registerWorldChunkManager() - { + protected void registerWorldChunkManager() + { super.worldChunkMgr = new WorldChunkManagerHell(mod_pocketDim.pocketBiome,1,1); - //this.dimensionId = ConfigAtum.dimensionID; - } + //this.dimensionId = ConfigAtum.dimensionID; + } + @Override public String getSaveFolder() - { - return (dimensionId == 0 ? null : "DimensionalDoors/pocketDimID" + dimensionId); - } - + { + return (dimensionId == 0 ? null : "DimensionalDoors/pocketDimID" + dimensionId); + } + public void saveAsSchematic(int id) { this.isSavingSchematic=true; this.dimensionId=id; - + } - + public Vec3 getSkyColor(Entity cameraEntity, float partialTicks) { - setCloudRenderer( new CloudRenderBlank()); - return this.worldObj.getWorldVec3Pool().getVecFromPool((double)0, (double)0, (double)0); + setCloudRenderer( new CloudRenderBlank()); + return this.worldObj.getWorldVec3Pool().getVecFromPool((double)0, (double)0, (double)0); } - - - - @SideOnly(Side.CLIENT) + + + + @SideOnly(Side.CLIENT) @Override public Vec3 getFogColor(float par1, float par2) - { - return this.worldObj.getWorldVec3Pool().getVecFromPool((double)0, (double)0, (double)0); + { + return this.worldObj.getWorldVec3Pool().getVecFromPool((double)0, (double)0, (double)0); + + } - } @Override public double getHorizon() - { - return worldObj.getHeight(); - } + { + return worldObj.getHeight(); + } + @Override public IChunkProvider createChunkGenerator() { return new pocketGenerator(worldObj, dimensionId, false); } - @Override - public boolean canSnowAt(int x, int y, int z) - { - return false; - } - public boolean canBlockFreeze(int x, int y, int z, boolean byWater) - { - return false; - } + + @Override + public boolean canSnowAt(int x, int y, int z) + { + return false; + } + + public boolean canBlockFreeze(int x, int y, int z, boolean byWater) + { + return false; + } @Override public String getDimensionName() { + //TODO: This should be a proper name. We need to show people proper names for things whenever possible. + //The question is whether this should be "Pocket Dimension" or "Pocket Dimension #" -- I'm not going to change + //it out of concern that it could break something. ~SenseiKiwi return "PocketDim " + this.dimensionId; } - - + public int getRespawnDimension(EntityPlayerMP player) { int respawnDim; - + if (properties.LimboEnabled) { respawnDim = properties.LimboDimensionID; } else { - respawnDim= dimHelper.dimList.get(this.dimensionId).exitDimLink.destDimID; + respawnDim = dimHelper.dimList.get(this.dimensionId).exitDimLink.destDimID; } - - if (dimHelper.getWorld(respawnDim)==null) + + if (dimHelper.getWorld(respawnDim) == null) { dimHelper.initDimension(respawnDim); } return respawnDim; } - - public boolean canRespawnHere() - { - return false; - } - - + public boolean canRespawnHere() + { + return false; + } } From 63be7fefc10222d00ea66fc23068d922abffed40 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sun, 16 Jun 2013 10:54:03 -0400 Subject: [PATCH 21/25] Tweaked Dungeon Tutorial Copy Code Tweaked the code that copies the dungeon export tutorial. I'm not sure it worked all the time before. It didn't seem quite right. I've confirmed it's working better now. Also cleaned up copyfile a little. --- .../mod_pocketDim/helpers/DungeonHelper.java | 7 ++---- .../mod_pocketDim/helpers/copyfile.java | 24 +++++++------------ 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index b05ed70..af66469 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -107,13 +107,10 @@ public class DungeonHelper private void initializeDungeons() { File file = new File(properties.CustomSchematicDirectory); - String helpFile = "/mods/DimDoors/How_to_add_dungeons.txt"; - if (new File(helpFile).exists()) + if (file.exists() || file.mkdir()) { - copyfile.copyFile(helpFile, file + "/How_to_add_dungeons.txt"); + copyfile.copyFile("/mods/DimDoors/How_to_add_dungeons.txt", file.getAbsolutePath() + "/How_to_add_dungeons.txt"); } - file.mkdir(); - registerFlipBlocks(); importCustomDungeons(properties.CustomSchematicDirectory); registerBaseDungeons(); diff --git a/StevenDimDoors/mod_pocketDim/helpers/copyfile.java b/StevenDimDoors/mod_pocketDim/helpers/copyfile.java index e83e7bb..32e0534 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/copyfile.java +++ b/StevenDimDoors/mod_pocketDim/helpers/copyfile.java @@ -1,6 +1,5 @@ package StevenDimDoors.mod_pocketDim.helpers; -import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; @@ -9,29 +8,24 @@ import StevenDimDoors.mod_pocketDim.mod_pocketDim; public class copyfile { - - public static boolean copyFile(String ori, String dest) { try { - InputStream in = (mod_pocketDim.class.getClass().getResourceAsStream(ori)); - OutputStream out = new FileOutputStream(dest); - byte[] buf = new byte[1024]; - int len; - while ((len = in.read(buf)) > 0) { - out.write(buf, 0, len); - } - in.close(); - out.close(); + InputStream in = (mod_pocketDim.class.getClass().getResourceAsStream(ori)); + OutputStream out = new FileOutputStream(dest); + byte[] buf = new byte[1024]; + int len; + while ((len = in.read(buf)) > 0) { + out.write(buf, 0, len); + } + in.close(); + out.close(); } catch(Exception e) { - //e.printStackTrace(); return false; } return true; } - - } \ No newline at end of file From f5429410742f4f472092a66fb9de5a0fe944f32e Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sun, 16 Jun 2013 11:06:08 -0400 Subject: [PATCH 22/25] Replaced Hashtable with HashMap Replaced all instances of Hashtable in our code with HashMap. I had never given that much thought until Steven mentioned it. HashMap is a better alternative for our code. --- StevenDimDoors/mod_pocketDim/DDLoot.java | 4 ++-- StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/DDLoot.java b/StevenDimDoors/mod_pocketDim/DDLoot.java index 7e6c646..4226697 100644 --- a/StevenDimDoors/mod_pocketDim/DDLoot.java +++ b/StevenDimDoors/mod_pocketDim/DDLoot.java @@ -1,7 +1,7 @@ package StevenDimDoors.mod_pocketDim; import java.util.ArrayList; -import java.util.Hashtable; +import java.util.HashMap; import java.util.Random; import net.minecraft.item.Item; @@ -77,7 +77,7 @@ public class DDLoot { //the same item. For instance, it cannot distinguish between different types of wood. That shouldn't //matter for most chest loot, though. This could be fixed if we cared enough. Random random = new Random(); - Hashtable container = new Hashtable(); + HashMap container = new HashMap(); for (String category : categories) { diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index af66469..2ca027d 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -5,7 +5,6 @@ import java.io.FileOutputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; -import java.util.Hashtable; import java.util.Random; import java.util.regex.Pattern; @@ -75,7 +74,7 @@ public class DungeonHelper public DungeonGenerator defaultUp = new DungeonGenerator(0, "/schematic/simpleStairsUp.schematic", true); private HashSet dungeonTypeChecker; - private Hashtable> dungeonTypeMapping; + private HashMap> dungeonTypeMapping; private DungeonHelper() { @@ -88,7 +87,7 @@ public class DungeonHelper } //Add all the basic dungeon types to dungeonTypeMapping - dungeonTypeMapping = new Hashtable>(); + dungeonTypeMapping = new HashMap>(); dungeonTypeMapping.put(SIMPLE_HALL_DUNGEON_TYPE, simpleHalls); dungeonTypeMapping.put(COMPLEX_HALL_DUNGEON_TYPE, complexHalls); dungeonTypeMapping.put(HUB_DUNGEON_TYPE, hubs); From 8dce8c1c268d0d9fb058bece9ffcec356e754538 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sun, 16 Jun 2013 12:06:21 -0400 Subject: [PATCH 23/25] Renamed all singleton create() to initialize() Renamed the create() function of DDProperties and DungeonHelper to initialize(). Why? Because it was bugging me. <.< That is all. --- StevenDimDoors/mod_pocketDim/DDProperties.java | 6 +++--- StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java | 6 +++--- StevenDimDoors/mod_pocketDim/mod_pocketDim.java | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/DDProperties.java b/StevenDimDoors/mod_pocketDim/DDProperties.java index b895c10..dcb364a 100644 --- a/StevenDimDoors/mod_pocketDim/DDProperties.java +++ b/StevenDimDoors/mod_pocketDim/DDProperties.java @@ -225,12 +225,12 @@ public class DDProperties config.save(); } - public static DDProperties create(File configFile) + public static DDProperties initialize(File configFile) { if (instance == null) instance = new DDProperties(configFile); else - throw new IllegalStateException("Cannot create DDProperties twice"); + throw new IllegalStateException("Cannot initialize DDProperties twice"); return instance; } @@ -241,7 +241,7 @@ public class DDProperties { //This is to prevent some frustrating bugs that could arise when classes //are loaded in the wrong order. Trust me, I had to squash a few... - throw new IllegalStateException("Instance of DDProperties requested before properties have been loaded"); + throw new IllegalStateException("Instance of DDProperties requested before initialization"); } return instance; } diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index 2ca027d..4e08bdb 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -115,7 +115,7 @@ public class DungeonHelper registerBaseDungeons(); } - public static DungeonHelper create() + public static DungeonHelper initialize() { if (instance == null) { @@ -123,7 +123,7 @@ public class DungeonHelper } else { - throw new IllegalStateException("Cannot create DungeonHelper twice"); + throw new IllegalStateException("Cannot initialize DungeonHelper twice"); } return instance; @@ -135,7 +135,7 @@ public class DungeonHelper { //This is to prevent some frustrating bugs that could arise when classes //are loaded in the wrong order. Trust me, I had to squash a few... - throw new IllegalStateException("Instance of DungeonHelper requested before creation"); + throw new IllegalStateException("Instance of DungeonHelper requested before initialization"); } return instance; } diff --git a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java index dab5560..740fbf1 100644 --- a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java +++ b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java @@ -145,7 +145,7 @@ public class mod_pocketDim public void PreInit(FMLPreInitializationEvent event) { //This should be the FIRST thing that gets done. - properties = DDProperties.create(event.getSuggestedConfigurationFile()); + properties = DDProperties.initialize(event.getSuggestedConfigurationFile()); //Now do other stuff MinecraftForge.EVENT_BUS.register(new EventHookContainer()); @@ -373,7 +373,7 @@ public class mod_pocketDim mod_pocketDim.blocksImmuneToRift.add(Block.blockLapis.blockID); mod_pocketDim.blocksImmuneToRift.add(Block.bedrock.blockID); - DungeonHelper.create(); + DungeonHelper.initialize(); proxy.loadTextures(); proxy.registerRenderers(); From b2f5c4ea4e8179dcd34c8fc377c91d46c828984a Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sun, 16 Jun 2013 14:36:32 -0400 Subject: [PATCH 24/25] Overhauled RiftGenerator Overhauled RIftGenerator. The code is significantly more readable now. It's commented and much more compact. I also removed all fields from RiftGenerator - they were unnecessary and using them increased the risk of buggy code. Made the code rely solely on the Random instance provided by MC, meaning our rifts and gateways will be tied to the world seed. Tweaked the code slightly so that clusters of rifts and gateways can never generate in the same chunk. This was previously possible, although highly unlikely. It's a work of art now. <3 --- .../mod_pocketDim/RiftGenerator.java | 218 +++++++++--------- 1 file changed, 107 insertions(+), 111 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/RiftGenerator.java b/StevenDimDoors/mod_pocketDim/RiftGenerator.java index c72a132..ce4db70 100644 --- a/StevenDimDoors/mod_pocketDim/RiftGenerator.java +++ b/StevenDimDoors/mod_pocketDim/RiftGenerator.java @@ -12,31 +12,14 @@ import cpw.mods.fml.common.IWorldGenerator; public class RiftGenerator implements IWorldGenerator { - //TODO: Stop the madness here... - //Based on reviewing the code in this mod, I believe that all IWorldGenerators - //must work as singletons. Given that each call that comes into them is independent, - //we shouldn't have ANY fields in here! At best they will end up causing bugs. - //In particular, using our own instance of Random instead of one derived from the world - //seed means that our chunk generation isn't linked to the world seed. Bad, very bad! - //I'm going to fix this later. <_<;; ~SenseiKiwi - - private int minableBlockId; - private int numberOfBlocks; - int cycles=40; - boolean shouldSave = false; - int count = 0; - int i; - int k; - int j; - Random rand = new Random(); - boolean shouldGenHere = true; - LinkData link; - DimData dimData; - public static final int MAX_GATEWAY_GENERATION_CHANCE = 10000; public static final int MAX_CLUSTER_GENERATION_CHANCE = 10000; private static final int CLUSTER_GROWTH_CHANCE = 80; private static final int MAX_CLUSTER_GROWTH_CHANCE = 100; + private static final int MIN_RIFT_Y = 21; + private static final int MAX_RIFT_Y = 250; + private static final int CHUNK_LENGTH = 16; + private static final int GATEWAY_RADIUS = 3; private static DDProperties properties = null; public RiftGenerator() @@ -48,107 +31,120 @@ public class RiftGenerator implements IWorldGenerator @Override public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) { - //TODO: This code could really use some cleaning up... ~SenseiKiwi - - shouldGenHere = properties.WorldRiftGenerationEnabled && !(world.provider instanceof pocketProvider) && !world.isRemote; - - if (shouldGenHere && random.nextInt(MAX_CLUSTER_GENERATION_CHANCE) < properties.ClusterGenerationChance) + //Don't generate rifts or gateways if the rift generation flag is disabled, + //the current world is a pocket dimension, or the world is remote. + if (!properties.WorldRiftGenerationEnabled || world.provider instanceof pocketProvider || world.isRemote) { - i = chunkX * 16 - random.nextInt(16); - k = chunkZ * 16 - random.nextInt(16); - j = world.getHeightValue(i, k); - - if (j > 20 && world.getBlockId(i, j, k) == 0) - { - // System.out.println(String.valueOf(i)+"x "+String.valueOf(j)+"y "+String.valueOf(k)+"z"+"Large gen"); - - link = new LinkData(world.provider.dimensionId, 0, i, j+1, k, i, j+1, k, true,rand.nextInt(4)); - link = dimHelper.instance.createPocket(link,true, true); - this.shouldSave=true; - - // SchematicLoader loader = new SchematicLoader(); - // loader.init(link); - // loader.generateSchematic(link); - count = 0; - while (random.nextInt(MAX_CLUSTER_GROWTH_CHANCE) < CLUSTER_GROWTH_CHANCE) - { - i = chunkX * 16 - random.nextInt(16); - k = chunkZ * 16 - random.nextInt(16); - - j = world.getHeightValue(i, k); - - if (world.isAirBlock(i, j + 1, k)) - { - link = dimHelper.instance.createLink(link.locDimID,link.destDimID, i, j+1, k,link.destXCoord,link.destYCoord,link.destZCoord); - } - } - } + return; } - if (shouldGenHere && random.nextInt(MAX_GATEWAY_GENERATION_CHANCE) < properties.GatewayGenerationChance) + int x, y, z; + int blockID; + LinkData link; + + //Randomly decide whether to place a cluster of rifts here + if (random.nextInt(MAX_CLUSTER_GENERATION_CHANCE) < properties.ClusterGenerationChance) { - // System.out.println("tryingToGen"); - int blockID = Block.stoneBrick.blockID; - if (world.provider.dimensionId == properties.LimboDimensionID) + link = null; + do { - blockID = properties.LimboBlockID; - } - i=chunkX*16-random.nextInt(16); - k=chunkZ*16-random.nextInt(16); + //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); - j= world.getHeightValue(i, k); - if(j>20 && world.getBlockId(i, j, k)==0) - { - //System.out.println(String.valueOf(i)+"x "+String.valueOf(j)+"y "+String.valueOf(k)+"z"+"small gen"); - count=0; - - if(world.isAirBlock(i, j+1, k)) + //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(world.isBlockOpaqueCube(i, j-2, k)||world.isBlockOpaqueCube(i, j-1, k)) + //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. + if (link == null) { - link = new LinkData(world.provider.dimensionId, 0, i, j+1, k, i, j+1, k, true,rand.nextInt(4)); - link =dimHelper.instance.createPocket(link,true, true); - - for(int xc=-3;xc<4;xc++) - { - for(int zc=-3;zc<4;zc++) - { - for(int yc=0;yc<200;yc++) - { - if(yc==0&&world.isBlockOpaqueCube(i+xc, j-2,k +zc)) - { - - if(Math.abs(xc)+Math.abs(zc)= 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)) + { + //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! + link = new LinkData(world.provider.dimensionId, 0, x, y + 1, z, x, y + 1, z, true, random.nextInt(4)); + link = dimHelper.instance.createPocket(link, true, true); + + //If the current dimension isn't Limbo, build a Rift Gateway out of Stone Bricks + if (world.provider.dimensionId != properties.LimboDimensionID) + { + blockID = Block.stoneBrick.blockID; + + //Replace some of the ground around the gateway with bricks + for (int xc = -GATEWAY_RADIUS; xc <= GATEWAY_RADIUS; xc++) + { + for (int zc= -GATEWAY_RADIUS; zc <= GATEWAY_RADIUS; zc++) + { + //Check that the block is supported by an opaque block. + //This prevents us from building over a cliff, on the peak of a mountain, + //or the surface of the ocean or a frozen lake. + if (world.isBlockOpaqueCube(x + xc, y - 2, z + zc)) + { + //Randomly choose whether to place bricks or not. The math is designed so that the + //chances of placing a block decrease as we get farther from the gateway's center. + if (Math.abs(xc) + Math.abs(zc) < random.nextInt(3) + 2) + { + //Place Stone Bricks + world.setBlock(x + xc, y - 1, z + zc, blockID); + } + 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, 1); + } + } + } + } + + //Use Chiseled Stone Bricks to top off the pillars around the door + world.setBlock(x, y + 2, z + 1, blockID, 3, 1); + world.setBlock(x, y + 2, z - 1, blockID, 3, 1); + } + 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, 1); + world.setBlock(x, y + 2, z - 1, blockID, 0, 1); + } + + //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, 1); + world.setBlock(x, y + 1, z + 1, blockID, 0, 1); + world.setBlock(x, y, z - 1, blockID, 0, 1); + world.setBlock(x, y, z + 1, blockID, 0, 1); + } } } } From cf2246061cc21dbace851324f34e9862d56c0225 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sun, 16 Jun 2013 14:40:26 -0400 Subject: [PATCH 25/25] Trivial Changes Made trivial changes to DungeonHelper. Just some spacing and a note to check something in the future. Need to commit to change branches. --- .../mod_pocketDim/helpers/DungeonHelper.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index 4e08bdb..98f80d1 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -507,15 +507,16 @@ public class DungeonHelper int depthWeight = rand.nextInt(depth)+rand.nextInt(depth)-2; - depth=depth-2; - // DungeonGenerator + depth = depth - 2; boolean flag = true; - int count=10; + int count = 10; try { - if(dimHelper.dimList.get(incoming.destDimID)!=null&&dimHelper.dimList.get(incoming.destDimID).dungeonGenerator!=null) + if (dimHelper.dimList.get(incoming.destDimID) != null&&dimHelper.dimList.get(incoming.destDimID).dungeonGenerator!=null) { mod_pocketDim.loader.init(incoming); + //TODO: Check this! + //What the hell? Isn't this line saying X = X..? ~SenseiKiwi dimHelper.dimList.get(incoming.destDimID).dungeonGenerator=dimHelper.dimList.get(incoming.destDimID).dungeonGenerator; return; } @@ -644,13 +645,13 @@ public class DungeonHelper } catch (Exception e) { + e.printStackTrace(); if (weightedDungeonGenList.size() > 0) { dungeon = weightedDungeonGenList.get(rand.nextInt(weightedDungeonGenList.size())); } else { - e.printStackTrace(); return; } }