Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

how can I store an ItemStack in an NBT (it's for a tileEntity Inventory). The thing is, is that it's not with a GUI, so I don't want to implement IInventory. Can someone help?

The proud(ish) developer of Ancients

  • Author

Does this allow for the ItemStack to be stored in the NBT of a TileEntity? It looks like you are just setting the NBT for the ItemStack.

The proud(ish) developer of Ancients

In writeToNBT, I'm setting a compound tag with the data from the itemstack, and reading it in readFromNBT.

Check out my mod, Realms of Chaos, here.

 

If I helped you, be sure to press the "Thank You" button!

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.

  • Author

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

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).

 

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.