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:
- More detailed instructions for setting up CraftBukkit with the RaspberryJuice API from Eric at Lost Bear Labs.
- Minecraft Pi projects, including a cannon, solar system simulator, and turtle graphics.
- Oodles of resources from The Don of Minecraft Pi Craig Richardson, who’s now working directly for the education team at Raspberry Pi. His unfinished-but-still-rather-good Python-via-Minecraft book is my next line of exploration.
- MCPIPY.com – resources and code examples.
- One of my big stumbling blocks with Minecraft was realising that the desktop, tablet/phone and Pi editions are all completely separate. In fact, Minecraft documentation in general is weirdly sparse. If you don’t have an eight year-old to hand to quiz, spin through this beginner’s guide. I’d also suggest looking at the introductory magazine specials available from newsagents. Retro.