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#
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 Set up 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:
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 Blocks do not appear.
The build script#
Save 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.
from mciwb.imports import (
Direction,
Item,
Vec3,
Volume,
get_client,
get_world,
polygon,
)
# the north west corner of the build, one block above the ground
ORIGIN = Vec3(632, 73, -1658)
world = get_world()
client = get_client()
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:
# everything is placed relative to ORIGIN: the site is 11 blocks from west
# to east, 13 from north to south and 8 high
site = Volume.from_corners(ORIGIN, ORIGIN + Vec3(10, 7, 12))
site.fill(client, Item.AIR)
Filling another paves it. One fill command places up to 32768 blocks, so it is much faster than placing blocks one at a time:
# one fill command paves the whole site
paving = Volume.from_corners(ORIGIN, ORIGIN + Vec3(10, 0, 12))
paving.fill(client, Item.STONE_BRICKS)
world.set_block places one block. Item
has every block in the game: Item.GOLD_BLOCK, Item.OAK_PLANKS and so
on.
# a single block, standing on the paving
centre = ORIGIN + Vec3(5, 1, 5)
world.set_block(centre, Item.GOLD_BLOCK)
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.
world.place_door places both halves of a
door.
# a hollow tower around it, 5 blocks high. With 12 sides it is nearly
# round, and 9 blocks across
polygon(client, centre, height=5, diameter=3, sides=12, item=Item.STONE_BRICKS)
# a door in the south side of the tower, facing out
door = centre + Direction.SOUTH * 4
world.place_door(door, Item.OAK_DOOR, Direction.SOUTH)
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=.
# two posts and a lintel on the south edge of the site, a block at a time
post = ORIGIN + Vec3(3, 1, 12)
for y in range(4):
world.set_block(post + Direction.UP * y, Item.OBSIDIAN)
world.set_block(post + Direction.EAST * 4 + Direction.UP * y, Item.OBSIDIAN)
for x in range(5):
world.set_block(post + Direction.EAST * x + Direction.UP * 4, Item.OBSIDIAN)
# a block state: a lantern hanging from the middle of the lintel
lantern = post + Direction.EAST * 2 + Direction.UP * 3
world.set_block(lantern, Item.LANTERN, nbt=["hanging=true"])
Last, the script reads two blocks back from the world, to check that the build is there:
print(f"built from {tuple(site.start)} to {tuple(site.end)}")
print(f"the centre is {world.get_block(centre)}")
print(f"the door is {world.get_block(door)}")
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 a Build to an Image 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 Back up and restore).
When you have finished, mciwb stop stops the server. The world is kept
in ~/mciwb-server, and mciwb start starts it again.
Command line lists every mciwb command and its options.
Next: Builders: a small house.