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've looked absolutely everywhere and I can't find a single answer to my question: how do I add values to compound nbt tags? I can do regular nbt tags like SkullOwner and the such, but not anything under "display", like "Name" or "Lore". How can I access/write to these tags?

Thanks in advance.

Are you doing this on your own custom Item?

Try:

itemstack.stackTagCompound.getString("Lore");

Should work.

I've looked absolutely everywhere and I can't find a single answer to my question: how do I add values to compound nbt tags? I can do regular nbt tags like SkullOwner and the such, but not anything under "display", like "Name" or "Lore". How can I access/write to these tags?

Thanks in advance.

HI

ย 

not sure I understand your question.ย  Could you show your code which works for SkullOwner but not for Display or Name or Lore?

ย 

-TGG

  • Author

Ok, so this works:

ย 

ย  ย  ย  ย  ItemStack head = new ItemStack(Items.skull,1,3);
ย  ย  ย  ย  head.setTagCompound(new NBTTagCompound());
ย  ย  ย  ย  head.stackTagCompound.setString("SkullOwner", "iWasHere");

ย 

BUT if I were to try and set the vanilla "name" tag, the name of the item stays the same in-game. It's because the Name and Lore tags are under the "display" tag, which is a compound tag. Because of that, I can't access the vanilla Name and Lore tags.

ย 

head.stackTagCompound.getCompoundTag("display").setString("Lore","It's special. Oh so special.");

ย 

The above doesn't work. I have no clue how to proceed.

ย 

EDIT: found out that there is a method for setting the display name of an itemstack. Still not sure about the lore though.

It appears Lore is a TagList itself, this is from taking a look at the vanilla code in ItemStack/getTooltip

ย 

ย  ย  ย  ย  ย  ย  if (this.stackTagCompound.hasKey("display", 10))
ย  ย  ย  ย  ย  ย  {
ย  ย  ย  ย  ย  ย  ย  ย  NBTTagCompound nbttagcompound = this.stackTagCompound.getCompoundTag("display");

ย  ย  ย  ย  ย  ย  ย  ย  if (nbttagcompound.hasKey("color", 3))
ย  ย  ย  ย  ย  ย  ย  ย  {
ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  if (p_82840_2_)
ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  {
ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  arraylist.add("Color: #" + Integer.toHexString(nbttagcompound.getInteger("color")).toUpperCase());
ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  }
ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  else
ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  {
ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  arraylist.add(EnumChatFormatting.ITALIC + StatCollector.translateToLocal("item.dyed"));
ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  }
ย  ย  ย  ย  ย  ย  ย  ย  }

ย  ย  ย  ย  ย  ย  ย  ย  if (nbttagcompound.getTagId("Lore") == 9)
ย  ย  ย  ย  ย  ย  ย  ย  {
ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  NBTTagList nbttaglist1 = nbttagcompound.getTagList("Lore", ;

ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  if (nbttaglist1.tagCount() > 0)
ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  {
ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  for (int j = 0; j < nbttaglist1.tagCount(); ++j)
ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  {
ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  arraylist.add(EnumChatFormatting.DARK_PURPLE + "" + EnumChatFormatting.ITALIC + nbttaglist1.getStringTagAt(j));
ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  }
ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  }
ย  ย  ย  ย  ย  ย  ย  ย  }
ย  ย  ย  ย  ย  ย  }

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.