Skip to main content

steel_core/behavior/blocks/vegetation/
dry_vegetation_block.rs

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