From ccb7a81dc998521356c886bac615fb998d5e6a32 Mon Sep 17 00:00:00 2001 From: Matt Worzala <35708499+mworzala@users.noreply.github.com> Date: Sat, 5 Aug 2023 12:57:38 -0400 Subject: [PATCH] hollow-cube/fix-riptide-animation (#44) Co-authored-by: TogAr2 <59421074+TogAr2@users.noreply.github.com> (cherry picked from commit d901eaaed110b3ed9f14172ba4e29146556940fd) --- .../event/item/ItemUpdateStateEvent.java | 19 +++++++++++++++++++ .../listener/PlayerDiggingListener.java | 3 ++- .../server/listener/UseItemListener.java | 3 +-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/minestom/server/event/item/ItemUpdateStateEvent.java b/src/main/java/net/minestom/server/event/item/ItemUpdateStateEvent.java index e7db9dc4b..2ae8cefc3 100644 --- a/src/main/java/net/minestom/server/event/item/ItemUpdateStateEvent.java +++ b/src/main/java/net/minestom/server/event/item/ItemUpdateStateEvent.java @@ -12,6 +12,7 @@ public class ItemUpdateStateEvent implements PlayerInstanceEvent, ItemEvent { private final Player.Hand hand; private final ItemStack itemStack; private boolean handAnimation; + private boolean riptideSpinAttack; public ItemUpdateStateEvent(@NotNull Player player, @NotNull Player.Hand hand, @NotNull ItemStack itemStack) { this.player = player; @@ -24,6 +25,11 @@ public class ItemUpdateStateEvent implements PlayerInstanceEvent, ItemEvent { 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) { this.handAnimation = handAnimation; } @@ -32,6 +38,19 @@ public class ItemUpdateStateEvent implements PlayerInstanceEvent, ItemEvent { 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 public @NotNull ItemStack getItemStack() { return itemStack; diff --git a/src/main/java/net/minestom/server/listener/PlayerDiggingListener.java b/src/main/java/net/minestom/server/listener/PlayerDiggingListener.java index fbdfe21c2..f377a4b55 100644 --- a/src/main/java/net/minestom/server/listener/PlayerDiggingListener.java +++ b/src/main/java/net/minestom/server/listener/PlayerDiggingListener.java @@ -146,7 +146,8 @@ public final class PlayerDiggingListener { player.refreshActiveHand(true, false, false); } else { final boolean isOffHand = itemUpdateStateEvent.getHand() == Player.Hand.OFF; - player.refreshActiveHand(itemUpdateStateEvent.hasHandAnimation(), isOffHand, false); + player.refreshActiveHand(itemUpdateStateEvent.hasHandAnimation(), + isOffHand, itemUpdateStateEvent.isRiptideSpinAttack()); } } diff --git a/src/main/java/net/minestom/server/listener/UseItemListener.java b/src/main/java/net/minestom/server/listener/UseItemListener.java index 28996a921..4ffb8dd45 100644 --- a/src/main/java/net/minestom/server/listener/UseItemListener.java +++ b/src/main/java/net/minestom/server/listener/UseItemListener.java @@ -41,7 +41,6 @@ public class UseItemListener { } PlayerItemAnimationEvent.ItemAnimationType itemAnimationType = null; - boolean riptideSpinAttack = false; boolean cancelAnimation = false; @@ -68,7 +67,7 @@ public class UseItemListener { if (!cancelAnimation && itemAnimationType != null) { PlayerItemAnimationEvent playerItemAnimationEvent = new PlayerItemAnimationEvent(player, itemAnimationType, hand); EventDispatcher.callCancellable(playerItemAnimationEvent, () -> { - player.refreshActiveHand(true, hand == Player.Hand.OFF, riptideSpinAttack); + player.refreshActiveHand(true, hand == Player.Hand.OFF, false); player.sendPacketToViewers(player.getMetadataPacket()); }); }