public class Schem {
public static void paste(Location start, File file)
throws IOException {
CompoundNBT schem = CompressedStreamTools.readCompressed(new FileInputStream(file));
CompoundNBT meta = schem.getCompound("Metadata");
Location pos = start
.add(new Vector(meta.getInt("WEOffsetX"), meta.getInt("WEOffsetY"), meta.getInt("WEOffsetZ")));
byte[] blockData = schem.getByteArray("BlockData");
CompoundNBT palette = schem.getCompound("Palette");
Map<Integer, String> paletteMap = new HashMap<Integer, String>();
for (String set : palette.keySet()) {
paletteMap.put(palette.getInt(set), set);
}
ListNBT blockEntities = schem.getList("BlockEntities", 10);
int i = 0;
// set block
for (int y = 0; y < schem.getShort("Height"); ++y) {
for (int z = 0; z < schem.getShort("Length"); ++z) {
for (int x = 0; x < schem.getShort("Width"); ++x) {
BlockData data = Bukkit.createBlockData(paletteMap.get((int) blockData[i]));
pos.getWorld().getBlockAt(pos.getBlockX() + x, pos.getBlockY() + y, pos.getBlockZ() + z)
.setBlockData(data);
i++;
}
}
}
// set inventory
for (INBT inbt : blockEntities) {
CompoundNBT blockEntity = (CompoundNBT) inbt;
int[] Pos = blockEntity.getIntArray("Pos");
for (INBT inbt2 : blockEntity.getList("Items", 10)) {
CompoundNBT stack = (CompoundNBT) inbt2;
Block block = pos.getWorld().getBlockAt(pos.getBlockX() + Pos[0], pos.getBlockY() + Pos[1],
pos.getBlockZ() + Pos[2]);
BlockState state = block.getState();
ItemStack item = SchemNMS.getItemStack(stack);
if (state instanceof Container) {
Container container = (Container) state;
container.getSnapshotInventory().setItem(stack.getInt("Slot"), item);
state.update();
}
}
}
}
}