diff options
Diffstat (limited to 'azalea-client/tests')
4 files changed, 93 insertions, 22 deletions
diff --git a/azalea-client/tests/change_dimension_to_nether_and_back.rs b/azalea-client/tests/change_dimension_to_nether_and_back.rs index 748ea713..969c5053 100644 --- a/azalea-client/tests/change_dimension_to_nether_and_back.rs +++ b/azalea-client/tests/change_dimension_to_nether_and_back.rs @@ -2,7 +2,7 @@ use azalea_client::{InConfigState, InGameState, test_simulation::*}; use azalea_core::{position::ChunkPos, resource_location::ResourceLocation}; use azalea_entity::LocalEntity; use azalea_protocol::packets::{ - ConnectionProtocol, + ConnectionProtocol, Packet, config::{ClientboundFinishConfiguration, ClientboundRegistryData}, }; use azalea_registry::DimensionType; @@ -12,6 +12,21 @@ use simdnbt::owned::{NbtCompound, NbtTag}; #[test] fn test_change_dimension_to_nether_and_back() { + generic_test_change_dimension_to_nether_and_back(true); + generic_test_change_dimension_to_nether_and_back(false); +} + +fn generic_test_change_dimension_to_nether_and_back(using_respawn: bool) { + let make_basic_login_or_respawn_packet = if using_respawn { + |dimension: DimensionType, instance_name: ResourceLocation| { + make_basic_respawn_packet(dimension, instance_name).into_variant() + } + } else { + |dimension: DimensionType, instance_name: ResourceLocation| { + make_basic_login_packet(dimension, instance_name).into_variant() + } + }; + let _ = tracing_subscriber::fmt::try_init(); let mut simulation = Simulation::new(ConnectionProtocol::Configuration); @@ -83,7 +98,7 @@ fn test_change_dimension_to_nether_and_back() { // NETHER // - simulation.receive_packet(make_basic_respawn_packet( + simulation.receive_packet(make_basic_login_or_respawn_packet( DimensionType::new_raw(2), // nether ResourceLocation::new("azalea:b"), )); @@ -105,7 +120,7 @@ fn test_change_dimension_to_nether_and_back() { simulation .chunk(ChunkPos::new(0, 0)) .expect("chunk should exist"); - simulation.receive_packet(make_basic_respawn_packet( + simulation.receive_packet(make_basic_login_or_respawn_packet( DimensionType::new_raw(2), // nether ResourceLocation::new("minecraft:nether"), )); diff --git a/azalea-client/tests/client_disconnect.rs b/azalea-client/tests/client_disconnect.rs new file mode 100644 index 00000000..354ac788 --- /dev/null +++ b/azalea-client/tests/client_disconnect.rs @@ -0,0 +1,21 @@ +use azalea_client::test_simulation::*; +use azalea_protocol::packets::ConnectionProtocol; +use azalea_world::InstanceName; +use bevy_log::tracing_subscriber; + +#[test] +fn test_client_disconnect() { + let _ = tracing_subscriber::fmt::try_init(); + + let mut simulation = Simulation::new(ConnectionProtocol::Game); + + simulation.disconnect(); + simulation.tick(); + + // make sure we're disconnected + let is_connected = simulation.has_component::<InstanceName>(); + assert!(!is_connected); + + // tick again to make sure nothing goes wrong + simulation.tick(); +} diff --git a/azalea-client/tests/despawn_entities_when_changing_dimension.rs b/azalea-client/tests/despawn_entities_when_changing_dimension.rs index 133506c9..3d7f2cb4 100644 --- a/azalea-client/tests/despawn_entities_when_changing_dimension.rs +++ b/azalea-client/tests/despawn_entities_when_changing_dimension.rs @@ -1,20 +1,14 @@ use azalea_client::test_simulation::*; -use azalea_core::{ - delta::PositionDelta8, - position::{ChunkPos, Vec3}, - resource_location::ResourceLocation, -}; +use azalea_core::{position::ChunkPos, resource_location::ResourceLocation}; use azalea_entity::metadata::Cow; use azalea_protocol::packets::{ ConnectionProtocol, config::{ClientboundFinishConfiguration, ClientboundRegistryData}, - game::ClientboundAddEntity, }; -use azalea_registry::DimensionType; +use azalea_registry::{DimensionType, EntityKind}; use bevy_ecs::query::With; use bevy_log::tracing_subscriber; use simdnbt::owned::{NbtCompound, NbtTag}; -use uuid::Uuid; #[test] fn test_despawn_entities_when_changing_dimension() { @@ -59,17 +53,7 @@ fn test_despawn_entities_when_changing_dimension() { simulation.receive_packet(make_basic_empty_chunk(ChunkPos::new(0, 0), (384 + 64) / 16)); simulation.tick(); // spawn a cow - simulation.receive_packet(ClientboundAddEntity { - id: 123.into(), - uuid: Uuid::from_u128(1234), - entity_type: azalea_registry::EntityKind::Cow, - position: Vec3::new(0., 64., 0.), - x_rot: 0, - y_rot: 0, - y_head_rot: 0, - data: 0, - velocity: PositionDelta8::default(), - }); + 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>>(); 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(); +} |
