Class LivingIncomingDamageEvent

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.LivingIncomingDamageEvent
All Implemented Interfaces:
net.neoforged.bus.api.ICancellableEvent

public class LivingIncomingDamageEvent extends LivingEvent implements net.neoforged.bus.api.ICancellableEvent
LivingIncomingDamageEvent is fired when a LivingEntity is about to receive damage.
This event is fired in LivingEntity.hurt(DamageSource, float) after invulnerability checks but before any damage processing/mitigation.
For custom posting of this event, the event expects to be fired before any damage reductions have been calculated. This event expects a mutable DamageContainer.
This event is fired via the CommonHooks.onEntityIncomingDamage(LivingEntity, DamageContainer).
See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • getContainer

      public DamageContainer getContainer()
      Returns the container for this damage sequence.
      Returns:
      the container for this damage sequence
    • getSource

      public DamageSource getSource()
      Returns the DamageSource for this damage sequence.
      Returns:
      the DamageSource for this damage sequence
    • getAmount

      public float getAmount()
      Returns the current damage to be applied to the entity.
      Returns:
      the current damage to be applied to the entity
    • getOriginalAmount

      public float getOriginalAmount()
      Returns the damage value passed into the damage sequence before modifications.
      Returns:
      the damage value passed into the damage sequence before modifications
    • setAmount

      public void setAmount(float newDamage)
      Parameters:
      newDamage - the damage value to be used in the rest of the damage sequence.
    • addReductionModifier

      public void addReductionModifier(DamageContainer.Reduction type, IReductionFunction reductionFunc)
      Reduction modifiers alter the vanilla damage reduction before it modifies the damage value. Modifiers are executed in sequence.
      Parameters:
      type - the reduction type to be modified
      reductionFunc - the function to apply to the reduction value.
    • setInvulnerabilityTicks

      public void setInvulnerabilityTicks(int ticks)
      When an entity's invulnerable time is fully cooled down, 20 ticks of invulnerability is added on the next attack. This method allows for setting a new invulnerability tick count when those conditions are met.
      Note: this value will be ignored if the damage is taken while invulnerability ticks are greater than 10 and the damage source does not bypass invulnerability
      Parameters:
      ticks - the number of ticks for the entity to remain invulnerable to incoming damage