amulet-core 2.0a6__cp311-cp311-win_amd64.whl → 2.0a8__cp311-cp311-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 (149) hide show
  1. amulet/__init__.cp311-win_amd64.pyd +0 -0
  2. amulet/__init__.py.cpp +6 -0
  3. amulet/__init__.pyi +2 -2
  4. amulet/_init.py +0 -2
  5. amulet/_version.py +3 -3
  6. amulet/biome.pyi +0 -2
  7. amulet/block.pyi +0 -2
  8. amulet/block_entity.pyi +0 -2
  9. amulet/chunk.hpp +2 -1
  10. amulet/chunk.pyi +0 -2
  11. amulet/chunk_components.pyi +20 -18
  12. amulet/collections/eq.py.hpp +1 -1
  13. amulet/collections/mapping.py.hpp +18 -11
  14. amulet/collections/mutable_mapping.py.hpp +17 -6
  15. amulet/collections/sequence.py.hpp +5 -6
  16. amulet/collections.pyi +8 -5
  17. amulet/entity.py +22 -20
  18. amulet/game/translate/_functions/_code_functions/_text.py +2 -2
  19. amulet/game/translate/_functions/abc.py +10 -3
  20. amulet/img/__init__.py +10 -0
  21. amulet/img/missing_no.png +0 -0
  22. amulet/img/missing_pack.png +0 -0
  23. amulet/level/__init__.pyi +2 -6
  24. amulet/level/abc/_chunk_handle.py +45 -22
  25. amulet/level/abc/_level/_creatable_level.py +1 -2
  26. amulet/level/abc/_level/_level.py +1 -5
  27. amulet/level/java/__init__.pyi +0 -5
  28. amulet/level/java/_raw/__init__.pyi +0 -4
  29. amulet/level/java/_raw/java_chunk_decode.cpp +2 -4
  30. amulet/level/java/long_array.pyi +2 -1
  31. amulet/mesh/block/__init__.pyi +301 -0
  32. amulet/mesh/block/_cube.py +198 -0
  33. amulet/mesh/block/_missing_block.py +20 -0
  34. amulet/mesh/block/block_mesh.cpp +107 -0
  35. amulet/mesh/block/block_mesh.hpp +207 -0
  36. amulet/mesh/util.py +17 -0
  37. amulet/player.py +4 -6
  38. amulet/pybind11/collections.hpp +80 -38
  39. amulet/pybind11/numpy.hpp +26 -0
  40. amulet/pybind11/py_module.hpp +16 -51
  41. amulet/pybind11/type_hints.hpp +51 -0
  42. amulet/pybind11/types.hpp +14 -6
  43. amulet/pybind11/typing.hpp +7 -0
  44. amulet/resource_pack/__init__.py +63 -0
  45. amulet/resource_pack/abc/__init__.py +2 -0
  46. amulet/resource_pack/abc/resource_pack.py +38 -0
  47. amulet/resource_pack/abc/resource_pack_manager.py +85 -0
  48. amulet/resource_pack/java/__init__.py +2 -0
  49. amulet/resource_pack/java/download_resources.py +212 -0
  50. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_black.png +0 -0
  51. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_blue.png +0 -0
  52. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_brown.png +0 -0
  53. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_cyan.png +0 -0
  54. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_gray.png +0 -0
  55. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_green.png +0 -0
  56. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_light_blue.png +0 -0
  57. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_light_gray.png +0 -0
  58. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_lime.png +0 -0
  59. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_magenta.png +0 -0
  60. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_orange.png +0 -0
  61. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_pink.png +0 -0
  62. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_purple.png +0 -0
  63. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_red.png +0 -0
  64. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_white.png +0 -0
  65. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_yellow.png +0 -0
  66. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/barrier.png +0 -0
  67. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/end_portal.png +0 -0
  68. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/grass.png +0 -0
  69. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/lava.png +0 -0
  70. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/structure_void.png +0 -0
  71. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/water.png +0 -0
  72. amulet/resource_pack/java/java_vanilla_fix/pack.png +0 -0
  73. amulet/resource_pack/java/resource_pack.py +44 -0
  74. amulet/resource_pack/java/resource_pack_manager.py +563 -0
  75. amulet/resource_pack/unknown_resource_pack.py +10 -0
  76. amulet/utils/__init__.pyi +0 -5
  77. amulet/utils/call_spec/_call_spec.py +2 -7
  78. amulet/utils/cast.py +10 -0
  79. amulet/utils/comment_json.py +188 -0
  80. amulet/utils/matrix.py +3 -3
  81. amulet/utils/numpy_helpers.py +2 -2
  82. amulet/utils/shareable_lock.py +2 -2
  83. amulet/utils/world_utils.py +2 -2
  84. amulet/version.pyi +0 -8
  85. {amulet_core-2.0a6.dist-info → amulet_core-2.0a8.dist-info}/METADATA +2 -2
  86. {amulet_core-2.0a6.dist-info → amulet_core-2.0a8.dist-info}/RECORD +91 -103
  87. {amulet_core-2.0a6.dist-info → amulet_core-2.0a8.dist-info}/WHEEL +1 -1
  88. amulet/chunk_/components/biome.py +0 -155
  89. amulet/chunk_/components/block_entity.py +0 -117
  90. amulet/chunk_/components/entity.py +0 -64
  91. amulet/chunk_/components/height_2d.py +0 -16
  92. amulet/level/bedrock/__init__.py +0 -2
  93. amulet/level/bedrock/_chunk_handle.py +0 -19
  94. amulet/level/bedrock/_dimension.py +0 -22
  95. amulet/level/bedrock/_level.py +0 -187
  96. amulet/level/bedrock/_raw/__init__.py +0 -5
  97. amulet/level/bedrock/_raw/_actor_counter.py +0 -53
  98. amulet/level/bedrock/_raw/_chunk.py +0 -54
  99. amulet/level/bedrock/_raw/_chunk_decode.py +0 -668
  100. amulet/level/bedrock/_raw/_chunk_encode.py +0 -602
  101. amulet/level/bedrock/_raw/_constant.py +0 -9
  102. amulet/level/bedrock/_raw/_dimension.py +0 -343
  103. amulet/level/bedrock/_raw/_level.py +0 -463
  104. amulet/level/bedrock/_raw/_level_dat.py +0 -90
  105. amulet/level/bedrock/_raw/_typing.py +0 -6
  106. amulet/level/bedrock/_raw/leveldb_chunk_versions.py +0 -83
  107. amulet/level/bedrock/chunk/__init__.py +0 -1
  108. amulet/level/bedrock/chunk/_chunk.py +0 -126
  109. amulet/level/bedrock/chunk/components/chunk_version.py +0 -12
  110. amulet/level/bedrock/chunk/components/finalised_state.py +0 -13
  111. amulet/level/bedrock/chunk/components/raw_chunk.py +0 -15
  112. amulet/level/construction/__init__.py +0 -0
  113. amulet/level/java/_chunk_handle.pyi +0 -15
  114. amulet/level/java/_dimension.pyi +0 -13
  115. amulet/level/java/_level.pyi +0 -120
  116. amulet/level/java/_raw/_chunk_decode.py +0 -561
  117. amulet/level/java/_raw/_chunk_encode.py +0 -463
  118. amulet/level/java/_raw/_constant.pyi +0 -20
  119. amulet/level/java/_raw/_data_pack/__init__.pyi +0 -8
  120. amulet/level/java/_raw/_data_pack/data_pack.pyi +0 -197
  121. amulet/level/java/_raw/_data_pack/data_pack_manager.pyi +0 -75
  122. amulet/level/java/_raw/_dimension.pyi +0 -72
  123. amulet/level/java/_raw/_level.pyi +0 -238
  124. amulet/level/java/_raw/_typing.pyi +0 -5
  125. amulet/level/java/anvil/__init__.pyi +0 -11
  126. amulet/level/java/anvil/_dimension.pyi +0 -109
  127. amulet/level/java/anvil/_region.pyi +0 -197
  128. amulet/level/java/anvil/_sector_manager.pyi +0 -142
  129. amulet/level/java_forge/__init__.py +0 -0
  130. amulet/level/mcstructure/__init__.py +0 -0
  131. amulet/level/nbt/__init__.py +0 -0
  132. amulet/level/schematic/__init__.py +0 -0
  133. amulet/level/sponge_schematic/__init__.py +0 -0
  134. amulet/pybind11/python.hpp +0 -14
  135. amulet/utils/call_spec/__init__.pyi +0 -53
  136. amulet/utils/call_spec/_call_spec.pyi +0 -272
  137. amulet/utils/matrix.pyi +0 -177
  138. amulet/utils/shareable_lock.pyi +0 -190
  139. amulet/utils/signal/__init__.pyi +0 -25
  140. amulet/utils/signal/_signal.pyi +0 -84
  141. amulet/utils/task_manager.pyi +0 -168
  142. amulet/utils/typing.py +0 -4
  143. amulet/utils/typing.pyi +0 -6
  144. amulet/utils/weakref.pyi +0 -50
  145. amulet/utils/world_utils.pyi +0 -109
  146. /amulet/img/{missing_world_icon.png → missing_world.png} +0 -0
  147. /amulet/{level/bedrock/chunk/components → mesh}/__init__.py +0 -0
  148. {amulet_core-2.0a6.dist-info → amulet_core-2.0a8.dist-info}/entry_points.txt +0 -0
  149. {amulet_core-2.0a6.dist-info → amulet_core-2.0a8.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,212 @@
1
+ import os
2
+ import shutil
3
+ import zipfile
4
+ import json
5
+ from urllib.request import urlopen, Request
6
+ import io
7
+ from typing import Generator, TypeVar, Any, Optional
8
+ import logging
9
+
10
+ from amulet.resource_pack import JavaResourcePack
11
+
12
+ T = TypeVar("T")
13
+
14
+ log = logging.getLogger(__name__)
15
+
16
+ launcher_manifest: Optional[dict] = None
17
+ INCLUDE_SNAPSHOT = False
18
+
19
+
20
+ def get_launcher_manifest() -> dict:
21
+ global launcher_manifest
22
+ if launcher_manifest is None:
23
+ log.info("Downloading java launcher manifest file.")
24
+ with urlopen(
25
+ "https://launchermeta.mojang.com/mc/game/version_manifest.json", timeout=20
26
+ ) as manifest:
27
+ launcher_manifest = json.load(manifest)
28
+ log.info("Finished downloading java launcher manifest file.")
29
+ return launcher_manifest
30
+
31
+
32
+ def generator_unpacker(gen: Generator[Any, Any, T]) -> T:
33
+ try:
34
+ while True:
35
+ next(gen)
36
+ except StopIteration as e:
37
+ return e.value # type: ignore
38
+
39
+
40
+ def get_latest() -> JavaResourcePack:
41
+ return generator_unpacker(get_latest_iter())
42
+
43
+
44
+ def get_latest_iter() -> Generator[float, None, JavaResourcePack]:
45
+ """Download the latest resource pack if required.
46
+
47
+ :return: The loaded Java resource pack.
48
+ :raises:
49
+ Exception: If the
50
+ """
51
+ vanilla_rp_path = os.path.join(
52
+ os.environ["CACHE_DIR"], "resource_packs", "java", "vanilla"
53
+ )
54
+ try:
55
+ if INCLUDE_SNAPSHOT:
56
+ new_version = get_launcher_manifest()["latest"]["snapshot"]
57
+ else:
58
+ new_version = get_launcher_manifest()["latest"]["release"]
59
+ except Exception as e:
60
+ if os.path.isdir(vanilla_rp_path):
61
+ log.error(
62
+ "Could not download the launcher manifest. The resource pack seems to be present so using that."
63
+ )
64
+ else:
65
+ raise e
66
+ else:
67
+ has_new_pack = False
68
+ if os.path.isfile(os.path.join(vanilla_rp_path, "version")):
69
+ with open(os.path.join(vanilla_rp_path, "version")) as f:
70
+ old_version = f.read()
71
+ has_new_pack = old_version == new_version
72
+
73
+ if not has_new_pack:
74
+ yield from _remove_and_download_iter(vanilla_rp_path, new_version)
75
+ return JavaResourcePack(vanilla_rp_path)
76
+
77
+
78
+ _java_vanilla_fix: Optional[JavaResourcePack] = None
79
+ _java_vanilla_latest: Optional[JavaResourcePack] = None
80
+
81
+
82
+ def get_java_vanilla_fix() -> JavaResourcePack:
83
+ global _java_vanilla_fix
84
+ if _java_vanilla_fix is None:
85
+ _java_vanilla_fix = JavaResourcePack(
86
+ os.path.join(os.path.dirname(__file__), "java_vanilla_fix")
87
+ )
88
+ return _java_vanilla_fix
89
+
90
+
91
+ def get_java_vanilla_latest() -> JavaResourcePack:
92
+ global _java_vanilla_latest
93
+ if _java_vanilla_latest is None:
94
+ _java_vanilla_latest = get_latest()
95
+ return _java_vanilla_latest
96
+
97
+
98
+ def get_java_vanilla_latest_iter() -> Generator[float, None, JavaResourcePack]:
99
+ global _java_vanilla_latest
100
+ if _java_vanilla_latest is None:
101
+ _java_vanilla_latest = yield from get_latest_iter()
102
+ return _java_vanilla_latest
103
+
104
+
105
+ def _remove_and_download(path: str, version: str) -> None:
106
+ for _ in _remove_and_download_iter(path, version):
107
+ pass
108
+
109
+
110
+ def _remove_and_download_iter(path: str, version: str) -> Generator[float, None, None]:
111
+ # try downloading the new resources to a temporary location
112
+ temp_path = os.path.join(os.path.dirname(path), "_temp_")
113
+ # clear the temporary location
114
+ if os.path.isfile(temp_path):
115
+ os.remove(temp_path)
116
+ elif os.path.isdir(temp_path):
117
+ shutil.rmtree(temp_path, ignore_errors=True)
118
+
119
+ yield from download_resources_iter(temp_path, version)
120
+ if os.path.isdir(path):
121
+ shutil.rmtree(path, ignore_errors=True)
122
+
123
+ shutil.move(temp_path, path)
124
+
125
+ with open(os.path.join(path, "version"), "w") as f:
126
+ f.write(version)
127
+
128
+
129
+ def download_with_retry(
130
+ url: str, chunk_size: int = 4096, attempts: int = 5
131
+ ) -> Generator[float, None, bytes]:
132
+ content_length_found = 0
133
+ content = []
134
+
135
+ for _ in range(attempts):
136
+ request = Request(url, headers={"Range": f"bytes={content_length_found}-"})
137
+ with urlopen(request, timeout=20) as response:
138
+ content_length = int(response.headers["content-length"].strip())
139
+ while content_length_found < content_length:
140
+ chunk = response.read(chunk_size)
141
+ if not chunk:
142
+ break
143
+ content.append(chunk)
144
+ content_length_found += len(chunk)
145
+ yield min(1.0, content_length_found / content_length)
146
+ if content_length == content_length_found:
147
+ break
148
+ else:
149
+ raise RuntimeError(f"Failed to download")
150
+ return b"".join(content)
151
+
152
+
153
+ def download_resources(path: str, version: str) -> None:
154
+ generator_unpacker(download_resources_iter(path, version))
155
+
156
+
157
+ def download_resources_iter(
158
+ path: str, version: str, chunk_size: int = 4096
159
+ ) -> Generator[float, None, None]:
160
+ log.info(f"Downloading Java resource pack for version {version}")
161
+ version_url = next(
162
+ (v["url"] for v in get_launcher_manifest()["versions"] if v["id"] == version),
163
+ None,
164
+ )
165
+ if version_url is None:
166
+ raise Exception(f"Could not find Java resource pack for version {version}.")
167
+
168
+ try:
169
+ with urlopen(version_url, timeout=20) as vm:
170
+ version_manifest = json.load(vm)
171
+ version_client_url = version_manifest["downloads"]["client"]["url"]
172
+
173
+ downloader = download_with_retry(version_client_url)
174
+ try:
175
+ while True:
176
+ yield next(downloader) / 2
177
+ except StopIteration as e:
178
+ data = e.value
179
+
180
+ client = zipfile.ZipFile(io.BytesIO(data))
181
+ paths: list[str] = [
182
+ fpath for fpath in client.namelist() if fpath.startswith("assets/")
183
+ ]
184
+ path_count = len(paths)
185
+ for path_index, fpath in enumerate(paths):
186
+ if not path_index % 30:
187
+ yield path_index / (path_count * 2) + 0.5
188
+ if fpath.endswith("/"):
189
+ continue
190
+ os.makedirs(
191
+ os.path.dirname(os.path.abspath(os.path.join(path, fpath))),
192
+ exist_ok=True,
193
+ )
194
+ client.extract(fpath, path)
195
+ if "pack.mcmeta" in client.namelist():
196
+ client.extract("pack.mcmeta", path)
197
+ else:
198
+ # TODO: work out proper version support for this
199
+ with open(os.path.join(path, "pack.mcmeta"), "w") as f:
200
+ f.write(
201
+ '{"pack": {"description": "The default data for Minecraft","pack_format": 7}}'
202
+ )
203
+ if "pack.png" in client.namelist():
204
+ client.extract("pack.png", path)
205
+
206
+ except Exception as e:
207
+ log.error(
208
+ f"Failed to download and extract the Java resource pack for version {version}.",
209
+ exc_info=True,
210
+ )
211
+ raise e
212
+ log.info(f"Finished downloading Java resource pack for version {version}")
@@ -0,0 +1,44 @@
1
+ import os
2
+ import json
3
+
4
+ from amulet.resource_pack.abc import BaseResourcePack
5
+
6
+
7
+ class JavaResourcePack(BaseResourcePack):
8
+ """A class to hold the bare bones information about the resource pack.
9
+ Holds the pack format, description and if the pack is valid.
10
+ This information can be used in a viewer to display the packs to the user."""
11
+
12
+ def __init__(self, resource_pack_path: str):
13
+ super().__init__(resource_pack_path)
14
+ meta_path = os.path.join(resource_pack_path, "pack.mcmeta")
15
+ self._pack_format = 0
16
+ if os.path.isfile(meta_path):
17
+ try:
18
+ with open(meta_path) as f:
19
+ pack_mcmeta = json.load(f)
20
+ except json.JSONDecodeError:
21
+ pass
22
+ else:
23
+ if "pack" in pack_mcmeta:
24
+ if "description" in pack_mcmeta["pack"]:
25
+ self._pack_description = str(pack_mcmeta["pack"]["description"])
26
+ if "pack_format" in pack_mcmeta["pack"]:
27
+ self._pack_format = pack_mcmeta["pack"]["pack_format"]
28
+ self._valid_pack = True
29
+
30
+ pack_icon_path = os.path.join(resource_pack_path, "pack.png")
31
+ if os.path.isfile(pack_icon_path):
32
+ self._pack_icon = pack_icon_path
33
+
34
+ @staticmethod
35
+ def is_valid(pack_path: str) -> bool:
36
+ return os.path.isfile(os.path.join(pack_path, "pack.mcmeta"))
37
+
38
+ def __repr__(self) -> str:
39
+ return f"JavaResourcePack({self._root_dir})"
40
+
41
+ @property
42
+ def pack_format(self) -> int:
43
+ """int - pack format number"""
44
+ return self._pack_format