What is it?
Minecraft pocket edition comes to the Raspberry Pi but it is more than just playing a computer game. Programming with Python on the Raspberry Pi is a powerful and fun way to modify Minecraft games. Using a few lines of code you can take control of the player and then every block in the world. This allows you to manipulate the entire world and how Steve interacts, think of the Matrix! (trailer here).
1. Getting Set Up
To get started, firstly download the Minecraft software for your Raspberry Pi. Load yourPi and log in with your username and password, run the GUI, type in “startx”.
In the LX Terminal type:
sudo apt-get update
sudo apt-get upgrade
wget https://s3.amazonaws.com/assets.minecraft.net/pi/minecraft-pi-0.1.1.tar.gz (all one the same line)
Or you can try:
wget http://goo.gl/o2aene -O mcpi.tar.gz --no-check-certificate
The next stage is to decompress the file with the code below, type:
tar -zxvf minecraft-pi-0.1.1.tar.gz
Then to run the game move to the Minecraft folder by typing:
You can type ls to list all the files in the mcpi folder
Then type: ./minecraft-pi
(Don't forget the dot before the /)
2. Let's Play
Getting started with hacking your Minecraft world is simple. There are many websites and cheat-sheets available which have a wealth of ideas, hacks and instructions to get you started and keep you coding for a long time.
Your First Program
In the Minecraft world the players position is located at X, Y, and Z co-ordinates. The Y is the height in the world, X is how far left or right and Z is backward or forward. This basic code will import the Minecraft API and then set the X, Y, and Z position to 1, 24 and 1, then the setTilePos moves the player to that position in the world. You can teleport the player anywhere by changing the X, Y, and Z numbers, even sending Steve underground!
In the LX Terminal type:
Then type the following code:
from mcpi import minecraft
mc = minecraft.Minecraft.create()
x = 1
y = 24
z = 1
Once you have finished typing save the Python file into the home/pi folder. Ensure that Minecraft is loaded up and then press F5 to run your code and teleport Steve.
Once the teleporting code was operational I considered building a teleporter within the game, this started off as blue blocks, then I wanted to place the player inside the device. This was achieved by working out the x, y and z position of the middle of the teleporter, (can I call it a TARDIS from now on!), then sending the player to that position to place them inside the TARDIS. But, with blue blocks it was too dark inside and you could not see anything, so I changed the blocks of the TARDIS to glass, hey presto a 'great glass elevator'.
The rest of the code introduced a function to allow the player to teleport around the world by selecting their desired x, y and z location. Once selected and entered, Steve was teleported to that location arriving in the in the TARDIS / elevator thingy machine. Yeah works nearly as well as in Half Life 2!