forked from EXTERNAL/bareiron
implement player poses (sneak/sprint)
* Added sending player metadata with poses to everyone * Renamed sendPlayerMetadataToAll to broadcastPlayerMetadata * Made entity metadata system flexible * Made broadcastPlayerMetadata create new metadata instead of using a global one * Moved writeEntityData, sizeEntityData and sizeEntityMetadata to procedures * style nitpicks --------- Co-authored-by: p2r3 <p2r3@p2r3.com>
This commit is contained in:
@@ -764,6 +764,10 @@ int cs_setPlayerMovementFlags (int client_fd, uint8_t *on_ground) {
|
||||
|
||||
*on_ground = readByte(client_fd) & 0x01;
|
||||
|
||||
PlayerData *player;
|
||||
if (!getPlayerData(client_fd, &player))
|
||||
broadcastPlayerMetadata(player);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -910,6 +914,26 @@ int sc_spawnEntity (
|
||||
return 0;
|
||||
}
|
||||
|
||||
// S->C Set Entity Metadata
|
||||
int sc_setEntityMetadata (int client_fd, int id, EntityData *metadata, size_t length) {
|
||||
int entity_metadata_size = sizeEntityMetadata(metadata, length);
|
||||
if (entity_metadata_size == -1) return 1;
|
||||
|
||||
writeVarInt(client_fd, 2 + sizeVarInt(id) + entity_metadata_size);
|
||||
writeByte(client_fd, 0x5C);
|
||||
|
||||
writeVarInt(client_fd, id); // Entity ID
|
||||
|
||||
for (size_t i = 0; i < length; i ++) {
|
||||
EntityData *data = &metadata[i];
|
||||
writeEntityData(client_fd, data);
|
||||
}
|
||||
|
||||
writeByte(client_fd, 0xFF); // End
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// S->C Spawn Entity (from PlayerData)
|
||||
int sc_spawnEntityPlayer (int client_fd, PlayerData player) {
|
||||
return sc_spawnEntity(
|
||||
@@ -1198,6 +1222,8 @@ int cs_playerInput (int client_fd) {
|
||||
if (flags & 0x20) player->flags |= 0x04;
|
||||
else player->flags &= ~0x04;
|
||||
|
||||
broadcastPlayerMetadata(player);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1215,6 +1241,8 @@ int cs_playerCommand (int client_fd) {
|
||||
if (action == 1) player->flags |= 0x08;
|
||||
else if (action == 2) player->flags &= ~0x08;
|
||||
|
||||
broadcastPlayerMetadata(player);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user