mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
make Account a component
This commit is contained in:
parent
659b6a1175
commit
b6586d500c
3 changed files with 26 additions and 23 deletions
|
@ -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,
|
||||
|
|
|
@ -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(),
|
||||
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(),
|
||||
entity_id_index: EntityIdIndex::default(),
|
||||
|
||||
mining: mining::MineBundle::default(),
|
||||
attack: attack::AttackBundle::default(),
|
||||
mining: mining::MineBundle::default(),
|
||||
attack: attack::AttackBundle::default(),
|
||||
|
||||
_local: LocalEntity,
|
||||
});
|
||||
_local: LocalEntity,
|
||||
},
|
||||
));
|
||||
|
||||
Ok((client, rx))
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Reference in a new issue