Hardware Reference
In-Depth Information
CHALLENGE
See if you can navigate to a new location, make a note of the coordinates and
then place some different blocks using the setBlock command. You can ind
the full list of blocks supported in Minecraft Pi in the ile block.py, which is
located in ~/mcpi/api/python/mcpi/ .
Placing Multiple Blocks
Placing one block at a time is still going to be time-consuming and not very helpful if
you want to build a bigger structure. But with the addition of one letter, you can place
more than one block at a time.
So far, with setBlock you have been using one set of coordinates to tell the game
where to place a single block. he setBlocks command (note the added s at the
end) works in much the same way as setBlock . You start with a set of x, y and z coor-
dinates that indicate where in the Minecraft world you want the blocks to be placed.
hen the second set of x, y and z coordinates represent the number of blocks needed to
make the shape you want to create:
setBlocks(x1, y1, z1, x2, y2, z2, blocktype)
For example, to generate a cube you would type:
setBlocks(0, 0, 0, 10, 10, 10, block.MELON)
he irst three numbers are the location for where the blocks should be placed. he last
three are the number of blocks. So the preceding code would place 10 MELON type
blocks on the x axis, 10 on the y axis and 10 on the z axis, forming a cube (see Figure
6-7).
However, if you try to use this script you may not be able to ind your cube of melons,
as Minecraft Pi will set the blocks from the center location ( 0, 0, 0 ) of the world.
Depending on the terrain, this could be inside a mountain!
It makes more sense to place the blocks where the player is located, so that you can
ind a nice empty spot for your cube. To do this, you need to get the player's position
using the following code:
pos = mc.player.getTilePos()
Search WWH ::




Custom Search