1.12.2 ItemStack NBT Tags

Discussion in 'Spigot Plugin Development' started by jusjus112, Jan 15, 2021.

  1. Hi Guys,

    I have some trouble using NBT tags with item stacks.
    I am setting the NBT tags, like this:

    Code (Java):
        public ItemStack build(){
            if (getType() == Material.AIR){
                return this;
            }
            if (this.itemMeta != null) {
                this.itemMeta.setLore(this.lore);
                setItemMeta(this.itemMeta);
            }

            if (this.isNBTItem()){
                net.minecraft.server.v1_12_R1.ItemStack nmsStack = CraftItemStack
                    .asNMSCopy(this);
                nmsStack.setTag(this.synergyNBTCompound);
                debug(nmsStack.getName()+" = NAME");

                ItemStack item = CraftItemStack.asBukkitCopy(nmsStack);
                debug(item.getItemMeta()+" = ITEMMETA");
                this.setItemMeta(item.getItemMeta());

            }
            return this;
        }
    Code (Text):
    public ItemStack build()
    is a function within a class that extends ItemStack.
    Code (Text):
    his.synergyNBTCompound
    is a class that extends NBTCompound.

    The "nmsStack.setTag(this.synergyNBTCompound);" is setting the tags, synergyNBTCompound is a copy of NBTTagCompound.
    Code (Java):
    public class SynergyNBTCompound extends NBTTagCompound {
    I am getting this debug output:
    Code (Text):
    [DEBUG] UNSPECIFIC_META:{meta-type=UNSPECIFIC, internal=H4sIAAAAAAAAAONiYGBm4ChOzclJTMpJZWBgYGQAAJQotE8TAAAA} = ITEMMETA
    The item doesn't have the created item meta from the item itself.
    And yes, the item meta works fine if I return the item without creating the craftItemStack.

    Hope someone knows what's going on.
     
    #1 jusjus112, Jan 15, 2021
    Last edited: Jan 17, 2021
  2. No one that has any clue?