Search in sources :

Example 1 with BlockStates

use of ivorius.ivtoolkit.blocks.BlockStates in project RecurrentComplex by Ivorforce.

the class SchematicFile method writeToNBT.

public void writeToNBT(NBTTagCompound tagCompound) {
    tagCompound.setString("Materials", "Alpha");
    tagCompound.setShort("Width", width);
    tagCompound.setShort("Height", height);
    tagCompound.setShort("Length", length);
    if (weOriginX != null)
        tagCompound.setShort("WEOriginX", weOriginX);
    if (weOriginY != null)
        tagCompound.setShort("WEOriginY", weOriginY);
    if (weOriginZ != null)
        tagCompound.setShort("WEOriginZ", weOriginZ);
    tagCompound.setByteArray("Data", IvStreams.toByteArray(Stream.of(blockStates).mapToInt(BlockStates::toMetadata)));
    byte[] blockIDs = new byte[blockStates.length];
    byte[] addBlocks = new byte[(blockStates.length + 1) / 2];
    SchematicMapping schematicMapping = new SchematicMapping();
    for (int i = 0; i < blockStates.length; i++) {
        Block block = blockStates[i].getBlock();
        int blockID = getBlockID(block);
        schematicMapping.putBlock(blockID, block);
        blockIDs[i] = (byte) (blockID & 0xff);
        boolean lowerNybble = (i & 1) == 0;
        addBlocks[i >> 1] |= lowerNybble ? (byte) ((blockID >> 8) & 0x0F) : (byte) ((blockID >> 4) & 0xF0);
    }
    tagCompound.setByteArray("Blocks", blockIDs);
    tagCompound.setByteArray("AddBlocks", addBlocks);
    tagCompound.setTag(SchematicMapping.COMPOUND_KEY, schematicMapping.writeToNBT());
    NBTTagList entities = new NBTTagList();
    entityCompounds.forEach(entities::appendTag);
    tagCompound.setTag("Entities", entities);
    NBTTagList tileEntitites = new NBTTagList();
    tileEntityCompounds.forEach(entities::appendTag);
    tagCompound.setTag("TileEntities", tileEntitites);
}
Also used : BlockStates(ivorius.ivtoolkit.blocks.BlockStates) NBTTagList(net.minecraft.nbt.NBTTagList) Block(net.minecraft.block.Block)

Aggregations

BlockStates (ivorius.ivtoolkit.blocks.BlockStates)1 Block (net.minecraft.block.Block)1 NBTTagList (net.minecraft.nbt.NBTTagList)1