amulet-core 2.0a5__cp311-cp311-win_amd64.whl → 2.0a7__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 (232) hide show
  1. amulet/__init__.cp311-win_amd64.pyd +0 -0
  2. amulet/__init__.py.cpp +43 -0
  3. amulet/__init__.pyi +0 -2
  4. amulet/_init.py +0 -2
  5. amulet/_version.py +3 -3
  6. amulet/biome.py.cpp +122 -0
  7. amulet/biome.pyi +0 -2
  8. amulet/block.py.cpp +377 -0
  9. amulet/block.pyi +0 -2
  10. amulet/block_entity.py.cpp +115 -0
  11. amulet/block_entity.pyi +0 -2
  12. amulet/chunk.py.cpp +80 -0
  13. amulet/chunk.pyi +0 -2
  14. amulet/chunk_components/biome_3d_component.cpp +5 -0
  15. amulet/chunk_components/biome_3d_component.hpp +79 -0
  16. amulet/chunk_components/block_component.cpp +41 -0
  17. amulet/chunk_components/block_component.hpp +88 -0
  18. amulet/chunk_components/block_entity_component.cpp +5 -0
  19. amulet/chunk_components/block_entity_component.hpp +147 -0
  20. amulet/chunk_components/section_array_map.cpp +129 -0
  21. amulet/chunk_components/section_array_map.hpp +147 -0
  22. amulet/chunk_components.pyi +20 -18
  23. amulet/collections/eq.py.hpp +37 -0
  24. amulet/collections/hash.py.hpp +27 -0
  25. amulet/collections/holder.py.hpp +37 -0
  26. amulet/collections/iterator.py.hpp +80 -0
  27. amulet/collections/mapping.py.hpp +199 -0
  28. amulet/collections/mutable_mapping.py.hpp +226 -0
  29. amulet/collections/sequence.py.hpp +163 -0
  30. amulet/collections.pyi +8 -5
  31. amulet/entity.py +22 -20
  32. amulet/game/translate/_functions/_code_functions/_text.py +2 -2
  33. amulet/game/translate/_functions/abc.py +10 -3
  34. amulet/img/__init__.py +10 -0
  35. amulet/img/missing_no.png +0 -0
  36. amulet/img/missing_pack.png +0 -0
  37. amulet/img/missing_world.png +0 -0
  38. amulet/io/binary_reader.hpp +45 -0
  39. amulet/io/binary_writer.hpp +30 -0
  40. amulet/level/__init__.pyi +2 -6
  41. amulet/level/abc/_level/_creatable_level.py +1 -2
  42. amulet/level/abc/_level/_level.py +1 -5
  43. amulet/level/java/__init__.pyi +0 -5
  44. amulet/level/java/_raw/__init__.pyi +0 -4
  45. amulet/level/java/_raw/java_chunk_decode.cpp +531 -0
  46. amulet/level/java/_raw/java_chunk_decode.hpp +23 -0
  47. amulet/level/java/_raw/java_chunk_encode.cpp +25 -0
  48. amulet/level/java/_raw/java_chunk_encode.hpp +23 -0
  49. amulet/level/java/chunk_components/data_version_component.cpp +32 -0
  50. amulet/level/java/chunk_components/data_version_component.hpp +31 -0
  51. amulet/level/java/chunk_components/java_raw_chunk_component.cpp +56 -0
  52. amulet/level/java/chunk_components/java_raw_chunk_component.hpp +45 -0
  53. amulet/level/java/java_chunk.cpp +170 -0
  54. amulet/level/java/java_chunk.hpp +141 -0
  55. amulet/level/java/long_array.hpp +175 -0
  56. amulet/level/java/long_array.pyi +2 -1
  57. amulet/mesh/block/__init__.py +1 -0
  58. amulet/mesh/block/block_mesh.py +369 -0
  59. amulet/mesh/block/cube.py +149 -0
  60. amulet/mesh/block/missing_block.py +20 -0
  61. amulet/mesh/util.py +17 -0
  62. amulet/palette/biome_palette.hpp +85 -0
  63. amulet/palette/block_palette.cpp +32 -0
  64. amulet/palette/block_palette.hpp +93 -0
  65. amulet/player.py +4 -6
  66. amulet/pybind11/collections.hpp +118 -0
  67. amulet/pybind11/numpy.hpp +26 -0
  68. amulet/pybind11/py_module.hpp +34 -0
  69. amulet/pybind11/type_hints.hpp +51 -0
  70. amulet/pybind11/types.hpp +25 -0
  71. amulet/pybind11/typing.hpp +7 -0
  72. amulet/resource_pack/__init__.py +62 -0
  73. amulet/resource_pack/abc/__init__.py +2 -0
  74. amulet/resource_pack/abc/resource_pack.py +38 -0
  75. amulet/resource_pack/abc/resource_pack_manager.py +87 -0
  76. amulet/resource_pack/bedrock/__init__.py +2 -0
  77. amulet/resource_pack/bedrock/bedrock_vanilla_fix/pack_icon.png +0 -0
  78. amulet/resource_pack/bedrock/bedrock_vanilla_fix/textures/blocks/grass_carried.png +0 -0
  79. amulet/resource_pack/bedrock/bedrock_vanilla_fix/textures/blocks/grass_side_carried.png +0 -0
  80. amulet/resource_pack/bedrock/bedrock_vanilla_fix/textures/blocks/water.png +0 -0
  81. amulet/resource_pack/bedrock/blockshapes/__init__.py +31 -0
  82. amulet/resource_pack/bedrock/blockshapes/air.py +35 -0
  83. amulet/resource_pack/bedrock/blockshapes/base_blockshape.py +29 -0
  84. amulet/resource_pack/bedrock/blockshapes/bubble_column.py +29 -0
  85. amulet/resource_pack/bedrock/blockshapes/cake.py +46 -0
  86. amulet/resource_pack/bedrock/blockshapes/chest.py +54 -0
  87. amulet/resource_pack/bedrock/blockshapes/comparator.py +51 -0
  88. amulet/resource_pack/bedrock/blockshapes/cross_texture.py +186 -0
  89. amulet/resource_pack/bedrock/blockshapes/cross_texture0.py +17 -0
  90. amulet/resource_pack/bedrock/blockshapes/cross_texture_green.py +16 -0
  91. amulet/resource_pack/bedrock/blockshapes/cube.py +38 -0
  92. amulet/resource_pack/bedrock/blockshapes/default.py +14 -0
  93. amulet/resource_pack/bedrock/blockshapes/door.py +38 -0
  94. amulet/resource_pack/bedrock/blockshapes/door1.py +14 -0
  95. amulet/resource_pack/bedrock/blockshapes/door2.py +14 -0
  96. amulet/resource_pack/bedrock/blockshapes/door3.py +14 -0
  97. amulet/resource_pack/bedrock/blockshapes/door4.py +14 -0
  98. amulet/resource_pack/bedrock/blockshapes/door5.py +14 -0
  99. amulet/resource_pack/bedrock/blockshapes/door6.py +14 -0
  100. amulet/resource_pack/bedrock/blockshapes/double_plant.py +40 -0
  101. amulet/resource_pack/bedrock/blockshapes/enchanting_table.py +22 -0
  102. amulet/resource_pack/bedrock/blockshapes/farmland.py +22 -0
  103. amulet/resource_pack/bedrock/blockshapes/fence.py +22 -0
  104. amulet/resource_pack/bedrock/blockshapes/flat.py +55 -0
  105. amulet/resource_pack/bedrock/blockshapes/flat_wall.py +55 -0
  106. amulet/resource_pack/bedrock/blockshapes/furnace.py +44 -0
  107. amulet/resource_pack/bedrock/blockshapes/furnace_lit.py +14 -0
  108. amulet/resource_pack/bedrock/blockshapes/green_cube.py +39 -0
  109. amulet/resource_pack/bedrock/blockshapes/ladder.py +36 -0
  110. amulet/resource_pack/bedrock/blockshapes/lilypad.py +14 -0
  111. amulet/resource_pack/bedrock/blockshapes/partial_block.py +57 -0
  112. amulet/resource_pack/bedrock/blockshapes/piston.py +44 -0
  113. amulet/resource_pack/bedrock/blockshapes/piston_arm.py +72 -0
  114. amulet/resource_pack/bedrock/blockshapes/portal_frame.py +22 -0
  115. amulet/resource_pack/bedrock/blockshapes/pressure_plate.py +29 -0
  116. amulet/resource_pack/bedrock/blockshapes/pumpkin.py +36 -0
  117. amulet/resource_pack/bedrock/blockshapes/pumpkin_carved.py +14 -0
  118. amulet/resource_pack/bedrock/blockshapes/pumpkin_lit.py +14 -0
  119. amulet/resource_pack/bedrock/blockshapes/red_dust.py +14 -0
  120. amulet/resource_pack/bedrock/blockshapes/repeater.py +53 -0
  121. amulet/resource_pack/bedrock/blockshapes/slab.py +33 -0
  122. amulet/resource_pack/bedrock/blockshapes/slab_double.py +15 -0
  123. amulet/resource_pack/bedrock/blockshapes/tree.py +41 -0
  124. amulet/resource_pack/bedrock/blockshapes/turtle_egg.py +15 -0
  125. amulet/resource_pack/bedrock/blockshapes/vine.py +52 -0
  126. amulet/resource_pack/bedrock/blockshapes/wall.py +22 -0
  127. amulet/resource_pack/bedrock/blockshapes/water.py +38 -0
  128. amulet/resource_pack/bedrock/download_resources.py +147 -0
  129. amulet/resource_pack/bedrock/resource_pack.py +40 -0
  130. amulet/resource_pack/bedrock/resource_pack_manager.py +361 -0
  131. amulet/resource_pack/bedrock/sort_blockshapes.py +15 -0
  132. amulet/resource_pack/java/__init__.py +2 -0
  133. amulet/resource_pack/java/download_resources.py +212 -0
  134. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_black.png +0 -0
  135. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_blue.png +0 -0
  136. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_brown.png +0 -0
  137. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_cyan.png +0 -0
  138. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_gray.png +0 -0
  139. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_green.png +0 -0
  140. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_light_blue.png +0 -0
  141. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_light_gray.png +0 -0
  142. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_lime.png +0 -0
  143. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_magenta.png +0 -0
  144. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_orange.png +0 -0
  145. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_pink.png +0 -0
  146. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_purple.png +0 -0
  147. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_red.png +0 -0
  148. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_white.png +0 -0
  149. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_yellow.png +0 -0
  150. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/barrier.png +0 -0
  151. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/end_portal.png +0 -0
  152. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/grass.png +0 -0
  153. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/lava.png +0 -0
  154. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/structure_void.png +0 -0
  155. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/water.png +0 -0
  156. amulet/resource_pack/java/java_vanilla_fix/pack.png +0 -0
  157. amulet/resource_pack/java/resource_pack.py +44 -0
  158. amulet/resource_pack/java/resource_pack_manager.py +551 -0
  159. amulet/resource_pack/unknown_resource_pack.py +10 -0
  160. amulet/utils/__init__.pyi +0 -5
  161. amulet/utils/call_spec/_call_spec.py +2 -7
  162. amulet/utils/comment_json.py +188 -0
  163. amulet/utils/matrix.py +3 -3
  164. amulet/utils/numpy.hpp +36 -0
  165. amulet/utils/numpy_helpers.py +2 -2
  166. amulet/utils/world_utils.py +2 -2
  167. amulet/version.py.cpp +281 -0
  168. amulet/version.pyi +0 -8
  169. {amulet_core-2.0a5.dist-info → amulet_core-2.0a7.dist-info}/METADATA +3 -3
  170. amulet_core-2.0a7.dist-info/RECORD +295 -0
  171. amulet/chunk_/components/biome.py +0 -155
  172. amulet/chunk_/components/block_entity.py +0 -117
  173. amulet/chunk_/components/entity.py +0 -64
  174. amulet/chunk_/components/height_2d.py +0 -16
  175. amulet/level/bedrock/__init__.py +0 -2
  176. amulet/level/bedrock/_chunk_handle.py +0 -19
  177. amulet/level/bedrock/_dimension.py +0 -22
  178. amulet/level/bedrock/_level.py +0 -187
  179. amulet/level/bedrock/_raw/__init__.py +0 -5
  180. amulet/level/bedrock/_raw/_actor_counter.py +0 -53
  181. amulet/level/bedrock/_raw/_chunk.py +0 -54
  182. amulet/level/bedrock/_raw/_chunk_decode.py +0 -668
  183. amulet/level/bedrock/_raw/_chunk_encode.py +0 -602
  184. amulet/level/bedrock/_raw/_constant.py +0 -9
  185. amulet/level/bedrock/_raw/_dimension.py +0 -343
  186. amulet/level/bedrock/_raw/_level.py +0 -463
  187. amulet/level/bedrock/_raw/_level_dat.py +0 -90
  188. amulet/level/bedrock/_raw/_typing.py +0 -6
  189. amulet/level/bedrock/_raw/leveldb_chunk_versions.py +0 -83
  190. amulet/level/bedrock/chunk/__init__.py +0 -1
  191. amulet/level/bedrock/chunk/_chunk.py +0 -126
  192. amulet/level/bedrock/chunk/components/chunk_version.py +0 -12
  193. amulet/level/bedrock/chunk/components/finalised_state.py +0 -13
  194. amulet/level/bedrock/chunk/components/raw_chunk.py +0 -15
  195. amulet/level/construction/__init__.py +0 -0
  196. amulet/level/java/_chunk_handle.pyi +0 -15
  197. amulet/level/java/_dimension.pyi +0 -13
  198. amulet/level/java/_level.pyi +0 -120
  199. amulet/level/java/_raw/_chunk_decode.py +0 -561
  200. amulet/level/java/_raw/_chunk_encode.py +0 -463
  201. amulet/level/java/_raw/_constant.pyi +0 -20
  202. amulet/level/java/_raw/_data_pack/__init__.pyi +0 -8
  203. amulet/level/java/_raw/_data_pack/data_pack.pyi +0 -197
  204. amulet/level/java/_raw/_data_pack/data_pack_manager.pyi +0 -75
  205. amulet/level/java/_raw/_dimension.pyi +0 -72
  206. amulet/level/java/_raw/_level.pyi +0 -238
  207. amulet/level/java/_raw/_typing.pyi +0 -5
  208. amulet/level/java/anvil/__init__.pyi +0 -11
  209. amulet/level/java/anvil/_dimension.pyi +0 -109
  210. amulet/level/java/anvil/_region.pyi +0 -197
  211. amulet/level/java/anvil/_sector_manager.pyi +0 -142
  212. amulet/level/java_forge/__init__.py +0 -0
  213. amulet/level/mcstructure/__init__.py +0 -0
  214. amulet/level/nbt/__init__.py +0 -0
  215. amulet/level/schematic/__init__.py +0 -0
  216. amulet/level/sponge_schematic/__init__.py +0 -0
  217. amulet/utils/call_spec/__init__.pyi +0 -53
  218. amulet/utils/call_spec/_call_spec.pyi +0 -272
  219. amulet/utils/matrix.pyi +0 -177
  220. amulet/utils/shareable_lock.pyi +0 -190
  221. amulet/utils/signal/__init__.pyi +0 -25
  222. amulet/utils/signal/_signal.pyi +0 -84
  223. amulet/utils/task_manager.pyi +0 -168
  224. amulet/utils/typing.py +0 -4
  225. amulet/utils/typing.pyi +0 -6
  226. amulet/utils/weakref.pyi +0 -50
  227. amulet/utils/world_utils.pyi +0 -109
  228. amulet_core-2.0a5.dist-info/RECORD +0 -210
  229. /amulet/{level/bedrock/chunk/components → mesh}/__init__.py +0 -0
  230. {amulet_core-2.0a5.dist-info → amulet_core-2.0a7.dist-info}/WHEEL +0 -0
  231. {amulet_core-2.0a5.dist-info → amulet_core-2.0a7.dist-info}/entry_points.txt +0 -0
  232. {amulet_core-2.0a5.dist-info → amulet_core-2.0a7.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,531 @@
1
+ #include <memory>
2
+ #include <map>
3
+ #include <cstdint>
4
+ #include <stdexcept>
5
+ #include <type_traits>
6
+ #include <string>
7
+ #include <functional>
8
+ #include <variant>
9
+ #include <algorithm>
10
+
11
+ #include <pybind11/pybind11.h>
12
+
13
+ #include <amulet_nbt/tag/named_tag.hpp>
14
+ #include <amulet_nbt/tag/compound.hpp>
15
+
16
+ #include <amulet/version.hpp>
17
+ #include <amulet/block.hpp>
18
+ #include <amulet/chunk.hpp>
19
+ #include <amulet/level/java/java_chunk.hpp>
20
+ #include <amulet/level/java/long_array.hpp>
21
+
22
+ namespace py = pybind11;
23
+ using namespace AmuletNBT;
24
+
25
+ namespace Amulet {
26
+ template <typename tagT>
27
+ tagT get_tag(const CompoundTag& compound, std::string name, std::function<tagT()> get_default) {
28
+ const auto& it = compound.find(name);
29
+ if (
30
+ it != compound.end() &&
31
+ std::holds_alternative<tagT>(it->second)
32
+ ) {
33
+ return std::get<tagT>(it->second);
34
+ }
35
+ return get_default();
36
+ }
37
+
38
+ template <typename tagT>
39
+ tagT pop_tag(CompoundTag& compound, std::string name, std::function<tagT()> get_default) {
40
+ auto node = compound.extract(name);
41
+ if (
42
+ node &&
43
+ std::holds_alternative<tagT>(node.mapped())
44
+ ) {
45
+ return std::get<tagT>(node.mapped());
46
+ }
47
+ return get_default();
48
+ }
49
+
50
+ CompoundTagPtr get_region(const std::map<std::string, NamedTag>& raw_chunk) {
51
+ const auto& it = raw_chunk.find("region");
52
+ if (
53
+ it != raw_chunk.end() &&
54
+ std::holds_alternative<CompoundTagPtr>(it->second.tag_node)
55
+ ) {
56
+ return std::get<CompoundTagPtr>(it->second.tag_node);
57
+ }
58
+ return std::make_shared<CompoundTag>();
59
+ }
60
+
61
+ CompoundTagPtr get_level(const CompoundTag& region) {
62
+ return get_tag<CompoundTagPtr>(
63
+ region,
64
+ "Level",
65
+ []() { return std::make_shared<CompoundTag>(); }
66
+ );
67
+ }
68
+
69
+ std::int64_t validate_coords(
70
+ CompoundTag& level,
71
+ std::int64_t cx,
72
+ std::int64_t cz
73
+ ) {
74
+ if (
75
+ pop_tag<IntTag>(level, "xPos", []() { return IntTag(); }).value != cx ||
76
+ pop_tag<IntTag>(level, "zPos", []() { return IntTag(); }).value != cz
77
+ ) {
78
+ throw std::runtime_error("Chunk coord data is incorrect.");
79
+ }
80
+ std::int64_t cy = pop_tag<IntTag>(level, "yPos", []() { return IntTag(); }).value;
81
+ return cy << 4;
82
+ }
83
+
84
+ template <typename chunkT>
85
+ void decode_last_update(chunkT& chunk, CompoundTag& level) {
86
+ // TODO
87
+ //pop_tag<LongTag>(level, "LastUpdate", []() { return LongTag(); }).value;
88
+ }
89
+
90
+ template <typename chunkT>
91
+ void decode_inhabited_time(chunkT& chunk, CompoundTag& level) {
92
+ // TODO
93
+ //pop_tag<LongTag>(level, "InhabitedTime", []() { return LongTag(); }).value;
94
+ }
95
+
96
+ template <typename chunkT>
97
+ void decode_terrain_populated(chunkT& chunk, CompoundTag& level) {
98
+ // TODO
99
+ //pop_tag<ByteTag>(level, "TerrainPopulated", []() { return ByteTag(1); }).value;
100
+ }
101
+
102
+ template <typename chunkT>
103
+ void decode_light_populated(chunkT& chunk, CompoundTag& level) {
104
+ // TODO
105
+ //pop_tag<ByteTag>(level, "LightPopulated", []() { return ByteTag(1); }).value;
106
+ }
107
+
108
+ template <typename chunkT>
109
+ void decode_status(chunkT& chunk, CompoundTag& level, std::int64_t data_version) {
110
+ // TODO
111
+ /*std::string status = pop_tag<StringTag>(level, "Status", []() { return StringTag(); });
112
+ if (!status.empty()) {
113
+ chunk.set_status(status);
114
+ }
115
+ else if (data_version >= 3454) {
116
+ chunk.set_status("minecraft:full");
117
+ }
118
+ else if (data_version >= 1912) {
119
+ chunk.set_status("full");
120
+ }
121
+ else {
122
+ chunk.set_status("postprocessed");
123
+ }*/
124
+ }
125
+
126
+ template <typename chunkT>
127
+ void decode_heightmap(chunkT& chunk, CompoundTag& level) {
128
+ // TODO
129
+ }
130
+
131
+ template <typename chunkT>
132
+ void decode_heightmaps_compound(chunkT& chunk, CompoundTag& level) {
133
+ // TODO
134
+ }
135
+
136
+ template <int DataVersion>
137
+ std::shared_ptr<JavaChunk> _decode_java_chunk(
138
+ py::object game_version,
139
+ std::map<std::string, NamedTag>& raw_chunk,
140
+ CompoundTag& region,
141
+ std::int64_t cx,
142
+ std::int64_t cz,
143
+ std::shared_ptr<VersionNumber> version,
144
+ std::int64_t data_version,
145
+ std::shared_ptr<BlockStack> default_block,
146
+ std::shared_ptr<Biome> default_biome,
147
+ std::function<std::shared_ptr<Block>()> get_water
148
+ ) {
149
+ // Validate coordinates
150
+ CompoundTagPtr level_ptr;
151
+ CompoundTag& level = [&]() -> CompoundTag& {
152
+ if constexpr (DataVersion >= 2203) {
153
+ return data_version >= 2844 ? region : *(level_ptr = get_level(region));
154
+ }
155
+ else {
156
+ level_ptr = get_level(region);
157
+ return *level_ptr;
158
+
159
+ }
160
+ }();
161
+ auto floor_y = validate_coords(level, cx, cz);
162
+
163
+ // Make the chunk
164
+ auto chunk_ptr = [&]() {
165
+ if constexpr (DataVersion >= 2203) {
166
+ return std::make_shared<JavaChunk2203>(
167
+ data_version,
168
+ default_block,
169
+ default_biome
170
+ );
171
+ }
172
+ else if constexpr (DataVersion >= 1466) {
173
+ return std::make_shared<JavaChunk1466>(
174
+ data_version,
175
+ default_block,
176
+ default_biome
177
+ );
178
+ }
179
+ else if constexpr (DataVersion >= 1444) {
180
+ return std::make_shared<JavaChunk1444>(
181
+ data_version,
182
+ default_block,
183
+ default_biome
184
+ );
185
+ }
186
+ else if constexpr (DataVersion >= 0) {
187
+ return std::make_shared<JavaChunk0>(
188
+ data_version,
189
+ default_block,
190
+ default_biome
191
+ );
192
+ }
193
+ else {
194
+ return std::make_shared<JavaChunkNA>(
195
+ default_block,
196
+ default_biome
197
+ );
198
+ }
199
+ }();
200
+ auto& chunk = *chunk_ptr;
201
+
202
+ if constexpr (DataVersion == -1) {
203
+ // LegacyVersionComponent TODO
204
+ //pop_tag<ByteTag>(*level, "V", []() { return ByteTag(1); });
205
+ }
206
+
207
+ decode_last_update(chunk, level);
208
+ decode_inhabited_time(chunk, level);
209
+
210
+ // Status
211
+ if constexpr (DataVersion >= 1444) {
212
+ decode_status(chunk, level, data_version);
213
+ }
214
+ else {
215
+ decode_terrain_populated(chunk, level);
216
+ decode_light_populated(chunk, level);
217
+ }
218
+
219
+ // Heightmaps
220
+ if constexpr (DataVersion >= 1466) {
221
+ decode_heightmaps_compound(chunk, level);
222
+ }
223
+ else {
224
+ decode_heightmap(chunk, level);
225
+ }
226
+
227
+ // Sections
228
+ ListTagPtr sections_ptr = get_tag<ListTagPtr>(level, "sections", []() { return std::make_shared<ListTag>(); });
229
+ if (!std::holds_alternative<CompoundListTag>(*sections_ptr)) {
230
+ throw std::invalid_argument("Chunk sections is not a list of compound tags.");
231
+ }
232
+ auto& sections = std::get<CompoundListTag>(*sections_ptr);
233
+ std::map<std::int64_t, CompoundTagPtr> sections_map;
234
+ for (auto& tag : sections) {
235
+ sections_map.emplace(
236
+ get_tag<ByteTag>(*tag, "Y", []() { return ByteTag(); }).value,
237
+ tag
238
+ );
239
+ }
240
+
241
+ // blocks
242
+ auto block_component = chunk.get_block();
243
+ auto block_palette = block_component->get_palette();
244
+ auto block_sections = block_component->get_sections();
245
+ if constexpr (DataVersion >= 1444) {
246
+ // Palette format
247
+ // if data_version >= 2844:
248
+ // region.sections[].block_states.data
249
+ // region.sections[].block_states.palette
250
+ // elif data_version >= 2836:
251
+ // region.Level.Sections[].block_states.data
252
+ // region.Level.Sections[].block_states.palette
253
+ // else:
254
+ // region.Level.Sections[].BlockStates
255
+ // region.Level.Sections[].Palette
256
+
257
+ // TODO: move this to C++
258
+ py::object Waterloggable = py::module::import("amulet.game.java").attr("Waterloggable");
259
+ py::object WaterloggableYes = Waterloggable.attr("Yes");
260
+ py::object WaterloggableAlways = Waterloggable.attr("Always");
261
+
262
+ for (auto& [cy, section] : sections_map) {
263
+ auto [palette_tag, data_tag] = [&]() {
264
+ if (data_version >= 2836) {
265
+ auto block_states_tag = pop_tag<CompoundTagPtr>(*section, "block_states", []() { return std::make_shared<CompoundTag>(); });
266
+ return std::make_pair(
267
+ pop_tag<ListTagPtr>(*block_states_tag, "palette", []() { return std::make_shared<ListTag>(); }),
268
+ pop_tag<LongArrayTagPtr>(*block_states_tag, "data", []() { return std::make_shared<LongArrayTag>(); })
269
+ );
270
+ }
271
+ else {
272
+ return std::make_pair(
273
+ pop_tag<ListTagPtr>(*section, "Palette", []() { return std::make_shared<ListTag>(); }),
274
+ pop_tag<LongArrayTagPtr>(*section, "BlockStates", []() { return std::make_shared<LongArrayTag>(); })
275
+ );
276
+ }
277
+ }();
278
+ if (!std::holds_alternative<CompoundListTag>(*palette_tag)) { continue; }
279
+ const auto& palette = std::get<CompoundListTag>(*palette_tag);
280
+ size_t palette_size = palette.size();
281
+ std::vector<std::uint32_t> lut;
282
+ lut.reserve(palette_size);
283
+ for (auto& block_tag : palette) {
284
+ auto block_name = get_tag<StringTag>(*block_tag, "Name", []() -> StringTag { throw std::invalid_argument("Block has no Name attribute."); });
285
+ auto colon_index = block_name.find(':');
286
+ auto [block_namespace, block_base_name] = [&]() -> std::pair<std::string, std::string> {
287
+ if (colon_index == std::string::npos) {
288
+ return std::make_pair("", block_name);
289
+ }
290
+ else {
291
+ return std::make_pair(
292
+ block_name.substr(0, colon_index),
293
+ block_name.substr(colon_index + 1)
294
+ );
295
+ }
296
+ }();
297
+ auto properties_tag = get_tag<CompoundTagPtr>(*block_tag, "Properties", []() { return std::make_shared<CompoundTag>(); });
298
+ std::map<std::string, PropertyValueType> block_properties;
299
+ for (const auto& [k, v] : *properties_tag) {
300
+ std::visit([&block_properties, &k](auto&& arg) {
301
+ using T = std::decay_t<decltype(arg)>;
302
+ if constexpr (
303
+ std::is_same_v<T, AmuletNBT::ByteTag> ||
304
+ std::is_same_v<T, AmuletNBT::ShortTag> ||
305
+ std::is_same_v<T, AmuletNBT::IntTag> ||
306
+ std::is_same_v<T, AmuletNBT::LongTag> ||
307
+ std::is_same_v<T, AmuletNBT::StringTag>
308
+ ) {
309
+ block_properties.emplace(k, arg);
310
+ }
311
+ }, v);
312
+ }
313
+ std::vector<std::shared_ptr<Block>> blocks;
314
+
315
+ // TODO: convert this to C++
316
+ py::object waterloggable = game_version.attr("block").attr("waterloggable")(block_namespace, block_base_name);
317
+ if (waterloggable.equal(WaterloggableYes)) {
318
+ auto waterlogged_it = block_properties.find("waterlogged");
319
+ if (
320
+ waterlogged_it != block_properties.end() and
321
+ std::holds_alternative<StringTag>(waterlogged_it->second)
322
+ ) {
323
+ if (std::get<StringTag>(waterlogged_it->second) == "true") {
324
+ blocks.push_back(get_water());
325
+ }
326
+ block_properties.erase(waterlogged_it);
327
+ }
328
+ }
329
+ else if (waterloggable.equal(WaterloggableAlways)) {
330
+ blocks.push_back(get_water());
331
+ }
332
+ blocks.insert(
333
+ blocks.begin(),
334
+ std::make_shared<Block>(
335
+ "java",
336
+ version,
337
+ block_namespace,
338
+ block_base_name,
339
+ block_properties
340
+ )
341
+ );
342
+
343
+ lut.push_back(
344
+ block_palette->block_stack_to_index(
345
+ std::make_shared<BlockStack>(blocks)
346
+ )
347
+ );
348
+ }
349
+
350
+ block_sections->set_section(
351
+ cy,
352
+ [&] {
353
+ if (data_tag->empty()) {
354
+ return std::make_shared<IndexArray3D>(
355
+ std::make_tuple<std::uint16_t>(16, 16, 16),
356
+ 0
357
+ );
358
+ }
359
+ else {
360
+ std::vector<std::uint32_t> decoded_vector(4096);
361
+ std::span<std::uint32_t> decoded_span(decoded_vector);
362
+ Amulet::decode_long_array(
363
+ std::span<std::uint64_t>(reinterpret_cast<std::uint64_t*>(data_tag->data()), data_tag->size()),
364
+ decoded_span,
365
+ std::max<std::uint8_t>(4, std::bit_width(palette_size - 1)),
366
+ data_version <= 2529
367
+ );
368
+ auto index_array = std::make_shared<IndexArray3D>(
369
+ std::make_tuple<std::uint16_t>(16, 16, 16)
370
+ );
371
+ std::span<std::uint32_t> index_array_span(index_array->get_buffer(), index_array->get_size());
372
+ // Convert YZX to XYZ and look up in lut.
373
+ for (size_t y = 0; y < 16; y++) {
374
+ for (size_t x = 0; x < 16; x++) {
375
+ for (size_t z = 0; z < 16; z++) {
376
+ auto& block_index = decoded_span[y * 256 + z * 16 + x];
377
+ if (palette_size <= block_index) {
378
+ throw std::runtime_error(
379
+ "Block index at cx=" + std::to_string(cx) +
380
+ ",cy=" + std::to_string(cy) +
381
+ ",cz=" + std::to_string(cx) +
382
+ ",dx=" + std::to_string(x) +
383
+ ",dy=" + std::to_string(y) +
384
+ ",dz=" + std::to_string(z) +
385
+ " is larger than the block palette size."
386
+ );
387
+ }
388
+ index_array_span[x * 256 + y * 16 + z] = lut[block_index];
389
+ }
390
+ }
391
+ }
392
+ return index_array;
393
+ }
394
+ }()
395
+ );
396
+ }
397
+ }
398
+ else {
399
+ // Numerical format
400
+ throw std::runtime_error("NotImplemented");
401
+ }
402
+
403
+ // TODO: biomes
404
+
405
+ // Return the chunk
406
+ return chunk_ptr;
407
+ }
408
+
409
+
410
+ // Get the default block for this dimension and version via the python API.
411
+ std::shared_ptr<BlockStack> get_default_block(
412
+ py::object dimension,
413
+ const VersionRange& version_range
414
+ ) {
415
+ auto default_block = dimension.attr("default_block")().cast<std::shared_ptr<BlockStack>>();
416
+ std::vector<std::shared_ptr<Block>> blocks;
417
+ for (const auto& block : default_block->get_blocks()) {
418
+ if (version_range.contains(block->get_platform(), *block->get_version())) {
419
+ blocks.push_back(block);
420
+ }
421
+ else {
422
+ py::object block_ = py::module::import("amulet.game").attr("get_game_version")(
423
+ py::cast(block->get_platform()),
424
+ py::cast(block->get_version())
425
+ ).attr("block").attr("translate")(
426
+ "java",
427
+ py::cast(version_range.get_max_version()),
428
+ py::cast(block)
429
+ ).attr("__getitem__")(0);
430
+ if (py::isinstance<Block>(block_)) {
431
+ blocks.push_back(block_.cast<std::shared_ptr<Block>>());
432
+ }
433
+ }
434
+ }
435
+ if (blocks.empty()) {
436
+ blocks.push_back(
437
+ std::make_shared<Block>(
438
+ version_range.get_platform(),
439
+ version_range.get_max_version(),
440
+ "minecraft",
441
+ "air"
442
+ )
443
+ );
444
+ }
445
+ return std::make_shared<BlockStack>(blocks);
446
+ }
447
+
448
+ std::shared_ptr<Biome> get_default_biome(
449
+ py::object dimension,
450
+ const VersionRange& version_range
451
+ ) {
452
+ auto biome = dimension.attr("default_biome")().cast<std::shared_ptr<Biome>>();
453
+ if (version_range.contains(biome->get_platform(), *biome->get_version())) {
454
+ return biome;
455
+ }
456
+ else {
457
+ return py::module::import("amulet.game").attr("get_game_version")(
458
+ py::cast(biome->get_platform()),
459
+ py::cast(biome->get_version())
460
+ ).attr("biome").attr("translate")(
461
+ "java",
462
+ py::cast(version_range.get_max_version()),
463
+ py::cast(biome)
464
+ ).cast<std::shared_ptr<Biome>>();
465
+ }
466
+ }
467
+
468
+ std::shared_ptr<JavaChunk> decode_java_chunk(
469
+ py::object raw_level,
470
+ py::object dimension,
471
+ std::map<std::string, NamedTag>& raw_chunk,
472
+ std::int64_t cx,
473
+ std::int64_t cz
474
+ ) {
475
+ // Get the region compound tag
476
+ CompoundTagPtr region = get_region(raw_chunk);
477
+
478
+ std::int64_t data_version = pop_tag<IntTag>(
479
+ *region,
480
+ "DataVersion",
481
+ []() { return IntTag(-1); }
482
+ ).value;
483
+
484
+ auto version = std::make_shared<VersionNumber>(std::initializer_list<std::int64_t>{ data_version });
485
+ auto version_range = std::make_shared<VersionRange>("java", version, version);
486
+ auto default_block = get_default_block(dimension, *version_range);
487
+ auto default_biome = get_default_biome(dimension, *version_range);
488
+ py::object game_version = py::module::import("amulet.game").attr("get_game_version")("java", py::cast(version));
489
+
490
+ std::shared_ptr<Block> _water_block;
491
+ auto get_water = [&version, &_water_block]() {
492
+ if (!_water_block) {
493
+ py::object block = py::module::import("amulet.game").attr("get_game_version")(
494
+ "java",
495
+ VersionNumber({ 3837 })
496
+ ).attr("block").attr("translate")(
497
+ "java",
498
+ version,
499
+ Block(
500
+ "java",
501
+ VersionNumber({ 3837 }),
502
+ "minecraft",
503
+ "water",
504
+ std::initializer_list<BlockProperites::value_type>{ {"level", StringTag("0")} }
505
+ )
506
+ ).attr("__getitem__")(0);
507
+ if (!py::isinstance<Block>(block)) {
508
+ throw std::runtime_error("Water block did not convert to a block in version Java " + version->toString());
509
+ }
510
+ _water_block = block.cast<std::shared_ptr<Block>>();
511
+ }
512
+ return _water_block;
513
+ };
514
+
515
+ if (data_version >= 2203) {
516
+ return _decode_java_chunk<2203>(game_version, raw_chunk, *region, cx, cz, version, data_version, default_block, default_biome, get_water);
517
+ }
518
+ else if (data_version >= 1466) {
519
+ return _decode_java_chunk<1466>(game_version, raw_chunk, *region, cx, cz, version, data_version, default_block, default_biome, get_water);
520
+ }
521
+ else if (data_version >= 1444) {
522
+ return _decode_java_chunk<1444>(game_version, raw_chunk, *region, cx, cz, version, data_version, default_block, default_biome, get_water);
523
+ }
524
+ else if (data_version >= 0) {
525
+ return _decode_java_chunk<0>(game_version, raw_chunk, *region, cx, cz, version, data_version, default_block, default_biome, get_water);
526
+ }
527
+ else {
528
+ return _decode_java_chunk<-1>(game_version, raw_chunk, *region, cx, cz, version, data_version, default_block, default_biome, get_water);
529
+ }
530
+ }
531
+ }
@@ -0,0 +1,23 @@
1
+ #pragma once
2
+ #include <memory>
3
+ #include <map>
4
+ #include <cstdint>
5
+
6
+ #include <pybind11/pybind11.h>
7
+
8
+ #include <amulet_nbt/tag/named_tag.hpp>
9
+
10
+ #include <amulet/chunk.hpp>
11
+ #include <amulet/level/java/java_chunk.hpp>
12
+
13
+ namespace py = pybind11;
14
+
15
+ namespace Amulet {
16
+ std::shared_ptr<Amulet::JavaChunk> decode_java_chunk(
17
+ py::object raw_level,
18
+ py::object dimension,
19
+ std::map<std::string, AmuletNBT::NamedTag>& raw_chunk,
20
+ std::int64_t cx,
21
+ std::int64_t cz
22
+ );
23
+ }
@@ -0,0 +1,25 @@
1
+ #include <memory>
2
+ #include <map>
3
+ #include <cstdint>
4
+ #include <stdexcept>
5
+
6
+ #include <pybind11/pybind11.h>
7
+
8
+ #include <amulet_nbt/tag/named_tag.hpp>
9
+
10
+ #include <amulet/chunk.hpp>
11
+ #include <amulet/level/java/java_chunk.hpp>
12
+
13
+ namespace py = pybind11;
14
+
15
+ namespace Amulet {
16
+ std::map<std::string, AmuletNBT::NamedTag> encode_java_chunk(
17
+ py::object raw_level,
18
+ py::object dimension,
19
+ std::shared_ptr<Amulet::JavaChunk> chunk,
20
+ std::int64_t cx,
21
+ std::int64_t cz
22
+ ) {
23
+ throw std::runtime_error("");
24
+ }
25
+ }
@@ -0,0 +1,23 @@
1
+ #pragma once
2
+ #include <memory>
3
+ #include <map>
4
+ #include <cstdint>
5
+
6
+ #include <pybind11/pybind11.h>
7
+
8
+ #include <amulet_nbt/tag/named_tag.hpp>
9
+
10
+ #include <amulet/chunk.hpp>
11
+ #include <amulet/level/java/java_chunk.hpp>
12
+
13
+ namespace py = pybind11;
14
+
15
+ namespace Amulet {
16
+ std::map<std::string, AmuletNBT::NamedTag> encode_java_chunk(
17
+ py::object raw_level,
18
+ py::object dimension,
19
+ std::shared_ptr<Amulet::JavaChunk> chunk,
20
+ std::int64_t cx,
21
+ std::int64_t cz
22
+ );
23
+ }
@@ -0,0 +1,32 @@
1
+ #include <cstdint>
2
+ #include <optional>
3
+
4
+ #include <amulet/io/binary_writer.hpp>
5
+ #include <amulet/io/binary_reader.hpp>
6
+
7
+ #include <amulet/level/java/chunk_components/data_version_component.hpp>
8
+
9
+ namespace Amulet {
10
+ const std::string DataVersionComponent::ComponentID = "Amulet::DataVersionComponent";
11
+
12
+ std::optional<std::string> DataVersionComponent::serialise() const {
13
+ if (_data_version) {
14
+ BinaryWriter writer;
15
+ writer.writeNumeric<std::int64_t>(_data_version.value());
16
+ return writer.getBuffer();
17
+ }
18
+ else {
19
+ return std::nullopt;
20
+ }
21
+ }
22
+ void DataVersionComponent::deserialise(std::optional<std::string> data) {
23
+ if (data) {
24
+ size_t position = 0;
25
+ BinaryReader reader(data.value(), position);
26
+ _data_version = reader.readNumeric<std::int64_t>();
27
+ }
28
+ else {
29
+ _data_version = std::nullopt;
30
+ }
31
+ }
32
+ }
@@ -0,0 +1,31 @@
1
+ #pragma once
2
+
3
+ #include <optional>
4
+ #include <cstdint>
5
+ #include <string>
6
+ #include <stdexcept>
7
+
8
+
9
+ namespace Amulet {
10
+ class DataVersionComponent {
11
+ private:
12
+ std::optional<std::int64_t> _data_version;
13
+ protected:
14
+ // Null constructor
15
+ DataVersionComponent() {};
16
+ // Default constructor
17
+ void init(std::int64_t data_version) { _data_version = data_version; }
18
+ // Serialise the component data
19
+ std::optional<std::string> serialise() const;
20
+ // Deserialise the component
21
+ void deserialise(std::optional<std::string>);
22
+ public:
23
+ static const std::string ComponentID;
24
+ std::int64_t get_data_version() {
25
+ if (_data_version) {
26
+ return *_data_version;
27
+ }
28
+ throw std::runtime_error("DataVersionComponent has not been loaded.");
29
+ };
30
+ };
31
+ }