aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2026-02-22 18:41:46 -0845
committermat <git@matdoes.dev>2026-02-22 18:41:46 -0845
commit341e99403b3b215a4ef09b02c0bd9ee40ac4205f (patch)
tree6653bd00d48b73e8464d05ddca01ed8a5cd2a93d
parentb4e4d2c001dddd530c6e416e841c571c7e127138 (diff)
downloadazalea-drasl-341e99403b3b215a4ef09b02c0bd9ee40ac4205f.tar.xz
use should_apply_entity_update for move_entity_pos packets
-rw-r--r--azalea-client/src/plugins/packet/game/mod.rs100
-rw-r--r--azalea-client/src/plugins/packet/relative_updates.rs6
2 files changed, 62 insertions, 44 deletions
diff --git a/azalea-client/src/plugins/packet/game/mod.rs b/azalea-client/src/plugins/packet/game/mod.rs
index 9f16c204..7b2fa8b7 100644
--- a/azalea-client/src/plugins/packet/game/mod.rs
+++ b/azalea-client/src/plugins/packet/game/mod.rs
@@ -842,10 +842,15 @@ impl GamePacketHandler<'_> {
pub fn rotate_head(&mut self, _p: &ClientboundRotateHead) {}
pub fn move_entity_pos(&mut self, p: &ClientboundMoveEntityPos) {
- as_system::<(Commands, Query<(&EntityIdIndex, &WorldHolder)>)>(
+ as_system::<(
+ Commands,
+ Query<(&EntityIdIndex, &WorldHolder)>,
+ Query<(&mut Physics, &mut Position)>,
+ EntityUpdateQuery,
+ )>(
self.ecs,
- |(mut commands, query)| {
- let (entity_id_index, world_holder) = query.get(self.player).unwrap();
+ |(mut commands, player_query, mut entity_query, entity_update_query)| {
+ let (entity_id_index, world_holder) = player_query.get(self.player).unwrap();
debug!("Got move entity pos packet {p:?}");
@@ -857,34 +862,41 @@ impl GamePacketHandler<'_> {
let new_delta = p.delta.clone();
let new_on_ground = p.on_ground;
- commands.entity(entity).queue(RelativeEntityUpdate::new(
- world_holder.partial.clone(),
- move |entity_mut| {
- let mut physics = entity_mut.get_mut::<Physics>().unwrap();
- let new_pos = physics.vec_delta_codec.decode(&new_delta);
- physics.vec_delta_codec.set_base(new_pos);
- physics.set_on_ground(new_on_ground);
-
- let mut position = entity_mut.get_mut::<Position>().unwrap();
- if new_pos != **position {
- **position = new_pos;
- }
- trace!(
- "Applied movement update for {entity_id} / {entity}",
- entity = entity_mut.id()
- );
- },
- ));
+ let (mut physics, mut position) = entity_query.get_mut(entity).unwrap();
+
+ if !should_apply_entity_update(
+ &mut commands,
+ &mut world_holder.partial.write(),
+ entity,
+ entity_update_query,
+ ) {
+ return;
+ }
+
+ let new_pos = physics.vec_delta_codec.decode(&new_delta);
+ physics.vec_delta_codec.set_base(new_pos);
+ physics.set_on_ground(new_on_ground);
+
+ if new_pos != **position {
+ **position = new_pos;
+ }
+
+ trace!("Applied movement update for {entity_id} / {entity}");
},
);
}
pub fn move_entity_pos_rot(&mut self, p: &ClientboundMoveEntityPosRot) {
- as_system::<(Commands, Query<(&EntityIdIndex, &WorldHolder)>)>(
+ as_system::<(
+ Commands,
+ Query<(&EntityIdIndex, &WorldHolder)>,
+ Query<(&mut Physics, &mut Position, &mut LookDirection)>,
+ EntityUpdateQuery,
+ )>(
self.ecs,
- |(mut commands, query)| {
- let (entity_id_index, world_holder) = query.get(self.player).unwrap();
+ |(mut commands, player_query, mut entity_query, entity_update_query)| {
+ let (entity_id_index, world_holder) = player_query.get(self.player).unwrap();
debug!("Got move entity pos rot packet {p:?}");
@@ -907,25 +919,29 @@ impl GamePacketHandler<'_> {
let new_on_ground = p.on_ground;
- commands.entity(entity).queue(RelativeEntityUpdate::new(
- world_holder.partial.clone(),
- move |entity_mut| {
- let mut physics = entity_mut.get_mut::<Physics>().unwrap();
- let new_position = physics.vec_delta_codec.decode(&new_delta);
- physics.vec_delta_codec.set_base(new_position);
- physics.set_on_ground(new_on_ground);
-
- let mut position = entity_mut.get_mut::<Position>().unwrap();
- if new_position != **position {
- **position = new_position;
- }
+ let (mut physics, mut position, mut look_direction) =
+ entity_query.get_mut(entity).unwrap();
- let mut look_direction = entity_mut.get_mut::<LookDirection>().unwrap();
- if new_look_direction != *look_direction {
- *look_direction = new_look_direction;
- }
- },
- ));
+ if !should_apply_entity_update(
+ &mut commands,
+ &mut world_holder.partial.write(),
+ entity,
+ entity_update_query,
+ ) {
+ return;
+ }
+
+ let new_position = physics.vec_delta_codec.decode(&new_delta);
+ physics.vec_delta_codec.set_base(new_position);
+ physics.set_on_ground(new_on_ground);
+
+ if new_position != **position {
+ **position = new_position;
+ }
+
+ if new_look_direction != *look_direction {
+ *look_direction = new_look_direction;
+ }
},
);
}
diff --git a/azalea-client/src/plugins/packet/relative_updates.rs b/azalea-client/src/plugins/packet/relative_updates.rs
index 2f7112b8..d6367829 100644
--- a/azalea-client/src/plugins/packet/relative_updates.rs
+++ b/azalea-client/src/plugins/packet/relative_updates.rs
@@ -23,7 +23,7 @@ use azalea_world::PartialWorld;
use bevy_ecs::prelude::*;
use derive_more::{Deref, DerefMut};
use parking_lot::RwLock;
-use tracing::warn;
+use tracing::{debug, warn};
use crate::packet::as_system;
@@ -94,7 +94,9 @@ pub fn should_apply_entity_update(
let Ok((minecraft_entity_id, updates_received, local_entity)) = entity_update_query.get(entity)
else {
- warn!("called should_apply_entity_update on an entity with missing components");
+ // this can happen when the entity despawns in the same Update that we got a
+ // relative update for it
+ debug!("called should_apply_entity_update on an entity with missing components {entity:?}");
return false;
};