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.
- Codecademy have an online Python course, which I found very patchy. The section on logical operators comes early and is particularly terrible. Having recently skimmed through their Javascript, JQuery and PHP courses I admire their whizzy in-browser tech, but I’d much rather have a better-written book or PDF. Just me?
- 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.
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…
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.
Ah, that makes sense. I think Java has its place, but writing short scripts like this definitely isn’t one of them.
Happy crafting 🙂