Hardware Reference
In-Depth Information
FIGURE.8-1 Create a Hello block friend to accompany your player on his Minecraft
adventures.
To program a block friend you need to think like her! She will be happy if she's near
your player, so she will want to follow him around and try to sit next to him. She'll stay
happy as long as your player is close to her; if your player walks off, she will walk after
him. If your player gets too far away, it will make the block friend sad and she will stop
following him until he comes back and gives her a hug (by standing next to her).
The block friend program has two distinct parts:
The rules the block uses to decide what it should do next: This part of the
program makes the block friend decide whether to move toward your player (the
target) or stay still.
The code that moves the block toward a target: Once the block friend reaches
her target, she uses the rules again to work out what to do next.
While the block friend is moving toward the target, she should be travelling “on top” of
the land, not floating in the air or burrowing under the ground! You do this by using
the function mc.getHeight(x,z) and passing it a horizontal position (x,z). It will
return the vertical position (y) of the first block down from the sky that isn't AIR .
To see a tutorial on how to create the block friend, visit the companion website at
www.wiley.com/go/adventuresinminecraft.
Search WWH ::




Custom Search