Hardware Reference
In-Depth Information
Finding Out What You
Are.Standing On
You learned in Adventure 2 that it is possible to track your player's position by reading
the coordinates with getTilePos() . These coordinates represent the x, y and z coor-
dinates in the Minecraft world where your player, Steve, is located at the moment. You
used these coordinates to sense whether Steve was standing on a magic doormat or,
using geo-fencing, whether he was standing in a field.
However, unless your programs maintain a detailed map of exactly where every block
is in the Minecraft world, just sensing by position is not going to be flexible enough for
you, as your programs become more sophisticated. You could always keep a detailed
map of your own—but why go to all that trouble when Minecraft must already have
that information in the computer's memory to display the 3D world on the screen?
Fortunately, the Minecraft API also includes a getBlock() function. This function
gives you full access to the in-memory world map of Minecraft and, by using coordi-
nates, you can use it to tell you about every block—not just the block where Steve is
located but every block at every position in the Minecraft world.
You also saw in Adventure 3 that it is possible, through block types, to change any block
in the Minecraft world. Fortunately, setBlock() and getBlock() work together as
a pair, so if you use setBlock() with a block id, and then use getBlock() immedi-
ately after that, you get the same block id back.
Soon you are going to build another exciting game inside Minecraft, but your pro-
gram will be quite big. The best way to build a big program is to build little programs
and then stick them all together once you know they work. Let's start by bringing this
idea to life with a simple program that tells you if your player is standing on some-
thing safe or not.
Finding out.if Your Feet
Are.on.the.Ground
Start up Minecraft, IDLE, and if you are working on a PC or a Mac, start up the server
too. You should have had a bit of practice with starting everything up by now, but refer
back to Adventure 1 if you need any reminders. You are now going to build a program
that gives you important information about your player's exact location. You need to
find out if his feet are on the ground before you can build your magic bridge into
the sky.
1. Create a new window by clicking File New File. Save your new program as
safeFeet.py . Remember to store your programs inside the MyAdventures
folder, otherwise they will not work.
 
Search WWH ::




Custom Search