steel_core/behavior/blocks/vegetation/
beetroots.rs1use 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#[block_behavior]
25pub struct BeetrootBlock {
26 block: BlockRef,
27}
28
29impl BeetrootBlock {
30 #[must_use]
32 pub const fn new(block: BlockRef) -> Self {
33 Self { block }
34 }
35}
36
37impl CropLike for BeetrootBlock {
38 fn block(&self) -> BlockRef {
39 self.block
40 }
41
42 fn age_property(&self) -> &IntProperty {
43 &BlockStateProperties::AGE_3
44 }
45
46 fn max_age(&self) -> u8 {
47 3
48 }
49
50 fn clone_item_stack(&self) -> ItemStack {
51 ItemStack::new(&vanilla_items::BEETROOT_SEEDS)
52 }
53
54 fn should_random_tick(&self) -> bool {
55 rand::random_range(0..3) != 0
56 }
57}
58
59impl Bonemealable for BeetrootBlock {
60 fn get_bonemeal_age_increase(&self, _world: &Arc<World>, rng: &mut dyn rand::Rng) -> u8 {
61 rng.random_range(2..=5) / 3
62 }
63
64 fn is_valid_bonemeal_target(
65 &self,
66 state: BlockStateId,
67 _world: &dyn LevelReader,
68 _pos: steel_utils::BlockPos,
69 ) -> bool {
70 !self.is_max_age(state)
71 }
72
73 fn perform_bonemeal(
74 &self,
75 state: BlockStateId,
76 world: &Arc<World>,
77 rng: &mut dyn rand::Rng,
78 pos: steel_utils::BlockPos,
79 ) {
80 self.default_perform_bonemeal(state, world, rng, pos);
81 }
82}