1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 06:16:04 +00:00

send ServerboundPlayerLoaded on join and respawn

This commit is contained in:
mat 2025-06-03 22:01:50 +03:30
parent 415c0d873e
commit f311ac27d4
5 changed files with 52 additions and 5 deletions

View file

@ -10,7 +10,7 @@ use tracing::info;
use super::login::IsAuthenticated;
use crate::{
chat_signing, client::JoinedClientBundle, connection::RawConnection,
chat_signing, client::JoinedClientBundle, connection::RawConnection, loading::HasClientLoaded,
local_player::InstanceHolder,
};
@ -69,6 +69,8 @@ pub struct RemoveOnDisconnectBundle {
pub chat_signing_session: chat_signing::ChatSigningSession,
/// They're not authenticated anymore if they disconnected.
pub is_authenticated: IsAuthenticated,
// send ServerboundPlayerLoaded next time we join
pub has_client_loaded: HasClientLoaded,
}
/// A system that removes the several components from our clients when they get

View file

@ -0,0 +1,40 @@
use azalea_core::tick::GameTick;
use azalea_entity::InLoadedChunk;
use azalea_physics::PhysicsSet;
use azalea_protocol::packets::game::ServerboundPlayerLoaded;
use bevy_app::{App, Plugin};
use bevy_ecs::prelude::*;
use crate::{mining::MiningSet, packet::game::SendPacketEvent};
pub struct PlayerLoadedPlugin;
impl Plugin for PlayerLoadedPlugin {
fn build(&self, app: &mut App) {
app.add_systems(
GameTick,
player_loaded_packet
.after(PhysicsSet)
.after(MiningSet)
.after(crate::movement::send_position),
);
}
}
// this component is removed on respawn or disconnect
// (notably, it's not removed on login)
// mojmap interchangably calls it 'has client loaded' and 'has player loaded', i
// prefer the client one because it makes it clear that the component is only
// present on our own clients
#[derive(Component)]
pub struct HasClientLoaded;
pub fn player_loaded_packet(
mut commands: Commands,
query: Query<Entity, (With<InLoadedChunk>, Without<HasClientLoaded>)>,
) {
for entity in query.iter() {
commands.trigger(SendPacketEvent::new(entity, ServerboundPlayerLoaded));
commands.entity(entity).insert(HasClientLoaded);
}
}

View file

@ -12,6 +12,7 @@ pub mod events;
pub mod interact;
pub mod inventory;
pub mod join;
pub mod loading;
pub mod login;
pub mod mining;
pub mod movement;
@ -48,6 +49,7 @@ impl PluginGroup for DefaultPlugins {
.add(attack::AttackPlugin)
.add(chunks::ChunksPlugin)
.add(tick_end::TickEndPlugin)
.add(loading::PlayerLoadedPlugin)
.add(brand::BrandPlugin)
.add(tick_broadcast::TickBroadcastPlugin)
.add(pong::PongPlugin)

View file

@ -57,7 +57,6 @@ pub fn handle_outgoing_packets_observer(
mut query: Query<(&mut RawConnection, Option<&InGameState>)>,
) {
let event = trigger.event();
trace!("Sending game packet: {:?}", event.packet);
if let Ok((mut raw_connection, in_game_state)) = query.get_mut(event.sent_by) {
if in_game_state.is_none() {
@ -68,10 +67,12 @@ pub fn handle_outgoing_packets_observer(
return;
}
// debug!("Sending game packet: {:?}", event.packet);
trace!("Sending game packet: {:?}", event.packet);
if let Err(e) = raw_connection.write(event.packet.clone()) {
error!("Failed to send packet: {e}");
}
} else {
trace!("Not sending game packet: {:?}", event.packet);
}
}

View file

@ -29,6 +29,7 @@ use crate::{
inventory::{
ClientSideCloseContainerEvent, Inventory, MenuOpenedEvent, SetContainerContentEvent,
},
loading::HasClientLoaded,
local_player::{Hunger, InstanceHolder, LocalGameMode, PlayerAbilities, TabList},
movement::{KnockbackEvent, KnockbackType},
packet::as_system,
@ -1490,8 +1491,9 @@ impl GamePacketHandler<'_> {
entity_bundle,
));
// Remove the Dead marker component from the player.
commands.entity(self.player).remove::<Dead>();
commands
.entity(self.player)
.remove::<(Dead, HasClientLoaded)>();
},
)
}