steel_core/behavior/blocks/building/
soul_sand_block.rs1use steel_macros::block_behavior;
2use steel_registry::blocks::BlockRef;
3use steel_registry::entity_type::EntityTypeRef;
4use steel_utils::{BlockPos, BlockStateId};
5
6use crate::{
7 behavior::{BlockBehavior, BlockPlaceContext},
8 entity::ai::path::PathComputationType,
9 world::LevelReader,
10};
11
12#[block_behavior]
14pub struct SoulSandBlock {
15 block: BlockRef,
16}
17
18impl SoulSandBlock {
19 #[must_use]
21 pub const fn new(block: BlockRef) -> Self {
22 Self { block }
23 }
24}
25
26impl BlockBehavior for SoulSandBlock {
27 fn get_state_for_placement(&self, _context: &BlockPlaceContext<'_>) -> Option<BlockStateId> {
28 Some(self.block.default_state())
29 }
30
31 fn is_valid_spawn(
32 &self,
33 _state: BlockStateId,
34 _world: &dyn LevelReader,
35 _pos: BlockPos,
36 _entity_type: EntityTypeRef,
37 ) -> bool {
38 true
39 }
40
41 fn is_pathfindable(
42 &self,
43 _state: BlockStateId,
44 _computation_type: PathComputationType,
45 ) -> bool {
46 false
47 }
48}
49
50#[cfg(test)]
51mod tests {
52 use steel_registry::init_vanilla_registry;
53 use steel_registry::vanilla_blocks;
54
55 use crate::behavior::block::BlockBehavior;
56 use crate::entity::ai::path::PathComputationType;
57
58 use super::SoulSandBlock;
59
60 #[test]
61 fn is_pathfindable_returns_false_for_all_types() {
62 init_vanilla_registry();
63 let block = SoulSandBlock::new(&vanilla_blocks::SOUL_SAND);
64 let state = vanilla_blocks::SOUL_SAND.default_state();
65
66 assert!(!block.is_pathfindable(state, PathComputationType::Land));
67 assert!(!block.is_pathfindable(state, PathComputationType::Water));
68 assert!(!block.is_pathfindable(state, PathComputationType::Air));
69 }
70}