Skip to main content
Version: 26.2

Mob Effect Events

dev.architectury.event.events.common.MobEffectEvent

Fires as mob effects (potion effects) are applied to and removed from living entities. All of these events fire on the server only.

Added in 21.1

MobEffectEvent was added in Architectury API 21.1.

Events

EventListener methodReturns
ALLOW_ADDallowAdd(LivingEntity, MobEffectInstance)EventResult - interrupt to prevent the effect being applied.
AFTER_ADDafterAdd(LivingEntity, MobEffectInstance)void (notification).
ALLOW_REMOVEallowRemove(LivingEntity, MobEffectInstance)EventResult - interrupt to prevent the effect being removed.

ALLOW_ADD runs before the effect is applied, so interrupting it with a false result keeps the entity from gaining the effect at all. AFTER_ADD runs once the effect is on the entity and cannot be cancelled.

note

ALLOW_REMOVE covers early removals only - drinking milk, using a totem of undying, or /effect clear. It does not fire when an effect simply runs out on its own.

These mirror NeoForge's MobEffectEvent.Applicable, MobEffectEvent.Added and MobEffectEvent.Remove, and Fabric's ServerMobEffectEvents.ALLOW_ADD, AFTER_ADD and ALLOW_EARLY_REMOVE.

Examples

Make a custom entity immune to poison:

MobEffectEvent.ALLOW_ADD.register((entity, effect) -> {
if (entity.getType() == MyEntities.MY_MOB.get() && effect.is(MobEffects.POISON)) {
return EventResult.interruptFalse(); // the effect is not applied
}
return EventResult.pass();
});

React once an effect has been applied:

MobEffectEvent.AFTER_ADD.register((entity, effect) -> {
if (entity instanceof ServerPlayer player) {
// the player now has `effect`
}
});

Keep a curse from being cleared early:

MobEffectEvent.ALLOW_REMOVE.register((entity, effect) -> {
if (effect.is(MyEffects.MY_CURSE)) {
return EventResult.interruptFalse(); // milk will not clear it
}
return EventResult.pass();
});