Posted March 24, 201510 yr 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.
March 24, 201510 yr Author Nope, just on a standard ItemStack with a vanilla item (like a stick or something).
March 24, 201510 yr 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
March 24, 201510 yr 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.
March 24, 201510 yr 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.