Custom Attribute Modifiers

Discussion in 'Plugin Development' started by Rexe0, Jul 4, 2021.

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

    Rexe0

    Hello,

    I've recently been trying to create custom attributes for items and I have seen a few threads demonstrating this but when I tried this for myself, it ended up with an error.

    Error:
    upload_2021-7-4_20-37-18.png

    Code:
     // Get NMS version
                        net.minecraft.server.v1_16_R3.ItemStack itemStack = CraftItemStack.asNMSCopy(item);
    
                        // Get NBT Tags
                        NBTTagCompound nbt = itemStack.hasTag() ? itemStack.getTag() : new NBTTagCompound();
    
                        // Get all AttributeModifiers in a list
                        NBTTagList modifiers = nbt.getList("AttributeModifiers", 10);
    
                        // Creating new attribute
                        NBTTagCompound attribute = new NBTTagCompound();
                        attribute.setString("AttributeName", "Test");
                        attribute.setString("Name", "attribute.name.Test");
                        attribute.setInt("Amount", 25);
                        attribute.setInt("Operation", 0);
                        attribute.setInt("UUIDLeast", 894654);
                        attribute.setInt("UUIDMost",2872);
                        attribute.setString("Slot","mainhand");
    
                        // Add the new attribute to the list of current ones
                        modifiers.add(attribute);
    
                        // Set the nbt's old modifiers to the new list
                        nbt.set("AttributeModifiers", modifiers);
    
                        // Set the old NBT to the new NBT
                        itemStack.setTag(nbt);
    
                        // Assign the variable the new item
                        item = CraftItemStack.asBukkitCopy(itemStack);
     
  2. Offline

    SmearySubset

    @Rexe0 please direct us to the line in the code that is causing the error
     
  3. Offline

    Rexe0

    It does not print a full stack trace when giving myself the item, nor does it give me the line at which the error is taking place. It only gives me the: 'Unable to create attribute: null.'
     
Thread Status:
Not open for further replies.

Share This Page