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.
A position in the world, or an offset between two positions. |
|
The six unit vectors, as |
|
A box of blocks in the world, with its sides along the axes. |
|
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 three planes that |
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,yandz. Y is up. It supports+,-,*,/and//with another Vec3 (each coordinate with its partner) or with a number (applied to every coordinate), andabs(),round(),math.floor()andmath.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
- 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 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:
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) orfrom_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.
- position#
The position of the anchor point.
- classmethod from_corners(start, end)[source]#
Make a box from two opposite corners. Both are inside the box.
- 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
/fillcommand 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
/fillcommand.
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_NWis the corner with the lowest x, y and z.CENTERandCENTREare other names forMIDDLE, here and inBOTTOM_MIDDLEandTOP_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.
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, indexedcuboid[x][y][z]: nested lists, or a 3Dnumpy.ndarray. It is whatgrab()returns and whatBlocksplaces.