aboutsummaryrefslogtreecommitdiff
path: root/azalea-world/src/heightmap.rs
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2026-01-12 02:09:41 -0600
committerGitHub <noreply@github.com>2026-01-12 02:09:41 -0600
commit1accbac964168af5fa0d87cb170389f0a9d01363 (patch)
tree1509b26c19beaa23a492289f6bf00d3958be44d5 /azalea-world/src/heightmap.rs
parent58339b9d229592dee40e15b8648fe4075cc391f4 (diff)
downloadazalea-drasl-1accbac964168af5fa0d87cb170389f0a9d01363.tar.xz
Make Bevy dependencies optional in azalea-protocol (#303)
* Make Bevy dependencies optional in azalea-protocol * derive serde traits on Direction again * update docs for types that may not have Component
Diffstat (limited to 'azalea-world/src/heightmap.rs')
-rw-r--r--azalea-world/src/heightmap.rs86
1 files changed, 22 insertions, 64 deletions
diff --git a/azalea-world/src/heightmap.rs b/azalea-world/src/heightmap.rs
index 033fa569..bae11cea 100644
--- a/azalea-world/src/heightmap.rs
+++ b/azalea-world/src/heightmap.rs
@@ -1,33 +1,20 @@
-use std::{
- fmt::{self, Display},
- str::FromStr,
-};
-
use azalea_block::{BlockState, BlockTrait};
-use azalea_buf::AzBuf;
-use azalea_core::{math, position::ChunkBlockPos};
+use azalea_core::{heightmap_kind::HeightmapKind as HeightmapKind_, math, position::ChunkBlockPos};
use azalea_registry::tags::blocks::LEAVES;
use tracing::warn;
use crate::{BitStorage, Section, chunk_storage::get_block_state_from_sections};
-// (wg stands for worldgen)
-
-#[derive(AzBuf, Clone, Copy, Debug, Eq, Hash, PartialEq)]
-pub enum HeightmapKind {
- WorldSurfaceWg,
- WorldSurface,
- OceanFloorWg,
- OceanFloor,
- MotionBlocking,
- MotionBlockingNoLeaves,
-}
+// TODO: when removing this deprecated marker, also rename `HeightmapKind_` back
+// to `HeightmapKind`.
+#[deprecated = "moved to `azalea_core::heightmap_kind::HeightmapKind`."]
+pub type HeightmapKind = azalea_core::heightmap_kind::HeightmapKind;
#[derive(Clone, Debug)]
pub struct Heightmap {
pub data: BitStorage,
pub min_y: i32,
- pub kind: HeightmapKind,
+ pub kind: HeightmapKind_,
}
fn blocks_motion(block_state: BlockState) -> bool {
@@ -43,25 +30,24 @@ fn motion_blocking(block_state: BlockState) -> bool {
.unwrap_or_default()
}
-impl HeightmapKind {
- pub fn is_opaque(self, block_state: BlockState) -> bool {
- let block = Box::<dyn BlockTrait>::from(block_state);
- let registry_block = block.as_registry_block();
- match self {
- HeightmapKind::WorldSurfaceWg => !block_state.is_air(),
- HeightmapKind::WorldSurface => !block_state.is_air(),
- HeightmapKind::OceanFloorWg => blocks_motion(block_state),
- HeightmapKind::OceanFloor => blocks_motion(block_state),
- HeightmapKind::MotionBlocking => motion_blocking(block_state),
- HeightmapKind::MotionBlockingNoLeaves => {
- motion_blocking(block_state) && !LEAVES.contains(&registry_block)
- }
+pub fn is_heightmap_opaque(heightmap: HeightmapKind_, block_state: BlockState) -> bool {
+ let block = Box::<dyn BlockTrait>::from(block_state);
+ let registry_block = block.as_registry_block();
+ type K = HeightmapKind_;
+ match heightmap {
+ K::WorldSurfaceWg => !block_state.is_air(),
+ K::WorldSurface => !block_state.is_air(),
+ K::OceanFloorWg => blocks_motion(block_state),
+ K::OceanFloor => blocks_motion(block_state),
+ K::MotionBlocking => motion_blocking(block_state),
+ K::MotionBlockingNoLeaves => {
+ motion_blocking(block_state) && !LEAVES.contains(&registry_block)
}
}
}
impl Heightmap {
- pub fn new(kind: HeightmapKind, dimension_height: u32, min_y: i32, data: Box<[u64]>) -> Self {
+ pub fn new(kind: HeightmapKind_, dimension_height: u32, min_y: i32, data: Box<[u64]>) -> Self {
let bits = math::ceil_log2(dimension_height + 1);
let mut bit_storage = BitStorage::new(bits as usize, 16 * 16, None)
.expect("data is empty, so this can't fail");
@@ -113,7 +99,7 @@ impl Heightmap {
if pos.y <= first_available_y - 2 {
return false;
}
- if self.kind.is_opaque(block_state) {
+ if is_heightmap_opaque(self.kind, block_state) {
// increase y
if pos.y >= first_available_y {
self.set_height(pos.x, pos.z, pos.y + 1);
@@ -122,7 +108,8 @@ impl Heightmap {
} else if first_available_y - 1 == pos.y {
// decrease y
for y in (self.min_y..pos.y).rev() {
- if self.kind.is_opaque(
+ if is_heightmap_opaque(
+ self.kind,
get_block_state_from_sections(
sections,
&ChunkBlockPos::new(pos.x, y, pos.z),
@@ -161,32 +148,3 @@ impl Heightmap {
})
}
}
-
-impl FromStr for HeightmapKind {
- type Err = ();
-
- fn from_str(s: &str) -> Result<Self, Self::Err> {
- match s {
- "WORLD_SURFACE_WG" => Ok(HeightmapKind::WorldSurfaceWg),
- "WORLD_SURFACE" => Ok(HeightmapKind::WorldSurface),
- "OCEAN_FLOOR_WG" => Ok(HeightmapKind::OceanFloorWg),
- "OCEAN_FLOOR" => Ok(HeightmapKind::OceanFloor),
- "MOTION_BLOCKING" => Ok(HeightmapKind::MotionBlocking),
- "MOTION_BLOCKING_NO_LEAVES" => Ok(HeightmapKind::MotionBlockingNoLeaves),
- _ => Err(()),
- }
- }
-}
-
-impl Display for HeightmapKind {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- match self {
- HeightmapKind::WorldSurfaceWg => write!(f, "WORLD_SURFACE_WG"),
- HeightmapKind::WorldSurface => write!(f, "WORLD_SURFACE"),
- HeightmapKind::OceanFloorWg => write!(f, "OCEAN_FLOOR_WG"),
- HeightmapKind::OceanFloor => write!(f, "OCEAN_FLOOR"),
- HeightmapKind::MotionBlocking => write!(f, "MOTION_BLOCKING"),
- HeightmapKind::MotionBlockingNoLeaves => write!(f, "MOTION_BLOCKING_NO_LEAVES"),
- }
- }
-}