Minecraft – How exactly does melon/pumpkin growth work

minecraft-java-edition

Often, when people discuss automatic melon/pumpkin farm designs on reddit or similar places, a question pops up:

Does pushing a block into the air block the melon/pumpkin will grow into reset the growth timer?

If the answer to this is yes, a badly set up timer can severely limit the production rate of your melon/pumpkin farm by resetting the growth all the time.

From a code perspective, this would mean that the game is looking at the air blocks surrounding a stem continuously, updating a growth timer somewhere when a random tick update hits the stem (or the air block?), which I guess is possible. It could also imagine it to pick a direction first and only check that block, but I don't know, which brings me to the question:

How exactly does melon/pumpkin growth work? What are the specific steps the game code runs, and how does it interact with the world? An answer based on decompiled code would be ideal, but extensive testing might also reveal the game's logic.

Best Answer

The following is based on the source decompiled via 1.9 ModCoderPack.


The current growth stage of the stem is saved as its metadata value. You can view this value via the F3 menu. The image shows a stem partway into its growth, via the age blockstate:

Age 3 melon stem

This value increments by random chance via random ticks rather than an internal timer. The following is the random chance condition, provided the light level above the stem is 9 or higher:

rand.nextInt((int)(25.0F / growthChance) + 1) == 0

If a random value generated from 25 divided by the "growth chance", and after being floored has 1 added, is equal to 0, then the crop has the ability to either grow taller or grow a melon/pumpkin, depending on its growth stage.

The value for growthChance is obtained using the same function that all crops use, being the existence and hydration of surrounding farmland and nearby crops. The wiki details the long list of conditions here.

For example, provided the following arrangement:

Single hydrated farmland with melon stem.

The growthChance will always be 4.0, which means a random value between 0 and 7 is chosen. If the random value is 0, then the crop is ready to grow.

If its growth stage (metadata value) is 6 or lower, it will increase by 1, visually increasing the height of the stem. Nothing else will happen and no other checks are made.

If the growth stage is 7, then one random location surrounding the stem will be chosen. If that location is air and the block below that is grass, farmland, or dirt, then a new melon/pumkin block will be placed. If those conditions fail, then nothing happens and it must receive another random tick to attempt placing another block.

If the growth stage is 7 while the blockstate facing is not "up", and it's facing a respective melon/pumpkin block, then a new melon/pumpkin block cannot grow.

As such, the growth timer will not reset by placing a block where a melon/pumking can grow since there is technically not a timer at all. But a badly-timed placement of a block could prevent potential growth should the stem receive a random tick update at that same moment. There would be no way to detect it and no way to prevent it, short of making sure you remove any impeding blocks as soon as possible to reduce the chance of a clash.

From a technical perspective, it is very possible that a melon could successfully grow twice in quick succession (as quick as twice in 2 ticks), but it is not probable.