From d028d7c3e9c84d177b7b10fa0d8f77d11bcea20f Mon Sep 17 00:00:00 2001 From: mat Date: Mon, 2 Jun 2025 07:45:26 +1100 Subject: add basic support for getting biome ids in chunks --- azalea-core/src/position.rs | 48 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) (limited to 'azalea-core/src') diff --git a/azalea-core/src/position.rs b/azalea-core/src/position.rs index 04cce036..5932cb5b 100644 --- a/azalea-core/src/position.rs +++ b/azalea-core/src/position.rs @@ -539,8 +539,8 @@ impl From for u64 { } impl nohash_hasher::IsEnabled for ChunkBlockPos {} -/// The coordinates of a block inside a chunk section. Each coordinate must be -/// in the range [0, 15]. +/// The coordinates of a block inside a chunk section. Each coordinate should be +/// in the range 0..=15. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] pub struct ChunkSectionBlockPos { pub x: u8, @@ -549,6 +549,50 @@ pub struct ChunkSectionBlockPos { } vec3_impl!(ChunkSectionBlockPos, u8); +/// The coordinates of a chunk inside a chunk section. Each coordinate should be +/// in the range 0..=3. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +pub struct ChunkSectionBiomePos { + pub x: u8, + pub y: u8, + pub z: u8, +} +impl From<&ChunkBiomePos> for ChunkSectionBiomePos { + #[inline] + fn from(pos: &ChunkBiomePos) -> Self { + ChunkSectionBiomePos { + x: pos.x, + y: (pos.y & 0b11) as u8, + z: pos.z, + } + } +} +vec3_impl!(ChunkSectionBiomePos, u8); + +/// The coordinates of a biome inside a chunk. Biomes are 4x4 blocks. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +pub struct ChunkBiomePos { + pub x: u8, + pub y: i32, + pub z: u8, +} +impl From<&BlockPos> for ChunkBiomePos { + #[inline] + fn from(pos: &BlockPos) -> Self { + ChunkBiomePos::from(&ChunkBlockPos::from(pos)) + } +} +impl From<&ChunkBlockPos> for ChunkBiomePos { + #[inline] + fn from(pos: &ChunkBlockPos) -> Self { + ChunkBiomePos { + x: pos.x >> 2, + y: pos.y >> 2, + z: pos.z >> 2, + } + } +} + impl Add for ChunkSectionPos { type Output = BlockPos; -- cgit v1.2.3