amulet.api.selection.box module

class amulet.api.selection.SelectionBox(point_1, point_2)[source]

Bases: AbstractBaseSelection

The SelectionBox class represents a single cuboid selection.

When combined with SelectionGroup it can represent any arbitrary shape.

__init__(point_1, point_2)[source]

Construct a new SelectionBox instance.

>>> # a selection box that selects one block.
>>> box = SelectionBox(
>>>     (0, 0, 0),
>>>     (1, 1, 1)
>>> )
Parameters
classmethod create_chunk_box(cx, cz, sub_chunk_size=16)[source]

Get a SelectionBox containing the whole of a given chunk.

>>> box = SelectionBox.create_chunk_box(1, 2)
SelectionBox((16, -1073741824, 32), (32, 1073741824, 48))
Parameters
  • cx (int) – The x coordinate of the chunk

  • cz (int) – The z coordinate of the chunk

  • sub_chunk_size (int) – The dimension of a sub-chunk. Default 16.

Return type

SelectionBox

classmethod create_sub_chunk_box(cx, cy, cz, sub_chunk_size=16)[source]

Get a SelectionBox containing the whole of a given sub-chunk.

>>> SelectionBox.create_sub_chunk_box(1, 0, 2)
SelectionBox((16, 0, 32), (32, 16, 48))
Parameters
  • cx (int) – The x coordinate of the chunk

  • cy (int) – The y coordinate of the chunk

  • cz (int) – The z coordinate of the chunk

  • sub_chunk_size (int) – The dimension of a sub-chunk. Default 16.

Return type

SelectionBox

create_moved_box(offset, subtract=False)[source]

Create a new SelectionBox based on this one with the coordinates moved by the given offset.

Parameters
  • offset (Union[Tuple[int, int, int], ndarray]) – The amount to move the box.

  • subtract – If true will subtract the offset rather than adding.

Return type

SelectionBox

Returns

The new selection with the given offset.

chunk_locations(sub_chunk_size=16)[source]

An iterable of chunk coordinates that intersect the selection.

>>> for cx, cz in selection1.chunk_locations():
>>>     ...
Parameters

sub_chunk_size (int) – The dimension of a sub-chunk. Default 16.

Return type

Iterable[Tuple[int, int]]

chunk_boxes(sub_chunk_size=16)[source]

An iterable of chunk coordinates and boxes that intersect the selection and the chunk.

>>> for (cx, cz), box in selection1.chunk_boxes():
>>>     ...
Parameters

sub_chunk_size (int) – The dimension of a sub-chunk. Default 16.

Return type

Iterable[Tuple[Tuple[int, int], SelectionBox]]

chunk_y_locations(sub_chunk_size=16)[source]

An iterable of all the sub-chunk y indexes this box intersects.

Parameters

sub_chunk_size (int) – The dimension of a sub-chunk. Default 16.

Return type

Iterable[int]

sub_chunk_locations(sub_chunk_size=16)[source]

An iterable of sub-chunk coordinates that intersect the selection.

>>> for cx, cy, cz in selection1.sub_chunk_locations():
>>>     ...
Parameters

sub_chunk_size (int) – The dimension of a sub-chunk. Default 16.

Return type

Iterable[Tuple[int, int, int]]

chunk_count(sub_chunk_size=16)[source]

The number of chunks that intersect the selection.

Parameters

sub_chunk_size (int) – The dimension of a sub-chunk. Default 16.

Return type

int

sub_chunk_count(sub_chunk_size=16)[source]

The number of sub-chunks that intersect the selection.

Parameters

sub_chunk_size (int) – The dimension of a sub-chunk. Default 16.

Return type

int

sub_chunk_boxes(sub_chunk_size=16)[source]

An iterable of sub-chunk coordinates and boxes that intersect the selection and the sub-chunk.

>>> for (cx, cy, cz), box in selection1.sub_chunk_boxes():
>>>     ...
Parameters

sub_chunk_size (int) – The dimension of a sub-chunk. Default 16.

Return type

Iterable[Tuple[Tuple[int, int, int], SelectionBox]]

property blocks: Iterable[Tuple[int, int, int]][source]

The location of every block in the selection.

Returns

An iterable of block locations.

contains_block(coords)[source]

Is the block contained within the selection.

>>> (1, 2, 3) in selection1
True
Parameters

coords (Union[Tuple[int, int, int], ndarray, Tuple[float, float, float]]) – The coordinate of the block defined by the most negative corner.

Return type

bool

Returns

True if the block is in the selection.

contains_point(coords)[source]

Is the point contained within the selection.

>>> (1.5, 2.5, 3.5) in selection1
True
Parameters

coords (Union[Tuple[int, int, int], ndarray, Tuple[float, float, float]]) – The coordinate of the point.

Return type

bool

Returns

True if the point is in the selection.

property slice: Tuple[slice, slice, slice][source]

Converts the SelectionBox minimum/maximum coordinates into slice arguments

Returns

The SelectionBox coordinates as slices in (x,y,z) order

chunk_slice(cx, cz, sub_chunk_size=16)[source]

Get the slice of the box in relative form for a given chunk.

>>> SelectionBox((0, 0, 0), (32, 32, 32)).chunk_slice(1, 1)
(slice(0, 16, None), slice(0, 32, None), slice(0, 16, None))
Parameters
  • cx (int) – The x coordinate of the chunk

  • cz (int) – The z coordinate of the chunk

  • sub_chunk_size (int) – The dimension of a sub-chunk. Default 16.

Return type

Tuple[slice, slice, slice]

sub_chunk_slice(cx, cy, cz, sub_chunk_size=16)[source]

Get the slice of the box in relative form for a given sub-chunk.

>>> SelectionBox((0, 0, 0), (32, 32, 32)).sub_chunk_slice(1, 1, 1)
(slice(0, 16, None), slice(0, 16, None), slice(0, 16, None))
Parameters
  • cx (int) – The x coordinate of the chunk

  • cy (int) – The y coordinate of the chunk

  • cz (int) – The z coordinate of the chunk

  • sub_chunk_size (int) – The dimension of a sub-chunk. Default 16.

Return type

Tuple[slice, slice, slice]

property point_1: Tuple[int, int, int][source]

The first value given to the constructor.

property point_2: Tuple[int, int, int][source]

The second value given to the constructor.

property points: Tuple[Tuple[int, int, int], Tuple[int, int, int]][source]

The points given to the constructor.

property points_array: ndarray[source]

The points given to the constructor as a numpy array.

property min_x: int[source]

The minimum x coordinate of the selection.

property min_y: int[source]

The minimum y coordinate of the selection.

property min_z: int[source]

The minimum z coordinate of the selection.

property max_x: int[source]

The maximum x coordinate of the selection.

property max_y: int[source]

The maximum y coordinate of the selection.

property max_z: int[source]

The maximum z coordinate of the selection.

property min: Tuple[int, int, int][source]

The minimum point in the selection.

property min_array: ndarray[source]

The minimum point in the selection as a numpy array.

property max: Tuple[int, int, int][source]

The maximum point in the selection.

property max_array: ndarray[source]

The maximum point in the selection as a numpy array.

property bounds: Tuple[Tuple[int, int, int], Tuple[int, int, int]][source]

The minimum and maximum points in the selection.

property bounds_array: ndarray[source]

The minimum and maximum points in the selection as a numpy array.

property size_x: int[source]

The length of the box in the x axis.

property size_y: int[source]

The length of the box in the y axis.

property size_z: int[source]

The length of the box in the z axis.

property shape: Tuple[int, int, int][source]

The shape of the box.

>>> SelectionBox((0, 0, 0), (1, 1, 1)).shape
(1, 1, 1)
property volume: int[source]

The number of blocks in the box.

>>> SelectionBox((0, 0, 0), (1, 1, 1)).shape
1
touches(other)[source]

Method to check if this instance of SelectionBox touches but does not intersect another SelectionBox.

Parameters

other (SelectionBox) – The other SelectionBox

Return type

bool

Returns

True if the two SelectionBox instances touch, False otherwise

touches_or_intersects(other)[source]

Method to check if this instance of SelectionBox touches or intersects another SelectionBox.

Parameters

other (SelectionBox) – The other SelectionBox.

Return type

bool

Returns

True if the two SelectionBox instances touch or intersect, False otherwise.

intersects(other)[source]

Method to check whether this instance of SelectionBox intersects another SelectionBox.

Parameters

other (SelectionBox) – The other SelectionBox to check for intersection.

Return type

bool

Returns

True if the two SelectionBox instances intersect, False otherwise.

contains_box(other)[source]

Method to check if the other SelectionBox other fits entirely within this instance of SelectionBox.

Parameters

other (SelectionBox) – The SelectionBox to test.

Return type

bool

Returns

True if other fits with self, False otherwise.

intersection(other)[source]

Create and return a new a selection containing the volume that this selection and other both contain.

If the selections do not intersect the returned selection will have no volume.

Use intersects() to test if the two selections intersect.

Parameters

other (SelectionBox) – The other selection.

Return type

SelectionBox

Returns

A new selection containing the intersection.

subtract(other)[source]

Get a SelectionGroup containing boxes that are in self but not in other.

This may be empty if other fully contains self or equal to self if they do not intersect.

Parameters

other (SelectionBox) – The SelectionBox to subtract.

Return type

SelectionGroup

Returns

intersects_vector(origin, vector)[source]

Determine if a vector from a given point collides with this selection box.

Parameters
Return type

Optional[float]

Returns

Multiplier of the vector to the collision location. None if it does not collide

transformed_points(transform)[source]

Get the locations of the transformed blocks and the source blocks they came from.

Parameters

transform (ndarray) – The matrix that this box will be transformed by.

Return type

Iterable[Tuple[float, Optional[ndarray], Optional[ndarray]]]

Returns

An iterable of two Nx3 numpy arrays of the source block locations and the destination block locations. The destination locations will be unique but the source may not be and some may not be included.

transform(scale, rotation, translation)[source]

Creates a SelectionGroup of transformed SelectionBox(es).

Parameters
Return type

SelectionGroup

Returns

A new SelectionGroup representing the transformed selection.