amulet-core 1.9.19__py3-none-any.whl → 1.9.20__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of amulet-core might be problematic. Click here for more details.
- amulet/__init__.py +27 -27
- amulet/__pyinstaller/__init__.py +2 -2
- amulet/__pyinstaller/hook-amulet.py +4 -4
- amulet/_version.py +21 -21
- amulet/api/__init__.py +2 -2
- amulet/api/abstract_base_entity.py +128 -128
- amulet/api/block.py +630 -630
- amulet/api/block_entity.py +71 -71
- amulet/api/cache.py +107 -107
- amulet/api/chunk/__init__.py +6 -6
- amulet/api/chunk/biomes.py +207 -207
- amulet/api/chunk/block_entity_dict.py +175 -175
- amulet/api/chunk/blocks.py +46 -46
- amulet/api/chunk/chunk.py +389 -389
- amulet/api/chunk/entity_list.py +75 -75
- amulet/api/chunk/status.py +167 -167
- amulet/api/data_types/__init__.py +4 -4
- amulet/api/data_types/generic_types.py +4 -4
- amulet/api/data_types/operation_types.py +16 -16
- amulet/api/data_types/world_types.py +49 -49
- amulet/api/data_types/wrapper_types.py +71 -71
- amulet/api/entity.py +74 -74
- amulet/api/errors.py +119 -119
- amulet/api/history/__init__.py +36 -36
- amulet/api/history/base/__init__.py +3 -3
- amulet/api/history/base/base_history.py +26 -26
- amulet/api/history/base/history_manager.py +63 -63
- amulet/api/history/base/revision_manager.py +73 -73
- amulet/api/history/changeable.py +15 -15
- amulet/api/history/data_types.py +7 -7
- amulet/api/history/history_manager/__init__.py +3 -3
- amulet/api/history/history_manager/container.py +102 -102
- amulet/api/history/history_manager/database.py +279 -279
- amulet/api/history/history_manager/meta.py +93 -93
- amulet/api/history/history_manager/object.py +116 -116
- amulet/api/history/revision_manager/__init__.py +2 -2
- amulet/api/history/revision_manager/disk.py +33 -33
- amulet/api/history/revision_manager/ram.py +12 -12
- amulet/api/item.py +75 -75
- amulet/api/level/__init__.py +4 -4
- amulet/api/level/base_level/__init__.py +1 -1
- amulet/api/level/base_level/base_level.py +1035 -1026
- amulet/api/level/base_level/chunk_manager.py +227 -227
- amulet/api/level/base_level/clone.py +389 -389
- amulet/api/level/base_level/player_manager.py +101 -101
- amulet/api/level/immutable_structure/__init__.py +1 -1
- amulet/api/level/immutable_structure/immutable_structure.py +94 -94
- amulet/api/level/immutable_structure/void_format_wrapper.py +117 -117
- amulet/api/level/structure.py +22 -22
- amulet/api/level/world.py +19 -19
- amulet/api/partial_3d_array/__init__.py +2 -2
- amulet/api/partial_3d_array/base_partial_3d_array.py +263 -263
- amulet/api/partial_3d_array/bounded_partial_3d_array.py +528 -528
- amulet/api/partial_3d_array/data_types.py +15 -15
- amulet/api/partial_3d_array/unbounded_partial_3d_array.py +229 -229
- amulet/api/partial_3d_array/util.py +152 -152
- amulet/api/player.py +65 -65
- amulet/api/registry/__init__.py +2 -2
- amulet/api/registry/base_registry.py +34 -34
- amulet/api/registry/biome_manager.py +153 -153
- amulet/api/registry/block_manager.py +156 -156
- amulet/api/selection/__init__.py +2 -2
- amulet/api/selection/abstract_selection.py +315 -315
- amulet/api/selection/box.py +805 -805
- amulet/api/selection/group.py +488 -488
- amulet/api/structure.py +37 -37
- amulet/api/wrapper/__init__.py +8 -8
- amulet/api/wrapper/chunk/interface.py +441 -441
- amulet/api/wrapper/chunk/translator.py +567 -567
- amulet/api/wrapper/format_wrapper.py +772 -772
- amulet/api/wrapper/structure_format_wrapper.py +116 -116
- amulet/api/wrapper/world_format_wrapper.py +63 -63
- amulet/level/__init__.py +1 -1
- amulet/level/formats/anvil_forge_world.py +40 -40
- amulet/level/formats/anvil_world/__init__.py +3 -3
- amulet/level/formats/anvil_world/_sector_manager.py +291 -384
- amulet/level/formats/anvil_world/data_pack/__init__.py +2 -2
- amulet/level/formats/anvil_world/data_pack/data_pack.py +224 -224
- amulet/level/formats/anvil_world/data_pack/data_pack_manager.py +77 -77
- amulet/level/formats/anvil_world/dimension.py +177 -177
- amulet/level/formats/anvil_world/format.py +769 -769
- amulet/level/formats/anvil_world/region.py +384 -384
- amulet/level/formats/construction/__init__.py +3 -3
- amulet/level/formats/construction/format_wrapper.py +515 -515
- amulet/level/formats/construction/interface.py +134 -134
- amulet/level/formats/construction/section.py +60 -60
- amulet/level/formats/construction/util.py +165 -165
- amulet/level/formats/leveldb_world/__init__.py +3 -3
- amulet/level/formats/leveldb_world/chunk.py +33 -33
- amulet/level/formats/leveldb_world/dimension.py +385 -419
- amulet/level/formats/leveldb_world/format.py +659 -641
- amulet/level/formats/leveldb_world/interface/chunk/__init__.py +36 -36
- amulet/level/formats/leveldb_world/interface/chunk/base_leveldb_interface.py +836 -836
- amulet/level/formats/leveldb_world/interface/chunk/generate_interface.py +31 -31
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_0.py +30 -30
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_1.py +12 -12
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_10.py +12 -12
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_11.py +12 -12
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_12.py +12 -12
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_13.py +12 -12
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_14.py +12 -12
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_15.py +12 -12
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_16.py +12 -12
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_17.py +12 -12
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_18.py +12 -12
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_19.py +12 -12
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_2.py +12 -12
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_20.py +12 -12
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_21.py +12 -12
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_22.py +12 -12
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_23.py +10 -10
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_24.py +10 -10
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_25.py +24 -24
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_26.py +10 -10
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_27.py +10 -10
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_28.py +10 -10
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_29.py +33 -33
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_3.py +57 -57
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_30.py +10 -10
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_31.py +10 -10
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_32.py +10 -10
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_33.py +10 -10
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_34.py +10 -10
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_35.py +10 -10
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_36.py +10 -10
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_37.py +10 -10
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_38.py +10 -10
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_39.py +12 -12
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_4.py +12 -12
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_40.py +16 -16
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_5.py +12 -12
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_6.py +12 -12
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_7.py +12 -12
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_8.py +180 -180
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_9.py +18 -18
- amulet/level/formats/leveldb_world/interface/chunk/leveldb_chunk_versions.py +79 -79
- amulet/level/formats/mcstructure/__init__.py +3 -3
- amulet/level/formats/mcstructure/chunk.py +50 -50
- amulet/level/formats/mcstructure/format_wrapper.py +408 -408
- amulet/level/formats/mcstructure/interface.py +175 -175
- amulet/level/formats/schematic/__init__.py +3 -3
- amulet/level/formats/schematic/chunk.py +55 -55
- amulet/level/formats/schematic/data_types.py +4 -4
- amulet/level/formats/schematic/format_wrapper.py +373 -373
- amulet/level/formats/schematic/interface.py +142 -142
- amulet/level/formats/sponge_schem/__init__.py +4 -4
- amulet/level/formats/sponge_schem/chunk.py +62 -62
- amulet/level/formats/sponge_schem/format_wrapper.py +463 -463
- amulet/level/formats/sponge_schem/interface.py +118 -118
- amulet/level/formats/sponge_schem/varint/__init__.py +1 -1
- amulet/level/formats/sponge_schem/varint/varint.py +87 -87
- amulet/level/interfaces/chunk/anvil/anvil_0.py +72 -72
- amulet/level/interfaces/chunk/anvil/anvil_1444.py +336 -336
- amulet/level/interfaces/chunk/anvil/anvil_1466.py +94 -94
- amulet/level/interfaces/chunk/anvil/anvil_1467.py +37 -37
- amulet/level/interfaces/chunk/anvil/anvil_1484.py +20 -20
- amulet/level/interfaces/chunk/anvil/anvil_1503.py +20 -20
- amulet/level/interfaces/chunk/anvil/anvil_1519.py +34 -34
- amulet/level/interfaces/chunk/anvil/anvil_1901.py +20 -20
- amulet/level/interfaces/chunk/anvil/anvil_1908.py +20 -20
- amulet/level/interfaces/chunk/anvil/anvil_1912.py +21 -21
- amulet/level/interfaces/chunk/anvil/anvil_1934.py +20 -20
- amulet/level/interfaces/chunk/anvil/anvil_2203.py +69 -69
- amulet/level/interfaces/chunk/anvil/anvil_2529.py +19 -19
- amulet/level/interfaces/chunk/anvil/anvil_2681.py +76 -76
- amulet/level/interfaces/chunk/anvil/anvil_2709.py +19 -19
- amulet/level/interfaces/chunk/anvil/anvil_2844.py +267 -267
- amulet/level/interfaces/chunk/anvil/anvil_3463.py +19 -19
- amulet/level/interfaces/chunk/anvil/anvil_na.py +607 -607
- amulet/level/interfaces/chunk/anvil/base_anvil_interface.py +326 -326
- amulet/level/load.py +59 -59
- amulet/level/loader.py +95 -95
- amulet/level/translators/chunk/bedrock/__init__.py +267 -267
- amulet/level/translators/chunk/bedrock/bedrock_nbt_blockstate_translator.py +46 -46
- amulet/level/translators/chunk/bedrock/bedrock_numerical_translator.py +39 -39
- amulet/level/translators/chunk/bedrock/bedrock_psudo_numerical_translator.py +37 -37
- amulet/level/translators/chunk/java/java_1_18_translator.py +40 -40
- amulet/level/translators/chunk/java/java_blockstate_translator.py +94 -94
- amulet/level/translators/chunk/java/java_numerical_translator.py +62 -62
- amulet/libs/leveldb/__init__.py +7 -7
- amulet/operations/__init__.py +5 -5
- amulet/operations/clone.py +18 -18
- amulet/operations/delete_chunk.py +32 -32
- amulet/operations/fill.py +30 -30
- amulet/operations/paste.py +65 -65
- amulet/operations/replace.py +58 -58
- amulet/utils/__init__.py +14 -14
- amulet/utils/format_utils.py +41 -41
- amulet/utils/generator.py +15 -15
- amulet/utils/matrix.py +243 -243
- amulet/utils/numpy_helpers.py +46 -46
- amulet/utils/world_utils.py +349 -349
- {amulet_core-1.9.19.dist-info → amulet_core-1.9.20.dist-info}/METADATA +97 -97
- amulet_core-1.9.20.dist-info/RECORD +208 -0
- amulet_core-1.9.19.dist-info/RECORD +0 -208
- {amulet_core-1.9.19.dist-info → amulet_core-1.9.20.dist-info}/WHEEL +0 -0
- {amulet_core-1.9.19.dist-info → amulet_core-1.9.20.dist-info}/entry_points.txt +0 -0
- {amulet_core-1.9.19.dist-info → amulet_core-1.9.20.dist-info}/top_level.txt +0 -0
|
@@ -1,153 +1,153 @@
|
|
|
1
|
-
from typing import Dict, overload, List, Union, Tuple, Generator, Iterable
|
|
2
|
-
from numpy import character, integer
|
|
3
|
-
|
|
4
|
-
from amulet_nbt import ByteTag, IntTag, ShortTag, LongTag, StringTag
|
|
5
|
-
from amulet.api.data_types import Int, BiomeType
|
|
6
|
-
from amulet.api.registry.base_registry import BaseRegistry
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class BiomeManager(BaseRegistry):
|
|
10
|
-
"""
|
|
11
|
-
Class to handle the mappings between biome strings and their index-based internal IDs
|
|
12
|
-
"""
|
|
13
|
-
|
|
14
|
-
def __init__(self, biomes: Iterable[BiomeType] = ()):
|
|
15
|
-
"""
|
|
16
|
-
Creates a new BiomeManager object
|
|
17
|
-
"""
|
|
18
|
-
self._index_to_biome: List[BiomeType] = []
|
|
19
|
-
self._biome_to_index: Dict[BiomeType, int] = {}
|
|
20
|
-
for biome in biomes:
|
|
21
|
-
# if a list is given it is assumed that the biome palette will be the same size as the list.
|
|
22
|
-
# Ensure that if a value is duplicated it will appear twice in the list
|
|
23
|
-
assert isinstance(biome, str), f"biome must be a string. Got {biome}"
|
|
24
|
-
if biome not in self._biome_to_index:
|
|
25
|
-
self._biome_to_index[biome] = len(self._index_to_biome)
|
|
26
|
-
self._index_to_biome.append(biome)
|
|
27
|
-
|
|
28
|
-
def __len__(self):
|
|
29
|
-
"""
|
|
30
|
-
The number of biomes in the registry.
|
|
31
|
-
|
|
32
|
-
>>> len(level.biome_palette)
|
|
33
|
-
10
|
|
34
|
-
"""
|
|
35
|
-
return len(self._index_to_biome)
|
|
36
|
-
|
|
37
|
-
def __contains__(self, item: Union[int, BiomeType]):
|
|
38
|
-
"""
|
|
39
|
-
Is the given biome string already in the registry.
|
|
40
|
-
|
|
41
|
-
>>> biome_string in level.biome_palette
|
|
42
|
-
True
|
|
43
|
-
>>> 7 in level.biome_palette
|
|
44
|
-
True
|
|
45
|
-
|
|
46
|
-
:param item: The biome or id to check.
|
|
47
|
-
"""
|
|
48
|
-
if isinstance(item, int):
|
|
49
|
-
return item < len(self._index_to_biome)
|
|
50
|
-
elif isinstance(item, str):
|
|
51
|
-
return item in self._biome_to_index
|
|
52
|
-
return False
|
|
53
|
-
|
|
54
|
-
def __iter__(self) -> Iterable[BiomeType]:
|
|
55
|
-
"""
|
|
56
|
-
Iterate through all biomes in the registry.
|
|
57
|
-
|
|
58
|
-
>>> for biome in level.biome_palette:
|
|
59
|
-
>>> ...
|
|
60
|
-
"""
|
|
61
|
-
yield from self._index_to_biome
|
|
62
|
-
|
|
63
|
-
@property
|
|
64
|
-
def biomes(self) -> Tuple[BiomeType]:
|
|
65
|
-
"""
|
|
66
|
-
The biomes in the registry as a tuple.
|
|
67
|
-
"""
|
|
68
|
-
return tuple(self._index_to_biome)
|
|
69
|
-
|
|
70
|
-
def values(self) -> Tuple[BiomeType]:
|
|
71
|
-
"""
|
|
72
|
-
The biomes in the registry as a tuple.
|
|
73
|
-
"""
|
|
74
|
-
return self.biomes
|
|
75
|
-
|
|
76
|
-
def items(self) -> Generator[Tuple[int, BiomeType], None, None]:
|
|
77
|
-
"""
|
|
78
|
-
A generator of the biome indexes and the biome strings.
|
|
79
|
-
"""
|
|
80
|
-
yield from enumerate(self._index_to_biome)
|
|
81
|
-
|
|
82
|
-
@overload
|
|
83
|
-
def __getitem__(self, item: BiomeType) -> int:
|
|
84
|
-
...
|
|
85
|
-
|
|
86
|
-
@overload
|
|
87
|
-
def __getitem__(self, item: Int) -> BiomeType:
|
|
88
|
-
...
|
|
89
|
-
|
|
90
|
-
@overload
|
|
91
|
-
def __getitem__(
|
|
92
|
-
self, item: Iterable[Union[Int, BiomeType]]
|
|
93
|
-
) -> List[Union[BiomeType, Int]]:
|
|
94
|
-
...
|
|
95
|
-
|
|
96
|
-
def __getitem__(self, item):
|
|
97
|
-
"""
|
|
98
|
-
If a string is passed to this function, it will return the internal ID/index of the biome.
|
|
99
|
-
|
|
100
|
-
If an int is given, this method will return the biome string at that specified index.
|
|
101
|
-
|
|
102
|
-
>>> level.biome_palette[biome]
|
|
103
|
-
7
|
|
104
|
-
>>> level.biome_palette[7]
|
|
105
|
-
biome
|
|
106
|
-
|
|
107
|
-
:param item: The string or int to get the mapping data of
|
|
108
|
-
:return: An int if a string was supplied, a string if an int was supplied
|
|
109
|
-
:raises KeyError if the requested item is not present.
|
|
110
|
-
"""
|
|
111
|
-
try:
|
|
112
|
-
return self._get_item(item)
|
|
113
|
-
except (KeyError, IndexError):
|
|
114
|
-
raise KeyError(
|
|
115
|
-
f"There is no {item} in the BiomeManager. "
|
|
116
|
-
f"You might want to use the `get_add_biome` function for the biome before accessing them."
|
|
117
|
-
)
|
|
118
|
-
|
|
119
|
-
def _get_item(self, item):
|
|
120
|
-
if isinstance(item, (str, character, StringTag)):
|
|
121
|
-
return self._biome_to_index[str(item)]
|
|
122
|
-
elif isinstance(item, (int, integer, ByteTag, ShortTag, IntTag, LongTag)):
|
|
123
|
-
return self._index_to_biome[int(item)]
|
|
124
|
-
# if it isn't an int or string assume an iterable of the above.
|
|
125
|
-
return [self._get_item(i) for i in item]
|
|
126
|
-
|
|
127
|
-
def get_add_biome(self, biome: BiomeType) -> int:
|
|
128
|
-
"""
|
|
129
|
-
Adds a biome string to the internal biome string/ID mappings.
|
|
130
|
-
|
|
131
|
-
If the biome already exists in the mappings, the existing ID is returned.
|
|
132
|
-
|
|
133
|
-
:param biome: The biome string to add to the manager
|
|
134
|
-
:return: The internal ID of the biome
|
|
135
|
-
"""
|
|
136
|
-
assert isinstance(biome, str), f"biome must be a string. Got {biome}"
|
|
137
|
-
if biome not in self._biome_to_index:
|
|
138
|
-
self._biome_to_index[biome] = len(self._index_to_biome)
|
|
139
|
-
self._index_to_biome.append(biome)
|
|
140
|
-
return self._biome_to_index[biome]
|
|
141
|
-
|
|
142
|
-
def register(self, biome: BiomeType) -> int:
|
|
143
|
-
"""
|
|
144
|
-
An alias of :meth:`get_add_biome`.
|
|
145
|
-
|
|
146
|
-
Adds a biome string to the internal biome string/ID mappings.
|
|
147
|
-
|
|
148
|
-
If the biome already exists in the mappings, the existing ID is returned.
|
|
149
|
-
|
|
150
|
-
:param biome: The biome string to add to the manager
|
|
151
|
-
:return: The internal ID of the biome
|
|
152
|
-
"""
|
|
153
|
-
return self.get_add_biome(biome)
|
|
1
|
+
from typing import Dict, overload, List, Union, Tuple, Generator, Iterable
|
|
2
|
+
from numpy import character, integer
|
|
3
|
+
|
|
4
|
+
from amulet_nbt import ByteTag, IntTag, ShortTag, LongTag, StringTag
|
|
5
|
+
from amulet.api.data_types import Int, BiomeType
|
|
6
|
+
from amulet.api.registry.base_registry import BaseRegistry
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class BiomeManager(BaseRegistry):
|
|
10
|
+
"""
|
|
11
|
+
Class to handle the mappings between biome strings and their index-based internal IDs
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
def __init__(self, biomes: Iterable[BiomeType] = ()):
|
|
15
|
+
"""
|
|
16
|
+
Creates a new BiomeManager object
|
|
17
|
+
"""
|
|
18
|
+
self._index_to_biome: List[BiomeType] = []
|
|
19
|
+
self._biome_to_index: Dict[BiomeType, int] = {}
|
|
20
|
+
for biome in biomes:
|
|
21
|
+
# if a list is given it is assumed that the biome palette will be the same size as the list.
|
|
22
|
+
# Ensure that if a value is duplicated it will appear twice in the list
|
|
23
|
+
assert isinstance(biome, str), f"biome must be a string. Got {biome}"
|
|
24
|
+
if biome not in self._biome_to_index:
|
|
25
|
+
self._biome_to_index[biome] = len(self._index_to_biome)
|
|
26
|
+
self._index_to_biome.append(biome)
|
|
27
|
+
|
|
28
|
+
def __len__(self):
|
|
29
|
+
"""
|
|
30
|
+
The number of biomes in the registry.
|
|
31
|
+
|
|
32
|
+
>>> len(level.biome_palette)
|
|
33
|
+
10
|
|
34
|
+
"""
|
|
35
|
+
return len(self._index_to_biome)
|
|
36
|
+
|
|
37
|
+
def __contains__(self, item: Union[int, BiomeType]):
|
|
38
|
+
"""
|
|
39
|
+
Is the given biome string already in the registry.
|
|
40
|
+
|
|
41
|
+
>>> biome_string in level.biome_palette
|
|
42
|
+
True
|
|
43
|
+
>>> 7 in level.biome_palette
|
|
44
|
+
True
|
|
45
|
+
|
|
46
|
+
:param item: The biome or id to check.
|
|
47
|
+
"""
|
|
48
|
+
if isinstance(item, int):
|
|
49
|
+
return item < len(self._index_to_biome)
|
|
50
|
+
elif isinstance(item, str):
|
|
51
|
+
return item in self._biome_to_index
|
|
52
|
+
return False
|
|
53
|
+
|
|
54
|
+
def __iter__(self) -> Iterable[BiomeType]:
|
|
55
|
+
"""
|
|
56
|
+
Iterate through all biomes in the registry.
|
|
57
|
+
|
|
58
|
+
>>> for biome in level.biome_palette:
|
|
59
|
+
>>> ...
|
|
60
|
+
"""
|
|
61
|
+
yield from self._index_to_biome
|
|
62
|
+
|
|
63
|
+
@property
|
|
64
|
+
def biomes(self) -> Tuple[BiomeType]:
|
|
65
|
+
"""
|
|
66
|
+
The biomes in the registry as a tuple.
|
|
67
|
+
"""
|
|
68
|
+
return tuple(self._index_to_biome)
|
|
69
|
+
|
|
70
|
+
def values(self) -> Tuple[BiomeType]:
|
|
71
|
+
"""
|
|
72
|
+
The biomes in the registry as a tuple.
|
|
73
|
+
"""
|
|
74
|
+
return self.biomes
|
|
75
|
+
|
|
76
|
+
def items(self) -> Generator[Tuple[int, BiomeType], None, None]:
|
|
77
|
+
"""
|
|
78
|
+
A generator of the biome indexes and the biome strings.
|
|
79
|
+
"""
|
|
80
|
+
yield from enumerate(self._index_to_biome)
|
|
81
|
+
|
|
82
|
+
@overload
|
|
83
|
+
def __getitem__(self, item: BiomeType) -> int:
|
|
84
|
+
...
|
|
85
|
+
|
|
86
|
+
@overload
|
|
87
|
+
def __getitem__(self, item: Int) -> BiomeType:
|
|
88
|
+
...
|
|
89
|
+
|
|
90
|
+
@overload
|
|
91
|
+
def __getitem__(
|
|
92
|
+
self, item: Iterable[Union[Int, BiomeType]]
|
|
93
|
+
) -> List[Union[BiomeType, Int]]:
|
|
94
|
+
...
|
|
95
|
+
|
|
96
|
+
def __getitem__(self, item):
|
|
97
|
+
"""
|
|
98
|
+
If a string is passed to this function, it will return the internal ID/index of the biome.
|
|
99
|
+
|
|
100
|
+
If an int is given, this method will return the biome string at that specified index.
|
|
101
|
+
|
|
102
|
+
>>> level.biome_palette[biome]
|
|
103
|
+
7
|
|
104
|
+
>>> level.biome_palette[7]
|
|
105
|
+
biome
|
|
106
|
+
|
|
107
|
+
:param item: The string or int to get the mapping data of
|
|
108
|
+
:return: An int if a string was supplied, a string if an int was supplied
|
|
109
|
+
:raises KeyError if the requested item is not present.
|
|
110
|
+
"""
|
|
111
|
+
try:
|
|
112
|
+
return self._get_item(item)
|
|
113
|
+
except (KeyError, IndexError):
|
|
114
|
+
raise KeyError(
|
|
115
|
+
f"There is no {item} in the BiomeManager. "
|
|
116
|
+
f"You might want to use the `get_add_biome` function for the biome before accessing them."
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
def _get_item(self, item):
|
|
120
|
+
if isinstance(item, (str, character, StringTag)):
|
|
121
|
+
return self._biome_to_index[str(item)]
|
|
122
|
+
elif isinstance(item, (int, integer, ByteTag, ShortTag, IntTag, LongTag)):
|
|
123
|
+
return self._index_to_biome[int(item)]
|
|
124
|
+
# if it isn't an int or string assume an iterable of the above.
|
|
125
|
+
return [self._get_item(i) for i in item]
|
|
126
|
+
|
|
127
|
+
def get_add_biome(self, biome: BiomeType) -> int:
|
|
128
|
+
"""
|
|
129
|
+
Adds a biome string to the internal biome string/ID mappings.
|
|
130
|
+
|
|
131
|
+
If the biome already exists in the mappings, the existing ID is returned.
|
|
132
|
+
|
|
133
|
+
:param biome: The biome string to add to the manager
|
|
134
|
+
:return: The internal ID of the biome
|
|
135
|
+
"""
|
|
136
|
+
assert isinstance(biome, str), f"biome must be a string. Got {biome}"
|
|
137
|
+
if biome not in self._biome_to_index:
|
|
138
|
+
self._biome_to_index[biome] = len(self._index_to_biome)
|
|
139
|
+
self._index_to_biome.append(biome)
|
|
140
|
+
return self._biome_to_index[biome]
|
|
141
|
+
|
|
142
|
+
def register(self, biome: BiomeType) -> int:
|
|
143
|
+
"""
|
|
144
|
+
An alias of :meth:`get_add_biome`.
|
|
145
|
+
|
|
146
|
+
Adds a biome string to the internal biome string/ID mappings.
|
|
147
|
+
|
|
148
|
+
If the biome already exists in the mappings, the existing ID is returned.
|
|
149
|
+
|
|
150
|
+
:param biome: The biome string to add to the manager
|
|
151
|
+
:return: The internal ID of the biome
|
|
152
|
+
"""
|
|
153
|
+
return self.get_add_biome(biome)
|
|
@@ -1,156 +1,156 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
from typing import Dict, Iterable, List, Tuple, overload, Generator, Union
|
|
3
|
-
from numpy import integer
|
|
4
|
-
|
|
5
|
-
from amulet_nbt import ByteTag, IntTag, ShortTag, LongTag
|
|
6
|
-
|
|
7
|
-
from amulet.api.data_types import Int
|
|
8
|
-
from amulet.api.block import Block
|
|
9
|
-
from .base_registry import BaseRegistry
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class BlockManager(BaseRegistry):
|
|
13
|
-
"""
|
|
14
|
-
Class to handle the mappings between Block objects and their index-based internal IDs
|
|
15
|
-
"""
|
|
16
|
-
|
|
17
|
-
def __init__(self, blocks: Iterable[Block] = ()):
|
|
18
|
-
"""
|
|
19
|
-
Creates a new BlockManager object
|
|
20
|
-
"""
|
|
21
|
-
self._index_to_block: List[Block] = []
|
|
22
|
-
self._block_to_index_map: Dict[Block, int] = {}
|
|
23
|
-
|
|
24
|
-
for block in blocks:
|
|
25
|
-
assert isinstance(block, Block), "BlockManager only takes Block objects."
|
|
26
|
-
if block not in self._block_to_index_map:
|
|
27
|
-
self._block_to_index_map[block] = len(self._block_to_index_map)
|
|
28
|
-
self._index_to_block.append(block)
|
|
29
|
-
|
|
30
|
-
def __len__(self):
|
|
31
|
-
"""
|
|
32
|
-
The number of blocks in the registry.
|
|
33
|
-
|
|
34
|
-
>>> len(level.block_palette)
|
|
35
|
-
10
|
|
36
|
-
"""
|
|
37
|
-
return len(self._index_to_block)
|
|
38
|
-
|
|
39
|
-
def __contains__(self, item: Block) -> bool:
|
|
40
|
-
"""
|
|
41
|
-
Is the given :class:`Block` already in the registry.
|
|
42
|
-
|
|
43
|
-
>>> block in level.block_palette
|
|
44
|
-
True
|
|
45
|
-
>>> 7 in level.block_palette
|
|
46
|
-
True
|
|
47
|
-
|
|
48
|
-
:param item: The block or index to check.
|
|
49
|
-
"""
|
|
50
|
-
if isinstance(item, int):
|
|
51
|
-
return item < len(self._index_to_block)
|
|
52
|
-
elif isinstance(item, Block):
|
|
53
|
-
return item in self._block_to_index_map
|
|
54
|
-
return False
|
|
55
|
-
|
|
56
|
-
def __iter__(self):
|
|
57
|
-
"""
|
|
58
|
-
Iterate through all blocks in the registry.
|
|
59
|
-
|
|
60
|
-
>>> for block in level.block_palette:
|
|
61
|
-
>>> ...
|
|
62
|
-
"""
|
|
63
|
-
yield from self._index_to_block
|
|
64
|
-
|
|
65
|
-
@property
|
|
66
|
-
def blocks(self) -> Tuple[Block, ...]:
|
|
67
|
-
"""
|
|
68
|
-
The blocks in the registry as a tuple.
|
|
69
|
-
"""
|
|
70
|
-
return tuple(self._index_to_block)
|
|
71
|
-
|
|
72
|
-
def values(self) -> Tuple[Block, ...]:
|
|
73
|
-
"""
|
|
74
|
-
The blocks in the registry as a tuple.
|
|
75
|
-
"""
|
|
76
|
-
return self.blocks
|
|
77
|
-
|
|
78
|
-
def items(self) -> Generator[Tuple[int, Block], None, None]:
|
|
79
|
-
"""
|
|
80
|
-
A generator of the block indexes and the block objects.
|
|
81
|
-
"""
|
|
82
|
-
yield from enumerate(self._index_to_block)
|
|
83
|
-
|
|
84
|
-
@overload
|
|
85
|
-
def __getitem__(self, item: Block) -> int:
|
|
86
|
-
...
|
|
87
|
-
|
|
88
|
-
@overload
|
|
89
|
-
def __getitem__(self, item: Int) -> Block:
|
|
90
|
-
...
|
|
91
|
-
|
|
92
|
-
@overload
|
|
93
|
-
def __getitem__(self, item: Iterable[Union[Int, Block]]) -> List[Union[Block, Int]]:
|
|
94
|
-
...
|
|
95
|
-
|
|
96
|
-
def __getitem__(self, item):
|
|
97
|
-
"""
|
|
98
|
-
If a Block object is passed to this function, it will return the internal ID/index of the blockstate.
|
|
99
|
-
|
|
100
|
-
If an int is given, this method will return the Block object at that specified index.
|
|
101
|
-
|
|
102
|
-
>>> level.block_palette[block]
|
|
103
|
-
7
|
|
104
|
-
>>> level.block_palette[7]
|
|
105
|
-
block
|
|
106
|
-
|
|
107
|
-
:param item: The Block object or int to get the mapping data of
|
|
108
|
-
:return: An int if a Block object was supplied, a Block object if an int was supplied
|
|
109
|
-
:raises KeyError if the requested item is not present.
|
|
110
|
-
"""
|
|
111
|
-
try:
|
|
112
|
-
return self._get_item(item)
|
|
113
|
-
except (KeyError, IndexError):
|
|
114
|
-
raise KeyError(
|
|
115
|
-
f"There is no {item} in the BlockManager. "
|
|
116
|
-
f"You might want to use the `get_add_block` function for your blocks before accessing them."
|
|
117
|
-
)
|
|
118
|
-
|
|
119
|
-
def _get_item(self, item):
|
|
120
|
-
if isinstance(item, Block):
|
|
121
|
-
return self._block_to_index_map[item]
|
|
122
|
-
elif isinstance(item, (int, integer, ByteTag, ShortTag, IntTag, LongTag)):
|
|
123
|
-
return self._index_to_block[int(item)]
|
|
124
|
-
# if it isn't an Block or int assume an iterable of the above.
|
|
125
|
-
return [self._get_item(i) for i in item]
|
|
126
|
-
|
|
127
|
-
def get_add_block(self, block: Block) -> int:
|
|
128
|
-
"""
|
|
129
|
-
Adds a Block object to the internal Block object/ID mappings.
|
|
130
|
-
|
|
131
|
-
If the Block already exists in the mappings, the existing ID is returned.
|
|
132
|
-
|
|
133
|
-
:param block: The Block to add to the manager
|
|
134
|
-
:return: The internal ID of the Block
|
|
135
|
-
"""
|
|
136
|
-
assert isinstance(block, Block), "BlockManager only takes Block objects."
|
|
137
|
-
if block in self._block_to_index_map:
|
|
138
|
-
return self._block_to_index_map[block]
|
|
139
|
-
|
|
140
|
-
self._block_to_index_map[block] = i = len(self._block_to_index_map)
|
|
141
|
-
self._index_to_block.append(block)
|
|
142
|
-
|
|
143
|
-
return i
|
|
144
|
-
|
|
145
|
-
def register(self, block: Block) -> int:
|
|
146
|
-
"""
|
|
147
|
-
An alias of :meth:`get_add_block`.
|
|
148
|
-
|
|
149
|
-
Adds a Block object to the internal Block object/ID mappings.
|
|
150
|
-
|
|
151
|
-
If the Block already exists in the mappings, the existing ID is returned.
|
|
152
|
-
|
|
153
|
-
:param block: The Block to add to the manager
|
|
154
|
-
:return: The internal ID of the Block
|
|
155
|
-
"""
|
|
156
|
-
return self.get_add_block(block)
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
from typing import Dict, Iterable, List, Tuple, overload, Generator, Union
|
|
3
|
+
from numpy import integer
|
|
4
|
+
|
|
5
|
+
from amulet_nbt import ByteTag, IntTag, ShortTag, LongTag
|
|
6
|
+
|
|
7
|
+
from amulet.api.data_types import Int
|
|
8
|
+
from amulet.api.block import Block
|
|
9
|
+
from .base_registry import BaseRegistry
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class BlockManager(BaseRegistry):
|
|
13
|
+
"""
|
|
14
|
+
Class to handle the mappings between Block objects and their index-based internal IDs
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
def __init__(self, blocks: Iterable[Block] = ()):
|
|
18
|
+
"""
|
|
19
|
+
Creates a new BlockManager object
|
|
20
|
+
"""
|
|
21
|
+
self._index_to_block: List[Block] = []
|
|
22
|
+
self._block_to_index_map: Dict[Block, int] = {}
|
|
23
|
+
|
|
24
|
+
for block in blocks:
|
|
25
|
+
assert isinstance(block, Block), "BlockManager only takes Block objects."
|
|
26
|
+
if block not in self._block_to_index_map:
|
|
27
|
+
self._block_to_index_map[block] = len(self._block_to_index_map)
|
|
28
|
+
self._index_to_block.append(block)
|
|
29
|
+
|
|
30
|
+
def __len__(self):
|
|
31
|
+
"""
|
|
32
|
+
The number of blocks in the registry.
|
|
33
|
+
|
|
34
|
+
>>> len(level.block_palette)
|
|
35
|
+
10
|
|
36
|
+
"""
|
|
37
|
+
return len(self._index_to_block)
|
|
38
|
+
|
|
39
|
+
def __contains__(self, item: Block) -> bool:
|
|
40
|
+
"""
|
|
41
|
+
Is the given :class:`Block` already in the registry.
|
|
42
|
+
|
|
43
|
+
>>> block in level.block_palette
|
|
44
|
+
True
|
|
45
|
+
>>> 7 in level.block_palette
|
|
46
|
+
True
|
|
47
|
+
|
|
48
|
+
:param item: The block or index to check.
|
|
49
|
+
"""
|
|
50
|
+
if isinstance(item, int):
|
|
51
|
+
return item < len(self._index_to_block)
|
|
52
|
+
elif isinstance(item, Block):
|
|
53
|
+
return item in self._block_to_index_map
|
|
54
|
+
return False
|
|
55
|
+
|
|
56
|
+
def __iter__(self):
|
|
57
|
+
"""
|
|
58
|
+
Iterate through all blocks in the registry.
|
|
59
|
+
|
|
60
|
+
>>> for block in level.block_palette:
|
|
61
|
+
>>> ...
|
|
62
|
+
"""
|
|
63
|
+
yield from self._index_to_block
|
|
64
|
+
|
|
65
|
+
@property
|
|
66
|
+
def blocks(self) -> Tuple[Block, ...]:
|
|
67
|
+
"""
|
|
68
|
+
The blocks in the registry as a tuple.
|
|
69
|
+
"""
|
|
70
|
+
return tuple(self._index_to_block)
|
|
71
|
+
|
|
72
|
+
def values(self) -> Tuple[Block, ...]:
|
|
73
|
+
"""
|
|
74
|
+
The blocks in the registry as a tuple.
|
|
75
|
+
"""
|
|
76
|
+
return self.blocks
|
|
77
|
+
|
|
78
|
+
def items(self) -> Generator[Tuple[int, Block], None, None]:
|
|
79
|
+
"""
|
|
80
|
+
A generator of the block indexes and the block objects.
|
|
81
|
+
"""
|
|
82
|
+
yield from enumerate(self._index_to_block)
|
|
83
|
+
|
|
84
|
+
@overload
|
|
85
|
+
def __getitem__(self, item: Block) -> int:
|
|
86
|
+
...
|
|
87
|
+
|
|
88
|
+
@overload
|
|
89
|
+
def __getitem__(self, item: Int) -> Block:
|
|
90
|
+
...
|
|
91
|
+
|
|
92
|
+
@overload
|
|
93
|
+
def __getitem__(self, item: Iterable[Union[Int, Block]]) -> List[Union[Block, Int]]:
|
|
94
|
+
...
|
|
95
|
+
|
|
96
|
+
def __getitem__(self, item):
|
|
97
|
+
"""
|
|
98
|
+
If a Block object is passed to this function, it will return the internal ID/index of the blockstate.
|
|
99
|
+
|
|
100
|
+
If an int is given, this method will return the Block object at that specified index.
|
|
101
|
+
|
|
102
|
+
>>> level.block_palette[block]
|
|
103
|
+
7
|
|
104
|
+
>>> level.block_palette[7]
|
|
105
|
+
block
|
|
106
|
+
|
|
107
|
+
:param item: The Block object or int to get the mapping data of
|
|
108
|
+
:return: An int if a Block object was supplied, a Block object if an int was supplied
|
|
109
|
+
:raises KeyError if the requested item is not present.
|
|
110
|
+
"""
|
|
111
|
+
try:
|
|
112
|
+
return self._get_item(item)
|
|
113
|
+
except (KeyError, IndexError):
|
|
114
|
+
raise KeyError(
|
|
115
|
+
f"There is no {item} in the BlockManager. "
|
|
116
|
+
f"You might want to use the `get_add_block` function for your blocks before accessing them."
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
def _get_item(self, item):
|
|
120
|
+
if isinstance(item, Block):
|
|
121
|
+
return self._block_to_index_map[item]
|
|
122
|
+
elif isinstance(item, (int, integer, ByteTag, ShortTag, IntTag, LongTag)):
|
|
123
|
+
return self._index_to_block[int(item)]
|
|
124
|
+
# if it isn't an Block or int assume an iterable of the above.
|
|
125
|
+
return [self._get_item(i) for i in item]
|
|
126
|
+
|
|
127
|
+
def get_add_block(self, block: Block) -> int:
|
|
128
|
+
"""
|
|
129
|
+
Adds a Block object to the internal Block object/ID mappings.
|
|
130
|
+
|
|
131
|
+
If the Block already exists in the mappings, the existing ID is returned.
|
|
132
|
+
|
|
133
|
+
:param block: The Block to add to the manager
|
|
134
|
+
:return: The internal ID of the Block
|
|
135
|
+
"""
|
|
136
|
+
assert isinstance(block, Block), "BlockManager only takes Block objects."
|
|
137
|
+
if block in self._block_to_index_map:
|
|
138
|
+
return self._block_to_index_map[block]
|
|
139
|
+
|
|
140
|
+
self._block_to_index_map[block] = i = len(self._block_to_index_map)
|
|
141
|
+
self._index_to_block.append(block)
|
|
142
|
+
|
|
143
|
+
return i
|
|
144
|
+
|
|
145
|
+
def register(self, block: Block) -> int:
|
|
146
|
+
"""
|
|
147
|
+
An alias of :meth:`get_add_block`.
|
|
148
|
+
|
|
149
|
+
Adds a Block object to the internal Block object/ID mappings.
|
|
150
|
+
|
|
151
|
+
If the Block already exists in the mappings, the existing ID is returned.
|
|
152
|
+
|
|
153
|
+
:param block: The Block to add to the manager
|
|
154
|
+
:return: The internal ID of the Block
|
|
155
|
+
"""
|
|
156
|
+
return self.get_add_block(block)
|
amulet/api/selection/__init__.py
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
from .group import SelectionGroup
|
|
2
|
-
from .box import SelectionBox
|
|
1
|
+
from .group import SelectionGroup
|
|
2
|
+
from .box import SelectionBox
|