-
-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow setting if the critical hit should disable sweep attack in Crit…
…icalHitEvent, adding SweepAttackEvent (#1496) This allows mods to have better handling over crit-sweep behavior through a new flag in `CriticalHitEvent` as well as providing full sweep control via `SweepAttackEvent`.
- Loading branch information
Showing
4 changed files
with
136 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/main/java/net/neoforged/neoforge/event/entity/player/SweepAttackEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright (c) NeoForged and contributors | ||
* SPDX-License-Identifier: LGPL-2.1-only | ||
*/ | ||
|
||
package net.neoforged.neoforge.event.entity.player; | ||
|
||
import net.minecraft.world.entity.Entity; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.neoforged.bus.api.ICancellableEvent; | ||
import net.neoforged.neoforge.common.ItemAbilities; | ||
|
||
/** | ||
* The SweepAttackEvent is fired when a {@link Player} attacks a target, after the {@link CriticalHitEvent} has been fired. | ||
* <p> | ||
* This event can be used to force an attack to trigger a sweep, or to prevent a sweep from occurring. | ||
* <p> | ||
* This event is fired on both the logical client and logical server. | ||
*/ | ||
public class SweepAttackEvent extends PlayerEvent implements ICancellableEvent { | ||
private final Entity target; | ||
private final boolean isVanillaSweep; | ||
|
||
private boolean isSweeping; | ||
|
||
public SweepAttackEvent(Player player, Entity target, boolean isVanillaSweep) { | ||
super(player); | ||
this.target = target; | ||
this.isSweeping = this.isVanillaSweep = isVanillaSweep; | ||
} | ||
|
||
/** | ||
* Returns the target of the attack, which is guaranteed to be a valid attack target. | ||
*/ | ||
public Entity getTarget() { | ||
return this.target; | ||
} | ||
|
||
/** | ||
* Returns true if the attack would cause a sweep by utilizing the vanilla rules. | ||
* <p> | ||
* The vanilla rules are as follows. All of them must be true for a vanilla sweep to occur: | ||
* <ol> | ||
* <li>The player's attack strength is greater than 90%.</li> | ||
* <li>The attack is not a critical hit, or is a critical hit which does not {@linkplain CriticalHitEvent#disableSweep() disable the sweep attack}.</li> | ||
* <li>The player is on the ground.</li> | ||
* <li>The distance the player has traveled this tick is less than their speed.</li> | ||
* <li>The player's weapon supports sweep attacks via {@link ItemAbilities#SWORD_SWEEP}.</li> | ||
* </ol> | ||
*/ | ||
public boolean isVanillaSweep() { | ||
return this.isVanillaSweep; | ||
} | ||
|
||
/** | ||
* Returns true if the attack will be trigger a sweep. | ||
*/ | ||
public boolean isSweeping() { | ||
return this.isSweeping; | ||
} | ||
|
||
/** | ||
* @param sweep Whether to enable a sweep for this attack. | ||
*/ | ||
public void setSweeping(boolean sweep) { | ||
this.isSweeping = sweep; | ||
} | ||
|
||
/** | ||
* Cancels the event, preventing further event handlers from acting. Canceling the event will use the current value of {@link #isSweeping()}. | ||
* <p> | ||
* If you intend to perform a custom sweep attack, you should cancel the event and {@link #setSweeping} to false before performing your handling. | ||
*/ | ||
@Override | ||
public void setCanceled(boolean canceled) { | ||
ICancellableEvent.super.setCanceled(canceled); | ||
} | ||
} |