Skip to content

Instantly share code, notes, and snippets.

@noahcoad
Last active March 2, 2024 22:02
Show Gist options
  • Save noahcoad/fc9d3984a5d4d61648269c0a9477c622 to your computer and use it in GitHub Desktop.
Save noahcoad/fc9d3984a5d4d61648269c0a9477c622 to your computer and use it in GitHub Desktop.
Code Minecraft with Python on Mac OSX

Code Minecraft with Python on Mac OSX

Here's a step-by-step to get started scripting Minecraft with Python on Mac OSX

Overview

There was a special build of Minecraft for the Raspberry Pi called Minecraft Pi that had a Python interface and library. You could code in Python to manipulate your Minecraft world! But you'd have to code on a Raspberry Pi computer. However thanks to using the RaspberryJuice plugin with a Spigot server, you can do this locally on a Mac. Probably in Linux or Windows too, but I'll leave that up to you.

Here we have a rainbow created by the rainbox script. rainbow

Step-by-step

# guide for Minecraft v1.13.1 server
# update minecraft server and spigot links for latest versions
 
# get started
mkdir minecraft_py; cd minecraft_py; mkdir spigot; cd spigot
 
# download minecraft server from https://minecraft.net/en-us/download/server/
wget https://launcher.mojang.com/v1/objects/fe123682e9cb30031eae351764f653500b7396c9/server.jar
 
# download spigot server from https://getbukkit.org/download/spigot
wget -O spigot.jar https://cdn.getbukkit.org/spigot/spigot-1.13.1.jar
 
# agree to eula
echo eula=true > eula.txt
 
# get RaspberryJuice from https://dev.bukkit.org/projects/raspberryjuice
mkdir plugins; cd plugins
wget -O raspberryjuice-1.11.jar https://dev.bukkit.org/projects/raspberryjuice/files/2496319/download
 
# get the mcpi libraries from https://github.com/zhuowei/RaspberryJuice
cd ../..
git clone https://github.com/zhuowei/RaspberryJuice.git
mkdir py
cp -r RaspberryJuice/src/main/resources/mcpi/api/python/modded/mcpi py/
 
# download an example python script from https://www.dropbox.com/s/k29ms42nzvgehjk/rainbow.py?dl=0
# alternatively see example here https://dev.bukkit.org/projects/raspberryjuice
cd py
wget -O rainbow.py https://www.dropbox.com/s/k29ms42nzvgehjk/rainbow.py\?dl\=1
 
# run spigot
cd ../spigot; java -jar spigot.jar
 
# in a new terminal under the minecraft_py/py folder
python2 rainbow.py

You're Running!

Start minecraft making sure the version matches (1.13.1 in this case), go into multiplayer mode, add a server with address: localhost

Connect, look around you, and you'll see the rainbow!

Want a first challenge? try making the rainbow thicker =)

Also

@webknjaz
Copy link

webknjaz commented Mar 5, 2021

socket.error: [Errno 61] Connection refused

Looks like you don't have Minecraft running. Start it first before attempting to connect to it...

@Janik-ux
Copy link

@voronkovventures @MarcinAtNovela

https://dev.bukkit.org/projects/raspberryjuice/files/2496319/download
Resolving dev.bukkit.org (dev.bukkit.org)... 104.19.146.132, 104.19.147.132
Connecting to dev.bukkit.org (dev.bukkit.org)|104.19.146.132|:443... connected.
HTTP request sent, awaiting response... 403 Forbidden
2020-01-14 15:11:39 ERROR 403: Forbidden.

Please help!

I had the same problem and a test with curl discovered, that cloudflare asks to solve a captcha because it thinks you are a bot. Not sure if this was also your error. It works to download the file manually from https://dev.bukkit.org/projects/raspberryjuice/files/2496319 and place it into the plugins folder.
Unfortunately I don't know a method to bypass this barrier, but I hope it helps someone who also gets stuck at this point!

Thank you very much for this tutorial @noahcoad it helped me as a minecraft plugin beginner!

@redsnapper73
Copy link

redsnapper73 commented Jan 7, 2022

I could find a solution by installing JDK over homebrew (other JDK should work fine as well probably):

brew install java
sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdkMBP 2015, MacOS 11.6.2

Hi, thank you for this good walkthrough, though, I have troubles starting the server:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/bukkit/craftbukkit/bootstrap/Main has been compiled by a more recent version of the Java Runtime (class file version 60.0), this version of the Java Runtime only recognizes class file versions up to 52.0

I have the most recent version of java installed:
java version "1.8.0_311"
Java(TM) SE Runtime Environment (build 1.8.0_311-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.311-b11, mixed mode)

Can somebody help me please?
Thank you, Andreas

@redsnapper73
Copy link

When I tried to do the first teleportations I stumbled about a mismatch in the coordinates between the ones shown in the Minecraft window and the ones entered in Python script (mc.setPos(x,y,z)). Just enter 'setworldspawn 0 0 0' in the server console, then everything works fine!

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