Class SweepAttackEvent
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.player.PlayerEvent
net.neoforged.neoforge.event.entity.player.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.
-
Nested Class Summary
Nested classes/interfaces inherited from class PlayerEvent
PlayerEvent.BreakSpeed, PlayerEvent.Clone, PlayerEvent.HarvestCheck, PlayerEvent.ItemCraftedEvent, PlayerEvent.ItemSmeltedEvent, PlayerEvent.LoadFromFile, PlayerEvent.NameFormat, PlayerEvent.PlayerChangedDimensionEvent, PlayerEvent.PlayerChangeGameModeEvent, PlayerEvent.PlayerLoggedInEvent, PlayerEvent.PlayerLoggedOutEvent, PlayerEvent.PlayerRespawnEvent, PlayerEvent.SaveToFile, PlayerEvent.StartTracking, PlayerEvent.StopTracking, PlayerEvent.TabListNameFormatNested classes/interfaces inherited from class LivingEvent
LivingEvent.LivingJumpEvent, LivingEvent.LivingVisibilityEventNested classes/interfaces inherited from class EntityEvent
EntityEvent.EnteringSection, EntityEvent.EntityConstructing, EntityEvent.Size -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the target of the attack, which is guaranteed to be a valid attack target.booleanReturns true if the attack will be trigger a sweep.booleanReturns true if the attack would cause a sweep by utilizing the vanilla rules.voidsetCanceled(boolean canceled) Cancels the event, preventing further event handlers from acting.voidsetSweeping(boolean sweep) Methods inherited from class PlayerEvent
getEntityMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.neoforged.bus.api.ICancellableEvent
isCanceled
-
Field Details
-
target
-
isVanillaSweep
private final boolean isVanillaSweep -
isSweeping
private boolean isSweeping
-
-
Constructor Details
-
SweepAttackEvent
-
-
Method Details
-
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:
- The player's attack strength is greater than 90%.
- The attack is not a critical hit, or is a critical hit which does not disable the sweep attack.
- The player is on the ground.
- The distance the player has traveled this tick is less than their speed.
- 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 ofisSweeping().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:
setCanceledin interfacenet.neoforged.bus.api.ICancellableEvent
-