mindustry logic execution, map- and schematic- parsing and rendering
Diffstat (limited to 'src/block/mod.rs')
| -rw-r--r-- | src/block/mod.rs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/block/mod.rs b/src/block/mod.rs index 69ff37c..9bed114 100644 --- a/src/block/mod.rs +++ b/src/block/mod.rs @@ -8,6 +8,7 @@ use crate::data::GridPos; use crate::data::dynamic::{DynData, DynType}; use crate::item::storage::Storage as ItemStorage; use crate::registry::RegistryEntry; +use crate::utils::OnceCell; pub mod base; pub mod content; @@ -157,13 +158,14 @@ pub struct Block { name: Cow<'static, str>, logic: BoxAccess<'static, dyn BlockLogic + Sync>, + build_cost: OnceCell<Option<ItemStorage>>, } impl Block { pub const fn new(name: Cow<'static, str>, logic: BoxAccess<'static, dyn BlockLogic + Sync>) -> Self { - Self{name, logic} + Self{name, logic, build_cost: OnceCell::new()} } pub fn get_size(&self) -> u8 @@ -176,6 +178,11 @@ impl Block self.logic.is_symmetric() } + pub fn get_build_cost(&self) -> Option<&ItemStorage> + { + self.build_cost.get_or_init(|| self.logic.as_ref().create_build_cost()).as_ref() + } + pub fn data_from_i32(&self, config: i32, pos: GridPos) -> Result<DynData, DataConvertError> { self.logic.data_from_i32(config, pos) |