Jump to content

Storing an ItemStack in NBT


memcallen

Recommended Posts

Why not use IInventory?

Even if you dont use a gui (which is totally missing the point of why people use IInventory) it is still the interface to use when creating a inventory.

it gives compatibility between mods and minecraft hoppers.

 

And if you look in the ItemStack class you can see that there are methods for writing an stack to NBT and methods for loading a stack from NBT.

Use those.

Link to comment
Share on other sites

I found loadItemStackFromNBT() but what is the other function to get an NBT tag from an ItemStack?

 

I don't want to use IInventory mainly because I don't want my mod to be easily automatable with other mods because I will add my own kind of automation, I will probably add a single block to add compatibility instead of having to use autonomus activators (from Thermal Expansion) to interact with my blocks.

The proud(ish) developer of Ancients

Link to comment
Share on other sites

you can get the NBTTagCompound from an ItemStack with the getTagCompound() method. Note that by default an ItemStack does not have an NBTTagCompound so you need to check for that, and create one if null.

 

to load an ItemStack from nbt you need ItemStack.loadItemStackFromNBT(tag).

and to save an ItemStack to nbt you need stack.writeToNBT(tag).

 

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.



×
×
  • Create New...

Important Information

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