implement arm swinging animation

* Added packets to show players swinging their arms

* fix misleading comment

---------

Co-authored-by: p2r3 <p2r3@p2r3.com>
This commit is contained in:
SDFTDusername
2025-09-14 15:59:25 +02:00
committed by GitHub
parent a34134918a
commit f6333429eb
3 changed files with 54 additions and 0 deletions

View File

@@ -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,