Class LivingDrownEvent
java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.event.entity.EntityEvent
net.neoforged.neoforge.event.entity.living.LivingEvent
net.neoforged.neoforge.event.entity.living.LivingDrownEvent
- 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
.
This event is fired on invalid reference
have a result
NeoForge.EVENT_BUS
-
Nested Class Summary
Nested classes/interfaces inherited from class net.neoforged.neoforge.event.entity.living.LivingEvent
LivingEvent.LivingJumpEvent, LivingEvent.LivingVisibilityEvent
Nested classes/interfaces inherited from class net.neoforged.neoforge.event.entity.EntityEvent
EntityEvent.EnteringSection, EntityEvent.EntityConstructing, EntityEvent.Size
-
Field Summary
Modifier and TypeFieldDescriptionprivate int
private float
private boolean
-
Constructor Summary
ConstructorDescriptionLivingDrownEvent
(LivingEntity entity) Constructor which auto-populates with all vanilla values.LivingDrownEvent
(LivingEntity entity, boolean isDrowning, float damageAmount, int bubbleCount) Constructs a new LivingDrownEvent. -
Method Summary
Modifier and TypeMethodDescriptionint
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.float
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).boolean
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.void
setBubbleCount
(int bubbleCount) Sets the amount of bubbles that may be spawned.void
setCanceled
(boolean cancel) Cancels the drowning event.
Cancellation is mostly equivalent tosetDrowning(boolean)
with a value of false.
However, this also incurs the usual side effects of cancellation.void
setDamageAmount
(float damageAmount) Sets the amount of drowning damage that may be inflicted.void
setDrowning
(boolean isDrowning) Sets if the entity is actively drowning.Methods inherited from class net.neoforged.neoforge.event.entity.living.LivingEvent
getEntity
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.neoforged.bus.api.ICancellableEvent
isCanceled
-
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
Constructor which auto-populates with all vanilla values.- See Also:
-
-
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 tosetDrowning(boolean)
with a value of false.
However, this also incurs the usual side effects of cancellation.- Specified by:
setCanceled
in interfacenet.neoforged.bus.api.ICancellableEvent
-