public static ItemStack compundToItemStack(TagCompound compound) { int id = compound.getAs("id", TagShort.class).getShortData(); int count = compound.getAs("Count", TagByte.class).getByteData(); int damage = compound.getAs("Damage", TagShort.class).getShortData(); ItemStack itemstack = new ItemStack(Item.getById(id), count, damage); if (compound.containsKeyAs("tag", TagCompound.class)) { TagCompound compoundToConvert = compound.get("tag"); itemstack.setTag((NBTTagCompound) compoundToVanillaCompound(compoundToConvert)); } return itemstack; }
public static TagCompound itemStackToCompund(ItemStack itemStack) { TagCompound compound = new TagCompound(); compound.getCompoundData().put("id", new TagShort((short) Item.getId(itemStack.getItem()))); compound.getCompoundData().put("Count", new TagByte((byte) itemStack.count)); compound.getCompoundData().put("Damage", new TagShort((short) itemStack.getData())); if (itemStack.getTag() != null) { compound.getCompoundData().put("tag", vanillaCompoundToCompound(itemStack.getTag())); } return compound; }
public void convert(StoredMyPet pet) { Version fromVersion = Version.v1_7_R4; TagCompound info = pet.getInfo(); if (info.containsKey("Version")) { if (info.containsKeyAs("Version", TagString.class)) { fromVersion = Version.valueOf(info.getAs("Version", TagString.class).getStringData()); } else if (info.containsKeyAs("Version", TagInt.class)) { fromVersion = Version.values()[info.getAs("Version", TagInt.class).getIntData() + 1]; } else { fromVersion = Version.values()[info.getAs("Version", TagShort.class).getShortData()]; } } for (Version v : Version.values()) { if (v.ordinal() <= fromVersion.ordinal()) { continue; } if (v.ordinal() > toVersion.ordinal()) { break; } try { Method m = this.getClass().getDeclaredMethod(v.name(), StoredMyPet.class); m.invoke(this, pet); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { } } } }
return new TagByte(((NBTTagByte) vanillaTag).f()); case 2: return new TagShort(((NBTTagShort) vanillaTag).e()); case 3: return new TagInt(((NBTTagInt) vanillaTag).d());
return new NBTTagInt(((TagInt) tag).getIntData()); case Short: return new NBTTagShort(((TagShort) tag).getShortData()); case String: return new NBTTagString(((TagString) tag).getStringData());