steel_core/behavior/blocks/vegetation/
tall_flower_block.rs1use std::sync::Arc;
2
3use steel_macros::block_behavior;
4use steel_registry::blocks::properties::Direction;
5use steel_registry::item_stack::ItemStack;
6use steel_registry::{REGISTRY, RegistryExt};
7use steel_utils::{BlockPos, BlockStateId};
8
9use crate::behavior::block::BlockBehavior;
10use crate::behavior::blocks::vegetation::bonemealable::Bonemealable;
11use crate::behavior::context::{BlockPlaceContext, PlacementSource};
12use crate::world::{LevelReader, ScheduledTickAccess, World};
13
14use super::{BlockRef, DoublePlantBlock};
15
16#[block_behavior]
18pub struct TallFlowerBlock {
19 base: DoublePlantBlock,
20}
21
22impl TallFlowerBlock {
23 #[must_use]
25 pub const fn new(block: BlockRef) -> Self {
26 Self {
27 base: DoublePlantBlock::new(block),
28 }
29 }
30}
31
32impl BlockBehavior for TallFlowerBlock {
33 fn update_shape(
34 &self,
35 state: BlockStateId,
36 world: &dyn ScheduledTickAccess,
37 pos: BlockPos,
38 direction: Direction,
39 neighbor_pos: BlockPos,
40 neighbor_state: BlockStateId,
41 ) -> BlockStateId {
42 self.base
43 .update_shape(state, world, pos, direction, neighbor_pos, neighbor_state)
44 }
45
46 fn can_survive(&self, state: BlockStateId, world: &dyn LevelReader, pos: BlockPos) -> bool {
47 self.base.can_survive(state, world, pos)
48 }
49
50 fn set_placed_by(
51 &self,
52 state: BlockStateId,
53 world: &Arc<World>,
54 pos: BlockPos,
55 source: &PlacementSource<'_>,
56 ) {
57 self.base.set_placed_by(state, world, pos, source);
58 }
59
60 fn get_state_for_placement(&self, context: &BlockPlaceContext<'_>) -> Option<BlockStateId> {
61 self.base.get_state_for_placement(context)
62 }
63
64 fn as_bonemealable(&self) -> Option<&dyn Bonemealable> {
65 Some(self)
66 }
67}
68
69impl Bonemealable for TallFlowerBlock {
70 fn is_valid_bonemeal_target(
71 &self,
72 _state: BlockStateId,
73 _world: &dyn LevelReader,
74 _pos: BlockPos,
75 ) -> bool {
76 true
77 }
78
79 fn perform_bonemeal(
80 &self,
81 _state: BlockStateId,
82 world: &Arc<World>,
83 _rng: &mut dyn rand::Rng,
84 pos: BlockPos,
85 ) {
86 if let Some(item) = REGISTRY.items.by_key(&self.base.block.key) {
87 world.pop_resource(pos, ItemStack::new(item));
88 }
89 }
90}