From f6333429eba6269d19498eb9eddc6f49be0ed9f9 Mon Sep 17 00:00:00 2001 From: SDFTDusername <85052868+SDFTDusername@users.noreply.github.com> Date: Sun, 14 Sep 2025 15:59:25 +0200 Subject: [PATCH] implement arm swinging animation * Added packets to show players swinging their arms * fix misleading comment --------- Co-authored-by: p2r3 --- include/packets.h | 2 ++ src/main.c | 4 ++++ src/packets.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/include/packets.h b/include/packets.h index fa0eaa1..4d3b36c 100644 --- a/include/packets.h +++ b/include/packets.h @@ -14,6 +14,7 @@ int cs_setPlayerPosition (int client_fd, double *x, double *y, double *z, uint8_ int cs_setPlayerRotation (int client_fd, float *yaw, float *pitch, uint8_t *on_ground); int cs_setPlayerMovementFlags (int client_fd, uint8_t *on_ground); int cs_setHeldItem (int client_fd); +int cs_swingArm (int client_fd); int cs_clickContainer (int client_fd); int cs_closeContainer (int client_fd); int cs_clientStatus (int client_fd); @@ -47,6 +48,7 @@ int sc_acknowledgeBlockChange (int client_fd, int sequence); int sc_playerInfoUpdateAddPlayer (int client_fd, PlayerData player); int sc_spawnEntity (int client_fd, int id, uint8_t *uuid, int type, double x, double y, double z, uint8_t yaw, uint8_t pitch); int sc_spawnEntityPlayer (int client_fd, PlayerData player); +int sc_entityAnimation (int client_fd, int id, uint8_t animation); int sc_teleportEntity (int client_fd, int id, double x, double y, double z, float yaw, float pitch); int sc_setHeadRotation (int client_fd, int id, uint8_t yaw); int sc_updateEntityRotation (int client_fd, int id, uint8_t yaw, uint8_t pitch); diff --git a/src/main.c b/src/main.c index 0e36da5..a489810 100644 --- a/src/main.c +++ b/src/main.c @@ -437,6 +437,10 @@ void handlePacket (int client_fd, int length, int packet_id, int state) { case 0x34: if (state == STATE_PLAY) cs_setHeldItem(client_fd); break; + + case 0x3C: + if (state == STATE_PLAY) cs_swingArm(client_fd); + break; case 0x28: if (state == STATE_PLAY) cs_playerAction(client_fd); diff --git a/src/packets.c b/src/packets.c index e712d6b..8fd13a4 100644 --- a/src/packets.c +++ b/src/packets.c @@ -762,6 +762,43 @@ int cs_setPlayerMovementFlags (int client_fd, uint8_t *on_ground) { return 0; } +// C->S Swing Arm (serverbound) +int cs_swingArm (int client_fd) { + + PlayerData *player; + if (getPlayerData(client_fd, &player)) return 1; + + uint8_t hand = readVarInt(client_fd); + + uint8_t animation = 255; + switch (hand) { + case 0: { + animation = 0; + break; + } + case 1: { + animation = 2; + break; + } + } + + if (animation == 255) + return 1; + + // Forward animation to all connected players + for (int i = 0; i < MAX_PLAYERS; i ++) { + PlayerData* other_player = &player_data[i]; + + if (other_player->client_fd == -1) continue; + if (other_player->client_fd == player->client_fd) continue; + if (other_player->flags & 0x20) continue; + + sc_entityAnimation(other_player->client_fd, player->client_fd, animation); + } + + return 0; +} + // C->S Set Held Item (serverbound) int cs_setHeldItem (int client_fd) { @@ -880,6 +917,17 @@ int sc_spawnEntityPlayer (int client_fd, PlayerData player) { ); } +// S->C Entity Animation +int sc_entityAnimation (int client_fd, int id, uint8_t animation) { + writeVarInt(client_fd, 2 + sizeVarInt(id)); + writeByte(client_fd, 0x02); + + writeVarInt(client_fd, id); // Entity ID + writeByte(client_fd, animation); // Animation + + return 0; +} + // S->C Teleport Entity int sc_teleportEntity ( int client_fd, int id,