steel_core/behavior/blocks/vegetation/
nether_sprouts.rs1use steel_macros::block_behavior;
2use steel_registry::{
3 blocks::{BlockRef, block_state_ext::BlockStateExt},
4 vanilla_block_tags::BlockTag,
5};
6use steel_utils::{BlockPos, BlockStateId};
7
8use crate::{
9 behavior::{
10 BlockBehavior, BlockPlaceContext,
11 blocks::vegetation::{
12 Vegetation,
13 vegetation_block::{survival_update_shape, vegetation_can_survive},
14 },
15 },
16 world::{LevelReader, ScheduledTickAccess},
17};
18
19#[block_behavior]
21pub struct NetherSproutsBlock {
22 block: BlockRef,
23}
24
25impl NetherSproutsBlock {
26 #[must_use]
28 pub const fn new(block: BlockRef) -> Self {
29 Self { block }
30 }
31}
32
33impl BlockBehavior for NetherSproutsBlock {
34 fn get_state_for_placement(&self, context: &BlockPlaceContext<'_>) -> Option<BlockStateId> {
35 if self.may_place_on(
36 context.world.get_block_state(context.place_pos().below()),
37 context.world,
38 context.place_pos().below(),
39 ) {
40 Some(self.block.default_state())
41 } else {
42 None
43 }
44 }
45
46 fn update_shape(
47 &self,
48 state: BlockStateId,
49 world: &dyn ScheduledTickAccess,
50 pos: BlockPos,
51 _direction: steel_utils::Direction,
52 _neighbor_pos: BlockPos,
53 _neighbor_state: BlockStateId,
54 ) -> BlockStateId {
55 survival_update_shape(self, state, world, pos)
56 }
57
58 fn can_survive(&self, state: BlockStateId, world: &dyn LevelReader, pos: BlockPos) -> bool {
59 vegetation_can_survive(self, state, world, pos)
60 }
61}
62
63impl Vegetation for NetherSproutsBlock {
64 fn may_place_on(&self, state: BlockStateId, _world: &dyn LevelReader, _pos: BlockPos) -> bool {
65 state
66 .get_block()
67 .has_tag(&BlockTag::SUPPORTS_NETHER_SPROUTS)
68 }
69}