pub struct Heightmap {
data: Box<[u16; 256]>,
map_type: HeightmapType,
min_y: i32,
height: i32,
}Expand description
A heightmap that tracks the highest blocks of a specific type in a chunk.
The heightmap stores heights for each column in a 16x16 chunk.
Heights are stored relative to min_y, so data[index] + min_y gives the actual Y coordinate.
Fields§
§data: Box<[u16; 256]>Height data stored as a flat array of 256 entries (16x16).
Each entry stores the height relative to min_y.
map_type: HeightmapTypeThe type of this heightmap.
min_y: i32The minimum Y coordinate of the world.
height: i32The total height of the world.
Implementations§
Source§impl Heightmap
impl Heightmap
Sourcepub fn new(map_type: HeightmapType, min_y: i32, height: i32) -> Self
pub fn new(map_type: HeightmapType, min_y: i32, height: i32) -> Self
Creates a new heightmap with all heights initialized to min_y.
Sourcepub const fn from_raw_data(
map_type: HeightmapType,
min_y: i32,
height: i32,
data: Box<[u16; 256]>,
) -> Self
pub const fn from_raw_data( map_type: HeightmapType, min_y: i32, height: i32, data: Box<[u16; 256]>, ) -> Self
Creates a heightmap from raw height data loaded from disk.
Sourcepub const fn heightmap_type(&self) -> HeightmapType
pub const fn heightmap_type(&self) -> HeightmapType
Returns the heightmap type.
Sourceconst fn get_index(local_x: usize, local_z: usize) -> usize
const fn get_index(local_x: usize, local_z: usize) -> usize
Gets the index into the data array for the given local coordinates.
Sourcepub fn get_first_available(&self, local_x: usize, local_z: usize) -> i32
pub fn get_first_available(&self, local_x: usize, local_z: usize) -> i32
Gets the first available Y coordinate (one above the highest block) at the given position.
Sourcepub fn get_highest_taken(&self, local_x: usize, local_z: usize) -> i32
pub fn get_highest_taken(&self, local_x: usize, local_z: usize) -> i32
Gets the highest taken Y coordinate at the given position.
Sourcepub fn set_height(&mut self, local_x: usize, local_z: usize, height: i32)
pub fn set_height(&mut self, local_x: usize, local_z: usize, height: i32)
Sets the height at the given position.
Sourcepub fn update<F>(
&mut self,
local_x: usize,
y: i32,
local_z: usize,
state: BlockStateId,
get_block: F,
) -> bool
pub fn update<F>( &mut self, local_x: usize, y: i32, local_z: usize, state: BlockStateId, get_block: F, ) -> bool
Updates the heightmap when a block changes.
Returns true if the heightmap was modified.
§Arguments
local_x- The local X coordinate (0-15)y- The absolute Y coordinatelocal_z- The local Z coordinate (0-15)state- The new block state at this positionget_block- A function to get block states at other positions for scanning down
Sourcepub fn update_for_initial_fill(
&mut self,
local_x: usize,
y: i32,
local_z: usize,
state: BlockStateId,
) -> bool
pub fn update_for_initial_fill( &mut self, local_x: usize, y: i32, local_z: usize, state: BlockStateId, ) -> bool
Updates this heightmap for a direct write into a previously-air block.
Vanilla’s noise fill writes sections directly and updates the worldgen heightmaps beside those writes. There is no downward scan in that path because blocks are only being added to an empty terrain column.
Sourcepub fn raw_data(&self) -> &[u16; 256]
pub fn raw_data(&self) -> &[u16; 256]
Returns a direct reference to the raw height data array.
Values are stored relative to min_y. Used for persistence.
Sourcepub fn get_raw_data(&self) -> Vec<i64>
pub fn get_raw_data(&self) -> Vec<i64>
Gets the raw data as a slice of i64 values for network serialization.
The data is packed using the minimum number of bits required to store
the height range (0 to world_height).
Sourceconst fn calculate_bits_per_value(height: i32) -> usize
const fn calculate_bits_per_value(height: i32) -> usize
Calculates the number of bits required to store heights for a given world height.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Heightmap
impl RefUnwindSafe for Heightmap
impl Send for Heightmap
impl Sync for Heightmap
impl Unpin for Heightmap
impl UnsafeUnpin for Heightmap
impl UnwindSafe for Heightmap
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreArc<SyncMutex<>>