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 net.neoforged.neoforge.event.entity.player.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.TabListNameFormat
Nested classes/interfaces inherited from class net.neoforged.neoforge.event.entity.living.LivingEvent
LivingEvent.LivingJumpEvent, LivingEvent.LivingVisibilityEvent
Nested classes/interfaces inherited from class net.neoforged.neoforge.event.entity.EntityEvent
EntityEvent.EnteringSection, EntityEvent.EntityConstructing, EntityEvent.Size
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private final boolean
private final net.minecraft.world.entity.Entity
-
Constructor Summary
ConstructorsConstructorDescriptionSweepAttackEvent
(net.minecraft.world.entity.player.Player player, net.minecraft.world.entity.Entity target, boolean isVanillaSweep) -
Method Summary
Modifier and TypeMethodDescriptionnet.minecraft.world.entity.Entity
Returns the target of the attack, which is guaranteed to be a valid attack target.boolean
Returns true if the attack will be trigger a sweep.boolean
Returns true if the attack would cause a sweep by utilizing the vanilla rules.void
setCanceled
(boolean canceled) Cancels the event, preventing further event handlers from acting.void
setSweeping
(boolean sweep) Methods inherited from class net.neoforged.neoforge.event.entity.player.PlayerEvent
getEntity
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.neoforged.bus.api.ICancellableEvent
isCanceled
-
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:
- 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:
setCanceled
in interfacenet.neoforged.bus.api.ICancellableEvent
-