@Override public void deserializeNBT(NBTBase nbt) { if (nbt == null) return; // NEW NBT DESERIALIZING if (nbt instanceof NBTTagIntArray) { int[] ia = ((NBTTagIntArray) nbt).getIntArray(); for (int i : ia) received.add(i); } // OLD NBT DESERIALIZING else if (nbt instanceof NBTTagList) { NBTTagList nbtl = (NBTTagList) nbt; for (int i = 0; i < nbtl.tagCount(); i++) { NBTBase nb = nbtl.get(i); if (nb instanceof NBTPrimitive) received.add(((NBTPrimitive) nb).getInt()); } } }
public static Object toLua(NBTBase nbt) { checkNotNull(nbt, "nbt == null!"); if (nbt instanceof NBTPrimitive) return toLua((NBTPrimitive) nbt); if (nbt instanceof NBTTagString) return toLua((NBTTagString) nbt); if (nbt instanceof NBTTagList) return toLua((NBTTagList) nbt); if (nbt instanceof NBTTagCompound) return toLua((NBTTagCompound) nbt); throw new IllegalArgumentException( "Unsupported NBT type for conversion: " + nbt.getClass().getName()); }
public static Number toLua(NBTPrimitive nbt) { checkNotNull(nbt, "nbt == null!"); if (nbt instanceof NBTTagDouble) return ((NBTTagDouble) nbt).getDouble(); if (nbt instanceof NBTTagFloat) return ((NBTTagFloat) nbt).getDouble(); return nbt.getLong(); }
/** * Compare two {@link NBTTagCompound}s for morphing acquiring */ public static boolean compareData(NBTTagCompound a, NBTTagCompound b) { /* Different count of tags? They're different */ if (a.getSize() != b.getSize()) { return false; } for (String key : a.getKeySet()) { NBTBase aTag = a.getTag(key); NBTBase bTag = b.getTag(key); /* Supporting condition for size check above, in case if the size * the same, but different keys are missing */ if (bTag == null) { return false; } /* We check only strings and primitives, lists and compounds aren't * concern of mine */ if (!(aTag instanceof NBTPrimitive) && !(aTag instanceof NBTTagString)) { continue; } if (!aTag.equals(bTag)) { return false; } } return true; }
/** * NBT item loading function with support for stack sizes > 32K */ public static void readItemStacksFromTag(ItemStack[] items, NBTTagList tagList) { for (int i = 0; i < tagList.tagCount(); i++) { NBTTagCompound tag = tagList.getCompoundTagAt(i); int b = tag.getShort("Slot"); items[b] = new ItemStack(tag); if (tag.hasKey("Quantity")) { items[b].setCount(((NBTPrimitive) tag.getTag("Quantity")).getInt()); } } }
public static float getUses(NBTTagCompound tag) { NBTBase value = tag.getTag(TAG_USES); if (value == null) return 0; if (value instanceof NBTPrimitive) return ((NBTPrimitive)value).getFloat(); throw new IllegalStateException("Invalid tag type: " + value); }
@Override public boolean test(NBTPrimitive nbtPrimitive) { return nbtPrimitive instanceof NBTTagFloat && comparisonMode.testFloat(this.getFloat(), nbtPrimitive.getFloat()); }
@Override public boolean test(NBTPrimitive nbtPrimitive) { return nbtPrimitive instanceof NBTTagShort && comparisonMode.testShort(this.getShort(), nbtPrimitive.getShort()); }
@Override public boolean test(NBTPrimitive nbtPrimitive) { return nbtPrimitive instanceof NBTTagLong && comparisonMode.testLong(this.getLong(), nbtPrimitive.getLong()); }
@Override public boolean test(NBTPrimitive nbtPrimitive) { return nbtPrimitive instanceof NBTTagDouble && comparisonMode.testDouble(this.getDouble(), nbtPrimitive.getDouble()); }
@Override public boolean test(NBTPrimitive nbtPrimitive) { return nbtPrimitive instanceof NBTTagByte && comparisonMode.testByte(this.getByte(), nbtPrimitive.getByte()); }
@Override public boolean test(NBTPrimitive nbtPrimitive) { return nbtPrimitive instanceof NBTTagInt && comparisonMode.testInt(this.getInt(), nbtPrimitive.getInt()); }
@Override public void readNBT(Capability<IMunny> capability, IMunny instance, EnumFacing side, NBTBase nbt) { instance.setMunny(((NBTPrimitive)nbt).getInt()); }
@Override public void readNBT(Capability<ICheatMode> capability, ICheatMode instance, EnumFacing side, NBTBase nbt) { instance.setCheatMode(((NBTPrimitive)nbt).getInt() == 1); }
private static boolean hasPrimitive(NBTTagCompound compound, String key) { return compound.hasKey(key) && compound.getTag(key) instanceof NBTPrimitive; }
public boolean test(NBTPrimitive numberTag);