use of net.minecraft.nbt.NBTTagFloat 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.NBTTagFloat 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.NBTTagFloat in project EnderIO by SleepyTrousers.
the class CapacitorHelper method getCapDataRaw.
public static List<Pair<String, Float>> getCapDataRaw(@Nonnull ItemStack stack) {
NBTTagCompound tag = stack.getSubCompound("eiocap");
if (tag == null) {
return null;
}
List<Pair<String, Float>> result = new ArrayList<Pair<String, Float>>();
for (String key : tag.getKeySet()) {
if (key != null && !"level".equals(key) && tag.hasKey(key, (new NBTTagFloat(0)).getId())) {
result.add(Pair.of(key, tag.getFloat(key)));
}
}
return result;
}
use of net.minecraft.nbt.NBTTagFloat in project EnderIO by SleepyTrousers.
the class CapacitorHelper method getNBTCapacitorDataFromItemStack.
@Nullable
protected static ICapacitorData getNBTCapacitorDataFromItemStack(@Nonnull ItemStack stack) {
final NBTTagCompound nbtRoot = stack.getTagCompound();
if (nbtRoot == null) {
return null;
}
if (!nbtRoot.hasKey("eiocap", (new NBTTagCompound()).getId())) {
return null;
}
final NBTTagCompound nbtTag = nbtRoot.getCompoundTag("eiocap");
if (!nbtTag.hasKey("level", (new NBTTagFloat(0)).getId())) {
return null;
}
final float capLevel = nbtTag.getFloat("level");
if (capLevel < 0 || capLevel >= 10) {
return null;
}
return new NBTCapacitorData(stack.getItem().getUnlocalizedName(stack), capLevel, nbtTag);
}
use of net.minecraft.nbt.NBTTagFloat 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