diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2025-08-14 20:40:13 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-14 20:40:13 -0500 |
| commit | e74ed047dbaf3877db4a89a2d589e992abd0bb11 (patch) | |
| tree | 0a728c8be167a1d59a5492ed9df666f41cf12e57 /azalea-client/tests | |
| parent | 6695132ddb31780786c67b8b9ff5df8ab3891438 (diff) | |
| download | azalea-drasl-e74ed047dbaf3877db4a89a2d589e992abd0bb11.tar.xz | |
Sneaking (#237)
* start implementing sneaking
* fix horizontal_collision being inverted and cleanup
* clippy
* change dimensions and eye height based on pose
* proper support for automatically crouching in certain cases
* fix anticheat issues
* add line to changelog and update a comment
Diffstat (limited to 'azalea-client/tests')
| -rw-r--r-- | azalea-client/tests/correct_sneak_movement.rs | 135 | ||||
| -rw-r--r-- | azalea-client/tests/correct_sprint_sneak_movement.rs | 153 |
2 files changed, 288 insertions, 0 deletions
diff --git a/azalea-client/tests/correct_sneak_movement.rs b/azalea-client/tests/correct_sneak_movement.rs new file mode 100644 index 00000000..cf1d17b5 --- /dev/null +++ b/azalea-client/tests/correct_sneak_movement.rs @@ -0,0 +1,135 @@ +use azalea_client::{PhysicsState, StartWalkEvent, WalkDirection, test_utils::prelude::*}; +use azalea_core::{ + position::{BlockPos, ChunkPos, Vec3}, + resource_location::ResourceLocation, +}; +use azalea_entity::LookDirection; +use azalea_protocol::{ + common::movements::{PositionMoveRotation, RelativeMovements}, + packets::{ + ConnectionProtocol, + config::{ClientboundFinishConfiguration, ClientboundRegistryData}, + game::{ + ClientboundBlockUpdate, ClientboundPlayerPosition, ServerboundGamePacket, + ServerboundPlayerInput, + }, + }, +}; +use azalea_registry::{Block, DataRegistry, DimensionType}; +use simdnbt::owned::{NbtCompound, NbtTag}; + +#[test] +fn test_correct_sneak_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(); + + simulation.receive_packet(make_basic_empty_chunk(ChunkPos::new(0, 0), (384 + 64) / 16)); + simulation.receive_packet(ClientboundBlockUpdate { + pos: BlockPos::new(0, 119, 0), + block_state: Block::Stone.into(), + }); + simulation.receive_packet(ClientboundBlockUpdate { + pos: BlockPos::new(0, 119, 1), + block_state: Block::Stone.into(), + }); + simulation.receive_packet(ClientboundPlayerPosition { + id: 1, + change: PositionMoveRotation { + pos: Vec3::new(0.5, 120., 0.5), + delta: Vec3::ZERO, + look_direction: LookDirection::default(), + }, + relative: RelativeMovements::all_absolute(), + }); + simulation.tick(); + simulation.tick(); + simulation.tick(); + sent_packets.clear(); + + simulation.with_component_mut::<PhysicsState>(|p| p.trying_to_crouch = true); + simulation.tick(); + sent_packets.expect("PlayerInput", |p| { + matches!( + p, + ServerboundGamePacket::PlayerInput(p) + if *p == ServerboundPlayerInput { shift: true, ..Default::default() } + ) + }); + sent_packets.expect_tick_end(); + sent_packets.expect_empty(); + + simulation.tick(); + simulation.send_event(StartWalkEvent { + entity: simulation.entity, + direction: WalkDirection::Forward, + }); + sent_packets.expect_tick_end(); + sent_packets.expect_empty(); + + simulation.tick(); + sent_packets.expect("PlayerInput", |p| { + matches!( + p, + ServerboundGamePacket::PlayerInput(p) + if *p == ServerboundPlayerInput { forward: true, shift: true, ..Default::default() } + ) + }); + sent_packets.expect("MovePlayerPos { z: 0.5294000033944846 }", |p| { + matches!( + p, + ServerboundGamePacket::MovePlayerPos(p) + if p.pos == Vec3::new(0.5, 120., 0.5294000033944846) + ) + }); + sent_packets.expect_tick_end(); + sent_packets.expect_empty(); + + simulation.tick(); + sent_packets.expect("MovePlayerPos { z: 0.5748524105068866 }", |p| { + matches!( + p, + ServerboundGamePacket::MovePlayerPos(p) + if p.pos == Vec3::new(0.5, 120., 0.5748524105068866) + ) + }); + sent_packets.expect_tick_end(); + sent_packets.expect_empty(); + + simulation.tick(); + sent_packets.expect("MovePlayerPos: { z: 0.6290694310673044 }", |p| { + matches!( + p, + ServerboundGamePacket::MovePlayerPos(p) + if p.pos == Vec3::new(0.5, 120., 0.6290694310673044) + ) + }); + sent_packets.expect_tick_end(); + sent_packets.expect_empty(); +} diff --git a/azalea-client/tests/correct_sprint_sneak_movement.rs b/azalea-client/tests/correct_sprint_sneak_movement.rs new file mode 100644 index 00000000..5b26a8a3 --- /dev/null +++ b/azalea-client/tests/correct_sprint_sneak_movement.rs @@ -0,0 +1,153 @@ +use azalea_client::{PhysicsState, SprintDirection, StartSprintEvent, test_utils::prelude::*}; +use azalea_core::{ + position::{BlockPos, ChunkPos, Vec3}, + resource_location::ResourceLocation, +}; +use azalea_entity::LookDirection; +use azalea_protocol::{ + common::movements::{PositionMoveRotation, RelativeMovements}, + packets::{ + ConnectionProtocol, + config::{ClientboundFinishConfiguration, ClientboundRegistryData}, + game::{ + ClientboundBlockUpdate, ClientboundPlayerPosition, ServerboundGamePacket, + ServerboundPlayerInput, + }, + }, +}; +use azalea_registry::{Block, DataRegistry, DimensionType}; +use simdnbt::owned::{NbtCompound, NbtTag}; + +#[test] +fn test_correct_sprint_sneak_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(); + + simulation.receive_packet(make_basic_empty_chunk(ChunkPos::new(0, 0), (384 + 64) / 16)); + simulation.receive_packet(ClientboundBlockUpdate { + pos: BlockPos::new(0, 119, 0), + block_state: Block::Stone.into(), + }); + simulation.receive_packet(ClientboundBlockUpdate { + pos: BlockPos::new(0, 119, 1), + block_state: Block::Stone.into(), + }); + simulation.receive_packet(ClientboundPlayerPosition { + id: 1, + change: PositionMoveRotation { + pos: Vec3::new(0.5, 120., 0.5), + delta: Vec3::ZERO, + look_direction: LookDirection::default(), + }, + relative: RelativeMovements::all_absolute(), + }); + simulation.tick(); + simulation.tick(); + simulation.tick(); + sent_packets.clear(); + + // start sprinting + simulation.send_event(StartSprintEvent { + entity: simulation.entity, + direction: SprintDirection::Forward, + }); + simulation.tick(); + sent_packets.expect("PlayerInput", |p| { + matches!( + p, + ServerboundGamePacket::PlayerInput(p) + if *p == ServerboundPlayerInput { forward: true, sprint: true, ..Default::default() } + ) + }); + sent_packets.expect("PlayerCommand", |p| { + matches!(p, ServerboundGamePacket::PlayerCommand(_)) + }); + sent_packets.expect("MovePlayerPos { z: 0.6274000124096872 }", |p| { + matches!( + p, + ServerboundGamePacket::MovePlayerPos(p) + if p.pos == Vec3::new(0.5, 120., 0.6274000124096872) + ) + }); + sent_packets.expect_tick_end(); + sent_packets.expect_empty(); + + simulation.tick(); + sent_packets.expect("MovePlayerPos { z: 0.8243604396746886 }", |p| { + matches!( + p, + ServerboundGamePacket::MovePlayerPos(p) + if p.pos == Vec3::new(0.5, 120., 0.8243604396746886) + ) + }); + sent_packets.expect_tick_end(); + sent_packets.expect_empty(); + simulation.with_component_mut::<PhysicsState>(|p| p.trying_to_crouch = true); + + simulation.tick(); + sent_packets.expect("PlayerInput", |p| { + matches!( + p, + ServerboundGamePacket::PlayerInput(p) + if *p == ServerboundPlayerInput { forward: true, sprint: true, shift: true, ..Default::default() } + ) + }); + sent_packets.expect("MovePlayerPos { z: 1.0593008578621674 }", |p| { + matches!( + p, + ServerboundGamePacket::MovePlayerPos(p) + if p.pos == Vec3::new(0.5, 120., 1.0593008578621674) + ) + }); + sent_packets.expect_tick_end(); + sent_packets.expect_empty(); + + simulation.tick(); + sent_packets.expect("MovePlayerPos { z: 1.2257983479146455 }", |p| { + matches!( + p, + ServerboundGamePacket::MovePlayerPos(p) + if p.pos == Vec3::new(0.5, 120., 1.2257983479146455) + ) + }); + sent_packets.expect_tick_end(); + sent_packets.expect_empty(); + + simulation.tick(); + sent_packets.expect("MovePlayerPos: { z: 1.3549259948648078 }", |p| { + matches!( + p, + ServerboundGamePacket::MovePlayerPos(p) + if p.pos == Vec3::new(0.5, 120., 1.3549259948648078) + ) + }); + sent_packets.expect_tick_end(); + sent_packets.expect_empty(); +} |
