Allow From<Vec3<T>> for (_,_,_) for easy destructuring.
This commit is contained in:
parent
286253cdc6
commit
4dce8aa90d
@ -98,6 +98,12 @@ impl<T> From<(T, T, T)> for Vector3<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T> From<Vector3<T>> for (T, T, T) {
|
||||||
|
fn from(vector: Vector3<T>) -> Self {
|
||||||
|
(vector.x, vector.y, vector.z)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub trait Math:
|
pub trait Math:
|
||||||
Mul<Output = Self>
|
Mul<Output = Self>
|
||||||
+ Neg<Output = Self>
|
+ Neg<Output = Self>
|
||||||
|
|||||||
@ -76,9 +76,7 @@ impl Player {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let entity = &mut self.entity;
|
let entity = &mut self.entity;
|
||||||
self.lastx = entity.pos.x;
|
self.last_position = entity.pos;
|
||||||
self.lasty = entity.pos.y;
|
|
||||||
self.lastz = entity.pos.z;
|
|
||||||
entity.set_pos(
|
entity.set_pos(
|
||||||
Self::clamp_horizontal(position.x),
|
Self::clamp_horizontal(position.x),
|
||||||
Self::clamp_vertical(position.feet_y),
|
Self::clamp_vertical(position.feet_y),
|
||||||
@ -89,9 +87,8 @@ impl Player {
|
|||||||
// send new position to all other players
|
// send new position to all other players
|
||||||
let on_ground = self.on_ground;
|
let on_ground = self.on_ground;
|
||||||
let entity_id = entity.entity_id;
|
let entity_id = entity.entity_id;
|
||||||
let (x, lastx) = (entity.pos.x, self.lastx);
|
let (x, y, z) = entity.pos.into();
|
||||||
let (y, lasty) = (entity.pos.y, self.lasty);
|
let (lastx, lasty, lastz) = self.last_position.into();
|
||||||
let (z, lastz) = (entity.pos.z, self.lastz);
|
|
||||||
let world = self.world.clone();
|
let world = self.world.clone();
|
||||||
let world = world.lock().await;
|
let world = world.lock().await;
|
||||||
world.broadcast_packet(
|
world.broadcast_packet(
|
||||||
@ -125,9 +122,7 @@ impl Player {
|
|||||||
}
|
}
|
||||||
let entity = &mut self.entity;
|
let entity = &mut self.entity;
|
||||||
|
|
||||||
self.lastx = entity.pos.x;
|
self.last_position = entity.pos;
|
||||||
self.lasty = entity.pos.y;
|
|
||||||
self.lastz = entity.pos.z;
|
|
||||||
entity.set_pos(
|
entity.set_pos(
|
||||||
Self::clamp_horizontal(position_rotation.x),
|
Self::clamp_horizontal(position_rotation.x),
|
||||||
Self::clamp_vertical(position_rotation.feet_y),
|
Self::clamp_vertical(position_rotation.feet_y),
|
||||||
@ -139,9 +134,8 @@ impl Player {
|
|||||||
// send new position to all other players
|
// send new position to all other players
|
||||||
let on_ground = self.on_ground;
|
let on_ground = self.on_ground;
|
||||||
let entity_id = entity.entity_id;
|
let entity_id = entity.entity_id;
|
||||||
let (x, lastx) = (entity.pos.x, self.lastx);
|
let (x, y, z) = entity.pos.into();
|
||||||
let (y, lasty) = (entity.pos.y, self.lasty);
|
let (lastx, lasty, lastz) = self.last_position.into();
|
||||||
let (z, lastz) = (entity.pos.z, self.lastz);
|
|
||||||
let yaw = modulus(entity.yaw * 256.0 / 360.0, 256.0);
|
let yaw = modulus(entity.yaw * 256.0 / 360.0, 256.0);
|
||||||
let pitch = modulus(entity.pitch * 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();
|
// let head_yaw = (entity.head_yaw * 256.0 / 360.0).floor();
|
||||||
|
|||||||
@ -69,9 +69,7 @@ pub struct Player {
|
|||||||
/// send `send_abilties_update` when changed
|
/// send `send_abilties_update` when changed
|
||||||
pub abilities: PlayerAbilities,
|
pub abilities: PlayerAbilities,
|
||||||
|
|
||||||
pub lastx: f64,
|
pub last_position: Vector3<f64>,
|
||||||
pub lasty: f64,
|
|
||||||
pub lastz: f64,
|
|
||||||
// Client side value, Should be not trusted
|
// Client side value, Should be not trusted
|
||||||
pub on_ground: bool,
|
pub on_ground: bool,
|
||||||
|
|
||||||
@ -132,9 +130,7 @@ impl Player {
|
|||||||
abilities: PlayerAbilities::default(),
|
abilities: PlayerAbilities::default(),
|
||||||
gamemode,
|
gamemode,
|
||||||
watched_section: Vector3::new(0, 0, 0),
|
watched_section: Vector3::new(0, 0, 0),
|
||||||
lastx: 0.0,
|
last_position: Vector3::new(0.0, 0.0, 0.0),
|
||||||
lasty: 0.0,
|
|
||||||
lastz: 0.0,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,9 +251,7 @@ impl Player {
|
|||||||
}
|
}
|
||||||
let entity = &mut self.entity;
|
let entity = &mut self.entity;
|
||||||
entity.set_pos(x, y, z);
|
entity.set_pos(x, y, z);
|
||||||
self.lastx = x;
|
self.last_position = entity.pos;
|
||||||
self.lasty = y;
|
|
||||||
self.lastz = z;
|
|
||||||
entity.yaw = yaw;
|
entity.yaw = yaw;
|
||||||
entity.pitch = pitch;
|
entity.pitch = pitch;
|
||||||
self.awaiting_teleport = Some((self.teleport_id_count.into(), Vector3::new(x, y, z)));
|
self.awaiting_teleport = Some((self.teleport_id_count.into(), Vector3::new(x, y, z)));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user