In the previous project, we allowed our Minecraft character to build a simple house at the touch of a button. We did no verification that the bottom of the house sat on the ground — in some cases, the house could have been built in mid-air.

In this project, we'll allow our character to construct the same house as in the previous project, but in this project, we'll place a base of blocks from the bottom of the house well down into the ground.

For this project, we just need a single button, wired to GPIO24:

First this project, we'll implement a base (or foundation) for the house if it's location is somewhere above ground level. We'll do this using the `setBlocks()` function, and we'll also take a little shortcut — we'll assume that the house is no more than 64 blocks above the ground.

To implement this, we'll need to draw a large cube below our house, and we'll need to pass the location of the two far corners of that cube to the `setBlocks()` function.

## Full Code

Here is what the code for this project should look like at this point (with new changes highlighted with arrows):

from rstem.button import Button from rstem.mcpi import minecraft, control, block from rstem.mcpi.vec3 import Vec3 import time house = [ [ '111111', '111111', '111111', '111111', '111111', '111111', ], [ '111111', '100001', '100001', '100001', '100001', '111111', ], [ '111111', '100001', '100001', '100001', '100001', '111111', ], [ '111111', '100001', '100001', '100001', '100001', '111111', ], [ '111111', '100001', '100001', '100001', '100001', '111111', ], ] block_types = [ block.AIR, block.STONE, ] def create_house(mc, house_slices, offset=Vec3(-1,0,-1), base=block.STONE): corner = mc.player.getTilePos() - offset for delta_y, house_slice in enumerate(house_slices): for delta_z, row in enumerate(house_slice): for delta_x, block_index in enumerate(row): block_type = block_types[int(block_index)] mc.setBlock(corner + Vec3(delta_x, delta_y, delta_z), block_type) * num_rows = len(house_slices[0]) * row_length = len(house_slices[0][0]) * mc.setBlocks( * (corner.x, -64, corner.z), * (corner.x + num_rows - 1, corner.y, corner.z + row_length - 1), * base) control.show() mc = minecraft.Minecraft.create() button = Button(24) while True: if button.presses(): create_house(mc, house) time.sleep(0.01)

Give it a try. Remember, the house is only being constructed at a small offset from our character, so you may need to move forward and turn around to see what you built.

1. Assuming you still have your controller wired up, add this house making code to the Minecraft controller code ( project) so that you can build a house while using the CREATOR Kit as a controller.

2. We built the foundation out of STONE — can you change this to BRICK?

3. Instead of making the foundation 64 block deep, only make it 3 blocks deep. Then, fly into the air and create a house — you'll be able to fly under it and see your 3 block thick foundation.

4. Can you create a foundation that is larger than the base of the house in the X and Z directions?