amulet-core 2.0a7__cp312-cp312-win_amd64.whl → 2.0a8__cp312-cp312-win_amd64.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.

Files changed (80) hide show
  1. amulet/__init__.cp312-win_amd64.pyd +0 -0
  2. amulet/__init__.py.cpp +2 -0
  3. amulet/__init__.pyi +2 -0
  4. amulet/_version.py +3 -3
  5. amulet/chunk.hpp +2 -1
  6. amulet/level/abc/_chunk_handle.py +45 -22
  7. amulet/mesh/block/__init__.pyi +301 -0
  8. amulet/mesh/block/_cube.py +198 -0
  9. amulet/mesh/block/{missing_block.py → _missing_block.py} +2 -2
  10. amulet/mesh/block/block_mesh.cpp +107 -0
  11. amulet/mesh/block/block_mesh.hpp +207 -0
  12. amulet/resource_pack/__init__.py +16 -15
  13. amulet/resource_pack/abc/resource_pack_manager.py +3 -5
  14. amulet/resource_pack/java/resource_pack_manager.py +185 -173
  15. amulet/utils/cast.py +10 -0
  16. amulet/utils/shareable_lock.py +2 -2
  17. {amulet_core-2.0a7.dist-info → amulet_core-2.0a8.dist-info}/METADATA +2 -2
  18. {amulet_core-2.0a7.dist-info → amulet_core-2.0a8.dist-info}/RECORD +21 -75
  19. {amulet_core-2.0a7.dist-info → amulet_core-2.0a8.dist-info}/WHEEL +1 -1
  20. amulet/mesh/block/__init__.py +0 -1
  21. amulet/mesh/block/block_mesh.py +0 -369
  22. amulet/mesh/block/cube.py +0 -149
  23. amulet/resource_pack/bedrock/__init__.py +0 -2
  24. amulet/resource_pack/bedrock/bedrock_vanilla_fix/pack_icon.png +0 -0
  25. amulet/resource_pack/bedrock/bedrock_vanilla_fix/textures/blocks/grass_carried.png +0 -0
  26. amulet/resource_pack/bedrock/bedrock_vanilla_fix/textures/blocks/grass_side_carried.png +0 -0
  27. amulet/resource_pack/bedrock/bedrock_vanilla_fix/textures/blocks/water.png +0 -0
  28. amulet/resource_pack/bedrock/blockshapes/__init__.py +0 -31
  29. amulet/resource_pack/bedrock/blockshapes/air.py +0 -35
  30. amulet/resource_pack/bedrock/blockshapes/base_blockshape.py +0 -29
  31. amulet/resource_pack/bedrock/blockshapes/bubble_column.py +0 -29
  32. amulet/resource_pack/bedrock/blockshapes/cake.py +0 -46
  33. amulet/resource_pack/bedrock/blockshapes/chest.py +0 -54
  34. amulet/resource_pack/bedrock/blockshapes/comparator.py +0 -51
  35. amulet/resource_pack/bedrock/blockshapes/cross_texture.py +0 -186
  36. amulet/resource_pack/bedrock/blockshapes/cross_texture0.py +0 -17
  37. amulet/resource_pack/bedrock/blockshapes/cross_texture_green.py +0 -16
  38. amulet/resource_pack/bedrock/blockshapes/cube.py +0 -38
  39. amulet/resource_pack/bedrock/blockshapes/default.py +0 -14
  40. amulet/resource_pack/bedrock/blockshapes/door.py +0 -38
  41. amulet/resource_pack/bedrock/blockshapes/door1.py +0 -14
  42. amulet/resource_pack/bedrock/blockshapes/door2.py +0 -14
  43. amulet/resource_pack/bedrock/blockshapes/door3.py +0 -14
  44. amulet/resource_pack/bedrock/blockshapes/door4.py +0 -14
  45. amulet/resource_pack/bedrock/blockshapes/door5.py +0 -14
  46. amulet/resource_pack/bedrock/blockshapes/door6.py +0 -14
  47. amulet/resource_pack/bedrock/blockshapes/double_plant.py +0 -40
  48. amulet/resource_pack/bedrock/blockshapes/enchanting_table.py +0 -22
  49. amulet/resource_pack/bedrock/blockshapes/farmland.py +0 -22
  50. amulet/resource_pack/bedrock/blockshapes/fence.py +0 -22
  51. amulet/resource_pack/bedrock/blockshapes/flat.py +0 -55
  52. amulet/resource_pack/bedrock/blockshapes/flat_wall.py +0 -55
  53. amulet/resource_pack/bedrock/blockshapes/furnace.py +0 -44
  54. amulet/resource_pack/bedrock/blockshapes/furnace_lit.py +0 -14
  55. amulet/resource_pack/bedrock/blockshapes/green_cube.py +0 -39
  56. amulet/resource_pack/bedrock/blockshapes/ladder.py +0 -36
  57. amulet/resource_pack/bedrock/blockshapes/lilypad.py +0 -14
  58. amulet/resource_pack/bedrock/blockshapes/partial_block.py +0 -57
  59. amulet/resource_pack/bedrock/blockshapes/piston.py +0 -44
  60. amulet/resource_pack/bedrock/blockshapes/piston_arm.py +0 -72
  61. amulet/resource_pack/bedrock/blockshapes/portal_frame.py +0 -22
  62. amulet/resource_pack/bedrock/blockshapes/pressure_plate.py +0 -29
  63. amulet/resource_pack/bedrock/blockshapes/pumpkin.py +0 -36
  64. amulet/resource_pack/bedrock/blockshapes/pumpkin_carved.py +0 -14
  65. amulet/resource_pack/bedrock/blockshapes/pumpkin_lit.py +0 -14
  66. amulet/resource_pack/bedrock/blockshapes/red_dust.py +0 -14
  67. amulet/resource_pack/bedrock/blockshapes/repeater.py +0 -53
  68. amulet/resource_pack/bedrock/blockshapes/slab.py +0 -33
  69. amulet/resource_pack/bedrock/blockshapes/slab_double.py +0 -15
  70. amulet/resource_pack/bedrock/blockshapes/tree.py +0 -41
  71. amulet/resource_pack/bedrock/blockshapes/turtle_egg.py +0 -15
  72. amulet/resource_pack/bedrock/blockshapes/vine.py +0 -52
  73. amulet/resource_pack/bedrock/blockshapes/wall.py +0 -22
  74. amulet/resource_pack/bedrock/blockshapes/water.py +0 -38
  75. amulet/resource_pack/bedrock/download_resources.py +0 -147
  76. amulet/resource_pack/bedrock/resource_pack.py +0 -40
  77. amulet/resource_pack/bedrock/resource_pack_manager.py +0 -361
  78. amulet/resource_pack/bedrock/sort_blockshapes.py +0 -15
  79. {amulet_core-2.0a7.dist-info → amulet_core-2.0a8.dist-info}/entry_points.txt +0 -0
  80. {amulet_core-2.0a7.dist-info → amulet_core-2.0a8.dist-info}/top_level.txt +0 -0
@@ -1,361 +0,0 @@
1
- import os
2
- import json
3
- from typing import Union, Iterable, Generator, Optional, TypedDict, Literal, Any
4
- from PIL import Image
5
- import numpy
6
-
7
- from amulet.block import Block
8
- from amulet.utils import comment_json
9
- from amulet.resource_pack import BaseResourcePackManager
10
- from amulet.resource_pack.bedrock import BedrockResourcePack
11
- from amulet.mesh.block.block_mesh import BlockMesh
12
- from .blockshapes import BlockShapeClasses
13
-
14
-
15
- class NumericalProperty(TypedDict):
16
- name: str
17
- type: Union[Literal["byte"], Literal["int"]]
18
- value: int
19
-
20
-
21
- class StrProperty(TypedDict):
22
- name: str
23
- type: Literal["string"]
24
- value: str
25
-
26
-
27
- class StateDict(TypedDict):
28
- name: str
29
- data: int
30
- states: list[Union[NumericalProperty, StrProperty]]
31
-
32
-
33
- class BlockPaletteDict(TypedDict):
34
- blocks: list[StateDict]
35
-
36
-
37
- def _load_data() -> tuple[
38
- dict[str, str],
39
- dict[
40
- str,
41
- tuple[
42
- tuple[tuple[str, Union[int, str]], ...],
43
- dict[tuple[Union[str, int], ...], int],
44
- ],
45
- ],
46
- ]:
47
- with open(os.path.join(os.path.dirname(__file__), "blockshapes.json")) as f:
48
- _block_shapes: dict[str, str] = comment_json.load(f) # type: ignore
49
-
50
- _aux_values: dict[
51
- str,
52
- tuple[
53
- tuple[tuple[str, Union[int, str]], ...],
54
- dict[tuple[Union[str, int], ...], int],
55
- ],
56
- ] = {}
57
- with open(os.path.join(os.path.dirname(__file__), "block_palette.json")) as f:
58
- _block_palette: BlockPaletteDict = comment_json.load(f) # type: ignore
59
- for block in _block_palette["blocks"]:
60
- data = block["data"]
61
- name = block["name"]
62
- if name not in _aux_values:
63
- _aux_values[name] = (
64
- tuple((state["name"], state["value"]) for state in block["states"]),
65
- {},
66
- )
67
- _aux_values[name][1][tuple(state["value"] for state in block["states"])] = data
68
-
69
- return _block_shapes, _aux_values
70
-
71
-
72
- BlockShapes, AuxValues = _load_data()
73
-
74
-
75
- def get_aux_value(block: Block) -> int:
76
- name = block.namespaced_name
77
- if name in AuxValues:
78
- property_names, aux_map = AuxValues[name]
79
- properties = block.properties
80
- key = tuple(
81
- (
82
- properties[property_name].py_data
83
- if property_name in properties
84
- else default
85
- )
86
- for property_name, default in property_names
87
- )
88
- return aux_map.get(key, 0)
89
- else:
90
- return 0
91
-
92
-
93
- class BedrockResourcePackManager(BaseResourcePackManager):
94
- """A class to load and handle the data from the packs.
95
- Packs are given as a list with the later packs overwriting the earlier ones."""
96
-
97
- def __init__(
98
- self,
99
- resource_packs: Union[BedrockResourcePack, Iterable[BedrockResourcePack]],
100
- load: bool = True,
101
- ) -> None:
102
- super().__init__()
103
- self._block_shapes: dict[str, str] = {} # block string to block shape
104
- self._blocks: dict[str, Union[dict[str, str], str, None]] = (
105
- {}
106
- ) # block string to short texture ids
107
- self._terrain_texture: dict[str, tuple[str, ...]] = (
108
- {}
109
- ) # texture ids to list of relative paths. Each relates to a different data value.
110
- self._textures: dict[str, str] = {} # relative path to texture path
111
- self._all_textures = None
112
-
113
- self._texture_is_transparent: dict[str, tuple[float, bool]] = {}
114
-
115
- if isinstance(resource_packs, (list, tuple)):
116
- self._packs = [
117
- rp for rp in resource_packs if isinstance(rp, BedrockResourcePack)
118
- ]
119
- elif isinstance(resource_packs, BedrockResourcePack):
120
- self._packs = [resource_packs]
121
- else:
122
- raise Exception(f"Invalid format {resource_packs}")
123
- if load:
124
- for _ in self.reload():
125
- pass
126
-
127
- def _unload(self) -> None:
128
- """Clear all loaded resources."""
129
- super()._unload()
130
- self._block_shapes.clear()
131
- self._blocks.clear()
132
- self._terrain_texture.clear()
133
- self._textures.clear()
134
- self._all_textures = None
135
-
136
- def _check_texture(self, texture_path: str) -> str:
137
- if os.path.isfile(texture_path + ".png"):
138
- texture_path += ".png"
139
- elif os.path.isfile(texture_path + ".tga"):
140
- texture_path += ".tga"
141
- else:
142
- texture_path = self.missing_no
143
- if (
144
- os.stat(texture_path).st_mtime
145
- != self._texture_is_transparent.get(texture_path, [0])[0]
146
- ):
147
- im: Image.Image = Image.open(texture_path)
148
- if im.mode == "RGBA":
149
- alpha = numpy.array(im.getchannel("A").getdata())
150
- texture_is_transparent = bool(numpy.any(alpha != 255))
151
- else:
152
- texture_is_transparent = False
153
-
154
- self._texture_is_transparent[texture_path] = (
155
- os.stat(texture_path).st_mtime,
156
- bool(texture_is_transparent),
157
- )
158
- return texture_path
159
-
160
- def _load_iter(self) -> Generator[float, None, None]:
161
- self._block_shapes.update(BlockShapes) # add the default block shapes
162
-
163
- transparency_cache_path = os.path.join(
164
- os.environ["CACHE_DIR"],
165
- "resource_packs",
166
- "bedrock",
167
- "transparency_cache.json",
168
- )
169
- self._load_transparency_cache(transparency_cache_path)
170
-
171
- self._textures["missing_no"] = self._check_texture("missing")
172
-
173
- pack_count = len(self._packs)
174
-
175
- for pack_index, pack in enumerate(self._packs):
176
- pack_progress = pack_index / pack_count
177
- yield pack_progress
178
-
179
- if pack.valid_pack:
180
- terrain_texture_path = os.path.join(
181
- pack.root_dir, "textures", "terrain_texture.json"
182
- )
183
- if os.path.isfile(terrain_texture_path):
184
- try:
185
- with open(terrain_texture_path) as f:
186
- terrain_texture = comment_json.load(f)
187
- except json.JSONDecodeError:
188
- pass
189
- else:
190
- if (
191
- isinstance(terrain_texture, dict)
192
- and "texture_data" in terrain_texture
193
- and isinstance(terrain_texture["texture_data"], dict)
194
- ):
195
- sub_progress = pack_progress
196
- image_count = len(terrain_texture["texture_data"])
197
-
198
- def get_texture(_relative_path: Any) -> str:
199
- if isinstance(_relative_path, dict):
200
- _relative_path = _relative_path.get(
201
- "path", "misssingno"
202
- )
203
- assert isinstance(_relative_path, str)
204
- if isinstance(_relative_path, str):
205
- full_path = self._check_texture(
206
- os.path.join(pack.root_dir, _relative_path)
207
- )
208
- if _relative_path in self._textures:
209
- if full_path != self.missing_no:
210
- self._textures[_relative_path] = full_path
211
- else:
212
- self._textures[_relative_path] = full_path
213
- else:
214
- raise TypeError
215
- return _relative_path
216
-
217
- for image_index, (texture_id, data) in enumerate(
218
- terrain_texture["texture_data"].items()
219
- ):
220
- if (
221
- isinstance(texture_id, str)
222
- and isinstance(data, dict)
223
- and "textures" in data
224
- ):
225
- texture_data = data["textures"]
226
- if isinstance(texture_data, list):
227
- self._terrain_texture[texture_id] = tuple(
228
- get_texture(relative_path)
229
- for relative_path in texture_data
230
- )
231
- else:
232
- self._terrain_texture[texture_id] = (
233
- get_texture(texture_data),
234
- ) * 16
235
- yield sub_progress + image_index / (
236
- image_count * pack_count * 2
237
- )
238
- sub_progress = pack_progress + 1 / (pack_count * 2)
239
- yield sub_progress
240
- blocks_path = os.path.join(pack.root_dir, "blocks.json")
241
- if os.path.isfile(blocks_path):
242
- try:
243
- with open(blocks_path) as f:
244
- blocks = comment_json.load(f)
245
- except json.JSONDecodeError:
246
- pass
247
- else:
248
- if isinstance(blocks, dict):
249
- model_count = len(blocks)
250
- for model_index, (block_id, data) in enumerate(
251
- blocks.items()
252
- ):
253
- if isinstance(block_id, str) and isinstance(data, dict):
254
- if ":" not in block_id:
255
- block_id = "minecraft:" + block_id
256
- textures = data.get("textures")
257
- if textures is None or isinstance(textures, str):
258
- self._blocks[block_id] = textures
259
- elif isinstance(textures, dict) and all(
260
- isinstance(v, str) for v in textures.values()
261
- ):
262
- self._blocks[block_id] = textures # type: ignore # TODO: improve this with TypeGuard
263
- else:
264
- raise TypeError
265
-
266
- yield sub_progress + (model_index) / (
267
- model_count * pack_count * 2
268
- )
269
- yield pack_progress + 1
270
-
271
- os.makedirs(os.path.dirname(transparency_cache_path), exist_ok=True)
272
- with open(transparency_cache_path, "w") as f:
273
- json.dump(self._texture_is_transparent, f)
274
-
275
- @property
276
- def textures(self) -> tuple[str, ...]:
277
- """Returns a tuple of all the texture paths in the resource pack."""
278
- return tuple(self._textures.values())
279
-
280
- def get_texture_path(self, namespace: Optional[str], relative_path: str) -> str:
281
- """Get the absolute texture path from the namespace and relative path pair"""
282
- if relative_path in self._textures:
283
- return self._textures[relative_path]
284
- else:
285
- return self.missing_no
286
-
287
- def _get_model(self, block: Block) -> BlockMesh:
288
- block_shape = self._block_shapes.get(block.namespaced_name, "cube")
289
-
290
- if block_shape in BlockShapeClasses:
291
- block_shape_class = BlockShapeClasses[block_shape]
292
- else:
293
- block_shape_class = BlockShapeClasses["cube"]
294
-
295
- if not block_shape_class.is_valid(block):
296
- block_shape_class = BlockShapeClasses["cube"]
297
-
298
- texture_index = block_shape_class.texture_index(block, get_aux_value(block))
299
-
300
- if block.namespaced_name in self._blocks:
301
- texture_id = self._blocks[block.namespaced_name]
302
- if isinstance(texture_id, str):
303
- up = down = north = east = south = west = self._get_texture(
304
- texture_id, texture_index
305
- )
306
- transparent = (self._texture_is_transparent[up][1],) * 6
307
-
308
- elif isinstance(texture_id, dict):
309
- down = self._get_texture(
310
- texture_id.get("down", "missing"), texture_index
311
- )
312
- up = self._get_texture(texture_id.get("up", "missing"), texture_index)
313
-
314
- if "side" in texture_id:
315
- north = east = south = west = self._get_texture(
316
- texture_id.get("side", "missing"), texture_index
317
- )
318
- transparent = (
319
- self._texture_is_transparent[down][1],
320
- self._texture_is_transparent[up][1],
321
- ) + (self._texture_is_transparent[north][1],) * 4
322
- else:
323
- north = self._get_texture(
324
- texture_id.get("north", "missing"), texture_index
325
- )
326
- east = self._get_texture(
327
- texture_id.get("east", "missing"), texture_index
328
- )
329
- south = self._get_texture(
330
- texture_id.get("south", "missing"), texture_index
331
- )
332
- west = self._get_texture(
333
- texture_id.get("west", "missing"), texture_index
334
- )
335
- transparent = (
336
- self._texture_is_transparent[down][1],
337
- self._texture_is_transparent[up][1],
338
- self._texture_is_transparent[north][1],
339
- self._texture_is_transparent[east][1],
340
- self._texture_is_transparent[south][1],
341
- self._texture_is_transparent[west][1],
342
- )
343
- else:
344
- up = down = north = east = south = west = self._get_texture(
345
- "missing", texture_index
346
- )
347
- transparent = (self._texture_is_transparent[up][1],) * 6
348
-
349
- return block_shape_class.get_block_model(
350
- block, down, up, north, east, south, west, transparent
351
- )
352
-
353
- return self.missing_block
354
-
355
- def _get_texture(self, texture_id: str, index: int) -> str:
356
- texture = self.missing_no
357
- if texture_id in self._terrain_texture:
358
- texture_list = self._terrain_texture[texture_id]
359
- if len(texture_list) > index:
360
- texture = self.get_texture_path(None, texture_list[index])
361
- return texture
@@ -1,15 +0,0 @@
1
- import os
2
- import json
3
-
4
-
5
- def main() -> None:
6
- with open(os.path.join(os.path.dirname(__file__), "blockshapes.json")) as f:
7
- shapes = json.load(f)
8
- shapes_tuple = tuple(sorted(shapes.items(), key=lambda i: (i[1], i[0])))
9
- shapes2 = dict(shapes_tuple)
10
- with open(os.path.join(os.path.dirname(__file__), "blockshapes.json"), "w") as f:
11
- json.dump(shapes2, f, indent=4)
12
-
13
-
14
- if __name__ == "__main__":
15
- main()