In a previous post I described how Leo and I have been using redstone to create digital hardware in Minecraft — or at least to try. This approach to interesting Minecraft is like pulling teeth. (More precisely, it’s like building a computer out of sand…almost literally!)
There are also several ways to program the Minecraft world itself. One way involves command blocks which allow you to execute arbitrary sets of Minecraft commands. We haven’t really tried this yet, but it seems kind of painful. But you can do some pretty complex stuff done this way, like this amazing Turing machine, and this complete SPARC CPU!
A much more direct way to program the Minecraft world is to reach into the server itself through its API. There’s a very good intro to programming in Python, by Craig Richardson, that’s all set in the Minecraft world. Getting the software to actually work requires hacking through the usual morass of stack hassles, wrong program versions, broken paths, missing files, and blah blah blah, but once I got through all that, it actually worked! (I’m always amazed when something in the Unix world actually works, considering the utter mess that is the Unix software stack!)
Once I got this to work as advertised, Leo and I were able to actually program in Python and have it take effect in the Minecraft world!
Considering that this is the first time Leo has programmed in an actual text-based programming language, we started with something simple.
First Leo wanted to build huge buildings, so we wrote a triple-nested loop:
def maketower(x1, x2, y1, y2, z1, z2, blocktype): for x in range(x1,x2): for y in range(y1,y2): for z in range(z1,z2): mc.setBlock(x,y,z,blocktype)
It only took about an hour to get him to understood the nested loops.
Next he wanted to drop blocks near us, and I had to idea to make this happen continuously as we move around. Here’s that program (blocktype 57 are diamonds):
def poopie(blocktype=57,sleepsecs=1): while True: pos=mc.player.getPos() print(pos) time.sleep(sleepsecs) mc.setBlock(pos.x,pos.y,pos.z,blocktype)
If you call this with sleepsecs=0.1 or so, then it leaves a trail as you move …thus its name! 🙂
Here are a couple of view of what the world looked like after we had made a bunch of giant blocks of diamond and emerald using maketower, and we had also flown around for a while pooping diamonds:
The totally great thing about this is that I can use Leo’s natural attraction (one might say “addiction”!) to Minecraft as a way into Computer Science for real. Unfortunately, Python is a ridiculous programming language — sort of the modern version of BASIC, or possibly worse!
At some point I’ll port the interface to a Lisp; then we’ll actually be able to do some real computer science!