Search in sources :

Example 6 with ListBinaryTag

use of com.sk89q.worldedit.util.nbt.ListBinaryTag in project FastAsyncWorldEdit by IntellectualSites.

the class AnvilChunk method populateTileEntities.

/**
 * Used to load the tile entities.
 */
private void populateTileEntities() throws DataException {
    ListBinaryTag tags = NbtUtils.getChildTag(rootTag, "TileEntities", BinaryTagTypes.LIST);
    tileEntities = new HashMap<>();
    for (BinaryTag tag : tags) {
        if (!(tag instanceof CompoundBinaryTag)) {
            throw new InvalidFormatException("CompoundTag expected in TileEntities");
        }
        CompoundBinaryTag t = (CompoundBinaryTag) tag;
        int x = 0;
        int y = 0;
        int z = 0;
        CompoundBinaryTag.Builder values = CompoundBinaryTag.builder();
        for (String key : t.keySet()) {
            BinaryTag value = t.get(key);
            switch(key) {
                case "x":
                    if (value instanceof IntBinaryTag) {
                        x = ((IntBinaryTag) value).value();
                    }
                    break;
                case "y":
                    if (value instanceof IntBinaryTag) {
                        y = ((IntBinaryTag) value).value();
                    }
                    break;
                case "z":
                    if (value instanceof IntBinaryTag) {
                        z = ((IntBinaryTag) value).value();
                    }
                    break;
                default:
                    break;
            }
            values.put(key, value);
        }
        BlockVector3 vec = BlockVector3.at(x, y, z);
        tileEntities.put(vec, values.build());
    }
}
Also used : ListBinaryTag(com.sk89q.worldedit.util.nbt.ListBinaryTag) IntBinaryTag(com.sk89q.worldedit.util.nbt.IntBinaryTag) BinaryTag(com.sk89q.worldedit.util.nbt.BinaryTag) CompoundBinaryTag(com.sk89q.worldedit.util.nbt.CompoundBinaryTag) ListBinaryTag(com.sk89q.worldedit.util.nbt.ListBinaryTag) IntBinaryTag(com.sk89q.worldedit.util.nbt.IntBinaryTag) BlockVector3(com.sk89q.worldedit.math.BlockVector3) InvalidFormatException(com.sk89q.worldedit.world.storage.InvalidFormatException) CompoundBinaryTag(com.sk89q.worldedit.util.nbt.CompoundBinaryTag)

Example 7 with ListBinaryTag

use of com.sk89q.worldedit.util.nbt.ListBinaryTag in project FastAsyncWorldEdit by IntellectualSites.

the class AnvilChunk13 method populateTileEntities.

/**
 * Used to load the tile entities.
 */
private void populateTileEntities() throws DataException {
    tileEntities = new HashMap<>();
    if (rootTag.get("TileEntities") == null) {
        return;
    }
    ListBinaryTag tags = NbtUtils.getChildTag(rootTag, "TileEntities", BinaryTagTypes.LIST);
    for (BinaryTag tag : tags) {
        if (!(tag instanceof CompoundBinaryTag)) {
            throw new InvalidFormatException("CompoundTag expected in TileEntities");
        }
        CompoundBinaryTag t = (CompoundBinaryTag) tag;
        int x = ((IntBinaryTag) t.get("x")).value();
        int y = ((IntBinaryTag) t.get("y")).value();
        int z = ((IntBinaryTag) t.get("z")).value();
        BlockVector3 vec = BlockVector3.at(x, y, z);
        tileEntities.put(vec, t);
    }
}
Also used : ListBinaryTag(com.sk89q.worldedit.util.nbt.ListBinaryTag) IntBinaryTag(com.sk89q.worldedit.util.nbt.IntBinaryTag) CompoundBinaryTag(com.sk89q.worldedit.util.nbt.CompoundBinaryTag) BinaryTag(com.sk89q.worldedit.util.nbt.BinaryTag) ListBinaryTag(com.sk89q.worldedit.util.nbt.ListBinaryTag) IntBinaryTag(com.sk89q.worldedit.util.nbt.IntBinaryTag) BlockVector3(com.sk89q.worldedit.math.BlockVector3) InvalidFormatException(com.sk89q.worldedit.world.storage.InvalidFormatException) CompoundBinaryTag(com.sk89q.worldedit.util.nbt.CompoundBinaryTag)

Aggregations

CompoundBinaryTag (com.sk89q.worldedit.util.nbt.CompoundBinaryTag)7 ListBinaryTag (com.sk89q.worldedit.util.nbt.ListBinaryTag)7 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)5 BinaryTag (com.sk89q.worldedit.util.nbt.BinaryTag)5 IntBinaryTag (com.sk89q.worldedit.util.nbt.IntBinaryTag)5 InvalidFormatException (com.sk89q.worldedit.world.storage.InvalidFormatException)4 BaseEntity (com.sk89q.worldedit.entity.BaseEntity)3 BlockVector2 (com.sk89q.worldedit.math.BlockVector2)2 Location (com.sk89q.worldedit.util.Location)2 DataException (com.sk89q.worldedit.world.DataException)2 Chunk (com.sk89q.worldedit.world.chunk.Chunk)2 MissingChunkException (com.sk89q.worldedit.world.storage.MissingChunkException)2 IOException (java.io.IOException)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 LocalBlockVectorSet (com.fastasyncworldedit.core.math.LocalBlockVectorSet)1 ByteArrayBinaryTag (com.sk89q.worldedit.util.nbt.ByteArrayBinaryTag)1 ByteBinaryTag (com.sk89q.worldedit.util.nbt.ByteBinaryTag)1 DoubleBinaryTag (com.sk89q.worldedit.util.nbt.DoubleBinaryTag)1 EndBinaryTag (com.sk89q.worldedit.util.nbt.EndBinaryTag)1