diff options
| author | Kumpelinus <kumpelinus@jat.de> | 2025-07-21 22:28:41 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-21 15:28:41 -0500 |
| commit | df9d776ff8e3945ce7d367e6cecb54957ee0fd7a (patch) | |
| tree | aa72f41953fb05e69b660b092d13ecd76e77c1bd /azalea-client/tests | |
| parent | ebc2e0c067d8b2c901ae02e032159e2c80eac7bc (diff) | |
| download | azalea-drasl-df9d776ff8e3945ce7d367e6cecb54957ee0fd7a.tar.xz | |
Add TicksAlive component (#229)
* Add TicksAlive component
* Rename TicksAlive to TicksConnected
* Move component to plugins/tick_counter.rs and add doc comment
Diffstat (limited to 'azalea-client/tests')
| -rw-r--r-- | azalea-client/tests/ticks_alive.rs | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/azalea-client/tests/ticks_alive.rs b/azalea-client/tests/ticks_alive.rs new file mode 100644 index 00000000..3be9a09c --- /dev/null +++ b/azalea-client/tests/ticks_alive.rs @@ -0,0 +1,57 @@ +use azalea_client::{test_utils::prelude::*, tick_counter::TicksConnected}; +use azalea_core::resource_location::ResourceLocation; +use azalea_protocol::packets::{config::{ClientboundFinishConfiguration, ClientboundRegistryData}, ConnectionProtocol}; +use azalea_registry::{DataRegistry, DimensionType}; +use simdnbt::owned::{NbtCompound, NbtTag}; + +#[test] +fn counter_increments_and_resets_on_disconnect() { + init_tracing(); + + let mut simulation = Simulation::new(ConnectionProtocol::Configuration); + + 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); + + simulation.tick(); + // we need a second tick to handle the state switch properly + simulation.tick(); + + assert!(!simulation.has_component::<TicksConnected>()); + + simulation.receive_packet(make_basic_login_packet( + DimensionType::new_raw(0), // overworld + ResourceLocation::new("minecraft:overworld"), + )); + simulation.tick(); + + assert!(simulation.has_component::<TicksConnected>()); + assert_eq!(simulation.component::<TicksConnected>().0, 1); + + // Tick three times; counter should read 2, 3, 4. + for expected in 2..=4 { + simulation.tick(); + let counter = simulation.component::<TicksConnected>(); + assert_eq!( + counter.0, expected, + "after {expected} tick(s) counter should be {expected}" + ); + } + + simulation.disconnect(); + simulation.tick(); + + assert!(!simulation.has_component::<TicksConnected>()); +} |
