steel_core/behavior/blocks/vegetation/
leaf_litter_block.rs1use super::BlockRef;
2use crate::behavior::BlockBehavior;
3use crate::behavior::BlockPlaceContext;
4use crate::behavior::blocks::vegetation::segmentable_block::{
5 segmentable_can_be_replaced, segmentable_get_state_for_placement,
6};
7use crate::world::{LevelReader, ScheduledTickAccess};
8use steel_macros::block_behavior;
9use steel_registry::blocks::properties::{BlockStateProperties, IntProperty};
10use steel_utils::{BlockPos, BlockStateId, Direction};
11
12use super::vegetation_block::survival_update_shape;
13
14const SEGMENT_PROPERTY: IntProperty = BlockStateProperties::SEGMENT_AMOUNT;
15
16#[block_behavior]
18pub struct LeafLitterBlock {
19 block: BlockRef,
20}
21
22impl LeafLitterBlock {
23 #[must_use]
25 pub const fn new(block: BlockRef) -> Self {
26 Self { block }
27 }
28}
29
30impl BlockBehavior for LeafLitterBlock {
31 fn can_survive(&self, _state: BlockStateId, world: &dyn LevelReader, pos: BlockPos) -> bool {
32 let below_pos = pos.below();
33 world.is_face_sturdy(world.get_block_state(below_pos), below_pos, Direction::Up)
34 }
35
36 fn get_state_for_placement(&self, context: &BlockPlaceContext<'_>) -> Option<BlockStateId> {
37 Some(segmentable_get_state_for_placement(
38 self.block,
39 &SEGMENT_PROPERTY,
40 context,
41 ))
42 }
43
44 fn can_be_replaced(&self, state: BlockStateId, context: &BlockPlaceContext<'_>) -> bool {
45 segmentable_can_be_replaced(&SEGMENT_PROPERTY, state, context)
46 }
47
48 fn update_shape(
49 &self,
50 state: BlockStateId,
51 world: &dyn ScheduledTickAccess,
52 pos: BlockPos,
53 _direction: Direction,
54 _neighbor_pos: BlockPos,
55 _neighbor_state: BlockStateId,
56 ) -> BlockStateId {
57 survival_update_shape(self, state, world, pos)
58 }
59}