Search in sources :

Example 1 with IntBinaryTag

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

the class NbtUtils method getInt.

/**
 * Get an integer from a tag.
 *
 * @param tag the tag to read from
 * @param key the key to look for
 * @return child tag
 * @throws InvalidFormatException if the format of the items is invalid
 * @since TODO
 */
public static int getInt(CompoundBinaryTag tag, String key) throws InvalidFormatException {
    BinaryTag childTag = tag.get(key);
    if (childTag == null) {
        throw new InvalidFormatException("Missing a \"" + key + "\" tag");
    }
    BinaryTagType<?> type = childTag.type();
    if (type == BinaryTagTypes.INT) {
        return ((IntBinaryTag) childTag).intValue();
    }
    if (type == BinaryTagTypes.BYTE) {
        return ((ByteBinaryTag) childTag).intValue();
    }
    if (type == BinaryTagTypes.SHORT) {
        return ((ShortBinaryTag) childTag).intValue();
    }
    throw new InvalidFormatException(key + " tag is not of int, short or byte tag type.");
}
Also used : ShortBinaryTag(com.sk89q.worldedit.util.nbt.ShortBinaryTag) ByteBinaryTag(com.sk89q.worldedit.util.nbt.ByteBinaryTag) BinaryTag(com.sk89q.worldedit.util.nbt.BinaryTag) IntBinaryTag(com.sk89q.worldedit.util.nbt.IntBinaryTag) ByteBinaryTag(com.sk89q.worldedit.util.nbt.ByteBinaryTag) ShortBinaryTag(com.sk89q.worldedit.util.nbt.ShortBinaryTag) CompoundBinaryTag(com.sk89q.worldedit.util.nbt.CompoundBinaryTag) IntBinaryTag(com.sk89q.worldedit.util.nbt.IntBinaryTag) InvalidFormatException(com.sk89q.worldedit.world.storage.InvalidFormatException)

Example 2 with IntBinaryTag

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

the class OldChunk method populateTileEntities.

/**
 * Used to load the tile entities.
 *
 * @throws DataException if there is an error getting the chunk data
 */
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 3 with IntBinaryTag

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

the class PaperweightAdapter method fromNativeBinary.

/**
 * Converts a WorldEdit-native NBT structure to a NMS structure.
 *
 * @param foreign structure to convert
 * @return non-native structure
 */
@Override
public net.minecraft.nbt.Tag fromNativeBinary(BinaryTag foreign) {
    if (foreign == null) {
        return null;
    }
    if (foreign instanceof CompoundBinaryTag) {
        net.minecraft.nbt.CompoundTag tag = new net.minecraft.nbt.CompoundTag();
        for (String key : ((CompoundBinaryTag) foreign).keySet()) {
            tag.put(key, fromNativeBinary(((CompoundBinaryTag) foreign).get(key)));
        }
        return tag;
    } else if (foreign instanceof ByteBinaryTag) {
        return net.minecraft.nbt.ByteTag.valueOf(((ByteBinaryTag) foreign).value());
    } else if (foreign instanceof ByteArrayBinaryTag) {
        return new net.minecraft.nbt.ByteArrayTag(((ByteArrayBinaryTag) foreign).value());
    } else if (foreign instanceof DoubleBinaryTag) {
        return net.minecraft.nbt.DoubleTag.valueOf(((DoubleBinaryTag) foreign).value());
    } else if (foreign instanceof FloatBinaryTag) {
        return net.minecraft.nbt.FloatTag.valueOf(((FloatBinaryTag) foreign).value());
    } else if (foreign instanceof IntBinaryTag) {
        return net.minecraft.nbt.IntTag.valueOf(((IntBinaryTag) foreign).value());
    } else if (foreign instanceof IntArrayBinaryTag) {
        return new net.minecraft.nbt.IntArrayTag(((IntArrayBinaryTag) foreign).value());
    } else if (foreign instanceof LongArrayBinaryTag) {
        return new net.minecraft.nbt.LongArrayTag(((LongArrayBinaryTag) foreign).value());
    } else if (foreign instanceof ListBinaryTag) {
        net.minecraft.nbt.ListTag tag = new net.minecraft.nbt.ListTag();
        ListBinaryTag foreignList = (ListBinaryTag) foreign;
        for (BinaryTag t : foreignList) {
            tag.add(fromNativeBinary(t));
        }
        return tag;
    } else if (foreign instanceof LongBinaryTag) {
        return net.minecraft.nbt.LongTag.valueOf(((LongBinaryTag) foreign).value());
    } else if (foreign instanceof ShortBinaryTag) {
        return net.minecraft.nbt.ShortTag.valueOf(((ShortBinaryTag) foreign).value());
    } else if (foreign instanceof StringBinaryTag) {
        return net.minecraft.nbt.StringTag.valueOf(((StringBinaryTag) foreign).value());
    } else if (foreign instanceof EndBinaryTag) {
        return net.minecraft.nbt.EndTag.INSTANCE;
    } else {
        throw new IllegalArgumentException("Don't know how to make NMS " + foreign.getClass().getCanonicalName());
    }
}
Also used : ListBinaryTag(com.sk89q.worldedit.util.nbt.ListBinaryTag) LongArrayBinaryTag(com.sk89q.worldedit.util.nbt.LongArrayBinaryTag) LongBinaryTag(com.sk89q.worldedit.util.nbt.LongBinaryTag) BinaryTag(com.sk89q.worldedit.util.nbt.BinaryTag) StringBinaryTag(com.sk89q.worldedit.util.nbt.StringBinaryTag) IntBinaryTag(com.sk89q.worldedit.util.nbt.IntBinaryTag) IntArrayBinaryTag(com.sk89q.worldedit.util.nbt.IntArrayBinaryTag) ShortBinaryTag(com.sk89q.worldedit.util.nbt.ShortBinaryTag) ByteArrayBinaryTag(com.sk89q.worldedit.util.nbt.ByteArrayBinaryTag) ListBinaryTag(com.sk89q.worldedit.util.nbt.ListBinaryTag) CompoundBinaryTag(com.sk89q.worldedit.util.nbt.CompoundBinaryTag) EndBinaryTag(com.sk89q.worldedit.util.nbt.EndBinaryTag) DoubleBinaryTag(com.sk89q.worldedit.util.nbt.DoubleBinaryTag) FloatBinaryTag(com.sk89q.worldedit.util.nbt.FloatBinaryTag) ByteBinaryTag(com.sk89q.worldedit.util.nbt.ByteBinaryTag) DoubleBinaryTag(com.sk89q.worldedit.util.nbt.DoubleBinaryTag) EndBinaryTag(com.sk89q.worldedit.util.nbt.EndBinaryTag) ByteBinaryTag(com.sk89q.worldedit.util.nbt.ByteBinaryTag) CompoundBinaryTag(com.sk89q.worldedit.util.nbt.CompoundBinaryTag) ShortBinaryTag(com.sk89q.worldedit.util.nbt.ShortBinaryTag) ByteArrayBinaryTag(com.sk89q.worldedit.util.nbt.ByteArrayBinaryTag) IntBinaryTag(com.sk89q.worldedit.util.nbt.IntBinaryTag) LongBinaryTag(com.sk89q.worldedit.util.nbt.LongBinaryTag) FloatBinaryTag(com.sk89q.worldedit.util.nbt.FloatBinaryTag) IntArrayBinaryTag(com.sk89q.worldedit.util.nbt.IntArrayBinaryTag) StringBinaryTag(com.sk89q.worldedit.util.nbt.StringBinaryTag) LongArrayBinaryTag(com.sk89q.worldedit.util.nbt.LongArrayBinaryTag)

Example 4 with IntBinaryTag

use of com.sk89q.worldedit.util.nbt.IntBinaryTag 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 5 with IntBinaryTag

use of com.sk89q.worldedit.util.nbt.IntBinaryTag 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

BinaryTag (com.sk89q.worldedit.util.nbt.BinaryTag)5 CompoundBinaryTag (com.sk89q.worldedit.util.nbt.CompoundBinaryTag)5 IntBinaryTag (com.sk89q.worldedit.util.nbt.IntBinaryTag)5 ListBinaryTag (com.sk89q.worldedit.util.nbt.ListBinaryTag)4 InvalidFormatException (com.sk89q.worldedit.world.storage.InvalidFormatException)4 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)3 ByteBinaryTag (com.sk89q.worldedit.util.nbt.ByteBinaryTag)2 ShortBinaryTag (com.sk89q.worldedit.util.nbt.ShortBinaryTag)2 ByteArrayBinaryTag (com.sk89q.worldedit.util.nbt.ByteArrayBinaryTag)1 DoubleBinaryTag (com.sk89q.worldedit.util.nbt.DoubleBinaryTag)1 EndBinaryTag (com.sk89q.worldedit.util.nbt.EndBinaryTag)1 FloatBinaryTag (com.sk89q.worldedit.util.nbt.FloatBinaryTag)1 IntArrayBinaryTag (com.sk89q.worldedit.util.nbt.IntArrayBinaryTag)1 LongArrayBinaryTag (com.sk89q.worldedit.util.nbt.LongArrayBinaryTag)1 LongBinaryTag (com.sk89q.worldedit.util.nbt.LongBinaryTag)1 StringBinaryTag (com.sk89q.worldedit.util.nbt.StringBinaryTag)1