Implemented Importing and Exporting Tile Entities; Additional Improvements #41
@@ -423,10 +423,10 @@ public class DungeonHelper
|
|||||||
short height = (short) (yMax - yMin + 1);
|
short height = (short) (yMax - yMin + 1);
|
||||||
short length = (short) (zMax - zMin + 1);
|
short length = (short) (zMax - zMin + 1);
|
||||||
|
|
||||||
//ArrayList<NBTCompoundTag> tileEntities = new ArrayList<NBTCompoundTag>();
|
|
||||||
byte[] blocks = new byte[width * height * length];
|
byte[] blocks = new byte[width * height * length];
|
||||||
byte[] addBlocks = null;
|
byte[] addBlocks = null;
|
||||||
byte[] blockData = new byte[width * height * length];
|
byte[] blockData = new byte[width * height * length];
|
||||||
|
NBTTagList tileEntities = new NBTTagList();
|
||||||
|
|
||||||
for (int x = 0; x < width; x++)
|
for (int x = 0; x < width; x++)
|
||||||
{
|
{
|
||||||
@@ -437,23 +437,28 @@ public class DungeonHelper
|
|||||||
int index = y * width * length + z * width + x;
|
int index = y * width * length + z * width + x;
|
||||||
int blockID = world.getBlockId(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);
|
int metadata = world.getBlockMetadata(x + xMin, y + yMin, z + zMin);
|
||||||
|
boolean changed = false;
|
||||||
|
|
||||||
if (blockID == properties.DimensionalDoorID)
|
if (blockID == properties.DimensionalDoorID)
|
||||||
{
|
{
|
||||||
blockID = Block.doorIron.blockID;
|
blockID = Block.doorIron.blockID;
|
||||||
|
changed = true;
|
||||||
}
|
}
|
||||||
if (blockID == properties.WarpDoorID)
|
if (blockID == properties.WarpDoorID)
|
||||||
{
|
{
|
||||||
blockID = Block.doorWood.blockID;
|
blockID = Block.doorWood.blockID;
|
||||||
|
changed = true;
|
||||||
}
|
}
|
||||||
//Map fabric of reality and permafabric blocks to standard export IDs
|
//Map fabric of reality and permafabric blocks to standard export IDs
|
||||||
if (blockID == properties.FabricBlockID)
|
if (blockID == properties.FabricBlockID)
|
||||||
{
|
{
|
||||||
blockID = FABRIC_OF_REALITY_EXPORT_ID;
|
blockID = FABRIC_OF_REALITY_EXPORT_ID;
|
||||||
|
changed = true;
|
||||||
}
|
}
|
||||||
if (blockID == properties.PermaFabricBlockID)
|
if (blockID == properties.PermaFabricBlockID)
|
||||||
{
|
{
|
||||||
blockID = PERMAFABRIC_EXPORT_ID;
|
blockID = PERMAFABRIC_EXPORT_ID;
|
||||||
|
changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save 4096 IDs in an AddBlocks section
|
// Save 4096 IDs in an AddBlocks section
|
||||||
@@ -473,37 +478,27 @@ public class DungeonHelper
|
|||||||
blocks[index] = (byte) blockID;
|
blocks[index] = (byte) blockID;
|
||||||
blockData[index] = (byte) metadata;
|
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
|
//Get the tile entity's description as a compound NBT tag
|
||||||
/*TileEntity container = world.getBlockTileEntity(x + xMin, y + yMin, z + zMin);
|
|
||||||
NBTTagCompound entityData = new NBTTagCompound();
|
NBTTagCompound entityData = new NBTTagCompound();
|
||||||
|
tileEntity.writeToNBT(entityData);
|
||||||
container.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);
|
||||||
//TODO fix this
|
entityData.setInteger("z", entityData.getInteger("z") - zMin);
|
||||||
/**
|
tileEntities.appendTag(entityData);
|
||||||
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);
|
|
||||||
}
|
|
||||||
**/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Write NBT tags for schematic file
|
||||||
NBTTagCompound schematicTag = new NBTTagCompound("Schematic");
|
NBTTagCompound schematicTag = new NBTTagCompound("Schematic");
|
||||||
|
|
||||||
schematicTag.setShort("Width", width);
|
schematicTag.setShort("Width", width);
|
||||||
@@ -514,14 +509,15 @@ public class DungeonHelper
|
|||||||
schematicTag.setByteArray("Data", blockData);
|
schematicTag.setByteArray("Data", blockData);
|
||||||
|
|
||||||
schematicTag.setTag("Entities", new NBTTagList());
|
schematicTag.setTag("Entities", new NBTTagList());
|
||||||
schematicTag.setTag("TileEntities", new NBTTagList());
|
schematicTag.setTag("TileEntities", tileEntities);
|
||||||
schematicTag.setString("Material", "Alpha");
|
schematicTag.setString("Materials", "Alpha");
|
||||||
|
|
||||||
if (addBlocks != null)
|
if (addBlocks != null)
|
||||||
{
|
{
|
||||||
schematicTag.setByteArray("AddBlocks", addBlocks);
|
schematicTag.setByteArray("AddBlocks", addBlocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Write schematic data to a file
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
FileOutputStream outputStream = new FileOutputStream(new File(exportPath));
|
FileOutputStream outputStream = new FileOutputStream(new File(exportPath));
|
||||||
|
|||||||
Reference in New Issue
Block a user