This task will describe how to:
You will need:
For installing and running Minecraft, perform the following steps:
startx
.LXTerminal
.wget
https://s3.amazonaws.com/assets.minecraft.net/pi/minecraft-pi-0.1.1.tar.gz into the terminal and pressing Enter.tar zxfv minecraft-pi-0.1.1.tar.gz
.cd mcpi
../minecraft-pi
.For creating a new Minecraft world, perform the following steps:
For using the Minecraft Pi Edition Application Programming Interface (API), perform the following steps:
mcpi
folder.cd api/python/mcpi /
.python
on the terminal.>>>
, which is where you will enter Python commands.import minecraft
import block
mc = minecraft.Minecraft.create()
mc.postToChat("I am using the API!")
I am using the API
message appear in your Minecraft window.player = mc.player.getPos()
player
Vec3(46.0,1.0,-14.0)
should appear.mc.setBlock(player.x +1, player.y, player.z, block.GOLD_BLOCK)
.Minecraft is a sandbox game from Studio Mojang. The goal of the game is to create, survive, and have fun. The game is only finished when you say so. The Raspberry Pi version of Minecraft is built on the Pocket Edition engine, which was used to power the Android and iOS version. Because of this, the Raspberry Pi edition can sometimes connect to worlds hosted by cell phones and tablets.
The controls are:
The biggest change that comes with the Raspberry Pi edition is the inclusion of an API. The API allows you to connect to your world with various programming languages, and modify the environment through various commands.
The first step needed to begin using the API is to go into the directory where the Python API files are stored. If you want to make your own programs, you would copy these files to your own project. When you run Python, you are brought into the interactive shell. The import
command loads the file, otherwise known as a module, into memory and makes its functions available for you to use. Next, load the minecraft
and block
modules that will allow you to connect to your running Minecraft game and manipulate the blocks.
Running mc = minecraft.Minecraft.create()
forms the connection to your Minecraft game and keeps the connection in the variable mc
. When you want to send a command to your game, you will make use of the mc
variable, because it's storing all the needed information. The postToChat()
function sends a line of text to your game's screen. player.getPos()
gets the current X, Y, and Z coordinates of your character in the game. We then store that into the variable player
. By typing the variable name into the shell, we can see the current value that it is been stored. In this case, it shows the saved coordinates.
Now that you have the player's coordinates, you can manipulate the world around it. By running mc.setBlock(1,1,1, block.GOLD_BLOCK)
, a gold block will appear at the coordinates of (1, 1, 1). But let's say you wanted that gold block to appear right in front of your character. You can use the player
variable, set earlier, to retrieve its coordinates. By entering mc.setBlock(player.x +1, player.y, player.z, block.GOLD_BLOCK)
in the command line, you are telling the game to place that gold block at the spot in front of the character. If you didn't add 1
to player.x
, the block would end up in the exact same spot you were in, so move it forward by one to avoid that.
The previous code only scratches the surface of what is available in the API.
A few useful reference links:
18.116.28.22