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.
A cuboid of blocks placed in the world, which can then be moved and rotated. |
|
Read the blocks of a region of the world, one block at a time. |
|
Get the type of the block at a position, over RCON. |
|
Save a cuboid, a profile (a 2D list) or a row (a list) of |
|
Load the items that |
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:
client (Client) -- The RCON client, from
get_client().vol (Volume) -- The region to read.
- Returns:
A cuboid of
Item, as nested lists. Block states such as the facing of stairs are not read: for those useSchematic.from_world().- Raises:
ValueError -- If a block can not be read (see
get_block()).- Return type:
- 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:
client (Client) -- The RCON client, from
get_client().pos (Vec3) -- The position of the block.
- 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 afterMINECRAFT_VERSION.- Return type:
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
setblockcommand.- Parameters:
client (Client) -- The RCON client, from
get_client().position (Vec3) -- Where to put the blocks.
cube (list[list[list[Item] | ndarray] | ndarray] | ndarray | list[list[Item] | ndarray] | list[Item]) -- The blocks: a 3D array of
Item, indexedcube[x][y][z].anchor (Anchor3) -- Which point of the cuboid goes at position.
render (bool) -- False to make the object without placing its blocks.
- 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:
client (Client) -- The RCON client, from
get_client().volume (Volume) -- The region to read.
- Returns:
The Blocks object. Its anchor is the bottom north west corner, at the
positionof volume.- Return type:
- 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
Itemto a JSON file.
- mciwb.cuboids.load_items(filename, dimensions=None)[source]#
Load the items that
save_items()saved.