Struct level_lib::anvil::region::chunk::section::ChunkSection

source ·
pub struct ChunkSection {
    pub y: i8,
    pub block_palette: Vec<BlockData>,
    pub block_data: Option<[i64; 4096]>,
    pub biome_palette: Vec<String>,
    pub biome_data: Option<[i64; 64]>,
    pub block_light: Option<[i8; 4096]>,
    pub sky_light: Option<[i8; 4096]>,
}
Expand description

A structure containing important data of a section of a Chunk it stores a section of 161616 (4096) blocks

§Source

§Info

Everything, taged as “Not confirmed for 1.18 format” is not implemented, but will be if it turnes out to be neccessarry

Fields§

§y: i8

The y position of the sector

§block_palette: Vec<BlockData>

A list of all used blocks in a chunk

§block_data: Option<[i64; 4096]>

A list of all placed blocks, the list contains the offset into the block_palette list to save some memmory, this field is optional, if None and block_palette.len() == 1 then the whole sections is filled with that one block.

§Example

full chunk of Air: the block_palette contains the data for air. the block_data is None to indicate that the same data is used accross the whole section

§Info

The stored indices are always as small as possible, but at least 4 bits with no packing accross multiple elements of the array. Meaning if the chunk consists of 33 different blocks, we need 5 bits to represent all unique blocks, now we can divide 64 by the amount of needed bits and floor the result to know how much block entries we can store per element(u64). For example $⌊64/5⌋ = 12$ so if we need 5 bits to represent each unique block we can store 12 per element.

§Note

The explanation above only applies to the nbt representation. The used on in the code has an entry for each element to keep the amount of computation low in a trade of with a bit more used memory

§biome_palette: Vec<String>

A list of all used biomes in the chunk

§biome_data: Option<[i64; 64]>

An optional list of the biomes used on each (x | z) position. If the value is None every location in the section has the same biome

§block_light: Option<[i8; 4096]>

The light emitter data of each block in the chunk

§Note

In the Nbt data this will be stored as a [u8; 2048] where each element will contain two block each 4-bits of light data.

§sky_light: Option<[i8; 4096]>

The sky light data of each block in the chunk

§Note

In the Nbt data this will be stored as a [u8; 2048] where each element will contain two block each 4-bits of light data.

Implementations§

source§

impl ChunkSection

source

pub fn new_filled(y: i8, filler: &str, sees_sky: bool) -> Self

creates a new ChunkSection that is filled with a specified block

source

pub fn new_with_height_map( y: i8, filler: &str, sees_sky: bool, heightmap: [[i16; 16]; 16] ) -> Self

creates a new chunk section, with a given heightmap

Trait Implementations§

source§

impl AsNbtValue for ChunkSection

source§

fn as_nbt_value(&self) -> Result<NbtValue, ()>

converts the struct to a NbtValue
source§

impl Debug for ChunkSection

source§

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

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

impl FromNbtValue for ChunkSection

source§

fn from_nbt_value(value: NbtValue) -> Result<Self, ()>
where Self: Sized,

converts the struct to a NbtValue
source§

impl PartialEq for ChunkSection

source§

fn eq(&self, other: &ChunkSection) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StructuralPartialEq for ChunkSection

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<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.