diff options
| author | mat <git@matdoes.dev> | 2025-09-28 13:10:04 -0545 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-09-28 13:10:04 -0545 |
| commit | 2c8b7c5c2c9297273abfba8f7743f1bc25f166b1 (patch) | |
| tree | 3d3aded400100c136287fa59293ce26c61644d00 /azalea-client/src/plugins/packet/config | |
| parent | e2ed19c1ed92f0dccc881d835d9ac6e0f7f834c0 (diff) | |
| download | azalea-drasl-2c8b7c5c2c9297273abfba8f7743f1bc25f166b1.tar.xz | |
upgrade bevy to 0.17.0-rc.2
Diffstat (limited to 'azalea-client/src/plugins/packet/config')
| -rw-r--r-- | azalea-client/src/plugins/packet/config/events.rs | 33 | ||||
| -rw-r--r-- | azalea-client/src/plugins/packet/config/mod.rs | 11 |
2 files changed, 20 insertions, 24 deletions
diff --git a/azalea-client/src/plugins/packet/config/events.rs b/azalea-client/src/plugins/packet/config/events.rs index a9237e75..be5cfdb1 100644 --- a/azalea-client/src/plugins/packet/config/events.rs +++ b/azalea-client/src/plugins/packet/config/events.rs @@ -9,7 +9,7 @@ use tracing::{debug, error}; use crate::{InConfigState, connection::RawConnection}; -#[derive(Event, Debug, Clone)] +#[derive(Message, Debug, Clone)] pub struct ReceiveConfigPacketEvent { /// The client entity that received the packet. pub entity: Entity, @@ -19,8 +19,9 @@ pub struct ReceiveConfigPacketEvent { /// An event for sending a packet to the server while we're in the /// `configuration` state. -#[derive(Event, Clone)] +#[derive(EntityEvent, Clone)] pub struct SendConfigPacketEvent { + #[event_target] pub sent_by: Entity, pub packet: ServerboundConfigPacket, } @@ -32,41 +33,33 @@ impl SendConfigPacketEvent { } pub fn handle_outgoing_packets_observer( - trigger: Trigger<SendConfigPacketEvent>, + send_config_packet: On<SendConfigPacketEvent>, mut query: Query<(&mut RawConnection, Option<&InConfigState>)>, ) { - let event = trigger.event(); - if let Ok((mut raw_conn, in_configuration_state)) = query.get_mut(event.sent_by) { + if let Ok((mut raw_conn, in_configuration_state)) = query.get_mut(send_config_packet.sent_by) { if in_configuration_state.is_none() { error!( "Tried to send a configuration packet {:?} while not in configuration state", - event.packet + send_config_packet.packet ); return; } - debug!("Sending config packet: {:?}", event.packet); - if let Err(e) = raw_conn.write(event.packet.clone()) { + debug!("Sending config packet: {:?}", send_config_packet.packet); + if let Err(e) = raw_conn.write(send_config_packet.packet.clone()) { error!("Failed to send packet: {e}"); } } } -/// A system that converts [`SendConfigPacketEvent`] events into triggers so -/// they get received by [`handle_outgoing_packets_observer`]. -pub fn handle_outgoing_packets( - mut commands: Commands, - mut events: EventReader<SendConfigPacketEvent>, -) { - for event in events.read() { - commands.trigger(event.clone()); - } -} /// A Bevy trigger that's sent when our client receives a [`ClientboundPing`] /// packet in the config state. /// -/// See [`PingEvent`] for more information. +/// Also see [`PingEvent`]. /// /// [`ClientboundPing`]: azalea_protocol::packets::config::ClientboundPing /// [`PingEvent`]: crate::packet::game::PingEvent #[derive(Event, Debug, Clone)] -pub struct ConfigPingEvent(pub azalea_protocol::packets::config::ClientboundPing); +pub struct ConfigPingEvent { + pub entity: Entity, + pub packet: azalea_protocol::packets::config::ClientboundPing, +} diff --git a/azalea-client/src/plugins/packet/config/mod.rs b/azalea-client/src/plugins/packet/config/mod.rs index 416019e8..e8bb017d 100644 --- a/azalea-client/src/plugins/packet/config/mod.rs +++ b/azalea-client/src/plugins/packet/config/mod.rs @@ -84,7 +84,7 @@ impl ConfigPacketHandler<'_> { pub fn disconnect(&mut self, p: &ClientboundDisconnect) { warn!("Got disconnect packet {p:?}"); - as_system::<EventWriter<_>>(self.ecs, |mut events| { + as_system::<MessageWriter<_>>(self.ecs, |mut events| { events.write(DisconnectEvent { entity: self.player, reason: Some(p.reason.clone()), @@ -126,7 +126,7 @@ impl ConfigPacketHandler<'_> { self.player ); - as_system::<(Commands, EventWriter<_>)>(self.ecs, |(mut commands, mut events)| { + as_system::<(Commands, MessageWriter<_>)>(self.ecs, |(mut commands, mut events)| { events.write(KeepAliveEvent { entity: self.player, id: p.id, @@ -142,14 +142,17 @@ impl ConfigPacketHandler<'_> { debug!("Got ping packet (in configuration) {p:?}"); as_system::<Commands>(self.ecs, |mut commands| { - commands.trigger_targets(ConfigPingEvent(p.clone()), self.player); + commands.trigger(ConfigPingEvent { + entity: self.player, + packet: p.clone(), + }); }); } pub fn resource_pack_push(&mut self, p: &ClientboundResourcePackPush) { debug!("Got resource pack push packet {p:?}"); - as_system::<EventWriter<_>>(self.ecs, |mut events| { + as_system::<MessageWriter<_>>(self.ecs, |mut events| { events.write(ResourcePackEvent { entity: self.player, id: p.id, |
