diff options
| author | mat <git@matdoes.dev> | 2025-06-02 07:45:26 +1100 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-06-02 07:45:26 +1100 |
| commit | d028d7c3e9c84d177b7b10fa0d8f77d11bcea20f (patch) | |
| tree | a37fa4167a3171dd46c17d8ea5b8674cc72c3c78 /azalea-core/src | |
| parent | b103e6fdc0daa131d1177c5d0705134640aa9d6e (diff) | |
| download | azalea-drasl-d028d7c3e9c84d177b7b10fa0d8f77d11bcea20f.tar.xz | |
add basic support for getting biome ids in chunks
Diffstat (limited to 'azalea-core/src')
| -rw-r--r-- | azalea-core/src/position.rs | 48 |
1 files changed, 46 insertions, 2 deletions
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<ChunkBlockPos> 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<ChunkSectionBlockPos> for ChunkSectionPos { type Output = BlockPos; |
