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 the critical damage multiplier. Additionally, this event allows controlling if the critical hit will impact sweep conditions.

This event is fired on both the logical client and logical server.

  • Field Details

    • target

      private final net.minecraft.world.entity.Entity target
    • vanillaDmgMultiplier

      private final float vanillaDmgMultiplier
    • isVanillaCritical

      private final boolean isVanillaCritical
    • dmgMultiplier

      private float dmgMultiplier
    • isCriticalHit

      private boolean isCriticalHit
    • disableSweep

      private boolean disableSweep
  • Constructor Details

  • Method Details

    • getTarget

      public net.minecraft.world.entity.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.

    • 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:
      dmgMultiplier - 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
    • setDisableSweep

      public void setDisableSweep(boolean disableSweep)
      Sets if this attack should prevent a sweep from occurring.

      In vanilla, a critical hit always prevents a sweep from occurring. This method can allow an attack to both critically hit and sweep without having to validate the other sweep conditions.

    • disableSweep

      public boolean disableSweep()
      If this attack is a critical hit, returns if a sweep should be prevented.

      If this attack is not a critical hit, the return value of this method is meaningless.