steel_core/behavior/blocks/vegetation/
lily_pad_block.rs1use steel_macros::block_behavior;
2use steel_registry::blocks::block_state_ext::BlockStateExt;
3use steel_registry::vanilla_block_tags::BlockTag;
4use steel_utils::{BlockPos, BlockStateId};
5
6use crate::behavior::block::BlockBehavior;
7use crate::behavior::context::BlockPlaceContext;
8use crate::fluid::{FluidStateExt, get_fluid_state_from_block};
9use crate::world::LevelReader;
10
11use super::{BlockRef, default_surviving_state};
12
13#[block_behavior]
16pub struct LilyPadBlock {
17 block: BlockRef,
18}
19
20impl LilyPadBlock {
21 #[must_use]
23 pub const fn new(block: BlockRef) -> Self {
24 Self { block }
25 }
26}
27
28impl BlockBehavior for LilyPadBlock {
29 fn can_survive(&self, _state: BlockStateId, world: &dyn LevelReader, pos: BlockPos) -> bool {
30 let below_pos = pos.below();
31 let below = world.get_block_state(below_pos);
32 let below_fluid = get_fluid_state_from_block(below);
33 let above_fluid = get_fluid_state_from_block(world.get_block_state(pos));
34
35 (below_fluid.is_water() || below.get_block().has_tag(&BlockTag::SUPPORTS_LILY_PAD))
36 && above_fluid.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}