Class ServerMobEffectEvents

java.lang.Object
net.fabricmc.fabric.api.entity.event.v1.effect.ServerMobEffectEvents

public final class ServerMobEffectEvents extends Object
Events related to status effects in mobs.

Status effect events are useful when implementing generic behavior for many status effects and modifying the addition and removal behavior of existing status effects.

When only one class of status effects requires code to be run before/after the addition or removal of the effect, consider using FabricMobEffect.onEffectAdded(MobEffectInstance, LivingEntity), FabricMobEffect.onEffectRemoved(MobEffectInstance, LivingEntity), or FabricMobEffect.onEffectStarted(MobEffectInstance, LivingEntity).

Additionally, an EffectEventContext parameter is passed to all listeners of these events.

See Also:
  • Field Details

    • ALLOW_ADD

      public static final Event<ServerMobEffectEvents.AllowAdd> ALLOW_ADD
      An event that checks whether an effect may be added.

      This event can be used to cancel effects given specific conditions such as a held item, a data attachment, or another status effect.

    • BEFORE_ADD

      public static final Event<ServerMobEffectEvents.BeforeAdd> BEFORE_ADD
      An event that is called before an effect is added.

      This event can be used to generalize behavior normally in the MobEffect.onEffectAdded(LivingEntity, int) methods to a subset of status effects or even to all status effects.

      See Also:
    • AFTER_ADD

      public static final Event<ServerMobEffectEvents.AfterAdd> AFTER_ADD
      An event that is called after an effect is added.

      This event is useful for code that is required to run only after an effect is applied, such as a method that checks if an effect is present on an entity.

    • ALLOW_EARLY_REMOVE

      public static final Event<ServerMobEffectEvents.AllowEarlyRemove> ALLOW_EARLY_REMOVE
      An event that checks whether an effect may be removed.

      Note: this event is not called when an effect expires. The behavior of effect expiry typically should not be modified.

      This event is called when effects are removed before they expire. For example, drinking milk, drinking honey when poisoned, using a totem of undying, or using a command such as /effect clear triggers this event. If you don't want commands to be affected, an EffectEventContext parameter is passed to listeners.

      This event can be used to cancel the removal of effects given specific conditions such as a held item, a data attachment, or another status effect.

    • BEFORE_REMOVE

      public static final Event<ServerMobEffectEvents.BeforeRemove> BEFORE_REMOVE
      An event that is called before an effect is removed.

      This event can be used to generalize behavior normally in the FabricMobEffect.onEffectRemoved(MobEffectInstance, LivingEntity) method to a subset of status effects or even to all status effects.

      See Also:
    • AFTER_REMOVE

      public static final Event<ServerMobEffectEvents.AfterRemove> AFTER_REMOVE
      An event that is called after an effect is removed.

      This event is useful for code that is required to run only after an effect is removed, such as a method that checks if an effect is present on an entity.