- Saved searches
- Use saved searches to filter your results more quickly
- sjlawson/mc_python_spigot_linux
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
- python-minecraft
- Introductions and Python Code examples for kids to learn python programming with minecraft. The Python code will run with a modified MCPI (Pi edition API Python Library) call `mcpi-e`, and a mincraft server call spigot with the RaspberryJuice plugin installed.
- Python programming with minecraft
- 0 Pre-Request
- 0.1 Install Minecraft Java edition
- 0.2 Setup mincraft server
- 0.3 Install Python
- 0.4 Install mcpi Python module
- Window
- Linux / MacOS
- 0.5 Install a Python Editor
- 1. Get Start Python with Minecraft
- 1.1 Connect to the Minecraft server and get your position
- 1.2. Frequently used mcpi commands
- 1.2.1 Find your location
- 1.2.2 Teleport
- 1.2.3 Set block
- 1.2.4 Get block
- 2 Learn Python With Minecraft
- To use the code examples in this site, please make sure include the piece of code below before the sample codes
- 2.1 Understand the coordinates of minecraft
- Click to view your Mincraft-Python Missions-1
- 2.2 Use for Loop to stack blocks
- Click to view your Coding Missions -2
- 2.3 Value Type: String , Number
- Click to view your Coding Missions -3
- 2.4 Use Condition if . else
- Click to view your Coding Missions -4
- 3 More Code Samples
- 3.1 Dropping the flowers when you move
- 3.2 Build a rainbow in the minecraft
- Installing Minecraft¶
- Minecraft¶
- Python 3 Distribution¶
- Java¶
- Minecraft Python API and Minecraft Spigot server¶
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
instructions for getting Spigot Minecraft server on Linux with py3minepi as done in Craig Richardson’s «Learn to Program with Minecraft»
sjlawson/mc_python_spigot_linux
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
Setting up minecraft for most recent version with Spigot and python api
Python3.6 or newer with venv module Java 8 (JRE and JDK — openjdk is great)
Build for specific version of MC: java -jar BuildTools.jar —rev 1.14.4
Run server: java -Xms512M -Xmx1024M -XX:MaxPermSize=128M -jar spigot-1.14.4.jar
(you may be required to accept the EULA by editing the text file it tells you about)
After the server has run successfuly, enter a stop command
This package is needed to setup the correct API routes for python Install maven:
Build the raspberry juice package:
git clone https://github.com/zhuowei/RaspberryJuice cd RaspberryJuice mvn package
Copy the produced file to the Spigot plugins directory: cp target/raspberryjuice-1.11.jar ~/mc_python/plugins/
Setup Python virtual environment and get py3minepi
- Create a working directory for your python files
- Get Mac minecraft tools (they say for Mac, but all you need is the python package): https://sourceforge.net/projects/program-with-minecraft-mac/
- Extract the download and copy the folder, py3minepi-master to your working directory
- in your working directory, create a python virtualenv with: python3.7 -m venv py
- activate the virtualenv: source py/bin/activate
- install the py3minepi package: pip install ./py3minepi-master
- start the server: (you may need to fill in a full path for spigot-n.nn.n.jar) java -Xms512M -Xmx1024M -XX:MaxPermSize=128M -jar spigot-1.14.4.jar
- start minecraft and login to the localhost minecraft server
- get somewhere in the game where you wont immediately die.
- alt-tab out to the terminal
- With the python virtual environment activated source py/bin/activate start a python console session by simply typing python
- Import and enter a test command:
>>> from mcpi.minecraft import Minecraft >>> mc = Minecraft.create() >>> mc.player.getTilePos() Vec3(117,2,-63)
It’s important to note that this vector is not your absolute position in the world, but your position relative to your spawn point.
About
instructions for getting Spigot Minecraft server on Linux with py3minepi as done in Craig Richardson’s «Learn to Program with Minecraft»
python-minecraft
Introductions and Python Code examples for kids to learn python programming with minecraft. The Python code will run with a modified MCPI (Pi edition API Python Library) call `mcpi-e`, and a mincraft server call spigot with the RaspberryJuice plugin installed.
Python programming with minecraft
Our goal is to learn programming while having fun in Minecraft
0 Pre-Request
0.1 Install Minecraft Java edition
Go to minecraft website download the Java Edition
0.2 Setup mincraft server
0.3 Install Python
Go to Python download page, download and install Python 3.8 and up
0.4 Install mcpi Python module
Window
input below script in the command line. (from start, search “cmd”)
Linux / MacOS
0.5 Install a Python Editor
- Python IDLE
- IDLD is commine with Python, Open it by in Start->Search, Input “IDLE”
- For how to use IDLE
- PyCharm Edu is a python editor help you learn Python
- Click to download pyCharm Edu
- VsCode is a editor for many different programming langurage.
- Click to download VsCode
- How to install VsCode for python
1. Get Start Python with Minecraft
1.1 Connect to the Minecraft server and get your position
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 faverate python editor to open the sample1.py file. When you install python, it come with a python editor call IDLE.j
1.2. Frequently used mcpi commands
1.2.1 Find your location
1.2.2 Teleport
move player to north 100 block
x,y,z = pos = mc.player.getTilePos() mc.player.setTilePos(x,y+100,z)
1.2.3 Set block
set the a stone block beside the player
x,y,z = pos = mc.player.getTilePos() mc.setBlock(x+1, y, z, 1)
setblock with constants block.STONE.id
#setblock with constants block.STONE.id from mcpi_e import block (x,y,z) = pos = mc.player.getTilePos() mc.setBlock(x+1, y, z+1, block.STONE.id)
set special block which extra properties
# set special block which extra properties flower = 38 flowerColor = 3 mc.setBlock(x+1, y, z+1, flower, flowerColor)
1.2.4 Get block
get the block type id of the player stepping on
# get the block current player step on x, y, z = mc.player.getTilePos() blockId= mc.getBlock(x, y, z) if(blockId == 0): print("current block is Air")
2 Learn Python With Minecraft
To use the code examples in this site, please make sure include the piece of code below before the sample codes
import mcpi_e.minecraft as minecraft import mcpi_e.block as block from math import * address="127.0.0.1" # change to address of your minecraft server name ="change you your name" mc = minecraft.Minecraft.create(address,4711,name) pos=mc.player.getTilePos() #your other code below .
2.1 Understand the coordinates of minecraft
Minecraft coordinates are different than what we learn from geomestry. You need keep the picture below in mind when you do the minecraft coding.
For basic python syntax, pleas check Python syntax for details.
The missions/codes below will use print and command from minecraft api mcpi
Click to view your Mincraft-Python Missions-1
2.2 Use for Loop to stack blocks
for loops are traditionally used when you have a block of code which you wnat to repeat number of times.
for x in range(0, 3): print("We're on time %d" % (x))
For learnning how to use for loop, please visit Python For Loops
Below mission only need using for . range loop.
Click to view your Coding Missions -2
2.3 Value Type: String , Number
In Python any amount of text call a string , you could use string like this
print("Hello Minecraft") name ="Steve the Miner" print(name)
String and Intiger is different DataType, for detail please read Python Data Types. Below is the Data Types we possible will used in our class
example of get type of a variable:
The data you got form input is a string, we need convert to number before using as number. int(str) could do this job.
blockType=input("Enter a block type:") blockTypeId=int(blockType)
other way if you want change a int to string, you could use str(number)
value=103 print("Watermelon block id is "+str(value))
Click to view your Coding Missions -3
2.4 Use Condition if . else
To learn comdition please check Python If…Else
Booleans represent one of two values: True or False
For learn more and practic Boolean, please check Python Boolean
Click to view your Coding Missions -4
3 More Code Samples
3.1 Dropping the flowers when you move
Set a random flower on where the play is standing
flower = 38 while True: x, y, z = mc.playerEn.getPos() blockId= mc.getBlock(x, y, z) print("current block:" + str(mc.getBlock(x, y, z))) if(blockId==0 or blockId ==78): mc.setBlock(x, y, z, flower,randrange(8)) sleep(0.2)
3.2 Build a rainbow in the minecraft
code example: rainbow.py build a rainbow with colored wool on the player’s location
import mcpi_e.minecraft as minecraft import mcpi_e.block as block from math import * address="127.0.0.1" # change to your minecraft server name ="change you your name" mc = minecraft.Minecraft.create(address,4711,name) playerPos=mc.player.getTilePos() colors = [14, 1, 4, 5, 3, 11, 10] height=50 for x in range(0, 128): for colourindex in range(0, len(colors)): y = playerPos.y+sin((x / 128.0) * pi) * height + colourindex mc.setBlock(playerPos.x+x - 64, int(y), playerPos.z, block.WOOL.id, colors[len(colors) - 1 - colourindex]) print("rainbow created at x:<> y:<> z:<>".format(playerPos.x,playerPos.y,playerPos.z))
python-minecraft maintained by stoneskin
Installing Minecraft¶
The software used for this course is provided as companion to the book Learn to Program with Minecraft. It is recommended that the students purchase the book.
To get things running, you will need:
- Minecraft
- Python 3
- Java
- Minecraft Python API
- The Minecraft server
Minecraft¶
Visit the Minecraft homepage to download. If you do not have an account, please email me and I will make sure you are provided with one.
Python 3 Distribution¶
Python 3 is the distribution we will be using. If you have Python 2, it is recommended that you uninstall Python 2 and install Python 3. If you don’t, there will be some inconsitencies that could be devestatingly confusing. Also, Python 3 has a lot of really cool, new features that aren’t in Python 2.
There are several ways to get Python. I personally recommend the Anaconda distribution. It has a bunch of things packaged with it above and beyond Python that make it useful. Anaconda comes with the Spyder editor. It is a decent editor, but I would recommend:
- PyCharm.
- If you download PyCharm, make sure you download the Community Edition.
- This is my personal favorite. It is lightweight and has many extensions.
- However, it does not run or debug Python files as easily as PyCharm.
- Very similar to Sublime
Java¶
You should have both Minecraft and Python installed at this point. You need to set Java up in order to run the server.
- Click the Start Menu (or press the Windows key)
- Type “cmd” to find the program called cmd. Open this.
- Type java -version at the prompt
- If you see an output describing the version of Java, you already have it and can continue to the next section.
- If you don’t, or it can’t find java, then go to here: http://www.java.com/en/download/
- Click Free Java Download. Then click Agree and Start
- When it is finished downloading, install this.
- IMPORTANT: If it asks you to install extra things or set Yahoo! as your homepage, click no.
Minecraft Python API and Minecraft Spigot server¶
An API is an interface. We will use it as a library that lets us communicate with the Minecraft server. We will not be able to edit the server in any way, but instead, just tell it instructions.
We will be using the Spigot server because it allows for the API to talk to it. Standard Minecraft does not.
- Go to https://www.nostarch.com/pythonwithminecraft/
- Download the MinecraftTools.zip for your operating system.
- When it has finished downloading, you can open it.
- a zip file is known as a compressed file
- it allows you to compress a set of files to make them smaller for downloading
- all operating systems let you open these files
- Important Although it looks like you have a folder, the contents of the Zip file are not a folder
- Create a folder somewhere convenient and name it MinecraftTools.
- Inside the Zip file, you can click “Extract all” or similar button.
- Extract it to your MinecraftTools folder.
- Go to the folder and double click the Install_API file.
- Now, you can run the server.
- There is a file called Start_Server. Running this will start the server.
- If you have any trouble, email me.
© Copyright 2016, Brian McMahan. Revision 94fef083 .
Versions latest Downloads pdf htmlzip epub On Read the Docs Project Home Builds Free document hosting provided by Read the Docs.