use of net.minecraft.nbt.NBTTagIntArray 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.NBTTagIntArray 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.NBTTagIntArray in project BetterQuesting by Funwayguy.
the class QuestInstance method writeToJson_Config.
private NBTTagCompound writeToJson_Config(NBTTagCompound jObj) {
jObj.setTag("properties", qInfo.writeToNBT(new NBTTagCompound(), EnumSaveType.CONFIG));
jObj.setTag("tasks", tasks.writeToNBT(new NBTTagList(), EnumSaveType.CONFIG));
jObj.setTag("rewards", rewards.writeToNBT(new NBTTagList(), EnumSaveType.CONFIG));
int[] reqArr = new int[preRequisites.size()];
for (int i = 0; i < preRequisites.size(); i++) {
reqArr[i] = parentDB.getKey(preRequisites.get(i));
}
jObj.setTag("preRequisites", new NBTTagIntArray(reqArr));
return jObj;
}
use of net.minecraft.nbt.NBTTagIntArray in project BetterQuesting by Funwayguy.
the class ItemComparison method CompareNBTTag.
public static boolean CompareNBTTag(NBTBase tag1, NBTBase tag2, boolean partial) {
if ((tag1 == null && tag2 != null) || (tag1 != null && tag2 == null)) {
return false;
} else if (tag1 == null && tag2 == null) {
return true;
}
if (tag1 instanceof NBTTagCompound && tag2 instanceof NBTTagCompound) {
return CompareNBTTagCompound((NBTTagCompound) tag1, (NBTTagCompound) tag2, partial);
} else if (tag1 instanceof NBTTagList && tag2 instanceof NBTTagList) {
NBTTagList list1 = (NBTTagList) tag1;
NBTTagList list2 = (NBTTagList) tag2;
if (list1.tagCount() > list2.tagCount() || (!partial && list1.tagCount() != list2.tagCount())) {
// Sample is missing requested tags or is not exact
return false;
}
topLoop: for (int i = 0; i < list1.tagCount(); i++) {
NBTBase lt1 = list1.getCompoundTagAt(i);
for (int j = 0; j < list2.tagCount(); j++) {
if (CompareNBTTag(lt1, list2.getCompoundTagAt(j), partial)) {
continue topLoop;
}
}
// Couldn't find requested tag in list
return false;
}
} else if (tag1 instanceof NBTTagIntArray && tag2 instanceof NBTTagIntArray) {
NBTTagIntArray list1 = (NBTTagIntArray) tag1;
NBTTagIntArray list2 = (NBTTagIntArray) tag2;
if (list1.getIntArray().length > list2.getIntArray().length || (!partial && list1.getIntArray().length != list2.getIntArray().length)) {
// Sample is missing requested tags or is not exact
return false;
}
topLoop: for (int i = 0; i < list1.getIntArray().length; i++) {
for (int j = 0; j < list2.getIntArray().length; j++) {
if (list1.getIntArray()[i] == list2.getIntArray()[j]) {
continue topLoop;
}
}
// Couldn't find requested integer in list
return false;
}
return false;
} else if (tag1 instanceof NBTTagByteArray && tag2 instanceof NBTTagByteArray) {
NBTTagByteArray list1 = (NBTTagByteArray) tag1;
NBTTagByteArray list2 = (NBTTagByteArray) tag2;
if (list1.getByteArray().length > list2.getByteArray().length || (!partial && list1.getByteArray().length != list2.getByteArray().length)) {
// Sample is missing requested tags or is not exact
return false;
}
// Duplicate control
ArrayList<Integer> usedIdxs = new ArrayList<Integer>();
topLoop: for (int i = 0; i < list1.getByteArray().length; i++) {
for (int j = 0; j < list2.getByteArray().length; j++) {
if (usedIdxs.contains(j)) {
continue;
} else if (list1.getByteArray()[i] == list2.getByteArray()[j]) {
usedIdxs.add(j);
continue topLoop;
}
}
// Couldn't find requested integer in list
return false;
}
return false;
} else if (tag1 instanceof NBTTagString && tag2 instanceof NBTTagString) {
return tag1.equals(tag2);
} else if (// Standardize numbers to not care about format
tag1 instanceof NBTPrimitive && tag2 instanceof NBTPrimitive) {
Number num1 = NBTConverter.getNumber(tag1);
Number num2 = NBTConverter.getNumber(tag2);
// Second number will be cast to the requested number format
if (tag1 instanceof NBTTagFloat || tag1 instanceof NBTTagDouble) {
return num1.doubleValue() == num2.doubleValue();
} else {
return num1.longValue() == num2.longValue();
}
} else {
return tag1.equals(tag2);
}
return true;
}
use of net.minecraft.nbt.NBTTagIntArray in project pnc-repressurized by TeamPneumatic.
the class JsonToNBTConverter method getTag.
private NBTTagCompound getTag(JsonObject object) {
NBTTagCompound nbt = new NBTTagCompound();
for (Map.Entry<String, JsonElement> entry : object.entrySet()) {
JsonObject keyObject = entry.getValue().getAsJsonObject();
int type = keyObject.get("type").getAsInt();
JsonElement element = keyObject.get("value");
switch(type) {
case 1:
nbt.setByte(entry.getKey(), (byte) element.getAsDouble());
break;
case 2:
nbt.setShort(entry.getKey(), (short) element.getAsDouble());
case 3:
nbt.setInteger(entry.getKey(), (int) element.getAsDouble());
break;
case 4:
nbt.setLong(entry.getKey(), (long) element.getAsDouble());
break;
case 5:
nbt.setFloat(entry.getKey(), (float) element.getAsDouble());
break;
case 6:
nbt.setDouble(entry.getKey(), element.getAsDouble());
break;
// break;
case 8:
nbt.setString(entry.getKey(), element.getAsString());
break;
case 9:
JsonArray array = element.getAsJsonArray();
NBTTagList tagList = new NBTTagList();
for (JsonElement e : array) {
tagList.appendTag(getTag(e.getAsJsonObject()));
}
nbt.setTag(entry.getKey(), tagList);
break;
case 10:
nbt.setTag(entry.getKey(), getTag(element.getAsJsonObject()));
break;
case 11:
array = element.getAsJsonArray();
int[] intArray = new int[array.size()];
for (int i = 0; i < array.size(); i++) {
intArray[i] = array.get(i).getAsInt();
}
nbt.setTag(entry.getKey(), new NBTTagIntArray(intArray));
break;
default:
throw new IllegalArgumentException("NBT type no " + type + " is not supported by the Json to NBT converter!");
}
}
return nbt;
}
Aggregations