aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src/plugins/packet/game
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-09-28 13:10:04 -0545
committermat <git@matdoes.dev>2025-09-28 13:10:04 -0545
commit2c8b7c5c2c9297273abfba8f7743f1bc25f166b1 (patch)
tree3d3aded400100c136287fa59293ce26c61644d00 /azalea-client/src/plugins/packet/game
parente2ed19c1ed92f0dccc881d835d9ac6e0f7f834c0 (diff)
downloadazalea-drasl-2c8b7c5c2c9297273abfba8f7743f1bc25f166b1.tar.xz
upgrade bevy to 0.17.0-rc.2
Diffstat (limited to 'azalea-client/src/plugins/packet/game')
-rw-r--r--azalea-client/src/plugins/packet/game/events.rs48
-rw-r--r--azalea-client/src/plugins/packet/game/mod.rs39
2 files changed, 39 insertions, 48 deletions
diff --git a/azalea-client/src/plugins/packet/game/events.rs b/azalea-client/src/plugins/packet/game/events.rs
index e341db3e..4ae51734 100644
--- a/azalea-client/src/plugins/packet/game/events.rs
+++ b/azalea-client/src/plugins/packet/game/events.rs
@@ -18,9 +18,9 @@ use crate::{client::InGameState, connection::RawConnection, player::PlayerInfo};
/// ```
/// # use azalea_client::packet::game::ReceiveGamePacketEvent;
/// # use azalea_protocol::packets::game::ClientboundGamePacket;
-/// # use bevy_ecs::event::EventReader;
+/// # use bevy_ecs::event::MessageReader;
///
-/// fn handle_packets(mut events: EventReader<ReceiveGamePacketEvent>) {
+/// fn handle_packets(mut events: MessageReader<ReceiveGamePacketEvent>) {
/// for ReceiveGamePacketEvent { entity, packet } in events.read() {
/// match packet.as_ref() {
/// ClientboundGamePacket::LevelParticles(p) => {
@@ -31,7 +31,7 @@ use crate::{client::InGameState, connection::RawConnection, player::PlayerInfo};
/// }
/// }
/// ```
-#[derive(Event, Debug, Clone)]
+#[derive(Message, Debug, Clone)]
pub struct ReceiveGamePacketEvent {
/// The client entity that received the packet.
pub entity: Entity,
@@ -40,8 +40,9 @@ pub struct ReceiveGamePacketEvent {
}
/// An event for sending a packet to the server while we're in the `game` state.
-#[derive(Event, Clone, Debug)]
+#[derive(EntityEvent, Clone, Debug)]
pub struct SendPacketEvent {
+ #[event_target]
pub sent_by: Entity,
pub packet: ServerboundGamePacket,
}
@@ -53,7 +54,7 @@ impl SendPacketEvent {
}
pub fn handle_outgoing_packets_observer(
- trigger: Trigger<SendPacketEvent>,
+ trigger: On<SendPacketEvent>,
mut query: Query<(&mut RawConnection, Option<&InGameState>)>,
) {
let event = trigger.event();
@@ -76,17 +77,9 @@ pub fn handle_outgoing_packets_observer(
}
}
-/// A system that converts [`SendPacketEvent`] events into triggers so they get
-/// received by [`handle_outgoing_packets_observer`].
-pub fn handle_outgoing_packets(mut commands: Commands, mut events: EventReader<SendPacketEvent>) {
- for event in events.read() {
- commands.trigger(event.clone());
- }
-}
-
/// A player joined the game (or more specifically, was added to the tab
/// list of a local player).
-#[derive(Event, Debug, Clone)]
+#[derive(Message, Debug, Clone)]
pub struct AddPlayerEvent {
/// The local player entity that received this event.
pub entity: Entity,
@@ -94,7 +87,7 @@ pub struct AddPlayerEvent {
}
/// A player left the game (or maybe is still in the game and was just
/// removed from the tab list of a local player).
-#[derive(Event, Debug, Clone)]
+#[derive(Message, Debug, Clone)]
pub struct RemovePlayerEvent {
/// The local player entity that received this event.
pub entity: Entity,
@@ -102,7 +95,7 @@ pub struct RemovePlayerEvent {
}
/// A player was updated in the tab list of a local player (gamemode, display
/// name, or latency changed).
-#[derive(Event, Debug, Clone)]
+#[derive(Message, Debug, Clone)]
pub struct UpdatePlayerEvent {
/// The local player entity that received this event.
pub entity: Entity,
@@ -112,7 +105,7 @@ pub struct UpdatePlayerEvent {
/// Event for when an entity dies. dies. If it's a local player and there's a
/// reason in the death screen, the [`ClientboundPlayerCombatKill`] will
/// be included.
-#[derive(Event, Debug, Clone)]
+#[derive(Message, Debug, Clone)]
pub struct DeathEvent {
pub entity: Entity,
pub packet: Option<ClientboundPlayerCombatKill>,
@@ -120,7 +113,7 @@ pub struct DeathEvent {
/// A KeepAlive packet is sent from the server to verify that the client is
/// still connected.
-#[derive(Event, Debug, Clone)]
+#[derive(Message, Debug, Clone)]
pub struct KeepAliveEvent {
pub entity: Entity,
/// The ID of the keepalive. This is an arbitrary number, but vanilla
@@ -128,7 +121,7 @@ pub struct KeepAliveEvent {
pub id: u64,
}
-#[derive(Event, Debug, Clone)]
+#[derive(Message, Debug, Clone)]
pub struct ResourcePackEvent {
pub entity: Entity,
/// The random ID for this request to download the resource pack. The packet
@@ -144,7 +137,7 @@ pub struct ResourcePackEvent {
///
/// Since the instance is given to you as a weak reference, it won't be able to
/// be `upgrade`d if all local players leave it.
-#[derive(Event, Debug, Clone)]
+#[derive(Message, Debug, Clone)]
pub struct InstanceLoadedEvent {
pub entity: Entity,
pub name: ResourceLocation,
@@ -156,15 +149,10 @@ pub struct InstanceLoadedEvent {
///
/// Also see [`ConfigPingEvent`] which is used for the config state.
///
-/// This is not an event and can't be listened to from a normal system,
-///so `EventReader<PingEvent>` will not work.
-///
-/// To use it, add your "system" with `add_observer` instead of `add_systems`
-/// and use `Trigger<PingEvent>` instead of `EventReader`.
-///
-/// The client Entity that received the packet will be attached to the trigger.
-///
/// [`ClientboundPing`]: azalea_protocol::packets::game::ClientboundPing
/// [`ConfigPingEvent`]: crate::packet::config::ConfigPingEvent
-#[derive(Event, Debug, Clone)]
-pub struct PingEvent(pub azalea_protocol::packets::game::ClientboundPing);
+#[derive(EntityEvent, Debug, Clone)]
+pub struct PingEvent {
+ pub entity: Entity,
+ pub packet: azalea_protocol::packets::game::ClientboundPing,
+}
diff --git a/azalea-client/src/plugins/packet/game/mod.rs b/azalea-client/src/plugins/packet/game/mod.rs
index fc8f34cf..dbdc8e26 100644
--- a/azalea-client/src/plugins/packet/game/mod.rs
+++ b/azalea-client/src/plugins/packet/game/mod.rs
@@ -207,7 +207,7 @@ impl GamePacketHandler<'_> {
),
With<LocalEntity>,
>,
- EventWriter<InstanceLoadedEvent>,
+ MessageWriter<InstanceLoadedEvent>,
ResMut<InstanceContainer>,
ResMut<EntityUuidIndex>,
Query<&mut LoadedBy, Without<LocalEntity>>,
@@ -336,7 +336,7 @@ impl GamePacketHandler<'_> {
// ends
debug!("Got chunk batch start");
- as_system::<EventWriter<_>>(self.ecs, |mut events| {
+ as_system::<MessageWriter<_>>(self.ecs, |mut events| {
events.write(chunks::ChunkBatchStartEvent {
entity: self.player,
});
@@ -346,7 +346,7 @@ impl GamePacketHandler<'_> {
pub fn chunk_batch_finished(&mut self, p: &ClientboundChunkBatchFinished) {
debug!("Got chunk batch finished {p:?}");
- as_system::<EventWriter<_>>(self.ecs, |mut events| {
+ as_system::<MessageWriter<_>>(self.ecs, |mut events| {
events.write(chunks::ChunkBatchFinishedEvent {
entity: self.player,
batch_size: p.batch_size,
@@ -387,7 +387,7 @@ impl GamePacketHandler<'_> {
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()),
@@ -440,8 +440,8 @@ impl GamePacketHandler<'_> {
as_system::<(
Query<&mut TabList>,
- EventWriter<AddPlayerEvent>,
- EventWriter<UpdatePlayerEvent>,
+ MessageWriter<AddPlayerEvent>,
+ MessageWriter<UpdatePlayerEvent>,
ResMut<TabList>,
)>(
self.ecs,
@@ -500,7 +500,7 @@ impl GamePacketHandler<'_> {
as_system::<(
Query<&mut TabList>,
- EventWriter<RemovePlayerEvent>,
+ MessageWriter<RemovePlayerEvent>,
ResMut<TabList>,
)>(
self.ecs,
@@ -542,7 +542,7 @@ impl GamePacketHandler<'_> {
pub fn level_chunk_with_light(&mut self, p: &ClientboundLevelChunkWithLight) {
debug!("Got chunk with light packet {} {}", p.x, p.z);
- as_system::<EventWriter<_>>(self.ecs, |mut events| {
+ as_system::<MessageWriter<_>>(self.ecs, |mut events| {
events.write(chunks::ReceiveChunkEvent {
entity: self.player,
packet: p.clone(),
@@ -740,7 +740,7 @@ impl GamePacketHandler<'_> {
instance_holder.partial_instance.clone(),
move |entity_mut| {
entity_mut.world_scope(|world| {
- world.send_event(KnockbackEvent { entity, knockback })
+ world.write_message(KnockbackEvent { entity, knockback })
});
},
));
@@ -957,7 +957,7 @@ impl GamePacketHandler<'_> {
pub fn keep_alive(&mut self, p: &ClientboundKeepAlive) {
debug!("Got keep alive packet {p:?} for {:?}", self.player);
- as_system::<(EventWriter<KeepAliveEvent>, Commands)>(
+ as_system::<(MessageWriter<KeepAliveEvent>, Commands)>(
self.ecs,
|(mut keepalive_events, mut commands)| {
keepalive_events.write(KeepAliveEvent {
@@ -1011,7 +1011,7 @@ impl GamePacketHandler<'_> {
pub fn player_chat(&mut self, p: &ClientboundPlayerChat) {
debug!("Got player chat packet {p:?}");
- as_system::<EventWriter<_>>(self.ecs, |mut events| {
+ as_system::<MessageWriter<_>>(self.ecs, |mut events| {
events.write(ChatReceivedEvent {
entity: self.player,
packet: ChatPacket::Player(Arc::new(p.clone())),
@@ -1022,7 +1022,7 @@ impl GamePacketHandler<'_> {
pub fn system_chat(&mut self, p: &ClientboundSystemChat) {
debug!("Got system chat packet {p:?}");
- as_system::<EventWriter<_>>(self.ecs, |mut events| {
+ as_system::<MessageWriter<_>>(self.ecs, |mut events| {
events.write(ChatReceivedEvent {
entity: self.player,
packet: ChatPacket::System(Arc::new(p.clone())),
@@ -1033,7 +1033,7 @@ impl GamePacketHandler<'_> {
pub fn disguised_chat(&mut self, p: &ClientboundDisguisedChat) {
debug!("Got disguised chat packet {p:?}");
- as_system::<EventWriter<_>>(self.ecs, |mut events| {
+ as_system::<MessageWriter<_>>(self.ecs, |mut events| {
events.write(ChatReceivedEvent {
entity: self.player,
packet: ChatPacket::Disguised(Arc::new(p.clone())),
@@ -1227,7 +1227,7 @@ impl GamePacketHandler<'_> {
pub fn explode(&mut self, p: &ClientboundExplode) {
trace!("Got explode packet {p:?}");
- as_system::<EventWriter<_>>(self.ecs, |mut knockback_events| {
+ as_system::<MessageWriter<_>>(self.ecs, |mut knockback_events| {
if let Some(knockback) = p.knockback {
knockback_events.write(KnockbackEvent {
entity: self.player,
@@ -1278,7 +1278,10 @@ impl GamePacketHandler<'_> {
debug!("Got ping packet {p:?}");
as_system::<Commands>(self.ecs, |mut commands| {
- commands.trigger_targets(PingEvent(p.clone()), self.player);
+ commands.trigger(PingEvent {
+ entity: self.player,
+ packet: p.clone(),
+ });
});
}
@@ -1294,7 +1297,7 @@ impl GamePacketHandler<'_> {
as_system::<(
Commands,
Query<(&MinecraftEntityId, Option<&Dead>)>,
- EventWriter<_>,
+ MessageWriter<_>,
)>(self.ecs, |(mut commands, mut query, mut events)| {
let (entity_id, dead) = query.get_mut(self.player).unwrap();
@@ -1315,7 +1318,7 @@ impl GamePacketHandler<'_> {
pub fn resource_pack_push(&mut self, p: &ClientboundResourcePackPush) {
debug!("Got resource pack 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,
@@ -1343,7 +1346,7 @@ impl GamePacketHandler<'_> {
),
With<LocalEntity>,
>,
- EventWriter<_>,
+ MessageWriter<_>,
ResMut<InstanceContainer>,
Query<&mut LoadedBy, Without<LocalEntity>>,
)>(