Separated part of the dungeon-exporting logic into a new class: Schematic. Also created a few classes to implement important operations. Some parts of the original exporting logic are missing now, such as mapping certain blocks to standard IDs. That will be reimplemented in the future. Importing schematics is not supported yet. I need to test what's done so far.
76 lines
1.8 KiB
Java
76 lines
1.8 KiB
Java
package StevenDimDoors.mod_pocketDim.schematic;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
import net.minecraft.nbt.NBTTagList;
|
|
import net.minecraft.tileentity.TileEntity;
|
|
import net.minecraft.world.World;
|
|
|
|
public class WorldCopyOperation extends WorldOperation
|
|
{
|
|
private int originX;
|
|
private int originY;
|
|
private int originZ;
|
|
private int index;
|
|
private short[] blockIDs;
|
|
private byte[] metadata;
|
|
private NBTTagList tileEntities;
|
|
|
|
public WorldCopyOperation()
|
|
{
|
|
super("WorldCopyOperation");
|
|
blockIDs = null;
|
|
metadata = null;
|
|
tileEntities = new NBTTagList();
|
|
}
|
|
|
|
@Override
|
|
protected boolean start(World world, int x, int y, int z, int width, int height, int length)
|
|
{
|
|
index = 0;
|
|
originX = x;
|
|
originY = y;
|
|
originZ = z;
|
|
blockIDs = new short[width * height * length];
|
|
metadata = new byte[width * height * length];
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
protected boolean applyToBlock(World world, int x, int y, int z)
|
|
{
|
|
blockIDs[index] = (short) world.getBlockId(x, y, z);
|
|
metadata[index] = (byte) world.getBlockMetadata(x, y, z);
|
|
|
|
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
|
if (tileEntity != null)
|
|
{
|
|
//Extract tile entity data
|
|
NBTTagCompound tileTag = new NBTTagCompound();
|
|
tileEntity.writeToNBT(tileTag);
|
|
//Translate the tile entity's position from the world's coordinate system
|
|
//to the schematic's coordinate system.
|
|
tileTag.setInteger("x", x - originX);
|
|
tileTag.setInteger("y", y - originY);
|
|
tileTag.setInteger("z", z - originZ);
|
|
tileEntities.appendTag(tileTag);
|
|
}
|
|
index++; //This works assuming the loops in WorldOperation are done in YZX order
|
|
return true;
|
|
}
|
|
|
|
public short[] getBlockIDs()
|
|
{
|
|
return blockIDs;
|
|
}
|
|
|
|
public byte[] getMetadata()
|
|
{
|
|
return metadata;
|
|
}
|
|
|
|
public NBTTagList getTileEntities()
|
|
{
|
|
return tileEntities;
|
|
}
|
|
}
|