Builders: a small house#
The first tutorial placed blocks, boxes and a polygon. This one uses mciwb’s builders, which each make one part of a building: a foundation, a roof, an arch, a column, a stairway, a road. Together they build this house:
The image that the script draws of its own house, here built in a flat test world#
You need the server and the install from Setup and first build. Save
house.py and run it, standing a few blocks
north or west of the spawn point:
$ mciwb run house.py
INFO: Connected to localhost on 20100
INFO: rendered iso, south, top to /home/you/house.png
walls 9 x 9, roof up to y = 85
eaves face east and west
INFO: Stopped all monitoring threads
The house has the same ORIGIN as the first build, and replaces it.
Change ORIGIN to keep both. The rest of this page goes through the
script.
How the builders work#
Positions are
Vec3, and a rectangle is given as two opposite corners.Blocks are
Itemmembers (Item.OAK_STAIRS), block state strings ("oak_stairs[facing=east]") orBlockStateobjects.Each builder returns the box that it built in, as a
Volumewith astart, anendand asize. Use it to place the next part, or to render or clear what was built.Each builder raises
BuildErrorif the server rejects a command, for example for a position in a chunk that is not loaded.
The site#
# the north west corner of the site, one block above the ground
ORIGIN = Vec3(632, 73, -1658)
# the render of the house, beside this script
PNG = Path(__file__).with_suffix(".png")
world = get_world()
# -- site --
# clear the site first: 13 blocks east, 22 south and 13 up from ORIGIN
site = Volume.from_corners(ORIGIN, ORIGIN + Vec3(12, 12, 21))
site.fill(get_client(), Item.AIR)
Clear the site before anything else, because the foundation takes whatever stands there as the ground.
The foundation#
foundation() makes a level platform on uneven
ground. Its corners give the top of the platform, and it fills each column
underneath down to the ground, whatever the height of the ground there.
# a level platform 3 blocks above the ground, filled down to the ground in
# each column. It is 11 x 13: the house plus a porch on its south side
floor = ORIGIN + Vec3(1, 2, 1)
foundation(floor, floor + Vec3(10, 0, 12), Item.COBBLESTONE)
The walls, with a Placer#
There is no builder for walls with corner posts and windows, so the script
makes its own from a Placer, as the builders do.
A Placer places blocks, checks the server’s replies, and keeps the box
around everything that it placed:
layer()places one level of blocks, given as a dictionary from(x, z)to block. It uses one fill for each rectangle of the same block.fill()fills a box, andsetblock()places one block.volumeis the box around them all.
# the walls stand one block in from the edge of the platform: nw is their
# bottom north west corner and se their top south east corner
nw = floor + Vec3(1, 1, 1)
se = nw + Vec3(8, 3, 8)
ring = {
(x, z): Item.OAK_LOG if x in (nw.x, se.x) and z in (nw.z, se.z) else Item.BRICKS
for x in range(nw.x, se.x + 1)
for z in range(nw.z, se.z + 1)
if x in (nw.x, se.x) or z in (nw.z, se.z)
}
placer = Placer()
for y in range(nw.y, se.y + 1):
placer.layer(y, ring)
# a window in the east wall and one in the west wall
for x in (nw.x, se.x):
placer.fill(
Vec3(x, nw.y + 1, nw.z + 3), Vec3(x, nw.y + 2, se.z - 3), Item.GLASS_PANE
)
walls = placer.volume
The door#
arch() builds an arch between its two feet, which
are in a line along x or z. style is "round" or "pointed".
With clear=True it also empties the opening under the arch, which cuts a
doorway through a wall that is already there.
A block can carry block entity data, such as the text of a sign or the
contents of a chest: with_nbt() adds it
to a block state, in the form that Minecraft’s setblock command takes.
# an arched doorway through the south wall: the arch is 5 blocks wide,
# feet included, and clear=True cuts the opening under it
foot = Vec3(nw.x + 2, nw.y, se.z)
arch(foot, foot + Direction.EAST * 4, Item.STONE_BRICKS, style="pointed", clear=True)
# a sign on the wall beside it. Block entity data, here the sign's text,
# goes with the block state
sign = BlockState.of(Item.OAK_WALL_SIGN, facing=Direction.SOUTH).with_nbt(
'{front_text:{messages:["","Tutorial","house",""]}}'
)
placer.setblock(Vec3(se.x - 1, nw.y + 1, se.z + 1), sign)
The roof#
A roof covers the rectangle between two corners, which are the top corners
of the walls: the roof starts one block above them.
gable_roof() has two slopes of stairs that meet at
a ridge. gable= fills in the triangles under the ends of the roof,
axis= chooses which way the ridge runs, and overhang= carries the
roof out past the walls.
# the roof sits on the walls: give it their top corners. Its ridge runs
# north to south, so there is a gable over the door
roof = gable_roof(
Vec3(walls.start.x, walls.end.y, walls.start.z),
walls.end,
Item.DARK_OAK_STAIRS,
gable=Item.DARK_OAK_PLANKS,
axis="z",
overhang=1,
)
hip_roof() (four slopes) and
flat_roof() (with an optional parapet) take the
same corners.
Columns#
column() stands on its base block, with an
optional wider plinth at the bottom and capital at the top.
# a column at each end of the porch
for x in (nw.x, se.x):
column(
Vec3(x, nw.y, se.z + 2),
4,
Item.QUARTZ_PILLAR,
plinth=Item.SMOOTH_QUARTZ,
capital=Item.SMOOTH_QUARTZ,
)
Steps and a path#
stairway() and road()
follow a list of points, where each straight section runs along x or along
z. A stairway climbs between the heights of its points, at most one block
up for each block along, and support= fills in underneath it. A road
ignores the heights of its points and replaces the top block of the ground,
so it goes up and down with the land.
# steps 3 wide from the ground up to the porch. The points are the blocks
# that you walk on: the bottom one is level with the ground
bottom = ORIGIN + Vec3(6, -1, 17)
top = Vec3(bottom.x, floor.y, bottom.z - 3)
stairway([bottom, top], Item.STONE_BRICK_STAIRS, width=3, support=Item.COBBLESTONE)
# a path over the ground from the bottom of the steps
road([bottom + Direction.SOUTH, bottom + Direction.SOUTH * 4], Item.GRAVEL)
Check the build#
world.render draws a region to an image, as
mciwb render does, and returns the blocks that it drew: index them with
a position to get the name of a block. The script draws the whole site to
house.png, beside the script, and checks that the doorway is open.
The images draw stairs as full blocks, and do not show which way they face.
Schematic.from_world reads
blocks back with their states, so the script uses it to check the bottom
row of the roof.
# render the whole site, with a layer of the ground under it
grid = world.render(
site.start + Direction.DOWN, site.end, PNG, views=["iso", "south", "top"]
)
assert grid[foot + Direction.EAST * 2] == "minecraft:air", "the doorway is blocked"
print(f"walls {walls.size.x} x {walls.size.z}, roof up to y = {roof.end.y}")
# renders draw stairs as full blocks, so read back the lowest row of the
# roof to see which way its stairs face
row = Volume.from_corners(
Vec3(roof.start.x, roof.start.y, nw.z), Vec3(roof.end.x, roof.start.y, nw.z)
)
eaves = Schematic.from_world(row).blocks[:, 0, 0]
print(f"eaves face {eaves[0].props['facing']} and {eaves[-1].props['facing']}")
Where next#
The reference has every builder and its options, and the others that this tutorial left out: reading the height of the ground, and saving, turning and pasting copies of a build with
Schematic.Build with Claude Code has an AI agent write scripts like this one for you.
The examples are much bigger builds made the same way.