Jump to content

[1.7.10] NBT Compound tags?


iWasHere

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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));
                        }
                    }
                }
            }

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.

Announcements



×
×
  • Create New...

Important Information

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