Hardware Reference
In-Depth Information
Using the Minecraft: Pi Edition Application
Programming Interface
Now that you have created your Minecraft world, you can explore, fight creepers, create
your own castle, and whatever else your mind can think of. The Raspberry Pi Edition in-
cludes something extra—a programming interface. You can use the Python programming
language to hook into Minecraft and edit the game world with lines of code.
To use the Minecraft API, perform the following actions:
1. Start the Python interactive shell by running python on the terminal.
2. You will see >>> , which is where you will enter the Python commands.
3. Enter the following commands:
from mcpi import minecraft
from mcpi import block
mc = minecraft.Minecraft.create()
mc.postToChat("I am using the API!")
4. You should now see I am using the API message appear in your Minecraft
window.
5. Enter the following commands:
player = mc.player.getPos()
player
6. An output similar to Vec3(46.0,1.0,-14.0) should appear.
7. Enter the next command:
mc.setBlock(player.x +1, player.y, player.z,
block.GOLD_BLOCK)
8. A golden block should appear directly in front of you:
Search WWH ::




Custom Search