Hardware Reference
In-Depth Information
blockMood = "hadenough"
mc.postToChat("<block> That's it. I have had
enough.")
5. Run the program.
When your player gets too far away from the block friend, if you wait long enough (for
a 1 in 100 chance to come true), the block friend will decide she has had enough and
'unfriend' the player! Once that happens, the block friend will say, “That's it. I have had
enough” and will sit there forever.
CHALLENGE
Change the program again so that there is a 1 in 50 chance that if the block
friend's mood is "hadenough" she will forgive the player, if he gives her a hug.
Bigger Shapes
In the block friend program, you made one block to move around and follow the player.
But what if you wanted to make a lot of blocks move around? Or how about a shape
made out of moving blocks, like a car or an alien spaceship?
This is where things become much more difficult, because you need to keep track of lots
of blocks. Each time you wanted to make it move you would need to set all the blocks
to AIR and then recreate the blocks in their new position. If there are a lot of blocks,
the shape will stop moving properly and slow down to a crawl.
he minecraftstuff module contains functions called MinecraftShape , which
has been written specially to create shapes and move them around. It does this by
keeping track of all the blocks that make up a shape; when the shape is moved, it only
changes the blocks that have changed, not all of them.
To use MinecraftShape , you have to tell it what the shape looks like by creating a list
of blocks that make up the shape. Each of the blocks in the shape has a position
(x, y, z) and a block type.
Figure 8-4 shows a simple shape made up of seven blocks, together with the positions
of the blocks. In this case, “position” isn't the same as the position in Minecraft. You'll
see that the centre of the wooden horse is 0,0,0 and each block is relative to the centre,
so the block to the right is 1,0,0.
 
Search WWH ::




Custom Search