Class LivingDrownEvent

java.lang.Object
net.neoforged.bus.api.Event
All Implemented Interfaces:
net.neoforged.bus.api.ICancellableEvent

public class LivingDrownEvent extends LivingEvent implements net.neoforged.bus.api.ICancellableEvent
LivingDrownEvent is fired whenever a living entity can't breathe and its air supply is less than or equal to zero.

This event is fired via CommonHooks.onLivingBreathe(LivingEntity, int, int).

This event is ICancellableEvent. Effects of cancellation are noted in setCanceled(boolean).

This event does not

invalid reference
have a result
. This event is fired on NeoForge.EVENT_BUS
  • Field Details

    • isDrowning

      private boolean isDrowning
    • damageAmount

      private float damageAmount
    • bubbleCount

      private int bubbleCount
  • Constructor Details

    • LivingDrownEvent

      public LivingDrownEvent(LivingEntity entity, boolean isDrowning, float damageAmount, int bubbleCount)
      Constructs a new LivingDrownEvent.
      Parameters:
      entity - The entity that is drowning.
      isDrowning - If the entity is "actively" drowning, and would take damage.
      damageAmount - The amount of drowning damage the entity would take.
      bubbleCount - The number of ParticleTypes.BUBBLE particles that will be spawned when actively drowning.
    • LivingDrownEvent

      public LivingDrownEvent(LivingEntity entity)
      Constructor which auto-populates with all vanilla values.
      See Also:
      • invalid reference
        #LivingDrownEvent(LivingEntity, boolean, float, boolean)
  • Method Details

    • isDrowning

      public boolean isDrowning()
      This method returns true if the entity is "actively" drowning.
      For most entities, this happens when their air supply reaches -20.
      When this is true, the entity will take damage, spawn particles, and reset their air supply to 0.
      Returns:
      If the entity is actively drowning.
    • setDrowning

      public void setDrowning(boolean isDrowning)
      Sets if the entity is actively drowning.
      Parameters:
      isDrowning - The new value.
      See Also:
    • getDamageAmount

      public float getDamageAmount()
      Gets the amount of drowning damage the entity would take.
      Drowning damage is only inflicted if the entity is actively drowning.
      For vanilla entities, the default amount of damage is 2 (1 heart).

      If the damage amount is less than or equal to zero, Entity.hurt(net.minecraft.world.damagesource.DamageSource, float) will not be called.

      Returns:
      The amount of damage that will be dealt to the entity when actively drowning.
    • setDamageAmount

      public void setDamageAmount(float damageAmount)
      Sets the amount of drowning damage that may be inflicted.
      Parameters:
      damageAmount - The new value.
      See Also:
    • getBubbleCount

      public int getBubbleCount()
      Gets the number of ParticleTypes.BUBBLE particles that would be spawned.
      Bubbles are only spawned if the entity is actively drowning.
      For vanilla entities, the default value is 8 particles.
      Returns:
      The number of bubble particles that will spawn when actively drowning.
    • setBubbleCount

      public void setBubbleCount(int bubbleCount)
      Sets the amount of bubbles that may be spawned.
      Parameters:
      bubbleCount - The new value.
      See Also:
    • setCanceled

      public void setCanceled(boolean cancel)
      Cancels the drowning event.
      Cancellation is mostly equivalent to setDrowning(boolean) with a value of false.
      However, this also incurs the usual side effects of cancellation.
      Specified by:
      setCanceled in interface net.neoforged.bus.api.ICancellableEvent