Build a House

Challenge

In this challenge we will build a simple, single story house with a flat roof. We could build a house with a loop to place every block but a nice easy way to do it is to use the setBlocks function to quickly build a solid cube shape of one block type. This way we can create a solid block then hollow out the insides using the same method but using an air block to give a living area.

Extensions

Example Solution

Super simple edition


import mcpi.minecraft as minecraft

world = minecraft.Minecraft.create()

x = 10
y = 11
z = 12

# width, height and depth
x2 = x + 10
y2 = y + 5
z2 = z + 8

stone_block_id = 4 # cobble stones
air_block_id = 0

world.setBlocks(x, y, z, x2, y2, z2, stone_block_id)
world.setBlocks(x + 1, y + 1, z + 1, x2 - 1, y2 - 1, z2 - 1, air_block_id)

Using a house function


import mcpi.minecraft as minecraft
import mcpi.block as block
import random

# a square house at x, y, z
def build_a_house(world, x, y, z, width, height):

    # floor
    world.setBlocks(x, y - 1, z, x + width, y - 1, z + width, block.GRASS.id)

    # walls
    world.setBlocks(x, y, z, x + width, y + height, z, block.STONE.id)
    world.setBlocks(x + width, y, z, x + width, y + height, z + width, block.STONE.id)
    world.setBlocks(x + width, y, z + width, x, y + height, z + width, block.STONE.id)
    world.setBlocks(x, y, z + width, x, y + height, z, block.STONE.id)

    #draw windows
    mc.setBlocks(x + (width / 2) - 2, y + 1, z, x + (width / 2) - 2, y + 2, z, block.GLASS.id)
    mc.setBlocks(x + (width / 2) + 2, y + 1, z, x + (width / 2) + 2, y + 2, z, block.GLASS.id)

    # doorway
    mc.setBlocks(x + (width / 2), y, z, x + (width / 2), y + 1, z, block.AIR.id)

    # flat roof
    mc.setBlocks(x, y + height + 1, z, x + width, y + height + 1, z + width, block.WOOD_PLANKS.id)


world = minecraft.Minecraft.create()

# build house in front of you
pos = world.player.getTilePos()
build_a_house(world, pos.x, pos.y, pos.z + 1, 10, 5)