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