Skip to main content

CropLike

Trait CropLike 

Source
pub trait CropLike {
    // Required methods
    fn block(&self) -> BlockRef;
    fn age_property(&self) -> &IntProperty;
    fn max_age(&self) -> u8;
    fn clone_item_stack(&self) -> ItemStack;

    // Provided methods
    fn should_random_tick(&self) -> bool { ... }
    fn get_age(&self, state: BlockStateId) -> u8 { ... }
    fn get_state_for_age(&self, age: u8) -> BlockStateId { ... }
    fn is_max_age(&self, state: BlockStateId) -> bool { ... }
    fn has_sufficient_light(
        &self,
        world: &dyn LevelReader,
        pos: BlockPos,
    ) -> bool { ... }
    fn has_sufficient_growth_light(
        &self,
        world: &dyn LevelReader,
        pos: BlockPos,
    ) -> bool { ... }
    fn get_growth_speed(&self, world: &Arc<World>, pos: BlockPos) -> f32 { ... }
    fn on_random_tick(
        &self,
        state: BlockStateId,
        world: &Arc<World>,
        pos: BlockPos,
    ) { ... }
}

Required Methods§

Source

fn block(&self) -> BlockRef

Source

fn age_property(&self) -> &IntProperty

Source

fn max_age(&self) -> u8

Source

fn clone_item_stack(&self) -> ItemStack

Provided Methods§

Source

fn should_random_tick(&self) -> bool

Additional checks before calling the standard on_random_tick code

Source

fn get_age(&self, state: BlockStateId) -> u8

Source

fn get_state_for_age(&self, age: u8) -> BlockStateId

Source

fn is_max_age(&self, state: BlockStateId) -> bool

Source

fn has_sufficient_light(&self, world: &dyn LevelReader, pos: BlockPos) -> bool

Source

fn has_sufficient_growth_light( &self, world: &dyn LevelReader, pos: BlockPos, ) -> bool

Source

fn get_growth_speed(&self, world: &Arc<World>, pos: BlockPos) -> f32

Calculates the growth speed based on surrounding farmland.

Factors affecting growth speed:

  • Farmland below: +1.0 (dry) or +3.0 (hydrated)
  • Adjacent farmland: +0.25 (dry) or +0.75 (hydrated)
  • Same crop in row: /2.0 speed penalty
Source

fn on_random_tick(&self, state: BlockStateId, world: &Arc<World>, pos: BlockPos)

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§