Setup and first build
=====================
This tutorial installs mciwb, starts a Minecraft server, and runs a first
build script: a paved square with a small round tower and a gateway. It
takes about half an hour, most of it waiting for downloads.
What you need
-------------
- Linux, macOS, or Windows with WSL2.
- Python 3.11 or later (`uv `_ can install it
for you).
- `Podman `_, which runs the Minecraft server in a
container.
- Minecraft Java Edition, to walk round what you build. mciwb can build and
draw images without it, so an AI agent does not need it.
Install mciwb
-------------
Make a virtual environment and install mciwb into it from GitHub::
$ uv venv --python 3.13 .venv
$ source .venv/bin/activate
$ uv pip install git+https://github.com/gilesknap/mciwb.git
$ mciwb --version
Without uv, use ``python3 -m venv .venv`` and ``python3 -m pip install`` in
the same way.
.. note::
The releases on PyPI (``pip install mciwb``) are older than Minecraft
26.x. Until there is a new release, install from GitHub.
Set up Podman
-------------
mciwb talks to Podman through its service socket. On Linux, install Podman
and switch the service on, once::
$ sudo apt install podman
$ systemctl --user enable --now podman.socket
For macOS, Windows and other Linux distributions see `podman`.
Start a server
--------------
::
$ mciwb start
INFO: Creating new Minecraft server in /home/you/mciwb-server
INFO: Launching Minecraft Server 'mciwb-server' on port 20101 ...
INFO: waiting for server to come online ...
INFO: Server mciwb-server is online on port 20101
The first start downloads the server and makes a new world, which takes a
few minutes. The server keeps running in the background until you run
``mciwb stop``. It listens on two ports: Minecraft clients join the game on
**20101**, and mciwb sends its commands to RCON on **20100**.
If this fails, see `troubleshooting`.
Join the game
-------------
In the Minecraft Launcher, play Minecraft Java Edition release **26.3**, the
release that the server runs (see `minecraft_version` if the Launcher offers
a newer one). Choose "Multiplayer", then "Add Server", and give the server
address ``localhost:20101``:
.. figure:: ../images/server_address.png
:alt: the Edit Server Info screen with the address localhost:20101
:width: 400px
:align: center
Join the server. You are in creative mode, in a desert beside an ocean, at
the world's spawn point: x 632, y 73, z -1658.
.. note::
Minecraft only changes blocks in chunks that are loaded, which means
near a player. So stay in the game, near the spawn point, while the
script runs. The build goes to the south east of the spawn point: step
a few blocks north or west to watch it. To build with nobody in the
game, see `unloaded_chunks`.
The build script
----------------
Save :download:`first_build.py ` in your folder. The
rest of this section goes through it.
It starts with its imports. Everything that a build script needs comes from
``mciwb.imports``. ``world`` is the connection to the server that ``mciwb
run`` made, and ``client`` is the RCON client underneath it, which the
functions that place many blocks take as their first argument.
.. literalinclude:: scripts/first_build.py
:start-at: from mciwb.imports
:end-before: # -- clear --
A position is a ``Vec3(x, y, z)``: x grows to the east, y upwards and z to
the south (see `coordinates`). ``ORIGIN`` is the spawn point, and every
other position in the script is worked out from it, so changing that one
line moves the whole build.
A ``Volume`` is a box of blocks between two opposite corners. Filling one
with air clears the site, so the script can be run again and again:
.. literalinclude:: scripts/first_build.py
:start-after: # -- clear --
:end-before: # -- floor --
Filling another paves it. One fill command places up to 32768 blocks, so it
is much faster than placing blocks one at a time:
.. literalinclude:: scripts/first_build.py
:start-after: # -- floor --
:end-before: # -- block --
:py:meth:`world.set_block ` places one block. ``Item``
has every block in the game: ``Item.GOLD_BLOCK``, ``Item.OAK_PLANKS`` and so
on.
.. literalinclude:: scripts/first_build.py
:start-after: # -- block --
:end-before: # -- tower --
``polygon`` builds a hollow shape with any number of sides, here a tower.
Its ``diameter`` is not the width of the shape, except for a square: with 12
sides a ``diameter`` of 3 gives a tower 9 blocks across.
``Direction`` has the six directions as vectors, to add to a position:
``centre + Direction.SOUTH * 4`` is the block 4 to the south of the centre.
:py:meth:`world.place_door ` places both halves of a
door.
.. literalinclude:: scripts/first_build.py
:start-after: # -- tower --
:end-before: # -- gateway --
Loops and ``Vec3`` arithmetic build anything else. Some blocks have block
states, such as which way stairs face or whether a lantern hangs: give them
to ``set_block`` in ``nbt=``, and a direction in ``facing=``.
.. literalinclude:: scripts/first_build.py
:start-after: # -- gateway --
:end-before: # -- check --
Last, the script reads two blocks back from the world, to check that the
build is there:
.. literalinclude:: scripts/first_build.py
:start-after: # -- check --
Run it
------
::
$ mciwb run first_build.py
INFO: Connected to localhost on 20100
built from (632, 73, -1658) to (642, 80, -1646)
the centre is minecraft:gold_block
the door is minecraft:oak_door
INFO: Stopped all monitoring threads
The build appears in the game at once, to the south east of the spawn point.
See it without the game
-----------------------
``mciwb render`` draws a region of the world to an image. Give it two
opposite corners, here the corners that the script printed, with one layer
of the ground as well::
$ mciwb render 632 72 -1658 642 80 -1646 --view iso --view top
This writes ``render.png``: a view from the south east and a plan. See
`render_howto` for the other views and options.
Change it
---------
Edit the script and run it again: it clears its site first, so each run
starts afresh. Try another ``Item`` for the tower, a taller gateway, or a
different ``ORIGIN`` to build somewhere else.
Before a bigger experiment, save the world with ``mciwb backup``, and get it
back with ``mciwb restore`` if the experiment goes wrong (see `backups`).
When you have finished, ``mciwb stop`` stops the server. The world is kept
in ``~/mciwb-server``, and ``mciwb start`` starts it again.
:doc:`/reference/cli` lists every ``mciwb`` command and its options.
Next: :doc:`02-builders`.