Hardware Reference
In-Depth Information
Your First Minecraft Pi Python
Program
Now that you have installed Minecraft Pi for the Raspberry Pi, it's time to see what
adventures you can have with code in the Minecraft world. In this project, you will run
a Minecraft game and write a Python script from the command line in LXTerminal to
test that your connection to the game works. You'll do this by displaying a message in
the game.
To see a tutorial for this part of the Minecraft Pi Python program, visit the
companion website at www.wiley.com/go/adventuresinrp . Click the
Videos tab and select the FirstMinecraftPi ile.
1. Begin by opening LXTerminal and running Minecraft Pi—if it is not already
open—by typing the following lines:
cd mcpi
./minecraft-pi
2. When Minecraft Pi has loaded, click on Start Game and select a world from the
list that is displayed. (If you have not yet created any worlds, click Create New to
enter build mode, as instructed earlier.)
3. Navigate back to the LXTerminal window with your mouse, and open a new tab
by clicking File New Tab. You need an open tab so that you can type com-
mands into LXTerminal while Minecraft Pi is running.
4. To make sure that you are in the right folder or directory to begin writing your
code, type this command in your new LXTerminal tab window:
cd api/python
5. To create your irst Minecraft Pi program, open the nano text editor by typing
this command:
nano testmcpi.py
his will open a text editor from the command line.
6. Type the following code into the nano text editor ile:
import mcpi.minecraft as minecraft
As in previous Python programs you have created, here you are importing a mod-
ule that you will need in your program—in this case, the minecraft module.
Now type the following command (being sure to use the correct capitalization):
mc = minecraft.Minecraft.create()
Search WWH ::




Custom Search