Get off to a good start with Minecraft Pi Edition. Play the game and write your first program using the API
If you’ve never played Minecraft Pi, and want to learn how to program Minecraft using a Raspberry Pi, then this is how to be a master block builder.
We’ll help you get stuck into Minecraft on the Rasbperry Pi, build a house, and get started with the API.
Minecraft is a game which has achieved monumental success; more than 120 million copies have been sold across all its versions. Not bad for a game which doesn’t really have a point! If it does have a point, as an indie sandbox game, it’s to make stuff. And people have really made stuff, from fully functioning computers to scale models of the Starship Enterprise.
The best things about Minecraft Pi Edition are that it’s free, and that it comes with an API. You don’t get this with any other version of Minecraft.
Minecraft is installed by default on Raspbian. If you have an older version, you can get it by opening a Terminal (Menu > Accessories > Terminal) and typing these commands, pressing ENTER after each:
sudo apt-get update
sudo apt-get install minecraft-pi
Click Menu > Games > Minecraft: Pi Edition to run the game. Minecraft: Pi Edition offers one playing mode, Classic, which is all about exploring and building. Click Start Game, then click Create New (or choose an existing world) to enter a world.
The API (application programming interface Minecraft Pi) allows you to
write programs which control, alter and interact Minecraft Pi with the
Minecraft world, unlocking a whole load of Minecraft Minecraft Pi
hacking. How about creating massive houses at the click of a button; writing a game which uses Minecraft Pi a LED and buzzer to help you
find a block; or recreating Nintendo’s Minecraft Pi Splatoon in
The API works by changing the world Minecraft Pi as the game is being played, allowing you to:
The first program all programmers create when learning something new is called Hello World Minecraft Pi, which puts the phrase ‘Hello World’ on
the screen. You’re going to do the same Minecraft Pi, but in Minecraft:
Switch back to Minecraft, click ‘Back to game’, and you should see the message ‘Hello Minecraft World’ on the screen. Be quick, though, as the message only stays on the screen for ten seconds.
Any errors will appear in red text in the Python Shell window. Check your code carefully for spelling mistakes, and ensure that you have used the right upper- or lower-case letters.
When you have successfully made the message appear on the screen, try changing it and running the program again.
Using your new Python programming skills and the Minecraft API, you can teleport Steve around the world by adding just one more line of code to your program.
Minecraft is a world of blocks, all about 1m × 1m × 1m. The player and every block in the world has a position made up of x, y, and z: x and z are the horizontal positions and y is the vertical. By changing the player’s x, y, and z position, you can teleport them wherever you want.
The player starts at position x = 0, y = 0, z = 0, which is the spawn point, and the player’s current position is shown at the top left of the screen.
Add the following code to your ‘Hello Minecraft World’ program to teleport the player to position x = 0, y = 50, z = 0, which will put your player 50 blocks up in the air:
Try changing the values in setPos() to teleport your player to different places around the world. Use values -125 to 125 for x and z and -64 to 64 for y, otherwise the player will be teleported outside the world.