The Raspberry Pi is a cute little computer. Quite cheap at $35, you plug in USB keyboard+mouse and a TV as monitor. And it is surprisingly capable, even for running 3D games.
One particularly interesting game is Minecraft: Pi Edition. As in other Minecraft versions, the main goal is to create a world. But unlike other versions, you can not only use the tools provided by the game, you can make your own tools! That's because it comes with a programming interface.
The Minecaft world is made of little cubes, and you normally place or remove these blocks by hand, one after another. This is fun, but for larger structures also quite cumbersome. For example, this rainbow here might take a long time to construct manually:
But I did not make the rainbow by hand. I programmed it, using the Smalltalk programming language. It's just these dozen lines of code in the Squeak programming environment:
Squeak is already installed on the Raspberry Pi, because Scratch was made in Squeak. Of course you need a little more to make this dozen lines of code work. Mojang (the developers of Minecraft) have provided "bindings" for the Python and Java programming languages, but not for Smalltalk. So I had to make these bindings first.
There are two packages, 'Minecraft-Pi-Base' and 'Minecraft-Pi-Demo', load them in this order. At the time of writing, the demo package has only the rainbow method in it. The code is not heavily commented, but from the examples it should be fairly obvious how to use it.
The bindings are still somewhat basic, but cover all the functions of the current Minecraft-Pi 0.1.1 release. There is certainly room for improvement. E.g. it would be nice to add symbolic block names, so you could write "wool" instead of "35". And the hit testing (when you right-click on a block with your sword) works, but could be made more convenient to use, perhaps by introducing an event class like in the other bindings.
One particularly interesting game is Minecraft: Pi Edition. As in other Minecraft versions, the main goal is to create a world. But unlike other versions, you can not only use the tools provided by the game, you can make your own tools! That's because it comes with a programming interface.
The Minecaft world is made of little cubes, and you normally place or remove these blocks by hand, one after another. This is fun, but for larger structures also quite cumbersome. For example, this rainbow here might take a long time to construct manually:
But I did not make the rainbow by hand. I programmed it, using the Smalltalk programming language. It's just these dozen lines of code in the Squeak programming environment:
Squeak is already installed on the Raspberry Pi, because Scratch was made in Squeak. Of course you need a little more to make this dozen lines of code work. Mojang (the developers of Minecraft) have provided "bindings" for the Python and Java programming languages, but not for Smalltalk. So I had to make these bindings first.
Here are the Bindings
Now you can use the bindings too, because I am publishing my code:http://ss3.gemstone.com/ss/minecraft.htmlSqueak can either run on the Raspberry Pi itself (a VM is already installed) or on another computer in your network.
There are two packages, 'Minecraft-Pi-Base' and 'Minecraft-Pi-Demo', load them in this order. At the time of writing, the demo package has only the rainbow method in it. The code is not heavily commented, but from the examples it should be fairly obvious how to use it.
The bindings are still somewhat basic, but cover all the functions of the current Minecraft-Pi 0.1.1 release. There is certainly room for improvement. E.g. it would be nice to add symbolic block names, so you could write "wool" instead of "35". And the hit testing (when you right-click on a block with your sword) works, but could be made more convenient to use, perhaps by introducing an event class like in the other bindings.
I made the repository open, so anyone can easily contribute. I'm curious what others will come up with. Like, control Minecraft from Etoys or Scratch? How about a Croquet bridge? Build a little game? In any case, have fun! :)
Comments
This is way cool! Thanks.
On Mac or Linux that API can be emulated by installing a bukkit server with the raspberryjuice plugin. Reportedly my Squeak bindings do indeed work with that, too.
http://ericclack.blogspot.co.uk/2014/03/programming-raspberry-pi-minecraft-with.html
...And added a few more demo methods and committed them to Squeak Source: to draw a table, and trees.