ProtoChunk

Struct ProtoChunk 

Source
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

Source

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.

Source

pub fn add_proto_entity_passengers( &mut self, host_index: usize, passenger_index: usize, )

Methods from Deref<Target = Chunk>§

Source

pub fn get_position(&self) -> (i32, i32)

Get the chunk position (x, z).

Source

pub fn get_env(&self) -> &Arc<LevelEnv>

Source

pub fn get_status(&self) -> ChunkStatus

Source

pub fn set_status(&mut self, status: ChunkStatus)

Source

pub fn get_inhabited_time(&self) -> u64

Source

pub fn set_inhabited_time(&mut self, time: u64)

Source

pub fn get_last_save(&self) -> Instant

Source

pub fn update_last_save(&mut self)

Source

pub fn get_height(&self) -> ChunkHeight

Return the configured height for the level owning this chunk.

Source

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.

Source

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.

Source

pub fn ensure_sub_chunk_at(&mut self, y: i32) -> ChunkResult<&mut SubChunk>

Source

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.

Source

pub fn get_sub_chunk(&self, cy: i8) -> Option<&SubChunk>

Get a sub chunk reference at a specified index.

Source

pub fn get_sub_chunk_at(&self, y: i32) -> Option<&SubChunk>

Source

pub fn get_sub_chunk_mut(&mut self, cy: i8) -> Option<&mut SubChunk>

Get a sub chunk mutable reference at a specified index.

Source

pub fn get_sub_chunk_at_mut(&mut self, y: i32) -> Option<&mut SubChunk>

Source

pub fn get_sub_chunks_count(&self) -> usize

Return the number of sub chunks in the height of this chunk.

Source

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).

Source

pub fn iter_loaded_sub_chunks( &self, ) -> impl Iterator<Item = (i8, &SubChunk)> + '_

Iterator only over loaded sub chunks.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn get_biome_at( &self, x: i32, y: i32, z: i32, ) -> ChunkResult<&'static Biome>

Source

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.

Source

pub fn set_biome_at( &mut self, x: i32, y: i32, z: i32, biome: &'static Biome, ) -> ChunkResult<()>

Source

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.

Source

pub fn set_biomes_3d(&mut self, biomes: &[&'static Biome]) -> ChunkResult<()>

Source

pub fn get_biomes_count(&self) -> usize

Source

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.

Source

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.

Source

pub fn set_heightmap_column_at( &mut self, heightmap_type: &'static HeightmapType, x: i32, z: i32, y: i32, ) -> ChunkResult<()>

Source

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.

Source

pub fn get_heightmap_column_at( &self, heightmap_type: &'static HeightmapType, x: i32, z: i32, ) -> ChunkResult<i32>

Source

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.

Source

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.

Source

pub unsafe fn add_entity_unchecked(&mut self, entity: Entity)

Source

pub unsafe fn remove_entity_unchecked(&mut self, entity: Entity)

Source

pub fn has_entity(&self, entity: Entity) -> bool

Trait Implementations§

Source§

impl Debug for ProtoChunk

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for ProtoChunk

Source§

type Target = Chunk

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for ProtoChunk

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Component for T
where T: Send + Sync + 'static,