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