Skip to content

Commit

Permalink
Fix rotation
Browse files Browse the repository at this point in the history
- The rotation was previously not taking the modulus of the degree (which is incorrect).
- `head_yaw` is currently not used, since the server only receives the yaw and pitch packet, it can be assumed that head yaw can be identical to yaw.
  • Loading branch information
lukas0008 committed Aug 13, 2024
1 parent 02a9d79 commit 2d3990b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions pumpkin/src/client/player_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ use crate::{

use super::{Client, PlayerConfig};

fn modulus(a: f32, b: f32) -> f32 {
((a % b) + b) % b
}

/// Handles all Play Packets send by a real Player
impl Client {
pub fn handle_confirm_teleport(
Expand Down Expand Up @@ -119,9 +123,9 @@ impl Client {
let (x, lastx) = (entity.x, entity.lastx);
let (y, lasty) = (entity.y, entity.lasty);
let (z, lastz) = (entity.z, entity.lastz);
let yaw = (entity.yaw * 256.0 / 360.0).floor();
let pitch = (entity.pitch * 256.0 / 360.0).floor();
let head_yaw = (entity.head_yaw * 256.0 / 360.0).floor();
let yaw = modulus(entity.yaw * 256.0 / 360.0, 256.0);
let pitch = modulus(entity.pitch * 256.0 / 360.0, 256.0);
// let head_yaw = (entity.head_yaw * 256.0 / 360.0).floor();

server.broadcast_packet(
self,
Expand All @@ -135,7 +139,7 @@ impl Client {
on_ground,
),
);
server.broadcast_packet(self, &CHeadRot::new(entity_id.into(), head_yaw as u8));
server.broadcast_packet(self, &CHeadRot::new(entity_id.into(), yaw as u8));
}

pub fn handle_rotation(&mut self, server: &mut Server, rotation: SPlayerRotation) {
Expand All @@ -150,15 +154,15 @@ impl Client {
// send new position to all other players
let on_ground = player.on_ground;
let entity_id = entity.entity_id;
let yaw = (entity.yaw * 256.0 / 360.0).floor();
let pitch = (entity.pitch * 256.0 / 360.0).floor();
let head_yaw = (entity.head_yaw * 256.0 / 360.0).floor();
let yaw = modulus(entity.yaw * 256.0 / 360.0, 256.0);
let pitch = modulus(entity.pitch * 256.0 / 360.0, 256.0);
// let head_yaw = modulus(entity.head_yaw * 256.0 / 360.0, 256.0);

server.broadcast_packet(
self,
&CUpdateEntityRot::new(entity_id.into(), yaw as u8, pitch as u8, on_ground),
);
server.broadcast_packet(self, &CHeadRot::new(entity_id.into(), head_yaw as u8));
server.broadcast_packet(self, &CHeadRot::new(entity_id.into(), yaw as u8));
}

pub fn handle_chat_command(&mut self, _server: &mut Server, command: SChatCommand) {
Expand Down
2 changes: 1 addition & 1 deletion pumpkin/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ impl Server {
"./world".parse().unwrap(),
);
level
.read_chunks(RadialIterator::new(32).collect(), sender)
.read_chunks(RadialIterator::new(2).collect(), sender)
.await;
});

Expand Down

0 comments on commit 2d3990b

Please sign in to comment.