Implemented Importing and Exporting Tile Entities; Additional Improvements #41

Merged
SenseiKiwi merged 15 commits from master into master 2013-07-15 22:08:53 +00:00
Showing only changes of commit d23198c4fa - Show all commits

View File

@@ -38,6 +38,7 @@ public class DungeonHelper
public static final String SCHEMATIC_FILE_EXTENSION = ".schematic"; public static final String SCHEMATIC_FILE_EXTENSION = ".schematic";
private static final int DEFAULT_DUNGEON_WEIGHT = 100; private static final int DEFAULT_DUNGEON_WEIGHT = 100;
public static final int MAX_DUNGEON_WEIGHT = 10000; //Used to prevent overflows and math breaking down 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 HUB_DUNGEON_TYPE = "Hub";
private static final String TRAP_DUNGEON_TYPE = "Trap"; private static final String TRAP_DUNGEON_TYPE = "Trap";
@@ -375,75 +376,74 @@ public class DungeonHelper
registeredDungeons.addAll(hubs); 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 xMin, yMin, zMin;
int yMin; int xMax, yMax, zMax;
int zMin; int xStart, yStart, zStart;
int xEnd, yEnd, zEnd;
int xMax; //Find the smallest bounding box that contains all non-air blocks within a max radius around the player.
int yMax; xMax = yMax = zMax = Integer.MIN_VALUE;
int zMax; xMin = yMin = zMin = Integer.MAX_VALUE;
xMin=xMax=xI; xStart = centerX - MAX_EXPORT_RADIUS;
yMin=yMax=yI; zStart = centerZ - MAX_EXPORT_RADIUS;
zMin=zMax=zI; yStart = Math.max(centerY - MAX_EXPORT_RADIUS, 0);
for (int count = 0; count < 50; count++) 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--; 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;
} }
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++;
} }
} }
short width =(short) (xMax-xMin); //Export all the blocks within our selected bounding box
short height= (short) (yMax-yMin); short width = (short) (xMax - xMin + 1);
short length= (short) (zMax-zMin); short height = (short) (yMax - yMin + 1);
short length = (short) (zMax - zMin + 1);
//ArrayList<NBTTagCompound> tileEntities = new ArrayList<NBTTagCompound>(); ArrayList<CompoundTag> tileEntities = new ArrayList<CompoundTag>();
ArrayList<Tag> tileEntites = new ArrayList<Tag>();
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];
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 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 meta= world.getBlockMetadata(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; blocks[index] = (byte) blockID;
blockData[index] = (byte) meta; blockData[index] = (byte) metadata;
if (Block.blocksList[blockID] instanceof BlockContainer) if (Block.blocksList[blockID] instanceof BlockContainer)
{ {
@@ -486,15 +486,6 @@ public class DungeonHelper
} }
} }
} }
/**
*
* nbtdata.setShort("Width", width);
nbtdata.setShort("Height", height);
nbtdata.setShort("Length", length);
nbtdata.setByteArray("Blocks", blocks);
nbtdata.setByteArray("Data", blockData);
*/
HashMap<String, Tag> schematic = new HashMap<String, Tag>(); HashMap<String, Tag> schematic = new HashMap<String, Tag>();
@@ -504,7 +495,7 @@ public class DungeonHelper
schematic.put("Width", new ShortTag("Width", (short) width)); schematic.put("Width", new ShortTag("Width", (short) width));
schematic.put("Length", new ShortTag("Length", (short) length)); schematic.put("Length", new ShortTag("Length", (short) length));
schematic.put("Height", new ShortTag("Height", (short) height)); 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) if (addBlocks != null)
{ {