Hardware Reference
In-Depth Information
CHALLENGE
Change the range() inside the for loop to create a tower that is even taller.
How tall a tower can you create before you can no longer see the top of it?
Clearing Some Space
Sometimes, finding enough space in the Minecraft world to build your structures can be
a bit frustrating. There are usually a lot of trees and mountains around your player, mean-
ing there is often not enough space to build big structures. You can solve this problem by
writing a program that clears some space for you to build whatever you want.
Using setBlocks to.Build Even Faster
All the blocks in the Minecraft world have a block identity (id) number, and this
includes the blank spaces that you see in front of you, called block.AIR.id . So, if
you make sure every block in a large area is set to block.AIR.id , it will clear a nice
space ready for building other objects. The id number (which is the block type number
discussed earlier) is listed in Appendix B for the most common blocks you will use. For
example, block.AIR.id is 0 and block.STONE.id is 1. Remember, the empty
space you see in the Minecraft world is really just a block with a block id of block.
AIR.id —it is a 1 metre cube space filled with air!
Computers are very fast, but the more program statements you use inside a for
loop, the slower the program will run. It takes a little while for the Minecraft game
to interpret your request to set a block inside the world, change the block type,
and update the display on the screen. You could always write a big loop that sets
hundreds of blocks in front of you to block.AIR.id to clear some space, and
that would work, but it would be really slow. Fortunately there is a better way to
set a lot of blocks in one go, and it is called setBlocks(). (Note the extra s
at the end of the name.) setBlock() sets one block, setBlocks() sets a
whole 3D area of blocks in one go!
The Minecraft programming interface has a setBlocks() statement that you can use
to give all the blocks inside a three-dimensional (3D) rectangular space the same block
id. Because this is a single request to the Minecraft game, Minecraft can optimise how
it does this work, meaning it will run much quicker than if you used a setBlock()
inside a for loop like you did with the tower.
 
Search WWH ::




Custom Search