pub trait BlockTrait: Debug + Any {
// Required methods
fn behavior(&self) -> BlockBehavior;
fn id(&self) -> &'static str;
fn as_block_state(&self) -> BlockState;
fn as_block_kind(&self) -> BlockKind;
fn property_map(&self) -> HashMap<&'static str, &'static str>;
fn get_property(&self, name: &str) -> Option<&'static str>;
fn set_property(
&mut self,
name: &str,
new_value: &str,
) -> Result<(), InvalidPropertyError>;
}Expand description
A trait that’s implemented on block structs.
See the azalea_block documentation for details.
Required Methods§
fn behavior(&self) -> BlockBehavior
Sourcefn id(&self) -> &'static str
fn id(&self) -> &'static str
Get the Minecraft string ID for this block.
For example, stone or grass_block.
Sourcefn as_block_state(&self) -> BlockState
fn as_block_state(&self) -> BlockState
Convert the block struct to a BlockState.
This is a lossless conversion, as BlockState also contains state
data.
Sourcefn as_block_kind(&self) -> BlockKind
fn as_block_kind(&self) -> BlockKind
Sourcefn property_map(&self) -> HashMap<&'static str, &'static str>
fn property_map(&self) -> HashMap<&'static str, &'static str>
Returns a map of property names on this block to their values as strings.
Consider using Self::get_property if you only need a single
property.
Sourcefn get_property(&self, name: &str) -> Option<&'static str>
fn get_property(&self, name: &str) -> Option<&'static str>
Get a property’s value as a string by its name, or None if the block
has no property with that name.
To get all properties, you may use Self::property_map.
To set a property, use Self::set_property.
Sourcefn set_property(
&mut self,
name: &str,
new_value: &str,
) -> Result<(), InvalidPropertyError>
fn set_property( &mut self, name: &str, new_value: &str, ) -> Result<(), InvalidPropertyError>
Update a property on this block, with the name and value being strings.
Returns Ok(()), if the property name and value are valid, otherwise it
returns Err(InvalidPropertyError).
To get a property, use Self::get_property.