steel_core/behavior/blocks/vegetation/
spore_blossom_block.rs1use steel_macros::block_behavior;
2use steel_registry::blocks::properties::Direction;
3use steel_registry::blocks::shapes::SupportType;
4use steel_utils::{BlockPos, BlockStateId};
5
6use crate::behavior::block::BlockBehavior;
7use crate::behavior::context::BlockPlaceContext;
8use crate::fluid::get_fluid_state_from_block;
9use crate::world::LevelReader;
10
11use super::{BlockRef, default_surviving_state};
12
13#[block_behavior]
16pub struct SporeBlossomBlock {
17 block: BlockRef,
18}
19
20impl SporeBlossomBlock {
21 #[must_use]
23 pub const fn new(block: BlockRef) -> Self {
24 Self { block }
25 }
26}
27
28impl BlockBehavior for SporeBlossomBlock {
29 fn can_survive(&self, _state: BlockStateId, world: &dyn LevelReader, pos: BlockPos) -> bool {
30 let above_pos = pos.above();
31 world.is_face_sturdy_for(
32 world.get_block_state(above_pos),
33 above_pos,
34 Direction::Down,
35 SupportType::Center,
36 ) && get_fluid_state_from_block(world.get_block_state(pos)).is_empty()
37 }
38
39 fn get_state_for_placement(&self, context: &BlockPlaceContext<'_>) -> Option<BlockStateId> {
40 default_surviving_state(self.block, self, context)
41 }
42}