From 0752c032d3001cd1d0d30606f09b2a34f1cc21de Mon Sep 17 00:00:00 2001 From: StevenRS11 Date: Sun, 16 Jun 2013 01:50:23 -0400 Subject: [PATCH] merged SenseiKiwi changes --- StevenDimDoors/mod_pocketDim/DDLoot.java | 20 +- .../mod_pocketDim/DungeonGenerator.java | 14 - .../mod_pocketDim/SchematicLoader.java | 5 +- .../commands/CommandAddDungeonRift.java | 12 +- .../commands/CommandEndDungeonCreation.java | 15 +- .../commands/CommandStartDungeonCreation.java | 2 +- .../mod_pocketDim/helpers/DungeonHelper.java | 980 +++++++++--------- .../mod_pocketDim/helpers/dimHelper.java | 2 +- .../mod_pocketDim/mod_pocketDim.java | 20 +- 9 files changed, 515 insertions(+), 555 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/DDLoot.java b/StevenDimDoors/mod_pocketDim/DDLoot.java index 7e7eadf1..7e6c6461 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() ); } diff --git a/StevenDimDoors/mod_pocketDim/DungeonGenerator.java b/StevenDimDoors/mod_pocketDim/DungeonGenerator.java index 5ea98727..906ade13 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 diff --git a/StevenDimDoors/mod_pocketDim/SchematicLoader.java b/StevenDimDoors/mod_pocketDim/SchematicLoader.java index a3041d0b..7cf5a326 100644 --- a/StevenDimDoors/mod_pocketDim/SchematicLoader.java +++ b/StevenDimDoors/mod_pocketDim/SchematicLoader.java @@ -173,7 +173,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)) { @@ -984,8 +984,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) diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandAddDungeonRift.java b/StevenDimDoors/mod_pocketDim/commands/CommandAddDungeonRift.java index 91066809..517f7803 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 8c8971a9..d17ef4cf 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() { @@ -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) { @@ -59,13 +61,12 @@ 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"); - mod_pocketDim.dungeonHelper.customDungeons.add(newDungeon); + 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 011bd6c1..57aa12e9 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 952d8f89..fd0a3f4a 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -4,14 +4,13 @@ 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.HashSet; +import java.util.Hashtable; import java.util.Random; +import java.util.regex.Pattern; 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 +18,224 @@ 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 DungeonHelper instance = null; private static DDProperties properties = null; + + 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; + 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"; + 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(); + public HashMap customDungeonStatus = new HashMap(); - public ArrayList customDungeons = new ArrayList(); + public ArrayList customDungeons = new ArrayList(); + public ArrayList registeredDungeons = new ArrayList(); - public ArrayList registeredDungeons = new ArrayList(); - - public ArrayList weightedDungeonGenList = 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 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 tagList = new ArrayList(); - - - - public ArrayList metadataFlipList = new ArrayList(); - - public ArrayList metadataNextList = new ArrayList(); - - public static DungeonGenerator defaultUp = new DungeonGenerator(0, "/schematic/simpleStairsUp.schematic", true); + public ArrayList metadataFlipList = new ArrayList(); + public ArrayList metadataNextList = new ArrayList(); public static DungeonGenerator defaultBreak = new DungeonGenerator(0, "/schematic/somethingBroke.schematic", true); + + + public DungeonGenerator defaultUp = new DungeonGenerator(0, "/schematic/simpleStairsUp.schematic", true); + private HashSet dungeonTypeChecker; + private Hashtable> dungeonTypeMapping; + + private 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 = new Hashtable>(); + 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(); + + 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; + } + + 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("_"); + + //Check for a valid number of parts + if (dungeonData.length < 3 || dungeonData.length > 4) + return false; + + + //Check if the dungeon type is valid + if (!dungeonTypeChecker.contains(dungeonData[0].toLowerCase())) + 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 || weight > MAX_DUNGEON_WEIGHT) + return false; + } + catch (NumberFormatException e) + { + //Not a number + return false; + } + } + return true; + } + public void registerCustomDungeon(File schematicFile) { + String name = schematicFile.getName(); + String path = schematicFile.getAbsolutePath(); try - { - - if(schematicFile.getName().contains(".schematic")) { - String[] name = schematicFile.getName().split("_"); - - if(name.length<4) + if (name.endsWith(SCHEMATIC_FILE_EXTENSION) && validateSchematicName(name)) { - 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 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()); + //Strip off the file extension while splitting the file name + String[] dungeonData = name.substring(0, name.length() - SCHEMATIC_FILE_EXTENSION.length()).split("_"); + 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); + + dungeonTypeMapping.get(dungeonType).add(generator); + weightedDungeonGenList.add(generator); + registeredDungeons.add(generator); + customDungeons.add(generator); + System.out.println("Imported " + name); } 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 +663,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 diff --git a/StevenDimDoors/mod_pocketDim/helpers/dimHelper.java b/StevenDimDoors/mod_pocketDim/helpers/dimHelper.java index f0c2a114..df742003 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 8298877a..6ebe0c79 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,19 +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(); - dungeonHelper.registerDungeonTypeTags(); } @Init @@ -250,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); @@ -391,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(); }