Hardware Reference
In-Depth Information
4. To communicate with a running Minecraft game, you need a connection to that
game. Type the following to connect to the Minecraft game:
mc = minecraft.Minecraft.create()
Be aware that Python is a case-sensitive language—so be careful how you
capitalise words! It's important that you type upper case and lower case letters
correctly. The second Minecraft in the statement you just typed in must start with
a capital letter for it to work properly.
5. Next, ask the Minecraft game for the position of your player by using
getTilePos() :
pos = mc.player.getTilePos()
6. Finally, tell the Minecraft game to display the coordinates of the player's posi-
tion. print() will display these coordinates on the Python Shell when your pro-
gram runs:
print(pos.x)
print(pos.y)
print(pos.z)
7. Save this file by choosing File Save, from the Editor menu.
8. Run the program by choosing Run Run Module, from the Editor menu.
You should now see the coordinates of the player's location displayed on the Python
Shell (see Figure  2-2). Later in this adventure, you'll use these coordinates to sense
where your player is standing, and build a magic doormat that welcomes your player
home when he stands on it!
FIGURE.2-2 Use getTilePos to show the player position on the Python Shell.
 
Search WWH ::




Custom Search