Skip to content

BaubleAttributeModifierEvent

Invadermonky edited this page Apr 9, 2026 · 3 revisions

BaubleAttributeModifierEvent

Event - BaubleAttributeModifierEvent

Similar to the ItemAttributeModifierEvent, this event allows developers to easily add, remove, or modify bauble attribute values. For a direct item implementation of this feature, see IAttributeBauble below.


IAttributeBauble

Interface - IAttributeBauble

A direct implementation of bauble attributes built into the IBauble interface, removing the need for event subscribers for individual items.


Examples

Bauble Event Handling

@SubscribeEvent
public static void onBaubleAttribute(BaubleAttributeModifierEvent event) {
    if(ExpandedEvents.isBaublesLoaded) {
        ItemStack stack = event.getItemStack();
        //Adding +6 armor and +6 health to Bauble's Miner's Ring
        if (stack.getItem() instanceof ItemRing && event.getBaubleType() == BaubleType.RING) {
            //Defining a modifier UUID will prevent the modifiers from stacking when equipped.
            // (Max +6.0 armor)
            event.addModifier(SharedMonsterAttributes.ARMOR, new AttributeModifier(
                    ATTRIBUTE_TEST_UUID,
                    "Bauble modifier",
                    6.0,
                    Constants.AttributeModifierOperation.ADD
            ));
            //Not defining a modifier UUID will allow the modifiers to stack with one another.
            // (+6 health per ring)
            event.addModifier(SharedMonsterAttributes.MAX_HEALTH, new AttributeModifier(
                    "Bauble modifier",
                    6.0,
                    Constants.AttributeModifierOperation.ADD
            ));
        }
    }
    }

Attribute Bauble Items

public class ItemTestAttributeRing extends Item implements IAttributeBauble {
    public static final UUID RING_ARMOR_BONUS = UUID.fromString("dc2e35db-02f1-4eb9-99e7-25f19903d0cc");
    
    @Override
    public @NotNull Multimap<String, AttributeModifier> getBaubleAttributeModifiers(BaubleType baubleType, ItemStack stack) {
        Multimap<String, AttributeModifier> multimap = HashMultimap.create();
        if(baubleType == BaubleType.RING) {
            //Grants a non-stacking +10% armor bonus
            multimap.put(SharedMonsterAttributes.ARMOR.getName(), new AttributeModifier(
                    RING_ARMOR_BONUS,
                    "Bauble modifier",
                    0.1,
                    Constants.AttributeModifierOperation.MULTIPLY
            ));
            //Grants a stacking +3 max health bonus
            multimap.put(SharedMonsterAttributes.MAX_HEALTH.getName(), new AttributeModifier(
                    "Bauble modifier",
                    3.0,
                    Constants.AttributeModifierOperation.ADD
            ));
        }
        return multimap;
    }

    @Override
    public BaubleType getBaubleType(ItemStack itemStack) {
        return BaubleType.RING;
    }
}

Clone this wiki locally