Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.8.9] Write NBT Between Item and Item Inventory


LogicTechCorp
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.