Interface FarmingBehaviour
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 Summary
Modifier and TypeMethodDescriptiondefault booleancanFertilize(FarmingWorld world, BlockPosition position, BlockData state) Returnstrueif a fertilizer can be used on the block as it is.default booleancanSurvive(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.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.default voidentityLanded(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.default voidfertilize(FarmingWorld world, BlockPosition position, BlockData state) Applies a fertilizer to the block: a crop gains a few growth stages at once.default voidrandomTick(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 therandom_tick_speedgame rule says.default voidtick(FarmingWorld world, BlockPosition position, BlockData state) Called when a tick scheduled for the block is due.default booleanticksRandomly(BlockData state) Returnstrueif the state may be picked for a random tick.default BlockDataupdateShape(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.
-
Method Details
-
ticksRandomly
Returnstrueif the state may be picked for a random tick.A state that has nothing left to do, such as a ripe crop, answers
falseso that the engine does not callrandomTick(FarmingWorld, BlockPosition, BlockData)for nothing.- Parameters:
state- the state of the block- Returns:
trueif the state may be picked for a random tick- Since:
- 0.1.0
-
randomTick
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 therandom_tick_speedgame rule says. This is where a plant grows and where soil dries out.- Parameters:
world- the world of the blockposition- where the block isstate- the state of the block- Since:
- 0.1.0
-
tick
Called when a tick scheduled for the block is due.- Parameters:
world- the world of the blockposition- where the block isstate- the state of the block- Since:
- 0.1.0
-
canSurvive
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 blockposition- where the block is, or would bestate- the state of the block- Returns:
trueto 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 blockposition- where the block isstate- the state of the blockdirection- the side of this block the changed neighbour is onneighbor- the new state of that neighbour- Returns:
- the state the block should take:
stateto keep it - Since:
- 0.1.0
-
canFertilize
Returnstrueif 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 blockposition- where the block isstate- the state of the block- Returns:
trueif a fertilizer can be used on the block as it is- Since:
- 0.1.0
-
fertilize
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 blockposition- where the block isstate- 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 blockposition- where the block isstate- the state being brokentool- what the block is broken with,ItemStack.EMPTYfor 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 blockposition- where the block isstate- the state of the blockentity- the entity that landedfallDistance- how far it fell, in blocks- Since:
- 0.1.0
-