diff options
| author | mat <git@matdoes.dev> | 2025-06-25 15:14:39 -1245 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-06-25 15:14:39 -1245 |
| commit | 08c409d04896e7057c31250f2d6f99c75b8af5b5 (patch) | |
| tree | 78c839b5d88f18df88dd1c562050f63d18814e41 /azalea-client/tests | |
| parent | f9e4b65713bbacabcd54416a388a92b90f56ab47 (diff) | |
| download | azalea-drasl-08c409d04896e7057c31250f2d6f99c75b8af5b5.tar.xz | |
improve packet_order test, add BlockUpdatePlugin, fix packet order for sprinting
Diffstat (limited to 'azalea-client/tests')
| -rw-r--r-- | azalea-client/tests/packet_order.rs | 91 |
1 files changed, 82 insertions, 9 deletions
diff --git a/azalea-client/tests/packet_order.rs b/azalea-client/tests/packet_order.rs index 1d3b29a2..d4dd2558 100644 --- a/azalea-client/tests/packet_order.rs +++ b/azalea-client/tests/packet_order.rs @@ -1,26 +1,32 @@ use std::{collections::VecDeque, sync::Arc}; -use azalea_client::{packet::game::SendPacketEvent, test_utils::prelude::*}; +use azalea_client::{ + SprintDirection, StartSprintEvent, packet::game::SendPacketEvent, test_utils::prelude::*, +}; use azalea_core::{ - position::{ChunkPos, Vec3}, + position::{BlockPos, ChunkPos, Vec3}, resource_location::ResourceLocation, }; use azalea_entity::LookDirection; use azalea_protocol::{ - common::movements::{PositionMoveRotation, RelativeMovements}, + common::movements::{MoveFlags, PositionMoveRotation, RelativeMovements}, packets::{ ConnectionProtocol, config::{ClientboundFinishConfiguration, ClientboundRegistryData}, - game::{ClientboundPlayerPosition, ServerboundAcceptTeleportation, ServerboundGamePacket}, + game::{ + ClientboundBlockUpdate, ClientboundPlayerPosition, ServerboundAcceptTeleportation, + ServerboundGamePacket, ServerboundMovePlayerPos, ServerboundMovePlayerPosRot, + ServerboundMovePlayerStatusOnly, + }, }, }; -use azalea_registry::{DataRegistry, DimensionType}; +use azalea_registry::{Block, DataRegistry, DimensionType}; use bevy_ecs::observer::Trigger; use parking_lot::Mutex; use simdnbt::owned::{NbtCompound, NbtTag}; #[test] -fn test_set_health_before_login() { +fn test_packet_order() { init_tracing(); let mut simulation = Simulation::new(ConnectionProtocol::Configuration); @@ -53,16 +59,26 @@ fn test_set_health_before_login() { // receive a chunk so the player is "loaded" now simulation.receive_packet(make_basic_empty_chunk(ChunkPos::new(0, 0), (384 + 64) / 16)); + simulation.receive_packet(ClientboundBlockUpdate { + pos: BlockPos::new(1, 1, 3), + block_state: Block::Stone.into(), + }); simulation.receive_packet(ClientboundPlayerPosition { id: 1, change: PositionMoveRotation { - pos: Vec3::new(1., 2., 3.), + pos: Vec3::new(1.5, 2., 3.5), delta: Vec3::ZERO, look_direction: LookDirection::default(), }, relative: RelativeMovements::all_absolute(), }); simulation.tick(); + + assert_eq!( + simulation.get_block_state(BlockPos::new(1, 1, 3)), + Some(Block::Stone.into()) + ); + println!("sent_packets: {:?}", sent_packets.list.lock()); sent_packets.expect("AcceptTeleportation", |p| { matches!( @@ -71,7 +87,16 @@ fn test_set_health_before_login() { ) }); sent_packets.expect("MovePlayerPosRot", |p| { - matches!(p, ServerboundGamePacket::MovePlayerPosRot(_)) + matches!( + p, + ServerboundGamePacket::MovePlayerPosRot(ServerboundMovePlayerPosRot { + flags: MoveFlags { + on_ground: false, + horizontal_collision: false + }, + .. + }) + ) }); // in vanilla these might be sent in a later tick (depending on how long it @@ -81,11 +106,59 @@ fn test_set_health_before_login() { matches!(p, ServerboundGamePacket::PlayerLoaded(_)) }); sent_packets.expect("MovePlayerPos", |p| { - matches!(p, ServerboundGamePacket::MovePlayerPos(_)) + matches!( + p, + ServerboundGamePacket::MovePlayerPos(ServerboundMovePlayerPos { + flags: MoveFlags { + on_ground: false, + horizontal_collision: false + }, + .. + }) + ) }); sent_packets.expect_tick_end(); sent_packets.expect_empty(); + + // it takes a tick for on_ground to be true + simulation.tick(); + sent_packets.expect("MovePlayerStatusOnly", |p| { + matches!( + p, + ServerboundGamePacket::MovePlayerStatusOnly(ServerboundMovePlayerStatusOnly { + flags: MoveFlags { + on_ground: true, + horizontal_collision: false + } + }) + ) + }); + sent_packets.expect_tick_end(); + sent_packets.expect_empty(); + + // make sure nothing happens now + simulation.tick(); + sent_packets.expect_tick_end(); + sent_packets.expect_empty(); + + // now sprint for a tick + simulation.send_event(StartSprintEvent { + entity: simulation.entity, + direction: SprintDirection::Forward, + }); + simulation.tick(); + sent_packets.expect("PlayerInput", |p| { + matches!(p, ServerboundGamePacket::PlayerInput(_)) + }); + sent_packets.expect("PlayerCommand", |p| { + matches!(p, ServerboundGamePacket::PlayerCommand(_)) + }); + sent_packets.expect("MovePlayerPos", |p| { + matches!(p, ServerboundGamePacket::MovePlayerPos(_)) + }); + sent_packets.expect_tick_end(); + sent_packets.expect_empty(); } #[derive(Clone)] |
