aboutsummaryrefslogtreecommitdiff
path: root/azalea-core
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-05-14 14:12:57 -0500
committermat <github@matdoes.dev>2022-05-14 14:12:57 -0500
commit6d2fd8afbad44bbe88f701e1d67cc2f251246c07 (patch)
tree3fa06efe4408c28db89aa6f115414d7a6995b1cc /azalea-core
parent70271ede1982b618b5bb592da4adffabcdd76dac (diff)
downloadazalea-drasl-6d2fd8afbad44bbe88f701e1d67cc2f251246c07.tar.xz
start adding get_block_state
Diffstat (limited to 'azalea-core')
-rwxr-xr-xazalea-core/src/lib.rs2
-rw-r--r--azalea-core/src/position.rs43
2 files changed, 42 insertions, 3 deletions
diff --git a/azalea-core/src/lib.rs b/azalea-core/src/lib.rs
index 0053dc9b..2b12db53 100755
--- a/azalea-core/src/lib.rs
+++ b/azalea-core/src/lib.rs
@@ -9,7 +9,7 @@ mod slot;
pub use slot::{Slot, SlotData};
mod position;
-pub use position::{BlockPos, ChunkPos, ChunkSectionPos};
+pub use position::{BlockPos, ChunkPos, ChunkSectionBlockPos, ChunkSectionPos};
mod direction;
pub use direction::Direction;
diff --git a/azalea-core/src/position.rs b/azalea-core/src/position.rs
index a2292651..1dd200ab 100644
--- a/azalea-core/src/position.rs
+++ b/azalea-core/src/position.rs
@@ -1,3 +1,5 @@
+use std::ops::Rem;
+
#[derive(Clone, Copy, Debug, Default)]
pub struct BlockPos {
pub x: i32,
@@ -11,6 +13,18 @@ impl BlockPos {
}
}
+impl Rem<i32> for BlockPos {
+ type Output = Self;
+
+ fn rem(self, rhs: i32) -> Self {
+ BlockPos {
+ x: self.x % rhs,
+ y: self.y % rhs,
+ z: self.z % rhs,
+ }
+ }
+}
+
#[derive(Clone, Copy, Debug, Default)]
pub struct ChunkPos {
pub x: i32,
@@ -23,8 +37,8 @@ impl ChunkPos {
}
}
-impl From<BlockPos> for ChunkPos {
- fn from(pos: BlockPos) -> Self {
+impl From<&BlockPos> for ChunkPos {
+ fn from(pos: &BlockPos) -> Self {
ChunkPos {
x: pos.x / 16,
z: pos.z / 16,
@@ -32,6 +46,7 @@ impl From<BlockPos> for ChunkPos {
}
}
+/// The coordinates of a chunk section in the world.
#[derive(Clone, Copy, Debug, Default)]
pub struct ChunkSectionPos {
pub x: i32,
@@ -60,3 +75,27 @@ impl From<ChunkSectionPos> for ChunkPos {
ChunkPos { x: pos.x, z: pos.z }
}
}
+
+/// The coordinates of a block inside a chunk section.
+#[derive(Clone, Copy, Debug, Default)]
+pub struct ChunkSectionBlockPos {
+ pub x: u8,
+ pub y: u8,
+ pub z: u8,
+}
+
+impl ChunkSectionBlockPos {
+ pub fn new(x: u8, y: u8, z: u8) -> Self {
+ ChunkSectionBlockPos { x, y, z }
+ }
+}
+
+impl From<&BlockPos> for ChunkSectionBlockPos {
+ fn from(pos: &BlockPos) -> Self {
+ ChunkSectionBlockPos {
+ x: pos.x.rem(16).abs() as u8,
+ y: pos.y.rem(16).abs() as u8,
+ z: pos.z.rem(16).abs() as u8,
+ }
+ }
+}