use of net.minecraft.nbt.NBTPrimitive 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;
}
Aggregations