Terrain and foundations#

Read the height of the ground, and build foundations that follow it.

ground_height() and ground_heights() give the y of the top ground block of a column, and foundation() fills from the ground up to a level platform to build on. road() reads the ground in the same way.

The ground height comes from the server’s heightmaps, with execute positioned over <heightmap>: one RCON command per column, which is much cheaper than reading blocks one at a time. A Heightmap chooses what counts as the ground, for example whether water or leaves do. The columns must be in loaded chunks (near a player, or loaded with the forceload command): otherwise BuildError is raised.

mciwb.builders.foundation(start, end, block=Item.COBBLESTONE, *, heightmap=Heightmap.OCEAN_FLOOR, max_depth=64)[source]#

Build a foundation that follows the terrain, with a level top.

Fills each column of a rectangular footprint from the ground up to start.y, giving a level platform at start.y to build on (at start.y + 1).

Build the foundation before anything above it: the ground height is the top of the highest block in each column, so a building already standing there would count as the ground. Columns where the ground is at or above start.y just get the top layer (replacing the ground there): higher ground is not dug away.

The ground is read with ground_heights(), so every column of the footprint must be in a loaded chunk.

Parameters:
  • start (Vec3) -- A corner of the footprint, at the height of the top of the foundation.

  • end (Vec3) -- The opposite corner of the footprint. Only x and z are used.

  • block (Item | str | BlockState) -- The block to build the foundation from.

  • heightmap (Heightmap | str) -- What counts as the ground: a Heightmap or its name. The default ignores water, so the foundation goes down to the bed of a lake or the sea.

  • max_depth (int) -- The deepest any column may go, in blocks below start.y (a guard against building down into a ravine or the void). 0 gives just the top layer.

Returns:

The bounding box of the foundation.

Raises:
  • ValueError -- If max_depth is negative, or heightmap is not the name of a heightmap.

  • BuildError -- If a column of the footprint is not in a loaded chunk, or the server rejects a command, for example for an unknown block.

Return type:

Volume

Example:

from mciwb.imports import Item, Vec3, foundation, ground_height

# a platform 9 by 7, one block above the ground at its first corner
top = ground_height(0, 0) + 1
base = foundation(Vec3(0, top, 0), Vec3(8, top, 6), Item.STONE_BRICKS)
floor_y = base.end.y + 1    # the first layer of the building
mciwb.builders.ground_height(x, z, heightmap=Heightmap.MOTION_BLOCKING_NO_LEAVES)[source]#

Find the y of the top ground block of one column.

This is ground_heights() for a single column. For many columns, call that once: it is quicker than calling this for each one.

Parameters:
  • x (float) -- The x of the column. Rounded down to a whole block.

  • z (float) -- The z of the column. Rounded down to a whole block.

  • heightmap (Heightmap | str) -- What counts as the ground: a Heightmap or its name. The default ignores leaves, and counts the surface of water as the ground.

Returns:

The y of the top ground block. In a column with no ground at all, such as the void in the End, this is one below the bottom of the world.

Raises:
  • ValueError -- If heightmap is not the name of a heightmap.

  • BuildError -- If the column is not in a loaded chunk, or the server’s reply cannot be understood.

Return type:

int

Example:

from mciwb.imports import Item, Vec3, get_world, ground_height

# put a gold block on the ground at x = 10, z = 20
y = ground_height(10, 20)
get_world().set_block(Vec3(10, y + 1, 20), Item.GOLD_BLOCK)
mciwb.builders.ground_heights(columns, heightmap=Heightmap.MOTION_BLOCKING_NO_LEAVES)[source]#

Find the y of the top ground block of each of a set of columns.

Teleports a temporary marker entity to the top of each column, which costs one RCON command per column (plus two to make and remove the marker). Uses the RCON client of the current thread, from get_client(). No blocks are changed.

Parameters:
  • columns (Iterable[tuple[float, float]]) -- The columns, as (x, z) pairs. Coordinates are rounded down to whole blocks.

  • heightmap (Heightmap | str) -- What counts as the ground: a Heightmap or its name. The default ignores leaves, and counts the surface of water as the ground.

Returns:

The y of the top ground block of each column, keyed by its (x, z) as whole numbers. In a column with no ground at all, such as the void in the End, this is one below the bottom of the world. No columns give an empty dictionary.

Raises:
  • ValueError -- If heightmap is not the name of a heightmap.

  • BuildError -- If a column is not in a loaded chunk, or the server’s reply cannot be understood.

Return type:

dict[tuple[int, int], int]

Example:

from mciwb.imports import Heightmap, ground_heights

corners = [(0, 0), (8, 0), (0, 6), (8, 6)]
heights = ground_heights(corners, Heightmap.OCEAN_FLOOR)
top = max(heights.values())
class mciwb.builders.Heightmap(value)[source]#

The Minecraft heightmaps: what counts as the ground.

Each value is the name that Minecraft uses for the heightmap, and the functions that take a heightmap accept that name as a plain string too, for example "ocean_floor".

WORLD_SURFACE = 'world_surface'#

The highest block that is not air (includes plants and snow layers).

MOTION_BLOCKING = 'motion_blocking'#

The highest block that blocks movement, or holds water or lava.

MOTION_BLOCKING_NO_LEAVES = 'motion_blocking_no_leaves'#

As MOTION_BLOCKING, but ignoring leaves.

OCEAN_FLOOR = 'ocean_floor'#

The highest block that blocks movement, ignoring water and lava. This is the bed of a lake or the sea.