Skip to main content

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