Notes on setting up pis to use Minecraft API

Wray Mills, 2015-05-20, Notes

Minecraft, python, raspberry pi

Just dropping in some code for instructors, students, and everyone [for Raspberry Pi 2].

Let's grab some Python libraries that can connect to your Minecraft World. Login to your pi and launch the GUI:


Open up a browser and go to:

and download the starter kit. Choose "open" and open the program called Xarchiver. Click Action -> Extract on the Xarchiver menu. Type /home/pi in the Extract to: text box.

Now, open up IDLE (Python) and create a new program file. You'll want to save this file in the "My Adventures" folder you just created. You can name this first file "". This actually assumes you have already done the LED input lesson and have a file that you have copied into your "My Adventures" folder. Finally, since this code uses the raspberry pi I/O, you'll need to open up a new terminal window (LX Terminal), change directory (using "cd") to "My Adventures" and run the file with sudo.

import mcpi.minecraft as minecraft

mc = minecraft.Minecraft.create()

mc.postToChat("Hello Minecraft World")

import time

    pos = mc.player.getTilePos()


    from led import *

    if pos.y > 5:


So, running this would go something like this:

cd "My Adventures"
sudo python

Want to build something?

import mcpi.minecraft as minecraft
mc = minecraft.Minecraft.create()

import mcpi.block as block

pos = mc.player.getTilePos()

for y in range(150):

Here is another cool program to try.

import mcpi.minecraft as minecraft
import mcpi.block as block
import time

mc = minecraft.Minecraft.create()

bridge = []

def buildBridge():
    pos = mc.player.getTilePos()
    b = mc.getBlock(pos.x,pos.y-1,pos.z)
    if b == or b == or b ==
        coordinate = [pos.x,pos.y-1,pos.z]

    elif b !=
        if len(bridge) > 0:
            coordinate = bridge.pop()

while True:

And while you are at it, can you post the current temp to the chat?? The hint here is that you should copy your file into your "MyAdventures" sub-directory, comment-out the deliver method and update the print method (at the end of the file) to postToChat. And, don't forget to do the minecraft setup (imports and creation) in order to postToChat.

What else can you do? Do you want to do? You all now have temp input, led output, minecraft control, and outbound email capabilities!!