Go to Ground in MakeCode for Minecraft

MakeCode for Minecraft coders sometimes assume that the player will be on the ground when the program starts. There is no harm in this except that some programs do weird things if the user forgets to move the player to the ground before running it. Users may find the weirdness difficult to understand. A wise coder would teleport the player to the ground as a first step in a program.

In a flat world with no complex structures, the player is teleported to the ground with code block below.

Go to Ground 1a

We can test this statement by wrapping it in a Chat command.

Go to Ground 1

Try flying the Player to various locations in the sky, then run the chat command to verify that the player is indeed teleported to the ground with no change in the X and Z coordinates.

A Reusable Go-to-Ground Function

Although only a single block is required to teleport the player to the ground, the block is so wide that often it cannot be read without scrolling to the right. Further, recoding the block for many programs can get old, Recoding can also introduce bugs because some little mistake is made in the recoding. I have, for example, mistakenly coded the Z coordinate as X, since X is the default in the “position get value of” block. As a remedy to all these issues, I created a little function that can be copied  to any program where it is needed.

Go to Ground 3

To test the function, I created the chat command “goToGround” shown below.

Go to Ground 2

Get the Code

The code for Go to Ground is shared at https://makecode.com/_8HhHxbTxMiu3. It can be downloaded and run in MakeCode for Minecraft.