Session 1: Get Started With Python and Minecraft
Session 1.1 Setup your Python-minecraft programming Environment
1. What python could do with Minecraft game
- A different way to play Minecraft
- Let Python do the boring tasks for you
- Change the Minecraft world by put or clear blocks
- Find the location resource underground
- Build small game in the Minecraft
2. Setup Minecraft Client and Server
2.1 Install Minecraft Java edition Client
Go to minecraft website download the Java Edition
2.2 Setup Minecraft Server
- Install Minecraft Server:
- Download Java and install it. (link to download Java)
- Download the spigot minecraft server and unzip it.
- Run it by double click the “StartMineCraftServer.bat” file.
- To understand how it works
- Connect to your server
3. Install Python and mcpi-e Modules
- Install Python
- Go to Python download page, download and install Python 3.8 and up
- How to Install Python
- Install Python-Minecraft API module
mcpi-e
-
Window
input below script in the command line. (from start, search “cmd”)
- use
pip3
pip3 install mcpi-e
- or use
py
orpython -m
py -m pip install mcpi-e
- use
-
Linux / MacOS
- sudo pip3 install mcpi-e
-
-
Install a Python Editor
- Python IDLE
- PyCharm
- PyCharm Edu is a python editor help you learn Python
- Click to download pyCharm Edu
- VsCode
- VsCode is a editor for many different programming langurage.
- Click to download VsCode
- How to install VsCode for python
4. Run your first python code in Minecraft world
Create a Python project folder, Download and save the sample1.py file to your python project folder
from mcpi_e.minecraft import Minecraft
serverAddress="127.0.0.1" # change to your minecraft server
pythonApiPort=4711 #default port for RaspberryJuice plugin is 4711, it could be changed in plugins\RaspberryJuice\config.yml
playerName="stoneskin" # change to your username
mc = Minecraft.create(serverAddress,pythonApiPort,playerName)
pos = mc.player.getPos()
print("pos: x:{},y:{},z:{}".format(pos.x,pos.y,pos.z))
Use your favorite python editor to open the sample1.py file. When you install python, it come with a python editor call IDLE.