Fix rotation
- 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.
This commit is contained in:
parent
02a9d79044
commit
2d3990bfa6
@ -24,6 +24,10 @@ use crate::{
|
|||||||
|
|
||||||
use super::{Client, PlayerConfig};
|
use super::{Client, PlayerConfig};
|
||||||
|
|
||||||
|
fn modulus(a: f32, b: f32) -> f32 {
|
||||||
|
((a % b) + b) % b
|
||||||
|
}
|
||||||
|
|
||||||
/// Handles all Play Packets send by a real Player
|
/// Handles all Play Packets send by a real Player
|
||||||
impl Client {
|
impl Client {
|
||||||
pub fn handle_confirm_teleport(
|
pub fn handle_confirm_teleport(
|
||||||
@ -119,9 +123,9 @@ impl Client {
|
|||||||
let (x, lastx) = (entity.x, entity.lastx);
|
let (x, lastx) = (entity.x, entity.lastx);
|
||||||
let (y, lasty) = (entity.y, entity.lasty);
|
let (y, lasty) = (entity.y, entity.lasty);
|
||||||
let (z, lastz) = (entity.z, entity.lastz);
|
let (z, lastz) = (entity.z, entity.lastz);
|
||||||
let yaw = (entity.yaw * 256.0 / 360.0).floor();
|
let yaw = modulus(entity.yaw * 256.0 / 360.0, 256.0);
|
||||||
let pitch = (entity.pitch * 256.0 / 360.0).floor();
|
let pitch = modulus(entity.pitch * 256.0 / 360.0, 256.0);
|
||||||
let head_yaw = (entity.head_yaw * 256.0 / 360.0).floor();
|
// let head_yaw = (entity.head_yaw * 256.0 / 360.0).floor();
|
||||||
|
|
||||||
server.broadcast_packet(
|
server.broadcast_packet(
|
||||||
self,
|
self,
|
||||||
@ -135,7 +139,7 @@ impl Client {
|
|||||||
on_ground,
|
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) {
|
pub fn handle_rotation(&mut self, server: &mut Server, rotation: SPlayerRotation) {
|
||||||
@ -150,15 +154,15 @@ impl Client {
|
|||||||
// send new position to all other players
|
// send new position to all other players
|
||||||
let on_ground = player.on_ground;
|
let on_ground = player.on_ground;
|
||||||
let entity_id = entity.entity_id;
|
let entity_id = entity.entity_id;
|
||||||
let yaw = (entity.yaw * 256.0 / 360.0).floor();
|
let yaw = modulus(entity.yaw * 256.0 / 360.0, 256.0);
|
||||||
let pitch = (entity.pitch * 256.0 / 360.0).floor();
|
let pitch = modulus(entity.pitch * 256.0 / 360.0, 256.0);
|
||||||
let head_yaw = (entity.head_yaw * 256.0 / 360.0).floor();
|
// let head_yaw = modulus(entity.head_yaw * 256.0 / 360.0, 256.0);
|
||||||
|
|
||||||
server.broadcast_packet(
|
server.broadcast_packet(
|
||||||
self,
|
self,
|
||||||
&CUpdateEntityRot::new(entity_id.into(), yaw as u8, pitch as u8, on_ground),
|
&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) {
|
pub fn handle_chat_command(&mut self, _server: &mut Server, command: SChatCommand) {
|
||||||
|
|||||||
@ -339,7 +339,7 @@ impl Server {
|
|||||||
"./world".parse().unwrap(),
|
"./world".parse().unwrap(),
|
||||||
);
|
);
|
||||||
level
|
level
|
||||||
.read_chunks(RadialIterator::new(32).collect(), sender)
|
.read_chunks(RadialIterator::new(2).collect(), sender)
|
||||||
.await;
|
.await;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user