amulet.utils.world_utils module

amulet.utils.world_utils.block_coords_to_chunk_coords(*args, sub_chunk_size=16)[source]

Converts the supplied block coordinates into chunk coordinates

Parameters
  • args (int) – The coordinate of the block(s)

  • sub_chunk_size (int) – The dimension of the chunk (Optional. Default 16)

Return type

Tuple[int, ...]

Returns

The resulting chunk coordinates in (x, z) order

amulet.utils.world_utils.chunk_coords_to_block_coords(x, z, chunk_x_size=16, chunk_z_size=16)[source]

Converts the supplied chunk coordinates into block coordinates

Parameters
  • x (int) – The x coordinate of the chunk

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

  • chunk_x_size (int) – The dimension of the chunk in the x direction (Optional. Default 16)

  • chunk_z_size (int) – The dimension of the chunk in the z direction (Optional. Default 16)

Return type

Tuple[int, int]

Returns

The resulting block coordinates in (x, z) order

amulet.utils.world_utils.chunk_coords_to_region_coords(cx, cz)[source]

Converts the supplied chunk coordinates into region coordinates

Parameters
  • cx (int) – The x coordinate of the chunk

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

Return type

Tuple[int, int]

Returns

The resulting region coordinates in (x, z) order

amulet.utils.world_utils.region_coords_to_chunk_coords(rx, rz)[source]

Converts the supplied region coordinates into the minimum chunk coordinates of that region

Parameters
  • rx (int) – The x coordinate of the region

  • rz (int) – The y coordinate of the region

Return type

Tuple[int, int]

Returns

The resulting minimum chunk coordinates of that region in (x, z) order

amulet.utils.world_utils.blocks_slice_to_chunk_slice(blocks_slice, chunk_shape, chunk_coord)[source]

Converts the supplied blocks slice into chunk slice

Parameters
  • blocks_slice (slice) – The slice of the blocks

  • chunk_shape (int) – The shape of the chunk in this direction

  • chunk_coord (int) – The coordinate of the chunk in this direction

Return type

slice

Returns

The resulting chunk slice

amulet.utils.world_utils.gunzip(data)[source]

Decompresses data that is in Gzip format

amulet.utils.world_utils.from_nibble_array(arr)[source]

Unpacks a flat nibble array into a full size numpy array

Parameters

arr (ndarray) – The nibble array

Return type

ndarray

Returns

The resulting array

amulet.utils.world_utils.to_nibble_array(arr)[source]

packs a full size numpy array into a nibble array.

Parameters

arr (ndarray) – Full numpy array

Return type

ndarray

Returns

The nibble array

amulet.utils.world_utils.decode_long_array(long_array, size, bits_per_entry, dense=True, signed=False)[source]

Decode a long array (from BlockStates or Heightmaps)

Parameters
  • long_array (ndarray) – Encoded long array

  • size (int) – The expected size of the returned array

  • bits_per_entry (int) – The number of bits per entry in the encoded array.

  • dense – If true the long arrays will be treated as a bit stream. If false they are distinct values with padding

  • signed (bool) – Should the returned array be signed.

Return type

ndarray

Returns

Decoded array as numpy array

amulet.utils.world_utils.encode_long_array(array, bits_per_entry=None, dense=True, min_bits_per_entry=1)[source]

Encode a long array (from BlockStates or Heightmaps)

Parameters
  • array (ndarray) – A numpy array of the data to be encoded.

  • bits_per_entry (Optional[int]) – The number of bits to use to store each value. If left as None will use the smallest bits per entry.

  • dense (bool) – If true the long arrays will be treated as a bit stream. If false they are distinct values with padding

  • min_bits_per_entry – The mimimum value that bits_per_entry can be. If it is less than this it will be capped at this value.

Return type

ndarray

Returns

Encoded array as numpy array

amulet.utils.world_utils.get_size(obj, seen=None)[source]

Recursively finds size of objects

amulet.utils.world_utils.get_smallest_dtype(arr, uint=True)[source]

Returns the smallest dtype (number) that the array can afford

Parameters
  • arr (ndarray) – The array to check on

  • uint (bool) – Should the array fit in uint or not (default: True)

Return type

int

Returns

The number of bits all the elements can be represented with