Hardware Reference
In-Depth Information
To watch a tutorial on how to build your house, visit the companion website at
www.wiley.com/go/adventuresinminecraft and choose the Adventure 3 Video.
Now that you have a design for your house, try and build it by following these steps:
1. Start a new program by choosing File New File from the menu.
2. Save this program by using File Save As from the menu, and call your program
buildHouse.py .
3. Import the required modules:
import mcpi.minecraft as minecraft
import mcpi.block as block
4. Connect to the Minecraft game:
mc = minecraft.Minecraft.create()
5. Use a constant for the size of your house. You use this SIZE constant quite a lot
in your house builder code. Using a constant here, instead of using the number
20 all over your code, will make it much easier to alter the size of your house later:
SIZE = 20
Remember that it is a programmer's convention that you put constants in upper
case. There is no rule in the Python language that says you have to do this, but it
helps you to remember that this is a constant and you intend it not to be changed
while the program is running.
6. Get the player's position so you can build the house just nearby:
pos = mc.player.getTilePos()
7. Store the x, y and z coordinates of the player in new variables. This will make the
next few program statements easier to type and read, and will help when you
come to do some other clever construction tasks with your house design later
on. The x variable will be set to two blocks away from the player position, so that
the house is not built right on top of the player:
x = pos.x+2
y = pos.y
z = pos.z
 
Search WWH ::




Custom Search