add hand swinging

This commit is contained in:
Pyrbu 2024-02-16 18:35:00 +01:00
parent 828a8a3465
commit 5213476d15
5 changed files with 22 additions and 0 deletions

@ -124,4 +124,10 @@ public interface Npc extends PropertyHolder {
* @return The set of players that can currently see this npc
*/
Set<Player> getViewers();
/**
* Swings the entity's hand
* @param offHand Should the hand be the offhand
*/
void swingHand(boolean offHand);
}

@ -73,6 +73,10 @@ public class PacketEntity implements PropertyHolder {
packetFactory.sendAllMetadata(player, this, properties);
}
public void swingHand(Player player, boolean offhand) {
packetFactory.sendHandSwing(player, this, offhand);
}
private static int reserveEntityID() {
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_14)) {
return Reflections.ATOMIC_ENTITY_ID_FIELD.get().incrementAndGet();

@ -214,4 +214,8 @@ public class NpcImpl extends Viewable implements Npc {
delete();
this.worldName = world.getName();
}
public void swingHand(boolean offHand) {
for (Player viewer : getViewers()) entity.swingHand(viewer, offHand);
}
}

@ -23,4 +23,5 @@ public interface PacketFactory {
void sendEquipment(Player player, PacketEntity entity, Equipment equipment);
void sendMetadata(Player player, PacketEntity entity, List<EntityData> data);
void sendHeadRotation(Player player, PacketEntity entity, float yaw, float pitch);
void sendHandSwing(Player player, PacketEntity entity, boolean offHand);
}

@ -175,4 +175,11 @@ public class V1_8PacketFactory implements PacketFactory {
protected void add(Map<Integer, EntityData> map, EntityData data) {
map.put(data.getIndex(), data);
}
@Override
public void sendHandSwing(Player player, PacketEntity entity, boolean offHand) {
sendPacket(player, new WrapperPlayServerEntityAnimation(entity.getEntityId(), offHand ?
WrapperPlayServerEntityAnimation.EntityAnimationType.SWING_OFF_HAND :
WrapperPlayServerEntityAnimation.EntityAnimationType.SWING_MAIN_ARM));
}
}