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

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?

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.

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.

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.