Struct mc_core::world::chunk::Chunk [−][src]
pub struct Chunk { /* fields omitted */ }Expand description
A vertical chunk, 16x16 blocks. This vertical chunk is composed of multiple SubChunks,
each sub chunk has stores blocks, biomes, lights. This structure however stores metadata
about the chunk like inhabited time and generation status. All entities and block entities
are also stored in the chunk.
Implementations
Return the configured height for the level owning this chunk.
Return the linear non-negative offset of the chunk at the given position, the position can be negative. None is returned if the chunk position is not within the chunk’s height.
Ensure that a sub chunk is existing at a specific chunk-Y coordinate, if this coordinate
is out of the height of the level, Err(ChunkError::SubChunkOutOfRange) is returned.
pub fn replace_sub_chunk(
&mut self,
cy: i8,
sub_chunk: SubChunk
) -> ChunkResult<&mut SubChunk>
pub fn replace_sub_chunk(
&mut self,
cy: i8,
sub_chunk: SubChunk
) -> ChunkResult<&mut SubChunk>
Replace the sub chunk at the given Y chunk coordinate by the given one.
Panics (debug only):
The method panics if the given sub chunk has not the same sub chunk environment as self.
Get a sub chunk reference at a specified index.
Get a sub chunk mutable reference at a specified index.
Return the number of sub chunks in the height of this chunk.
Iterator over all sub chunks with their Y coordinate, sub chunks may be not loaded (None).
Iterator only over loaded sub chunks.
Return the index of the first sub chunk (starting from the top sub chunk) that is loaded AND contains a non null block.
Get the block at a specific position.
Returns Ok(&BlockState) if the block is found and valid,
Err(ChunkError::SubChunkOutOfRange) if the given y coordinate is out of the chunk
height, if the Y coordinate is valid but the sub chunk is yet loaded, the “null-block”
is returned.
Panics (debug-only)
This method panics if either X or Z is higher than 15.
Same description as get_block but accept level coordinates instead of relative ones. This
method ignore if the given coordinates are not actually pointing to this chunk, it only
take the 4 least significant bits.
pub fn set_block(
&mut self,
x: u8,
y: i32,
z: u8,
state: &'static BlockState
) -> ChunkResult<()>
pub fn set_block(
&mut self,
x: u8,
y: i32,
z: u8,
state: &'static BlockState
) -> ChunkResult<()>
Set the block at a specific position relative to this chunk.
Return Ok(()) if the biome was successfully set, Err(ChunkError::SubChunkOutOfRange) if
the given Y coordinate is invalid for the level or Err(ChunkError::IllegalBlock) if the
given block state is not registered in the current world.
Panics (debug-only)
This method panics if either X or Z is higher than 15.
pub fn set_block_at(
&mut self,
x: i32,
y: i32,
z: i32,
state: &'static BlockState
) -> ChunkResult<()>
pub fn set_block_at(
&mut self,
x: i32,
y: i32,
z: i32,
state: &'static BlockState
) -> ChunkResult<()>
Same description as set_block but accept level coordinates instead of relative ones. This
method ignore if the given coordinates are not actually pointing to this chunk, it only
take the 4 least significant bits.
Get a biome at specific biome coordinates, biome coordinates are different from block coordinates because there is only 4x4x4 biomes samples for each sub chunk. Given X and Z coordinates must be lower than 4 and given Y coordinate must be valid for the chunk height.
Returns Ok(biome) or Err(ChunkError::SubChunkOutOfRange) if the given Y coordinate
is not supported by this chunk’s height.
Panics (debug-only)
This method panics if either X or Z is higher than 3.
Get a biome at specific biome coordinates, biome coordinates are different from block coordinates because there is only 4x4x4 biomes samples for each sub chunk. Given X and Z coordinates must be lower than 4 and given Y coordinate must be valid for the chunk height.
Returns Ok(biome) or Err(ChunkError::SubChunkOutOfRange) if the given Y coordinate
is not supported by this chunk’s height.
Panics (debug-only)
This method panics if either X or Z is higher than 3.
pub fn set_biome_at(
&mut self,
x: i32,
y: i32,
z: i32,
biome: &'static Biome
) -> ChunkResult<()>
Set all biome quads in this chunk according a to a 2D biomes rectangle (16x16). The implementation currently take the lower coordinates biome in each 4x4 rectangle and set it to the whole chunk height.
Expose internal biomes storage, retuning an iterator with each biomes in this chunk, ordered by X, Z then Y.
pub fn set_heightmap_column(
&mut self,
heightmap_type: &'static HeightmapType,
x: u8,
z: u8,
y: i32
) -> ChunkResult<()>
pub fn set_heightmap_column(
&mut self,
heightmap_type: &'static HeightmapType,
x: u8,
z: u8,
y: i32
) -> ChunkResult<()>
Set the value of a specific heightmap at specific coordinates. This is very unsafe to do that manually, you should ensure that the condition of the given heightmap type are kept.
pub fn set_heightmap_column_at(
&mut self,
heightmap_type: &'static HeightmapType,
x: i32,
z: i32,
y: i32
) -> ChunkResult<()>
pub fn get_heightmap_column(
&self,
heightmap_type: &'static HeightmapType,
x: u8,
z: u8
) -> ChunkResult<i32>
pub fn get_heightmap_column(
&self,
heightmap_type: &'static HeightmapType,
x: u8,
z: u8
) -> ChunkResult<i32>
Get the value of a specific heightmap at specific coordinates.
pub fn get_heightmap_column_at(
&self,
heightmap_type: &'static HeightmapType,
x: i32,
z: i32
) -> ChunkResult<i32>
Public method that you can use to recompute a single column for all heightmaps.
pub fn iter_heightmap_raw_columns(
&self,
heightmap_type: &'static HeightmapType
) -> Option<(u8, impl Iterator<Item = u64> + '_)>
pub fn iter_heightmap_raw_columns(
&self,
heightmap_type: &'static HeightmapType
) -> Option<(u8, impl Iterator<Item = u64> + '_)>
Direct access method to internal packed array, returning each of the 256 values from the given heightmap type if it exists, ordered by X then Z.
