mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-08 08:21:50 +01:00
Added LivingEntity#swingMainHand and LivingEntity#swingOffHand
This commit is contained in:
parent
eed946e948
commit
f8758d2933
@ -414,6 +414,28 @@ public abstract class LivingEntity extends Entity implements EquipmentHandler {
|
||||
this.expandedBoundingBox = getBoundingBox().expand(1, 0.5f, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a {@link EntityAnimationPacket} to swing the main hand
|
||||
* (can be used for attack animation)
|
||||
*/
|
||||
public void swingMainHand() {
|
||||
EntityAnimationPacket animationPacket = new EntityAnimationPacket();
|
||||
animationPacket.entityId = getEntityId();
|
||||
animationPacket.animation = EntityAnimationPacket.Animation.SWING_MAIN_ARM;
|
||||
sendPacketToViewers(animationPacket);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a {@link EntityAnimationPacket} to swing the off hand
|
||||
* (can be used for attack animation)
|
||||
*/
|
||||
public void swingOffHand() {
|
||||
EntityAnimationPacket animationPacket = new EntityAnimationPacket();
|
||||
animationPacket.entityId = getEntityId();
|
||||
animationPacket.animation = EntityAnimationPacket.Animation.SWING_OFF_HAND;
|
||||
sendPacketToViewers(animationPacket);
|
||||
}
|
||||
|
||||
public void refreshActiveHand(boolean isHandActive, boolean offHand, boolean riptideSpinAttack) {
|
||||
this.isHandActive = isHandActive;
|
||||
this.offHand = offHand;
|
||||
|
@ -3,18 +3,21 @@ package net.minestom.server.listener;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.event.animation.AnimationEvent;
|
||||
import net.minestom.server.network.packet.client.play.ClientAnimationPacket;
|
||||
import net.minestom.server.network.packet.server.play.EntityAnimationPacket;
|
||||
|
||||
public class AnimationListener {
|
||||
|
||||
public static void animationListener(ClientAnimationPacket packet, Player player) {
|
||||
AnimationEvent animationEvent = new AnimationEvent(player, packet.hand);
|
||||
player.callCancellableEvent(AnimationEvent.class, animationEvent, () -> {
|
||||
EntityAnimationPacket entityAnimationPacket = new EntityAnimationPacket();
|
||||
entityAnimationPacket.entityId = player.getEntityId();
|
||||
entityAnimationPacket.animation = animationEvent.getHand() == Player.Hand.MAIN ?
|
||||
EntityAnimationPacket.Animation.SWING_MAIN_ARM : EntityAnimationPacket.Animation.SWING_OFF_HAND;
|
||||
player.sendPacketToViewers(entityAnimationPacket);
|
||||
Player.Hand hand = animationEvent.getHand();
|
||||
switch (hand) {
|
||||
case MAIN:
|
||||
player.swingMainHand();
|
||||
break;
|
||||
case OFF:
|
||||
player.swingOffHand();
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user