Class PetDamageEvent

All Implemented Interfaces:
Cancellable

public class PetDamageEvent extends CancellablePetEvent
Fired before a pet deals mêlée damage to a target. Listeners may modify the damage amount or cancel the strike entirely.

Fires from PetSkillTriggerListener after the Damage / Bleed / Fire / Knockback / Lightning / Stomp / Wither chain has computed final damage but before the target's damage() call. getDamage() reflects the already-computed total — base attack damage plus skill modifiers.

Cancellable: cancellation aborts both the damage application and any on-hit skills queued for the strike — see PetOnHitSkillEvent, which is dispatched per on-hit skill in the same flow.

Mutable damage: setDamage(d) clamps to max(0, d) — negative values can't heal the target through this hook. Setting damage to 0 does NOT cancel the swing; the entity damage call still runs (which triggers vanilla animation). To skip the strike entirely, cancel.

Pet state: live pet, with the owner online (the firing path requires the owner to be tracking the pet entity).

  • Constructor Details

    • PetDamageEvent

      public PetDamageEvent(Pet pet, Entity target, double damage)
      Creates the event for a mêlée strike that is about to land.
      Parameters:
      pet - the attacking pet
      target - the entity being struck
      damage - the already-computed final damage
  • Method Details

    • getHandlerList

      public static HandlerList getHandlerList()
      Returns the handler list for this event type.
      Returns:
      the shared HandlerList every PetDamageEvent is dispatched through
    • setDamage

      public void setDamage(double damage)
      Sets the damage this strike deals, clamped to zero at the low end so a negative value cannot heal the target. Setting 0 does not cancel the strike -- the damage call still runs and plays the vanilla hurt animation; cancel the event to skip it entirely.
      Parameters:
      damage - the damage to deal; values below 0 become 0
    • getHandlers

      public @NonNull HandlerList getHandlers()
      Specified by:
      getHandlers in class Event
    • getPet

      public Pet getPet()
      The pet dealing the damage.
      Specified by:
      getPet in class PetEvent
      Returns:
      the attacking pet
    • getTarget

      public Entity getTarget()
      The entity about to be damaged.
      Returns:
      the entity being struck
    • getDamage

      public double getDamage()
      The damage about to be dealt: base attack damage with every on-hit skill modifier already folded in.
      Returns:
      the damage this strike will deal