aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src/packet_handling.rs
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2023-09-16 22:30:28 -0500
committermat <git@matdoes.dev>2023-09-16 22:30:28 -0500
commit61e63c08968f7b0f451c4c3b07ea8d4927b14a2f (patch)
treef7b489bedde2a3bb9f703aa542c6863191f00ced /azalea-client/src/packet_handling.rs
parenta920359c9a8f254bbfb6c1d04f2bda6365c09c6b (diff)
downloadazalea-drasl-61e63c08968f7b0f451c4c3b07ea8d4927b14a2f.tar.xz
don't apply metadata updates multiple times in swarms
Diffstat (limited to 'azalea-client/src/packet_handling.rs')
-rw-r--r--azalea-client/src/packet_handling.rs35
1 files changed, 24 insertions, 11 deletions
diff --git a/azalea-client/src/packet_handling.rs b/azalea-client/src/packet_handling.rs
index de88665e..0522d7e5 100644
--- a/azalea-client/src/packet_handling.rs
+++ b/azalea-client/src/packet_handling.rs
@@ -634,11 +634,11 @@ pub fn process_packet_events(ecs: &mut World) {
let mut system_state: SystemState<(
Commands,
- Query<&EntityIdIndex>,
+ Query<(&EntityIdIndex, &LocalPlayer)>,
Query<&EntityKind>,
)> = SystemState::new(ecs);
let (mut commands, mut query, entity_kind_query) = system_state.get_mut(ecs);
- let entity_id_index = query.get_mut(player_entity).unwrap();
+ let (entity_id_index, local_player) = query.get_mut(player_entity).unwrap();
let entity = entity_id_index.get(&MinecraftEntityId(p.id));
@@ -646,15 +646,28 @@ pub fn process_packet_events(ecs: &mut World) {
warn!("Server sent an entity data packet for an entity id ({}) that we don't know about", p.id);
continue;
};
- let entity_kind = entity_kind_query.get(entity).unwrap();
- let mut entity_commands = commands.entity(entity);
- if let Err(e) = apply_metadata(
- &mut entity_commands,
- **entity_kind,
- (*p.packed_items).clone(),
- ) {
- warn!("{e}");
- }
+ let entity_kind = *entity_kind_query.get(entity).unwrap();
+
+ // we use RelativeEntityUpdate because it makes sure changes aren't made
+ // multiple times
+ commands.entity(entity).add(RelativeEntityUpdate {
+ partial_world: local_player.partial_instance.clone(),
+ update: Box::new(move |entity| {
+ let entity_id = entity.id();
+ entity.world_scope(|world| {
+ let mut commands_system_state = SystemState::<Commands>::new(world);
+ let mut commands = commands_system_state.get_mut(world);
+ let mut entity_comands = commands.entity(entity_id);
+ if let Err(e) = apply_metadata(
+ &mut entity_comands,
+ *entity_kind,
+ (*p.packed_items).clone(),
+ ) {
+ warn!("{e}");
+ }
+ });
+ }),
+ });
system_state.apply(ecs);
}