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
impl GlobalBlocks
pub fn new() -> Self
Sourcepub fn with_all(slice: &[&'static Block]) -> Result<Self, ()>
pub fn with_all(slice: &[&'static Block]) -> Result<Self, ()>
A simple constructor to directly call register_all with given blocks slice.
Sourcepub fn register(&mut self, block: &'static Block) -> Result<(), ()>
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.
Sourcepub fn register_all(&mut self, slice: &[&'static Block]) -> Result<(), ()>
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.
Sourcepub fn get_sid_from(&self, state: &'static BlockState) -> Option<u32>
pub fn get_sid_from(&self, state: &'static BlockState) -> Option<u32>
Get the save ID from the given state.
Sourcepub fn get_state_from(&self, sid: u32) -> Option<&'static BlockState>
pub fn get_state_from(&self, sid: u32) -> Option<&'static BlockState>
Get the block state from the given save ID.
Sourcepub fn get_block_from_name(&self, name: &str) -> Option<&'static Block>
pub fn get_block_from_name(&self, name: &str) -> Option<&'static Block>
Get the default state from the given block name.
Sourcepub fn has_block(&self, block: &'static Block) -> bool
pub fn has_block(&self, block: &'static Block) -> bool
Return true if the palette contains the given block.
Sourcepub fn has_state(&self, state: &'static BlockState) -> bool
pub fn has_state(&self, state: &'static BlockState) -> bool
Return true if the palette contains the given block state.
Sourcepub fn check_state<E>(
&self,
state: &'static BlockState,
err: impl FnOnce() -> E,
) -> Result<&'static BlockState, E>
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.
Sourcepub fn register_tag_type(&mut self, tag_type: &'static TagType)
pub fn register_tag_type(&mut self, tag_type: &'static TagType)
Register a tag type that will be later possible to set to blocks.
Sourcepub fn set_blocks_tag<I>(
&mut self,
tag_type: &'static TagType,
enabled: bool,
blocks: I,
) -> Result<(), ()>where
I: IntoIterator<Item = &'static Block>,
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.
Sourcepub fn has_block_tag(
&self,
block: &'static Block,
tag_type: &'static TagType,
) -> bool
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.