mindustry logic execution, map- and schematic- parsing and rendering
Diffstat (limited to 'src/block/fluid.rs')
| -rw-r--r-- | src/block/fluid.rs | 33 |
1 files changed, 8 insertions, 25 deletions
diff --git a/src/block/fluid.rs b/src/block/fluid.rs index 55b0097..90289bc 100644 --- a/src/block/fluid.rs +++ b/src/block/fluid.rs @@ -2,9 +2,11 @@ use std::any::Any; use std::error::Error; use std::fmt; -use crate::block::{BlockLogic, DataConvertError, DeserializeError, make_register, SerializeError}; -use crate::block::simple::{BuildCost, cost, SimpleBlock, state_impl}; +use crate::block::simple::{cost, state_impl, BuildCost, SimpleBlock}; use crate::block::transport::BridgeBlock; +use crate::block::{ + impl_block, make_register, BlockLogic, DataConvertError, DeserializeError, SerializeError, +}; use crate::content; use crate::data::dynamic::{DynData, DynType}; use crate::data::GridPos; @@ -37,10 +39,9 @@ pub struct FluidBlock { } impl FluidBlock { + #[must_use] pub const fn new(size: u8, symmetric: bool, build_cost: BuildCost) -> Self { - if size == 0 { - panic!("invalid size"); - } + assert!(size != 0, "invalid size"); Self { size, symmetric, @@ -52,28 +53,10 @@ impl FluidBlock { } impl BlockLogic for FluidBlock { - fn get_size(&self) -> u8 { - self.size - } - - fn is_symmetric(&self) -> bool { - self.symmetric - } - - fn create_build_cost(&self) -> Option<Storage> { - if !self.build_cost.is_empty() { - let mut storage = Storage::new(); - for (ty, cnt) in self.build_cost { - storage.add(*ty, *cnt, u32::MAX); - } - Some(storage) - } else { - None - } - } + impl_block!(); fn data_from_i32(&self, config: i32, _: GridPos) -> Result<DynData, DataConvertError> { - if config < 0 || config > u16::MAX as i32 { + if config < 0 || config > i32::from(u16::MAX) { return Err(DataConvertError::Custom(Box::new(FluidConvertError( config, )))); |