1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 06:16:04 +00:00
azalea/azalea-client/src/player.rs
mat e21e1b97bf
Refactor azalea-client (#205)
* start organizing packet_handling more by moving packet handlers into their own functions

* finish writing all the handler functions for packets

* use macro for generating match statement for packet handler functions

* fix set_entity_data

* update config state to also use handler functions

* organize az-client file structure by moving things into plugins directory

* fix merge issues
2025-02-22 21:45:26 -06:00

47 lines
1.6 KiB
Rust
Executable file

use azalea_auth::game_profile::GameProfile;
use azalea_chat::FormattedText;
use azalea_core::game_type::GameMode;
use azalea_entity::indexing::EntityUuidIndex;
use bevy_ecs::{
event::EventReader,
system::{Commands, Res},
};
use uuid::Uuid;
use crate::{GameProfileComponent, packet::game::AddPlayerEvent};
/// A player in the tab list.
#[derive(Debug, Clone)]
pub struct PlayerInfo {
/// Information about the player's Minecraft account, including their
/// username.
pub profile: GameProfile,
/// The player's UUID.
pub uuid: Uuid,
/// The current gamemode of the player, like survival or creative.
pub gamemode: GameMode,
/// The player's latency in milliseconds. The bars in the tab screen depend
/// on this.
pub latency: i32,
/// The player's display name in the tab list, but only if it's different
/// from the player's normal username. Use `player_info.profile.name` to get
/// the player's actual username.
pub display_name: Option<FormattedText>,
}
/// Add a [`GameProfileComponent`] when an [`AddPlayerEvent`] is received.
/// Usually the `GameProfileComponent` will be added from the
/// `ClientboundGamePacket::AddPlayer` handler though.
pub fn retroactively_add_game_profile_component(
mut commands: Commands,
mut events: EventReader<AddPlayerEvent>,
entity_uuid_index: Res<EntityUuidIndex>,
) {
for event in events.read() {
if let Some(entity) = entity_uuid_index.get(&event.info.uuid) {
commands
.entity(entity)
.insert(GameProfileComponent(event.info.profile.clone()));
}
}
}