diff options
| author | mat <git@matdoes.dev> | 2025-08-12 20:50:40 -1030 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-08-12 20:50:40 -1030 |
| commit | 55a7db13ef028f5b6c6e87a81406b3525cea196f (patch) | |
| tree | 6a995bc0b46c527e9fab0874508f81e07deb673e /azalea-client/tests | |
| parent | ac66744586880afd657969ae078700a9749e293a (diff) | |
| download | azalea-drasl-55a7db13ef028f5b6c6e87a81406b3525cea196f.tar.xz | |
send correct packets on teleport
Diffstat (limited to 'azalea-client/tests')
| -rw-r--r-- | azalea-client/tests/packet_order.rs | 23 | ||||
| -rw-r--r-- | azalea-client/tests/teleport_movement.rs | 180 |
2 files changed, 191 insertions, 12 deletions
diff --git a/azalea-client/tests/packet_order.rs b/azalea-client/tests/packet_order.rs index 014d9f46..f9e3f43b 100644 --- a/azalea-client/tests/packet_order.rs +++ b/azalea-client/tests/packet_order.rs @@ -11,8 +11,7 @@ use azalea_protocol::{ config::{ClientboundFinishConfiguration, ClientboundRegistryData}, game::{ ClientboundBlockUpdate, ClientboundPlayerPosition, ServerboundAcceptTeleportation, - ServerboundGamePacket, ServerboundMovePlayerPos, ServerboundMovePlayerPosRot, - ServerboundMovePlayerStatusOnly, + ServerboundGamePacket, ServerboundMovePlayerPosRot, ServerboundMovePlayerStatusOnly, }, }, }; @@ -80,13 +79,15 @@ fn test_packet_order() { sent_packets.expect("MovePlayerPosRot", |p| { matches!( p, - ServerboundGamePacket::MovePlayerPosRot(ServerboundMovePlayerPosRot { + ServerboundGamePacket::MovePlayerPosRot(p) + if p == &ServerboundMovePlayerPosRot { flags: MoveFlags { on_ground: false, horizontal_collision: false }, - .. - }) + pos: Vec3::new(1.5, 2., 3.5), + look_direction: LookDirection::default(), + } ) }); @@ -99,13 +100,11 @@ fn test_packet_order() { sent_packets.expect("MovePlayerPos", |p| { matches!( p, - ServerboundGamePacket::MovePlayerPos(ServerboundMovePlayerPos { - flags: MoveFlags { - on_ground: false, - horizontal_collision: false - }, - .. - }) + ServerboundGamePacket::MovePlayerPos(p) + if p.flags == MoveFlags { + on_ground: false, + horizontal_collision: false + } ) }); diff --git a/azalea-client/tests/teleport_movement.rs b/azalea-client/tests/teleport_movement.rs new file mode 100644 index 00000000..a03e730c --- /dev/null +++ b/azalea-client/tests/teleport_movement.rs @@ -0,0 +1,180 @@ +use azalea_client::test_utils::prelude::*; +use azalea_core::{ + delta::PositionDelta8, + position::{BlockPos, ChunkPos, Vec3}, + resource_location::ResourceLocation, +}; +use azalea_entity::LookDirection; +use azalea_protocol::{ + common::movements::{MoveFlags, PositionMoveRotation, RelativeMovements}, + packets::{ + ConnectionProtocol, + config::{ClientboundFinishConfiguration, ClientboundRegistryData}, + game::{ + ClientboundBlockUpdate, ClientboundForgetLevelChunk, ClientboundPing, + ClientboundPlayerPosition, ClientboundSetChunkCacheCenter, ClientboundSetEntityMotion, + ServerboundGamePacket, ServerboundMovePlayerPos, ServerboundMovePlayerPosRot, + }, + }, +}; +use azalea_registry::{Block, DataRegistry, DimensionType}; +use azalea_world::MinecraftEntityId; +use simdnbt::owned::{NbtCompound, NbtTag}; + +#[test] +fn test_teleport_movement() { + init_tracing(); + + let mut simulation = Simulation::new(ConnectionProtocol::Configuration); + let sent_packets = SentPackets::new(&mut simulation); + + 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.tick(); + simulation.receive_packet(ClientboundFinishConfiguration); + simulation.tick(); + + simulation.receive_packet(make_basic_login_packet( + DimensionType::new_raw(0), // overworld + ResourceLocation::new("minecraft:overworld"), + )); + simulation.tick(); + + sent_packets.expect_tick_end(); + sent_packets.expect_empty(); + + // receive a chunk so the player is "loaded" now + simulation.receive_packet(ClientboundSetChunkCacheCenter { x: 1, z: 23 }); + simulation.receive_packet(make_basic_empty_chunk( + ChunkPos::new(1, 23), + (384 + 64) / 16, + )); + simulation.receive_packet(ClientboundBlockUpdate { + pos: BlockPos::new(31, 63, 370), + block_state: Block::Stone.into(), + }); + simulation.receive_packet(ClientboundPlayerPosition { + id: 1, + change: PositionMoveRotation { + pos: Vec3::new(31.5, 64., 370.5), + delta: Vec3::ZERO, + look_direction: LookDirection::default(), + }, + relative: RelativeMovements::all_absolute(), + }); + simulation.tick(); + simulation.tick(); + sent_packets.clear(); + + // now teleport to a far-away location + tracing::info!("meow!"); + simulation.receive_packet(ClientboundPing { id: 1 }); + simulation.receive_packet(ClientboundPlayerPosition { + id: 2, + change: PositionMoveRotation { + pos: Vec3::new(10000.5, 70.0, 0.5), + delta: Vec3::ZERO, + look_direction: LookDirection::default(), + }, + relative: RelativeMovements::all_absolute(), + }); + simulation.receive_packet(ClientboundPing { id: 2 }); + simulation.tick(); + sent_packets.expect_pong(1); + sent_packets.expect("AcceptTeleportation", |p| { + matches!(p, ServerboundGamePacket::AcceptTeleportation(_)) + }); + sent_packets.expect("MovePlayerPosRot", |p| { + matches!( + p, + ServerboundGamePacket::MovePlayerPosRot(p) + if p == &ServerboundMovePlayerPosRot { + pos: Vec3::new(10000.5, 70.0, 0.5), + flags: MoveFlags::default(), + look_direction: LookDirection::default(), + } + ) + }); + sent_packets.expect_pong(2); + sent_packets.expect("MovePlayerPos", |p| { + matches!( + p, + ServerboundGamePacket::MovePlayerPos(p) + if p == &ServerboundMovePlayerPos { + pos: Vec3::new(10000.5, 70.0, 0.5), + flags: MoveFlags::default() + } + ) + }); + + sent_packets.expect_tick_end(); + sent_packets.expect_empty(); + + // + + simulation.receive_packet(ClientboundForgetLevelChunk { + pos: ChunkPos { x: 1, z: 23 }, + }); + simulation.receive_packet(ClientboundSetChunkCacheCenter { x: 625, z: 0 }); + simulation.receive_packet(ClientboundPing { id: 3 }); + simulation.receive_packet(ClientboundPlayerPosition { + id: 3, + change: PositionMoveRotation { + pos: Vec3::new(10000.5, 70.0000001, 0.5), + delta: Vec3::ZERO, + look_direction: LookDirection::default(), + }, + relative: RelativeMovements::all_absolute(), + }); + simulation.receive_packet(ClientboundPing { id: 4 }); + simulation.receive_packet(ClientboundSetEntityMotion { + id: MinecraftEntityId(0), + delta: PositionDelta8 { + xa: 0, + ya: -627, + za: 0, + }, + }); + simulation.receive_packet(ClientboundPing { id: 5 }); + simulation.tick(); + + sent_packets.expect_pong(3); + sent_packets.expect("AcceptTeleportation", |p| { + matches!(p, ServerboundGamePacket::AcceptTeleportation(_)) + }); + sent_packets.expect("MovePlayerPosRot", |p| { + matches!( + p, + ServerboundGamePacket::MovePlayerPosRot(p) + if p == &ServerboundMovePlayerPosRot { + pos: Vec3::new(10000.5, 70.0000001, 0.5), + flags: MoveFlags::default(), + look_direction: LookDirection::default(), + }) + }); + sent_packets.expect_pong(4); + sent_packets.expect_pong(5); + sent_packets.expect("MovePlayerPos", |p| { + matches!( + p, + ServerboundGamePacket::MovePlayerPos(p) + if p == &ServerboundMovePlayerPos { + pos: Vec3::new(10000.5, 69.9216251, 0.5), + flags: MoveFlags::default() + } + ) + }); + + sent_packets.expect_tick_end(); + sent_packets.expect_empty(); +} |
