hollow-cube/fix-riptide-animation (#44)

Co-authored-by: TogAr2 <59421074+TogAr2@users.noreply.github.com>
(cherry picked from commit d901eaaed1)
This commit is contained in:
Matt Worzala 2023-08-05 12:57:38 -04:00
parent edf7b870c7
commit ccb7a81dc9
3 changed files with 22 additions and 3 deletions

View File

@ -12,6 +12,7 @@ public class ItemUpdateStateEvent implements PlayerInstanceEvent, ItemEvent {
private final Player.Hand hand; private final Player.Hand hand;
private final ItemStack itemStack; private final ItemStack itemStack;
private boolean handAnimation; private boolean handAnimation;
private boolean riptideSpinAttack;
public ItemUpdateStateEvent(@NotNull Player player, @NotNull Player.Hand hand, @NotNull ItemStack itemStack) { public ItemUpdateStateEvent(@NotNull Player player, @NotNull Player.Hand hand, @NotNull ItemStack itemStack) {
this.player = player; this.player = player;
@ -24,6 +25,11 @@ public class ItemUpdateStateEvent implements PlayerInstanceEvent, ItemEvent {
return hand; return hand;
} }
/**
* Sets whether the player should have a hand animation.
*
* @param handAnimation whether the player should have a hand animation
*/
public void setHandAnimation(boolean handAnimation) { public void setHandAnimation(boolean handAnimation) {
this.handAnimation = handAnimation; this.handAnimation = handAnimation;
} }
@ -32,6 +38,19 @@ public class ItemUpdateStateEvent implements PlayerInstanceEvent, ItemEvent {
return handAnimation; return handAnimation;
} }
/**
* Sets whether the player should have a riptide spin attack animation.
*
* @param riptideSpinAttack whether the player should have a riptide spin attack animation
*/
public void setRiptideSpinAttack(boolean riptideSpinAttack) {
this.riptideSpinAttack = riptideSpinAttack;
}
public boolean isRiptideSpinAttack() {
return riptideSpinAttack;
}
@Override @Override
public @NotNull ItemStack getItemStack() { public @NotNull ItemStack getItemStack() {
return itemStack; return itemStack;

View File

@ -146,7 +146,8 @@ public final class PlayerDiggingListener {
player.refreshActiveHand(true, false, false); player.refreshActiveHand(true, false, false);
} else { } else {
final boolean isOffHand = itemUpdateStateEvent.getHand() == Player.Hand.OFF; final boolean isOffHand = itemUpdateStateEvent.getHand() == Player.Hand.OFF;
player.refreshActiveHand(itemUpdateStateEvent.hasHandAnimation(), isOffHand, false); player.refreshActiveHand(itemUpdateStateEvent.hasHandAnimation(),
isOffHand, itemUpdateStateEvent.isRiptideSpinAttack());
} }
} }

View File

@ -41,7 +41,6 @@ public class UseItemListener {
} }
PlayerItemAnimationEvent.ItemAnimationType itemAnimationType = null; PlayerItemAnimationEvent.ItemAnimationType itemAnimationType = null;
boolean riptideSpinAttack = false;
boolean cancelAnimation = false; boolean cancelAnimation = false;
@ -68,7 +67,7 @@ public class UseItemListener {
if (!cancelAnimation && itemAnimationType != null) { if (!cancelAnimation && itemAnimationType != null) {
PlayerItemAnimationEvent playerItemAnimationEvent = new PlayerItemAnimationEvent(player, itemAnimationType, hand); PlayerItemAnimationEvent playerItemAnimationEvent = new PlayerItemAnimationEvent(player, itemAnimationType, hand);
EventDispatcher.callCancellable(playerItemAnimationEvent, () -> { EventDispatcher.callCancellable(playerItemAnimationEvent, () -> {
player.refreshActiveHand(true, hand == Player.Hand.OFF, riptideSpinAttack); player.refreshActiveHand(true, hand == Player.Hand.OFF, false);
player.sendPacketToViewers(player.getMetadataPacket()); player.sendPacketToViewers(player.getMetadataPacket());
}); });
} }