Skip to main content

steel_core/behavior/blocks/vegetation/
growing_plant_block.rs

1use steel_registry::blocks::{BlockRef, block_state_ext::BlockStateExt};
2use steel_utils::{BlockPos, Direction};
3
4use crate::world::LevelReader;
5
6/// Vanilla `GrowingPlantBlock.canSurvive`.
7///
8/// The block opposite the growth direction must be the head, the body, or
9/// face-sturdy on the face pointing toward us (i.e. `growth_direction`).
10pub(crate) fn can_survive(
11    world: &dyn LevelReader,
12    pos: BlockPos,
13    growth_direction: Direction,
14    head: BlockRef,
15    body: BlockRef,
16) -> bool {
17    let attached_pos = pos.relative(growth_direction.opposite());
18    let attached_state = world.get_block_state(attached_pos);
19    let attached_block = attached_state.get_block();
20    attached_block == head
21        || attached_block == body
22        || world.is_face_sturdy(attached_state, attached_pos, growth_direction)
23}