diff options
Diffstat (limited to 'azalea-block/src')
| -rw-r--r-- | azalea-block/src/generated.rs | 2 | ||||
| -rw-r--r-- | azalea-block/src/lib.rs | 13 |
2 files changed, 12 insertions, 3 deletions
diff --git a/azalea-block/src/generated.rs b/azalea-block/src/generated.rs index 8d91695f..d042da22 100644 --- a/azalea-block/src/generated.rs +++ b/azalea-block/src/generated.rs @@ -1,6 +1,6 @@ //! This code is @generated by codegen/genblocks.py. -use std::fmt::Debug; +use std::{fmt::Debug, str::FromStr}; use azalea_block_macros::make_block_states; diff --git a/azalea-block/src/lib.rs b/azalea-block/src/lib.rs index ad78102c..3c64af25 100644 --- a/azalea-block/src/lib.rs +++ b/azalea-block/src/lib.rs @@ -7,7 +7,7 @@ mod generated; mod range; use core::fmt::Debug; -use std::{any::Any, collections::HashMap}; +use std::{any::Any, collections::HashMap, str::FromStr}; use azalea_registry::builtin::BlockKind; pub use behavior::BlockBehavior; @@ -43,7 +43,16 @@ pub trait BlockTrait: Debug + Any { /// has no property with that name. /// /// To get all properties, you may use [`Self::property_map`]. + /// + /// To set a property, use [`Self::set_property`]. fn get_property(&self, name: &str) -> Option<&'static str>; + /// 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(())`. + /// + /// To get a property, use [`Self::get_property`]. + fn set_property(&mut self, name: &str, new_value: &str) -> Result<(), ()>; } impl dyn BlockTrait { @@ -52,7 +61,7 @@ impl dyn BlockTrait { } } -pub trait Property { +pub trait Property: FromStr { type Value; fn try_from_block_state(state: BlockState) -> Option<Self::Value>; |
