aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/tests/move_despawned_entity.rs
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-03-13 20:13:58 +0000
committermat <git@matdoes.dev>2025-03-13 20:13:58 +0000
commit7a192acc99358818c2f90cf4e2b8b236f91cfbf7 (patch)
treecf632093809a4e06eaf651399c365c137fb6cdd8 /azalea-client/tests/move_despawned_entity.rs
parente9a5df2e875fe845e098781a0bde4b6d8c0786f1 (diff)
downloadazalea-drasl-7a192acc99358818c2f90cf4e2b8b236f91cfbf7.tar.xz
properly remove from the EntityIdIndex component on despawn
Diffstat (limited to 'azalea-client/tests/move_despawned_entity.rs')
-rw-r--r--azalea-client/tests/move_despawned_entity.rs51
1 files changed, 51 insertions, 0 deletions
diff --git a/azalea-client/tests/move_despawned_entity.rs b/azalea-client/tests/move_despawned_entity.rs
new file mode 100644
index 00000000..74f7e942
--- /dev/null
+++ b/azalea-client/tests/move_despawned_entity.rs
@@ -0,0 +1,51 @@
+use azalea_client::test_simulation::*;
+use azalea_core::{position::ChunkPos, resource_location::ResourceLocation};
+use azalea_entity::metadata::Cow;
+use azalea_protocol::packets::{ConnectionProtocol, game::ClientboundMoveEntityRot};
+use azalea_registry::{DimensionType, EntityKind};
+use azalea_world::MinecraftEntityId;
+use bevy_ecs::query::With;
+use bevy_log::tracing_subscriber;
+
+#[test]
+fn test_move_despawned_entity() {
+ 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("azalea:overworld"),
+ ));
+
+ simulation.receive_packet(make_basic_empty_chunk(ChunkPos::new(0, 0), (384 + 64) / 16));
+ simulation.tick();
+ // spawn a cow
+ simulation.receive_packet(make_basic_add_entity(EntityKind::Cow, 123, (0.5, 64., 0.5)));
+ simulation.tick();
+
+ // make sure it's spawned
+ let mut cow_query = simulation.app.world_mut().query_filtered::<(), With<Cow>>();
+ let cow_iter = cow_query.iter(simulation.app.world());
+ assert_eq!(cow_iter.count(), 1, "cow should be despawned");
+
+ // despawn the cow by receiving a login packet
+ simulation.receive_packet(make_basic_login_packet(
+ DimensionType::new_raw(0),
+ ResourceLocation::new("azalea:overworld"),
+ ));
+ simulation.tick();
+
+ // make sure it's despawned
+ let mut cow_query = simulation.app.world_mut().query_filtered::<(), With<Cow>>();
+ let cow_iter = cow_query.iter(simulation.app.world());
+ assert_eq!(cow_iter.count(), 0, "cow should be despawned");
+
+ // send a move_entity_rot
+ simulation.receive_packet(ClientboundMoveEntityRot {
+ entity_id: MinecraftEntityId(123),
+ y_rot: 0,
+ x_rot: 0,
+ on_ground: false,
+ });
+ simulation.tick();
+}