pub trait Chunk {
Show 18 methods
// Required methods
fn height(&self) -> u32;
fn block_state(&self, x: u32, y: u32, z: u32) -> BlockState;
fn set_block_state(
&mut self,
x: u32,
y: u32,
z: u32,
block: BlockState,
) -> BlockState;
fn fill_block_state_section(&mut self, sect_y: u32, block: BlockState);
fn block_entity(&self, x: u32, y: u32, z: u32) -> Option<&Compound>;
fn block_entity_mut(
&mut self,
x: u32,
y: u32,
z: u32,
) -> Option<&mut Compound>;
fn set_block_entity(
&mut self,
x: u32,
y: u32,
z: u32,
block_entity: Option<Compound>,
) -> Option<Compound>;
fn clear_block_entities(&mut self);
fn biome(&self, x: u32, y: u32, z: u32) -> BiomeId;
fn set_biome(&mut self, x: u32, y: u32, z: u32, biome: BiomeId) -> BiomeId;
fn fill_biome_section(&mut self, sect_y: u32, biome: BiomeId);
fn shrink_to_fit(&mut self);
// Provided methods
fn block(&self, x: u32, y: u32, z: u32) -> BlockRef<'_> { ... }
fn set_block(
&mut self,
x: u32,
y: u32,
z: u32,
block: impl IntoBlock,
) -> Block { ... }
fn fill_blocks(&mut self, block: impl IntoBlock) { ... }
fn fill_block_states(&mut self, block: BlockState) { ... }
fn fill_biomes(&mut self, biome: BiomeId) { ... }
fn clear(&mut self) { ... }
}
Expand description
Common operations on chunks. Notable implementors are
LoadedChunk
and
UnloadedChunk
.
Required Methods§
Sourcefn block_state(&self, x: u32, y: u32, z: u32) -> BlockState
fn block_state(&self, x: u32, y: u32, z: u32) -> BlockState
Gets the block state at the provided position in this chunk. x
and z
are in the range 0..16
while y
is in the range 0..height
.
§Panics
May panic if the position is out of bounds.
Sourcefn set_block_state(
&mut self,
x: u32,
y: u32,
z: u32,
block: BlockState,
) -> BlockState
fn set_block_state( &mut self, x: u32, y: u32, z: u32, block: BlockState, ) -> BlockState
Sets the block state at the provided position in this chunk. x
and z
are in the range 0..16
while y
is in the range 0..height
. The
previous block state at the position is returned.
NOTE: This is a low-level function which may break expected
invariants for block entities. Prefer Self::set_block
if performance
is not a concern.
§Panics
May panic if the position is out of bounds.
Sourcefn fill_block_state_section(&mut self, sect_y: u32, block: BlockState)
fn fill_block_state_section(&mut self, sect_y: u32, block: BlockState)
Replaces all the block states in a section with the provided block state.
NOTE: This is a low-level function which may break expected
invariants for block entities. Prefer Self::set_block
if performance
is not a concern.
§Panics
May panic if the section offset is out of bounds.
Sourcefn block_entity(&self, x: u32, y: u32, z: u32) -> Option<&Compound>
fn block_entity(&self, x: u32, y: u32, z: u32) -> Option<&Compound>
Gets the block entity at the provided position in this chunk. x
and
z
are in the range 0..16
while y
is in the range 0..height
.
§Panics
May panic if the position is out of bounds.
Sourcefn block_entity_mut(&mut self, x: u32, y: u32, z: u32) -> Option<&mut Compound>
fn block_entity_mut(&mut self, x: u32, y: u32, z: u32) -> Option<&mut Compound>
Gets a mutable reference to the block entity at the provided position in
this chunk. x
and z
are in the range 0..16
while y
is in the
range 0..height
.
§Panics
May panic if the position is out of bounds.
Sourcefn set_block_entity(
&mut self,
x: u32,
y: u32,
z: u32,
block_entity: Option<Compound>,
) -> Option<Compound>
fn set_block_entity( &mut self, x: u32, y: u32, z: u32, block_entity: Option<Compound>, ) -> Option<Compound>
Sets the block entity at the provided position in this chunk. x
and
z
are in the range 0..16
while y
is in the range 0..height
.
The previous block entity at the position is returned.
NOTE: This is a low-level function which may break expected
invariants for block entities. Prefer Self::set_block
if performance
is not a concern.
§Panics
May panic if the position is out of bounds.
Sourcefn clear_block_entities(&mut self)
fn clear_block_entities(&mut self)
Removes all block entities from the chunk.
NOTE: This is a low-level function which may break expected
invariants for block entities. Prefer Self::set_block
if performance
is not a concern.
Sourcefn biome(&self, x: u32, y: u32, z: u32) -> BiomeId
fn biome(&self, x: u32, y: u32, z: u32) -> BiomeId
Gets the biome at the provided position in this chunk. x
and z
are
in the range 0..4
while y
is in the range 0..height / 4
.
Note that biomes are 4x4x4 segments of a chunk, so the xyz arguments to
this method differ from those to Self::block_state
and
Self::block_entity
.
§Panics
May panic if the position is out of bounds.
Sourcefn set_biome(&mut self, x: u32, y: u32, z: u32, biome: BiomeId) -> BiomeId
fn set_biome(&mut self, x: u32, y: u32, z: u32, biome: BiomeId) -> BiomeId
Sets the biome at the provided position in this chunk. The Previous
biome at the position is returned. x
and z
are in the range 0..4
while y
is in the range 0..height / 4
.
Note that biomes are 4x4x4 segments of a chunk, so the xyz arguments to
this method differ from those to Self::block_state
and
Self::block_entity
.
§Panics
May panic if the position is out of bounds.
Sourcefn fill_biome_section(&mut self, sect_y: u32, biome: BiomeId)
fn fill_biome_section(&mut self, sect_y: u32, biome: BiomeId)
Replaces all the biomes in a section with the provided biome.
§Panics
May panic if the section offset is out of bounds.
Sourcefn shrink_to_fit(&mut self)
fn shrink_to_fit(&mut self)
Attempts to optimize this chunk by reducing its memory usage or other characteristics. This may be a relatively expensive operation.
This method must not alter the semantics of the chunk in any observable way.
Provided Methods§
Sourcefn block(&self, x: u32, y: u32, z: u32) -> BlockRef<'_>
fn block(&self, x: u32, y: u32, z: u32) -> BlockRef<'_>
Gets the block at the provided position in this chunk. x
and z
are in the range 0..16
while y
is in the range 0..height
.
§Panics
May panic if the position is out of bounds.
Sourcefn set_block(&mut self, x: u32, y: u32, z: u32, block: impl IntoBlock) -> Block
fn set_block(&mut self, x: u32, y: u32, z: u32, block: impl IntoBlock) -> Block
Sets the block at the provided position in this chunk. x
and z
are in the range 0..16
while y
is in the range 0..height
. The
previous block at the position is returned.
§Panics
May panic if the position is out of bounds.
Sourcefn fill_blocks(&mut self, block: impl IntoBlock)
fn fill_blocks(&mut self, block: impl IntoBlock)
Sets all the blocks in the entire chunk to the provided block.
Sourcefn fill_block_states(&mut self, block: BlockState)
fn fill_block_states(&mut self, block: BlockState)
Replaces all block states in the entire chunk with the provided block state.
NOTE: This is a low-level function which may break expected
invariants for block entities. Prefer Self::fill_blocks
instead.
Sourcefn fill_biomes(&mut self, biome: BiomeId)
fn fill_biomes(&mut self, biome: BiomeId)
Sets all the biomes in the entire chunk to the provided biome.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.