1.12.2 NMS NBT Nested Compounds not setting

Discussion in 'Spigot Plugin Development' started by SeanTMG, Apr 2, 2020.

  1. Hello, I don't have that much experience in NMS or NBT data modification but I'm trying to set NBT Data for items, it works fine on the root but trying to set anything like display attributes inside the "display" compound it just doesn't set.

    Here is my code for normally setting data, which works fine:
    Code (Text):
        public void setNBTData(String key, NBTBase data) {
            net.minecraft.server.v1_12_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
            NBTTagCompound itemCompound = (nmsItem.hasTag()) ? nmsItem.getTag() : new NBTTagCompound();
            itemCompound.set(key, data);
            nmsItem.setTag(itemCompound);
            item = CraftItemStack.asBukkitCopy(nmsItem);
        }
    And here's my code for setting data inside the display compound, which doesn't work.
    Code (Text):
        public void setDisplayAttribute(String key, NBTBase data) {
            net.minecraft.server.v1_12_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
            NBTTagCompound itemCompound = (nmsItem.hasTag()) ? nmsItem.getTag() : new NBTTagCompound();
            if (!itemCompound.hasKey("display"))
                itemCompound.set("display", new NBTTagCompound());
            NBTTagCompound display = itemCompound.getCompound("display");
            display.set(key, data);
            itemCompound.set("display", display);
            nmsItem.setTag(itemCompound);
            item = CraftItemStack.asBukkitCopy(nmsItem);
        }
    Any help is appreciated!
     
  2. Update:

    Turns out it sets if the key is something other than display, for example I can set "display1" to a compound of my data, but if I try setting "display", it never sets and is still just the name and lore
    [​IMG]