Interface FarmingWorld
- All Superinterfaces:
BlockGetter
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 Summary
Modifier and TypeMethodDescriptionvoidblockChanged(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.booleancanSeeSky(BlockPosition position) Returnstrueif nothing stands between a position and the sky.booleancanSurvive(BlockPosition position, BlockData state) Returnstrueif a state could stand at a position.booleandestroy(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.voiddropItem(BlockPosition position, ItemStack stack) Drops a stack from the middle of a block, as a harvest falls.voidentityLanded(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.booleangrow(BlockPosition plant, BlockPosition target, BlockData grown, boolean fertilized) Makes a plant grow: fires aPlantGrowEvent, then writes what the listeners left of the grown state.default booleangrow(BlockPosition plant, BlockData grown) Makes a plant grow in place, on its own.floatgrowthSpeed(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.booleanharvest(BlockPosition position, @Nullable Player player, ItemStack tool) Drops what a block gives: fires aHarvestEventwith the drops of its behaviour, then drops what the listeners left of them.booleanhasWater(BlockPosition position) Returnstrueif the block at a position is water, or holds water.booleanisRainingAt(BlockPosition position) Returnstrueif rain is falling on a position.booleanisTagged(BlockPosition position, TagKey<BlockType> tag) Returnstrueif the block at a position belongs to a tag,falsewhen it does not or is not loaded.intlightLevel(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.random()Returns the source of randomness of the calling thread, for growth chances.voidscheduleTick(BlockPosition position, int delay) Schedules a call toFarmingBehaviour.tick(FarmingWorld, BlockPosition, BlockData), oncedelaygame ticks have elapsed.booleansetBlock(BlockPosition position, BlockData state) Replaces a block.booleanuseItem(Player player, int slot, BlockPosition position, BlockFace face) Uses the item a player holds on a block, when the item is one theFarmingRegistryknows: a hoe tills, a fertilizer feeds a plant.world()Returns the world these plants grow in.Methods inherited from interface BlockGetter
blockAt
-
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
Returnstrueif the block at a position belongs to a tag,falsewhen 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 blocktag- the tag- Returns:
trueif the block at a position belongs to a tag,falsewhen it does not or is not loaded- Since:
- 0.1.0
-
lightLevel
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
0to15 - Since:
- 0.1.0
-
canSeeSky
Returnstrueif nothing stands between a position and the sky.- Parameters:
position- the block- Returns:
trueif nothing stands between a position and the sky- Since:
- 0.1.0
-
isRainingAt
Returnstrueif rain is falling on a position.- Parameters:
position- the block- Returns:
trueif rain is falling on a position- Since:
- 0.1.0
-
hasWater
Returnstrueif the block at a position is water, or holds water.- Parameters:
position- the block- Returns:
trueif the block at a position is water, or holds water- Since:
- 0.1.0
-
growthSpeed
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_cropstag. The built-in crops grow on a random tick with one chance infloor(25 / speed) + 1.- Parameters:
position- where the plant is- Returns:
- the speed,
1for a lone plant on dry soil, more on a well kept field - Since:
- 0.1.0
-
canSurvive
Returnstrueif a state could stand at a position.: what itsFarmingBehaviour.canSurvive(FarmingWorld, BlockPosition, BlockData)answers,truefor a block type without a farming behaviour- Parameters:
position- where the block would bestate- the state- Returns:
trueif a state could stand at a position- Since:
- 0.1.0
-
setBlock
Replaces a block. Players see the change, light and redstone follow, and the plants around are told.- Parameters:
position- where the block isstate- the new state- Returns:
falseif the block already held that state, its chunk is not loaded, or the calling thread does not own it- Since:
- 0.1.0
-
grow
Makes a plant grow: fires aPlantGrowEvent, then writes what the listeners left of the grown state.- Parameters:
plant- where the plant growing istarget- where the grown state goes:plantfor a crop ripening, another position for a cane growing taller or a stem bearing a fruitgrown- the state to write attargetfertilized-trueif a fertilizer causes the growth- Returns:
falseif a listener cancelled the growth, or the block could not be written- Since:
- 0.1.0
-
grow
Makes a plant grow in place, on its own.- Parameters:
plant- where the plant isgrown- the state it takes- Returns:
falseif a listener cancelled the growth, or the block could not be written- Since:
- 0.1.0
- See Also:
-
destroy
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:
falseif there was nothing to break, its chunk is not loaded, or the calling thread does not own it- Since:
- 0.1.0
-
harvest
Drops what a block gives: fires aHarvestEventwith 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 isplayer- the player breaking the block,nullwhen nobody doestool- what the block is broken with,ItemStack.EMPTYfor none- Returns:
trueif at least one stack was dropped- Since:
- 0.1.0
-
dropItem
Drops a stack from the middle of a block, as a harvest falls.- Parameters:
position- the block to drop fromstack- the stack, nothing is dropped when it is empty- Since:
- 0.1.0
-
scheduleTick
Schedules a call toFarmingBehaviour.tick(FarmingWorld, BlockPosition, BlockData), oncedelaygame 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 tickdelay- the number of game ticks to wait,1for the next tick- Since:
- 0.1.0
-
blockChanged
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 isprevious- the state that was replacedcurrent- the state now in place- Since:
- 0.1.0
-
useItem
Uses the item a player holds on a block, when the item is one theFarmingRegistryknows: 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 playerslot- the slot of the inventory of the player holding the itemposition- the block the item is used onface- the face of that block the player clicked- Returns:
trueif the item did something, and nothing else should be done with it- Since:
- 0.1.0
-
entityLanded
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 landedposition- the block it landed onfallDistance- how far it fell, in blocks- Since:
- 0.1.0
-