From 09d515c8cdd1bae32a5bc387b81360bad79eecf5 Mon Sep 17 00:00:00 2001 From: mat Date: Fri, 4 Apr 2025 18:09:14 +0000 Subject: breaking change: send azalea::Event::Spawn every time we switch worlds instead of only once ever --- azalea-client/src/plugins/events.rs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'azalea-client/src/plugins') diff --git a/azalea-client/src/plugins/events.rs b/azalea-client/src/plugins/events.rs index ac26aaf5..64dcf4f5 100644 --- a/azalea-client/src/plugins/events.rs +++ b/azalea-client/src/plugins/events.rs @@ -76,13 +76,19 @@ pub enum Event { /// Your position may be [`Vec3::ZERO`] immediately after you receive this /// event, but it'll be ready by the time you get [`Event::Spawn`]. /// + /// It's possible for this event to be sent multiple times per client if a + /// server sends multiple login packets (like when switching worlds). + /// /// [`Vec3::ZERO`]: azalea_core::position::Vec3::ZERO Login, - /// Fired when the player fully spawns into the world and is ready to - /// interact with it. + /// Fired when the player fully spawns into the world (is in a loaded chunk) + /// and is ready to interact with it. /// /// This is usually the event you should listen for when waiting for the bot /// to be ready. + /// + /// This event will be sent every time the client respawns or switches + /// worlds, as long as the server sends chunks to the client. Spawn, /// A chat message was sent in the game chat. Chat(ChatPacket), @@ -165,9 +171,13 @@ pub fn init_listener(query: Query<&LocalPlayerEvents, Added>) } // when MinecraftEntityId is added, it means the player is now in the world -pub fn login_listener(query: Query<&LocalPlayerEvents, Added>) { - for local_player_events in &query { +pub fn login_listener( + query: Query<(Entity, &LocalPlayerEvents), Added>, + mut commands: Commands, +) { + for (entity, local_player_events) in &query { let _ = local_player_events.send(Event::Login); + commands.entity(entity).remove::(); } } @@ -175,7 +185,8 @@ pub fn login_listener(query: Query<&LocalPlayerEvents, Added> /// [`Event::Spawn`]. /// /// This is just used internally by the [`spawn_listener`] system to avoid -/// sending the event twice for the same client. +/// sending the event twice if we stop being in an unloaded chunk. It's removed +/// when we receive a login packet. #[derive(Component)] pub struct SentSpawnEvent; #[allow(clippy::type_complexity)] -- cgit v1.2.3