diff options
| author | mat <git@matdoes.dev> | 2025-03-02 05:42:15 +0000 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-03-02 05:42:15 +0000 |
| commit | c9022e8f671b5838f4d4ab446013c42191b07f37 (patch) | |
| tree | e07cc01bc86653704e46ff976493a555d5abed8c /azalea-client/tests | |
| parent | 72d87349feaf0240848b735be94448836e0bf4e5 (diff) | |
| download | azalea-drasl-c9022e8f671b5838f4d4ab446013c42191b07f37.tar.xz | |
fix errors when switching to Game state and add fast_login test
Diffstat (limited to 'azalea-client/tests')
| -rw-r--r-- | azalea-client/tests/change_dimension_to_nether_and_back.rs | 15 | ||||
| -rw-r--r-- | azalea-client/tests/fast_login.rs | 43 |
2 files changed, 47 insertions, 11 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 16febca0..748ea713 100644 --- a/azalea-client/tests/change_dimension_to_nether_and_back.rs +++ b/azalea-client/tests/change_dimension_to_nether_and_back.rs @@ -1,10 +1,9 @@ -use azalea_client::{InConfigState, test_simulation::*}; +use azalea_client::{InConfigState, InGameState, test_simulation::*}; use azalea_core::{position::ChunkPos, resource_location::ResourceLocation}; -use azalea_entity::{LocalEntity, metadata::Health}; +use azalea_entity::LocalEntity; use azalea_protocol::packets::{ ConnectionProtocol, config::{ClientboundFinishConfiguration, ClientboundRegistryData}, - game::ClientboundSetHealth, }; use azalea_registry::DimensionType; use azalea_world::InstanceName; @@ -17,6 +16,7 @@ fn test_change_dimension_to_nether_and_back() { let mut simulation = Simulation::new(ConnectionProtocol::Configuration); assert!(simulation.has_component::<InConfigState>()); + assert!(!simulation.has_component::<InGameState>()); simulation.receive_packet(ClientboundRegistryData { registry_id: ResourceLocation::new("minecraft:dimension_type"), @@ -53,16 +53,9 @@ fn test_change_dimension_to_nether_and_back() { simulation.tick(); assert!(!simulation.has_component::<InConfigState>()); + assert!(simulation.has_component::<InGameState>()); assert!(simulation.has_component::<LocalEntity>()); - simulation.receive_packet(ClientboundSetHealth { - health: 15., - food: 20, - saturation: 20., - }); - simulation.tick(); - assert_eq!(*simulation.component::<Health>(), 15.); - // // OVERWORLD // diff --git a/azalea-client/tests/fast_login.rs b/azalea-client/tests/fast_login.rs new file mode 100644 index 00000000..bc26079a --- /dev/null +++ b/azalea-client/tests/fast_login.rs @@ -0,0 +1,43 @@ +use azalea_client::{InConfigState, test_simulation::*}; +use azalea_core::resource_location::ResourceLocation; +use azalea_entity::metadata::Health; +use azalea_protocol::packets::{ + ConnectionProtocol, + config::{ClientboundFinishConfiguration, ClientboundRegistryData}, + game::ClientboundSetHealth, +}; +use bevy_log::tracing_subscriber; +use simdnbt::owned::{NbtCompound, NbtTag}; + +#[test] +fn test_fast_login() { + let _ = tracing_subscriber::fmt::try_init(); + + let mut simulation = Simulation::new(ConnectionProtocol::Configuration); + assert!(simulation.has_component::<InConfigState>()); + + simulation.receive_packet(ClientboundRegistryData { + registry_id: ResourceLocation::new("minecraft:dimension_type"), + entries: vec![( + ResourceLocation::new("minecraft:overworld"), + Some(NbtCompound::from_values(vec![ + ("height".into(), NbtTag::Int(384)), + ("min_y".into(), NbtTag::Int(-64)), + ])), + )] + .into_iter() + .collect(), + }); + + simulation.receive_packet(ClientboundFinishConfiguration); + // note that there's no simulation tick here + simulation.receive_packet(ClientboundSetHealth { + health: 15., + food: 20, + saturation: 20., + }); + simulation.tick(); + // we need a second tick to handle the state switch properly + simulation.tick(); + assert_eq!(*simulation.component::<Health>(), 15.); +} |
