Hardware Reference
In-Depth Information
unsupported, but sand blocks will fall to the ground. Cacti can't be planted in grass, but can
be placed on top of sand. If you chip away at the banks of a lake, the water will low to ill the
space you made. You can't place water and lava source blocks within the game, although you
can program them using Python and they can cascade down and cover a wide area. When
they come into contact with each other, water sometimes cools lava into stone.
Preparing for Python
One of the peculiarities of Minecraft is that it takes control of your mouse, so you have to
press Tab to stop it from doing that if you want to use any other programs on your desktop.
To start using the mouse in Minecraft again, click the Minecraft window. You'll soon become
used to pressing Tab before you try to do any programming. Press Tab now to leave Minecraft
running, but bring the mouse cursor back into the desktop.
To make your Minecraft programs, you're going to use IDLE, so double-click its icon on the
desktop to start it. You might have to click the top of the Minecraft window and drag it out
of the way irst.
One of the irst things you'll notice is that Minecraft sits on top of other windows, and your
IDLE window might well be underneath it, so a certain amount of reorganisation is neces-
sary. To move a window, you click and drag the title bar at the top of it, and you click and
drag the edges or corners of a window to resize it. I recommend that you arrange your win-
dows so that you can see them all at once. On my reasonably standard size monitor, I have
room for Minecraft in the top left, a small box for the Python shell in the top right, and the
window I'm writing my program in the bottom half of the screen. I don't recommend resiz-
ing the Minecraft window: In the version I'm running, the mouse controls became unrespon-
sive when I did that. You can ignore (but not close) the LXTerminal window.
Using the Minecraft Module
You're now ready to write your irst Python program for Minecraft, which will send a mes-
sage to the chat feature in the game.
From the Python shell, click the File menu and choose New to open your programming win-
dow. Enter the following in the window, use the File menu to save it in your pi directory and
press F5 to run it. You must have a Minecraft game session running for this to work.
import sys, random
sys.path.append(“./mcpi/api/python/mcpi”)
import minecraft
mc = minecraft.Minecraft.create()
mc.postToChat(“Welcome to Minecraft Maze!”)
Search WWH ::




Custom Search