From a713dcd2a3803a486e773e46537dc6536d8f4d80 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Tue, 9 Jul 2013 15:41:39 -0400 Subject: [PATCH 01/13] Minor Change Added a reminder to remove a debug print. --- StevenDimDoors/mod_pocketDim/SchematicLoader.java | 1 + 1 file changed, 1 insertion(+) diff --git a/StevenDimDoors/mod_pocketDim/SchematicLoader.java b/StevenDimDoors/mod_pocketDim/SchematicLoader.java index bb78f83..ab44246 100644 --- a/StevenDimDoors/mod_pocketDim/SchematicLoader.java +++ b/StevenDimDoors/mod_pocketDim/SchematicLoader.java @@ -958,6 +958,7 @@ public class SchematicLoader entranceRiftLocation.getX(), entranceRiftLocation.getY() - 1, entranceRiftLocation.getZ()); + //TODO: Remove this debug print System.out.println("Metadata Orientation: " + sideLink.linkOrientation); } -- 2.39.5 From d23198c4fafcead0e21b1810f8e78b31ce02e179 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Mon, 15 Jul 2013 00:47:32 -0400 Subject: [PATCH 02/13] Fixed Selection of Bounds for Custom Dungeons Fixed the selection of boundaries for custom dungeons. The code had a bug that would clip off a portion of dungeons during exporting. Also, permafabric is not used to mark the edges of the dungeon anymore. That means dungeons can contain permafabric now without getting cut off, and the permafabric shells will be included as part of the export. --- .../mod_pocketDim/helpers/DungeonHelper.java | 117 ++++++++---------- 1 file changed, 54 insertions(+), 63 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index 2639f0a..2a384d6 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -38,6 +38,7 @@ public class DungeonHelper public static final String SCHEMATIC_FILE_EXTENSION = ".schematic"; private static final int DEFAULT_DUNGEON_WEIGHT = 100; public static final int MAX_DUNGEON_WEIGHT = 10000; //Used to prevent overflows and math breaking down + private static final int MAX_EXPORT_RADIUS = 50; private static final String HUB_DUNGEON_TYPE = "Hub"; private static final String TRAP_DUNGEON_TYPE = "Trap"; @@ -375,75 +376,74 @@ public class DungeonHelper registeredDungeons.addAll(hubs); } - public boolean exportDungeon(World world, int xI, int yI, int zI, String exportPath) + public boolean exportDungeonX(World world, int centerX, int centerY, int centerZ, String exportPath) { - int xMin; - int yMin; - int zMin; - - int xMax; - int yMax; - int zMax; - - xMin=xMax=xI; - yMin=yMax=yI; - zMin=zMax=zI; - - for (int count = 0; count < 50; count++) + int xMin, yMin, zMin; + int xMax, yMax, zMax; + int xStart, yStart, zStart; + int xEnd, yEnd, zEnd; + + //Find the smallest bounding box that contains all non-air blocks within a max radius around the player. + xMax = yMax = zMax = Integer.MIN_VALUE; + xMin = yMin = zMin = Integer.MAX_VALUE; + + xStart = centerX - MAX_EXPORT_RADIUS; + zStart = centerZ - MAX_EXPORT_RADIUS; + yStart = Math.max(centerY - MAX_EXPORT_RADIUS, 0); + + xEnd = centerX + MAX_EXPORT_RADIUS; + zEnd = centerZ + MAX_EXPORT_RADIUS; + yEnd = Math.min(centerY - MAX_EXPORT_RADIUS, world.getActualHeight()); + + //This could be done more efficiently, but honestly, this is the simplest approach and it + //makes it easy for us to verify that the code is correct. + for (int x = xStart; x <= xEnd; x++) { - if(world.getBlockId(xMin, yI, zI)!=properties.PermaFabricBlockID) + for (int z = zStart; z <= zEnd; z++) { - xMin--; - } - if(world.getBlockId(xI, yMin, zI)!=properties.PermaFabricBlockID) - { - yMin--; - } - if(world.getBlockId(xI, yI, zMin)!=properties.PermaFabricBlockID) - { - zMin--; - } - if(world.getBlockId(xMax, yI, zI)!=properties.PermaFabricBlockID) - { - xMax++; - } - if(world.getBlockId(xI, yMax, zI)!=properties.PermaFabricBlockID) - { - yMax++; - } - if(world.getBlockId(xI, yI, zMax)!=properties.PermaFabricBlockID) - { - zMax++; + for (int y = yStart; y <= yEnd; y++) + { + if (!world.isAirBlock(x, y, z)) + { + xMax = x > xMax ? x : xMax; + zMax = z > zMax ? z : zMax; + yMax = y > yMax ? y : yMax; + + xMin = x < xMin ? x : xMin; + zMin = z < zMin ? z : zMin; + yMin = y < yMin ? y : yMin; + } + } } } + + //Export all the blocks within our selected bounding box + short width = (short) (xMax - xMin + 1); + short height = (short) (yMax - yMin + 1); + short length = (short) (zMax - zMin + 1); - short width =(short) (xMax-xMin); - short height= (short) (yMax-yMin); - short length= (short) (zMax-zMin); - - //ArrayList tileEntities = new ArrayList(); - ArrayList tileEntites = new ArrayList(); + ArrayList tileEntities = 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 x = 0; x < width; x++) { - for (int y = 0; y < height; ++y) + for (int z = 0; z < length; z++) { - for (int z = 0; z < length; ++z) + for (int y = 0; y < height; y++) { 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); + int blockID = world.getBlockId(x + xMin, y + yMin, z + zMin); + int metadata = world.getBlockMetadata(x + xMin, y + yMin, z + zMin); - if(blockID==properties.DimensionalDoorID) + if (blockID == properties.DimensionalDoorID) { - blockID=Block.doorIron.blockID; + blockID = Block.doorIron.blockID; } - if(blockID==properties.WarpDoorID) + if (blockID == properties.WarpDoorID) { - blockID=Block.doorWood.blockID; + blockID = Block.doorWood.blockID; } @@ -461,7 +461,7 @@ public class DungeonHelper } blocks[index] = (byte) blockID; - blockData[index] = (byte) meta; + blockData[index] = (byte) metadata; if (Block.blocksList[blockID] instanceof BlockContainer) { @@ -486,16 +486,7 @@ public class DungeonHelper } } } - /** - * - * nbtdata.setShort("Width", width); - nbtdata.setShort("Height", height); - nbtdata.setShort("Length", length); - - nbtdata.setByteArray("Blocks", blocks); - nbtdata.setByteArray("Data", blockData); - */ - + HashMap schematic = new HashMap(); schematic.put("Blocks", new ByteArrayTag("Blocks", blocks)); @@ -504,7 +495,7 @@ public class DungeonHelper 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)); + schematic.put("TileEntites", new ListTag("TileEntities", CompoundTag.class, tileEntities)); if (addBlocks != null) { -- 2.39.5 From 90b463b54de1a5ca73a24462cdcc853392439dc1 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Mon, 15 Jul 2013 00:54:53 -0400 Subject: [PATCH 03/13] Standardized Exported Block IDs Standardized exported block IDs for fabric of reality and permafabric blocks. Now we should always export the same block IDs. --- .../mod_pocketDim/helpers/DungeonHelper.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index 2a384d6..3257cde 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -40,6 +40,9 @@ public class DungeonHelper public static final int MAX_DUNGEON_WEIGHT = 10000; //Used to prevent overflows and math breaking down private static final int MAX_EXPORT_RADIUS = 50; + public static final int FABRIC_OF_REALITY_EXPORT_ID = 1973; + public static final int PERMAFABRIC_EXPORT_ID = 220; + 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"; @@ -444,14 +447,23 @@ public class DungeonHelper if (blockID == properties.WarpDoorID) { blockID = Block.doorWood.blockID; - + } + //Map fabric of reality and permafabric blocks to standard export IDs + if (blockID == properties.FabricBlockID) + { + blockID = FABRIC_OF_REALITY_EXPORT_ID; + } + if (blockID == properties.PermaFabricBlockID) + { + blockID = PERMAFABRIC_EXPORT_ID; } // Save 4096 IDs in an AddBlocks section if (blockID > 255) { if (addBlocks == null) - { // Lazily create section + { + //Lazily create section addBlocks = new byte[(blocks.length >> 1) + 1]; } -- 2.39.5 From 404ae3f80d3bb8af93af554aa8b6dc4134c7809f Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Mon, 15 Jul 2013 01:58:01 -0400 Subject: [PATCH 04/13] Minor Change Fixed DungeonHelper.exportDungeon() to have proper name. I'd changed the name before to track where the function was being used in our code. --- StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index 3257cde..5cf0bb2 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -379,7 +379,7 @@ public class DungeonHelper registeredDungeons.addAll(hubs); } - public boolean exportDungeonX(World world, int centerX, int centerY, int centerZ, String exportPath) + public boolean exportDungeon(World world, int centerX, int centerY, int centerZ, String exportPath) { int xMin, yMin, zMin; int xMax, yMax, zMax; -- 2.39.5 From 7dba7683b31ad5b83fad35302252301f96a2d8c7 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Mon, 15 Jul 2013 01:59:02 -0400 Subject: [PATCH 05/13] Progress on Tile Entity Export Support Committing some minor code before making major changes. --- StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index 5cf0bb2..561f822 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -12,6 +12,8 @@ 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.util.WeightedRandom; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; @@ -477,6 +479,13 @@ public class DungeonHelper if (Block.blocksList[blockID] instanceof BlockContainer) { + //Export container information + TileEntity container = world.getBlockTileEntity(x + xMin, y + yMin, z + zMin); + NBTTagCompound entityData = new NBTTagCompound(); + + container.writeToNBT(entityData); + + //TODO fix this /** TileEntity tileEntityBlock = world.getBlockTileEntity(x+xMin, y+yMin, z+zMin); -- 2.39.5 From 5756796218493963b5257beed2d1471ae9ae7a07 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Mon, 15 Jul 2013 02:32:34 -0400 Subject: [PATCH 06/13] Removed the JNBT Package and Classes Removed the JNBT package and classes. I'm going to try rewriting DungeonHelper to export dungeons using Minecraft's standard NBT classes. --- .../mod_pocketDim/helpers/DungeonHelper.java | 8 +- .../helpers/jnbt/ByteArrayTag.java | 86 ----- .../mod_pocketDim/helpers/jnbt/ByteTag.java | 78 ----- .../helpers/jnbt/CompoundTag.java | 89 ----- .../mod_pocketDim/helpers/jnbt/DoubleTag.java | 78 ----- .../mod_pocketDim/helpers/jnbt/EndTag.java | 62 ---- .../mod_pocketDim/helpers/jnbt/FloatTag.java | 78 ----- .../helpers/jnbt/IntArrayTag.java | 86 ----- .../mod_pocketDim/helpers/jnbt/IntTag.java | 78 ----- .../mod_pocketDim/helpers/jnbt/ListTag.java | 106 ------ .../mod_pocketDim/helpers/jnbt/LongTag.java | 78 ----- .../helpers/jnbt/NBTConstants.java | 104 ------ .../helpers/jnbt/NBTInputStream.java | 204 ------------ .../helpers/jnbt/NBTOutputStream.java | 313 ------------------ .../mod_pocketDim/helpers/jnbt/NBTUtils.java | 193 ----------- .../mod_pocketDim/helpers/jnbt/ShortTag.java | 78 ----- .../mod_pocketDim/helpers/jnbt/StringTag.java | 78 ----- .../mod_pocketDim/helpers/jnbt/Tag.java | 75 ----- 18 files changed, 1 insertion(+), 1871 deletions(-) delete mode 100644 StevenDimDoors/mod_pocketDim/helpers/jnbt/ByteArrayTag.java delete mode 100644 StevenDimDoors/mod_pocketDim/helpers/jnbt/ByteTag.java delete mode 100644 StevenDimDoors/mod_pocketDim/helpers/jnbt/CompoundTag.java delete mode 100644 StevenDimDoors/mod_pocketDim/helpers/jnbt/DoubleTag.java delete mode 100644 StevenDimDoors/mod_pocketDim/helpers/jnbt/EndTag.java delete mode 100644 StevenDimDoors/mod_pocketDim/helpers/jnbt/FloatTag.java delete mode 100644 StevenDimDoors/mod_pocketDim/helpers/jnbt/IntArrayTag.java delete mode 100644 StevenDimDoors/mod_pocketDim/helpers/jnbt/IntTag.java delete mode 100644 StevenDimDoors/mod_pocketDim/helpers/jnbt/ListTag.java delete mode 100644 StevenDimDoors/mod_pocketDim/helpers/jnbt/LongTag.java delete mode 100644 StevenDimDoors/mod_pocketDim/helpers/jnbt/NBTConstants.java delete mode 100644 StevenDimDoors/mod_pocketDim/helpers/jnbt/NBTInputStream.java delete mode 100644 StevenDimDoors/mod_pocketDim/helpers/jnbt/NBTOutputStream.java delete mode 100644 StevenDimDoors/mod_pocketDim/helpers/jnbt/NBTUtils.java delete mode 100644 StevenDimDoors/mod_pocketDim/helpers/jnbt/ShortTag.java delete mode 100644 StevenDimDoors/mod_pocketDim/helpers/jnbt/StringTag.java delete mode 100644 StevenDimDoors/mod_pocketDim/helpers/jnbt/Tag.java diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index 561f822..d4ee651 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -21,12 +21,6 @@ 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.jnbt.ByteArrayTag; -import StevenDimDoors.mod_pocketDim.helpers.jnbt.CompoundTag; -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.Tag; import StevenDimDoors.mod_pocketDim.items.itemDimDoor; import StevenDimDoors.mod_pocketDim.util.WeightedContainer; @@ -427,7 +421,7 @@ public class DungeonHelper short height = (short) (yMax - yMin + 1); short length = (short) (zMax - zMin + 1); - ArrayList tileEntities = new ArrayList(); + ArrayList tileEntities = new ArrayList(); byte[] blocks = new byte[width * height * length]; byte[] addBlocks = null; byte[] blockData = new byte[width * height * length]; diff --git a/StevenDimDoors/mod_pocketDim/helpers/jnbt/ByteArrayTag.java b/StevenDimDoors/mod_pocketDim/helpers/jnbt/ByteArrayTag.java deleted file mode 100644 index da90147..0000000 --- a/StevenDimDoors/mod_pocketDim/helpers/jnbt/ByteArrayTag.java +++ /dev/null @@ -1,86 +0,0 @@ -package StevenDimDoors.mod_pocketDim.helpers.jnbt; - - -/* - * JNBT License - * - * Copyright (c) 2010 Graham Edgecombe - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the JNBT team nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * The TAG_Byte_Array tag. - * - * @author Graham Edgecombe - * - */ -public final class ByteArrayTag extends Tag { - - /** - * The value. - */ - private final byte[] value; - - /** - * Creates the tag. - * - * @param name - * The name. - * @param value - * The value. - */ - public ByteArrayTag(String name, byte[] value) { - super(name); - this.value = value; - } - - @Override - public byte[] getValue() { - return value; - } - - @Override - public String toString() { - StringBuilder hex = new StringBuilder(); - for (byte b : value) { - String hexDigits = Integer.toHexString(b).toUpperCase(); - if (hexDigits.length() == 1) { - hex.append("0"); - } - hex.append(hexDigits).append(" "); - } - String name = getName(); - String append = ""; - if (name != null && !name.equals("")) { - append = "(\"" + this.getName() + "\")"; - } - return "TAG_Byte_Array" + append + ": " + hex.toString(); - } - -} diff --git a/StevenDimDoors/mod_pocketDim/helpers/jnbt/ByteTag.java b/StevenDimDoors/mod_pocketDim/helpers/jnbt/ByteTag.java deleted file mode 100644 index a84cfb9..0000000 --- a/StevenDimDoors/mod_pocketDim/helpers/jnbt/ByteTag.java +++ /dev/null @@ -1,78 +0,0 @@ -package StevenDimDoors.mod_pocketDim.helpers.jnbt; - - -/* - * JNBT License - * - * Copyright (c) 2010 Graham Edgecombe - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the JNBT team nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * The TAG_Byte tag. - * - * @author Graham Edgecombe - * - */ -public final class ByteTag extends Tag { - - /** - * The value. - */ - private final byte value; - - /** - * Creates the tag. - * - * @param name - * The name. - * @param value - * The value. - */ - public ByteTag(String name, byte value) { - super(name); - this.value = value; - } - - @Override - public Byte getValue() { - return value; - } - - @Override - public String toString() { - String name = getName(); - String append = ""; - if (name != null && !name.equals("")) { - append = "(\"" + this.getName() + "\")"; - } - return "TAG_Byte" + append + ": " + value; - } - -} diff --git a/StevenDimDoors/mod_pocketDim/helpers/jnbt/CompoundTag.java b/StevenDimDoors/mod_pocketDim/helpers/jnbt/CompoundTag.java deleted file mode 100644 index 1b3ee86..0000000 --- a/StevenDimDoors/mod_pocketDim/helpers/jnbt/CompoundTag.java +++ /dev/null @@ -1,89 +0,0 @@ -package StevenDimDoors.mod_pocketDim.helpers.jnbt; - -/* - * JNBT License - * - * Copyright (c) 2010 Graham Edgecombe - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the JNBT team nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -import java.util.Collections; -import java.util.Map; - -/** - * The TAG_Compound tag. - * - * @author Graham Edgecombe - * - */ -public final class CompoundTag extends Tag { - - /** - * The value. - */ - private final Map value; - - /** - * Creates the tag. - * - * @param name - * The name. - * @param value - * The value. - */ - public CompoundTag(String name, Map value) { - super(name); - this.value = Collections.unmodifiableMap(value); - } - - @Override - public Map getValue() { - return value; - } - - @Override - public String toString() { - String name = getName(); - String append = ""; - if (name != null && !name.equals("")) { - append = "(\"" + this.getName() + "\")"; - } - StringBuilder bldr = new StringBuilder(); - bldr.append("TAG_Compound" + append + ": " + value.size() - + " entries\r\n{\r\n"); - for (Map.Entry entry : value.entrySet()) { - bldr.append(" " - + entry.getValue().toString().replaceAll("\r\n", "\r\n ") - + "\r\n"); - } - bldr.append("}"); - return bldr.toString(); - } - -} diff --git a/StevenDimDoors/mod_pocketDim/helpers/jnbt/DoubleTag.java b/StevenDimDoors/mod_pocketDim/helpers/jnbt/DoubleTag.java deleted file mode 100644 index 6ea2671..0000000 --- a/StevenDimDoors/mod_pocketDim/helpers/jnbt/DoubleTag.java +++ /dev/null @@ -1,78 +0,0 @@ -package StevenDimDoors.mod_pocketDim.helpers.jnbt; - - -/* - * JNBT License - * - * Copyright (c) 2010 Graham Edgecombe - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the JNBT team nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * The TAG_Double tag. - * - * @author Graham Edgecombe - * - */ -public final class DoubleTag extends Tag { - - /** - * The value. - */ - private final double value; - - /** - * Creates the tag. - * - * @param name - * The name. - * @param value - * The value. - */ - public DoubleTag(String name, double value) { - super(name); - this.value = value; - } - - @Override - public Double getValue() { - return value; - } - - @Override - public String toString() { - String name = getName(); - String append = ""; - if (name != null && !name.equals("")) { - append = "(\"" + this.getName() + "\")"; - } - return "TAG_Double" + append + ": " + value; - } - -} diff --git a/StevenDimDoors/mod_pocketDim/helpers/jnbt/EndTag.java b/StevenDimDoors/mod_pocketDim/helpers/jnbt/EndTag.java deleted file mode 100644 index 8558618..0000000 --- a/StevenDimDoors/mod_pocketDim/helpers/jnbt/EndTag.java +++ /dev/null @@ -1,62 +0,0 @@ -package StevenDimDoors.mod_pocketDim.helpers.jnbt; - - -/* - * JNBT License - * - * Copyright (c) 2010 Graham Edgecombe - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the JNBT team nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * The TAG_End tag. - * - * @author Graham Edgecombe - * - */ -public final class EndTag extends Tag { - - /** - * Creates the tag. - */ - public EndTag() { - super(""); - } - - @Override - public Object getValue() { - return null; - } - - @Override - public String toString() { - return "TAG_End"; - } - -} diff --git a/StevenDimDoors/mod_pocketDim/helpers/jnbt/FloatTag.java b/StevenDimDoors/mod_pocketDim/helpers/jnbt/FloatTag.java deleted file mode 100644 index 19c9bc7..0000000 --- a/StevenDimDoors/mod_pocketDim/helpers/jnbt/FloatTag.java +++ /dev/null @@ -1,78 +0,0 @@ -package StevenDimDoors.mod_pocketDim.helpers.jnbt; - - -/* - * JNBT License - * - * Copyright (c) 2010 Graham Edgecombe - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the JNBT team nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * The TAG_Float tag. - * - * @author Graham Edgecombe - * - */ -public final class FloatTag extends Tag { - - /** - * The value. - */ - private final float value; - - /** - * Creates the tag. - * - * @param name - * The name. - * @param value - * The value. - */ - public FloatTag(String name, float value) { - super(name); - this.value = value; - } - - @Override - public Float getValue() { - return value; - } - - @Override - public String toString() { - String name = getName(); - String append = ""; - if (name != null && !name.equals("")) { - append = "(\"" + this.getName() + "\")"; - } - return "TAG_Float" + append + ": " + value; - } - -} diff --git a/StevenDimDoors/mod_pocketDim/helpers/jnbt/IntArrayTag.java b/StevenDimDoors/mod_pocketDim/helpers/jnbt/IntArrayTag.java deleted file mode 100644 index 4c2023a..0000000 --- a/StevenDimDoors/mod_pocketDim/helpers/jnbt/IntArrayTag.java +++ /dev/null @@ -1,86 +0,0 @@ -package StevenDimDoors.mod_pocketDim.helpers.jnbt; - - -/* - * JNBT License - * - * Copyright (c) 2010 Graham Edgecombe - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the JNBT team nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * The TAG_Int_Array tag. - * - * @author Graham Edgecombe - * - */ -public final class IntArrayTag extends Tag { - - /** - * The value. - */ - private final int[] value; - - /** - * Creates the tag. - * - * @param name - * The name. - * @param value - * The value. - */ - public IntArrayTag(String name, int[] value) { - super(name); - this.value = value; - } - - @Override - public int[] getValue() { - return value; - } - - @Override - public String toString() { - StringBuilder hex = new StringBuilder(); - for (int b : value) { - String hexDigits = Integer.toHexString(b).toUpperCase(); - if (hexDigits.length() == 1) { - hex.append("0"); - } - hex.append(hexDigits).append(" "); - } - String name = getName(); - String append = ""; - if (name != null && !name.equals("")) { - append = "(\"" + this.getName() + "\")"; - } - return "TAG_Int_Array" + append + ": " + hex.toString(); - } - -} diff --git a/StevenDimDoors/mod_pocketDim/helpers/jnbt/IntTag.java b/StevenDimDoors/mod_pocketDim/helpers/jnbt/IntTag.java deleted file mode 100644 index 7c1119f..0000000 --- a/StevenDimDoors/mod_pocketDim/helpers/jnbt/IntTag.java +++ /dev/null @@ -1,78 +0,0 @@ -package StevenDimDoors.mod_pocketDim.helpers.jnbt; - - -/* - * JNBT License - * - * Copyright (c) 2010 Graham Edgecombe - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the JNBT team nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * The TAG_Int tag. - * - * @author Graham Edgecombe - * - */ -public final class IntTag extends Tag { - - /** - * The value. - */ - private final int value; - - /** - * Creates the tag. - * - * @param name - * The name. - * @param value - * The value. - */ - public IntTag(String name, int value) { - super(name); - this.value = value; - } - - @Override - public Integer getValue() { - return value; - } - - @Override - public String toString() { - String name = getName(); - String append = ""; - if (name != null && !name.equals("")) { - append = "(\"" + this.getName() + "\")"; - } - return "TAG_Int" + append + ": " + value; - } - -} diff --git a/StevenDimDoors/mod_pocketDim/helpers/jnbt/ListTag.java b/StevenDimDoors/mod_pocketDim/helpers/jnbt/ListTag.java deleted file mode 100644 index edc8d9f..0000000 --- a/StevenDimDoors/mod_pocketDim/helpers/jnbt/ListTag.java +++ /dev/null @@ -1,106 +0,0 @@ -package StevenDimDoors.mod_pocketDim.helpers.jnbt; - -/* - * JNBT License - * - * Copyright (c) 2010 Graham Edgecombe - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the JNBT team nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -import java.util.Collections; -import java.util.List; - -/** - * The TAG_List tag. - * - * @author Graham Edgecombe - * - */ -public final class ListTag extends Tag { - - /** - * The type. - */ - private final Class type; - - /** - * The value. - */ - private final List value; - - /** - * Creates the tag. - * - * @param name - * The name. - * @param type - * The type of item in the list. - * @param value - * The value. - */ - public ListTag(String name, Class type, List value) { - super(name); - this.type = type; - this.value = Collections.unmodifiableList(value); - } - - /** - * Gets the type of item in this list. - * - * @return The type of item in this list. - */ - public Class getType() { - return type; - } - - @Override - public List getValue() { - return value; - } - - @Override - public String toString() { - String name = getName(); - String append = ""; - if (name != null && !name.equals("")) { - append = "(\"" + this.getName() + "\")"; - } - StringBuilder bldr = new StringBuilder(); - bldr.append("TAG_List" + append + ": " + value.size() - + " entries of type " + NBTUtils.getTypeName(type) - + "\r\n{\r\n"); - for (Tag t : value) { - bldr.append(" " + t.toString().replaceAll("\r\n", "\r\n ") - + "\r\n"); - } - bldr.append("}"); - return bldr.toString(); - } - -} diff --git a/StevenDimDoors/mod_pocketDim/helpers/jnbt/LongTag.java b/StevenDimDoors/mod_pocketDim/helpers/jnbt/LongTag.java deleted file mode 100644 index d9fd208..0000000 --- a/StevenDimDoors/mod_pocketDim/helpers/jnbt/LongTag.java +++ /dev/null @@ -1,78 +0,0 @@ -package StevenDimDoors.mod_pocketDim.helpers.jnbt; - - -/* - * JNBT License - * - * Copyright (c) 2010 Graham Edgecombe - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the JNBT team nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * The TAG_Long tag. - * - * @author Graham Edgecombe - * - */ -public final class LongTag extends Tag { - - /** - * The value. - */ - private final long value; - - /** - * Creates the tag. - * - * @param name - * The name. - * @param value - * The value. - */ - public LongTag(String name, long value) { - super(name); - this.value = value; - } - - @Override - public Long getValue() { - return value; - } - - @Override - public String toString() { - String name = getName(); - String append = ""; - if (name != null && !name.equals("")) { - append = "(\"" + this.getName() + "\")"; - } - return "TAG_Long" + append + ": " + value; - } - -} diff --git a/StevenDimDoors/mod_pocketDim/helpers/jnbt/NBTConstants.java b/StevenDimDoors/mod_pocketDim/helpers/jnbt/NBTConstants.java deleted file mode 100644 index ce76f07..0000000 --- a/StevenDimDoors/mod_pocketDim/helpers/jnbt/NBTConstants.java +++ /dev/null @@ -1,104 +0,0 @@ -package StevenDimDoors.mod_pocketDim.helpers.jnbt; - -import java.nio.charset.Charset; - -/* - * JNBT License - * - * Copyright (c) 2010 Graham Edgecombe - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the JNBT team nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * A class which holds constant values. - * - * @author Graham Edgecombe - * - */ -public final class NBTConstants { - - /** - * The character set used by NBT (UTF-8). - */ - public static final Charset CHARSET = Charset.forName("UTF-8"); - - /** - * Tag type constants. - */ - public static final int TYPE_END = 0, TYPE_BYTE = 1, TYPE_SHORT = 2, - TYPE_INT = 3, TYPE_LONG = 4, TYPE_FLOAT = 5, TYPE_DOUBLE = 6, - TYPE_BYTE_ARRAY = 7, TYPE_STRING = 8, TYPE_LIST = 9, - TYPE_COMPOUND = 10, TYPE_INT_ARRAY = 11; - - /** - * Default private constructor. - */ - private NBTConstants() { - - } - - /** - * Convert a type ID to its corresponding {@link Tag} class. - * - * @param id type ID - * @return tag class - * @throws IllegalArgumentException thrown if the tag ID is not valid - */ - public static Class getClassFromType(int id) { - switch (id) { - case TYPE_END: - return EndTag.class; - case TYPE_BYTE: - return ByteTag.class; - case TYPE_SHORT: - return ShortTag.class; - case TYPE_INT: - return IntTag.class; - case TYPE_LONG: - return LongTag.class; - case TYPE_FLOAT: - return FloatTag.class; - case TYPE_DOUBLE: - return DoubleTag.class; - case TYPE_BYTE_ARRAY: - return ByteArrayTag.class; - case TYPE_STRING: - return StringTag.class; - case TYPE_LIST: - return ListTag.class; - case TYPE_COMPOUND: - return CompoundTag.class; - case TYPE_INT_ARRAY: - return IntArrayTag.class; - default: - throw new IllegalArgumentException("Unknown tag type ID of " + id); - } - } - -} diff --git a/StevenDimDoors/mod_pocketDim/helpers/jnbt/NBTInputStream.java b/StevenDimDoors/mod_pocketDim/helpers/jnbt/NBTInputStream.java deleted file mode 100644 index c4fb8ee..0000000 --- a/StevenDimDoors/mod_pocketDim/helpers/jnbt/NBTInputStream.java +++ /dev/null @@ -1,204 +0,0 @@ -package StevenDimDoors.mod_pocketDim.helpers.jnbt; - -/* - * JNBT License - * - * Copyright (c) 2010 Graham Edgecombe - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the JNBT team nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -import java.io.Closeable; -import java.io.DataInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - *

- * This class reads NBT, or Named Binary Tag - * streams, and produces an object graph of subclasses of the Tag - * object. - *

- * - *

- * The NBT format was created by Markus Persson, and the specification may be - * found at - * http://www.minecraft.net/docs/NBT.txt. - *

- * - * @author Graham Edgecombe - * - */ -public final class NBTInputStream implements Closeable { - - /** - * The data input stream. - */ - private final DataInputStream is; - - /** - * Creates a new NBTInputStream, which will source its data - * from the specified input stream. - * - * @param is - * The input stream. - * @throws IOException - * if an I/O error occurs. - */ - public NBTInputStream(InputStream is) throws IOException { - this.is = new DataInputStream(is); - } - - /** - * Reads an NBT tag from the stream. - * - * @return The tag that was read. - * @throws IOException - * if an I/O error occurs. - */ - public Tag readTag() throws IOException { - return readTag(0); - } - - /** - * Reads an NBT from the stream. - * - * @param depth - * The depth of this tag. - * @return The tag that was read. - * @throws IOException - * if an I/O error occurs. - */ - private Tag readTag(int depth) throws IOException { - int type = is.readByte() & 0xFF; - - String name; - if (type != NBTConstants.TYPE_END) { - int nameLength = is.readShort() & 0xFFFF; - byte[] nameBytes = new byte[nameLength]; - is.readFully(nameBytes); - name = new String(nameBytes, NBTConstants.CHARSET); - } else { - name = ""; - } - - return readTagPayload(type, name, depth); - } - - /** - * Reads the payload of a tag, given the name and type. - * - * @param type - * The type. - * @param name - * The name. - * @param depth - * The depth. - * @return The tag. - * @throws IOException - * if an I/O error occurs. - */ - private Tag readTagPayload(int type, String name, int depth) - throws IOException { - switch (type) { - case NBTConstants.TYPE_END: - if (depth == 0) { - throw new IOException( - "TAG_End found without a TAG_Compound/TAG_List tag preceding it."); - } else { - return new EndTag(); - } - case NBTConstants.TYPE_BYTE: - return new ByteTag(name, is.readByte()); - case NBTConstants.TYPE_SHORT: - return new ShortTag(name, is.readShort()); - case NBTConstants.TYPE_INT: - return new IntTag(name, is.readInt()); - case NBTConstants.TYPE_LONG: - return new LongTag(name, is.readLong()); - case NBTConstants.TYPE_FLOAT: - return new FloatTag(name, is.readFloat()); - case NBTConstants.TYPE_DOUBLE: - return new DoubleTag(name, is.readDouble()); - case NBTConstants.TYPE_BYTE_ARRAY: - int length = is.readInt(); - byte[] bytes = new byte[length]; - is.readFully(bytes); - return new ByteArrayTag(name, bytes); - case NBTConstants.TYPE_STRING: - length = is.readShort(); - bytes = new byte[length]; - is.readFully(bytes); - return new StringTag(name, new String(bytes, NBTConstants.CHARSET)); - case NBTConstants.TYPE_LIST: - int childType = is.readByte(); - length = is.readInt(); - - List tagList = new ArrayList(); - for (int i = 0; i < length; ++i) { - Tag tag = readTagPayload(childType, "", depth + 1); - if (tag instanceof EndTag) { - throw new IOException("TAG_End not permitted in a list."); - } - tagList.add(tag); - } - - return new ListTag(name, NBTUtils.getTypeClass(childType), tagList); - case NBTConstants.TYPE_COMPOUND: - Map tagMap = new HashMap(); - while (true) { - Tag tag = readTag(depth + 1); - if (tag instanceof EndTag) { - break; - } else { - tagMap.put(tag.getName(), tag); - } - } - - return new CompoundTag(name, tagMap); - case NBTConstants.TYPE_INT_ARRAY: - length = is.readInt(); - int[] data = new int[length]; - for (int i = 0; i < length; i++) { - data[i] = is.readInt(); - } - return new IntArrayTag(name, data); - default: - throw new IOException("Invalid tag type: " + type + "."); - } - } - - public void close() throws IOException { - is.close(); - } - -} diff --git a/StevenDimDoors/mod_pocketDim/helpers/jnbt/NBTOutputStream.java b/StevenDimDoors/mod_pocketDim/helpers/jnbt/NBTOutputStream.java deleted file mode 100644 index 4f30ee5..0000000 --- a/StevenDimDoors/mod_pocketDim/helpers/jnbt/NBTOutputStream.java +++ /dev/null @@ -1,313 +0,0 @@ -package StevenDimDoors.mod_pocketDim.helpers.jnbt; - -import java.io.Closeable; -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.util.List; -import java.util.zip.GZIPOutputStream; - -/* - * JNBT License - * - * Copyright (c) 2010 Graham Edgecombe - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the JNBT team nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/** - *

- * This class writes NBT, or Named Binary Tag - * Tag objects to an underlying OutputStream. - *

- * - *

- * The NBT format was created by Markus Persson, and the specification may be - * found at - * http://www.minecraft.net/docs/NBT.txt. - *

- * - * @author Graham Edgecombe - * - */ -public final class NBTOutputStream implements Closeable { - - /** - * The output stream. - */ - private final DataOutputStream os; - - /** - * Creates a new NBTOutputStream, which will write data to the - * specified underlying output stream. - * - * @param os - * The output stream. - * @throws IOException - * if an I/O error occurs. - */ - public NBTOutputStream(OutputStream os) throws IOException { - this.os = new DataOutputStream(new GZIPOutputStream(os)); - } - - /** - * Writes a tag. - * - * @param tag - * The tag to write. - * @throws IOException - * if an I/O error occurs. - */ - public void writeTag(Tag tag) throws IOException { - int type = NBTUtils.getTypeCode(tag.getClass()); - String name = tag.getName(); - byte[] nameBytes = name.getBytes(NBTConstants.CHARSET); - - os.writeByte(type); - os.writeShort(nameBytes.length); - os.write(nameBytes); - - if (type == NBTConstants.TYPE_END) { - throw new IOException("Named TAG_End not permitted."); - } - - writeTagPayload(tag); - } - - /** - * Writes tag payload. - * - * @param tag - * The tag. - * @throws IOException - * if an I/O error occurs. - */ - private void writeTagPayload(Tag tag) throws IOException { - int type = NBTUtils.getTypeCode(tag.getClass()); - switch (type) { - case NBTConstants.TYPE_END: - writeEndTagPayload((EndTag) tag); - break; - case NBTConstants.TYPE_BYTE: - writeByteTagPayload((ByteTag) tag); - break; - case NBTConstants.TYPE_SHORT: - writeShortTagPayload((ShortTag) tag); - break; - case NBTConstants.TYPE_INT: - writeIntTagPayload((IntTag) tag); - break; - case NBTConstants.TYPE_LONG: - writeLongTagPayload((LongTag) tag); - break; - case NBTConstants.TYPE_FLOAT: - writeFloatTagPayload((FloatTag) tag); - break; - case NBTConstants.TYPE_DOUBLE: - writeDoubleTagPayload((DoubleTag) tag); - break; - case NBTConstants.TYPE_BYTE_ARRAY: - writeByteArrayTagPayload((ByteArrayTag) tag); - break; - case NBTConstants.TYPE_STRING: - writeStringTagPayload((StringTag) tag); - break; - case NBTConstants.TYPE_LIST: - writeListTagPayload((ListTag) tag); - break; - case NBTConstants.TYPE_COMPOUND: - writeCompoundTagPayload((CompoundTag) tag); - break; - case NBTConstants.TYPE_INT_ARRAY: - writeIntArrayTagPayload((IntArrayTag) tag); - break; - default: - throw new IOException("Invalid tag type: " + type + "."); - } - } - - /** - * Writes a TAG_Byte tag. - * - * @param tag - * The tag. - * @throws IOException - * if an I/O error occurs. - */ - private void writeByteTagPayload(ByteTag tag) throws IOException { - os.writeByte(tag.getValue()); - } - - /** - * Writes a TAG_Byte_Array tag. - * - * @param tag - * The tag. - * @throws IOException - * if an I/O error occurs. - */ - private void writeByteArrayTagPayload(ByteArrayTag tag) throws IOException { - byte[] bytes = tag.getValue(); - os.writeInt(bytes.length); - os.write(bytes); - } - - /** - * Writes a TAG_Compound tag. - * - * @param tag - * The tag. - * @throws IOException - * if an I/O error occurs. - */ - private void writeCompoundTagPayload(CompoundTag tag) throws IOException { - for (Tag childTag : tag.getValue().values()) { - writeTag(childTag); - } - os.writeByte((byte) 0); // end tag - better way? - } - - /** - * Writes a TAG_List tag. - * - * @param tag - * The tag. - * @throws IOException - * if an I/O error occurs. - */ - private void writeListTagPayload(ListTag tag) throws IOException { - Class clazz = tag.getType(); - List tags = tag.getValue(); - int size = tags.size(); - - os.writeByte(NBTUtils.getTypeCode(clazz)); - os.writeInt(size); - for (int i = 0; i < size; ++i) { - writeTagPayload(tags.get(i)); - } - } - - /** - * Writes a TAG_String tag. - * - * @param tag - * The tag. - * @throws IOException - * if an I/O error occurs. - */ - private void writeStringTagPayload(StringTag tag) throws IOException { - byte[] bytes = tag.getValue().getBytes(NBTConstants.CHARSET); - os.writeShort(bytes.length); - os.write(bytes); - } - - /** - * Writes a TAG_Double tag. - * - * @param tag - * The tag. - * @throws IOException - * if an I/O error occurs. - */ - private void writeDoubleTagPayload(DoubleTag tag) throws IOException { - os.writeDouble(tag.getValue()); - } - - /** - * Writes a TAG_Float tag. - * - * @param tag - * The tag. - * @throws IOException - * if an I/O error occurs. - */ - private void writeFloatTagPayload(FloatTag tag) throws IOException { - os.writeFloat(tag.getValue()); - } - - /** - * Writes a TAG_Long tag. - * - * @param tag - * The tag. - * @throws IOException - * if an I/O error occurs. - */ - private void writeLongTagPayload(LongTag tag) throws IOException { - os.writeLong(tag.getValue()); - } - - /** - * Writes a TAG_Int tag. - * - * @param tag - * The tag. - * @throws IOException - * if an I/O error occurs. - */ - private void writeIntTagPayload(IntTag tag) throws IOException { - os.writeInt(tag.getValue()); - } - - /** - * Writes a TAG_Short tag. - * - * @param tag - * The tag. - * @throws IOException - * if an I/O error occurs. - */ - private void writeShortTagPayload(ShortTag tag) throws IOException { - os.writeShort(tag.getValue()); - } - - /** - * Writes a TAG_Empty tag. - * - * @param tag - * The tag. - * @throws IOException - * if an I/O error occurs. - */ - private void writeEndTagPayload(EndTag tag) { - /* empty */ - } - - private void writeIntArrayTagPayload(IntArrayTag tag) throws IOException { - int[] data = tag.getValue(); - os.writeInt(data.length); - for (int i = 0; i < data.length; i++) { - os.writeInt(data[i]); - } - } - - public void close() throws IOException { - os.close(); - } - -} diff --git a/StevenDimDoors/mod_pocketDim/helpers/jnbt/NBTUtils.java b/StevenDimDoors/mod_pocketDim/helpers/jnbt/NBTUtils.java deleted file mode 100644 index 7300cba..0000000 --- a/StevenDimDoors/mod_pocketDim/helpers/jnbt/NBTUtils.java +++ /dev/null @@ -1,193 +0,0 @@ -package StevenDimDoors.mod_pocketDim.helpers.jnbt; - -import java.util.Map; - -/* - * JNBT License - * - * Copyright (c) 2010 Graham Edgecombe - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the JNBT team nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * A class which contains NBT-related utility methods. - * - * @author Graham Edgecombe - * - */ -public final class NBTUtils { - - /** - * Gets the type name of a tag. - * - * @param clazz - * The tag class. - * @return The type name. - */ - public static String getTypeName(Class clazz) { - if (clazz.equals(ByteArrayTag.class)) { - return "TAG_Byte_Array"; - } else if (clazz.equals(ByteTag.class)) { - return "TAG_Byte"; - } else if (clazz.equals(CompoundTag.class)) { - return "TAG_Compound"; - } else if (clazz.equals(DoubleTag.class)) { - return "TAG_Double"; - } else if (clazz.equals(EndTag.class)) { - return "TAG_End"; - } else if (clazz.equals(FloatTag.class)) { - return "TAG_Float"; - } else if (clazz.equals(IntTag.class)) { - return "TAG_Int"; - } else if (clazz.equals(ListTag.class)) { - return "TAG_List"; - } else if (clazz.equals(LongTag.class)) { - return "TAG_Long"; - } else if (clazz.equals(ShortTag.class)) { - return "TAG_Short"; - } else if (clazz.equals(StringTag.class)) { - return "TAG_String"; - } else if (clazz.equals(IntArrayTag.class)) { - return "TAG_Int_Array"; - } else { - throw new IllegalArgumentException("Invalid tag classs (" - + clazz.getName() + ")."); - } - } - - /** - * Gets the type code of a tag class. - * - * @param clazz - * The tag class. - * @return The type code. - * @throws IllegalArgumentException - * if the tag class is invalid. - */ - public static int getTypeCode(Class clazz) { - if (clazz.equals(ByteArrayTag.class)) { - return NBTConstants.TYPE_BYTE_ARRAY; - } else if (clazz.equals(ByteTag.class)) { - return NBTConstants.TYPE_BYTE; - } else if (clazz.equals(CompoundTag.class)) { - return NBTConstants.TYPE_COMPOUND; - } else if (clazz.equals(DoubleTag.class)) { - return NBTConstants.TYPE_DOUBLE; - } else if (clazz.equals(EndTag.class)) { - return NBTConstants.TYPE_END; - } else if (clazz.equals(FloatTag.class)) { - return NBTConstants.TYPE_FLOAT; - } else if (clazz.equals(IntTag.class)) { - return NBTConstants.TYPE_INT; - } else if (clazz.equals(ListTag.class)) { - return NBTConstants.TYPE_LIST; - } else if (clazz.equals(LongTag.class)) { - return NBTConstants.TYPE_LONG; - } else if (clazz.equals(ShortTag.class)) { - return NBTConstants.TYPE_SHORT; - } else if (clazz.equals(StringTag.class)) { - return NBTConstants.TYPE_STRING; - } else if (clazz.equals(IntArrayTag.class)) { - return NBTConstants.TYPE_INT_ARRAY; - } else { - throw new IllegalArgumentException("Invalid tag classs (" - + clazz.getName() + ")."); - } - } - - /** - * Gets the class of a type of tag. - * - * @param type - * The type. - * @return The class. - * @throws IllegalArgumentException - * if the tag type is invalid. - */ - public static Class getTypeClass(int type) { - switch (type) { - case NBTConstants.TYPE_END: - return EndTag.class; - case NBTConstants.TYPE_BYTE: - return ByteTag.class; - case NBTConstants.TYPE_SHORT: - return ShortTag.class; - case NBTConstants.TYPE_INT: - return IntTag.class; - case NBTConstants.TYPE_LONG: - return LongTag.class; - case NBTConstants.TYPE_FLOAT: - return FloatTag.class; - case NBTConstants.TYPE_DOUBLE: - return DoubleTag.class; - case NBTConstants.TYPE_BYTE_ARRAY: - return ByteArrayTag.class; - case NBTConstants.TYPE_STRING: - return StringTag.class; - case NBTConstants.TYPE_LIST: - return ListTag.class; - case NBTConstants.TYPE_COMPOUND: - return CompoundTag.class; - case NBTConstants.TYPE_INT_ARRAY: - return IntArrayTag.class; - default: - throw new IllegalArgumentException("Invalid tag type : " + type - + "."); - } - } - - /** - * Default private constructor. - */ - private NBTUtils() { - - } - - /** - * Get child tag of a NBT structure. - * - * @param items - * @param key - * @param expected - * @return child tag - * @throws InvalidFormatException - */ - public static T getChildTag(Map items, String key, - Class expected) throws Exception { - if (!items.containsKey(key)) { - throw new Exception("Missing a \"" + key + "\" tag"); - } - Tag tag = items.get(key); - if (!expected.isInstance(tag)) { - throw new Exception(key + " tag is not of tag type " + expected.getName()); - } - return expected.cast(tag); - } - -} diff --git a/StevenDimDoors/mod_pocketDim/helpers/jnbt/ShortTag.java b/StevenDimDoors/mod_pocketDim/helpers/jnbt/ShortTag.java deleted file mode 100644 index 61362b4..0000000 --- a/StevenDimDoors/mod_pocketDim/helpers/jnbt/ShortTag.java +++ /dev/null @@ -1,78 +0,0 @@ -package StevenDimDoors.mod_pocketDim.helpers.jnbt; - - -/* - * JNBT License - * - * Copyright (c) 2010 Graham Edgecombe - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the JNBT team nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * The TAG_Short tag. - * - * @author Graham Edgecombe - * - */ -public final class ShortTag extends Tag { - - /** - * The value. - */ - private final short value; - - /** - * Creates the tag. - * - * @param name - * The name. - * @param value - * The value. - */ - public ShortTag(String name, short value) { - super(name); - this.value = value; - } - - @Override - public Short getValue() { - return value; - } - - @Override - public String toString() { - String name = getName(); - String append = ""; - if (name != null && !name.equals("")) { - append = "(\"" + this.getName() + "\")"; - } - return "TAG_Short" + append + ": " + value; - } - -} diff --git a/StevenDimDoors/mod_pocketDim/helpers/jnbt/StringTag.java b/StevenDimDoors/mod_pocketDim/helpers/jnbt/StringTag.java deleted file mode 100644 index 880ec78..0000000 --- a/StevenDimDoors/mod_pocketDim/helpers/jnbt/StringTag.java +++ /dev/null @@ -1,78 +0,0 @@ -package StevenDimDoors.mod_pocketDim.helpers.jnbt; - - -/* - * JNBT License - * - * Copyright (c) 2010 Graham Edgecombe - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the JNBT team nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * The TAG_String tag. - * - * @author Graham Edgecombe - * - */ -public final class StringTag extends Tag { - - /** - * The value. - */ - private final String value; - - /** - * Creates the tag. - * - * @param name - * The name. - * @param value - * The value. - */ - public StringTag(String name, String value) { - super(name); - this.value = value; - } - - @Override - public String getValue() { - return value; - } - - @Override - public String toString() { - String name = getName(); - String append = ""; - if (name != null && !name.equals("")) { - append = "(\"" + this.getName() + "\")"; - } - return "TAG_String" + append + ": " + value; - } - -} diff --git a/StevenDimDoors/mod_pocketDim/helpers/jnbt/Tag.java b/StevenDimDoors/mod_pocketDim/helpers/jnbt/Tag.java deleted file mode 100644 index a3f6251..0000000 --- a/StevenDimDoors/mod_pocketDim/helpers/jnbt/Tag.java +++ /dev/null @@ -1,75 +0,0 @@ -package StevenDimDoors.mod_pocketDim.helpers.jnbt; - -/* - * JNBT License - * - * Copyright (c) 2010 Graham Edgecombe - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the JNBT team nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * Represents a single NBT tag. - * - * @author Graham Edgecombe - * - */ -public abstract class Tag { - - /** - * The name of this tag. - */ - private final String name; - - /** - * Creates the tag with the specified name. - * - * @param name - * The name. - */ - public Tag(String name) { - this.name = name; - } - - /** - * Gets the name of this tag. - * - * @return The name of this tag. - */ - public final String getName() { - return name; - } - - /** - * Gets the value of this tag. - * - * @return The value of this tag. - */ - public abstract Object getValue(); - -} -- 2.39.5 From 203580bbbf7ed2e6addfdba4cc881ff8b501b525 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Mon, 15 Jul 2013 03:29:15 -0400 Subject: [PATCH 07/13] Changed Dungeon Export to use MC NBT Classes Changed DungeonHelper.exportDungeon() to use Minecraft's NBT tag classes instead of using JNBT. The implementation is actually slightly simpler than our original JNBT version. I also fixed a bug in the way the extremes of the bounding box search were calculated that caused yEnd to have an incorrect value. Exporting works properly now. Confirmed with tests. --- .../mod_pocketDim/helpers/DungeonHelper.java | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index d4ee651..62fdc8b 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -12,7 +12,9 @@ import java.util.regex.Pattern; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; +import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.WeightedRandom; import net.minecraft.world.World; @@ -392,7 +394,7 @@ public class DungeonHelper xEnd = centerX + MAX_EXPORT_RADIUS; zEnd = centerZ + MAX_EXPORT_RADIUS; - yEnd = Math.min(centerY - MAX_EXPORT_RADIUS, world.getActualHeight()); + yEnd = Math.min(centerY + MAX_EXPORT_RADIUS, world.getActualHeight()); //This could be done more efficiently, but honestly, this is the simplest approach and it //makes it easy for us to verify that the code is correct. @@ -421,7 +423,7 @@ public class DungeonHelper short height = (short) (yMax - yMin + 1); short length = (short) (zMax - zMin + 1); - ArrayList tileEntities = new ArrayList(); + //ArrayList tileEntities = new ArrayList(); byte[] blocks = new byte[width * height * length]; byte[] addBlocks = null; byte[] blockData = new byte[width * height * length]; @@ -474,10 +476,10 @@ public class DungeonHelper if (Block.blocksList[blockID] instanceof BlockContainer) { //Export container information - TileEntity container = world.getBlockTileEntity(x + xMin, y + yMin, z + zMin); + /*TileEntity container = world.getBlockTileEntity(x + xMin, y + yMin, z + zMin); NBTTagCompound entityData = new NBTTagCompound(); - container.writeToNBT(entityData); + container.writeToNBT(entityData);*/ //TODO fix this @@ -502,27 +504,31 @@ public class DungeonHelper } } - HashMap schematic = new HashMap(); + NBTTagCompound schematicTag = new NBTTagCompound("Schematic"); - schematic.put("Blocks", new ByteArrayTag("Blocks", blocks)); - schematic.put("Data", new ByteArrayTag("Data", blockData)); + schematicTag.setShort("Width", width); + schematicTag.setShort("Length", length); + schematicTag.setShort("Height", height); - 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, tileEntities)); + schematicTag.setByteArray("Blocks", blocks); + schematicTag.setByteArray("Data", blockData); + + schematicTag.setTag("Entities", new NBTTagList()); + schematicTag.setTag("TileEntities", new NBTTagList()); + schematicTag.setString("Material", "Alpha"); if (addBlocks != null) { - schematic.put("AddBlocks", new ByteArrayTag("AddBlocks", addBlocks)); + schematicTag.setByteArray("AddBlocks", addBlocks); } - CompoundTag schematicTag = new CompoundTag("Schematic", schematic); try { - NBTOutputStream stream = new NBTOutputStream(new FileOutputStream(exportPath)); - stream.writeTag(schematicTag); - stream.close(); + FileOutputStream outputStream = new FileOutputStream(new File(exportPath)); + CompressedStreamTools.writeCompressed(schematicTag, outputStream); + //writeCompressed() probably closes the stream on its own - call close again just in case. + //Closing twice will not throw an exception. + outputStream.close(); return true; } catch(Exception e) -- 2.39.5 From 8cc8f50f34a431bccf89fd0aee1255be0d9290df Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Mon, 15 Jul 2013 04:15:58 -0400 Subject: [PATCH 08/13] Added Support for Exporting Tile Entities Added support for exporting tile entities as part of custom dungeons. I've produced a schematic as a test that shows items are exported properly and they're recognized in MCedit. I still need to add support for loading tile entities in imported schematics. --- .../mod_pocketDim/helpers/DungeonHelper.java | 50 +++++++++---------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index 62fdc8b..4c5292c 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -423,10 +423,10 @@ public class DungeonHelper short height = (short) (yMax - yMin + 1); short length = (short) (zMax - zMin + 1); - //ArrayList tileEntities = new ArrayList(); byte[] blocks = new byte[width * height * length]; byte[] addBlocks = null; byte[] blockData = new byte[width * height * length]; + NBTTagList tileEntities = new NBTTagList(); for (int x = 0; x < width; x++) { @@ -437,23 +437,28 @@ public class DungeonHelper int index = y * width * length + z * width + x; int blockID = world.getBlockId(x + xMin, y + yMin, z + zMin); int metadata = world.getBlockMetadata(x + xMin, y + yMin, z + zMin); + boolean changed = false; if (blockID == properties.DimensionalDoorID) { blockID = Block.doorIron.blockID; + changed = true; } if (blockID == properties.WarpDoorID) { blockID = Block.doorWood.blockID; + changed = true; } //Map fabric of reality and permafabric blocks to standard export IDs if (blockID == properties.FabricBlockID) { blockID = FABRIC_OF_REALITY_EXPORT_ID; + changed = true; } if (blockID == properties.PermaFabricBlockID) { blockID = PERMAFABRIC_EXPORT_ID; + changed = true; } // Save 4096 IDs in an AddBlocks section @@ -473,37 +478,27 @@ public class DungeonHelper blocks[index] = (byte) blockID; blockData[index] = (byte) metadata; - if (Block.blocksList[blockID] instanceof BlockContainer) + //Obtain and export the tile entity of the current block, if any. + //Do not obtain a tile entity if the block was changed from its original ID. + //I'm not sure if this approach is the most efficient but it works. ~SenseiKiwi + TileEntity tileEntity = !changed ? world.getBlockTileEntity(x + xMin, y + yMin, z + zMin) : null; + + if (tileEntity != null) { - //Export container information - /*TileEntity container = world.getBlockTileEntity(x + xMin, y + yMin, z + zMin); + //Get the tile entity's description as a compound NBT tag NBTTagCompound entityData = new NBTTagCompound(); - - container.writeToNBT(entityData);*/ - - - //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); - } - **/ + tileEntity.writeToNBT(entityData); + //Change the tile entity's location to be relative to (xMin, yMin, zMin) + entityData.setInteger("x", entityData.getInteger("x") - xMin); + entityData.setInteger("y", entityData.getInteger("y") - yMin); + entityData.setInteger("z", entityData.getInteger("z") - zMin); + tileEntities.appendTag(entityData); } } } } + //Write NBT tags for schematic file NBTTagCompound schematicTag = new NBTTagCompound("Schematic"); schematicTag.setShort("Width", width); @@ -514,14 +509,15 @@ public class DungeonHelper schematicTag.setByteArray("Data", blockData); schematicTag.setTag("Entities", new NBTTagList()); - schematicTag.setTag("TileEntities", new NBTTagList()); - schematicTag.setString("Material", "Alpha"); + schematicTag.setTag("TileEntities", tileEntities); + schematicTag.setString("Materials", "Alpha"); if (addBlocks != null) { schematicTag.setByteArray("AddBlocks", addBlocks); } + //Write schematic data to a file try { FileOutputStream outputStream = new FileOutputStream(new File(exportPath)); -- 2.39.5 From d21f29ec2cf133b9c9c6e541e751e798538ef113 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Mon, 15 Jul 2013 04:38:51 -0400 Subject: [PATCH 09/13] Minor Change to Tile Entity Exporting Rewrote the code that changes the position of a tile entity to be expressed in the schematic coordinate system. The new code should be equivalent but easier to understand. --- StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index 4c5292c..9e01ead 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -488,10 +488,11 @@ public class DungeonHelper //Get the tile entity's description as a compound NBT tag NBTTagCompound entityData = new NBTTagCompound(); tileEntity.writeToNBT(entityData); - //Change the tile entity's location to be relative to (xMin, yMin, zMin) - entityData.setInteger("x", entityData.getInteger("x") - xMin); - entityData.setInteger("y", entityData.getInteger("y") - yMin); - entityData.setInteger("z", entityData.getInteger("z") - zMin); + //Change the tile entity's location to the schematic coordinate system + entityData.setInteger("x", x); + entityData.setInteger("y", y); + entityData.setInteger("z", z); + tileEntities.appendTag(entityData); } } -- 2.39.5 From 7583df430cac5478f09fcf01fe54d244122a347f Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Mon, 15 Jul 2013 04:42:20 -0400 Subject: [PATCH 10/13] Minor Change Removed import of BlockContainer from DungeonHelper. --- StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java | 1 - 1 file changed, 1 deletion(-) diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index 9e01ead..f987196 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -11,7 +11,6 @@ import java.util.Random; import java.util.regex.Pattern; import net.minecraft.block.Block; -import net.minecraft.block.BlockContainer; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -- 2.39.5 From 888e6fe590ec32ed3c03b3784c48a6996f84271a Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Mon, 15 Jul 2013 12:56:32 -0400 Subject: [PATCH 11/13] Fixed Bug in CommandEndDungeonCreation Fixed a simple bug that caused dd-export to ask the user to use 'override' even though it was already being used. --- .../mod_pocketDim/commands/CommandEndDungeonCreation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandEndDungeonCreation.java b/StevenDimDoors/mod_pocketDim/commands/CommandEndDungeonCreation.java index a89abf1..9e1127c 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandEndDungeonCreation.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandEndDungeonCreation.java @@ -78,7 +78,7 @@ public class CommandEndDungeonCreation extends DDCommandBase //The user must have used the 3-argument version of this command //Check if the current dimension is a pocket for building custom dungeons or if the override argument was used. - if (!dungeonHelper.isCustomDungeon(sender.worldObj.provider.dimensionId) || + if (!dungeonHelper.isCustomDungeon(sender.worldObj.provider.dimensionId) && !command[command.length - 1].equalsIgnoreCase("override")) { //This dimension may not be exported without overriding! -- 2.39.5 From 1ac934b5e4290a0b51d3377d3377d6fab9bda4ef Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Mon, 15 Jul 2013 16:58:44 -0400 Subject: [PATCH 12/13] Added Support for Importing Tile Entities Added code to SchematicLoader so that we can import tile entities. Empty chests and dispensers will still be filled as before. --- StevenDimDoors/mod_pocketDim/Point3D.java | 75 ++++++-- .../mod_pocketDim/SchematicLoader.java | 161 ++++++++++++------ .../mod_pocketDim/helpers/DungeonHelper.java | 10 +- 3 files changed, 170 insertions(+), 76 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/Point3D.java b/StevenDimDoors/mod_pocketDim/Point3D.java index 27e5081..29f7374 100644 --- a/StevenDimDoors/mod_pocketDim/Point3D.java +++ b/StevenDimDoors/mod_pocketDim/Point3D.java @@ -4,9 +4,9 @@ import java.io.Serializable; public class Point3D implements Serializable { - private int x; - private int y; - private int z; + private int x; + private int y; + private int z; public Point3D(int x, int y,int z) { @@ -29,20 +29,20 @@ public class Point3D implements Serializable { { return z; } - - public int setY(int y) - { - return this.y=y; - } public int setX(int x) { - return this. x=x; + return this.x = x; + } + + public int setY(int y) + { + return this.y = y; } public int setZ(int z) { - return this. z=z; + return this.z = z; } public Point3D clone() @@ -50,14 +50,57 @@ public class Point3D implements Serializable { return new Point3D(x, y, z); } - public boolean equals(Object other) + public boolean equals(Point3D other) { - boolean result = false; - if (other instanceof Point3D) + if (other == null) + return false; + + if (this == other) + return true; + + return (this.x == other.x && this.y == other.y && this.z == other.z); + } + + public boolean equals(Object other) + { + return equals((Point3D) other); + } + + @Override + public int hashCode() + { + //Time for some witchcraft. + //The code here is inspired by a discussion on Stack Overflow regarding hash codes for 3D. + //Source: http://stackoverflow.com/questions/9858376/hashcode-for-3d-integer-coordinates-with-high-spatial-coherence + + //I believe that most of the time, any points we might be hashing will be in close proximity to each other. + //For instance, points that are within the same chunk or within a few neighboring chunks. Only the low-order + //bits of each component would differ. I'll use 8 bits from Y and the 12 bits from X and Z. ~SenseiKiwi + + //The result of this could be cached but that would break serialization for this class! >_< + + int bit; + int hash; + int index; + + hash = 0; + index = 0; + for (bit = 0; bit < 8; bit++) { - Point3D that = (Point3D) other; - result = (this.getX() == that.getX() && this.getY() == that.getY()&& this.getY() == that.getZ()); + hash |= ((y >> bit) & 1) << index; + index++; + hash |= ((x >> bit) & 1) << index; + index++; + hash |= ((z >> bit) & 1) << index; + index++; } - return result; + for (; bit < 12; bit++) + { + hash |= ((x >> bit) & 1) << index; + index++; + hash |= ((z >> bit) & 1) << index; + index++; + } + return hash; } } \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/SchematicLoader.java b/StevenDimDoors/mod_pocketDim/SchematicLoader.java index ab44246..f7f4038 100644 --- a/StevenDimDoors/mod_pocketDim/SchematicLoader.java +++ b/StevenDimDoors/mod_pocketDim/SchematicLoader.java @@ -3,6 +3,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.util.ArrayList; +import java.util.HashMap; import java.util.Random; import net.minecraft.block.Block; @@ -12,11 +13,13 @@ import net.minecraft.block.BlockDoor; import net.minecraft.block.BlockRedstoneRepeater; import net.minecraft.block.BlockStairs; import net.minecraft.entity.Entity; +import net.minecraft.inventory.IInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; +import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityChest; import net.minecraft.tileentity.TileEntityDispenser; import net.minecraft.util.MathHelper; @@ -34,6 +37,7 @@ public class SchematicLoader { private final static int EAST_DOOR_METADATA = 0; private final static int NORTH_DOOR_METADATA = 3; + private final static int MAX_VANILLA_BLOCK_ID = 158; private DDProperties properties = DDProperties.instance(); @@ -688,15 +692,16 @@ public class SchematicLoader //block metaData byte[] blockData = new byte[0]; - //first 4 bytes of the block ID + //first 8 bits of the block ID byte[] blockId = new byte[0]; - //second 4 bytes of the block ID + //additional 4 bits of the block ID byte[] addId = new byte[0]; + //Variables for loading tile entities + boolean blockChanged = false; NBTTagList tileEntities = null; - NBTTagCompound[] tileEntityList; - NBTTagList entities; + HashMap pointToTileEntityMap = new HashMap(); //the wooden door leading into the pocket Point3D schematicEntrance = new Point3D(0,0,0); @@ -727,37 +732,24 @@ public class SchematicLoader System.out.println(new File(fname).exists()); input = new FileInputStream(fname); } - NBTTagCompound nbtdata = CompressedStreamTools.readCompressed(input); + + NBTTagCompound schematicTag = CompressedStreamTools.readCompressed(input); + input.close(); //readCompressed() probably closes the stream anyway, but close again to be sure. //load size of schematic to generate - width = nbtdata.getShort("Width"); - height = nbtdata.getShort("Height"); - length = nbtdata.getShort("Length"); + width = schematicTag.getShort("Width"); + height = schematicTag.getShort("Height"); + length = schematicTag.getShort("Length"); //load block info - blockId = nbtdata.getByteArray("Blocks"); - blockData = nbtdata.getByteArray("Data"); - addId = nbtdata.getByteArray("AddBlocks"); + blockId = schematicTag.getByteArray("Blocks"); + blockData = schematicTag.getByteArray("Data"); + addId = schematicTag.getByteArray("AddBlocks"); //create combined block list blocks = new short[blockId.length]; - //load ticking things - tileEntities = nbtdata.getTagList("TileEntities"); - //tileEntityList = new NBTTagCompound[width*height*length]; - /** - for(int count = 0; count> 1) >= addId.length) @@ -776,6 +768,21 @@ public class SchematicLoader } } } + + //Get the list of tile entities + tileEntities = schematicTag.getTagList("TileEntities"); + + //Map tile entity positions to the tile entity itself using a hash map + int count = tileEntities.tagCount(); + for (int index = 0; index < count; index++) + { + NBTTagCompound tileEntityData = (NBTTagCompound) tileEntities.tagAt(index); + Point3D location = new Point3D( + tileEntityData.getInteger("x"), + tileEntityData.getInteger("y"), + tileEntityData.getInteger("z")); + pointToTileEntityMap.put(location, tileEntityData); + } } catch (Exception e) { @@ -801,6 +808,7 @@ public class SchematicLoader //Coordinates relative to the schematic, start at 0 and increase up to max width/height/length int x, y, z; + Point3D schematicPoint = new Point3D(0, 0, 0); //The real point where a block will be placed int realX, realY, realZ; @@ -816,11 +824,11 @@ public class SchematicLoader //First loop through the schematic to load in all rift locations and Monolith spawn locations. //Also find the entry door, which determines the final position and orientation of the dungeon. - for ( x = 0; x < width; ++x) + for (y = 0; y < height; y++) { - for ( y = 0; y < height; ++y) + for (z = 0; z < length; z++) { - for ( z = 0; z < length; ++z) + for (x = 0; x < width; x++) { int index = y * width * length + z * width + x; int indexBelow = (y - 1) * width * length + z * width + x; @@ -857,12 +865,16 @@ public class SchematicLoader } //Loop to actually place the blocks - for (x = 0; x < width; x++) + for (y = 0; y < height; y++) { + schematicPoint.setY(y); for (z = 0; z < length; z++) { - for (y = 0; y < height; y++) + schematicPoint.setZ(z); + for (x = 0; x < width; x++) { + schematicPoint.setX(x); + //Reinitialize pocketPoint with the current schematic coordinate system pocketPoint.setX(x); pocketPoint.setY(y); @@ -877,17 +889,28 @@ public class SchematicLoader int index = y * width * length + z * width + x; int currentBlock = blocks[index]; int blockMetadata = blockData[index]; - NBTTagList tileEntity = tileEntities; + blockChanged = false; //replace tagging blocks with air, and mod blocks with FoR if (currentBlock == Block.endPortalFrame.blockID) { currentBlock = 0; + blockChanged = true; } - else if ((Block.blocksList[currentBlock] == null && currentBlock != 0) || - (currentBlock > 158 && currentBlock != mod_pocketDim.blockDimWallPerm.blockID)) //TODO- replace 158 with max vanilla block ID + else if (currentBlock == DungeonHelper.FABRIC_OF_REALITY_EXPORT_ID) { currentBlock = mod_pocketDim.blockDimWall.blockID; + blockChanged = true; + } + else if (currentBlock == DungeonHelper.PERMAFABRIC_EXPORT_ID) + { + currentBlock = mod_pocketDim.blockDimWallPerm.blockID; + blockChanged = true; + } + else if ((Block.blocksList[currentBlock] == null && currentBlock != 0) || currentBlock > MAX_VANILLA_BLOCK_ID) + { + currentBlock = mod_pocketDim.blockDimWall.blockID; + blockChanged = true; } //Place blocks and set metadata @@ -901,41 +924,58 @@ public class SchematicLoader if (currentBlock == Block.doorIron.blockID) { setBlockDirectly(world, realX, realY, realZ, properties.DimensionalDoorID, fixedMetadata); + blockChanged = true; } else if (currentBlock == Block.doorWood.blockID) { setBlockDirectly(world, realX, realY, realZ, properties.WarpDoorID, fixedMetadata); + blockChanged = true; } else { setBlockDirectly(world, realX, realY, realZ, currentBlock, fixedMetadata); } - - //Fill containers (e.g. chests, dispensers) - if(Block.blocksList[currentBlock] instanceof BlockContainer) + + //Load the tile entity at this location if any exists, but only if the block wasn't changed + if (!blockChanged) { - /** - TileEntity tile = world.getBlockTileEntity(i+xCooe, j+yCooe, k+zCooe); - NBTTagCompound tag = this.tileEntityList[index]; - if(tag!=null) + NBTTagCompound tileEntityData = pointToTileEntityMap.get(schematicPoint); + + if (tileEntityData != null) { - tile.readFromNBT(tag); + //Change the tile entity's position + tileEntityData.setInteger("x", realX); + tileEntityData.setInteger("y", realY); + tileEntityData.setInteger("z", realZ); + //Load the tile entity into the world + world.setBlockTileEntity(realX, realY, realZ, TileEntity.createAndLoadEntity(tileEntityData)); } - **/ + } + + //Fill empty chests and dispensers + if (Block.blocksList[currentBlock] instanceof BlockContainer) + { + TileEntity tileEntity = world.getBlockTileEntity(realX, realY, realZ); //Fill chests - if (world.getBlockTileEntity(realX, realY, realZ) instanceof TileEntityChest) + if (tileEntity instanceof TileEntityChest) { - TileEntityChest chest = (TileEntityChest) world.getBlockTileEntity(realX, realY, realZ); - ChestGenHooks info = DDLoot.DungeonChestInfo; - WeightedRandomChestContent.generateChestContents(rand, info.getItems(rand), chest, info.getCount(rand)); + TileEntityChest chest = (TileEntityChest) tileEntity; + if (isInventoryEmpty(chest)) + { + ChestGenHooks info = DDLoot.DungeonChestInfo; + WeightedRandomChestContent.generateChestContents(rand, info.getItems(rand), chest, info.getCount(rand)); + } } - + //Fill dispensers - if (world.getBlockTileEntity(realX, realY, realZ) instanceof TileEntityDispenser) + if (tileEntity instanceof TileEntityDispenser) { - TileEntityDispenser dispenser = (TileEntityDispenser) world.getBlockTileEntity(realX, realY, realZ); - dispenser.addItem(new ItemStack(Item.arrow, 64)); + TileEntityDispenser dispenser = (TileEntityDispenser) tileEntity; + if (isInventoryEmpty(dispenser)) + { + dispenser.addItem(new ItemStack(Item.arrow, 64)); + } } } } @@ -958,8 +998,6 @@ public class SchematicLoader entranceRiftLocation.getX(), entranceRiftLocation.getY() - 1, entranceRiftLocation.getZ()); - //TODO: Remove this debug print - System.out.println("Metadata Orientation: " + sideLink.linkOrientation); } //Generate the LinkData defined by the door placement, Iron Dim doors first @@ -1077,7 +1115,20 @@ public class SchematicLoader } } - private void transformPoint(Point3D position, Point3D srcOrigin, int angle, Point3D destOrigin) + private static boolean isInventoryEmpty(IInventory inventory) + { + int size = inventory.getSizeInventory(); + for (int index = 0; index < size; index++) + { + if (inventory.getStackInSlot(index) != null) + { + return false; + } + } + return true; + } + + private static void transformPoint(Point3D position, Point3D srcOrigin, int angle, Point3D destOrigin) { //This function receives a position (e.g. point in schematic space), translates it relative //to a source coordinate system (e.g. the point that will be the center of a schematic), diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index f987196..bea7fab 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -397,18 +397,18 @@ public class DungeonHelper //This could be done more efficiently, but honestly, this is the simplest approach and it //makes it easy for us to verify that the code is correct. - for (int x = xStart; x <= xEnd; x++) + for (int y = yStart; y <= yEnd; y++) { for (int z = zStart; z <= zEnd; z++) { - for (int y = yStart; y <= yEnd; y++) + for (int x = xStart; x <= xEnd; x++) { if (!world.isAirBlock(x, y, z)) { xMax = x > xMax ? x : xMax; zMax = z > zMax ? z : zMax; yMax = y > yMax ? y : yMax; - + xMin = x < xMin ? x : xMin; zMin = z < zMin ? z : zMin; yMin = y < yMin ? y : yMin; @@ -427,11 +427,11 @@ public class DungeonHelper byte[] blockData = new byte[width * height * length]; NBTTagList tileEntities = new NBTTagList(); - for (int x = 0; x < width; x++) + for (int y = 0; y < height; y++) { for (int z = 0; z < length; z++) { - for (int y = 0; y < height; y++) + for (int x = 0; x < width; x++) { int index = y * width * length + z * width + x; int blockID = world.getBlockId(x + xMin, y + yMin, z + zMin); -- 2.39.5 From 3e096c007472a17ac3a7333acd0dcbed4359eddb Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Mon, 15 Jul 2013 17:00:09 -0400 Subject: [PATCH 13/13] Minor Change Removed a comment from Point3D. We don't need to cache hashes since HashMap does so internally. --- StevenDimDoors/mod_pocketDim/Point3D.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/Point3D.java b/StevenDimDoors/mod_pocketDim/Point3D.java index 29f7374..5d4a03d 100644 --- a/StevenDimDoors/mod_pocketDim/Point3D.java +++ b/StevenDimDoors/mod_pocketDim/Point3D.java @@ -77,8 +77,6 @@ public class Point3D implements Serializable { //For instance, points that are within the same chunk or within a few neighboring chunks. Only the low-order //bits of each component would differ. I'll use 8 bits from Y and the 12 bits from X and Z. ~SenseiKiwi - //The result of this could be cached but that would break serialization for this class! >_< - int bit; int hash; int index; -- 2.39.5