Solved NMS Nbt tags, Attack Damage

Discussion in 'Plugin Development' started by 87pen, Nov 20, 2015.

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

    87pen

    I have been looking to introduce myself to the world of NMS so I decided to look at something that always interested me. NBT tags, I found this:
    Code:
           ItemStack i = new ItemStack(Material.IRON_SWORD);
    
            net.minecraft.server.v1_8_R1.ItemStack stack = CraftItemStack.asNMSCopy(i);
            NBTTagCompound tag = stack.hasTag() ? stack.getTag() : new NBTTagCompound();
          
            tag.set("Unbreakable", new NBTTagByte((byte)1));
            stack.setTag(tag);
    
            i = CraftItemStack.asBukkitCopy(stack);
    
            p.getInventory().addItem(i);
    Which uses NMS and Nbt to add unbreakable to the sword so it never loses durability. But I was wondering on how I would access and modify the items attack damage. The NBT tag that displays on the item as +# Attack Damage. I was wondering if someone could point me in the direction to learn how to or rather give me an example or idea on how to.

    EDIT: found out how to do it. For those who are curious it is this:
    Code:
                    ItemStack i = new ItemStack(Material.IRON_SWORD);
          
                net.minecraft.server.v1_8_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(i);
                NBTTagCompound compound = nmsStack.getTag();
                if (compound == null) {
                   compound = new NBTTagCompound();
                    nmsStack.setTag(compound);
                    compound = nmsStack.getTag();
                }
                NBTTagList modifiers = new NBTTagList();
                NBTTagCompound damage = new NBTTagCompound();
                damage.set("AttributeName", new NBTTagString("generic.attackDamage"));
                damage.set("Name", new NBTTagString("generic.attackDamage"));
                damage.set("Amount", new NBTTagInt(20));
                damage.set("Operation", new NBTTagInt(0));
                damage.set("UUIDLeast", new NBTTagInt(894654));
                damage.set("UUIDMost", new NBTTagInt(2872));
                modifiers.add(damage);
                compound.set("AttributeModifiers", modifiers);
                nmsStack.setTag(compound);
                i = CraftItemStack.asBukkitCopy(nmsStack);
              
                    p.getInventory().addItem(i);
     
    Last edited: Nov 20, 2015
  2. Offline

    RoboticPlayer

    @87pen If this is now solved, please mark it as so.
     
Thread Status:
Not open for further replies.

Share This Page