Python coding with Minecraft on PC

1 How it works

2 Setup environment

2.1 Install python 3.6.6 using pyenv

2.2 Install Minecraft: Pi edition API Python Library (https://github.com/martinohanlon/mcpi)

$ pip install mcpi

2.3 Install Java JDK 8+

2.4 Build spigot minecraft server

  1. Download spigot BuildTools (https://hub.spigotmc.org/jenkins/job/BuildTools/)

  2. Run BuildTools.jar to build spigot server with specific Minecraft version

    $ java -jar BuildTools.jar --rev 1.13
    

You will get file: spigot-1.13.jar

2.5 Download or build RaspberryJuice

RaspberryJuice jar file can be downloaded from https://github.com/zhuowei/RaspberryJuice/tree/master/jars

Or you can build it by yourself following instruction from https://github.com/zhuowei/RaspberryJuice#build

You will get file: raspberryjuice-1.11.jar

2.6 Install Minecraft server and raspberryjuice plugin

  1. Move file spigot-1.13.jar to a empty folder for your Minecraft server and run below command line

    $ java -Xmx1024M -Xms1024M -jar spigot-1.13.jar
    

    Once server is started successfully, you can stop server for now.

  2. copy raspberryjuice-1.11.jar to /plugins

2.7 Configure Minecraft server server.properties (Optional)

Recommended:

gamemode=1  # Creative mode

reference: https://minecraft.gamepedia.com/Server.properties

3 Start coding

3.1 Start Minecraft server

$ java -Xmx1024M -Xms1024M -jar spigot-1.13.jar

3.2 Start Minecraft client

  1. Open Minecraft client

  2. Find and join local Minecraft server in Multiplayer Mode

3.3 Start python commandline and start coding

$ python

Try below code in your python commandline:

from mcpi.minecraft import Minecraft

mc = Minecraft.create()

mc.postToChat("Hello world")

You can find more examples from: https://projects.raspberrypi.org/en/projects/getting-started-with-minecraft-pi/5


© 2015-2020 tendant