Skip to main content

steel_core/behavior/blocks/building/
mud.rs

1use steel_macros::block_behavior;
2use steel_registry::blocks::BlockRef;
3use steel_utils::BlockStateId;
4
5use crate::{
6    behavior::{BlockBehavior, BlockPlaceContext},
7    entity::ai::path::PathComputationType,
8};
9
10/// Behavior for mud blocks.
11#[block_behavior]
12pub struct MudBlock {
13    block: BlockRef,
14}
15
16impl MudBlock {
17    /// Creates a new mud block behavior.
18    #[must_use]
19    pub const fn new(block: BlockRef) -> Self {
20        Self { block }
21    }
22}
23
24impl BlockBehavior for MudBlock {
25    fn get_state_for_placement(&self, _context: &BlockPlaceContext<'_>) -> Option<BlockStateId> {
26        Some(self.block.default_state())
27    }
28
29    fn is_pathfindable(
30        &self,
31        _state: BlockStateId,
32        _computation_type: PathComputationType,
33    ) -> bool {
34        false
35    }
36}
37
38#[cfg(test)]
39mod tests {
40    use steel_registry::init_vanilla_registry;
41    use steel_registry::vanilla_blocks;
42
43    use crate::behavior::block::BlockBehavior;
44    use crate::entity::ai::path::PathComputationType;
45
46    use super::MudBlock;
47
48    #[test]
49    fn is_pathfindable_returns_false_for_all_types() {
50        init_vanilla_registry();
51        let block = MudBlock::new(&vanilla_blocks::MUD);
52        let state = vanilla_blocks::MUD.default_state();
53
54        assert!(!block.is_pathfindable(state, PathComputationType::Land));
55        assert!(!block.is_pathfindable(state, PathComputationType::Water));
56        assert!(!block.is_pathfindable(state, PathComputationType::Air));
57    }
58}