From 3f60bdadac1a02e1109148bbbe5a8a3545f13849 Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Thu, 17 Apr 2025 16:16:51 -0500 Subject: Move login state to the ECS (#213) * use packet handlers code for login custom_query * initial broken implementation for ecs-only login * fixes * run Update schedule 60 times per second and delete code related to run_schedule_sender * fix tests * fix online-mode * reply to query packets in a separate system and make it easier for plugins to disable individual replies * remove unused imports --- azalea/src/container.rs | 7 +++++-- azalea/src/swarm/mod.rs | 16 +++++----------- 2 files changed, 10 insertions(+), 13 deletions(-) (limited to 'azalea/src') diff --git a/azalea/src/container.rs b/azalea/src/container.rs index 0ce0fc44..0d1cfb16 100644 --- a/azalea/src/container.rs +++ b/azalea/src/container.rs @@ -1,7 +1,7 @@ use std::fmt::Debug; use std::fmt::Formatter; -use azalea_client::packet::game::ReceivePacketEvent; +use azalea_client::packet::game::ReceiveGamePacketEvent; use azalea_client::{ Client, inventory::{CloseContainerEvent, ContainerClickEvent, Inventory}, @@ -234,7 +234,10 @@ impl ContainerHandle { #[derive(Component, Debug)] pub struct WaitingForInventoryOpen; -fn handle_menu_opened_event(mut commands: Commands, mut events: EventReader) { +fn handle_menu_opened_event( + mut commands: Commands, + mut events: EventReader, +) { for event in events.read() { if let ClientboundGamePacket::ContainerSetContent { .. } = event.packet.as_ref() { commands diff --git a/azalea/src/swarm/mod.rs b/azalea/src/swarm/mod.rs index eb56ae2d..ba8fd7bb 100644 --- a/azalea/src/swarm/mod.rs +++ b/azalea/src/swarm/mod.rs @@ -55,8 +55,6 @@ pub struct Swarm { bots_tx: mpsc::UnboundedSender<(Option, Client)>, swarm_tx: mpsc::UnboundedSender, - - run_schedule_sender: mpsc::Sender<()>, } /// Create a new [`Swarm`]. @@ -396,12 +394,9 @@ where swarm_tx.send(SwarmEvent::Init).unwrap(); - let (run_schedule_sender, run_schedule_receiver) = mpsc::channel(1); - let main_schedule_label = self.app.main().update_schedule.unwrap(); - let ecs_lock = - start_ecs_runner(self.app, run_schedule_receiver, run_schedule_sender.clone()); + let ecs_lock = start_ecs_runner(self.app); let swarm = Swarm { ecs_lock: ecs_lock.clone(), @@ -414,8 +409,6 @@ where bots_tx, swarm_tx: swarm_tx.clone(), - - run_schedule_sender, }; // run the main schedule so the startup systems run @@ -495,7 +488,8 @@ where let Some(first_bot_state) = first_bot.query::>(&mut ecs).cloned() else { error!( "the first bot ({} / {}) is missing the required state component! none of the client handler functions will be called.", - first_bot.profile.name, first_bot.entity + first_bot.username(), + first_bot.entity ); continue; }; @@ -513,7 +507,8 @@ where let Some(state) = bot.query::>(&mut ecs).cloned() else { error!( "one of our bots ({} / {}) is missing the required state component! its client handler function will not be called.", - bot.profile.name, bot.entity + bot.username(), + bot.entity ); continue; }; @@ -665,7 +660,6 @@ impl Swarm { address: &address, resolved_address: &resolved_address, proxy: join_opts.proxy.clone(), - run_schedule_sender: self.run_schedule_sender.clone(), event_sender: Some(tx), }) .await?; -- cgit v1.2.3