diff options
| author | mat <github@matdoes.dev> | 2023-03-08 19:26:40 +0000 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2023-03-08 19:26:40 +0000 |
| commit | f28efd5637cf3e129af018066421c090cb73ad50 (patch) | |
| tree | b9fefb31f4f315d794b5b8ff8e8426337619d94b /azalea-client/src/client.rs | |
| parent | 5ce830ae6ce12982cdfa578673374de7444abf3f (diff) | |
| download | azalea-drasl-f28efd5637cf3e129af018066421c090cb73ad50.tar.xz | |
make ClientInformation and TabList their own components
Diffstat (limited to 'azalea-client/src/client.rs')
| -rw-r--r-- | azalea-client/src/client.rs | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs index 79501fd4..8f460da8 100644 --- a/azalea-client/src/client.rs +++ b/azalea-client/src/client.rs @@ -51,6 +51,7 @@ use bevy_ecs::{ }; use bevy_log::LogPlugin; use bevy_time::{prelude::FixedTime, TimePlugin}; +use derive_more::{Deref, DerefMut}; use log::{debug, error}; use parking_lot::{Mutex, RwLock}; use std::{collections::HashMap, fmt::Debug, io, net::SocketAddr, sync::Arc, time::Duration}; @@ -58,8 +59,6 @@ use thiserror::Error; use tokio::{sync::mpsc, time}; use uuid::Uuid; -pub type ClientInformation = ServerboundClientInformationPacket; - /// `Client` has the things that a user interacting with the library will want. /// Things that a player in the world will want to know are in [`LocalPlayer`]. /// @@ -93,6 +92,16 @@ pub struct Client { pub run_schedule_sender: mpsc::UnboundedSender<()>, } +/// A component that contains some of the "settings" for this client that are +/// sent to the server, such as render distance. +#[derive(Component, Clone, Debug, Deref, DerefMut, Default, Eq, PartialEq)] +pub struct ClientInformation(ServerboundClientInformationPacket); + +/// A component that contains a map of player UUIDs to their information in the +/// tab list +#[derive(Component, Clone, Debug, Deref, DerefMut, Default)] +pub struct TabList(HashMap<Uuid, PlayerInfo>); + /// An error that happened while joining the server. #[derive(Error, Debug)] pub enum JoinError { @@ -238,6 +247,8 @@ impl Client { game_profile: GameProfileComponent(game_profile), physics_state: PhysicsState::default(), local_player_events: LocalPlayerEvents(tx), + client_information: ClientInformation::default(), + tab_list: TabList::default(), _local: Local, }); @@ -451,32 +462,21 @@ impl Client { client_information: ServerboundClientInformationPacket, ) -> Result<(), std::io::Error> { { - self.local_player_mut(&mut self.ecs.lock()) - .client_information = client_information; + let mut ecs = self.ecs.lock(); + let mut client_information_mut = self.query::<&mut ClientInformation>(&mut ecs); + **client_information_mut = client_information.clone(); } if self.logged_in() { - let client_information_packet = self - .local_player(&mut self.ecs.lock()) - .client_information - .clone() - .get(); log::debug!( "Sending client information (already logged in): {:?}", - client_information_packet + client_information ); - self.write_packet(client_information_packet); + self.write_packet(client_information.get()); } Ok(()) } - - /// Get a HashMap of all the players in the tab list. - /// - /// Internally, this fetches the `players` field in [`LocalPlayer`]. - pub fn players(&mut self) -> HashMap<Uuid, PlayerInfo> { - self.local_player(&mut self.ecs.lock()).players.clone() - } } /// A bundle for the components that are present on a local player that received @@ -488,6 +488,8 @@ pub struct JoinedClientBundle { pub game_profile: GameProfileComponent, pub physics_state: PhysicsState, pub local_player_events: LocalPlayerEvents, + pub client_information: ClientInformation, + pub tab_list: TabList, pub _local: Local, } |
