Skip to content

Commit

Permalink
Replaced depreciated Tuple, List and Dict type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlegiantJGC committed May 24, 2024
1 parent 93c7fa7 commit e3b4316
Show file tree
Hide file tree
Showing 41 changed files with 105 additions and 172 deletions.
10 changes: 5 additions & 5 deletions minecraft_model_reader/api/amulet/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from sys import getsizeof
import re
from typing import Dict, Iterable, Tuple, Union, Optional, Any
from typing import Iterable, Union, Optional, Any
import amulet_nbt

PropertyValueType = Union[
Expand All @@ -12,7 +12,7 @@
amulet_nbt.TAG_Long,
amulet_nbt.TAG_String,
]
PropertyType = Dict[str, PropertyValueType]
PropertyType = dict[str, PropertyValueType]

PropertyDataTypes = (
amulet_nbt.TAG_Byte,
Expand Down Expand Up @@ -249,7 +249,7 @@ def base_block(self) -> Block:
)

@property
def extra_blocks(self) -> Tuple[Block, ...]:
def extra_blocks(self) -> tuple[Block, ...]:
"""
Returns a tuple of the extra blocks contained in the Block instance
Expand All @@ -258,7 +258,7 @@ def extra_blocks(self) -> Tuple[Block, ...]:
return self._extra_blocks

@property
def block_tuple(self) -> Tuple[Block, ...]:
def block_tuple(self) -> tuple[Block, ...]:
"""
Returns the stack of blocks represented by this object as a tuple.
This is a tuple of base_block and extra_blocks
Expand All @@ -269,7 +269,7 @@ def block_tuple(self) -> Tuple[Block, ...]:
@staticmethod
def parse_blockstate_string(
blockstate: str, snbt: bool = False
) -> Tuple[str, str, PropertyType]:
) -> tuple[str, str, PropertyType]:
"""Parse a blockstate string and return the data.
:param blockstate: The blockstate to parse
Expand Down
36 changes: 18 additions & 18 deletions minecraft_model_reader/api/mesh/block/cube.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from typing import Dict, Tuple, Optional
from typing import Optional
import numpy
import itertools

from minecraft_model_reader.api.mesh.block.block_mesh import FACE_KEYS, BlockMesh

BoundsType = Tuple[Tuple[float, float], Tuple[float, float], Tuple[float, float]]
TextureUVType = Tuple[
Tuple[float, float, float, float],
Tuple[float, float, float, float],
Tuple[float, float, float, float],
Tuple[float, float, float, float],
Tuple[float, float, float, float],
Tuple[float, float, float, float],
BoundsType = tuple[tuple[float, float], tuple[float, float], tuple[float, float]]
TextureUVType = tuple[
tuple[float, float, float, float],
tuple[float, float, float, float],
tuple[float, float, float, float],
tuple[float, float, float, float],
tuple[float, float, float, float],
tuple[float, float, float, float],
]


Expand Down Expand Up @@ -71,10 +71,10 @@ def get_cube(
south: str,
west: str,
transparency=0,
tint: Tuple[int, int, int] = (1, 1, 1),
tint: tuple[int, int, int] = (1, 1, 1),
bounds: BoundsType = ((0, 1), (0, 1), (0, 1)),
texture_uv: TextureUVType = ((0, 0, 1, 1),) * 6,
do_not_cull: Tuple[bool, bool, bool, bool, bool, bool] = (
do_not_cull: tuple[bool, bool, bool, bool, bool, bool] = (
False,
False,
False,
Expand All @@ -84,13 +84,13 @@ def get_cube(
),
):
box_coordinates = numpy.array(list(itertools.product(*bounds)))
_texture_uv: Dict[Optional[str], numpy.ndarray] = {
_texture_uv: dict[Optional[str], numpy.ndarray] = {
face: numpy.array(texture_uv[i], float) for i, face in enumerate(cube_face_lut)
}
_verts: Dict[Optional[str], numpy.ndarray] = {}
_texture_coords: Dict[Optional[str], numpy.ndarray] = {}
_tint_verts: Dict[Optional[str], numpy.ndarray] = {}
_tri_faces: Dict[Optional[str], numpy.ndarray] = {}
_verts: dict[Optional[str], numpy.ndarray] = {}
_texture_coords: dict[Optional[str], numpy.ndarray] = {}
_tint_verts: dict[Optional[str], numpy.ndarray] = {}
_tri_faces: dict[Optional[str], numpy.ndarray] = {}
for _face_dir in cube_face_lut:
_verts[_face_dir] = box_coordinates[
cube_face_lut[_face_dir]
Expand All @@ -105,7 +105,7 @@ def get_cube(
(down, up, north, east, south, west), return_inverse=True
)
texture_paths = tuple(texture_paths)
_tri_texture_index: Dict[str, numpy.ndarray] = {
_tri_texture_index: dict[Optional[str], numpy.ndarray] = {
side: numpy.full(2, texture_index[side_index], dtype=numpy.uint32)
for side_index, side in enumerate(cube_face_lut)
}
Expand Down Expand Up @@ -144,6 +144,6 @@ def get_unit_cube(
south: str,
west: str,
transparency: int = 0,
tint: Tuple[int, int, int] = (1, 1, 1),
tint: tuple[int, int, int] = (1, 1, 1),
) -> BlockMesh:
return get_cube(down, up, north, east, south, west, transparency, tint)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Dict, Tuple, Generator, Optional
from typing import Generator, Optional
import os
import json
import copy
Expand All @@ -13,10 +13,10 @@ class BaseResourcePackManager:
"""The base class that all resource pack managers must inherit from. Defines the base api."""

def __init__(self):
self._packs: List[BaseResourcePack] = []
self._packs: list[BaseResourcePack] = []
self._missing_block = None
self._texture_is_transparent = {}
self._cached_models: Dict[Block, BlockMesh] = {}
self._cached_models: dict[Block, BlockMesh] = {}

@property
def pack_paths(self):
Expand Down Expand Up @@ -55,7 +55,7 @@ def missing_block(self) -> BlockMesh:
return self._missing_block

@property
def textures(self) -> Tuple[str, ...]:
def textures(self) -> tuple[str, ...]:
"""Returns a tuple of all the texture paths in the resource pack."""
raise NotImplementedError

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Tuple

from minecraft_model_reader.api.mesh.block import BlockMesh
from minecraft_model_reader.api import Block
from minecraft_model_reader.api.resource_pack.bedrock.blockshapes.base_blockshape import (
Expand Down Expand Up @@ -29,7 +27,7 @@ def get_block_model(
east: str,
south: str,
west: str,
transparency: Tuple[bool, bool, bool, bool, bool, bool],
transparency: tuple[bool, bool, bool, bool, bool, bool],
) -> BlockMesh:
return BlockMesh(3, {}, {}, {}, {}, {}, (), 2)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Tuple

from minecraft_model_reader.api.mesh.block import BlockMesh
from minecraft_model_reader.api import Block

Expand All @@ -26,6 +24,6 @@ def get_block_model(
east: str,
south: str,
west: str,
transparency: Tuple[bool, bool, bool, bool, bool, bool],
transparency: tuple[bool, bool, bool, bool, bool, bool],
) -> BlockMesh:
raise NotImplementedError
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Tuple

from minecraft_model_reader.api.resource_pack.bedrock.blockshapes.cross_texture import (
Cross,
)
Expand All @@ -20,7 +18,7 @@ def get_block_model(
east: str,
south: str,
west: str,
transparency: Tuple[bool, bool, bool, bool, bool, bool],
transparency: tuple[bool, bool, bool, bool, bool, bool],
) -> BlockMesh:
return super().get_block_model(
block, north, north, north, north, north, north, transparency
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Tuple

from minecraft_model_reader.api.resource_pack.bedrock.blockshapes.partial_block import (
PartialBlock,
)
Expand All @@ -18,7 +16,7 @@ def blockshape(self) -> str:

def bounds(
self, block: Block
) -> Tuple[Tuple[float, float], Tuple[float, float], Tuple[float, float]]:
) -> tuple[tuple[float, float], tuple[float, float], tuple[float, float]]:
return (
(1 / 16 + block.properties["bite_counter"].py_data * 2 / 16, 15 / 16),
(0, 0.5),
Expand All @@ -29,7 +27,7 @@ def texture_index(self, block: Block, aux_value: int) -> int:
return min(block.properties["bite_counter"].py_data, 1)

@property
def do_not_cull(self) -> Tuple[bool, bool, bool, bool, bool, bool]:
def do_not_cull(self) -> tuple[bool, bool, bool, bool, bool, bool]:
return False, True, True, True, True, True


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Tuple

from minecraft_model_reader.api.resource_pack.bedrock.blockshapes.partial_block import (
PartialBlock,
)
Expand All @@ -14,14 +12,14 @@ def blockshape(self) -> str:

def bounds(
self, block: Block
) -> Tuple[Tuple[float, float], Tuple[float, float], Tuple[float, float]]:
) -> tuple[tuple[float, float], tuple[float, float], tuple[float, float]]:
return (1 / 16, 15 / 16), (0, 14 / 16), (1 / 16, 15 / 16)

def texture_index(self, block: Block, aux_value: int) -> int:
return 0

@property
def do_not_cull(self) -> Tuple[bool, bool, bool, bool, bool, bool]:
def do_not_cull(self) -> tuple[bool, bool, bool, bool, bool, bool]:
return False, True, True, True, True, True

def get_block_model(
Expand All @@ -33,7 +31,7 @@ def get_block_model(
east: str,
south: str,
west: str,
transparency: Tuple[bool, bool, bool, bool, bool, bool],
transparency: tuple[bool, bool, bool, bool, bool, bool],
modify_uv=True,
) -> BlockMesh:
rotation = {2: 2, 3: 0, 4: 1, 5: 3}.get(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Tuple

from minecraft_model_reader.api.resource_pack.bedrock.blockshapes.partial_block import (
PartialBlock,
)
Expand All @@ -21,11 +19,11 @@ def texture_index(self, block: Block, aux_value: int) -> int:

def bounds(
self, block: Block
) -> Tuple[Tuple[float, float], Tuple[float, float], Tuple[float, float]]:
) -> tuple[tuple[float, float], tuple[float, float], tuple[float, float]]:
return (0, 1), (0, 2 / 16), (0, 1)

@property
def do_not_cull(self) -> Tuple[bool, bool, bool, bool, bool, bool]:
def do_not_cull(self) -> tuple[bool, bool, bool, bool, bool, bool]:
return False, True, False, False, False, False

def get_block_model(
Expand All @@ -37,7 +35,7 @@ def get_block_model(
east: str,
south: str,
west: str,
transparency: Tuple[bool, bool, bool, bool, bool, bool],
transparency: tuple[bool, bool, bool, bool, bool, bool],
) -> BlockMesh:
return (
super()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from typing import Tuple
import numpy

from minecraft_model_reader.api.mesh.block import BlockMesh
Expand All @@ -22,7 +21,7 @@ def texture_index(self, block: Block, aux_value: int) -> int:
return aux_value % 16

@property
def tint(self) -> Tuple[float, float, float]:
def tint(self) -> tuple[float, float, float]:
return 1, 1, 1

def get_block_model(
Expand All @@ -34,7 +33,7 @@ def get_block_model(
east: str,
south: str,
west: str,
transparency: Tuple[bool, bool, bool, bool, bool, bool],
transparency: tuple[bool, bool, bool, bool, bool, bool],
) -> BlockMesh:
return BlockMesh(
3,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Tuple

from minecraft_model_reader.api.resource_pack.bedrock.blockshapes.cross_texture import (
Cross,
)
Expand All @@ -11,7 +9,7 @@ def blockshape(self) -> str:
return "cross_texture_green"

@property
def tint(self) -> Tuple[float, float, float]:
def tint(self) -> tuple[float, float, float]:
return 0, 1, 0


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Tuple

from minecraft_model_reader.api.mesh.block import BlockMesh
from minecraft_model_reader.api import Block
from minecraft_model_reader.api.mesh.block.cube import get_unit_cube
Expand All @@ -20,7 +18,7 @@ def get_block_model(
east: str,
south: str,
west: str,
transparency: Tuple[bool, bool, bool, bool, bool, bool],
transparency: tuple[bool, bool, bool, bool, bool, bool],
) -> BlockMesh:
return get_unit_cube(down, up, north, east, south, west, int(any(transparency)))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Tuple

from minecraft_model_reader.api.mesh.block import BlockMesh
from minecraft_model_reader.api import Block
from minecraft_model_reader.api.mesh.block.cube import get_unit_cube
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Tuple, Dict

from minecraft_model_reader.api.mesh.block import BlockMesh
from minecraft_model_reader.api import Block
from minecraft_model_reader.api.resource_pack.bedrock.blockshapes.cube import Cube
Expand All @@ -26,7 +24,7 @@ def get_block_model(
east: str,
south: str,
west: str,
transparency: Tuple[bool, bool, bool, bool, bool, bool],
transparency: tuple[bool, bool, bool, bool, bool, bool],
) -> BlockMesh:
if block.properties["upper_block_bit"].py_data:
return super().get_block_model(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Tuple

from minecraft_model_reader.api.resource_pack.bedrock.blockshapes.cross_texture import (
Cross,
)
Expand Down Expand Up @@ -27,7 +25,7 @@ def get_block_model(
east: str,
south: str,
west: str,
transparency: Tuple[bool, bool, bool, bool, bool, bool],
transparency: tuple[bool, bool, bool, bool, bool, bool],
) -> BlockMesh:
if block.properties["upper_block_bit"].py_data:
return super().get_block_model(block, up, up, up, up, up, up, transparency)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Tuple

from minecraft_model_reader.api.resource_pack.bedrock.blockshapes.partial_block import (
PartialBlock,
)
Expand All @@ -13,11 +11,11 @@ def blockshape(self) -> str:

def bounds(
self, block: Block
) -> Tuple[Tuple[float, float], Tuple[float, float], Tuple[float, float]]:
) -> tuple[tuple[float, float], tuple[float, float], tuple[float, float]]:
return (0, 1), (0, 12 / 16), (0, 1)

@property
def do_not_cull(self) -> Tuple[bool, bool, bool, bool, bool, bool]:
def do_not_cull(self) -> tuple[bool, bool, bool, bool, bool, bool]:
return False, True, False, False, False, False


Expand Down
Loading

0 comments on commit e3b4316

Please sign in to comment.