mirror of
https://github.com/Pumpkin-MC/Pumpkin.git
synced 2026-08-30 20:14:23 +00:00
Allow From<Vec3<T>> for (_,_,_) for easy destructuring.
This commit is contained in:
@@ -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:
|
||||
Mul<Output = Self>
|
||||
+ Neg<Output = Self>
|
||||
|
||||
@@ -76,9 +76,7 @@ impl Player {
|
||||
return;
|
||||
}
|
||||
let entity = &mut self.entity;
|
||||
self.lastx = entity.pos.x;
|
||||
self.lasty = entity.pos.y;
|
||||
self.lastz = entity.pos.z;
|
||||
self.last_position = entity.pos;
|
||||
entity.set_pos(
|
||||
Self::clamp_horizontal(position.x),
|
||||
Self::clamp_vertical(position.feet_y),
|
||||
@@ -89,9 +87,8 @@ impl Player {
|
||||
// send new position to all other players
|
||||
let on_ground = self.on_ground;
|
||||
let entity_id = entity.entity_id;
|
||||
let (x, lastx) = (entity.pos.x, self.lastx);
|
||||
let (y, lasty) = (entity.pos.y, self.lasty);
|
||||
let (z, lastz) = (entity.pos.z, self.lastz);
|
||||
let (x, y, z) = entity.pos.into();
|
||||
let (lastx, lasty, lastz) = self.last_position.into();
|
||||
let world = self.world.clone();
|
||||
let world = world.lock().await;
|
||||
world.broadcast_packet(
|
||||
@@ -125,9 +122,7 @@ impl Player {
|
||||
}
|
||||
let entity = &mut self.entity;
|
||||
|
||||
self.lastx = entity.pos.x;
|
||||
self.lasty = entity.pos.y;
|
||||
self.lastz = entity.pos.z;
|
||||
self.last_position = entity.pos;
|
||||
entity.set_pos(
|
||||
Self::clamp_horizontal(position_rotation.x),
|
||||
Self::clamp_vertical(position_rotation.feet_y),
|
||||
@@ -139,9 +134,8 @@ impl Player {
|
||||
// send new position to all other players
|
||||
let on_ground = self.on_ground;
|
||||
let entity_id = entity.entity_id;
|
||||
let (x, lastx) = (entity.pos.x, self.lastx);
|
||||
let (y, lasty) = (entity.pos.y, self.lasty);
|
||||
let (z, lastz) = (entity.pos.z, self.lastz);
|
||||
let (x, y, z) = entity.pos.into();
|
||||
let (lastx, lasty, lastz) = self.last_position.into();
|
||||
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();
|
||||
|
||||
@@ -69,9 +69,7 @@ pub struct Player {
|
||||
/// send `send_abilties_update` when changed
|
||||
pub abilities: PlayerAbilities,
|
||||
|
||||
pub lastx: f64,
|
||||
pub lasty: f64,
|
||||
pub lastz: f64,
|
||||
pub last_position: Vector3<f64>,
|
||||
// Client side value, Should be not trusted
|
||||
pub on_ground: bool,
|
||||
|
||||
@@ -132,9 +130,7 @@ impl Player {
|
||||
abilities: PlayerAbilities::default(),
|
||||
gamemode,
|
||||
watched_section: Vector3::new(0, 0, 0),
|
||||
lastx: 0.0,
|
||||
lasty: 0.0,
|
||||
lastz: 0.0,
|
||||
last_position: Vector3::new(0.0, 0.0, 0.0),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,9 +251,7 @@ impl Player {
|
||||
}
|
||||
let entity = &mut self.entity;
|
||||
entity.set_pos(x, y, z);
|
||||
self.lastx = x;
|
||||
self.lasty = y;
|
||||
self.lastz = z;
|
||||
self.last_position = entity.pos;
|
||||
entity.yaw = yaw;
|
||||
entity.pitch = pitch;
|
||||
self.awaiting_teleport = Some((self.teleport_id_count.into(), Vector3::new(x, y, z)));
|
||||
|
||||
Reference in New Issue
Block a user