Class SweepAttackEvent

All Implemented Interfaces:
net.neoforged.bus.api.ICancellableEvent

public class SweepAttackEvent extends PlayerEvent implements net.neoforged.bus.api.ICancellableEvent
The SweepAttackEvent is fired when a Player attacks a target, after the CriticalHitEvent has been fired.

This event can be used to force an attack to trigger a sweep, or to prevent a sweep from occurring.

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

  • Field Details

    • target

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

      private final boolean isVanillaSweep
    • isSweeping

      private boolean isSweeping
  • Constructor Details

    • SweepAttackEvent

      public SweepAttackEvent(net.minecraft.world.entity.player.Player player, net.minecraft.world.entity.Entity target, boolean isVanillaSweep)
  • Method Details

    • getTarget

      public net.minecraft.world.entity.Entity getTarget()
      Returns the target of the attack, which is guaranteed to be a valid attack target.
    • isVanillaSweep

      public boolean isVanillaSweep()
      Returns true if the attack would cause a sweep by utilizing the vanilla rules.

      The vanilla rules are as follows. All of them must be true for a vanilla sweep to occur:

      1. The player's attack strength is greater than 90%.
      2. The attack is not a critical hit, or is a critical hit which does not disable the sweep attack.
      3. The player is on the ground.
      4. The distance the player has traveled this tick is less than their speed.
      5. The player's weapon supports sweep attacks via ItemAbilities.SWORD_SWEEP.
    • isSweeping

      public boolean isSweeping()
      Returns true if the attack will be trigger a sweep.
    • setSweeping

      public void setSweeping(boolean sweep)
      Parameters:
      sweep - Whether to enable a sweep for this attack.
    • setCanceled

      public void setCanceled(boolean canceled)
      Cancels the event, preventing further event handlers from acting. Canceling the event will use the current value of isSweeping().

      If you intend to perform a custom sweep attack, you should cancel the event and setSweeping(boolean) to false before performing your handling.

      Specified by:
      setCanceled in interface net.neoforged.bus.api.ICancellableEvent