aboutsummaryrefslogtreecommitdiff
path: root/azalea-client
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-08-04 16:17:41 -0900
committermat <git@matdoes.dev>2025-08-04 19:33:00 -0545
commit827d943c3f27c65724ff83689b40c87d1cd1838c (patch)
tree52d0145a8d482e912ceccb076accddce4da75c5e /azalea-client
parent013cd9f17674a4939d885ef91b7058b5a59d9ae1 (diff)
downloadazalea-drasl-827d943c3f27c65724ff83689b40c87d1cd1838c.tar.xz
fix wrong float rounding in get_friction_influenced_speed
Diffstat (limited to 'azalea-client')
-rw-r--r--azalea-client/src/plugins/movement.rs2
-rw-r--r--azalea-client/tests/correct_movement.rs103
2 files changed, 104 insertions, 1 deletions
diff --git a/azalea-client/src/plugins/movement.rs b/azalea-client/src/plugins/movement.rs
index e4778be1..aeb946fa 100644
--- a/azalea-client/src/plugins/movement.rs
+++ b/azalea-client/src/plugins/movement.rs
@@ -423,7 +423,7 @@ fn distance_to_unit_square(v: Vec2) -> f32 {
let x = v.x.abs();
let y = v.y.abs();
let ratio = if y > x { x / y } else { y / x };
- (1.0 + ratio * ratio).sqrt()
+ (1. + ratio * ratio).sqrt()
}
impl Client {
diff --git a/azalea-client/tests/correct_movement.rs b/azalea-client/tests/correct_movement.rs
new file mode 100644
index 00000000..c20fdb85
--- /dev/null
+++ b/azalea-client/tests/correct_movement.rs
@@ -0,0 +1,103 @@
+use azalea_client::{StartWalkEvent, WalkDirection, test_utils::prelude::*};
+use azalea_core::{
+ 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, ClientboundPlayerPosition, ClientboundSetChunkCacheCenter,
+ ServerboundGamePacket, ServerboundMovePlayerPos,
+ },
+ },
+};
+use azalea_registry::{Block, DataRegistry, DimensionType};
+use simdnbt::owned::{NbtCompound, NbtTag};
+
+#[test]
+fn test_correct_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();
+
+ // walk for a tick
+ simulation.send_event(StartWalkEvent {
+ entity: simulation.entity,
+ direction: WalkDirection::Forward,
+ });
+ sent_packets.clear();
+ simulation.tick();
+ sent_packets.expect("PlayerInput", |p| {
+ matches!(p, ServerboundGamePacket::PlayerInput(_))
+ });
+ sent_packets.expect("MovePlayerPos { pos.z: 370.59800000336764, ... }", |p| {
+ matches!(
+ p,
+ ServerboundGamePacket::MovePlayerPos(ServerboundMovePlayerPos {
+ pos: Vec3 {
+ x: 31.5,
+ y: 64.0,
+ z: 370.59800000336764
+ },
+ flags: MoveFlags {
+ on_ground: true,
+ horizontal_collision: false
+ }
+ })
+ )
+ });
+ sent_packets.expect_tick_end();
+ sent_packets.expect_empty();
+}