Shapes#

Shapes made by extruding a 2D profile of blocks along a line.

polygon() extrudes a regular polygon, which makes towers, floors and clearings. It sends one /fill command for each block of the profile.

Scripts import it from mciwb.imports.

polygon

Build a hollow prism with a regular polygon as its cross section: a tower, or with fill_item a floor.

mciwb.shapes.polygon(client, center, height, diameter, sides=4, direction=Direction.UP, item=Item.STONE, offset=None, mode=FillMode.KEEP, fill_item=Item.AIR)[source]#

Build a hollow prism with a regular polygon as its cross section: a tower, or with fill_item a floor.

Parameters:
  • client (Client) -- The RCON client, from get_client().

  • center (Vec3) -- The centre of the polygon at the start of the prism.

  • height (int) -- The length of the prism along direction, in blocks.

  • diameter (int) -- The length of each side: about this many blocks. For a square, an odd diameter is its width. A polygon with more sides is wider: with 12 sides, a diameter of 3 gives a tower 9 blocks across.

  • sides -- The number of sides.

  • direction -- Which way the prism runs. The default, up, makes a tower.

  • item (Item) -- The item to build the sides from.

  • offset -- The angle of the first corner in radians. The default puts a side, not a corner, towards positive x.

  • mode -- What to do with the blocks that are already there. The default, FillMode.KEEP, fills only air.

  • fill_item (Item) -- The item to fill the inside with. The default is air.

The air of the polygon’s profile is placed like its other blocks. With the default mode that changes nothing. With FillMode.REPLACE it clears the inside, and the corners of the square that the polygon fits in.

Raises:

ValueError -- If sides is less than 3.

Example:

from mciwb.imports import FillMode, Item, Vec3, get_client, polygon

# a hexagonal tower of stone bricks, 10 high
polygon(get_client(), Vec3(0, 64, 0), height=10, diameter=9,
        sides=6, item=Item.STONE_BRICKS)
# clear a 21 x 21 square, 3 high
polygon(get_client(), Vec3(0, 64, 0), height=3, diameter=21,
        item=Item.AIR, mode=FillMode.REPLACE)

Profiles#

The functions that polygon() is made from. They are not in mciwb.imports: import them from mciwb.shapes.

mciwb.shapes.poly_profile(sides=4, diameter=15, item=Item.STONE, offset=None, fill_item=Item.AIR)[source]#

Make a profile that holds the outline of a regular polygon. The profile is just large enough for the polygon.

Parameters:
  • sides -- The number of sides.

  • diameter -- The length of each side, in blocks (see poly_points()).

  • item (Item) -- The item to draw the outline in.

  • offset -- The angle of the first corner in radians (see poly_points()).

  • fill_item (Item) -- The item to fill the inside with. The default, air, leaves it empty.

Returns:

The profile, a 2D array of Item with air outside the polygon.

Raises:

ValueError -- If sides is less than 3.

Return type:

ndarray

mciwb.shapes.poly_points(diameter, sides, offset=None)[source]#

Work out the corners of a regular polygon centred on (0, 0).

Parameters:
  • diameter (int) -- The length of each side: about this many blocks. For a square, an odd diameter is its width. A polygon with more sides is wider than its diameter.

  • sides (int) -- The number of sides.

  • offset (float | None) -- The angle of the first corner in radians. The default is half the angle between two corners, which puts a side, not a corner, on the positive x axis.

Returns:

The x coordinates of the corners, and their z coordinates.

Raises:

ValueError -- If sides is less than 3.

mciwb.shapes.poly_draw(profile, vertices, center, item, fill_item=Item.AIR)[source]#

Draw a polygon in a profile, as lines between its corners.

Parameters:
  • profile (ndarray) -- The 2D array of Item to draw in. It is changed in place.

  • vertices (list[tuple[int, int]]) -- The corners, as (x, z) relative to center.

  • center (tuple[int, int]) -- The indices in profile of the polygon’s centre.

  • item (Item) -- The item to draw the lines in.

  • fill_item (Item) -- The item to fill the inside with. The default, air, leaves it empty.

Returns:

profile.

Return type:

ndarray

mciwb.shapes.draw_line_xz(profile, start, end, item=Item.AIR, overlap=0)[source]#

Draw a straight line in a profile.

Parameters:
  • profile (ndarray) -- The 2D array of Item to draw in. It is changed in place.

  • start (tuple[int, int]) -- The indices of one end of the line.

  • end (tuple[int, int]) -- The indices of the other end.

  • item (Item) -- The item to draw the line in.

  • overlap (int) -- Not used.

mciwb.shapes.validate(items)[source]#

Count the dimensions of a row, profile or cuboid.

Parameters:

items (list[list[list[Item] | ndarray] | ndarray] | ndarray | list[list[Item] | ndarray] | list[Item]) -- The items to check.

Returns:

1 for a row, 2 for a profile, 3 for a cuboid, or 0 if the rows are not all the same length.