Create a path of flowers and a yellow brick road wherever you walk.
In this project we are going to learn how to create a program Minecraft that will leave a trail of flowers or a yellow brick road behind you wherever you walk in the world.
First, open Minecraft Education Edition, login, create a new world and open the Code Builder.
To create a new Minecraft coding project you will need to follow these steps:
Add the following code to leave a trail of flowers behind you, wherever you walk in the Minecraft world.
player.onTravelled(WALK, function () { blocks.place(YELLOW_FLOWER, pos(0, 0, 0)) })
As we are using the position 0 0 0, the flowers get created wherever you are. The on player [walk] block triggers whatever code you put inside it when the player walks.
A position represents a location in the Minecraft world. Positions are used in many blocks and commands to spawn mobs, fill blocks and more.
A position is represented by 3 numbers, x, y, and z:
The numbers for x, y, and z are the coordinates (a coordinate is also known as a direction or an axis) of the position.
There are two kinds of positions: a relative position and a world position.
Next update your code as follows to place different types of flowers wherever you walk.
player.onTravelled(WALK, function () {
blocks.place(POPPY, pos(0, 0, 0))
blocks.place(ALLIUM, pos(0, 0, 0))
blocks.place(CORNFLOWER, pos(0, 0, 0))
})
You may have noticed the on player [walk] block can be changed to trigger the code inside it for different things the player can do.
Change the block so that it triggers on player [fly] and then run your code.
player.onTravelled(FLY, function () {
blocks.place(POPPY, pos(0, 0, 0))
blocks.place(ALLIUM, pos(0, 0, 0))
blocks.place(CORNFLOWER, pos(0, 0, 0))
})
To make your player fly, press the space bar twice and then use the w or s keys to move around.
Add the following new code to place a gold block wherever your player walks.
player.onTravelled(WALK, function () {
blocks.place(GOLD_BLOCK, pos(0, 0, 0))
})
Run your code and make your player walk around. Notice that gold blocks get placed on top of the ground, wherever you walk.