aboutsummaryrefslogtreecommitdiff
path: root/azalea-block/src/lib.rs
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2026-01-03 13:57:10 -1030
committermat <git@matdoes.dev>2026-01-04 05:28:22 +0500
commita4a63ead6e00a645899bf87deea4ec94a66703f3 (patch)
tree5c202045614ba045a311fca80964fc17d5279a01 /azalea-block/src/lib.rs
parentf0a14ca83f6eb8946d6add25210194cf95df3110 (diff)
downloadazalea-drasl-a4a63ead6e00a645899bf87deea4ec94a66703f3.tar.xz
add BlockTrait::set_property
closes #140
Diffstat (limited to 'azalea-block/src/lib.rs')
-rw-r--r--azalea-block/src/lib.rs13
1 files changed, 11 insertions, 2 deletions
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>;