Search in sources :

Example 11 with NBTTagByte

use of net.minecraft.nbt.NBTTagByte in project BuildCraft by BuildCraft.

the class NbtSquishMap method addTag.

public void addTag(NBTBase nbt) {
    if (nbt instanceof NBTTagString) {
        String val = ((NBTTagString) nbt).getString();
        if (!strings.contains(val)) {
            strings.add(val);
        }
    } else if (nbt instanceof NBTTagByte) {
        byte val = ((NBTTagByte) nbt).getByte();
        if (!bytes.contains(val)) {
            bytes.add(val);
        }
    } else if (nbt instanceof NBTTagShort) {
        short val = ((NBTTagShort) nbt).getShort();
        if (!shorts.contains(val)) {
            shorts.add(val);
        }
    } else if (nbt instanceof NBTTagInt) {
        int val = ((NBTTagInt) nbt).getInt();
        if (!ints.contains(val)) {
            ints.add(val);
        }
    } else if (nbt instanceof NBTTagLong) {
        long val = ((NBTTagLong) nbt).getLong();
        if (!longs.contains(val)) {
            longs.add(val);
        }
    } else if (nbt instanceof NBTTagFloat) {
        float val = ((NBTTagFloat) nbt).getFloat();
        if (!floats.contains(val)) {
            floats.add(val);
        }
    } else if (nbt instanceof NBTTagDouble) {
        double val = ((NBTTagDouble) nbt).getDouble();
        if (!doubles.contains(val)) {
            doubles.add(val);
        }
    } else if (nbt instanceof NBTTagByteArray) {
        byte[] val = ((NBTTagByteArray) nbt).getByteArray();
        TByteArrayList array = new TByteArrayList(val);
        if (!byteArrays.contains(array)) {
            byteArrays.add(array);
        }
    } else if (nbt instanceof NBTTagIntArray) {
        int[] val = ((NBTTagIntArray) nbt).getIntArray();
        TIntArrayList array = new TIntArrayList(val);
        if (!intArrays.contains(array)) {
            intArrays.add(array);
        }
    } else if (nbt instanceof NBTTagList) {
        NBTTagList list = (NBTTagList) nbt;
        if (!complex.contains(list)) {
            for (int i = 0; i < list.tagCount(); i++) {
                addTag(list.get(i));
            }
            complex.add(list);
        }
    } else if (nbt instanceof NBTTagCompound) {
        NBTTagCompound compound = (NBTTagCompound) nbt;
        if (!complex.contains(compound)) {
            for (String key : compound.getKeySet()) {
                if (!strings.contains(key)) {
                    strings.add(key);
                }
                addTag(compound.getTag(key));
            }
            complex.add(compound);
        }
    } else {
        throw new IllegalArgumentException("Cannot handle tag " + nbt);
    }
}
Also used : NBTTagFloat(net.minecraft.nbt.NBTTagFloat) TByteArrayList(gnu.trove.list.array.TByteArrayList) NBTTagInt(net.minecraft.nbt.NBTTagInt) NBTTagByte(net.minecraft.nbt.NBTTagByte) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString) TIntArrayList(gnu.trove.list.array.TIntArrayList) NBTTagIntArray(net.minecraft.nbt.NBTTagIntArray) NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagShort(net.minecraft.nbt.NBTTagShort) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagByteArray(net.minecraft.nbt.NBTTagByteArray) NBTTagLong(net.minecraft.nbt.NBTTagLong) NBTTagDouble(net.minecraft.nbt.NBTTagDouble)

Example 12 with NBTTagByte

use of net.minecraft.nbt.NBTTagByte in project BuildCraft by BuildCraft.

the class NbtSquishMap method indexOfTag.

public int indexOfTag(NBTBase nbt) {
    int offset = 0;
    if (nbt instanceof NBTTagByte) {
        return bytes.indexOf(((NBTTagByte) nbt).getByte());
    } else {
        offset += bytes.size();
    }
    if (nbt instanceof NBTTagShort) {
        return offset + shorts.indexOf(((NBTTagShort) nbt).getShort());
    } else {
        offset += shorts.size();
    }
    if (nbt instanceof NBTTagInt) {
        return offset + ints.indexOf(((NBTTagInt) nbt).getInt());
    } else {
        offset += ints.size();
    }
    if (nbt instanceof NBTTagLong) {
        return offset + longs.indexOf(((NBTTagLong) nbt).getLong());
    } else {
        offset += longs.size();
    }
    if (nbt instanceof NBTTagFloat) {
        return offset + floats.indexOf(((NBTTagFloat) nbt).getFloat());
    } else {
        offset += floats.size();
    }
    if (nbt instanceof NBTTagDouble) {
        return offset + doubles.indexOf(((NBTTagDouble) nbt).getDouble());
    } else {
        offset += doubles.size();
    }
    if (nbt instanceof NBTTagByteArray) {
        byte[] val = ((NBTTagByteArray) nbt).getByteArray();
        TByteArrayList array = new TByteArrayList(val);
        return offset + byteArrays.indexOf(array);
    } else {
        offset += byteArrays.size();
    }
    if (nbt instanceof NBTTagIntArray) {
        int[] val = ((NBTTagIntArray) nbt).getIntArray();
        TIntArrayList array = new TIntArrayList(val);
        return offset + intArrays.indexOf(array);
    } else {
        offset += intArrays.size();
    }
    if (nbt instanceof NBTTagString) {
        return offset + strings.indexOf(((NBTTagString) nbt).getString());
    } else {
        offset += strings.size();
    }
    if (nbt instanceof NBTTagList) {
        return offset + complex.indexOf(nbt);
    } else if (nbt instanceof NBTTagCompound) {
        return offset + complex.indexOf(nbt);
    }
    throw new IllegalArgumentException("Cannot handle tag " + nbt);
}
Also used : NBTTagFloat(net.minecraft.nbt.NBTTagFloat) TByteArrayList(gnu.trove.list.array.TByteArrayList) NBTTagInt(net.minecraft.nbt.NBTTagInt) NBTTagByte(net.minecraft.nbt.NBTTagByte) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) TIntArrayList(gnu.trove.list.array.TIntArrayList) NBTTagIntArray(net.minecraft.nbt.NBTTagIntArray) NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagShort(net.minecraft.nbt.NBTTagShort) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagByteArray(net.minecraft.nbt.NBTTagByteArray) NBTTagLong(net.minecraft.nbt.NBTTagLong) NBTTagDouble(net.minecraft.nbt.NBTTagDouble)

Example 13 with NBTTagByte

use of net.minecraft.nbt.NBTTagByte in project BuildCraft by BuildCraft.

the class NBTUtilBC method readEnumSet.

public static <E extends Enum<E>> EnumSet<E> readEnumSet(NBTBase tag, Class<E> clazz) {
    E[] constants = clazz.getEnumConstants();
    if (constants == null)
        throw new IllegalArgumentException("Not an enum type " + clazz);
    byte[] bytes;
    if (tag instanceof NBTTagByte) {
        bytes = new byte[] { ((NBTTagByte) tag).getByte() };
    } else if (tag instanceof NBTTagByteArray) {
        bytes = ((NBTTagByteArray) tag).getByteArray();
    } else {
        bytes = new byte[] {};
        BCLog.logger.warn("[lib.nbt] Tried to read an enum set from " + tag);
    }
    BitSet bitset = BitSet.valueOf(bytes);
    EnumSet<E> set = EnumSet.noneOf(clazz);
    for (E e : constants) {
        if (bitset.get(e.ordinal())) {
            set.add(e);
        }
    }
    return set;
}
Also used : NBTTagByte(net.minecraft.nbt.NBTTagByte) BitSet(java.util.BitSet) NBTTagByteArray(net.minecraft.nbt.NBTTagByteArray)

Aggregations

NBTTagByte (net.minecraft.nbt.NBTTagByte)13 NBTTagByteArray (net.minecraft.nbt.NBTTagByteArray)10 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)10 NBTTagList (net.minecraft.nbt.NBTTagList)9 NBTTagString (net.minecraft.nbt.NBTTagString)9 NBTTagDouble (net.minecraft.nbt.NBTTagDouble)8 NBTTagFloat (net.minecraft.nbt.NBTTagFloat)8 NBTTagInt (net.minecraft.nbt.NBTTagInt)8 NBTTagIntArray (net.minecraft.nbt.NBTTagIntArray)8 NBTTagLong (net.minecraft.nbt.NBTTagLong)8 NBTTagShort (net.minecraft.nbt.NBTTagShort)7 NBTBase (net.minecraft.nbt.NBTBase)5 Map (java.util.Map)4 List (java.util.List)3 TByteArrayList (gnu.trove.list.array.TByteArrayList)2 TIntArrayList (gnu.trove.list.array.TIntArrayList)2 ArrayList (java.util.ArrayList)2 BitSet (java.util.BitSet)2 HashMap (java.util.HashMap)2 Entry (java.util.Map.Entry)2