aboutsummaryrefslogtreecommitdiff
path: root/azalea-core/src
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-05-14 15:02:13 -0500
committermat <github@matdoes.dev>2022-05-14 15:02:13 -0500
commite58c9390a717517db0bf4366c55a3802c832b144 (patch)
treea55bdc2d8fe40786ce475cc6c124134b419f3aa6 /azalea-core/src
parent6d2fd8afbad44bbe88f701e1d67cc2f251246c07 (diff)
downloadazalea-drasl-e58c9390a717517db0bf4366c55a3802c832b144.tar.xz
get_block_state works
Diffstat (limited to 'azalea-core/src')
-rwxr-xr-xazalea-core/src/difficulty.rs1
-rwxr-xr-xazalea-core/src/lib.rs4
-rw-r--r--azalea-core/src/position.rs68
3 files changed, 65 insertions, 8 deletions
diff --git a/azalea-core/src/difficulty.rs b/azalea-core/src/difficulty.rs
index 21e980ba..5d869325 100755
--- a/azalea-core/src/difficulty.rs
+++ b/azalea-core/src/difficulty.rs
@@ -83,7 +83,6 @@ mod tests {
assert_eq!(1, Difficulty::EASY.id());
assert_eq!(2, Difficulty::NORMAL.id());
assert_eq!(3, Difficulty::HARD.id());
- assert_eq!(4, Difficulty::PEACEFUL.id());
}
#[test]
diff --git a/azalea-core/src/lib.rs b/azalea-core/src/lib.rs
index 2b12db53..d2a2d558 100755
--- a/azalea-core/src/lib.rs
+++ b/azalea-core/src/lib.rs
@@ -1,5 +1,7 @@
//! Random miscellaneous things like UUIDs that don't deserve their own crate.
+#![feature(int_roundings)]
+
pub mod difficulty;
pub mod game_type;
pub mod resource_location;
@@ -9,7 +11,7 @@ mod slot;
pub use slot::{Slot, SlotData};
mod position;
-pub use position::{BlockPos, ChunkPos, ChunkSectionBlockPos, ChunkSectionPos};
+pub use position::{BlockPos, ChunkBlockPos, ChunkPos, ChunkSectionBlockPos, ChunkSectionPos};
mod direction;
pub use direction::Direction;
diff --git a/azalea-core/src/position.rs b/azalea-core/src/position.rs
index 1dd200ab..9c7cd132 100644
--- a/azalea-core/src/position.rs
+++ b/azalea-core/src/position.rs
@@ -25,7 +25,7 @@ impl Rem<i32> for BlockPos {
}
}
-#[derive(Clone, Copy, Debug, Default)]
+#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct ChunkPos {
pub x: i32,
pub z: i32,
@@ -40,8 +40,8 @@ impl ChunkPos {
impl From<&BlockPos> for ChunkPos {
fn from(pos: &BlockPos) -> Self {
ChunkPos {
- x: pos.x / 16,
- z: pos.z / 16,
+ x: pos.x.div_floor(16),
+ z: pos.z.div_floor(16),
}
}
}
@@ -63,9 +63,9 @@ impl ChunkSectionPos {
impl From<BlockPos> for ChunkSectionPos {
fn from(pos: BlockPos) -> Self {
ChunkSectionPos {
- x: pos.x / 16,
- y: pos.y / 16,
- z: pos.z / 16,
+ x: pos.x.div_floor(16),
+ y: pos.y.div_floor(16),
+ z: pos.z.div_floor(16),
}
}
}
@@ -76,11 +76,38 @@ impl From<ChunkSectionPos> for ChunkPos {
}
}
+/// The coordinates of a block inside a chunk.
+#[derive(Clone, Copy, Debug, Default, PartialEq)]
+pub struct ChunkBlockPos {
+ pub x: u8,
+ pub y: i32,
+ pub z: u8,
+}
+
+impl ChunkBlockPos {
+ pub fn new(x: u8, y: i32, z: u8) -> Self {
+ ChunkBlockPos { x, y, z }
+ }
+}
+
+impl From<&BlockPos> for ChunkBlockPos {
+ fn from(pos: &BlockPos) -> Self {
+ ChunkBlockPos {
+ x: pos.x.rem_euclid(16).abs() as u8,
+ y: pos.y,
+ z: pos.z.rem_euclid(16).abs() as u8,
+ }
+ }
+}
+
/// The coordinates of a block inside a chunk section.
#[derive(Clone, Copy, Debug, Default)]
pub struct ChunkSectionBlockPos {
+ /// A number between 0 and 16.
pub x: u8,
+ /// A number between 0 and 16.
pub y: u8,
+ /// A number between 0 and 16.
pub z: u8,
}
@@ -99,3 +126,32 @@ impl From<&BlockPos> for ChunkSectionBlockPos {
}
}
}
+
+impl From<&ChunkBlockPos> for ChunkSectionBlockPos {
+ fn from(pos: &ChunkBlockPos) -> Self {
+ ChunkSectionBlockPos {
+ x: pos.x,
+ y: pos.y.rem(16).abs() as u8,
+ z: pos.z,
+ }
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn test_from_block_pos_to_chunk_pos() {
+ let block_pos = BlockPos::new(5, 78, -2);
+ let chunk_pos = ChunkPos::from(&block_pos);
+ assert_eq!(chunk_pos, ChunkPos::new(0, -1));
+ }
+
+ #[test]
+ fn test_from_block_pos_to_chunk_block_pos() {
+ let block_pos = BlockPos::new(5, 78, -2);
+ let chunk_block_pos = ChunkBlockPos::from(&block_pos);
+ assert_eq!(chunk_block_pos, ChunkBlockPos::new(5, 78, 14));
+ }
+}