NBT tags don't register on item

Discussion in 'Plugin Development' started by Mr. Sandwich, Oct 30, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    Mr. Sandwich

    Hey so I coded a constructor class to make special items and I added a method to add a NBT tag to the item but it's not working at all for some reason and I can't figure out why, here's the code(Note: the modifiers list is defined somewhere else but I tried defining it in the method and have a mention of it only in the method but it still doesn't work)
    Code:
        public void addNBTTag(String name, double amount, String slot) {
            net.minecraft.server.v1_7_R4.ItemStack nmsStack = CraftItemStack.asNMSCopy(this.item);
            NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
            if (name == "Unbreakable")
                compound.set("Unbreakable", new NBTTagByte((byte) 1));
            else {
                plugin.getServer().broadcastMessage("TEST");//It get here and broadcasts TEST
                NBTTagCompound attribute = new NBTTagCompound();
                attribute.set("AttributeName", new NBTTagString(name)); //Examples: "generic.attribute", "generic.maxHealth", "generic.movementSpeed", "generic.armor", "generic.followRange", "generic.knockbackResistance".
                attribute.set("Name", new NBTTagString(name));
                attribute.set("Amount", new NBTTagDouble(amount));
                attribute.set("Operation", new NBTTagInt(0));
                attribute.set("UUIDLeast", new NBTTagInt(894654));
                attribute.set("UUIDMost", new NBTTagInt(2872));
                if (slot != null)
                    attribute.set("Slot", new NBTTagString(slot));
                modifiers.add(attribute);
                compound.set("AttributeModifiers", modifiers);
            }
            nmsStack.setTag(compound);
            this.item = CraftItemStack.asBukkitCopy(nmsStack);
        }
    
    Can someone tell me what's the problem? Thanks in advance.
     
  2. Offline

    MightyOne

    Do you get any error message in the console?
     
  3. Offline

    Mr. Sandwich

    No
     
Thread Status:
Not open for further replies.

Share This Page