amulet-core 2.0a8__cp312-cp312-win_amd64.whl → 2.0.1a3.post250529101330__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 (271) hide show
  1. amulet/core/__init__.py +36 -0
  2. amulet/core/__pyinstaller/hook-amulet.core.py +4 -0
  3. amulet/core/_amulet_core.cp312-win_amd64.pyd +0 -0
  4. amulet/core/_amulet_core.pyi +7 -0
  5. amulet/{_version.py → core/_version.py} +3 -3
  6. amulet/core/amulet_core.dll +0 -0
  7. amulet/core/amulet_core.lib +0 -0
  8. amulet/core/amulet_coreConfig.cmake +18 -0
  9. amulet/{biome.pyi → core/biome/__init__.pyi} +3 -3
  10. amulet/core/biome/biome.hpp +53 -0
  11. amulet/{block.pyi → core/block/__init__.pyi} +25 -26
  12. amulet/core/block/block.hpp +156 -0
  13. amulet/{block_entity.pyi → core/block_entity/__init__.pyi} +7 -7
  14. amulet/core/block_entity/block_entity.hpp +84 -0
  15. amulet/{errors.py → core/chunk/__init__.pyi} +37 -33
  16. amulet/core/chunk/chunk.hpp +126 -0
  17. amulet/core/chunk/component/__init__.pyi +18 -0
  18. amulet/core/chunk/component/biome_3d_component.hpp +96 -0
  19. amulet/core/chunk/component/block_component.hpp +101 -0
  20. amulet/core/chunk/component/block_component.pyi +28 -0
  21. amulet/core/chunk/component/block_entity_component.hpp +119 -0
  22. amulet/core/chunk/component/section_array_map.hpp +129 -0
  23. amulet/{chunk_components.pyi → core/chunk/component/section_array_map.pyi} +4 -24
  24. amulet/core/dll.hpp +21 -0
  25. amulet/core/entity/__init__.pyi +105 -0
  26. amulet/core/entity/entity.hpp +100 -0
  27. amulet/{palette → core/palette}/__init__.pyi +2 -2
  28. amulet/core/palette/biome_palette.hpp +65 -0
  29. amulet/{palette → core/palette}/biome_palette.pyi +8 -8
  30. amulet/core/palette/block_palette.hpp +71 -0
  31. amulet/{palette → core/palette}/block_palette.pyi +12 -10
  32. amulet/core/selection/__init__.pyi +8 -0
  33. amulet/core/selection/box.hpp +86 -0
  34. amulet/core/selection/box.pyi +215 -0
  35. amulet/core/selection/group.hpp +80 -0
  36. amulet/core/selection/group.pyi +213 -0
  37. amulet/{version.pyi → core/version/__init__.pyi} +58 -10
  38. amulet/core/version/version.hpp +204 -0
  39. {amulet_core-2.0a8.dist-info → amulet_core-2.0.1a3.post250529101330.dist-info}/METADATA +25 -20
  40. amulet_core-2.0.1a3.post250529101330.dist-info/RECORD +45 -0
  41. {amulet_core-2.0a8.dist-info → amulet_core-2.0.1a3.post250529101330.dist-info}/WHEEL +1 -1
  42. amulet_core-2.0.1a3.post250529101330.dist-info/entry_points.txt +2 -0
  43. amulet/__init__.cp312-win_amd64.pyd +0 -0
  44. amulet/__init__.py.cpp +0 -45
  45. amulet/__init__.pyi +0 -30
  46. amulet/__pyinstaller/hook-amulet.py +0 -4
  47. amulet/_init.py +0 -26
  48. amulet/biome.cpp +0 -36
  49. amulet/biome.hpp +0 -43
  50. amulet/biome.py.cpp +0 -122
  51. amulet/block.cpp +0 -435
  52. amulet/block.hpp +0 -119
  53. amulet/block.py.cpp +0 -377
  54. amulet/block_entity.cpp +0 -12
  55. amulet/block_entity.hpp +0 -56
  56. amulet/block_entity.py.cpp +0 -115
  57. amulet/chunk.cpp +0 -16
  58. amulet/chunk.hpp +0 -100
  59. amulet/chunk.py.cpp +0 -80
  60. amulet/chunk.pyi +0 -28
  61. amulet/chunk_components/biome_3d_component.cpp +0 -5
  62. amulet/chunk_components/biome_3d_component.hpp +0 -79
  63. amulet/chunk_components/block_component.cpp +0 -41
  64. amulet/chunk_components/block_component.hpp +0 -88
  65. amulet/chunk_components/block_entity_component.cpp +0 -5
  66. amulet/chunk_components/block_entity_component.hpp +0 -147
  67. amulet/chunk_components/section_array_map.cpp +0 -129
  68. amulet/chunk_components/section_array_map.hpp +0 -147
  69. amulet/collections/eq.py.hpp +0 -37
  70. amulet/collections/hash.py.hpp +0 -27
  71. amulet/collections/holder.py.hpp +0 -37
  72. amulet/collections/iterator.py.hpp +0 -80
  73. amulet/collections/mapping.py.hpp +0 -199
  74. amulet/collections/mutable_mapping.py.hpp +0 -226
  75. amulet/collections/sequence.py.hpp +0 -163
  76. amulet/collections.pyi +0 -40
  77. amulet/data_types.py +0 -29
  78. amulet/entity.py +0 -182
  79. amulet/game/__init__.py +0 -7
  80. amulet/game/_game.py +0 -152
  81. amulet/game/_universal/__init__.py +0 -1
  82. amulet/game/_universal/_biome.py +0 -17
  83. amulet/game/_universal/_block.py +0 -47
  84. amulet/game/_universal/_version.py +0 -68
  85. amulet/game/abc/__init__.py +0 -22
  86. amulet/game/abc/_block_specification.py +0 -150
  87. amulet/game/abc/biome.py +0 -213
  88. amulet/game/abc/block.py +0 -331
  89. amulet/game/abc/game_version_container.py +0 -25
  90. amulet/game/abc/json_interface.py +0 -27
  91. amulet/game/abc/version.py +0 -44
  92. amulet/game/bedrock/__init__.py +0 -1
  93. amulet/game/bedrock/_biome.py +0 -35
  94. amulet/game/bedrock/_block.py +0 -42
  95. amulet/game/bedrock/_version.py +0 -165
  96. amulet/game/java/__init__.py +0 -2
  97. amulet/game/java/_biome.py +0 -35
  98. amulet/game/java/_block.py +0 -60
  99. amulet/game/java/_version.py +0 -176
  100. amulet/game/translate/__init__.py +0 -12
  101. amulet/game/translate/_functions/__init__.py +0 -15
  102. amulet/game/translate/_functions/_code_functions/__init__.py +0 -0
  103. amulet/game/translate/_functions/_code_functions/_text.py +0 -553
  104. amulet/game/translate/_functions/_code_functions/banner_pattern.py +0 -67
  105. amulet/game/translate/_functions/_code_functions/bedrock_chest_connection.py +0 -152
  106. amulet/game/translate/_functions/_code_functions/bedrock_moving_block_pos.py +0 -88
  107. amulet/game/translate/_functions/_code_functions/bedrock_sign.py +0 -152
  108. amulet/game/translate/_functions/_code_functions/bedrock_skull_rotation.py +0 -16
  109. amulet/game/translate/_functions/_code_functions/custom_name.py +0 -146
  110. amulet/game/translate/_functions/_frozen.py +0 -66
  111. amulet/game/translate/_functions/_state.py +0 -54
  112. amulet/game/translate/_functions/_typing.py +0 -98
  113. amulet/game/translate/_functions/abc.py +0 -123
  114. amulet/game/translate/_functions/carry_nbt.py +0 -160
  115. amulet/game/translate/_functions/carry_properties.py +0 -80
  116. amulet/game/translate/_functions/code.py +0 -143
  117. amulet/game/translate/_functions/map_block_name.py +0 -66
  118. amulet/game/translate/_functions/map_nbt.py +0 -111
  119. amulet/game/translate/_functions/map_properties.py +0 -93
  120. amulet/game/translate/_functions/multiblock.py +0 -112
  121. amulet/game/translate/_functions/new_block.py +0 -42
  122. amulet/game/translate/_functions/new_entity.py +0 -43
  123. amulet/game/translate/_functions/new_nbt.py +0 -206
  124. amulet/game/translate/_functions/new_properties.py +0 -64
  125. amulet/game/translate/_functions/sequence.py +0 -51
  126. amulet/game/translate/_functions/walk_input_nbt.py +0 -331
  127. amulet/game/translate/_translator.py +0 -433
  128. amulet/img/__init__.py +0 -10
  129. amulet/img/missing_no.png +0 -0
  130. amulet/img/missing_pack.png +0 -0
  131. amulet/img/missing_world.png +0 -0
  132. amulet/io/binary_reader.hpp +0 -45
  133. amulet/io/binary_writer.hpp +0 -30
  134. amulet/item.py +0 -75
  135. amulet/level/__init__.pyi +0 -23
  136. amulet/level/_load.py +0 -100
  137. amulet/level/abc/__init__.py +0 -12
  138. amulet/level/abc/_chunk_handle.py +0 -358
  139. amulet/level/abc/_dimension.py +0 -86
  140. amulet/level/abc/_history/__init__.py +0 -1
  141. amulet/level/abc/_history/_cache.py +0 -224
  142. amulet/level/abc/_history/_history_manager.py +0 -291
  143. amulet/level/abc/_level/__init__.py +0 -5
  144. amulet/level/abc/_level/_compactable_level.py +0 -10
  145. amulet/level/abc/_level/_creatable_level.py +0 -28
  146. amulet/level/abc/_level/_disk_level.py +0 -17
  147. amulet/level/abc/_level/_level.py +0 -449
  148. amulet/level/abc/_level/_loadable_level.py +0 -42
  149. amulet/level/abc/_player_storage.py +0 -7
  150. amulet/level/abc/_raw_level.py +0 -187
  151. amulet/level/abc/_registry.py +0 -40
  152. amulet/level/java/__init__.pyi +0 -16
  153. amulet/level/java/_chunk_handle.py +0 -17
  154. amulet/level/java/_dimension.py +0 -20
  155. amulet/level/java/_level.py +0 -184
  156. amulet/level/java/_raw/__init__.pyi +0 -15
  157. amulet/level/java/_raw/_chunk.pyi +0 -23
  158. amulet/level/java/_raw/_constant.py +0 -9
  159. amulet/level/java/_raw/_data_pack/__init__.py +0 -2
  160. amulet/level/java/_raw/_data_pack/data_pack.py +0 -241
  161. amulet/level/java/_raw/_data_pack/data_pack_manager.py +0 -77
  162. amulet/level/java/_raw/_dimension.py +0 -86
  163. amulet/level/java/_raw/_level.py +0 -507
  164. amulet/level/java/_raw/_typing.py +0 -3
  165. amulet/level/java/_raw/java_chunk_decode.cpp +0 -531
  166. amulet/level/java/_raw/java_chunk_decode.hpp +0 -23
  167. amulet/level/java/_raw/java_chunk_encode.cpp +0 -25
  168. amulet/level/java/_raw/java_chunk_encode.hpp +0 -23
  169. amulet/level/java/anvil/__init__.py +0 -2
  170. amulet/level/java/anvil/_dimension.py +0 -170
  171. amulet/level/java/anvil/_region.py +0 -421
  172. amulet/level/java/anvil/_sector_manager.py +0 -223
  173. amulet/level/java/chunk.pyi +0 -81
  174. amulet/level/java/chunk_/_chunk.py +0 -260
  175. amulet/level/java/chunk_/components/inhabited_time.py +0 -12
  176. amulet/level/java/chunk_/components/last_update.py +0 -12
  177. amulet/level/java/chunk_/components/legacy_version.py +0 -12
  178. amulet/level/java/chunk_/components/light_populated.py +0 -12
  179. amulet/level/java/chunk_/components/named_height_2d.py +0 -37
  180. amulet/level/java/chunk_/components/status.py +0 -11
  181. amulet/level/java/chunk_/components/terrain_populated.py +0 -12
  182. amulet/level/java/chunk_components/data_version_component.cpp +0 -32
  183. amulet/level/java/chunk_components/data_version_component.hpp +0 -31
  184. amulet/level/java/chunk_components/java_raw_chunk_component.cpp +0 -56
  185. amulet/level/java/chunk_components/java_raw_chunk_component.hpp +0 -45
  186. amulet/level/java/chunk_components.pyi +0 -22
  187. amulet/level/java/java_chunk.cpp +0 -170
  188. amulet/level/java/java_chunk.hpp +0 -141
  189. amulet/level/java/long_array.hpp +0 -175
  190. amulet/level/java/long_array.pyi +0 -39
  191. amulet/level/temporary_level/__init__.py +0 -1
  192. amulet/level/temporary_level/_level.py +0 -16
  193. amulet/mesh/__init__.py +0 -0
  194. amulet/mesh/block/__init__.pyi +0 -301
  195. amulet/mesh/block/_cube.py +0 -198
  196. amulet/mesh/block/_missing_block.py +0 -20
  197. amulet/mesh/block/block_mesh.cpp +0 -107
  198. amulet/mesh/block/block_mesh.hpp +0 -207
  199. amulet/mesh/util.py +0 -17
  200. amulet/palette/biome_palette.hpp +0 -85
  201. amulet/palette/block_palette.cpp +0 -32
  202. amulet/palette/block_palette.hpp +0 -93
  203. amulet/player.py +0 -62
  204. amulet/pybind11/collections.hpp +0 -118
  205. amulet/pybind11/numpy.hpp +0 -26
  206. amulet/pybind11/py_module.hpp +0 -34
  207. amulet/pybind11/type_hints.hpp +0 -51
  208. amulet/pybind11/types.hpp +0 -25
  209. amulet/pybind11/typing.hpp +0 -7
  210. amulet/resource_pack/__init__.py +0 -63
  211. amulet/resource_pack/abc/__init__.py +0 -2
  212. amulet/resource_pack/abc/resource_pack.py +0 -38
  213. amulet/resource_pack/abc/resource_pack_manager.py +0 -85
  214. amulet/resource_pack/java/__init__.py +0 -2
  215. amulet/resource_pack/java/download_resources.py +0 -212
  216. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_black.png +0 -0
  217. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_blue.png +0 -0
  218. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_brown.png +0 -0
  219. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_cyan.png +0 -0
  220. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_gray.png +0 -0
  221. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_green.png +0 -0
  222. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_light_blue.png +0 -0
  223. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_light_gray.png +0 -0
  224. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_lime.png +0 -0
  225. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_magenta.png +0 -0
  226. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_orange.png +0 -0
  227. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_pink.png +0 -0
  228. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_purple.png +0 -0
  229. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_red.png +0 -0
  230. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_white.png +0 -0
  231. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_yellow.png +0 -0
  232. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/barrier.png +0 -0
  233. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/end_portal.png +0 -0
  234. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/grass.png +0 -0
  235. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/lava.png +0 -0
  236. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/structure_void.png +0 -0
  237. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/water.png +0 -0
  238. amulet/resource_pack/java/java_vanilla_fix/pack.png +0 -0
  239. amulet/resource_pack/java/resource_pack.py +0 -44
  240. amulet/resource_pack/java/resource_pack_manager.py +0 -563
  241. amulet/resource_pack/unknown_resource_pack.py +0 -10
  242. amulet/selection/__init__.py +0 -2
  243. amulet/selection/abstract_selection.py +0 -342
  244. amulet/selection/box.py +0 -852
  245. amulet/selection/group.py +0 -481
  246. amulet/utils/__init__.pyi +0 -23
  247. amulet/utils/call_spec/__init__.py +0 -24
  248. amulet/utils/call_spec/_call_spec.py +0 -257
  249. amulet/utils/cast.py +0 -10
  250. amulet/utils/comment_json.py +0 -188
  251. amulet/utils/format_utils.py +0 -41
  252. amulet/utils/generator.py +0 -18
  253. amulet/utils/matrix.py +0 -243
  254. amulet/utils/numpy.hpp +0 -36
  255. amulet/utils/numpy.pyi +0 -11
  256. amulet/utils/numpy_helpers.py +0 -19
  257. amulet/utils/shareable_lock.py +0 -335
  258. amulet/utils/signal/__init__.py +0 -10
  259. amulet/utils/signal/_signal.py +0 -228
  260. amulet/utils/task_manager.py +0 -235
  261. amulet/utils/typed_property.py +0 -111
  262. amulet/utils/weakref.py +0 -70
  263. amulet/utils/world_utils.py +0 -102
  264. amulet/version.cpp +0 -136
  265. amulet/version.hpp +0 -142
  266. amulet/version.py.cpp +0 -281
  267. amulet_core-2.0a8.dist-info/RECORD +0 -241
  268. amulet_core-2.0a8.dist-info/entry_points.txt +0 -2
  269. /amulet/{__pyinstaller → core/__pyinstaller}/__init__.py +0 -0
  270. /amulet/{py.typed → core/py.typed} +0 -0
  271. {amulet_core-2.0a8.dist-info → amulet_core-2.0.1a3.post250529101330.dist-info}/top_level.txt +0 -0
amulet/block.cpp DELETED
@@ -1,435 +0,0 @@
1
- #include <map>
2
- #include <variant>
3
- #include <type_traits>
4
- #include <string>
5
- #include <functional>
6
- #include <stdexcept>
7
-
8
- #include <amulet/block.hpp>
9
- #include <amulet_nbt/nbt_encoding/binary.hpp>
10
- #include <amulet_nbt/nbt_encoding/string.hpp>
11
-
12
- namespace Amulet {
13
- void Block::serialise(BinaryWriter& writer) const {
14
- writer.writeNumeric<std::uint8_t>(1);
15
- writer.writeSizeAndBytes(get_platform());
16
- get_version()->serialise(writer);
17
- writer.writeSizeAndBytes(namespace_);
18
- writer.writeSizeAndBytes(base_name);
19
-
20
- writer.writeNumeric<std::uint64_t>(properties.size());
21
- for (auto const& [key, val] : properties) {
22
- writer.writeSizeAndBytes(key);
23
- std::visit([&writer](auto&& tag) {
24
- AmuletNBT::write_nbt(writer, "", tag);
25
- }, val);
26
- }
27
- }
28
- std::shared_ptr<Block> Block::deserialise(BinaryReader& reader){
29
- auto version_number = reader.readNumeric<std::uint8_t>();
30
- switch (version_number) {
31
- case 1:
32
- {
33
- std::string platform = reader.readSizeAndBytes();
34
- std::shared_ptr<VersionNumber> version = VersionNumber::deserialise(reader);
35
- std::string namespace_ = reader.readSizeAndBytes();
36
- std::string base_name = reader.readSizeAndBytes();
37
- std::uint64_t property_count;
38
- BlockProperites properties;
39
- reader.readNumericInto<std::uint64_t>(property_count);
40
- for (std::uint64_t i = 0; i < property_count; i++) {
41
- std::string name = reader.readSizeAndBytes();
42
- AmuletNBT::NamedTag named_tag = AmuletNBT::read_nbt(reader);
43
- properties[name] = std::visit([](auto&& tag) -> PropertyValueType {
44
- using T = std::decay_t<decltype(tag)>;
45
- if constexpr (
46
- std::is_same_v<T, AmuletNBT::ByteTag> ||
47
- std::is_same_v<T, AmuletNBT::ShortTag> ||
48
- std::is_same_v<T, AmuletNBT::IntTag> ||
49
- std::is_same_v<T, AmuletNBT::LongTag> ||
50
- std::is_same_v<T, AmuletNBT::StringTag>
51
- ) {
52
- return tag;
53
- }
54
- else {
55
- throw std::invalid_argument("Property tag must be Byte, Short, Int, Long or String");
56
- }
57
- }, named_tag.tag_node);
58
- }
59
- return std::make_shared<Block>(platform, version, namespace_, base_name, properties);
60
- }
61
- default:
62
- throw std::invalid_argument("Unsupported Block version " + std::to_string(version_number));
63
- }
64
- }
65
-
66
- template <typename T>
67
- inline std::vector<std::string> get_ordered_keys(const T& map) {
68
- std::vector<std::string> keys;
69
- keys.reserve(map.size());
70
- for (const auto& [key, _] : map) {
71
- keys.push_back(key);
72
- }
73
- std::sort(keys.begin(), keys.end());
74
- return keys;
75
- }
76
-
77
- std::string Block::java_blockstate() const {
78
- std::string blockstate;
79
- blockstate += get_namespace();
80
- blockstate += ":";
81
- blockstate += get_base_name();
82
- const auto& properties = get_properties();
83
- if (!properties.empty()) {
84
- blockstate += "[";
85
- auto keys = get_ordered_keys(properties);
86
- bool is_first = true;
87
- for (const std::string& key : keys) {
88
- const auto& it = properties.find(key);
89
- std::visit(
90
- [&is_first, &blockstate, &key](auto&& tag) {
91
- using T = std::decay_t<decltype(tag)>;
92
- if constexpr (std::is_same_v<T, AmuletNBT::StringTag>) {
93
- if (is_first) {
94
- is_first = false;
95
- }
96
- else {
97
- blockstate += ",";
98
- }
99
- blockstate += key;
100
- blockstate += "=";
101
- blockstate += tag;
102
- }
103
- },
104
- it->second
105
- );
106
- }
107
- blockstate += "]";
108
- }
109
- return blockstate;
110
- }
111
- std::string Block::bedrock_blockstate() const {
112
- std::string blockstate;
113
- blockstate += get_namespace();
114
- blockstate += ":";
115
- blockstate += get_base_name();
116
- const auto& properties = get_properties();
117
- if (!properties.empty()) {
118
- blockstate += "[";
119
- auto keys = get_ordered_keys(properties);
120
- bool is_first = true;
121
- for (const std::string& key : keys) {
122
- const auto& it = properties.find(key);
123
- std::visit(
124
- [&is_first, &blockstate, &key](auto&& tag) {
125
- if (is_first) {
126
- is_first = false;
127
- }
128
- else {
129
- blockstate += ",";
130
- }
131
- blockstate += "\"";
132
- blockstate += key;
133
- blockstate += "\"=";
134
- using T = std::decay_t<decltype(tag)>;
135
- if constexpr (std::is_same_v<T, AmuletNBT::ByteTag>) {
136
- if (tag == 0) {
137
- blockstate += "false";
138
- } else if (tag == 1) {
139
- blockstate += "true";
140
- }
141
- else {
142
- blockstate += AmuletNBT::write_snbt(tag);
143
- }
144
- }
145
- else if constexpr (std::is_same_v<T, AmuletNBT::StringTag>) {
146
- blockstate += "\"";
147
- blockstate += tag;
148
- blockstate += "\"";
149
- }
150
- else {
151
- blockstate += AmuletNBT::write_snbt(tag);
152
- }
153
- },
154
- it->second
155
- );
156
- }
157
- blockstate += "]";
158
- }
159
- return blockstate;
160
- }
161
-
162
- template <
163
- void(*namespace_validator)(const size_t&, const std::string&),
164
- void(*base_name_validator)(const size_t&, const std::string&),
165
- std::string(*capture_key)(const std::string&, size_t&),
166
- PropertyValueType(*capture_value)(const std::string&, size_t&)
167
- >
168
- std::shared_ptr<Block> parse_blockstate(
169
- const PlatformType& platform,
170
- std::shared_ptr<VersionNumber> version,
171
- const std::string& blockstate
172
- ) {
173
- // This is more lenient than the game parser.
174
- // It may parse formats that the game parsers wouldn't parse but it should support everything they do parse.
175
-
176
- // Find the start of the property section and the end of the resource identifier.
177
- size_t property_start = blockstate.find("[");
178
- if (property_start > blockstate.size()) {
179
- property_start = blockstate.size();
180
- }
181
-
182
- size_t colon_pos = blockstate.find(":");
183
- std::string namespace_;
184
- std::string base_name;
185
- if (colon_pos < property_start) {
186
- // namespaced name
187
- if (colon_pos == 0) { throw std::invalid_argument("namespace is empty"); }
188
- namespace_ = std::string(blockstate.begin(), blockstate.begin() + colon_pos);
189
- if (colon_pos + 1 == property_start) { throw std::invalid_argument("base name is empty"); }
190
- base_name = std::string(blockstate.begin() + colon_pos + 1, blockstate.begin() + property_start);
191
- namespace_validator(0, namespace_);
192
- base_name_validator(colon_pos + 1, base_name);
193
- }
194
- else {
195
- // only base name
196
- namespace_ = "minecraft";
197
- if (property_start == 0) { throw std::invalid_argument("base name is empty"); }
198
- base_name = std::string(blockstate.begin(), blockstate.begin() + property_start);
199
- base_name_validator(0, base_name);
200
- }
201
-
202
- if (property_start < blockstate.size()) {
203
- // has properties
204
- BlockProperites properties;
205
- size_t property_pos = property_start + 1;
206
- if (property_pos < blockstate.size() && blockstate[property_pos] == ']') {
207
- // []
208
- property_pos++;
209
- if (property_pos < blockstate.size()) {
210
- throw std::invalid_argument("Extra data after ]");
211
- }
212
- return std::make_shared<Block>(platform, version, namespace_, base_name, properties);
213
- }
214
- for (;;) {
215
- std::string key = capture_key(blockstate, property_pos);
216
-
217
- if (property_pos >= blockstate.size() || blockstate[property_pos] != '=') {
218
- throw std::invalid_argument("Expected = at position " + std::to_string(property_pos));
219
- }
220
- property_pos++;
221
-
222
- properties[key] = capture_value(blockstate, property_pos);
223
-
224
- if (property_pos >= blockstate.size()) {
225
- throw std::invalid_argument("Expected , or ] at position " + std::to_string(property_pos));
226
- }
227
- switch (blockstate[property_pos]) {
228
- case ',':
229
- break;
230
- case ']':
231
- property_pos++;
232
- if (property_pos < blockstate.size()) {
233
- throw std::invalid_argument("Extra data after ]");
234
- }
235
- return std::make_shared<Block>(platform, version, namespace_, base_name, properties);
236
- default:
237
- throw std::invalid_argument("Expected , or ] at position " + std::to_string(property_pos));
238
- }
239
- property_pos++;
240
- }
241
- }
242
- else {
243
- // does not have properties
244
- return std::make_shared<Block>(platform, version, namespace_, base_name);
245
- }
246
- }
247
-
248
- auto is_alnum = [](const char& chr) {
249
- return (
250
- ('0' <= chr && chr <= '9') ||
251
- ('a' <= (chr | 32) && (chr | 32) <= 'z')
252
- );
253
- };
254
-
255
- inline void validate_java_namespace(const size_t& offset, const std::string& namespace_) {
256
- for (size_t i = 0; i < namespace_.size(); i++) {
257
- const auto& chr = namespace_[i];
258
- if (!(is_alnum(chr) || chr == '_' || chr == '-' || chr == '.')){
259
- throw std::invalid_argument("Invalid namespace character at position " + std::to_string(offset + i));
260
- }
261
- }
262
- }
263
- inline void validate_java_base_name(const size_t& offset, const std::string& base_name) {
264
- for (size_t i = 0; i < base_name.size(); i++) {
265
- const auto& chr = base_name[i];
266
- if (!(is_alnum(chr) || chr == '_' || chr == '-' || chr == '.' || chr == '/')) {
267
- throw std::invalid_argument("Invalid base name character at position " + std::to_string(offset + i));
268
- }
269
- }
270
- }
271
- // key=str
272
- inline std::string capture_java_blockstate_property_key(const std::string& blockstate, size_t& offset) {
273
- size_t key_start = offset;
274
- while (offset < blockstate.size()) {
275
- const auto& chr = blockstate[offset];
276
- if (!(is_alnum(chr) || chr == '_')) {
277
- break;
278
- }
279
- offset++;
280
- }
281
- if (key_start == offset) {
282
- throw std::invalid_argument("Expected a key or ] at position " + std::to_string(offset));
283
- }
284
- return std::string(blockstate.begin() + key_start, blockstate.begin() + offset);
285
- }
286
- inline PropertyValueType capture_java_blockstate_property_value(const std::string& blockstate, size_t& offset) {
287
- size_t value_start = offset;
288
- while (offset < blockstate.size()) {
289
- const auto& chr = blockstate[offset];
290
- if (!(is_alnum(chr) || chr == '_')) {
291
- break;
292
- }
293
- offset++;
294
- }
295
- if (value_start == offset) {
296
- throw std::invalid_argument("Expected a value at position " + std::to_string(offset));
297
- }
298
- return AmuletNBT::StringTag(blockstate.begin() + value_start, blockstate.begin() + offset);
299
- }
300
-
301
- // I think Bedrock resource identifiers are not limited to a-z0-9_-.
302
- inline void validate_bedrock_namespace(const size_t& offset, const std::string& namespace_) {
303
- for (size_t i = 0; i < namespace_.size(); i++) {
304
- const auto& chr = namespace_[i];
305
- if (!(is_alnum(chr) || chr == '_' || chr == '-' || chr == '.')) {
306
- throw std::invalid_argument("Invalid namespace character at position " + std::to_string(offset + i));
307
- }
308
- }
309
- }
310
- inline void validate_bedrock_base_name(const size_t& offset, const std::string& base_name) {
311
- for (size_t i = 0; i < base_name.size(); i++) {
312
- const auto& chr = base_name[i];
313
- if (!(is_alnum(chr) || chr == '_' || chr == '-' || chr == '.')) {
314
- throw std::invalid_argument("Invalid base name character at position " + std::to_string(offset + i));
315
- }
316
- }
317
- }
318
- // "key"=false
319
- // "key"=true
320
- // "key"=nbt
321
- inline std::string capture_bedrock_blockstate_property_key(const std::string& blockstate, size_t& offset) {
322
- // Opening "
323
- if (offset >= blockstate.size() || blockstate[offset] != '"') {
324
- throw std::invalid_argument("Expected \" at position " + std::to_string(offset));
325
- }
326
- offset++;
327
-
328
- // Key
329
- size_t key_start = offset;
330
- while (offset < blockstate.size()) {
331
- const auto& chr = blockstate[offset];
332
- if (!(is_alnum(chr) || chr == '_')) {
333
- break;
334
- }
335
- offset++;
336
- }
337
- if (key_start == offset) {
338
- throw std::invalid_argument("Expected a key or ] at position " + std::to_string(offset));
339
- }
340
- size_t key_end = offset;
341
-
342
- // Closing "
343
- if (offset >= blockstate.size() || blockstate[offset] != '"') {
344
- throw std::invalid_argument("Expected \" at position " + std::to_string(offset));
345
- }
346
- offset++;
347
-
348
- return std::string(blockstate.begin() + key_start, blockstate.begin() + key_end);
349
- }
350
- inline PropertyValueType capture_bedrock_blockstate_property_value(const std::string& blockstate, size_t& offset) {
351
- size_t value_start = offset;
352
- size_t value_end = std::min(
353
- blockstate.find(",", value_start),
354
- blockstate.find("]", value_start)
355
- );
356
- if (value_end >= blockstate.size()) {
357
- throw std::invalid_argument("Expected , or ] after position " + std::to_string(offset));
358
- }
359
- offset = value_end;
360
- AmuletNBT::TagNode node;
361
- try {
362
- node = AmuletNBT::read_snbt(std::string(blockstate.begin() + value_start, blockstate.begin() + value_end));
363
- }
364
- catch (const std::exception& e) {
365
- throw std::invalid_argument("Failed parsing SNBT at position " + std::to_string(value_start) + ". " + e.what());
366
- }
367
- return std::visit(
368
- [](auto&& tag) -> PropertyValueType {
369
- using T = std::decay_t<decltype(tag)>;
370
- if constexpr (
371
- std::is_same_v<T, AmuletNBT::ByteTag> ||
372
- std::is_same_v<T, AmuletNBT::ShortTag> ||
373
- std::is_same_v<T, AmuletNBT::IntTag> ||
374
- std::is_same_v<T, AmuletNBT::LongTag> ||
375
- std::is_same_v<T, AmuletNBT::StringTag>
376
- ) {
377
- return tag;
378
- }
379
- else {
380
- throw std::invalid_argument("Values must be byte, short, int, long or string tags.");
381
- }
382
- },
383
- node
384
- );
385
- }
386
-
387
- std::shared_ptr<Block> Block::from_java_blockstate(const PlatformType& platform, std::shared_ptr<VersionNumber> version, const std::string& blockstate) {
388
- return parse_blockstate<
389
- validate_java_namespace,
390
- validate_java_base_name,
391
- capture_java_blockstate_property_key,
392
- capture_java_blockstate_property_value
393
- >(
394
- platform,
395
- version,
396
- blockstate
397
- );
398
- }
399
- std::shared_ptr<Block> Block::from_bedrock_blockstate(const PlatformType& platform, std::shared_ptr<VersionNumber> version, const std::string& blockstate) {
400
- return parse_blockstate<
401
- validate_bedrock_namespace,
402
- validate_bedrock_base_name,
403
- capture_bedrock_blockstate_property_key,
404
- capture_bedrock_blockstate_property_value
405
- >(
406
- platform,
407
- version,
408
- blockstate
409
- );
410
- }
411
-
412
- void BlockStack::serialise(BinaryWriter& writer) const {
413
- writer.writeNumeric<std::uint8_t>(1);
414
- writer.writeNumeric<std::uint64_t>(get_blocks().size());
415
- for (const auto& block : get_blocks()) {
416
- block->serialise(writer);
417
- }
418
- }
419
- std::shared_ptr<BlockStack> BlockStack::deserialise(BinaryReader& reader) {
420
- auto version_number = reader.readNumeric<std::uint8_t>();
421
- switch (version_number) {
422
- case 1:
423
- {
424
- std::vector<std::shared_ptr<Block>> blocks;
425
- auto count = reader.readNumeric<std::uint64_t>();
426
- for (auto i = 0; i < count; i++) {
427
- blocks.push_back(Block::deserialise(reader));
428
- }
429
- return std::make_shared<BlockStack>(blocks);
430
- }
431
- default:
432
- throw std::invalid_argument("Unsupported BlockStack version " + std::to_string(version_number));
433
- }
434
- }
435
- }
amulet/block.hpp DELETED
@@ -1,119 +0,0 @@
1
- #pragma once
2
-
3
- #include <map>
4
- #include <variant>
5
- #include <string>
6
-
7
- #include <amulet/io/binary_reader.hpp>
8
- #include <amulet/io/binary_writer.hpp>
9
- #include <amulet/version.hpp>
10
- #include <amulet_nbt/tag/int.hpp>
11
- #include <amulet_nbt/tag/string.hpp>
12
-
13
-
14
- namespace Amulet {
15
- typedef std::variant<
16
- AmuletNBT::ByteTag,
17
- AmuletNBT::ShortTag,
18
- AmuletNBT::IntTag,
19
- AmuletNBT::LongTag,
20
- AmuletNBT::StringTag
21
- > PropertyValueType;
22
-
23
- typedef std::map<std::string, PropertyValueType> BlockProperites;
24
-
25
- class Block: public PlatformVersionContainer {
26
- private:
27
- std::string namespace_;
28
- std::string base_name;
29
- BlockProperites properties;
30
- public:
31
- const std::string& get_namespace() const { return namespace_; }
32
- const std::string& get_base_name() const { return base_name; }
33
- const BlockProperites& get_properties() const {
34
- return properties;
35
- }
36
-
37
- template <typename versionT>
38
- Block(
39
- const PlatformType& platform,
40
- const versionT& version,
41
- const std::string& namespace_,
42
- const std::string& base_name
43
- ) :
44
- PlatformVersionContainer(platform, version),
45
- namespace_(namespace_),
46
- base_name(base_name),
47
- properties() {}
48
-
49
- template <
50
- typename versionT,
51
- typename propertiesT
52
- >
53
- Block(
54
- const PlatformType& platform,
55
- const versionT& version,
56
- const std::string& namespace_,
57
- const std::string& base_name,
58
- const propertiesT& properties
59
- ):
60
- PlatformVersionContainer(platform, version),
61
- namespace_(namespace_),
62
- base_name(base_name),
63
- properties(properties) {}
64
-
65
- void serialise(BinaryWriter&) const;
66
- static std::shared_ptr<Block> deserialise(BinaryReader&);
67
-
68
- auto operator<=>(const Block& other) const {
69
- auto cmp = PlatformVersionContainer::operator<=>(other);
70
- if (cmp != 0) { return cmp; }
71
- cmp = namespace_ <=> other.namespace_;
72
- if (cmp != 0) { return cmp; }
73
- cmp = base_name <=> other.base_name;
74
- if (cmp != 0) { return cmp; }
75
- return properties <=> other.properties;
76
- }
77
- bool operator==(const Block& other) const {
78
- return (*this <=> other) == 0;
79
- };
80
-
81
- std::string java_blockstate() const;
82
- std::string bedrock_blockstate() const;
83
- static std::shared_ptr<Block> from_java_blockstate(const PlatformType&, std::shared_ptr<VersionNumber>, const std::string&);
84
- static std::shared_ptr<Block> from_bedrock_blockstate(const PlatformType&, std::shared_ptr<VersionNumber>, const std::string&);
85
- };
86
-
87
- class BlockStack {
88
- private:
89
- std::vector<std::shared_ptr<Block>> _blocks;
90
- public:
91
- const std::vector<std::shared_ptr<Block>>& get_blocks() const { return _blocks; }
92
-
93
- template <typename T>
94
- BlockStack(const T& blocks) : _blocks(blocks) {
95
- if (_blocks.empty()) {
96
- throw std::invalid_argument("A BlockStack must contain at least one block");
97
- }
98
- }
99
-
100
- void serialise(BinaryWriter&) const;
101
- static std::shared_ptr<BlockStack> deserialise(BinaryReader&);
102
-
103
- auto operator<=>(const BlockStack& other) const {
104
- auto cmp = size() <=> other.size();
105
- if (cmp != 0) { return cmp; }
106
- for (size_t i = 0; i < size(); i++) {
107
- cmp = *(*this)[i] <=> *other[i];
108
- if (cmp != 0) { return cmp; }
109
- }
110
- return std::strong_ordering::equal;
111
- }
112
- bool operator==(const BlockStack& other) const {
113
- return (*this <=> other) == 0;
114
- };
115
-
116
- size_t size() const { return _blocks.size(); }
117
- std::shared_ptr<Block> operator[](size_t index) const { return _blocks[index]; };
118
- };
119
- }