Skip to main content

steel_core/behavior/blocks/vegetation/
flower_block.rs

1use steel_macros::block_behavior;
2use steel_registry::blocks::BlockRef;
3use steel_utils::{BlockPos, BlockStateId, Direction};
4
5use crate::{
6    behavior::{
7        BlockBehavior, BlockPlaceContext,
8        blocks::vegetation::{
9            Vegetation, default_surviving_state,
10            vegetation_block::{survival_update_shape, vegetation_can_survive},
11        },
12    },
13    world::{LevelReader, ScheduledTickAccess},
14};
15
16/// Behavior for most flower blocks.
17#[block_behavior]
18pub struct FlowerBlock {
19    block: BlockRef,
20}
21
22impl FlowerBlock {
23    /// Creates a new flower behavior.
24    #[must_use]
25    pub const fn new(block: BlockRef) -> Self {
26        Self { block }
27    }
28}
29
30impl BlockBehavior for FlowerBlock {
31    fn update_shape(
32        &self,
33        state: BlockStateId,
34        world: &dyn ScheduledTickAccess,
35        pos: BlockPos,
36        _direction: Direction,
37        _neighbor_pos: BlockPos,
38        _neighbor_state: BlockStateId,
39    ) -> BlockStateId {
40        survival_update_shape(self, state, world, pos)
41    }
42
43    fn can_survive(&self, state: BlockStateId, world: &dyn LevelReader, pos: BlockPos) -> bool {
44        vegetation_can_survive(self, state, world, pos)
45    }
46
47    fn get_state_for_placement(&self, context: &BlockPlaceContext<'_>) -> Option<BlockStateId> {
48        default_surviving_state(self.block, self, context)
49    }
50}
51
52impl Vegetation for FlowerBlock {}