Friday, January 23, 2015

Minecraft and python: Raspberry Jam Mod

I have a special interest in programming education for children, mainly because I have children and because so much of the fun I had as a child was from programming. Not too long ago, I came across the fact that on the Raspberry PI, you can control things in Minecraft with simple python code--in particular, you can procedurally generate objects. This is very attractive because my kids of course are really into Minecraft. But we don't have a PI, and while they're cheap, they need an HDMI display device and we don't have one. It turns out that there are plugins (e.g., Raspberry Juice for Bukkit) for Minecraft servers that implement (most of) the PI's protocol, but it seems overkill to run a private server just to do this.

So this January I made a mod for Minecraft 1.8 and Forge that implements most of the Raspberry PI protocol and works with most of the python scripts that work with Minecraft PI Edition. For instance, here's a spiral and a glass torus with water inside.



To install, you'll need python, Minecraft 1.8, Minecraft Forge, my Raspberry Jam Mod and the Minecraft PI Python package. Then:

  1. Install Forge for 1.8. 
  2. Create a Minecraft profile that uses it.
  3. Create a mods subdirectory to your Minecraft directory (%appdata%\.minecraft on Windows, I believe).
  4. Put my mod in the mods directory.
  5. Create an mcpipy subdirectory to your Minecraft directory.
  6. Put the contents of the Minecraft PI Python package into the mcpipy directory.
  7. Create a Minecraft profile that uses the 1.8 Forge.
  8. Run Minecraft and create a world.
  9. Run python scripts via commandline or straight in Minecraft via /py scriptname. E.g., /py nt7s_sphere will draw a sphere.
The scripts communicate with Minecraft via ASCII messages sent over port 4711. The python API is described here. The subset I implement is the Raspberry Juice one. There is a lot of information on python programming of Minecraft here (and the author of that site has a book which I've ordered for my kids but it hasn't come yet).

I am hoping that this will be great for both programming education and  teaching 3D geometry. 

It turns out that someone beat me to this by a couple of weeks, and has a mod for 1.7.10 that does the same thing. (In fact some of the ideas in the current version of my mod are based on the ideas from that mod.)

5 comments:

Alexander R Pruss said...

If anybody wants more sample scripts, here are some, including my donut, Klein bottle and Mobius strip scripts.

Kana Gokul said...
This comment has been removed by a blog administrator.
Alexander R Pruss said...

My Windows installer now has full support for Python 3.

markgrammer said...

Thanks a million! Yours is the best API I've found so far for supporting multiplayer minigames (getting player names, iDs, etc.) All of the example projects are awesome too! I am attempting to teach Python with Minecraft in my high school programming class this year. I hope this gets my students more involved. Thanks for all your hard work!

Alexander R Pruss said...

You're very welcome. I have been working with someone who has a Minecraft server for homeschooling families, and so I've been improving multiplayer security and support.