The enigmatic monolith appears out of nowhere in Minecraft.

The dawn of a new civilisation… in Minecraft

I’ve been playing with Minecraft, inevitably prompted by various and sundry nieces and nephews. My explorations do not, however, revolve around surviving first-night Creeper attacks: I’m more interested in the programming interface.

There’s a rather lovely Raspberry Pi release of Minecraft which doesn’t have any of the survival mode bash-the-monster stuff, but does have an interface for the Python language. That’s great, but my Pi is one of the early models and it struggles a bit. I also struggle to run power to it in my office (I’m already using all the power sockets…), and you know what? I already have 14 processors running Unix in here, let’s just throw a Minecraft server on one of those.

First hurdle: the Python interface to Minecraft is Raspberry Pi only. Unless, that is, you run a third-party Minecraft server like CraftBukkit (hint: use the latest beta CraftBukkit server for a current Minecraft client), and install the RaspberryJuice plugin which brings the Python stuff over to the desktop world. Then you need to pull this library into your code (there’s a Python equivalent of Ruby’s gem to install this sort of thing system-wide, right?), and presto:

# ALL THESE WORLDS ARE YOURS EXCEPT EUROPA ATTEMPT NO CRAFTING THERE
# based on example code from lostbearlabs.com

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

# connect to the Minecraft server
# Pass "server_address", port, "player_name" if executing against a non-local
# server. Default port is 4711.
world = minecraft.Minecraft.create()

# Get the player's current position and store the coordinates
[x,y,z] = world.player.getPos()

# Classic proportions and plausible guess of material
height = 9
width = 4
length = 1
material = block.OBSIDIAN

# build the monolith
for level in range (0, height):
 for span in range (0, width):
   for depth in range (0, length):
     world.setBlock( x+1+span, y+level, z+1+depth, material )
     depth = depth + 1;
   span = span + 1;
 level = level + 1;

…builds the artefact you see in the image at the head of this post. Which is pretty damn cool as far as this chimp is concerned.

Links and notes:

3 thoughts on “The dawn of a new civilisation… in Minecraft”

  1. Hmm. Seems an awful faff virtualising a Pi (I’m surprised you’re running Unix not Linux) just to expose Python interface. I looked at the normal Minecraft which expects modifications to be written in Java. The tutorial at http://www.minecraftforge.net/wiki/Basic_Modding is not so simple I guess – Java is a bit more boiler-plate’y of course.

    In terms of Python, the equivalent to a Ruby gem is ‘pip’ I think.

    One solution to simplify hobbyist development it would be for someone to write a Java mod that called python scripts – which might not be too bad – Java natively supports a scripting engine system…

  2. Oh heck, no, this isn’t a virtualised Pi, that would be madness. It’s just one of the Minecraft server packages running under Java on my Mac. The RaspberryJuice plugin implements the API from Minecraft Pi Edition (and is presumably itself Java, as you suggest).

    There are Java bindings for Raspberry Juice as well as Python (and Ruby, I think?). However, I’ve happily avoided dealing with Java for the last 20 years, I don’t see much point in starting now.

Leave a Reply