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;
}
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();
}
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;
}
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);
}
}
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);
}
Aggregations