aboutsummaryrefslogtreecommitdiff
path: root/azalea-entity/src/lib.rs
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2022-06-25 05:09:26 +0000
committerGitHub <noreply@github.com>2022-06-25 05:09:26 +0000
commit7d3e57763e32ac9cf94180b1c714704cfbc3034d (patch)
tree2dcfe72bf09a42f6614f9dc988dc0254162ea0bf /azalea-entity/src/lib.rs
parent69c47eda4c496b13dadd80976bffd2fab7ea5894 (diff)
parentca7067e173129f3044ebc8c77634f06da29a086e (diff)
downloadazalea-drasl-7d3e57763e32ac9cf94180b1c714704cfbc3034d.tar.xz
Merge pull request #10 from mat-1/azalea-entity
azalea-entity
Diffstat (limited to 'azalea-entity/src/lib.rs')
-rw-r--r--azalea-entity/src/lib.rs59
1 files changed, 59 insertions, 0 deletions
diff --git a/azalea-entity/src/lib.rs b/azalea-entity/src/lib.rs
new file mode 100644
index 00000000..9436d753
--- /dev/null
+++ b/azalea-entity/src/lib.rs
@@ -0,0 +1,59 @@
+mod data;
+
+use azalea_core::{EntityPos, PositionDelta};
+pub use data::*;
+use uuid::Uuid;
+
+#[derive(Default, Debug)]
+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,
+ old_pos: pos,
+ delta: PositionDelta::default(),
+ x_rot: 0.0,
+ y_rot: 0.0,
+ }
+ }
+
+ pub fn pos(&self) -> &EntityPos {
+ &self.pos
+ }
+
+ /// Sets the position of the entity. This doesn't update the cache in
+ /// azalea-world, and should only be used within azalea-world!
+ pub fn unsafe_move(&mut self, new_pos: EntityPos) {
+ self.pos = new_pos;
+ }
+
+ pub fn set_rotation(&mut self, y_rot: f32, x_rot: f32) {
+ self.y_rot = y_rot.clamp(-90.0, 90.0) % 360.0;
+ self.x_rot = x_rot % 360.0;
+ // TODO: minecraft also sets yRotO and xRotO to xRot and yRot ... but idk what they're used for so
+ }
+}
+
+// #[cfg(test)]
+// mod tests {
+// #[test]
+// fn it_works() {
+// let result = 2 + 2;
+// assert_eq!(result, 4);
+// }
+// }