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: .. figure:: ../images/tutorial-house.png :alt: three views of a brick house with a dark roof on a stone platform, with steps up to an arched door between two white columns 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 :doc:`01-first-build`. Save :download:`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 ``Item`` members (``Item.OAK_STAIRS``), block state strings (``"oak_stairs[facing=east]"``) or :py:class:`~mciwb.builders.BlockState` objects. - Each builder returns the box that it built in, as a ``Volume`` with a ``start``, an ``end`` and a ``size``. Use it to place the next part, or to render or clear what was built. - Each builder raises :py:exc:`~mciwb.builders.BuildError` if the server rejects a command, for example for a position in a chunk that is not loaded. The site -------- .. literalinclude:: scripts/house.py :start-at: # the north west corner of the site :end-before: # -- foundation -- Clear the site before anything else, because the foundation takes whatever stands there as the ground. The foundation -------------- :py:func:`~mciwb.builders.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. .. literalinclude:: scripts/house.py :start-after: # -- foundation -- :end-before: # -- walls -- The walls, with a Placer ------------------------ There is no builder for walls with corner posts and windows, so the script makes its own from a :py:class:`~mciwb.builders.Placer`, as the builders do. A ``Placer`` places blocks, checks the server's replies, and keeps the box around everything that it placed: - :py:meth:`~mciwb.builders.Placer.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. - :py:meth:`~mciwb.builders.Placer.fill` fills a box, and :py:meth:`~mciwb.builders.Placer.setblock` places one block. - :py:attr:`~mciwb.builders.Placer.volume` is the box around them all. .. literalinclude:: scripts/house.py :start-after: # -- walls -- :end-before: # -- door -- The door -------- :py:func:`~mciwb.builders.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: :py:meth:`~mciwb.builders.BlockState.with_nbt` adds it to a block state, in the form that Minecraft's ``setblock`` command takes. .. literalinclude:: scripts/house.py :start-after: # -- door -- :end-before: # -- roof -- 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. :py:func:`~mciwb.builders.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. .. literalinclude:: scripts/house.py :start-after: # -- roof -- :end-before: # -- columns -- :py:func:`~mciwb.builders.hip_roof` (four slopes) and :py:func:`~mciwb.builders.flat_roof` (with an optional parapet) take the same corners. Columns ------- :py:func:`~mciwb.builders.column` stands on its base block, with an optional wider ``plinth`` at the bottom and ``capital`` at the top. .. literalinclude:: scripts/house.py :start-after: # -- columns -- :end-before: # -- stairs -- Steps and a path ---------------- :py:func:`~mciwb.builders.stairway` and :py:func:`~mciwb.builders.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. .. literalinclude:: scripts/house.py :start-after: # -- stairs -- :end-before: # -- check -- Check the build --------------- :py:meth:`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. :py:meth:`Schematic.from_world ` reads blocks back with their states, so the script uses it to check the bottom row of the roof. .. literalinclude:: scripts/house.py :start-after: # -- check -- Where next ---------- - The :doc:`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 :py:class:`~mciwb.builders.Schematic`. - :doc:`../how-to/claude-skill` has an AI agent write scripts like this one for you. - The `examples `_ are much bigger builds made the same way.