From 9fc51e6c823fa3855a0d8eb7f6a748ff718ec180 Mon Sep 17 00:00:00 2001 From: EightFactorial <29801334+EightFactorial@users.noreply.github.com> Date: Sun, 23 Mar 2025 01:07:55 -0700 Subject: [PATCH] Wait for plugins to load before starting the ECS Also runs `App:finish()` after plugins finish loading. --- azalea-client/src/client.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs index f18de86d..93e89d33 100644 --- a/azalea-client/src/client.rs +++ b/azalea-client/src/client.rs @@ -39,7 +39,7 @@ use azalea_protocol::{ resolver, }; use azalea_world::{Instance, InstanceContainer, InstanceName, PartialInstance}; -use bevy_app::{App, Plugin, PluginGroup, PluginGroupBuilder, Update}; +use bevy_app::{App, Plugin, PluginGroup, PluginGroupBuilder, PluginsState, Update}; use bevy_ecs::{ bundle::Bundle, component::Component, @@ -60,7 +60,7 @@ use tokio::{ }, time, }; -use tracing::{debug, error}; +use tracing::{debug, error, info}; use uuid::Uuid; use crate::{ @@ -863,6 +863,14 @@ pub fn start_ecs_runner( run_schedule_receiver: mpsc::Receiver<()>, run_schedule_sender: mpsc::Sender<()>, ) -> Arc> { + // Wait for plugins to load + if app.plugins_state() == PluginsState::Adding { + info!("Waiting for plugins to load ..."); + while matches!(app.plugins_state(), PluginsState::Adding) {} + } + // Finish adding the plugins + app.finish(); + // all resources should have been added by now so we can take the ecs from the // app let ecs = Arc::new(Mutex::new(std::mem::take(app.world_mut())));