Class CriticalHitEvent


public class CriticalHitEvent extends PlayerEvent
This event is fired when a player attacks an entity in Player.attack(Entity). It can be used to change the critical hit status and damage modifier

In the event the attack was not a critical hit, the event will still be fired, but it will be preemptively cancelled.

  • Field Details

    • target

      private final Entity target
    • vanillaDmgMultiplier

      private final float vanillaDmgMultiplier
    • isVanillaCritical

      private final boolean isVanillaCritical
    • dmgMultiplier

      private float dmgMultiplier
    • isCriticalHit

      private boolean isCriticalHit
  • Constructor Details

  • Method Details

    • getTarget

      public Entity getTarget()
      Returns the entity that was attacked by the player.
      Returns:
      the entity that was attacked by the player
    • getDamageMultiplier

      public float getDamageMultiplier()
      The damage multiplier is applied to the base attack's damage if the attack critically hits.

      A damage multiplier of 1.0 will not change the damage, a value of 1.5 will increase the damage by 50%, and so on.

      Parameters:
      modifier - The new damage modifier.
    • setDamageMultiplier

      public void setDamageMultiplier(float dmgMultiplier)
      Sets the damage multiplier for the critical hit. Not used if isCriticalHit() is false.

      Changing the damage modifier to zero does not guarantee that the attack does zero damage.

      Parameters:
      modifier - The new damage modifier. Must not be negative.
      See Also:
    • isCriticalHit

      public boolean isCriticalHit()
      Returns if the attack will critically hit.
      Returns:
      if the attack will critically hit
    • setCriticalHit

      public void setCriticalHit(boolean isCriticalHit)
      Changes the critical hit state.
      Parameters:
      isCriticalHit - true if the attack should critically hit
    • getVanillaMultiplier

      public float getVanillaMultiplier()
      Gets the original damage multiplier set by vanilla.

      If the event isVanillaCritical(), the damage multiplier will be 1.5, otherwise it will be 1.0

      See Also:
    • isVanillaCritical

      public boolean isVanillaCritical()
      Returns true if the attack was considered a critical hit by vanilla.
      Returns:
      true if the attack was considered a critical hit by vanilla