Interface FarmingWorld

All Superinterfaces:
BlockGetter

public interface FarmingWorld extends BlockGetter
A world as the farming engine drives it: what plants look at to grow, the changes they make, and what the server reports to the engine.

Reads only look at loaded chunks, and are allowed from any thread. Writes happen on the thread of the region owning the block: a write aimed at a block of another region, or of a chunk that is not loaded, does nothing and returns false, so that a plant growing sideways simply tries again later.

Since:
0.1.0
See Also:
  • Method Details

    • world

      World world()
      Returns the world these plants grow in.
      Returns:
      the world these plants grow in
      Since:
      0.1.0
    • random

      RandomGenerator random()
      Returns the source of randomness of the calling thread, for growth chances.
      Returns:
      the source of randomness of the calling thread, for growth chances
      Since:
      0.1.0
    • isTagged

      boolean isTagged(BlockPosition position, TagKey<BlockType> tag)
      Returns true if the block at a position belongs to a tag, false when it does not or is not loaded.

      Soils are tags, such as minecraft:supports_crops: a data pack or a plugin adding a block to the tag makes it a soil.

      Parameters:
      position - the block
      tag - the tag
      Returns:
      true if the block at a position belongs to a tag, false when it does not or is not loaded
      Since:
      0.1.0
    • lightLevel

      int lightLevel(BlockPosition position)
      Gets the light a plant at a position gets: the brighter of the light blocks give and the light the sky gives at this time of day and in this weather.

      While the light of a chunk is still being worked out, right after it was loaded, its blocks are taken to stand in full light and under the open sky: a plant is not uprooted for a darkness that is not there.

      Parameters:
      position - the block
      Returns:
      the light, from 0 to 15
      Since:
      0.1.0
    • canSeeSky

      boolean canSeeSky(BlockPosition position)
      Returns true if nothing stands between a position and the sky.
      Parameters:
      position - the block
      Returns:
      true if nothing stands between a position and the sky
      Since:
      0.1.0
    • isRainingAt

      boolean isRainingAt(BlockPosition position)
      Returns true if rain is falling on a position.
      Parameters:
      position - the block
      Returns:
      true if rain is falling on a position
      Since:
      0.1.0
    • hasWater

      boolean hasWater(BlockPosition position)
      Returns true if the block at a position is water, or holds water.
      Parameters:
      position - the block
      Returns:
      true if the block at a position is water, or holds water
      Since:
      0.1.0
    • growthSpeed

      float growthSpeed(BlockPosition position)
      Gets how well a field feeds the plant at a position: the soil right under it counts most, the soil around it adds to it, wet soil counts more than dry soil, and a plant crowded by its own kind on several sides grows half as fast as one planted in rows.

      Soil is a block of the minecraft:grows_crops tag. The built-in crops grow on a random tick with one chance in floor(25 / speed) + 1.

      Parameters:
      position - where the plant is
      Returns:
      the speed, 1 for a lone plant on dry soil, more on a well kept field
      Since:
      0.1.0
    • canSurvive

      boolean canSurvive(BlockPosition position, BlockData state)
      Returns true if a state could stand at a position.: what its FarmingBehaviour.canSurvive(FarmingWorld, BlockPosition, BlockData) answers, true for a block type without a farming behaviour
      Parameters:
      position - where the block would be
      state - the state
      Returns:
      true if a state could stand at a position
      Since:
      0.1.0
    • setBlock

      boolean setBlock(BlockPosition position, BlockData state)
      Replaces a block. Players see the change, light and redstone follow, and the plants around are told.
      Parameters:
      position - where the block is
      state - the new state
      Returns:
      false if the block already held that state, its chunk is not loaded, or the calling thread does not own it
      Since:
      0.1.0
    • grow

      boolean grow(BlockPosition plant, BlockPosition target, BlockData grown, boolean fertilized)
      Makes a plant grow: fires a PlantGrowEvent, then writes what the listeners left of the grown state.
      Parameters:
      plant - where the plant growing is
      target - where the grown state goes: plant for a crop ripening, another position for a cane growing taller or a stem bearing a fruit
      grown - the state to write at target
      fertilized - true if a fertilizer causes the growth
      Returns:
      false if a listener cancelled the growth, or the block could not be written
      Since:
      0.1.0
    • grow

      default boolean grow(BlockPosition plant, BlockData grown)
      Makes a plant grow in place, on its own.
      Parameters:
      plant - where the plant is
      grown - the state it takes
      Returns:
      false if a listener cancelled the growth, or the block could not be written
      Since:
      0.1.0
      See Also:
    • destroy

      boolean destroy(BlockPosition position)
      Breaks a block that can no longer stand: it drops its harvest, players see and hear it break, and it leaves air behind, or its water when it held some.
      Parameters:
      position - where the block is
      Returns:
      false if there was nothing to break, its chunk is not loaded, or the calling thread does not own it
      Since:
      0.1.0
    • harvest

      boolean harvest(BlockPosition position, @Nullable Player player, ItemStack tool)
      Drops what a block gives: fires a HarvestEvent with the drops of its behaviour, then drops what the listeners left of them. The block itself is left as it is.

      The server calls it when a player who is not in creative mode breaks a block, right before the block is removed.

      Parameters:
      position - where the block is
      player - the player breaking the block, null when nobody does
      tool - what the block is broken with, ItemStack.EMPTY for none
      Returns:
      true if at least one stack was dropped
      Since:
      0.1.0
    • dropItem

      void dropItem(BlockPosition position, ItemStack stack)
      Drops a stack from the middle of a block, as a harvest falls.
      Parameters:
      position - the block to drop from
      stack - the stack, nothing is dropped when it is empty
      Since:
      0.1.0
    • scheduleTick

      void scheduleTick(BlockPosition position, int delay)
      Schedules a call to FarmingBehaviour.tick(FarmingWorld, BlockPosition, BlockData), once delay game ticks have elapsed. The tick only runs if the block is still of the same type by then, and is lost if the server stops before.
      Parameters:
      position - the block to tick
      delay - the number of game ticks to wait, 1 for the next tick
      Since:
      0.1.0
    • blockChanged

      void blockChanged(BlockPosition position, BlockData previous, BlockData current)
      Tells the engine a block was replaced, so that the plants and the soil around it react: those that can no longer stand break, the others follow the change.

      The server calls it for every block that changes, whatever changed it; a plugin only needs it when it writes blocks by means the server does not see.

      Parameters:
      position - where the block is
      previous - the state that was replaced
      current - the state now in place
      Since:
      0.1.0
    • useItem

      boolean useItem(Player player, int slot, BlockPosition position, BlockFace face)
      Uses the item a player holds on a block, when the item is one the FarmingRegistry knows: a hoe tills, a fertilizer feeds a plant. The item is worn or used up in the inventory of the player, unless they are in creative mode.

      The server calls it when a player uses an item on a block, before trying to place a block out of the item.

      Parameters:
      player - the player
      slot - the slot of the inventory of the player holding the item
      position - the block the item is used on
      face - the face of that block the player clicked
      Returns:
      true if the item did something, and nothing else should be done with it
      Since:
      0.1.0
    • entityLanded

      void entityLanded(Entity entity, BlockPosition position, double fallDistance)
      Tells the engine an entity landed on a block after a fall, so that the behaviour of the block reacts.
      Parameters:
      entity - the entity that landed
      position - the block it landed on
      fallDistance - how far it fell, in blocks
      Since:
      0.1.0