Hardware Reference
In-Depth Information
Because setBlocks() works on a 3D area, it needs two sets of coordinates—the
coordinates of one corner of the 3D rectangle, and the coordinates of the opposite
corner. Because each 3D coordinate has three numbers, you need six numbers to com-
pletely describe a 3D space to Minecraft.
You are now going to write a useful little utility program that you can use any time you
want to clear a bit of space in front of you to do some building:
1. Start a new program by choosing File New File from the menu.
2. Save the program using File Save As and choose the name clearSpace.py .
3. Import the modules that you need:
import mcpi.minecraft as minecraft
import mcpi.block as block
4. Connect to the Minecraft game:
mc = minecraft.Minecraft.create()
5. You want to clear space in front of the player, and you will be using relative coor-
dinates to do this. First get the player's position:
pos = mc.player.getTilePos()
6. Now clear a space that is 50 by 50 by 50 blocks. The bottom left corner of your
space will be the position of your player, and the top right corner will be 50
blocks away in the x, y and z dimensions:
mc.setBlocks(pos.x, pos.y, pos.z, pos.x+50, pos.y+50, pos.
z+50, block.AIR.id)
7. Save your program.
The fantastic thing about the program you've just created is that it allows you to walk
to any location inside Minecraft and clear a 50 by 50 by 50 area any time you like; just
run the program by choosing Run Run Module from the menu, and the trees and
mountains and everything nearby will magically vanish before your eyes!
Move around the Minecraft world and re-run your program to clear lots of space in
front of your player.
Reading Input from.the Keyboard
Another useful thing you can do to your clearSpace.py program is to make it easy
to change the size of the space that is cleared. That way, if you are only going to build a
small structure, you can clear a small space but if you know you are going to build lots
of big structures, you can clear a huge space first.
To do this, you will use a new Python statement called raw_input() to read a num-
ber from the keyboard first. You can then go to any part of the Minecraft world, run
 
 
Search WWH ::




Custom Search