aboutsummaryrefslogtreecommitdiff
path: root/azalea-core/src/delta.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-core/src/delta.rs
parent5643cc4a9450d000a3cc7bc771409313cdfbf5b4 (diff)
downloadazalea-drasl-b030b0ea330c674415f7e30634957167b2fa6a6d.tar.xz
start adding moving
Diffstat (limited to 'azalea-core/src/delta.rs')
-rw-r--r--azalea-core/src/delta.rs59
1 files changed, 48 insertions, 11 deletions
diff --git a/azalea-core/src/delta.rs b/azalea-core/src/delta.rs
index 41923ffb..c0056411 100644
--- a/azalea-core/src/delta.rs
+++ b/azalea-core/src/delta.rs
@@ -1,15 +1,41 @@
use crate::EntityPos;
pub use azalea_buf::McBuf;
-/// Only works for up to 8 blocks
-#[derive(Clone, Debug, McBuf)]
+pub trait PositionDeltaTrait {
+ fn x(&self) -> f64;
+ fn y(&self) -> f64;
+ fn z(&self) -> f64;
+}
+
+#[derive(Clone, Debug, McBuf, Default)]
pub struct PositionDelta {
- xa: i16,
- ya: i16,
- za: i16,
+ pub xa: f64,
+ pub ya: f64,
+ pub za: f64,
+}
+
+/// Only works for up to 8 blocks
+#[derive(Clone, Debug, McBuf, Default)]
+pub struct PositionDelta8 {
+ pub xa: i16,
+ pub ya: i16,
+ pub za: i16,
+}
+
+impl PositionDeltaTrait for PositionDelta {
+ fn x(&self) -> f64 {
+ self.xa
+ }
+ fn y(&self) -> f64 {
+ self.ya
+ }
+ fn z(&self) -> f64 {
+ self.za
+ }
}
-impl PositionDelta {
+impl PositionDelta8 {
+ #[deprecated]
pub fn float(&self) -> (f64, f64, f64) {
(
(self.xa as f64) / 4096.0,
@@ -19,13 +45,24 @@ impl PositionDelta {
}
}
+impl PositionDeltaTrait for PositionDelta8 {
+ fn x(&self) -> f64 {
+ (self.xa as f64) / 4096.0
+ }
+ fn y(&self) -> f64 {
+ (self.ya as f64) / 4096.0
+ }
+ fn z(&self) -> f64 {
+ (self.za as f64) / 4096.0
+ }
+}
+
impl EntityPos {
- pub fn with_delta(&self, delta: &PositionDelta) -> EntityPos {
- let (x, y, z) = delta.float();
+ pub fn with_delta(&self, delta: &dyn PositionDeltaTrait) -> EntityPos {
EntityPos {
- x: self.x + x,
- y: self.y + y,
- z: self.z + z,
+ x: self.x + delta.x(),
+ y: self.y + delta.y(),
+ z: self.z + delta.z(),
}
}
}