Skip to content

Instantly share code, notes, and snippets.

@jtsaito
Forked from bendavis78/python-minecraft-ubuntu.md
Last active January 17, 2021 20:20
Show Gist options
  • Save jtsaito/5fcc1524925d1b8d09007011de9f5b3f to your computer and use it in GitHub Desktop.
Save jtsaito/5fcc1524925d1b8d09007011de9f5b3f to your computer and use it in GitHub Desktop.

Using Python w/ Minecraft on Ubuntu

These instructions should work on any Ubuntu-based OS, but have only been tested on GalliumOS.

Install required packages

Copy and paste the following line into a terminal and press enter to install all the dependencies (you might already have some installed):

sudo apt update
sudo apt install python-software-properties python3 python3-pip idle3 git
sudo apt install openjdk-8-jre-headless openjdk-8-jdk maven

Install minecraft

sudo add-apt-repository ppa:flexiondotorg/minecraft
sudo apt update
sudo apt install minecraft-installer

At this point, you can run the "minecraft" command to see if you can run and play the game.

Install Spigot and RaspberryJuice

Spigot is a popular minecraft server that allows modding. RaspberryJuice is a Spigot plugin that allows modding with Python.

Make note of your current minecraft version (you can check it in the game launcher) and use it for the --rev argument when building Spigot.

mkdir ~/spigot
cd ~/spigot
wget "https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar"
git config --global --unset core.autocrlf
java -jar BuildTools.jar --rev 1.12.2

This will take a while to build.

Download and build RaspberryJuice and install it into the spigot plugins dir:

git clone https://github.com/zhuowei/RaspberryJuice ~/spigot/RaspberryJuice
cd ~/spigot/RaspberryJuice
mvn package
mkdir ~/spigot/plugins
cp ~/spigot/RaspberryJuice/jars/raspberryjuice-1.11.jar ~/spigot/plugins/
echo "eula=true" > ~/spigot/eula.txt

Create the following startup shell script in ~/spigot/start.sh

#!/bin/sh
java -Xms512M -Xmx1024M -jar /home/spigot/spigot-1.12.2.jar

Make sure to use the latest version jar of RaspberryJuice from RaspberryJuice/jars/ or else the lib won't work with the plugin.

Install the py3minepi library

Install the latest version of py3minepi from github:

sudo pip3 install git+https://github.com/py3minepi/py3minepi/

Test everything out

  1. Start your spigot server in a terminal window: ~/spigot/start.sh
  2. Start the minecraft launcher, log in, and press Play.
  3. Select "Multiplayer"
  4. Select "Direct Connect"
  5. Type in "localhost" and Select "Join Server"

Then, run idle3 (python shell) and test out a simple "Hello World" message:

>>> from mcpi.minecraft import Minecraft
>>> mc = Minecraft.create()
>>> mc.postToChat('Hello World!')

Quickly switch back to your game, and you should see "Hello World!" pop up in a chat message.

Notes

The spigot server will create a server.properties once started. In that document set online-mode=false as pointed out by a comment on the orignal guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment