diff options
Diffstat (limited to 'azalea-client/src')
| -rw-r--r-- | azalea-client/src/client.rs | 6 | ||||
| -rw-r--r-- | azalea-client/src/configuration.rs | 6 | ||||
| -rw-r--r-- | azalea-client/src/disconnect.rs | 2 | ||||
| -rw-r--r-- | azalea-client/src/lib.rs | 4 | ||||
| -rw-r--r-- | azalea-client/src/local_player.rs | 23 | ||||
| -rw-r--r-- | azalea-client/src/packet_handling/configuration.rs | 10 | ||||
| -rw-r--r-- | azalea-client/src/packet_handling/game.rs | 2 | ||||
| -rw-r--r-- | azalea-client/src/raw_connection.rs | 14 |
8 files changed, 41 insertions, 26 deletions
diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs index cfef34d1..7c1aca78 100644 --- a/azalea-client/src/client.rs +++ b/azalea-client/src/client.rs @@ -326,7 +326,7 @@ impl Client { client_information: crate::ClientInformation::default(), instance_holder, }, - InConfigurationState, + InConfigState, )); Ok((client, rx)) @@ -757,8 +757,8 @@ pub struct JoinedClientBundle { /// A marker component for local players that are currently in the /// `configuration` state. -#[derive(Component)] -pub struct InConfigurationState; +#[derive(Component, Clone, Debug)] +pub struct InConfigState; pub struct AzaleaPlugin; impl Plugin for AzaleaPlugin { diff --git a/azalea-client/src/configuration.rs b/azalea-client/src/configuration.rs index bfaa36f0..bf07710b 100644 --- a/azalea-client/src/configuration.rs +++ b/azalea-client/src/configuration.rs @@ -10,7 +10,7 @@ use azalea_protocol::{ use bevy_app::prelude::*; use bevy_ecs::prelude::*; -use crate::{client::InConfigurationState, packet_handling::configuration::SendConfigurationEvent}; +use crate::{client::InConfigState, packet_handling::configuration::SendConfigurationEvent}; pub struct ConfigurationPlugin; impl Plugin for ConfigurationPlugin { @@ -18,13 +18,13 @@ impl Plugin for ConfigurationPlugin { app.add_systems( Update, handle_in_configuration_state - .after(crate::packet_handling::configuration::handle_send_packet_event), + .before(crate::packet_handling::configuration::handle_send_packet_event), ); } } fn handle_in_configuration_state( - query: Query<(Entity, &ClientInformation), Added<InConfigurationState>>, + query: Query<(Entity, &ClientInformation), Added<InConfigState>>, mut send_packet_events: EventWriter<SendConfigurationEvent>, ) { for (entity, client_information) in query.iter() { diff --git a/azalea-client/src/disconnect.rs b/azalea-client/src/disconnect.rs index 37bb37dd..5b377ce2 100644 --- a/azalea-client/src/disconnect.rs +++ b/azalea-client/src/disconnect.rs @@ -13,6 +13,7 @@ use bevy_ecs::{ system::{Commands, Query}, }; use derive_more::Deref; +use tracing::trace; use crate::{client::JoinedClientBundle, events::LocalPlayerEvents, raw_connection::RawConnection}; @@ -45,6 +46,7 @@ pub fn remove_components_from_disconnected_players( mut events: EventReader<DisconnectEvent>, ) { for DisconnectEvent { entity, .. } in events.read() { + trace!("Got DisconnectEvent for {entity:?}"); commands .entity(*entity) .remove::<JoinedClientBundle>() diff --git a/azalea-client/src/lib.rs b/azalea-client/src/lib.rs index 68354c87..652ae439 100644 --- a/azalea-client/src/lib.rs +++ b/azalea-client/src/lib.rs @@ -33,8 +33,8 @@ pub mod task_pool; pub use account::{Account, AccountOpts}; pub use azalea_protocol::common::client_information::ClientInformation; pub use client::{ - start_ecs_runner, Client, DefaultPlugins, JoinError, JoinedClientBundle, StartClientOpts, - TickBroadcast, + start_ecs_runner, Client, DefaultPlugins, InConfigState, JoinError, JoinedClientBundle, + LocalPlayerBundle, StartClientOpts, TickBroadcast, }; pub use events::Event; pub use local_player::{GameProfileComponent, Hunger, InstanceHolder, TabList}; diff --git a/azalea-client/src/local_player.rs b/azalea-client/src/local_player.rs index 7c9254a7..2d691826 100644 --- a/azalea-client/src/local_player.rs +++ b/azalea-client/src/local_player.rs @@ -20,14 +20,23 @@ use crate::{ /// A component that keeps strong references to our [`PartialInstance`] and /// [`Instance`] for local players. +/// +/// This can also act as a convenience for accessing the player's Instance since +/// the alternative is to look up the player's [`InstanceName`] in the +/// [`InstanceContainer`]. +/// +/// [`InstanceContainer`]: azalea_world::InstanceContainer +/// [`InstanceName`]: azalea_world::InstanceName #[derive(Component, Clone)] pub struct InstanceHolder { /// The partial instance is the world this client currently has loaded. It /// has a limited render distance. pub partial_instance: Arc<RwLock<PartialInstance>>, /// The world is the combined [`PartialInstance`]s of all clients in the - /// same world. (Only relevant if you're using a shared world, i.e. a - /// swarm) + /// same world. + /// + /// This is only relevant if you're using a shared world (i.e. a + /// swarm). pub instance: Arc<RwLock<Instance>>, } @@ -114,12 +123,16 @@ impl Default for Hunger { } impl InstanceHolder { - /// Create a new `InstanceHolder`. - pub fn new(entity: Entity, world: Arc<RwLock<Instance>>) -> Self { + /// Create a new `InstanceHolder` for the given entity. + /// + /// The partial instance will be created for you. The render distance will + /// be set to a default value, which you can change by creating a new + /// partial_instance. + pub fn new(entity: Entity, instance: Arc<RwLock<Instance>>) -> Self { let client_information = ClientInformation::default(); InstanceHolder { - instance: world, + instance, partial_instance: Arc::new(RwLock::new(PartialInstance::new( azalea_world::chunk_storage::calculate_chunk_storage_range( client_information.view_distance.into(), diff --git a/azalea-client/src/packet_handling/configuration.rs b/azalea-client/src/packet_handling/configuration.rs index 8eccebf5..9124f6aa 100644 --- a/azalea-client/src/packet_handling/configuration.rs +++ b/azalea-client/src/packet_handling/configuration.rs @@ -14,7 +14,7 @@ use bevy_ecs::prelude::*; use bevy_ecs::system::SystemState; use tracing::{debug, error, warn}; -use crate::client::InConfigurationState; +use crate::client::InConfigState; use crate::disconnect::DisconnectEvent; use crate::local_player::Hunger; use crate::packet_handling::game::KeepAliveEvent; @@ -30,7 +30,7 @@ pub struct ConfigurationEvent { } pub fn send_packet_events( - query: Query<(Entity, &RawConnection), With<InConfigurationState>>, + query: Query<(Entity, &RawConnection), With<InConfigState>>, mut packet_events: ResMut<Events<ConfigurationEvent>>, ) { // we manually clear and send the events at the beginning of each update @@ -110,7 +110,7 @@ pub fn process_packet_events(ecs: &mut World) { let mut raw_conn = query.get_mut(player_entity).unwrap(); raw_conn - .write_packet(ServerboundFinishConfiguration {}) + .write_packet(ServerboundFinishConfiguration) .expect( "we should be in the right state and encoding this packet shouldn't fail", ); @@ -118,7 +118,7 @@ pub fn process_packet_events(ecs: &mut World) { // these components are added now that we're going to be in the Game state ecs.entity_mut(player_entity) - .remove::<InConfigurationState>() + .remove::<InConfigState>() .insert(crate::JoinedClientBundle { physics_state: crate::PhysicsState::default(), inventory: crate::inventory::Inventory::default(), @@ -251,7 +251,7 @@ impl SendConfigurationEvent { pub fn handle_send_packet_event( mut send_packet_events: EventReader<SendConfigurationEvent>, - mut query: Query<(&mut RawConnection, Option<&InConfigurationState>)>, + mut query: Query<(&mut RawConnection, Option<&InConfigState>)>, ) { for event in send_packet_events.read() { if let Ok((raw_conn, in_configuration_state)) = query.get_mut(event.sent_by) { diff --git a/azalea-client/src/packet_handling/game.rs b/azalea-client/src/packet_handling/game.rs index d715d6c6..a7326198 100644 --- a/azalea-client/src/packet_handling/game.rs +++ b/azalea-client/src/packet_handling/game.rs @@ -1470,7 +1470,7 @@ pub fn process_packet_events(ecs: &mut World) { commands .entity(player_entity) - .insert(crate::client::InConfigurationState) + .insert(crate::client::InConfigState) .remove::<crate::JoinedClientBundle>(); system_state.apply(ecs); diff --git a/azalea-client/src/raw_connection.rs b/azalea-client/src/raw_connection.rs index 2091c14e..50f41049 100644 --- a/azalea-client/src/raw_connection.rs +++ b/azalea-client/src/raw_connection.rs @@ -18,26 +18,26 @@ use tracing::error; /// yourself. It will do the compression and encryption for you though. #[derive(Component)] pub struct RawConnection { - reader: RawConnectionReader, - writer: RawConnectionWriter, + pub reader: RawConnectionReader, + pub writer: RawConnectionWriter, /// Packets sent to this will be sent to the server. /// A task that reads packets from the server. The client is disconnected /// when this task ends. - read_packets_task: tokio::task::JoinHandle<()>, + pub read_packets_task: tokio::task::JoinHandle<()>, /// A task that writes packets from the server. - write_packets_task: tokio::task::JoinHandle<()>, + pub write_packets_task: tokio::task::JoinHandle<()>, - connection_protocol: ConnectionProtocol, + pub connection_protocol: ConnectionProtocol, } #[derive(Clone)] -struct RawConnectionReader { +pub struct RawConnectionReader { pub incoming_packet_queue: Arc<Mutex<Vec<Box<[u8]>>>>, pub run_schedule_sender: mpsc::UnboundedSender<()>, } #[derive(Clone)] -struct RawConnectionWriter { +pub struct RawConnectionWriter { pub outgoing_packets_sender: mpsc::UnboundedSender<Box<[u8]>>, } |
