Minecraft on the Raspberry Pi

mysnapshot_04Well… I escaped the whole Minecraft phenomenon for this long. Sure, I’d heard about it from the students and a few visitors at the Exeter Raspberry Jam loaded it up on my Pi, but I’d never delved any further.

Minecraft appears to be a game which puts the user in control of “Steve” – a superhero who can hop and fly at the touch of the spacebar. Armed with his trusty sword which can build and tear down (echoes of Ecclesiastes 3) he can navigate the cubic world at will. The world coordinates are limited to +/- 127 units but that’s a fair amount of walking and flying. I’m guessing the scale is somewhere around 1 unit = 1 metre. It’s all vaguely reminiscent of 3d Construction Kit which I used to run on my Amiga.


This is Steve. He’s pretty shy. I’ve seen his face when I’ve networked two Pi’s together, but for the most part you either see his back or walk in his shoes.

Where it really seems to score is the way the API can be used with Python. I’ve had a play and I’m pretty pleased with the results.

First up – Bung on an i2c LCD display (Cheap from Ebay) and then use it to plot my coordinates and the CPU temperature. Not really useful, but perhaps ideal as a proof of concept.

import os
import commands
import time
import pylcdlib
import datetime
from mcpi import minecraft

mc = minecraft.Minecraft.create()
lcd = pylcdlib.lcd(0x27,0)
lcd.lcd_puts("                 ",1) #display on line 1
lcd.lcd_puts("                 ",2) #display on line 2

cmd = 'hostname -I'
line = os.popen(cmd).readline().strip()

lcd.lcd_puts(line,1) #display on line 1
lcd.lcd_puts("Minecraft Online ",2) #display on line 2


lcd.lcd_puts("                 ",1) #display on line 1
lcd.lcd_puts("                 ",2) #display on line 2

def get_cpu_temp():
	tempFile = open( "/sys/class/thermal/thermal_zone0/temp" )
	cpu_temp = tempFile.read()
	return float(cpu_temp)/1000

while True:
	x,y,z = mc.player.getPos()
	lcd.lcd_puts("X"+str(x)[0:4]+" Y"+str(y)[0:4]+" Z"+str(z)[0:4]+"       ",2) #display on line 2
	lcd.lcd_puts("CPU :"+str(get_cpu_temp())+"       ",1) #display on line 1

This works by grabbing the CPU temperature from /sys/class/thermal/thermal_zone0/temp and processing it, and using the API to grab the current position. The rest is just isolation of the useful data. It occasionally seems that the LCD doesn’t start properly, so that’s another thing to look at.

"LCD showing Steve in Minecraft.

Displaying the CPU temperature and the current coordinates of “Steve”.

One thing that confused me is the coordinate system used. X is left-right (East/West perhaps) followed by Z as North/South. Up/Down are on the Y axis. This is different to our school’s CNC Router, which uses Y as North/South. It’s there in the API documentation, but to me it’s counterintuitive.

I then had the idea of creating a Maze type game using the API. I’d already written a basic cave adventure game in Python and I wanted to see if the two-dimensional array would turn into a 3d maze. Well – pretty straightforward, but that’s for another post!

For some really awesome information on Minecraft on the Raspberry Pi, jump to Raspberry Pi Spy and Stuff About Code.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s