{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "A bit over two years ago I wrote [a post about hacking minecraft with Python](/blog/2015/minecraft-python-0.html). During my holiday break this year I decided to revisit this, and have a bit more of a go with it. Some things have changed, including the Minecraft Bukkit Server that I used then (CanaryMod) being abandoned, and some new enhanced modules that let you run Minecraft PI Python code on a non-PI machine, with Python 3! So let's dig in.\n", "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "----\n", "\n", "# Connecting Python programs to Minecraft \n", "\n", "## Minecraft Pi Edition \n", "\n", "**Quick recap**: The [Minecraft Pi Edition](https://www.raspberrypi.org/documentation/usage/minecraft/README.md) game included with the [Raspbian OS](https://www.raspbian.org/) for [Raspberry Pi](https://www.raspberrypi.org) may be accessed by an [Application Programming Interface](https://en.wikipedia.org/wiki/Application_programming_interface) (API). The API is a collection of well defined methods for a computer Application to do some things in Minecraft, and it was written by Mojang (Minecraft's creators) especially for the Pi Edition of the game, to be an Interface for Java and Python programs.\n", "\n", "The *MCPI API* describes a computer [protocol](/jargon/html/P/protocol.html) for a *client* program to connect to a Minecraft game *server* and then communicate with it through network messages. The core of the protocol is described in the file `mcpi_protocol_spec.txt` included with the MCPIPY download when you install it per the Raspberry Pi instructions, or the excellent tutorials and guides at [Stuff About Code](http://www.stuffaboutcode.com/p/minecraft.html). I've also placed [a copy of the spec' on my web site](http://milosophical.me/hax/mcpi_protocol_spec.txt) for easy finding.\n", "\n", "The *Stuff About Code* site has lots of helpful information for hacking in Python 2.*x* and connecting your programs to Minecraft Pi Edition. If you have a Raspberry Pi, then this is the quickest and easiest option to get started. **Martin O'Hanlon** (the man behind Stuff About Code), together with David Whale, have written a fantastic book *Adventures in Minecraft* (you can find a link to purchase this on their web site), which introduces programming basics in Python. It is full of fun projects, and also extends MCPIPY with some [higher-level primitive shapes](http://www.stuffaboutcode.com/2013/11/coding-shapes-in-minecraft.html) (drawing lines, polygons and polyhedra, as well as [turtle-graphics](http://www.stuffaboutcode.com/2014/05/minecraft-graphics-turtle.html)).\n", "\n", "\n", "## Minecraft Java Edition\n", "\n", "If you don't have a Raspberry Pi, or you want to use a more familiar computer, then Martin O'Hanlon also has you covered. He created [Raspberry Juice](https://github.com/martinohanlon/canaryraspberryjuice), a [Bukkit server](https://dev.bukkit.org/)-compatible module that implements most of the MCPI API. The [method described on Stuff About Code](http://www.stuffaboutcode.com/2014/10/minecraft-raspberryjuice-and-canarymod.html) (and which I followed on my blog years ago) installs Raspberry Juice into the *CanaryMod* Bukkit server and then has you use Minecraft's *Multiplayer* mode to connect the game to CanaryMod.\n", "\n", "Unfortunately those instructions are quite dated now, and CanaryMod itself has been abondoned. There is a newer Bukkit server that also works with Raspberry Juice, called [Spigot](https://www.spigotmc.org/). I have been able to follow Martin's instructions using Spigot instead of CanaryMod. My results were satisfactory, but I've found something even better." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Raspberry Jam: a new way to connect Python to Minecraft Java\n", "\n", "A far easier way to start coding on Minecraft Java is to use [raspberryjammod](https://github.com/arpruss/raspberryjammod), a [Minecraft Forge](https://mcforge.readthedocs.io/en/latest/) module. *Forge* is a Minecraft \"modding\" framework, widely used to expand or enhance the Java edition of the game with new modules such as better rendering, minigames, new creatures and blocks. Chances are good that Minecraft players reading this already know a lot about it.\n", "\n", "The creator of *raspberryjammod*, [Alexander Pruss](https://www.blogger.com/profile/05989277655934827117), has documented installing and using it in [an Instructable](http://www.instructables.com/id/Python-coding-for-Minecraft/). The Instructable is really good and complete and I've successfully followed the instructions to install it on Macintosh, PC (Windows 10), and Linux (SUSE). I recommend following the instructable. It's *almost* as easy as installing Raspbian OS and getting going on a Pi.\n", "\n", "A really neat thing about Dr. Pruss' work is: **it also includes an updated version of the MCPIPY code from Stuff About Code, with additional examples, plus changes to make it compatible with Python 3!** You can get it from [Arpruss' raspberryjammod releases GitHub page](https://github.com/arpruss/raspberryjammod/releases) (look for `python-scripts.zip`). These scripts still work with Python 2 and still target the original MCPI API, so you can use this Python code everywhere, including on the Pi.\n", "\n", "Dr. Pruss' blog entries on [Minecraft](https://alexanderpruss.blogspot.com.au/search/label/Minecraft) and [Python](https://alexanderpruss.blogspot.com.au/search/label/Python) (there is some overlap here) are well worth reading." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## PythonTool Mod\n", "\n", "The [PythonTool Mod](https://ngcm.github.io/PythonTool-Mod/) is another *Forge* mod, which works together with *raspberryjammod* to take the hacking experience even further. It improves on the Raspberry Jam base in a few important ways:\n", "\n", " * In-game script loading/reloading\n", " * Execute scripts by Equipping them and then Using them, rather than entering `/py somescript` commands in the Chat\n", " * Allows you to have a folder for your own scripts separate to the MCPIPY library\n", " * The website introduces Using [Jupyter Notebooks](http://jupyter.org/) to [note-take and explore](https://ngcm.github.io/PythonTool-Mod/startcoding/)\n", " \n", "There are [instructions to install PythonTool Mod](https://ngcm.github.io/PythonTool-Mod/installation/) also. I have a few notes and gotchas though which I'd like to expand in my next blog post.\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.0" }, "nikola": { "category": "", "date": "2018-02-05 11:18:42 UTC+11:00", "description": "", "link": "", "slug": "minecraft-python-1", "tags": "hacking, minecraft, python, getkidscoding, kids, RaspberryPi", "title": "Minecraft Jamin'", "type": "text" } }, "nbformat": 4, "nbformat_minor": 2 }