tiles¶
Module with structure to process Terraria worlds’ tile matrixes.
array_dtype¶
Submodule containing TILE_DTYPE.
- lihzahrd.terraria.world.tiles.array_dtype.TILE_DTYPE = dtype([('block_id', '<u2'), ('block_u', '<u2'), ('block_v', '<u2'), ('block_shape', 'u1'), ('block_inactive', '?'), ('block_paint', 'u1'), ('block_illuminant', '?'), ('block_echo', '?'), ('wall_id', '<u2'), ('wall_paint', 'u1'), ('wall_illuminant', '?'), ('wall_echo', '?'), ('liquid_id', 'u1'), ('liquid_volume', 'u1'), ('wire_red', '?'), ('wire_green', '?'), ('wire_blue', '?'), ('wire_yellow', '?'), ('wire_actuator', '?')])¶
The
numpy.dtypewith whichWorldTilesstores tiles.The fields
block_idandwall_idare special:if their value is
0, it means that the tile has no block or wall presentif their value is
1or more, if means that a block or wall is present, and that its ID is the value, minus one.
tile¶
Submodule containing Tile.
- class lihzahrd.terraria.world.tiles.tile.Tile(*, block: BlockBase | None = None, wall: WallBase | None = None, liquid: LiquidBase | None = None, wiring: Wiring | None = None)¶
Developer-friendly representation of a tile in a Terraria world, with its characteristics.
- liquid: LiquidBase | None¶
The liquid present in the tile, or
Noneif there isn’t any.
- to_scalar() ndarray[tuple[Literal[1]], Any]¶
Convert a
Tileinto a scalarnumpy.ndarrayofTILE_DTYPE.- Parameters:
self – The
Tileto convert.- Returns:
The resulting scalar
numpy.ndarray.
- __array__(dtype=None, copy=None) ndarray[tuple[Literal[1]], Any]¶
Allow
numpyto treat this as an array.See also
- classmethod from_scalar(scalar: ndarray[tuple[Literal[1]], Any], *, frame_important: WorldFrameImportant) Tile¶
Convert a scalar
numpy.ndarrayofTILE_DTYPEinto aTile.Tip
Useful to get a
Tileout ofWorldTiles!- Parameters:
scalar – The scalar
numpy.ndarrayofTILE_DTYPEto convert.frame_important – The value of
WorldFrameImportantto use to determine which blocks should have associated UV values, and which shouldn’t.
- Returns:
The resulting
Tile.
wiring¶
Submodule containing Tile.
world_tiles¶
Submodule containing WorldTiles.
- class lihzahrd.terraria.world.tiles.world_tiles.WorldTiles(value: Value)¶
Bases:
OpCollection[ndarray[tuple[int,int],Any]],PackPrimitive[ndarray[tuple[int,int],Any]]PackPrimitiveof the tiles present in a world.Internally, it’s represented by a 2-dimensional
numpy.ndarrayof theTILE_DTYPE.- classmethod _read_batch_to_ndarray(fp: FileProcessor, data: ndarray[tuple[int], Any], *, frame_important: WorldFrameImportant) int¶
Read a batch of tiles to the given 1-dimensional
numpy.ndarray.The tiles are written to the array starting from offset 0 and ending at an unknown offset, determined by the read
repeatvalue.The
repeatvalue, or the number of read tiles, is then returned.- Parameters:
fp – The
FileProcessorto read tiles from.data – The
numpy.ndarrayto write tiles into.frame_important – The value of
WorldFrameImportantto use to determine which blocks have associated UV values, and which don’t.
- Returns:
The number of read tiles (
repeatvalue).
- classmethod _read_column_to_ndarray(fp: FileProcessor, data: ndarray[tuple[int], Any], *, frame_important: WorldFrameImportant) None¶
Read a column of tiles to the given 1-dimensional
numpy.ndarray.The tiles are written to the array from start to end, and are read from the
FileProcessoruntil the array has no more room.- Parameters:
fp – The
FileProcessorto read tiles from.data – The
numpy.ndarrayto write tiles into.frame_important – The value of
WorldFrameImportantto use to determine which blocks have associated UV values, and which don’t.
- classmethod _read_matrix_to_ndarray(fp: FileProcessor, data: ndarray[tuple[int, int], Any], *, frame_important: WorldFrameImportant) None¶
Read the whole tile matrix to the given 2-dimensional
numpy.ndarray.For each column of the matrix,
_read_column_to_ndarray()is called to fill it.- Parameters:
fp – The
FileProcessorto read tiles from.data – The
numpy.ndarrayto write tiles into.frame_important – The value of
WorldFrameImportantto use to determine which blocks have associated UV values, and which don’t.
- classmethod _create_difference_matrix(value: ndarray[tuple[int, int], Any]) ndarray[tuple[int, int], BoolDType]¶
Given a tile matrix, create a new boolean matrix where the true values indicate which tiles mark the start of a new tile batch.
- Parameters:
value – The
numpy.ndarrayto use for the computation.- Returns:
The resulting matrix.
- classmethod _create_tile_batches()¶
Given a tile matrix, return a
listof tile batches.The first element of each
tupleis the tile scalar to write, still innumpy.ndarrayformat, and the second element is how many times the tile is repeated vertically.- Parameters:
value – The
numpy.ndarrayto use for the computation.- Returns:
- classmethod _write_tile_batch()¶
Write a single batch of tiles to the given
FileProcessor.- Parameters:
fp – The
FileProcessorto write tiles to.batch – The batch of tiles to write, in the form of a
tuplereturned by_create_tile_batches().frame_important – The value of
WorldFrameImportantto use to determine which blocks have associated UV values, and which don’t.
- exception InvalidShapeError(value: Value)¶
Bases:
ValidationErrorThe shape of the underlying
numpy.ndarraydoes not match the given world size.