aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2023-12-02 16:06:42 -0600
committermat <git@matdoes.dev>2023-12-02 16:06:42 -0600
commitf052882123220bdfaeb827199394f920ea1cd43d (patch)
tree734e243d10ac477c2b036247aeddd9478e3477e3
parent34a40270108e51014e0884c3b6b6619ba42c17dc (diff)
downloadazalea-drasl-f052882123220bdfaeb827199394f920ea1cd43d.tar.xz
make sure Startup system runs before any bots join
-rw-r--r--azalea-client/src/client.rs6
-rw-r--r--azalea/src/lib.rs9
-rw-r--r--azalea/src/swarm/mod.rs12
3 files changed, 24 insertions, 3 deletions
diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs
index 95b7b747..21d3a80a 100644
--- a/azalea-client/src/client.rs
+++ b/azalea-client/src/client.rs
@@ -54,7 +54,9 @@ use azalea_protocol::{
resolver, ServerAddress,
};
use azalea_world::{Instance, InstanceContainer, InstanceName, PartialInstance};
-use bevy_app::{App, FixedUpdate, Plugin, PluginGroup, PluginGroupBuilder, Update};
+use bevy_app::{
+ App, FixedUpdate, Plugin, PluginGroup, PluginGroupBuilder, PreStartup, Startup, Update,
+};
use bevy_ecs::{
bundle::Bundle,
component::Component,
@@ -653,7 +655,7 @@ impl Plugin for AzaleaPlugin {
/// [`DefaultPlugins`].
#[doc(hidden)]
pub fn start_ecs_runner(
- app: App,
+ mut app: App,
run_schedule_receiver: mpsc::UnboundedReceiver<()>,
run_schedule_sender: mpsc::UnboundedSender<()>,
) -> Arc<Mutex<World>> {
diff --git a/azalea/src/lib.rs b/azalea/src/lib.rs
index bf00cbbe..8f86f97f 100644
--- a/azalea/src/lib.rs
+++ b/azalea/src/lib.rs
@@ -193,9 +193,18 @@ where
// An event that causes the schedule to run. This is only used internally.
let (run_schedule_sender, run_schedule_receiver) = mpsc::unbounded_channel();
+ let main_schedule_label = self.app.main_schedule_label;
+
let ecs_lock =
start_ecs_runner(self.app, run_schedule_receiver, run_schedule_sender.clone());
+ // run the main schedule so the startup systems run
+ {
+ let mut ecs = ecs_lock.lock();
+ ecs.run_schedule(main_schedule_label);
+ ecs.clear_trackers();
+ }
+
let (bot, mut rx) = Client::start_client(
ecs_lock,
&account,
diff --git a/azalea/src/swarm/mod.rs b/azalea/src/swarm/mod.rs
index 417ca168..5d1a73df 100644
--- a/azalea/src/swarm/mod.rs
+++ b/azalea/src/swarm/mod.rs
@@ -320,6 +320,9 @@ where
let (swarm_tx, mut swarm_rx) = mpsc::unbounded_channel();
let (run_schedule_sender, run_schedule_receiver) = mpsc::unbounded_channel();
+
+ let main_schedule_label = self.app.main_schedule_label;
+
let ecs_lock =
start_ecs_runner(self.app, run_schedule_receiver, run_schedule_sender.clone());
@@ -337,7 +340,14 @@ where
run_schedule_sender,
};
- ecs_lock.lock().insert_resource(swarm.clone());
+
+ // run the main schedule so the startup systems run
+ {
+ let mut ecs = ecs_lock.lock();
+ ecs.insert_resource(swarm.clone());
+ ecs.run_schedule(main_schedule_label);
+ ecs.clear_trackers();
+ }
// SwarmBuilder (self) isn't Send so we have to take all the things we need out
// of it