Interactive Python Programming for Minecraft: PythonTool Mod
by periprohus in Living > Video Games
30856 Views, 36 Favorites, 0 Comments
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.
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)
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.
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!
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!