Search in sources :

Example 6 with InvalidFormatException

use of com.sk89q.worldedit.world.storage.InvalidFormatException 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 InvalidFormatException

use of com.sk89q.worldedit.world.storage.InvalidFormatException 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

InvalidFormatException (com.sk89q.worldedit.world.storage.InvalidFormatException)7 BinaryTag (com.sk89q.worldedit.util.nbt.BinaryTag)6 CompoundBinaryTag (com.sk89q.worldedit.util.nbt.CompoundBinaryTag)6 IntBinaryTag (com.sk89q.worldedit.util.nbt.IntBinaryTag)6 ListBinaryTag (com.sk89q.worldedit.util.nbt.ListBinaryTag)4 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)3 ByteBinaryTag (com.sk89q.worldedit.util.nbt.ByteBinaryTag)2 ShortBinaryTag (com.sk89q.worldedit.util.nbt.ShortBinaryTag)2 CompoundTag (com.sk89q.jnbt.CompoundTag)1 IntTag (com.sk89q.jnbt.IntTag)1 ListTag (com.sk89q.jnbt.ListTag)1 ShortTag (com.sk89q.jnbt.ShortTag)1 StringTag (com.sk89q.jnbt.StringTag)1 Tag (com.sk89q.jnbt.Tag)1 BaseEntity (com.sk89q.worldedit.entity.BaseEntity)1