TeachCraft Lesson 3

Blocks, Lava, and a Bird's Eye View

The next minecraft api function we are going to look at is mc.setBlock(x, y, z, block_id). X/Y/Z are the coordinates of the block you want to set, and block_id is the number representing the block (you can see all the numbers here).

In the example code on the right, we are getting the player's current position, setting a dirt block 50 units above their head, and then teleporting the player onto the dirt block.

This gives us a bird's eye view of the map, and can teleport us to safety rapidly if need be! Try it out!

Sample Code

from mcpi import minecraft
mc = minecraft.Minecraft.create(address="127.0.0.1", name="steve")

pos = mc.player.getTilePos()

dirt_block_id = 3
mc.setBlock(pos.x, pos.y+50, pos.z, dirt_block_id)

mc.player.setTilePos(pos.x, pos.y+51, pos.z)


Let's setup our next challenge.

Run the code on the right to spawn a lava pool 10 blocks away from your user.

Sample Code

from mcpi import minecraft
mc = minecraft.Minecraft.create(address="127.0.0.1", name="steve")

pos = mc.player.getPos()
lava_block_id = 10
mc.setBlock(pos.x+10, pos.y+1, pos.z, lava_block_id)


Your Challenge: Walk in the lava without dying!

When you walk into lava, you will get set on fire. To avoid your character dying, you must find water to put out the fire...

Your Challenge: Write a script that when executed, spawns water over your head to save you from burning. To prove your script works, touch the lava to set yourself on fire, then spawn water to put out the fire.

You can get the block ID of flowing water here.