TeachCraft Lesson 4

Blocks, Buildings, and Shields

The next minecraft api function we are going to look at is mc.setBlocks(x, y, z, x2, y2, z2, block_id).

The two sets of x/y/z variables specify opposite corners of the building you wish to construct (e.g. the bottom right front and the top left back).

Choose an interesting block ID to use for a building from here), and then try running the script on the right to create a building. Glass (block ID 20) is a great choice because it's see-through!

Try experimenting with the size of the building by changing how much you add to the second set of coordinates. Please be respectful though, if you use too high of a number the server will crash and take 60 seconds to restart!

Sample Code

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

pos = mc.player.getTilePos()

glass_block_id = 20
mc.setBlocks(pos.x+1, pos.y, pos.z+1, pos.x+6, pos.y+10, pos.z+8, glass_block_id)



You may have noticed the above building was solid! Let's make it hollow!

To make a building hollow, make a smaller building out of air blocks inside your main building. Try running the code on the right. You'll notice that the smaller air building's coordinates are different than the main building - the first set is 1 unit higher, the second is 1 unit lower.

Sample Code

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

pos = mc.player.getTilePos()

glass_block_id = 20
mc.setBlocks(pos.x+1, pos.y, pos.z+1, pos.x+6, pos.y+10, pos.z+8, glass_block_id)

air_block_id = 0
mc.setBlocks(pos.x+2, pos.y+1, pos.z+2, pos.x+5, pos.y+9, pos.z+7, air_block_id)



A building can be used as a shield! Up to this point, we've been creating buildings to the side of our character...

Your Challenge: Write a script that when executed, spawns a hollow glass building around your character. The block ID for Glass is 20.

Hint: To do this, you'll need to use substraction on one set of coordinates (up to this point, we've only used addition).