GlobalBlocks

Struct GlobalBlocks 

Source
pub struct GlobalBlocks { /* private fields */ }
Expand description

This is a global blocks palette, it is used in chunk storage to store block states. It allows you to register individual blocks in it as well as static blocks arrays defined using the macro blocks!.

Implementations§

Source§

impl GlobalBlocks

Source

pub fn new() -> Self

Source

pub fn with_all(slice: &[&'static Block]) -> Result<Self, ()>

A simple constructor to directly call register_all with given blocks slice.

Source

pub fn register(&mut self, block: &'static Block) -> Result<(), ()>

Register a single block to this palette, returns Err if no more save ID (SID) is available, Ok is returned if successful, if a block was already in the palette it also returns Ok.

Source

pub fn register_all(&mut self, slice: &[&'static Block]) -> Result<(), ()>

An optimized way to call register multiple times for each given block, the returned follow the same rules as register, if an error happens, it return without and previous added blocks are kept.

Source

pub fn get_sid_from(&self, state: &'static BlockState) -> Option<u32>

Get the save ID from the given state.

Source

pub fn get_state_from(&self, sid: u32) -> Option<&'static BlockState>

Get the block state from the given save ID.

Source

pub fn get_block_from_name(&self, name: &str) -> Option<&'static Block>

Get the default state from the given block name.

Source

pub fn has_block(&self, block: &'static Block) -> bool

Return true if the palette contains the given block.

Source

pub fn has_state(&self, state: &'static BlockState) -> bool

Return true if the palette contains the given block state.

Source

pub fn check_state<E>( &self, state: &'static BlockState, err: impl FnOnce() -> E, ) -> Result<&'static BlockState, E>

Check if the given state is registered in this palette, Ok is returned if true, in the other case Err is returned with the error created by the given err closure.

Source

pub fn register_tag_type(&mut self, tag_type: &'static TagType)

Register a tag type that will be later possible to set to blocks.

Source

pub fn set_blocks_tag<I>( &mut self, tag_type: &'static TagType, enabled: bool, blocks: I, ) -> Result<(), ()>
where I: IntoIterator<Item = &'static Block>,

Set or unset a tag to some blocks.

Source

pub fn has_block_tag( &self, block: &'static Block, tag_type: &'static TagType, ) -> bool

Get the tag state on specific block, returning false if unknown block or tag type.

Source

pub fn blocks_count(&self) -> usize

Source

pub fn states_count(&self) -> usize

Source

pub fn tags_count(&self) -> usize

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

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,