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

@@ -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);

View File

@@ -438,6 +438,10 @@ void handlePacket (int client_fd, int length, int packet_id, int state) {
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);
break;

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,