Hardware Reference
In-Depth Information
Delete the
pass
statement that is indented under the function.
2.
Indented under the
def createDiamonds(arenaPos, number):
line, cre-
ate a connection to Minecraft:
mc = minecraft.Minecraft.create()
3.
Create the number of diamonds you require by finding random x and z positions
in the arena and setting the block to a
DIAMOND_BLOCK
:
for diamond in range(0, number):
x = random.randint(arenaPos.x, arenaPos.x + ARENAX)
z = random.randint(arenaPos.z, arenaPos.z + ARENAZ)
mc.setBlock(x, arenaPos.y + 1, z,
block.DIAMOND_BLOCK.id)
4.
he
createDiamonds()
function now needs to be called at the start of the
game
loop; every time a new level starts, a new set of diamonds is created. Indented
under the
game
loop, directly under the
while
loop, add the following code:
#game loop
while not gameOver:
createDiamonds(arenaPos, DIAMONDS[level])
diamondsLeft = DIAMONDS[level]
The variable
diamondsLeft
is also created; this will hold the number of dia-
monds remaining for the player to collect.
5.
Run the program. Because you are on the first level, you should see three dia-
monds created at random locations in the arena.
After you have created the diamonds, you can add the code to monitor the player's hit
events using the
pollBlockHits
function (which you learned in Adventure 4) and,
when if the player hits a
DIAMOND
block, turn it to
AIR
.
Add the following code under the
level
loop to turn the
DIAMOND_BLOCK
to
AIR
if
the player hits it:
1.
Indented under the
level
loop, call the
pollBlockHits
function to get any
block hit events:
#level loop
while not gameOver and not levelComplete:
hits = mc.events.pollBlockHits()
2.
Loop through the block hit events and get the type of block that was hit:
for hit in hits:
blockHitType = mc.getBlock(hit.pos.x, hit.pos.y,
hit.pos.z)