mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-12 18:31:41 +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);
|
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) {
|
public void refreshActiveHand(boolean isHandActive, boolean offHand, boolean riptideSpinAttack) {
|
||||||
this.isHandActive = isHandActive;
|
this.isHandActive = isHandActive;
|
||||||
this.offHand = offHand;
|
this.offHand = offHand;
|
||||||
|
@ -3,18 +3,21 @@ package net.minestom.server.listener;
|
|||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
import net.minestom.server.event.animation.AnimationEvent;
|
import net.minestom.server.event.animation.AnimationEvent;
|
||||||
import net.minestom.server.network.packet.client.play.ClientAnimationPacket;
|
import net.minestom.server.network.packet.client.play.ClientAnimationPacket;
|
||||||
import net.minestom.server.network.packet.server.play.EntityAnimationPacket;
|
|
||||||
|
|
||||||
public class AnimationListener {
|
public class AnimationListener {
|
||||||
|
|
||||||
public static void animationListener(ClientAnimationPacket packet, Player player) {
|
public static void animationListener(ClientAnimationPacket packet, Player player) {
|
||||||
AnimationEvent animationEvent = new AnimationEvent(player, packet.hand);
|
AnimationEvent animationEvent = new AnimationEvent(player, packet.hand);
|
||||||
player.callCancellableEvent(AnimationEvent.class, animationEvent, () -> {
|
player.callCancellableEvent(AnimationEvent.class, animationEvent, () -> {
|
||||||
EntityAnimationPacket entityAnimationPacket = new EntityAnimationPacket();
|
Player.Hand hand = animationEvent.getHand();
|
||||||
entityAnimationPacket.entityId = player.getEntityId();
|
switch (hand) {
|
||||||
entityAnimationPacket.animation = animationEvent.getHand() == Player.Hand.MAIN ?
|
case MAIN:
|
||||||
EntityAnimationPacket.Animation.SWING_MAIN_ARM : EntityAnimationPacket.Animation.SWING_OFF_HAND;
|
player.swingMainHand();
|
||||||
player.sendPacketToViewers(entityAnimationPacket);
|
break;
|
||||||
|
case OFF:
|
||||||
|
player.swingOffHand();
|
||||||
|
break;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user