Introduction: Interactive Python Programming for Minecraft: PythonTool Mod
Minecraft is one of the best-selling video games of all history, has a massive player community and offers endless adventures and educational capabilities.
Lots of people around the world use Minecraft for teaching/learning in a variety of setups, from University courses in AI, to schools or summer camps. It has been used for a variety of disciplines, from chemistry, to physics, history and much more!
Particularly interesting are the opportunities it offers to teach programming in a gamified and friendly environment. There are great resources for this, such as ComputerCraft mod which is played in-game, the creation of Minecraft mods, or Minecraft Pi edition for the Raspberry Pi which allows interaction between the Python programming language and Minecraft in real time!
Luckily, this is not available only for Minecraft Raspberry Pi edition. It can be installed in any computer version of Minecraft (Windows, Mac or Linux) with little effort, using the Forge mod RaspberryJam created by user arpruss here in Instructables.
In order to make the Minecraft + Python interaction funnier and easier, a Minecraft mod called PythonTool was developed at the University of Southampton in the UK. Have a look at the video!
MIT License Copyright (c) 2016, Alvaro Perez-Diaz & Hans Fangohr. NGCM, University of Southampton, UK.
Step 1: Installation & Configuration
Detailed installation & configuration instructions are available from PythonTool's website.
Here is the process in a nutshell:
- Download and install Minecraft
- Load your desired version of Minecraft, for example the most recent one, 1.10.2
- Download and install the same version of Forge
- Download and install RaspberryJam Mod. Don't forget to copy both the mcpipy and mods folders to your Minecraft installation folder.
- Download and install PythonTool mod
- Download and install Python (comes by default with Linux and Mac)
Configuration: there are two custom paths that can be defined in PythonTool's config menu, inside Minecraft
- mcpipy path: type the path of the mcpipy folder you installed before in step 4 (by default it points to the Minecraft's default installation folder, so if everything was installed in their default folders, no need to touch this)
- personal path: the path of the folder you wish to use to store the Python scripts you want in-game (by default it points to the mcpipy folder, which has lots of examples to get you started)
Step 2: User Guide
This user guide can be found in PythonTool's website.
PythonTool provides a custom block and a custom item, the Computer Block and the Python Script Item. The Computer Block can be crafted out of 8xCobblestone blocks and 1xGlass block, or found in the Miscellaneous tab in creative mode. Place it in your world.
The Computer Block looks at a given folder in your system (select it in PythonTool’s mod config menu) where you will place your scripts: create your own or get dozens freely available online! Right-click on the Computer Block, you will see all those scripts in your folder as Python Script Items in the game, you can move them to your inventory or hot bar.
Equip and right-click a Script Item to get it running!
An arbitrary number of Python Scripts can be running at the same time. Right click on a Python Script will stop all running scripts andexecute the new one. If you want to launch a new script and keep any previous ones running, use shift+right click (sneak click!). If you wish to just stop all running scripts without running a new one, you can type /py in the chat console.
Step 3: Get Started Coding!
By default, PyCraft uses the example scripts that come with RaspberryJam Mod. There are several dozens, created by many different people who have made them freely available online. You are very welcome to look, use and modify them as you like!
All the Python scripts which interact with Minecraft use a collection of other Python scripts called mcpi, which handles all the difficult stuff, like connecting to your world and moving things around as you wish, you just have to tell it what you want.
here are many good sources to get started, plenty of blogs and tutorials online. A really good self-contained guide detailing everything from setting up your computer to creating interactive games, is the book Adventures in Minecraft by Martin O’Hanlon.
We propose you use the Jupyter Notebook to write your Python programs. Once installed, it opens in your browser, and let’s you do all your programming there, allowing you to write and execute small pieces of your code whenever you want!
There are several examples in the PythonTool's website to get you started:
- Hello world! Covers the basics, connect to your Minecraft world and post messages to chat!
- Convert blocks into diamond: basic block manipulation, convert blocks around you into diamond
- Build a house: build a fully equipped house, with windows, a chest and a crafting table, lighted by some torches!
Step 4: Modify and Improve PythonTool
PythonTool is an open-source mod, so you can have a look at the code and modify whatever you want! Improvements are encouraged and very appreciated :)
Any comments and feedback are welcome, enjoy!
Question 3 years ago
is (python tool) safe?
Question 3 years ago on Introduction
Is this project still on?
I really want to embed minecraft - python in my classes. I am new in minecraft but I am learning fast. I bought Minecraft 3 weeks ago. I now have the 1.14.4 version. I saw that in your instructions that I need 1.10.2 version of Minecraft. I am not sure how to find this one. could you help?
Answer 3 years ago
Hi, sorry for the late reply.
You are right, you need Minecraft 1.10.2 -or earlier- to run this mod. Installation is very easy, and here is the link to the official instructions: https://help.mojang.com/customer/portal/articles/1475923-changing-game-versions
It's done super quick and then you can easily select what version of Minecraft to launch!
Let me know how you get along and happy to help.
Reply 3 years ago
Thank you very much for your answer. Do you have any plans to update the tool for later versions of Minecraft? I really need to use it in python programming but I am afraid the reactions of my students when I ask them to use such an old version of minecraft..
Also, is there another way to use python and minecraft together?
Reply 3 years ago
Hi, no problem. So using Python inside Minecraft has been around for a while and there are several ways to do it:
1. Python Pi Edition https://www.minecraft.net/en-us/edition/pi/ it is free but works only on a Raspberry Pi
2. Mods that allow doing this with "normal" Minecraft, such as this instructable. This mod basically wraps another mod and allows using python scripts as objects in the game, which we found very cool for gamification.
It is very likely that PythonTool mod won't be updated for newer versions of Minecraft anytime soon: I don't have the time and the other low-level mod (developed by someone else) which it builds upon hasn't been updated either.
However, there seem to be another couple of libraries with support for newer versions of Minecraft and, with probably a fair amount of hacking around on your side, they may be able to execute Python scripts inside Minecraft:
I haven't tried these myself and I'm not entirely sure of what they do/don't.
In all honesty, I'm not familiar with newer versions of Minecraft, but if the game is to be used as an education tool, perhaps there's no need for the new items/features that come in recent versions. You can do extremely cool stuff with Python in there that seemed to get student's attentions quite quickly when we ran workshops in the past :)
5 years ago
Thanks! Just what I was looking for to teach my boys programming.
Reply 5 years ago
Great! Feel free to get in touch either here or via the contact form in PythonTool's website.