- Saved searches
- Use saved searches to filter your results more quickly
- License
- stoneskin/python-minecraft
- 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
- Controlling Minecraft from Python¶
- Minecraft Programming Reference¶
- World¶
- Player¶
- Blocks¶
- Saved searches
- Use saved searches to filter your results more quickly
- License
- martinohanlon/mcpi
- 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
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.
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.
License
stoneskin/python-minecraft
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
Python programming with minecraft
Our goal is to learn programming while having fun in Minecraft
0.1 Install Minecraft Java edition
Go to minecraft website download the Java Edition
Go to Python download page, download and install Python 3.8 and up
0.4 Install mcpi Python module
input below script in the command line. (from start, search «cmd»)
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
move player to north 100 block
x,y,z = pos = mc.player.getTilePos() mc.player.setTilePos(x,y+100,z)
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)
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 .
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
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.
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))
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
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))
About
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.
Controlling Minecraft from Python¶
Most coordinates are in the form of a three integer vector (x,y,z) which address a specific tile in the game world. (0,0,0) is the spawn point sea level. (X,Z) is the ground plane, and Y is towards the sky. In other words, X is left and right, Z is forward and backward, and Y is up and down.
Minecraft’s odd x-y-z coordinate system
Minecraft Programming Reference¶
These are just a few highlights. A more detailed reference can be found in the full API reference.
World¶
Look up the type of block at the specified coordinates.
Set the block at the specified coordinates to the type block_type.
Create a set of blocks starting at one coordinate point extending to another point with blocks of the type block_type. This can be used to make cubes or rectangles.
Look up the height (y coordinate) of the tallest brick at the specified x and y coordinates.
world. postToChat ( «Message» ) ¶
Player¶
Look up the coordinates that the player is currently positioned at.
Set the player’s position to the specified coordinates.
Blocks¶
As is the case in most things related to programming, the mcpi/block.py source code file is the ultimate authority for which blocks are available for your use. The table below lists those constants and includes a few notes about some of the blocks.
Block Name Notes AIR STONE GRASS DIRT COBBLESTONE WOOD_PLANKS Use block_data to control what kind of planks. SAPLING BEDROCK WATER_FLOWING WATER An alias for WATER_FLOWING WATER_STATIONARY LAVA_FLOWING LAVA An alias for LAVA_FLOWING LAVA_STATIONARY SAND GRAVEL GOLD_ORE IRON_ORE COAL_ORE WOOD Use block_data to control what kind of wood. LEAVES GLASS LAPIS_LAZULI_ORE LAPIS_LAZULI_BLOCK SANDSTONE BED COBWEB GRASS_TALL WOOL Use block_data to control what color wool. FLOWER_YELLOW FLOWER_CYAN MUSHROOM_BROWN MUSHROOM_RED GOLD_BLOCK IRON_BLOCK STONE_SLAB_DOUBLE STONE_SLAB BRICK_BLOCK TNT BOOKSHELF MOSS_STONE OBSIDIAN TORCH FIRE STAIRS_WOOD CHEST DIAMOND_ORE DIAMOND_BLOCK CRAFTING_TABLE FARMLAND FURNACE_INACTIVE FURNACE_ACTIVE DOOR_WOOD LADDER RAIL STAIRS_COBBLESTONE DOOR_IRON REDSTONE_ORE SNOW ICE SNOW_BLOCK CACTUS CLAY SUGAR_CANE FENCE GLOWSTONE_BLOCK BEDROCK_INVISIBLE STONE_BRICK GLASS_PANE MELON FENCE_GATE GLOWING_OBSIDIAN NETHER_REACTOR_CORE The underlying engine actually provides all of these block types. If you see one is missing from the MCPI block module, you are free to edit mcpi/block.py to add more blocks using the decimal value listed and following the pattern you find in the existing code.
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.
Minecraft: Pi Edition API Python Library
License
martinohanlon/mcpi
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
Minecraft: Pi edition API Python Library
mcpi Python library for communicating with Minecraft: Pi edition and RaspberryJuice.
The Minecraft: Pi edition Python library was originally created by Mojang and released with Minecraft: Pi edition.
Initial supported was provided for Python 2 only, but during a sprint at PyconUK 2014 it was migrated to Python 3 and py3minepi was created.
The ability to hack Minecraft from Python was very popular and the RaspberryJuice plugin was created for Minecraft Java edition. RaspberryJuice also extended the API adding additional features.
This python library supports Python 2 & 3 and Minecraft: Pi edition and RaspberryJuice.
Documentation for the Minecraft: Pi edition and RaspberryJuice API’s can be found at www.stuffaboutcode.com/p/minecraft-api-reference.html.
It was released onto PyPI in May 2018.
If you want some cool additional tools for modifying Minecraft, check out minecraft-stuff.
This library is a collection of the following sources: