From be81877137df57de26030bceecbef68b9f05b3e5 Mon Sep 17 00:00:00 2001 From: mat Date: Wed, 4 Jun 2025 21:53:06 -0600 Subject: [PATCH] fix panic when receiving add_entity and start_configuration in the same update --- ...ve_spawn_entity_and_start_config_packet.rs | 42 +++++++++++++++++++ azalea-entity/src/plugin/mod.rs | 5 +++ 2 files changed, 47 insertions(+) create mode 100644 azalea-client/tests/receive_spawn_entity_and_start_config_packet.rs diff --git a/azalea-client/tests/receive_spawn_entity_and_start_config_packet.rs b/azalea-client/tests/receive_spawn_entity_and_start_config_packet.rs new file mode 100644 index 00000000..d64d2209 --- /dev/null +++ b/azalea-client/tests/receive_spawn_entity_and_start_config_packet.rs @@ -0,0 +1,42 @@ +use azalea_client::{InConfigState, test_simulation::*}; +use azalea_core::{position::Vec3, resource_location::ResourceLocation}; +use azalea_protocol::packets::{ + ConnectionProtocol, + game::{ClientboundAddEntity, ClientboundStartConfiguration}, +}; +use azalea_registry::{DataRegistry, DimensionType, EntityKind}; +use azalea_world::InstanceName; +use bevy_log::tracing_subscriber; +use uuid::Uuid; + +#[test] +fn test_receive_spawn_entity_and_start_config_packet() { + let _ = tracing_subscriber::fmt::try_init(); + + let mut simulation = Simulation::new(ConnectionProtocol::Game); + simulation.receive_packet(make_basic_login_packet( + DimensionType::new_raw(0), + ResourceLocation::new("minecraft:overworld"), + )); + simulation.tick(); + assert!(simulation.has_component::()); + simulation.tick(); + + simulation.receive_packet(ClientboundAddEntity { + id: 123.into(), + uuid: Uuid::new_v4(), + entity_type: EntityKind::ArmorStand, + position: Vec3::ZERO, + x_rot: 0, + y_rot: 0, + y_head_rot: 0, + data: 0, + velocity: Default::default(), + }); + simulation.receive_packet(ClientboundStartConfiguration); + + simulation.tick(); + assert!(simulation.has_component::()); + + // make sure that the entity is despawned +} diff --git a/azalea-entity/src/plugin/mod.rs b/azalea-entity/src/plugin/mod.rs index 03afe7cd..6a6c9615 100644 --- a/azalea-entity/src/plugin/mod.rs +++ b/azalea-entity/src/plugin/mod.rs @@ -46,6 +46,11 @@ impl Plugin for EntityPlugin { Update, ( ( + // remove_despawned_entities_from_indexes is done again here to correctly + // handle the case where an entity is spawned and then the world is removed at + // the same time (like with ClientboundStartConfiguration). + indexing::remove_despawned_entities_from_indexes + .in_set(EntityUpdateSet::Deindex), indexing::update_entity_chunk_positions, indexing::insert_entity_chunk_position, )