pub struct ProtoChunk {
pub dirty: bool,
/* private fields */
}
Expand description
A temporary chunk structure used to add entity builders that will be added to the level’s ECS later in sync when the source actually returns it.
Fields§
§dirty: bool
This boolean indicates when the proto chunk must be saved after being added to the level.
Implementations§
Source§impl ProtoChunk
impl ProtoChunk
Sourcepub fn add_proto_entity(&mut self, entity_builder: EntityBuilder) -> usize
pub fn add_proto_entity(&mut self, entity_builder: EntityBuilder) -> usize
Add an entity builder to this proto chunk, this builder will be added to the level when
building the actual Chunk
. You must ensure that this entity contains a BaseEntity
component with an entity_type
supported by the level’s environment.
This method also return the index of this entity within the proto chunk, this can be used to add passengers to this entity or make this entity ride another one.
pub fn add_proto_entity_passengers( &mut self, host_index: usize, passenger_index: usize, )
Methods from Deref<Target = Chunk>§
Sourcepub fn get_position(&self) -> (i32, i32)
pub fn get_position(&self) -> (i32, i32)
Get the chunk position (x, z)
.
pub fn get_env(&self) -> &Arc<LevelEnv>
pub fn get_status(&self) -> ChunkStatus
pub fn set_status(&mut self, status: ChunkStatus)
pub fn get_inhabited_time(&self) -> u64
pub fn set_inhabited_time(&mut self, time: u64)
pub fn get_last_save(&self) -> Instant
pub fn update_last_save(&mut self)
Sourcepub fn get_height(&self) -> ChunkHeight
pub fn get_height(&self) -> ChunkHeight
Return the configured height for the level owning this chunk.
Sourcepub fn get_sub_chunk_offset(&self, cy: i8) -> Option<usize>
pub fn get_sub_chunk_offset(&self, cy: i8) -> Option<usize>
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.
Sourcepub fn ensure_sub_chunk(&mut self, cy: i8) -> ChunkResult<&mut SubChunk>
pub fn ensure_sub_chunk(&mut self, cy: i8) -> ChunkResult<&mut SubChunk>
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 ensure_sub_chunk_at(&mut self, y: i32) -> ChunkResult<&mut SubChunk>
Sourcepub 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.
Sourcepub fn get_sub_chunk(&self, cy: i8) -> Option<&SubChunk>
pub fn get_sub_chunk(&self, cy: i8) -> Option<&SubChunk>
Get a sub chunk reference at a specified index.
pub fn get_sub_chunk_at(&self, y: i32) -> Option<&SubChunk>
Sourcepub fn get_sub_chunk_mut(&mut self, cy: i8) -> Option<&mut SubChunk>
pub fn get_sub_chunk_mut(&mut self, cy: i8) -> Option<&mut SubChunk>
Get a sub chunk mutable reference at a specified index.
pub fn get_sub_chunk_at_mut(&mut self, y: i32) -> Option<&mut SubChunk>
Sourcepub fn get_sub_chunks_count(&self) -> usize
pub fn get_sub_chunks_count(&self) -> usize
Return the number of sub chunks in the height of this chunk.
Sourcepub fn iter_sub_chunks(
&self,
) -> impl Iterator<Item = (i8, Option<&SubChunk>)> + '_
pub fn iter_sub_chunks( &self, ) -> impl Iterator<Item = (i8, Option<&SubChunk>)> + '_
Iterator over all sub chunks with their Y coordinate, sub chunks may be not loaded (None
).
Sourcepub fn iter_loaded_sub_chunks(
&self,
) -> impl Iterator<Item = (i8, &SubChunk)> + '_
pub fn iter_loaded_sub_chunks( &self, ) -> impl Iterator<Item = (i8, &SubChunk)> + '_
Iterator only over loaded sub chunks.
Sourcepub fn get_highest_non_null_sub_chunk(&self) -> i8
pub fn get_highest_non_null_sub_chunk(&self) -> i8
Return the index of the first sub chunk (starting from the top sub chunk) that is loaded AND contains a non null block.
Sourcepub fn get_block(
&self,
x: u8,
y: i32,
z: u8,
) -> ChunkResult<&'static BlockState>
pub fn get_block( &self, x: u8, y: i32, z: u8, ) -> ChunkResult<&'static BlockState>
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.
Sourcepub fn get_block_at(
&self,
x: i32,
y: i32,
z: i32,
) -> ChunkResult<&'static BlockState>
pub fn get_block_at( &self, x: i32, y: i32, z: i32, ) -> ChunkResult<&'static BlockState>
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.
Sourcepub 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.
Sourcepub 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.
Sourcepub fn get_biome(&self, x: u8, y: i32, z: u8) -> ChunkResult<&'static Biome>
pub fn get_biome(&self, x: u8, y: i32, z: u8) -> ChunkResult<&'static Biome>
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 get_biome_at( &self, x: i32, y: i32, z: i32, ) -> ChunkResult<&'static Biome>
Sourcepub fn set_biome(
&mut self,
x: u8,
y: i32,
z: u8,
biome: &'static Biome,
) -> ChunkResult<()>
pub fn set_biome( &mut self, x: u8, y: i32, z: u8, biome: &'static Biome, ) -> ChunkResult<()>
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<()>
Sourcepub fn set_biomes_2d(
&mut self,
biomes: &Rect<&'static Biome>,
) -> ChunkResult<()>
pub fn set_biomes_2d( &mut self, biomes: &Rect<&'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.
pub fn set_biomes_3d(&mut self, biomes: &[&'static Biome]) -> ChunkResult<()>
pub fn get_biomes_count(&self) -> usize
Sourcepub fn iter_biomes(&self) -> impl Iterator<Item = &'static Biome> + '_
pub fn iter_biomes(&self) -> impl Iterator<Item = &'static Biome> + '_
Expose internal biomes storage, retuning an iterator with each biomes in this chunk, ordered by X, Z then Y.
Sourcepub 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<()>
Sourcepub 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>
Sourcepub fn recompute_heightmap_column(&mut self, x: u8, z: u8)
pub fn recompute_heightmap_column(&mut self, x: u8, z: u8)
Public method that you can use to recompute a single column for all heightmaps.
Sourcepub 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.