Recently, I wrote about the book, Learn to Program With Minecraft, and shared my experience getting set up to use the book with Ubuntu instead of with Windows or Mac OSX.
Yesterday I learned that the author of that book, Craig Richardson, appeared on this weekâs episode of Triangulation with Leo Laporte. Itâs a fun episode⊠they set up Leoâs Mac to run a local Minecraft server, and test out a bunch of fun stuff from the book. Well worth the watch!
Update 3/20/2016: Thanks to one of our readers, Fabrizio Fazzino, for pointing out that a software update since these instructions were prepared makes it necessary to modify them. Specifically, weâre changing how the Spigot Server component gets installed & used. Iâve updated the instructions below accordingly.
Also, heâs prepared a more succinct set of instructions that summarizes the steps. If youâre not interested in learning as much about how and why this works, Iâd recommend you check my âQuick Note About Folder Structureâ (in the yellow box below) and then follow his instructions in this comment, which Fabrizio was kind enough to post here since his original blog post is no longer accessible to the public.
Python is a programming language that Iâve long wanted to get acquainted with, and since she loves Minecraft so much, I felt like this book would be an ideal way for my daughter to also gain some exposure to it.
The only problem? We each use the Ubuntu distribution of Linux instead of Windows or Mac OSX.
You wouldnât think this would be a problem: Minecraft is built in Java, which runs without a problem on Ubuntu (and many other platforms). Python is readily available for Ubuntu. Seems like a no-brainer, right?
Well⊠not quite. After the Amazon box arrived, I spotted this note on the back cover of the book:
The code in this book will run on Windows 7 or later, OS X 10.10 or later, or the Raspberry Pi. (See the last page for detailed requirements.)
No problem! The Raspberry Pi runs a special distribution of Linux called âRaspbian,â which is a version of Debian Linux, which is the upstream version of Linux that Ubuntu is based on. In other words: Raspbian & Ubuntu are cousins.
It seems reasonable, then, that if you can get this stuff working on the Raspberry Pi, then a much more powerful laptop running Ubuntu should be great!
Even more encouraging, thereâs a nifty footnote at the bottom of Page 1 of the Learn to Program With Minecraft book which reads:
Since the book had already been out for a few weeks, this note gave me hope that perhaps some instructions for setting up all the tools on Ubuntu mightâve already been added. Unfortunately, this is not the case (yet, anyway).
So⊠I decided to try to do it anyway. Since author Craig Richardson and the No Starch Press team had prepared download packages for the Mac & Windows platforms, I figured that at the very worst, there would be some clues in those packages that might help me get going.
Getting Minecraft & Python Set Up On Ubuntu
First, here is a simple set of requirements (as I understand them) for you to be able to use the instructions in the Learn to Program With Minecraft book on Ubuntu:
Minecraft â this is the game itself. If you donât already have a license for the game, youâll need to pick one up and install it. âInstallingâ Minecraft for Ubuntu is quite easy: simply download the .jar file from your Mojang account and launch it. We had done this long ago, so this step was already completed for us.
Python â This is the programming language youâre learning. More on finding & installing it in a moment.
Java â while you probably have a basic interpreter (the âruntime environmentâ) for Java already, youâll need the Java Development Kit to run this next tool..
Spigot Server â This is Minecraft âserverâ software, which you can run on the same computer that Minecraft will run on. You need this because the Python connection to Minecraft relies on a server plugin that you canât just run with your plain old Minecraft installation.
Minecraft Python API (py3minepi) â It turns out that this connection between Python and Minecraft was originally developed especially for the Raspberry Pi. The way I understand it, this tool is an API for Minecraft that works with Python. You need it.
Raspberry Juice Some brave souls created Raspberry Juice as a way to run the Python/Minecraft connection on other platforms (not just the Raspberry Pi). When you follow the instructions in the book for Windows or Mac, this little gem is bundled in. But if youâre installing from scratch for Ubuntu, youâll need to get it yourself. Not realizing this, I installed all the other tools and ran into a really nasty error that I couldnât get around:
This error message was the part of the installation that was trickiest to resolve, but after a bit of digging, I was able to work it out.
The detailed instructions for each of these items follows (below). The one note Iâd like to insert here is this:
Iâm using Ubuntu 14.04 LTS, so your installation steps may vary somewhat if youâre using a different Ubuntu version.
Installing Python 3
You actually need 3 separate items that fall under the Python 3 heading:
Python 3 (the programming language itself)
IDLE (the development environment for Python, a/k/a the place where youâll type commands and write programs)
PIP (the âpackage managerâ for Python). You need this to install
For packages that are developed for Ubuntu, I tend to prefer using the âUbuntu Software Centerâ to install stuff like this.
The only âgotchaâ with Python is that there are a number of software versions and tools and so forth. So⊠launch the Software Center and search âpython3â (with no space).
You should see a listing that says something like, âInteractive high-level object-oriented language (default python3 version)â
Thatâs the one you want. Do yourself a favor and click on âmore infoâ so you can check the box for âIDLE 3â while youâre at it.
Install those, then run a similar search for âpython3-pipâ so you can use the package manager.
Prefer the command line to the Software Center?
Here are the commands to get python installed if youâd rather do this than use the Software Center. Youâll need to open a terminal to run these:
With Ubuntu, as is often the case, you have options here. You definitely need the Java SE SDK version 7 (presumably something newer would work as well) for the Spigot server to run.
From the Ubuntu Software Center, just search âopenjdk-7â and look for the âheadlessâ option (this is lighter weight because it doesnât include a GUI).
Or from the terminal:
sudo apt-get install openjdk-7-jre-headless
Installing Spigot Server
Update 3/20/2016 As I mentioned in the update at the top of this post, Spigot Server has released a new version: 1.9. Since the other components weâre using have not yet (as of today) updated to accommodate this, youâll need to make sure that you download Spigot 1.8.8 and use it even though it is not the most recent version available.
Spigot is one of the most popular Minecraft server options, and is a necessary component in order to get Python & Minecraft talking to each other.
Getting the server software up & running is a matter of compiling the latest version. This reference page from the Spigot wiki is the one I used, and it seems to stay up to date. However, since it contains the instructions for multiple platforms, Iâll endeavor to simplify here.
One item to install first that will make this simpler is git. Youâre going to need a terminal window anyway, so Iâd recommend going ahead and opening it now and running this command to install git:
To help make things easier on yourself, you might find it useful to use a somewhat similar folder structure to the one described in Learn to Program with Minecraft for the Windows & Mac users.
To accomplish this for myself, I opened the âFilesâ application and browsed to my âDocumentsâ folder, then created a new folder called âMinecraftPythonâ, then inside that folder another called âMinecraftToolsâ.
I recommend moving the BuildTools.jar file that you just downloaded into that âMinecraftToolsâ folder.
To do this, you have a few options:
You can drag and drop using 2 âFilesâ windows, or
you can cut & paste if you just have one of those windows open.
Otherwise, you can move the file from the command line in a Terminal window with something like: mv ./Downloads/BuildTools.jar ./Documents/MinecraftPython/MinecraftTools/BuildTools.jar. Of course, youâll need to modify that command to suit your particular situation (if youâre using a different folder structure or starting from a different location in your Terminal window than I did, for example).
Once thatâs done, from your Terminal window, youâll need to change directories to the location of your BuildTools.jar file. Depending upon where youâre starting from, that might mean a command that looks something like: cd ./Documents/MinecraftPython/MinecraftTools.
Then youâll want to execute these 2 commands:
git config --global --unset core.autocrlf
java -jar BuildTools.jar This needs to be tweaked to make sure you use version 1.8.8 of the Spigot Server component (for now).
java -jar BuildTools.jar --rev 1.8.8
This will get the Spigot Server built. In order to finish installing, creating a startup script will be helpful. You can create one with gedit by running a command like this:
gedit start.sh
The gedit text editor will open. Copy and paste this into the editor:
Note: the filename âspigot-1.8.8.jarâ was the current filename as of this writing. Youâll need to confirm that filename based upon your build, and edit the command here if itâs different use that filename as is for now (until the other components are updated to accommodate newer versions of Spigot server). Also, the Spigot instructions specifically note that the âMaxPermSizeâ directive is no longer needed or supported in Java 8, but since Iâm using Java 7, I left it in mine.
Save the file and close gedit.
Next, youâll need to make the script executable. From the same terminal window, type:
chmod +x start.sh
Before you launch this file, youâll need to accept the End User License Agreement. Locate the eula.txt file in your âMinecraftToolsâ folder and open it for editing. You can do this from a terminal window by typing gedit eula.txt . From the âFilesâ application, you can right-click the eula.txt file and choose the option to edit it with gedit.
Before you change the line that reads eula=false to eula=true, youâll want to review the Minecraft End User License Agreement and verify that youâre ready to agree to its terms. Once you are, changing the value to âtrueâ and saving the file will allow you to launch the Spigot Server without a hiccup (assuming that it is installed correctly).
Starting Your Spigot Server
Once thatâs completed, you can start the Spigot Server to ensure itâs working properly. Youâll use this same command start the server each time you need to use it:
./start.sh
If all has gone according to plan, you should see the output of the server startup process in your terminal window. The Spigot Server will create a new Minecraft world as it launches, and once itâs up and running, youâll see a > prompt with a flashing cursor next to it. You need to keep this window open.
Testing Your Spigot Server Installation
To test your server, launch Minecraft as usual.
Click âMultiplayerâ and then choose âAdd Serverâ
Give your new local server a name. The book recommends Minecraft Python World for it. In the âAddressâ box, type localhost. Thereâs a picture at the top of page 17 of the book which you can refer to as an example.
Quick note: if youâre using a typical Minecraft installation, then your Minecraft version will have updated by now to a version newer than the Spigot Server version. If so, youâll need to edit your âProfileâ and specify the Minecraft version to run so that it matches your Spigot Server version (1.8.8 if youâre following this writing exactly). Alternatively, you can create a new profile instead (this is what I chose to do) so that your main Minecraft profile continues to use the latest Minecraft version.
You can double-click the Minecraft Python World and check out your new world.
Note:The authorâs downloads for Mac & Windows operating systems are pre-configured to be in Creative Mode. This world will be in Survival Mode instead. This can be changed by editing the server.properties file in your âMinecraftToolsâ folder and changing the line that reads gamemode=0 to gamemode=1 . You may also find that you need to change the line that reads force-gamemode=false to force-gamemode=true .
Play as long as you like, but before proceeding: youâll want to stop the Spigot Server. In the window with the flashing cursor, simply type stop at the > prompt, and the Spigot Server will save everything and shut itself down.
Installing the Minecraft Python API
Next, youâll need the Minecraft Python API. Thereâs a Github repository here:
https://github.com/py3minepi/py3minepi
I recommend just hitting the âDownload Zipâ button there. The file will be saved to your âDownloadsâ folder. Youâll want to extract the .zip fileâs contents. Youâll end up with a folder called py3minepi-master, which we need to copy into the âDocuments/MinecraftPython/MinecraftTools/â folder.
Once the folder has been relocated to the âMinecraftToolsâ folder, we need to run a command to install it. From your terminal window (assuming your current directory is still the âMinecraftToolsâ folder), type:
sudo pip3 install ./py3minepi-master
Installing Raspberry Juice
The last piece, I believe, is the actual Raspberry Juice plugin for Spigot. You can find it on the projectâs home page:
Look for the âRecent Filesâ link on the right. As of this writing, the latest was RaspberryJuice v1.7 for 1.8.1. Follow the links, and eventually, youâll end up with a .jar file.
This file needs to be copied into the âpluginsâ folder of your Spigot Server installation. If youâre following the directions here specifically, then youâll find that folder at â/Documents/MinecraftPython/MinecraftTools/pluginsâ
Put the .jar file in that folder. Your Spigot Server will automatically find it the next time it starts up.
Time to Test!
If all has gone well, you should be ready for the âGetting to Know IDLEâ section of the setup instructions on Page 20 of the book. If youâre able to successfully run the tests there, youâve got everything set up correctly!
It was at this stage that I got that nasty error I mentioned earlier:
When I got the âconnection refusedâ error, I did a bunch of searching, but nothing seemed to fit. Ultimately, I hunted down the port number that the âminecraft.pyâ script was trying to connect to (port 4711). This didnât make any sense, because the Minecraft server software defaults to port 25565. Searching around for information about what might be running (or not running, in my case) on port 4711 was what yielded the information about the Minecraft Python API.
Thankfully, author Craig Richardson left some clues for us in the pre-packaged downloads he made available for Windows & OSX. On my Ubuntu system, I opened up the download he prepared for OSX (since OSX and Linux are more or less cousins, I figured it would be worth a shot) and found Raspberry Juice. It was perhaps the least obvious component of this whole setup.
So far, this setup has been working for me. Iâm not 100% certain that I havenât missed something, but if I have, then it doesnât appear to be affecting things so far.
I hope you find this helpful! Let me know what you run into in the comments. Iâll do my best to help!