Posted January 30, 20169 yr I have an item that has a one slot inventory. I would like to write NBT to the item based on the item in the inventory. How would I do so?
January 30, 20169 yr If I understand you: ItemStack represents some container item (e.g: backpack) with one slot for another item. Container (backpack) item stores its content (that one item) inside its NBT using primitives. So if you want to change container item OR the item within based on item within, you need to read it. You can either do something like: ItemStack itemWithin = ItemStack.loadItemStackFromNBT(nbtOfContainerItem.getTag("itemWithin")); And then operate on it. Or you can operate on ItemStack within without recreating it (so basically operate on raw data). 1.7.10 is no longer supported by forge, you are on your own.
January 31, 20169 yr You can create an NBT for the inner item (the one inside the backpack) and then save that NBT as an entry in the outer item (backpack) NBT. Let me show you an example of what I'm thinking: public static void SaveBackpack(ItemStack backpack, ItemStack item) { if (stack != null && stack.hasTagCompound() && item != null && item.hasTagCompound()) { stack.getTagCompound().setTag("backpackItems", NBTBase.createNewByType((byte)10)); NBTTagCompound backpackItems = extendedProperties.getCompoundTag("backpackItems"); backpackItems = item.getTagCompound(); } } This code would save the NBT of an item to the NBT of the backpack. I believe you were looking for a way to save NBT subtags, this is the way to do it. Hope this helps, feel free to try it out and let us know if it worked. I still haven't published a mod because I can never get that in-dev version just right to warrant a public release. And yes, after two years of mod development I am still learning to speak Java. Follow me on GitHub: https://github.com/yooksi Contact me on Twitter: https://twitter.com/yooksi Read my Minecraft blog: https://yooksidoesminecraft.blogspot.de/
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.