Search in sources :

Example 1 with TByteArrayList

use of gnu.trove.list.array.TByteArrayList in project BuildCraft by BuildCraft.

the class NbtSquishMapReader method readInternal.

private NbtSquishMap readInternal(DataInput in) throws IOException {
    WrittenType type = WrittenType.readType(in);
    int flags = in.readInt();
    if (isFlag(flags, NbtSquishConstants.FLAG_HAS_BYTES)) {
        int count = readVarInt(in);
        for (int i = 0; i < count; i++) {
            map.bytes.add(in.readByte());
        }
    }
    if (isFlag(flags, NbtSquishConstants.FLAG_HAS_SHORTS)) {
        int count = readVarInt(in);
        for (int i = 0; i < count; i++) {
            map.shorts.add(in.readShort());
        }
    }
    if (isFlag(flags, NbtSquishConstants.FLAG_HAS_INTS)) {
        int count = readVarInt(in);
        for (int i = 0; i < count; i++) {
            map.ints.add(in.readInt());
        }
    }
    if (isFlag(flags, NbtSquishConstants.FLAG_HAS_LONGS)) {
        int count = readVarInt(in);
        for (int i = 0; i < count; i++) {
            map.longs.add(in.readLong());
        }
    }
    if (isFlag(flags, NbtSquishConstants.FLAG_HAS_FLOATS)) {
        int count = readVarInt(in);
        for (int i = 0; i < count; i++) {
            map.floats.add(in.readFloat());
        }
    }
    if (isFlag(flags, NbtSquishConstants.FLAG_HAS_DOUBLES)) {
        int count = readVarInt(in);
        for (int i = 0; i < count; i++) {
            map.doubles.add(in.readDouble());
        }
    }
    if (isFlag(flags, NbtSquishConstants.FLAG_HAS_BYTE_ARRAYS)) {
        int count = readVarInt(in);
        for (int i = 0; i < count; i++) {
            int arraySize = in.readUnsignedShort();
            TByteArrayList list = new TByteArrayList();
            for (int j = 0; j < arraySize; j++) {
                list.add(in.readByte());
            }
            map.byteArrays.add(list);
        }
    }
    if (isFlag(flags, NbtSquishConstants.FLAG_HAS_INT_ARRAYS)) {
        int count = readVarInt(in);
        for (int i = 0; i < count; i++) {
            int arraySize = in.readUnsignedShort();
            TIntArrayList list = new TIntArrayList();
            for (int j = 0; j < arraySize; j++) {
                list.add(in.readInt());
            }
            map.intArrays.add(list);
        }
    }
    if (isFlag(flags, NbtSquishConstants.FLAG_HAS_STRINGS)) {
        int count = readVarInt(in);
        for (int i = 0; i < count; i++) {
            int length = in.readUnsignedShort();
            byte[] bytes = new byte[length];
            in.readFully(bytes);
            map.strings.add(new String(bytes, StandardCharsets.UTF_8));
        }
    }
    if (isFlag(flags, NbtSquishConstants.FLAG_HAS_COMPLEX)) {
        int count = readVarInt(in);
        for (int i = 0; i < count; i++) {
            int complexType = in.readUnsignedByte();
            if (complexType == NbtSquishConstants.COMPLEX_COMPOUND) {
                map.complex.add(readCompound(type, in));
            } else if (complexType == NbtSquishConstants.COMPLEX_LIST) {
                map.complex.add(readNormalList(type, in));
            } else if (complexType == NbtSquishConstants.COMPLEX_LIST_PACKED) {
                map.complex.add(readPackedList(type, in));
            } else {
                throw new IOException("Unknown complex type " + complexType);
            }
        }
    }
    return map;
}
Also used : TByteArrayList(gnu.trove.list.array.TByteArrayList) IOException(java.io.IOException) TIntArrayList(gnu.trove.list.array.TIntArrayList)

Example 2 with TByteArrayList

use of gnu.trove.list.array.TByteArrayList in project Terasology by MovingBlocks.

the class ChunkSerializer method runLengthEncode8.

private static EntityData.RunLengthEncoding8 runLengthEncode8(TeraArray array) {
    EntityData.RunLengthEncoding8.Builder builder = EntityData.RunLengthEncoding8.newBuilder();
    TByteList values = new TByteArrayList(16384);
    byte lastItem = (byte) array.get(0, 0, 0);
    int counter = 0;
    for (int y = 0; y < array.getSizeY(); ++y) {
        for (int z = 0; z < array.getSizeZ(); ++z) {
            for (int x = 0; x < array.getSizeX(); ++x) {
                byte item = (byte) array.get(x, y, z);
                if (lastItem != item) {
                    builder.addRunLengths(counter);
                    values.add(lastItem);
                    lastItem = item;
                    counter = 1;
                } else {
                    counter++;
                }
            }
        }
    }
    if (lastItem != 0) {
        builder.addRunLengths(counter);
        values.add(lastItem);
    }
    builder.setValues(ByteString.copyFrom(values.toArray()));
    return builder.build();
}
Also used : TByteList(gnu.trove.list.TByteList) TByteArrayList(gnu.trove.list.array.TByteArrayList)

Example 3 with TByteArrayList

use of gnu.trove.list.array.TByteArrayList in project BuildCraft by BuildCraft.

the class RetroGenData method writeToNBT.

@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
    Set<String> allNames = new HashSet<>();
    for (Set<String> used : gennedChunks.values()) {
        allNames.addAll(used);
    }
    TObjectByteHashMap<String> map = new TObjectByteHashMap<>();
    List<String> list = new ArrayList<>(allNames);
    NBTTagList registry = new NBTTagList();
    for (int i = 0; i < list.size(); i++) {
        String name = list.get(i);
        map.put(name, (byte) i);
        registry.appendTag(new NBTTagString(name));
    }
    nbt.setTag("registry", registry);
    NBTTagCompound data = new NBTTagCompound();
    for (Entry<ChunkPos, Set<String>> entry : gennedChunks.entrySet()) {
        String key = serializeChunkPos(entry.getKey());
        Set<String> names = entry.getValue();
        TByteArrayList ids = new TByteArrayList();
        for (String s : names) {
            byte b = map.get(s);
            ids.add(b);
        }
        data.setByteArray(key, ids.toArray());
    }
    nbt.setTag("data", data);
    return nbt;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) TByteArrayList(gnu.trove.list.array.TByteArrayList) TObjectByteHashMap(gnu.trove.map.hash.TObjectByteHashMap) ArrayList(java.util.ArrayList) TByteArrayList(gnu.trove.list.array.TByteArrayList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagString(net.minecraft.nbt.NBTTagString) ChunkPos(net.minecraft.util.math.ChunkPos) HashSet(java.util.HashSet)

Example 4 with TByteArrayList

use of gnu.trove.list.array.TByteArrayList 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 5 with TByteArrayList

use of gnu.trove.list.array.TByteArrayList 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)

Aggregations

TByteArrayList (gnu.trove.list.array.TByteArrayList)6 TIntArrayList (gnu.trove.list.array.TIntArrayList)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 NBTTagList (net.minecraft.nbt.NBTTagList)4 NBTTagString (net.minecraft.nbt.NBTTagString)3 NBTTagByte (net.minecraft.nbt.NBTTagByte)2 NBTTagByteArray (net.minecraft.nbt.NBTTagByteArray)2 NBTTagDouble (net.minecraft.nbt.NBTTagDouble)2 NBTTagFloat (net.minecraft.nbt.NBTTagFloat)2 NBTTagInt (net.minecraft.nbt.NBTTagInt)2 NBTTagIntArray (net.minecraft.nbt.NBTTagIntArray)2 NBTTagLong (net.minecraft.nbt.NBTTagLong)2 NBTTagShort (net.minecraft.nbt.NBTTagShort)2 TByteList (gnu.trove.list.TByteList)1 TDoubleArrayList (gnu.trove.list.array.TDoubleArrayList)1 TFloatArrayList (gnu.trove.list.array.TFloatArrayList)1 TLongArrayList (gnu.trove.list.array.TLongArrayList)1 TShortArrayList (gnu.trove.list.array.TShortArrayList)1 TObjectByteHashMap (gnu.trove.map.hash.TObjectByteHashMap)1 IOException (java.io.IOException)1