In this project, we'll build a simple house in the Minecraft world at the touch of a button.

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

The code for this project should look very familiar. It is very similar to the Minecraft project, where we drew an animation of our character using blocks. In that project, we were also drawing the sprite on our LED Matrix, so we used 0 to denote LED off and 1-8 and A-F to denote intensity of the LED display.

Because we're not using the LED Matrix in this project, we don't need to include the LED intensity in our sprite design. Instead, we will simply use 0 and 1 to denote our block types — 0 will indicate no block (block type AIR) and 1 will indicate a stone block. We implement this using a list, and the 0 and 1 are simply indexes in that list.

The magic happens in a function we've created called `create_house()`. Similar to the `sprite_in_minecraft()` function in the project, we go through a set of nested loops to draw blocks in the Minecraft world. In that project, we drew the animation in 2 dimensions (X and Y), and therefore we used two nested loops. In this project, we'll draw the house in 3 dimensions, which means we'll need three nested loops.

The corner of the house is drawn relative to Steve's position, plus an offset. An offset is just a small change in position. We chose a small offset so that the house is close to Steve, but not right on top of him.

## Full Code

Here is what the full code for this project should look like:

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, base=block.STONE): corner = mc.player.getTilePos() - offset for delta_y, house_slice in enumerate(house_slices): for delta_x, row in enumerate(house_slice): for delta_z, block_index in enumerate(row): block_type = block_types[int(block_index)] mc.setBlock(corner + Vec3(delta_x, delta_y, delta_z), block_type) control.show() mc = minecraft.Minecraft.create() button = Button(24) while True: if button.presses(): create_house(mc, house, Vec3(3,1,3)) time.sleep(0.01)

Give it a try. You'll need to fly up and into the house to see the inside.

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. The house is made of AIR and STONE. Try swapping those materials to get a strange inverted house.

3. Adjust the `offset` passed into `create_house()` so that when the house is built, Steve is just outside of it.

4. Let's be honest — it's not much of a house. Make it a little better by adding a hole for a door and a flat roof.