Interface FarmingBehaviour


public interface FarmingBehaviour
The farming side of a block type: how it grows, what it needs to stand, how it answers to fertilizer, and what it gives when harvested.

Every method has a default doing nothing, so that a behaviour only says what its block does: a plant overrides growth and survival, soil overrides what happens when it is walked on.

Every method runs on the thread of the region owning the block.

Since:
0.1.0
See Also:
  • Method Details

    • ticksRandomly

      default boolean ticksRandomly(BlockData state)
      Returns true if the state may be picked for a random tick.

      A state that has nothing left to do, such as a ripe crop, answers false so that the engine does not call randomTick(FarmingWorld, BlockPosition, BlockData) for nothing.

      Parameters:
      state - the state of the block
      Returns:
      true if the state may be picked for a random tick
      Since:
      0.1.0
    • randomTick

      default void randomTick(FarmingWorld world, BlockPosition position, BlockData state)
      Called when the block is picked for a random tick: a few blocks of every chunk section are picked at random on each game tick, as many as the random_tick_speed game rule says. This is where a plant grows and where soil dries out.
      Parameters:
      world - the world of the block
      position - where the block is
      state - the state of the block
      Since:
      0.1.0
    • tick

      default void tick(FarmingWorld world, BlockPosition position, BlockData state)
      Called when a tick scheduled for the block is due.
      Parameters:
      world - the world of the block
      position - where the block is
      state - the state of the block
      Since:
      0.1.0
    • canSurvive

      default boolean canSurvive(FarmingWorld world, BlockPosition position, BlockData state)
      Tells whether the block can stand where it is: a crop on its soil, a cane next to water.

      It is asked before a player plants the block, in which case the block is not in the world yet, and every time one of its six neighbours changes. A block that cannot stand any more is destroyed, and drops its harvest.

      Parameters:
      world - the world of the block
      position - where the block is, or would be
      state - the state of the block
      Returns:
      true to stay, or to be planted
      Since:
      0.1.0
    • updateShape

      default BlockData updateShape(FarmingWorld world, BlockPosition position, BlockData state, BlockFace direction, BlockData neighbor)
      Called when the block next to this one on one side changed, once it is known that this one can still stand, to let it follow: a stem whose fruit was picked lets go of it, soil covered by a solid block turns back to dirt.
      Parameters:
      world - the world of the block
      position - where the block is
      state - the state of the block
      direction - the side of this block the changed neighbour is on
      neighbor - the new state of that neighbour
      Returns:
      the state the block should take: state to keep it
      Since:
      0.1.0
    • canFertilize

      default boolean canFertilize(FarmingWorld world, BlockPosition position, BlockData state)
      Returns true if a fertilizer can be used on the block as it is.

      When it can, the fertilizer is used up, whether or not fertilize(FarmingWorld, BlockPosition, BlockData) then changes anything.

      Parameters:
      world - the world of the block
      position - where the block is
      state - the state of the block
      Returns:
      true if a fertilizer can be used on the block as it is
      Since:
      0.1.0
    • fertilize

      default void fertilize(FarmingWorld world, BlockPosition position, BlockData state)
      Applies a fertilizer to the block: a crop gains a few growth stages at once.

      Only called when canFertilize(FarmingWorld, BlockPosition, BlockData) agreed.

      Parameters:
      world - the world of the block
      position - where the block is
      state - the state of the block
      Since:
      0.1.0
    • drops

      default List<ItemStack> drops(FarmingWorld world, BlockPosition position, BlockData state, ItemStack tool)
      Works out what the block gives when it is broken: by a player who is not in creative mode, or because it could no longer stand.
      Parameters:
      world - the world of the block
      position - where the block is
      state - the state being broken
      tool - what the block is broken with, ItemStack.EMPTY for a bare hand or when nobody breaks it
      Returns:
      the stacks to drop, empty for nothing
      Since:
      0.1.0
    • entityLanded

      default void entityLanded(FarmingWorld world, BlockPosition position, BlockData state, Entity entity, double fallDistance)
      Called when an entity lands on top of the block after a fall: where soil gets trampled.
      Parameters:
      world - the world of the block
      position - where the block is
      state - the state of the block
      entity - the entity that landed
      fallDistance - how far it fell, in blocks
      Since:
      0.1.0