I am mikek's Blog

The personal blog of Mike Karthauser, who you may know from Brightstorm Limited or the internet.

Scripted building in Minecraft Pi edition

Following on from our success at getting hold of Minecraft Pi edition running https://iammikek.wordpress.com/2013/02/03/minecraft-pi-edition/, it was time to explore programming Pi edition directly.

We started by getting the demo minecraft API program from stuffaboutcode.

Having run through the demo we had a bit of fun changing the parameters of various commands to understand more about how things worked, settling on the ‘diamond tower’ as the best to modify.

We started with building towers, then walls and then big blocks (20x20x20) made from various materials such as diamond, glass, water and lava.

Flowing water


Flowing lava


I’m not that familiar with python scripting so will need to dip into the docs a bit before further modification.

Here’s what’s been written so far (modified from stuffoncodes example)

#Raspberry Pi, Minecraft API - the basics
#Tower mod

#import the minecraft.py module from the minecraft directory
import minecraft.minecraft as minecraft
#import minecraft block module
import minecraft.block as block
#import time, so delays can be used
import time

if __name__ == "__main__":

#Gives us plenty of time to switch between terminal and Minecraft Pi edition

#Connect to minecraft by creating the minecraft object
# - minecraft needs to be running and in a game
mc = minecraft.Minecraft.create()

#Find out your players position
playerPos = mc.player.getPos()

#Using your players position
# - the players position is an x,y,z coordinate of floats (e.g. 23.59,12.00,-45.32)
# - in order to use the players position in other commands we need integers (e.g. 23,12,-45)
# - so round the players position
# - the Vec3 object is part of the minecraft class library
playerPos = minecraft.Vec3(int(playerPos.x), int(playerPos.y), int(playerPos.z))

mc.postToChat("Create blocks - making a crazy tower for ern")

# - loop 10 times
for zpos in range(0,10):
# builds along the z axis
for xpos in range(0,10):
#sets y axis to ground level (0)
# makes towers
for up in range(0, 10):
mc.setBlock(playerPos.x + xpos, playerPos.y + up, playerPos.z + zpos, block.LAVA_FLOWING)

A few times we ran this script, we ended up stuck inside the cubes and had to exit the game. I would imagine placing this many blocks at once might make the app a bit fragile.

Sadly this week it seems an upgrade on the iOS Minecraft Pocket edition means that we can’t access each others networked games. Hopefully we’ll get that functionality back when another version of Pi edition is released.

Am thinking now of ways we can add some sensors via GPIO and see how we can program a bit of outside world interaction with the game – maybe getting the dog involved to be a bit of chaos.. Watch this space.

Filed under: code snippets, raspberry pi

One Response

  1. […] Update: We’ve since tracked down and installed the alpha version and also had a play with the API […]

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

mikek on twitter

%d bloggers like this: