diff options
| author | mat <git@matdoes.dev> | 2023-09-15 17:09:04 -0500 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2023-09-15 17:09:04 -0500 |
| commit | b6586d500cc01b790aa11b019cca9a829e3efc27 (patch) | |
| tree | c40e57151fa2b5dcad45175772f6373bc63a4277 | |
| parent | 659b6a1175298f4e2204c151e1fab0e18548f2ce (diff) | |
| download | azalea-drasl-b6586d500cc01b790aa11b019cca9a829e3efc27.tar.xz | |
make Account a component
| -rwxr-xr-x | azalea-client/src/account.rs | 3 | ||||
| -rw-r--r-- | azalea-client/src/client.rs | 50 | ||||
| -rw-r--r-- | azalea/src/swarm/mod.rs | 2 |
3 files changed, 29 insertions, 26 deletions
diff --git a/azalea-client/src/account.rs b/azalea-client/src/account.rs index 0e67a79a..46d0a728 100755 --- a/azalea-client/src/account.rs +++ b/azalea-client/src/account.rs @@ -5,6 +5,7 @@ use std::sync::Arc; use crate::get_mc_dir; use azalea_auth::certs::{Certificates, FetchCertificatesError}; use azalea_auth::AccessTokenResponse; +use bevy_ecs::component::Component; use parking_lot::Mutex; use thiserror::Error; use uuid::Uuid; @@ -28,7 +29,7 @@ use uuid::Uuid; /// /// [`Client::join`]: crate::Client::join /// [`azalea::ClientBuilder`]: https://docs.rs/azalea/latest/azalea/struct.ClientBuilder.html -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Component)] pub struct Account { /// The Minecraft username of the account. pub username: String, diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs index f26fe6d8..561c5a24 100644 --- a/azalea-client/src/client.rs +++ b/azalea-client/src/client.rs @@ -260,8 +260,7 @@ impl Client { let mut ecs = ecs_lock.lock(); // Make the ecs entity for this client - let entity_mut = ecs.spawn_empty(); - let entity = entity_mut.id(); + let entity = ecs.spawn_empty().id(); // we got the GameConnection, so the server is now connected :) let client = Client::new( @@ -296,28 +295,31 @@ impl Client { write_packets_task, ); - ecs.entity_mut(entity).insert(JoinedClientBundle { - local_player, - packet_receiver, - game_profile: GameProfileComponent(game_profile), - physics_state: PhysicsState::default(), - local_player_events: LocalPlayerEvents(tx), - inventory: InventoryComponent::default(), - client_information: ClientInformation::default(), - tab_list: TabList::default(), - current_sequence_number: CurrentSequenceNumber::default(), - last_sent_direction: LastSentLookDirection::default(), - abilities: PlayerAbilities::default(), - permission_level: PermissionLevel::default(), - hunger: Hunger::default(), - - entity_id_index: EntityIdIndex::default(), - - mining: mining::MineBundle::default(), - attack: attack::AttackBundle::default(), - - _local: LocalEntity, - }); + ecs.entity_mut(entity).insert(( + account.to_owned(), + JoinedClientBundle { + local_player, + packet_receiver, + game_profile: GameProfileComponent(game_profile), + physics_state: PhysicsState::default(), + local_player_events: LocalPlayerEvents(tx), + inventory: InventoryComponent::default(), + client_information: ClientInformation::default(), + tab_list: TabList::default(), + current_sequence_number: CurrentSequenceNumber::default(), + last_sent_direction: LastSentLookDirection::default(), + abilities: PlayerAbilities::default(), + permission_level: PermissionLevel::default(), + hunger: Hunger::default(), + + entity_id_index: EntityIdIndex::default(), + + mining: mining::MineBundle::default(), + attack: attack::AttackBundle::default(), + + _local: LocalEntity, + }, + )); Ok((client, rx)) } diff --git a/azalea/src/swarm/mod.rs b/azalea/src/swarm/mod.rs index f2d7e5b6..ba38a17e 100644 --- a/azalea/src/swarm/mod.rs +++ b/azalea/src/swarm/mod.rs @@ -537,7 +537,6 @@ impl Swarm { let cloned_bots = self.bots.clone(); let cloned_bots_tx = self.bots_tx.clone(); let cloned_bot = bot.clone(); - let owned_account = account.clone(); let swarm_tx = self.swarm_tx.clone(); tokio::spawn(async move { while let Some(event) = rx.recv().await { @@ -548,6 +547,7 @@ impl Swarm { } } cloned_bots.lock().remove(&bot.entity); + let owned_account = cloned_bot.component::<Account>(); swarm_tx .send(SwarmEvent::Disconnect(Box::new(owned_account))) .unwrap(); |
