aboutsummaryrefslogtreecommitdiff
path: root/azalea/src
diff options
context:
space:
mode:
Diffstat (limited to 'azalea/src')
-rw-r--r--azalea/src/pathfinder/rel_block_pos.rs20
1 files changed, 18 insertions, 2 deletions
diff --git a/azalea/src/pathfinder/rel_block_pos.rs b/azalea/src/pathfinder/rel_block_pos.rs
index 6b5fa69a..b8e96041 100644
--- a/azalea/src/pathfinder/rel_block_pos.rs
+++ b/azalea/src/pathfinder/rel_block_pos.rs
@@ -1,4 +1,8 @@
-use std::ops::{Add, Mul};
+use std::{
+ hash::{Hash, Hasher},
+ mem::transmute,
+ ops::{Add, Mul},
+};
use azalea_core::position::BlockPos;
@@ -7,7 +11,7 @@ use azalea_core::position::BlockPos;
/// This fits in 64 bits, so it's more efficient than a BlockPos in some cases.
///
/// The X and Z are limited to ±32k.
-#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
+#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(C)]
pub struct RelBlockPos {
pub x: i16,
@@ -89,6 +93,12 @@ impl RelBlockPos {
z: self.z,
}
}
+
+ #[inline]
+ pub fn as_u64(self) -> u64 {
+ // SAFETY: RelBlockPos can be represented as a u64
+ unsafe { transmute::<Self, u64>(self) }
+ }
}
impl Add<RelBlockPos> for RelBlockPos {
@@ -113,3 +123,9 @@ impl Mul<i16> for RelBlockPos {
}
}
}
+
+impl Hash for RelBlockPos {
+ fn hash<H: Hasher>(&self, state: &mut H) {
+ self.as_u64().hash(state);
+ }
+}