Cuboids (frozen)#

Cuboids: 3D arrays of Item, read from the world and placed in it one block at a time.

Note

This module is frozen. It works and it is tested, but it is no longer being developed. A cuboid holds block types only, not block states, so stairs lose their facing. For new work use Schematic, which keeps block states and reads and writes .schem files, and mciwb.render.scan() to read a region quickly.

A cuboid (Cuboid) is indexed cuboid[x][y][z]. grab() reads one from the world, Blocks places one, and save_items() and load_items() keep one in a JSON file.

Blocks

A cuboid of blocks placed in the world, which can then be moved and rotated.

grab

Read the blocks of a region of the world, one block at a time.

get_block

Get the type of the block at a position, over RCON.

save_items

Save a cuboid, a profile (a 2D list) or a row (a list) of Item to a JSON file.

load_items

Load the items that save_items() saved.

The type of a cuboid is Cuboid.

Reading blocks#

mciwb.cuboids.grab(client, vol)[source]#

Read the blocks of a region of the world, one block at a time.

Parameters:
Returns:

A cuboid of Item, as nested lists. Block states such as the facing of stairs are not read: for those use Schematic.from_world().

Raises:

ValueError -- If a block can not be read (see get_block()).

Return type:

list[list[list[Item] | ndarray] | ndarray] | ndarray

mciwb.cuboids.get_block(client, pos)[source]#

Get the type of the block at a position, over RCON.

This sends loot spawn <dump> mine <pos>, which reports the loot table of the block: minecraft:blocks/<id>. A block without a loot table, such as air, water or bedrock, is identified from the error message instead.

Some blocks share the loot table of a related block: a wall torch reads back as a torch, and a wall sign as a sign.

Parameters:
Returns:

The type of the block.

Raises:

ValueError -- If the position is not loaded, or the server reports a block that is not in Item: one added after MINECRAFT_VERSION.

Return type:

Item

Placing and moving blocks#

class mciwb.cuboids.Blocks(client, position, cube, anchor=Anchor3.BOTTOM_NW, render=True)[source]#

A cuboid of blocks placed in the world, which can then be moved and rotated.

Air in the cuboid is not placed: the blocks already in the world show through it. Each other block is placed with one setblock command.

Parameters:
Raises:

ValueError -- If cube is not a regular 3D array.

Example:

from mciwb.imports import Blocks, Item, Planes3d, Vec3, get_client

S, G = Item.STONE, Item.GLASS
cube = [[[S, G], [S, G]], [[S, S], [S, S]]]
blocks = Blocks(get_client(), Vec3(0, 64, 0), cube)
blocks.move(Vec3(5, 0, 0))
blocks.rotate(Planes3d.XZ)
classmethod from_volume(client, volume)[source]#

Make a Blocks object from the blocks that are in a region of the world.

Parameters:
Returns:

The Blocks object. Its anchor is the bottom north west corner, at the position of volume.

Return type:

Blocks

rotate(plane, steps=1, clear=True)[source]#

Turn the blocks by quarter turns, and place them again.

Parameters:
  • plane (Planes3d) -- The plane to turn them in.

  • steps (int) -- The number of quarter turns.

  • clear -- Fill the region that the blocks were in with air first.

move(vector, clear=True)[source]#

Move the blocks, and place them again.

Parameters:
  • vector (Vec3) -- How far to move them along x, y and z.

  • clear (bool) -- Set the blocks that are left behind to air.

move_to(position, clear=True)[source]#

Move the blocks to a new position, and place them again.

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

  • clear (bool) -- Afterwards, fill the region that the blocks were in with air. That also removes the blocks just placed wherever the new region overlaps the old one.

to_cuboid()[source]#
Returns:

The blocks, as nested lists indexed [x][y][z].

Return type:

list[list[list[Item] | ndarray] | ndarray] | ndarray

save_blocks(file)[source]#

Save the blocks to a JSON file, with save_items().

Parameters:

file (Path) -- The file to write.

load_blocks(file)[source]#

Replace the blocks with those in a JSON file, and place them at the same position. The blocks that were there before are not cleared.

Parameters:

file (Path) -- The file to read, as saved by save_items().

Raises:

ValueError -- If the file does not hold a cuboid.

Files#

mciwb.cuboids.save_items(items, filename)[source]#

Save a cuboid, a profile (a 2D list) or a row (a list) of Item to a JSON file.

Parameters:
Raises:

ValueError -- If items is not a regular 1D, 2D or 3D array of items.

mciwb.cuboids.load_items(filename, dimensions=None)[source]#

Load the items that save_items() saved.

Parameters:
  • filename (Path | str) -- The file to read.

  • dimensions (int | None) -- If given, the number of dimensions (1, 2 or 3) that the file must hold.

Returns:

The row, profile or cuboid of Item.

Raises:

ValueError -- If the file does not hold items, or holds a different number of dimensions from dimensions.

Return type:

list[list[list[Item] | ndarray] | ndarray] | ndarray | list[list[Item] | ndarray] | list[Item]

mciwb.cuboids.ITEM_KEY = '__Item__'#

The key that marks an Item in a saved JSON file.