tekichan / minecraft-py-docker

Build a docker image with Minecraft Server which supports Python coding

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Minecraft Python Docker

License

This is a repository to instruct how to build a docker image with Minecraft Server which supports Python coding. You can utilize Docker to ease the setup of Minecraft Server for Python coding.

Minecraft Rainbow I coded in Python to create a rainbow in a world of Minecraft Java edition

Introduction

Minecraft is one of the most popular games amongst teenagers. They enjoy building their own worlds with blocks and start adventure there.

Interestingly there is a special build for Raspberry Pi called Minecraft Pi Edition. With this edition, you could code in Python to interact with your Minecraft world. Yet this edition requires you a Rasberry Pi.

Thanking RaspberryJuice plugin with Spigot Minecraft server, on the other hand, you can code in Python with your typical Minecraft Java edition.

You could follow this article to learn how to set them step by step in your computer. In addition, in order to make the whole setup portable, I will also suggest building a Docker image to contain them together.

Perquisite

  1. Purchase Minecraft Java edition account
  2. Install Minecraft and Docker in your computer.
  3. Install Python 3
  4. Install Java 8 or above if you want to run Minecraft Server without Docker
  5. In this article, the commands are for Mac OS X. They are available for Linux as well. If you use Windows, you could just do the command's result with Windows mean.

Setup Procedure

  1. Create your working folder minecraft_py and a sub-folder spigot for a Spigot server.
mkdir minecraft_py; cd minecraft_py; mkdir spigot; cd spigot
  1. Download Minecraft Server
curl https://launcher.mojang.com/v1/objects/1b557e7b033b583cd9f66746b7a9ab1ec1673ced/server.jar --output server.jar
  1. Download SPIGOT Server
curl https://cdn.getbukkit.org/spigot/spigot-1.16.5.jar --output spigot.jar
  • Create a text file eula.txt to agree to End User License Agreement. You can create it by a text editor to contain a line eula=true or run a command echo eula=true > eula.txt

  • Download properties files: log4j2.xml, server.properties and scripts startServer.sh, testLocalServer.sh from this repository to your spigot sub-folder. Ensure executable for the script files: chmod +x *.sh.

  1. Download RaspberryJuice
  • Create plugins sub-folder
mkdir plugins; cd plugins
curl https://dev.bukkit.org/projects/raspberryjuice/files/2496319/download --output raspberryjuice.jar
  1. Download MCPI module and create Python coding sub-folder
  • Go back the root of your working folder
cd ../..
  • Create a local server folder data: mkdir data

  • Execute a command to download the source: git clone https://github.com/zhuowei/RaspberryJuice.git or directly download the whole folder from RaspberryJuice's repository

  • Create a sub-folder py for our Python coding: mkdir py

  • Copy MCPI module from RaspberryJuice to py folder. You could run a command:

cp -r RaspberryJuice/src/main/resources/mcpi/api/python/modded/mcpi py/

or directly copy the whole RaspberryJuice/src/main/resources/mcpi/api/python/modded/mcpi folder to py folder.

  1. First test-run (Optional)
  • Start the Minecraft server: cd data; ../spitgot/testLocalServer.sh

  • Open Minecraft, select Multiplayers and join the localhost server

Connect in Minecraft

  • Open a new terminal, go to py folder, run the testing code: python3 rainbow.py. Then you can see the rainbow in the world as shown in the beginning of this article.

  • You could stop here if you are happy with localhost server instance and do not want to build a Docker image.

  1. Build a Docker image
  • Download Dockerfile from this repository to the root of your working folder.

  • Build a Docker image docker build -t "[your account]/[your repository]" .: e.g.

docker build -t "tekichan/minecraft-py-server" .
  • Check your Docker images: docker images
  1. Run the Docker image
  • Empty data folder if you use it with local server instance before.

  • Create a Docker volume spigot-data: docker volume create spigot-data

  • Inspect the Docker volume: docker inspect spigot-data

  • Run the Docker image: docker run --name minecraft-spigot -d -v spigot-data:/data -p 4711:4711 -p 25565:25565 -p 25575:25575 [your account]/[your repository]. e.g.

docker run --name minecraft-spigot -d -v spigot-data:/data -p 4711:4711 -p 25565:25565 -p 25575:25575 tekichan/minecraft-py-server
  1. Test-run with the Docker image
  • Open Minecraft, select Multiplayers and join the localhost server

  • Open a new terminal, go to py folder, run the testing code: python3 rainbow.py. Then you can see the rainbow in the world as shown in the beginning of this article.

  1. Clean-up (after you finish playing in Minecraft)
  • Stop the container: docker container stop minecraft-spigot
  • Remove the container: docker container rm minecraft-spigot
  • If you do not want to reserve the game setting, you could remove the volume as well: docker volume rm spigot-data and empty data folder.

References

Authors

About

Build a docker image with Minecraft Server which supports Python coding

License:MIT License


Languages

Language:Shell 55.5%Language:Dockerfile 25.9%Language:Python 18.7%