Skip to main content

steel_core/behavior/blocks/vegetation/
beetroots.rs

1use std::sync::Arc;
2
3use rand::RngExt;
4use steel_macros::block_behavior;
5use steel_registry::{
6    blocks::{
7        BlockRef,
8        properties::{BlockStateProperties, IntProperty},
9    },
10    item_stack::ItemStack,
11    vanilla_items,
12};
13use steel_utils::BlockStateId;
14
15use crate::{
16    behavior::blocks::vegetation::{
17        bonemealable::{Bonemealable, CropBonemealExt},
18        crop_block::CropLike,
19    },
20    world::{LevelReader, World},
21};
22
23/// Behavior for the Beetroots Block
24#[block_behavior]
25pub struct BeetrootBlock {
26    block: BlockRef,
27}
28
29const AGE: &IntProperty = &BlockStateProperties::AGE_3;
30
31impl BeetrootBlock {
32    /// Creates a new crop block behavior with a custom age property.
33    #[must_use]
34    pub const fn new(block: BlockRef) -> Self {
35        Self { block }
36    }
37}
38
39impl CropLike for BeetrootBlock {
40    fn block(&self) -> BlockRef {
41        self.block
42    }
43
44    fn age_property(&self) -> &IntProperty {
45        AGE
46    }
47
48    fn max_age(&self) -> u8 {
49        AGE.max
50    }
51
52    fn clone_item_stack(&self) -> ItemStack {
53        ItemStack::new(&vanilla_items::BEETROOT_SEEDS)
54    }
55
56    fn should_random_tick(&self) -> bool {
57        rand::random_range(0..3) != 0
58    }
59}
60
61impl Bonemealable for BeetrootBlock {
62    fn get_bonemeal_age_increase(&self, _world: &Arc<World>, rng: &mut dyn rand::Rng) -> u8 {
63        rng.random_range(2..=5) / 3
64    }
65
66    fn is_valid_bonemeal_target(
67        &self,
68        state: BlockStateId,
69        _world: &dyn LevelReader,
70        _pos: steel_utils::BlockPos,
71    ) -> bool {
72        !self.is_max_age(state)
73    }
74
75    fn perform_bonemeal(
76        &self,
77        state: BlockStateId,
78        world: &Arc<World>,
79        rng: &mut dyn rand::Rng,
80        pos: steel_utils::BlockPos,
81    ) {
82        self.default_perform_bonemeal(state, world, rng, pos);
83    }
84}