Skip to content

ItemAttributeModifierEvent

Invadermonky edited this page Apr 9, 2026 · 1 revision

ItemAttributeModifierEvent

Event - ItemAttributeModifierEvent

This event allows developers to easily add, remove, or modify item attributes dynamically.


Examples

Adding Attribute Modifiers

@SubscribeEvent
public static void onItemAttribute(ItemAttributeModifierEvent event) {
    ItemStack stack = event.getItemStack();
    //Adding +10% Movement speed to golden boots.
    if (stack.getItem() == Items.GOLDEN_BOOTS && event.getSlotType() == EntityEquipmentSlot.FEET) {
        event.addModifier(SharedMonsterAttributes.MOVEMENT_SPEED, new AttributeModifier(
                ATTRIBUTE_TEST_UUID,
                "Armor modifier",
                0.1,
                Constants.AttributeModifierOperation.MULTIPLY
        ));
    }
}

Modifying or Removing Existing Attribute Modifiers

@SubscribeEvent
public static void onItemAttribute(ItemAttributeModifierEvent event) {
    ItemStack stack = event.getItemStack();
    //Modifying an Iron Sword to increase base damage by 3.
    if(stack.getItem() == Items.IRON_SWORD && event.getSlotType() == EntityEquipmentSlot.MAINHAND) {
        //Getting all current Attack Damage attribute modifiers.
        Collection<AttributeModifier> modifiers = event.getOriginalModifiers().get(SharedMonsterAttributes.ATTACK_DAMAGE.getName());
        //Locating the item attack damage attribute modifier.
        AttributeModifier toModify = null;
        for(AttributeModifier modifier : modifiers) {
            //Comparing the modifier UUID with the base sword attack damage UUID.
            if(modifier.getID().equals(Item.ATTACK_DAMAGE_MODIFIER)) {
                toModify = modifier;
                break;
            }
        }
        //If modifier is found, re-add the adjusted modifier.
        if(toModify != null) {
            event.removeModifier(SharedMonsterAttributes.ATTACK_DAMAGE, toModify);
            event.addModifier(SharedMonsterAttributes.ATTACK_DAMAGE, new AttributeModifier(
                    toModify.getID(),
                    toModify.getName(),
                    toModify.getAmount() + 3.0,
                    toModify.getOperation())
            );
        }
    }
}

Clone this wiki locally