Solved How can I set the attack damage/protection values of any item?

Discussion in 'Spigot Plugin Development' started by Hibbix, Jan 28, 2021.

Thread Status:
Not open for further replies.
  1. Hello!
    I am trying to create custom items that deal custom damage, or give certain armor points when worn.
    I know I probably need to do it through AttributeModifiers, but there is only ADD and MULTIPLY (i think)

    Is there a way to precisely set the attack damage/protection values of items?

    Thank you :‎)
  2. This is a little janky, but if you want to set the attack damage of a certain item, you could write a listener for EntityDamageByEntityEvent, then check that the entity doing the damage is a player, and that the item they are holding is the item you want to modify, then use event.setDamage() to set the damage.

    As far as I know, attribute modifiers are the only way to attach this information to an itemstack in such a way that it works without listeners (and even if your plugin is uninstalled). You can probably use the answer here ( to get the current damage from the item the player is holding.
  3. Im sure this is not the way. I'm also not entirely sure how they work, but an idea, multiply by 0 then add your value
  4. Thank you, I will try this tomorrow.
    Fingers crossed! :)
  5. Changing attribute modifiers automatically replaces the default values. So just work with "add" as a "set" .
    • Informative Informative x 1
  6. Are you sure? I just checked the wiki and it said that using the ADD operation does indeed add to the damage. Your method would work for anything that doesn't do attack damage by default (basically everything that isn't a tool/sword), but if I wanted to use a Netherite sword and cause it to do 4 damage, it would just add to it.
  7. Well not sure how it would behave but you can alwyas try to add negative values (-4) to reset it
  8. Get default value of attribute modifier, and then:toadd=custom-default
  9. Sorry this is my first time working with AttributeModifiers, how do I get the default of an item?
  10. Did this solution not yield any results?
    • Like Like x 1
    • Winner Winner x 1
  11. Thank you so much for your help, marking as solved.
Thread Status:
Not open for further replies.