steel_core/behavior/blocks/vegetation/
sapling_block.rs1use steel_macros::block_behavior;
2use steel_registry::vanilla_block_tags::BlockTag;
3use steel_utils::{BlockPos, BlockStateId};
4
5use crate::behavior::block::BlockBehavior;
6use crate::behavior::context::BlockPlaceContext;
7use crate::world::LevelReader;
8
9use super::{BlockRef, default_surviving_state, survives_on_tag};
10
11#[block_behavior]
14pub struct SaplingBlock {
15 block: BlockRef,
16}
17
18impl SaplingBlock {
19 #[must_use]
21 pub const fn new(block: BlockRef) -> Self {
22 Self { block }
23 }
24}
25
26impl BlockBehavior for SaplingBlock {
27 fn can_survive(&self, _state: BlockStateId, world: &dyn LevelReader, pos: BlockPos) -> bool {
28 survives_on_tag(world, pos, &BlockTag::SUPPORTS_VEGETATION)
29 }
30
31 fn get_state_for_placement(&self, context: &BlockPlaceContext<'_>) -> Option<BlockStateId> {
32 default_surviving_state(self.block, self, context)
33 }
34}