Positions and boxes#

Positions, directions and boxes: the types that everything else is built on.

Vec3 is a position or an offset, Direction holds the six unit vectors, and Volume is a box of blocks. Anchor3 says which point of a box a position refers to.

Scripts import these names from mciwb.imports.

Vec3

A position in the world, or an offset between two positions.

Direction

The six unit vectors, as Vec3.

Volume

A box of blocks in the world, with its sides along the axes.

Anchor3

Which point of a box a position refers to: one of its eight corners, the middle of its top or bottom face, or its centre.

Planes3d

The three planes that Blocks.rotate() can turn blocks in.

Positions and directions#

class mciwb.geometry.Vec3(x=0, y=0, z=0)[source]#

A position in the world, or an offset between two positions.

It is a named tuple of x, y and z. Y is up. It supports +, -, *, / and // with another Vec3 (each coordinate with its partner) or with a number (applied to every coordinate), and abs(), round(), math.floor() and math.ceil().

Example:

from mciwb.imports import Direction, Vec3

pos = Vec3(10, 64, -3)
above = pos + Direction.UP * 3       # Vec3(x=10, y=67, z=-3)
offset = above - pos                 # Vec3(x=0, y=3, z=0)
x, y, z = pos
x: float | int#

Alias for field number 0

y: float | int#

Alias for field number 1

z: float | int#

Alias for field number 2

keys()[source]#
Returns:

The names of the coordinates, ("x", "y", "z").

with_ints()[source]#

Round every coordinate down to a whole number.

Returns:

The position of the block that contains this point.

property volume#

The number of blocks in a box of this size (dx * dy * dz).

property is_direction#

True if exactly one coordinate is not zero.

property dx#

The absolute value of x.

property dy#

The absolute value of y.

property dz#

The absolute value of z.

property length#

The length of the vector, in a straight line.

property west#

True if the vector points west (x is negative).

property east#

True if the vector points east (x is positive).

property north#

True if the vector points north (z is negative).

property south#

True if the vector points south (z is positive).

property down#

True if the vector points down (y is negative).

property up#

True if the vector points up (y is positive).

property f_tuple#

The coordinates as a plain tuple of float.

property i_tuple#

The coordinates as a plain tuple of int.

class mciwb.geometry.Direction[source]#

The six unit vectors, as Vec3.

Multiply one by a number for an offset: pos + Direction.NORTH * 5.

Example:

from mciwb.imports import Direction, Vec3

Direction.cardinals()               # [SOUTH, WEST, NORTH, EAST]
Direction.name(Direction.EAST)      # "east"
Direction.facing(Vec3(0, 64, 0), Vec3(9, 64, 2))    # Direction.EAST
SOUTH = (0, 0, 1)#

Towards positive z.

WEST = (-1, 0, 0)#

Towards negative x.

NORTH = (0, 0, -1)#

Towards negative z.

EAST = (1, 0, 0)#

Towards positive x.

UP = (0, 1, 0)#

Towards positive y.

DOWN = (0, -1, 0)#

Towards negative y.

classmethod values()[source]#
Returns:

The six directions, in the order south, west, north, east, up, down.

Return type:

list[Vec3]

classmethod all()[source]#
Returns:

The six directions, in the same order as values().

Return type:

list[Vec3]

classmethod cardinals()[source]#
Returns:

The four compass directions, in the order south, west, north, east. Each is a quarter turn clockwise (seen from above) from the one before.

Return type:

list[Vec3]

classmethod name(direction)[source]#

Get the name of a direction, as Minecraft writes it in a block state such as facing=north.

Parameters:

direction (Vec3) -- One of the six directions.

Returns:

The name in lower case, for example "north".

Raises:

ValueError -- If direction is not one of the six directions.

Return type:

str

classmethod facing(p1, p2)[source]#

Get the compass direction that someone at one point faces to look at another.

Parameters:
  • p1 (Vec3) -- The point to look from.

  • p2 (Vec3) -- The point to look at. The heights of the points are ignored.

Returns:

The nearest of the four compass directions. It is east if the points are in the same column.

Return type:

Vec3

mciwb.geometry.Number#

The type of each coordinate of a Vec3.

Boxes#

class mciwb.geometry.Volume[source]#

A box of blocks in the world, with its sides along the axes.

Make one with from_corners() (two opposite corners) or from_anchor() (one point, a size, and which point of the box that is). Volume() itself makes an empty box at the origin.

Example:

from mciwb.imports import Item, Vec3, Volume, get_client

box = Volume.from_corners(Vec3(0, 64, 0), Vec3(9, 68, 9))
box.size                            # Vec3(x=10, y=5, z=10)
box.fill(get_client(), Item.STONE)
box.inside(Vec3(3, 65, 3))          # True
start#

The corner with the lowest x, y and z.

end#

The corner with the highest x, y and z. It is inside the box.

size#

The number of blocks along x, y and z.

anchor#

Which point of the box position is.

position#

The position of the anchor point.

classmethod from_anchor(position, size, anchor)[source]#

Make a box from one point and a size.

Parameters:
  • position (Vec3) -- The position of the anchor point.

  • size (Vec3) -- The number of blocks along x, y and z.

  • anchor (Anchor3) -- Which point of the box is at position.

Returns:

The box.

Return type:

Volume

classmethod from_corners(start, end)[source]#

Make a box from two opposite corners. Both are inside the box.

Parameters:
  • start (Vec3) -- One corner. It is rounded down to whole blocks.

  • end (Vec3) -- The opposite corner, rounded down in the same way.

Returns:

The box. Its position and start are the corner with the lowest x, y and z, whichever corners were given.

Return type:

Volume

inside(position, xtol=0, ytol=0, ztol=0)[source]#

Check whether a position is in the box.

Parameters:
  • position (Vec3) -- The position to check.

  • xtol (int) -- How far outside the box, along x, still counts as inside.

  • ytol (int) -- The same, along y.

  • ztol (int) -- The same, along z.

Returns:

True if the position is in the box, or within the tolerances of it.

Return type:

bool

move(distance)[source]#

Move the box. This changes the Volume, not the blocks in the world.

Parameters:

distance (Vec3) -- How far to move it along x, y and z.

move_to(position)[source]#

Move the box so that its anchor point is at a new position. This changes the Volume, not the blocks in the world.

Parameters:

position (Vec3) -- The new position of the anchor point.

fill(client, block=Item.AIR)[source]#

Fill the box with one type of block, replacing every block in it.

A box of any size can be filled: one that is too big for a single /fill command is split into boxes that are small enough.

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

  • block (Item) -- The block to fill with. The default, air, clears the box.

walls(client, block, *, thickness=1, top=True, bottom=True, north=True, south=True, east=True, west=True)[source]#

Build walls on the faces of the box, leaving the inside as it is.

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

  • block (Item) -- The block to build the walls from.

  • thickness (int) -- The thickness of the walls, in blocks. The bottom is always 2 blocks thick.

  • top (bool) -- Build the top face.

  • bottom (bool) -- Build the bottom face.

  • north (bool) -- Build the north face.

  • south (bool) -- Build the south face.

  • east (bool) -- Build the east face.

  • west (bool) -- Build the west face.

mciwb.geometry.MAX_MINECRAFT_FILL_COMMAND = 32768#

The most blocks that Minecraft fills with one /fill command.

Anchors and planes#

class mciwb.geometry.Anchor3(value)[source]#

Which point of a box a position refers to: one of its eight corners, the middle of its top or bottom face, or its centre.

The corners are named for the compass: BOTTOM_NW is the corner with the lowest x, y and z. CENTER and CENTRE are other names for MIDDLE, here and in BOTTOM_MIDDLE and TOP_MIDDLE.

Example:

from mciwb.imports import Anchor3, Vec3, Volume

# a 5 x 4 x 5 box that stands on the block at (0, 64, 0)
box = Volume.from_anchor(Vec3(0, 64, 0), Vec3(5, 4, 5), Anchor3.BOTTOM_MIDDLE)
MIDDLE = 'middle'#
CENTER = 'middle'#
CENTRE = 'middle'#
BOTTOM_MIDDLE = 'bottom_middle'#
BOTTOM_CENTER = 'bottom_middle'#
BOTTOM_CENTRE = 'bottom_middle'#
TOP_MIDDLE = 'top_middle'#
TOP_CENTER = 'top_middle'#
TOP_CENTRE = 'top_middle'#
BOTTOM_SW = 'bottom_sw'#
BOTTOM_NW = 'bottom_nw'#
BOTTOM_NE = 'bottom_ne'#
BOTTOM_SE = 'bottom_se'#
TOP_SW = 'top_sw'#
TOP_NW = 'top_nw'#
TOP_NE = 'top_ne'#
TOP_SE = 'top_se'#
class mciwb.geometry.Anchor3Face[source]#

Sets of Anchor3, grouped by the face of the box that they are on. Volume.from_anchor() uses them.

class mciwb.geometry.Planes3d(value)[source]#

The three planes that Blocks.rotate() can turn blocks in.

Each value is the pair of array axes that make the plane, where 0 is x, 1 is y and 2 is z.

XY = (0, 1)#
XZ = (0, 2)#
YZ = (1, 2)#

Arrays of items#

mciwb.geometry.Row#

a list, or a 1D numpy.ndarray.

Type:

The type of a row of Item

mciwb.geometry.Profile#

a list of rows, or a 2D numpy.ndarray. poly_profile() makes one.

Type:

The type of a 2D array of Item

mciwb.geometry.Cuboid#

The type of a 3D array of Item, indexed cuboid[x][y][z]: nested lists, or a 3D numpy.ndarray. It is what grab() returns and what Blocks places.

mciwb.geometry.Items#

A Cuboid, a Profile or a Row.