Step 3

Completing our program


Next, let’s add the code as shown to complete our program!

We first use an if statement to check if the block the player is standing on is a “grass” block.

If it is, we then turn the grass block into a “farmland” block. Then we turn the block above it into a “wheat” block, which will plant it inside the “farmland” block.

Then we need to subtract 1 from our “seeds” variable, what would happen if we didn’t do this?

Lastly, after the if statment (notice the unindent), we add a slight pause to the loop. We also post a message to the chat when the loop is completed.

Running our program


Now that all of our code is completed, let’s go ahead and test it out!

If done correctly, you should be able to plant wheat as you walk on grass! It should also deactivate after 100 seeds have been planted.

If it doesn’t work, double check all of your code to see if you made any mistakes.

With this done, think of some other ways you can further modify or improve this program!