aboutsummaryrefslogtreecommitdiff
path: root/azalea-entity/src/lib.rs
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-06-24 23:10:59 -0500
committermat <github@matdoes.dev>2022-06-24 23:10:59 -0500
commitb030b0ea330c674415f7e30634957167b2fa6a6d (patch)
treea55ca353bb546967fb56e250e0da469f8d4ea291 /azalea-entity/src/lib.rs
parent5643cc4a9450d000a3cc7bc771409313cdfbf5b4 (diff)
downloadazalea-drasl-b030b0ea330c674415f7e30634957167b2fa6a6d.tar.xz
start adding moving
Diffstat (limited to 'azalea-entity/src/lib.rs')
-rw-r--r--azalea-entity/src/lib.rs30
1 files changed, 23 insertions, 7 deletions
diff --git a/azalea-entity/src/lib.rs b/azalea-entity/src/lib.rs
index 065413a5..63c717d3 100644
--- a/azalea-entity/src/lib.rs
+++ b/azalea-entity/src/lib.rs
@@ -1,11 +1,6 @@
mod data;
-use azalea_core::EntityPos;
-#[cfg(feature = "protocol")]
-use azalea_protocol::packets::game::{
- clientbound_add_entity_packet::ClientboundAddEntityPacket,
- clientbound_add_player_packet::ClientboundAddPlayerPacket,
-};
+use azalea_core::{EntityPos, PositionDelta};
pub use data::*;
use uuid::Uuid;
@@ -14,12 +9,27 @@ pub struct Entity {
/// The incrementing numerical id of the entity.
pub id: u32,
pub uuid: Uuid,
+ /// The position of the entity right now.
pos: EntityPos,
+ /// The position of the entity last tick.
+ pub old_pos: EntityPos,
+ pub delta: PositionDelta,
+
+ pub x_rot: f32,
+ pub y_rot: f32,
}
impl Entity {
pub fn new(id: u32, uuid: Uuid, pos: EntityPos) -> Self {
- Self { id, uuid, pos }
+ Self {
+ id,
+ uuid,
+ pos,
+ old_pos: pos,
+ delta: PositionDelta::default(),
+ x_rot: 0.0,
+ y_rot: 0.0,
+ }
}
pub fn pos(&self) -> &EntityPos {
@@ -31,6 +41,12 @@ impl Entity {
pub fn unsafe_move(&mut self, new_pos: EntityPos) {
self.pos = new_pos;
}
+
+ pub fn set_rotation(&mut self, x_rot: f32, y_rot: f32) {
+ self.x_rot = x_rot % 360.0;
+ self.y_rot = y_rot.clamp(-90.0, 90.0) % 360.0;
+ // TODO: minecraft also sets yRotO and xRotO to xRot and yRot ... but idk what they're used for so
+ }
}
// #[cfg(test)]