pub trait BlockTrait: Debug + Any {
// Required methods
fn behavior(&self) -> BlockBehavior;
fn id(&self) -> &'static str;
fn as_block_state(&self) -> BlockState;
fn as_registry_block(&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>;
}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_registry_block(&self) -> BlockKind
fn as_registry_block(&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.
Implementations§
Source§impl dyn BlockTrait
impl dyn BlockTrait
pub fn downcast_ref<T: BlockTrait>(&self) -> Option<&T>
Trait Implementations§
Source§impl From<BlockState> for Box<dyn BlockTrait>
impl From<BlockState> for Box<dyn BlockTrait>
Source§fn from(block_state: BlockState) -> Self
fn from(block_state: BlockState) -> Self
Converts to this type from the input type.