amulet-core 2.0a5__cp311-cp311-macosx_10_9_universal2.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 (210) hide show
  1. amulet/__init__.cpython-311-darwin.so +0 -0
  2. amulet/__init__.pyi +30 -0
  3. amulet/__pyinstaller/__init__.py +2 -0
  4. amulet/__pyinstaller/hook-amulet.py +4 -0
  5. amulet/_init.py +28 -0
  6. amulet/_version.py +21 -0
  7. amulet/biome.cpp +36 -0
  8. amulet/biome.hpp +43 -0
  9. amulet/biome.pyi +77 -0
  10. amulet/block.cpp +435 -0
  11. amulet/block.hpp +119 -0
  12. amulet/block.pyi +273 -0
  13. amulet/block_entity.cpp +12 -0
  14. amulet/block_entity.hpp +56 -0
  15. amulet/block_entity.pyi +80 -0
  16. amulet/chunk.cpp +16 -0
  17. amulet/chunk.hpp +99 -0
  18. amulet/chunk.pyi +30 -0
  19. amulet/chunk_/components/biome.py +155 -0
  20. amulet/chunk_/components/block_entity.py +117 -0
  21. amulet/chunk_/components/entity.py +64 -0
  22. amulet/chunk_/components/height_2d.py +16 -0
  23. amulet/chunk_components.pyi +95 -0
  24. amulet/collections.pyi +37 -0
  25. amulet/data_types.py +29 -0
  26. amulet/entity.py +180 -0
  27. amulet/errors.py +63 -0
  28. amulet/game/__init__.py +7 -0
  29. amulet/game/_game.py +152 -0
  30. amulet/game/_universal/__init__.py +1 -0
  31. amulet/game/_universal/_biome.py +17 -0
  32. amulet/game/_universal/_block.py +47 -0
  33. amulet/game/_universal/_version.py +68 -0
  34. amulet/game/abc/__init__.py +22 -0
  35. amulet/game/abc/_block_specification.py +150 -0
  36. amulet/game/abc/biome.py +213 -0
  37. amulet/game/abc/block.py +331 -0
  38. amulet/game/abc/game_version_container.py +25 -0
  39. amulet/game/abc/json_interface.py +27 -0
  40. amulet/game/abc/version.py +44 -0
  41. amulet/game/bedrock/__init__.py +1 -0
  42. amulet/game/bedrock/_biome.py +35 -0
  43. amulet/game/bedrock/_block.py +42 -0
  44. amulet/game/bedrock/_version.py +165 -0
  45. amulet/game/java/__init__.py +2 -0
  46. amulet/game/java/_biome.py +35 -0
  47. amulet/game/java/_block.py +60 -0
  48. amulet/game/java/_version.py +176 -0
  49. amulet/game/translate/__init__.py +12 -0
  50. amulet/game/translate/_functions/__init__.py +15 -0
  51. amulet/game/translate/_functions/_code_functions/__init__.py +0 -0
  52. amulet/game/translate/_functions/_code_functions/_text.py +553 -0
  53. amulet/game/translate/_functions/_code_functions/banner_pattern.py +67 -0
  54. amulet/game/translate/_functions/_code_functions/bedrock_chest_connection.py +152 -0
  55. amulet/game/translate/_functions/_code_functions/bedrock_moving_block_pos.py +88 -0
  56. amulet/game/translate/_functions/_code_functions/bedrock_sign.py +152 -0
  57. amulet/game/translate/_functions/_code_functions/bedrock_skull_rotation.py +16 -0
  58. amulet/game/translate/_functions/_code_functions/custom_name.py +146 -0
  59. amulet/game/translate/_functions/_frozen.py +66 -0
  60. amulet/game/translate/_functions/_state.py +54 -0
  61. amulet/game/translate/_functions/_typing.py +98 -0
  62. amulet/game/translate/_functions/abc.py +116 -0
  63. amulet/game/translate/_functions/carry_nbt.py +160 -0
  64. amulet/game/translate/_functions/carry_properties.py +80 -0
  65. amulet/game/translate/_functions/code.py +143 -0
  66. amulet/game/translate/_functions/map_block_name.py +66 -0
  67. amulet/game/translate/_functions/map_nbt.py +111 -0
  68. amulet/game/translate/_functions/map_properties.py +93 -0
  69. amulet/game/translate/_functions/multiblock.py +112 -0
  70. amulet/game/translate/_functions/new_block.py +42 -0
  71. amulet/game/translate/_functions/new_entity.py +43 -0
  72. amulet/game/translate/_functions/new_nbt.py +206 -0
  73. amulet/game/translate/_functions/new_properties.py +64 -0
  74. amulet/game/translate/_functions/sequence.py +51 -0
  75. amulet/game/translate/_functions/walk_input_nbt.py +331 -0
  76. amulet/game/translate/_translator.py +433 -0
  77. amulet/item.py +75 -0
  78. amulet/level/__init__.pyi +27 -0
  79. amulet/level/_load.py +100 -0
  80. amulet/level/abc/__init__.py +12 -0
  81. amulet/level/abc/_chunk_handle.py +335 -0
  82. amulet/level/abc/_dimension.py +86 -0
  83. amulet/level/abc/_history/__init__.py +1 -0
  84. amulet/level/abc/_history/_cache.py +224 -0
  85. amulet/level/abc/_history/_history_manager.py +291 -0
  86. amulet/level/abc/_level/__init__.py +5 -0
  87. amulet/level/abc/_level/_compactable_level.py +10 -0
  88. amulet/level/abc/_level/_creatable_level.py +29 -0
  89. amulet/level/abc/_level/_disk_level.py +17 -0
  90. amulet/level/abc/_level/_level.py +453 -0
  91. amulet/level/abc/_level/_loadable_level.py +42 -0
  92. amulet/level/abc/_player_storage.py +7 -0
  93. amulet/level/abc/_raw_level.py +187 -0
  94. amulet/level/abc/_registry.py +40 -0
  95. amulet/level/bedrock/__init__.py +2 -0
  96. amulet/level/bedrock/_chunk_handle.py +19 -0
  97. amulet/level/bedrock/_dimension.py +22 -0
  98. amulet/level/bedrock/_level.py +187 -0
  99. amulet/level/bedrock/_raw/__init__.py +5 -0
  100. amulet/level/bedrock/_raw/_actor_counter.py +53 -0
  101. amulet/level/bedrock/_raw/_chunk.py +54 -0
  102. amulet/level/bedrock/_raw/_chunk_decode.py +668 -0
  103. amulet/level/bedrock/_raw/_chunk_encode.py +602 -0
  104. amulet/level/bedrock/_raw/_constant.py +9 -0
  105. amulet/level/bedrock/_raw/_dimension.py +343 -0
  106. amulet/level/bedrock/_raw/_level.py +463 -0
  107. amulet/level/bedrock/_raw/_level_dat.py +90 -0
  108. amulet/level/bedrock/_raw/_typing.py +6 -0
  109. amulet/level/bedrock/_raw/leveldb_chunk_versions.py +83 -0
  110. amulet/level/bedrock/chunk/__init__.py +1 -0
  111. amulet/level/bedrock/chunk/_chunk.py +126 -0
  112. amulet/level/bedrock/chunk/components/__init__.py +0 -0
  113. amulet/level/bedrock/chunk/components/chunk_version.py +12 -0
  114. amulet/level/bedrock/chunk/components/finalised_state.py +13 -0
  115. amulet/level/bedrock/chunk/components/raw_chunk.py +15 -0
  116. amulet/level/construction/__init__.py +0 -0
  117. amulet/level/java/__init__.pyi +21 -0
  118. amulet/level/java/_chunk_handle.py +17 -0
  119. amulet/level/java/_chunk_handle.pyi +15 -0
  120. amulet/level/java/_dimension.py +20 -0
  121. amulet/level/java/_dimension.pyi +13 -0
  122. amulet/level/java/_level.py +184 -0
  123. amulet/level/java/_level.pyi +120 -0
  124. amulet/level/java/_raw/__init__.pyi +19 -0
  125. amulet/level/java/_raw/_chunk.pyi +23 -0
  126. amulet/level/java/_raw/_chunk_decode.py +561 -0
  127. amulet/level/java/_raw/_chunk_encode.py +463 -0
  128. amulet/level/java/_raw/_constant.py +9 -0
  129. amulet/level/java/_raw/_constant.pyi +20 -0
  130. amulet/level/java/_raw/_data_pack/__init__.py +2 -0
  131. amulet/level/java/_raw/_data_pack/__init__.pyi +8 -0
  132. amulet/level/java/_raw/_data_pack/data_pack.py +241 -0
  133. amulet/level/java/_raw/_data_pack/data_pack.pyi +197 -0
  134. amulet/level/java/_raw/_data_pack/data_pack_manager.py +77 -0
  135. amulet/level/java/_raw/_data_pack/data_pack_manager.pyi +75 -0
  136. amulet/level/java/_raw/_dimension.py +86 -0
  137. amulet/level/java/_raw/_dimension.pyi +72 -0
  138. amulet/level/java/_raw/_level.py +507 -0
  139. amulet/level/java/_raw/_level.pyi +238 -0
  140. amulet/level/java/_raw/_typing.py +3 -0
  141. amulet/level/java/_raw/_typing.pyi +5 -0
  142. amulet/level/java/anvil/__init__.py +2 -0
  143. amulet/level/java/anvil/__init__.pyi +11 -0
  144. amulet/level/java/anvil/_dimension.py +170 -0
  145. amulet/level/java/anvil/_dimension.pyi +109 -0
  146. amulet/level/java/anvil/_region.py +421 -0
  147. amulet/level/java/anvil/_region.pyi +197 -0
  148. amulet/level/java/anvil/_sector_manager.py +223 -0
  149. amulet/level/java/anvil/_sector_manager.pyi +142 -0
  150. amulet/level/java/chunk.pyi +81 -0
  151. amulet/level/java/chunk_/_chunk.py +260 -0
  152. amulet/level/java/chunk_/components/inhabited_time.py +12 -0
  153. amulet/level/java/chunk_/components/last_update.py +12 -0
  154. amulet/level/java/chunk_/components/legacy_version.py +12 -0
  155. amulet/level/java/chunk_/components/light_populated.py +12 -0
  156. amulet/level/java/chunk_/components/named_height_2d.py +37 -0
  157. amulet/level/java/chunk_/components/status.py +11 -0
  158. amulet/level/java/chunk_/components/terrain_populated.py +12 -0
  159. amulet/level/java/chunk_components.pyi +22 -0
  160. amulet/level/java/long_array.pyi +38 -0
  161. amulet/level/java_forge/__init__.py +0 -0
  162. amulet/level/mcstructure/__init__.py +0 -0
  163. amulet/level/nbt/__init__.py +0 -0
  164. amulet/level/schematic/__init__.py +0 -0
  165. amulet/level/sponge_schematic/__init__.py +0 -0
  166. amulet/level/temporary_level/__init__.py +1 -0
  167. amulet/level/temporary_level/_level.py +16 -0
  168. amulet/palette/__init__.pyi +8 -0
  169. amulet/palette/biome_palette.pyi +45 -0
  170. amulet/palette/block_palette.pyi +45 -0
  171. amulet/player.py +64 -0
  172. amulet/py.typed +0 -0
  173. amulet/selection/__init__.py +2 -0
  174. amulet/selection/abstract_selection.py +342 -0
  175. amulet/selection/box.py +852 -0
  176. amulet/selection/group.py +481 -0
  177. amulet/utils/__init__.pyi +28 -0
  178. amulet/utils/call_spec/__init__.py +24 -0
  179. amulet/utils/call_spec/__init__.pyi +53 -0
  180. amulet/utils/call_spec/_call_spec.py +262 -0
  181. amulet/utils/call_spec/_call_spec.pyi +272 -0
  182. amulet/utils/format_utils.py +41 -0
  183. amulet/utils/generator.py +18 -0
  184. amulet/utils/matrix.py +243 -0
  185. amulet/utils/matrix.pyi +177 -0
  186. amulet/utils/numpy.pyi +11 -0
  187. amulet/utils/numpy_helpers.py +19 -0
  188. amulet/utils/shareable_lock.py +335 -0
  189. amulet/utils/shareable_lock.pyi +190 -0
  190. amulet/utils/signal/__init__.py +10 -0
  191. amulet/utils/signal/__init__.pyi +25 -0
  192. amulet/utils/signal/_signal.py +228 -0
  193. amulet/utils/signal/_signal.pyi +84 -0
  194. amulet/utils/task_manager.py +235 -0
  195. amulet/utils/task_manager.pyi +168 -0
  196. amulet/utils/typed_property.py +111 -0
  197. amulet/utils/typing.py +4 -0
  198. amulet/utils/typing.pyi +6 -0
  199. amulet/utils/weakref.py +70 -0
  200. amulet/utils/weakref.pyi +50 -0
  201. amulet/utils/world_utils.py +102 -0
  202. amulet/utils/world_utils.pyi +109 -0
  203. amulet/version.cpp +136 -0
  204. amulet/version.hpp +142 -0
  205. amulet/version.pyi +94 -0
  206. amulet_core-2.0a5.dist-info/METADATA +103 -0
  207. amulet_core-2.0a5.dist-info/RECORD +210 -0
  208. amulet_core-2.0a5.dist-info/WHEEL +5 -0
  209. amulet_core-2.0a5.dist-info/entry_points.txt +2 -0
  210. amulet_core-2.0a5.dist-info/top_level.txt +1 -0
amulet/block.hpp ADDED
@@ -0,0 +1,119 @@
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
+ }
amulet/block.pyi ADDED
@@ -0,0 +1,273 @@
1
+ from __future__ import annotations
2
+
3
+ import collections.abc
4
+ import types
5
+ import typing
6
+
7
+ import amulet.version
8
+ import amulet_nbt
9
+
10
+ __all__ = ["Block", "BlockStack", "PropertyValueType"]
11
+
12
+ class Block(amulet.version.PlatformVersionContainer):
13
+ """
14
+ A class to manage the state of a block.
15
+
16
+ It is an immutable object that contains the platform, version, namespace, base name and properties.
17
+
18
+ Here's a few examples on how create a Block object:
19
+
20
+ >>> # Create a stone block for Java 1.20.2
21
+ >>> stone = Block("java", VersionNumber(3578), "minecraft", "stone")
22
+ >>> # The Java block version number is the Java data version
23
+
24
+ >>> # Create a stone block for Bedrock
25
+ >>> stone = Block("bedrock", VersionNumber(1, 21, 0, 3), "minecraft", "stone")
26
+ >>> # The Bedrock block version number is the value stored as an int with the block data.
27
+
28
+ >>> # Create a Java water block with the level property
29
+ >>> water = Block(
30
+ >>> "java", VersionNumber(3578),
31
+ >>> "minecraft", # the namespace
32
+ >>> "water", # the base name
33
+ >>> { # A dictionary of properties.
34
+ >>> # Keys must be strings and values must be a numerical or string NBT type.
35
+ >>> "level": StringTag("0") # define a property `level` with a string value `0`
36
+ >>> }
37
+ >>> )
38
+ """
39
+
40
+ @staticmethod
41
+ def from_bedrock_blockstate(
42
+ platform: str, version: amulet.version.VersionNumber, blockstate: str
43
+ ) -> Block:
44
+ """
45
+ Parse a Bedrock format blockstate where values are all strings and populate a :class:`Block` class with the data.
46
+
47
+ >>> stone = Block.from_bedrock_blockstate("minecraft:stone")
48
+ >>> water = Block.from_bedrock_blockstate("minecraft:water["liquid_depth"=0]")
49
+
50
+ :param platform: The platform the block is defined in.
51
+ :param version: The version the block is defined in.
52
+ :param blockstate: The Bedrock blockstate string to parse.
53
+ :return: A Block instance containing the state.
54
+ """
55
+
56
+ @staticmethod
57
+ def from_java_blockstate(
58
+ platform: str, version: amulet.version.VersionNumber, blockstate: str
59
+ ) -> Block:
60
+ """
61
+ Parse a Java format blockstate where values are all strings and populate a :class:`Block` class with the data.
62
+
63
+ >>> stone = Block.from_java_blockstate("minecraft:stone")
64
+ >>> water = Block.from_java_blockstate("minecraft:water[level=0]")
65
+
66
+ :param platform: The platform the block is defined in.
67
+ :param version: The version the block is defined in.
68
+ :param blockstate: The Java blockstate string to parse.
69
+ :return: A Block instance containing the state.
70
+ """
71
+
72
+ @typing.overload
73
+ def __eq__(self, arg0: Block) -> bool: ...
74
+ @typing.overload
75
+ def __eq__(self, arg0: typing.Any) -> bool | types.NotImplementedType: ...
76
+ def __ge__(self, arg0: Block) -> bool: ...
77
+ def __getstate__(self) -> bytes: ...
78
+ def __gt__(self, arg0: Block) -> bool: ...
79
+ def __hash__(self) -> int: ...
80
+ def __init__(
81
+ self,
82
+ platform: str,
83
+ version: amulet.version.VersionNumber,
84
+ namespace: str,
85
+ base_name: str,
86
+ properties: dict[
87
+ str,
88
+ amulet_nbt.ByteTag
89
+ | amulet_nbt.ShortTag
90
+ | amulet_nbt.IntTag
91
+ | amulet_nbt.LongTag
92
+ | amulet_nbt.StringTag,
93
+ ] = {},
94
+ ) -> None: ...
95
+ def __le__(self, arg0: Block) -> bool: ...
96
+ def __lt__(self, arg0: Block) -> bool: ...
97
+ def __repr__(self) -> str: ...
98
+ def __setstate__(self, arg0: bytes) -> None: ...
99
+ @property
100
+ def base_name(self) -> str:
101
+ """
102
+ The base name of the blockstate represented by the :class:`Block` object.
103
+
104
+ >>> block: Block
105
+ >>> block.base_name
106
+
107
+ :return: The base name of the blockstate
108
+ """
109
+
110
+ @property
111
+ def bedrock_blockstate(self) -> str:
112
+ """
113
+ The Bedrock blockstate string of this :class:`Block` object.
114
+ Converts the property values to the SNBT format to preserve type.
115
+
116
+ >>> bell = Block(
117
+ >>> "java", VersionNumber(3578),
118
+ >>> "minecraft",
119
+ >>> "bell",
120
+ >>> {
121
+ >>> "attachment":StringTag("standing"),
122
+ >>> "direction":IntTag(0),
123
+ >>> "toggle_bit":ByteTag(0)
124
+ >>> }
125
+ >>> )
126
+ >>> bell.bedrock_blockstate
127
+ minecraft:bell["attachment"="standing","direction"=0,"toggle_bit"=false]
128
+
129
+ :return: The SNBT blockstate string
130
+ """
131
+
132
+ @property
133
+ def java_blockstate(self) -> str:
134
+ """
135
+ The Java blockstate string of this :class:`Block` object.
136
+ Note this will only contain properties with StringTag values.
137
+
138
+ >>> stone = Block("java", VersionNumber(3578), "minecraft", "stone")
139
+ >>> stone.java_blockstate
140
+ minecraft:stone
141
+ >>> water = Block("java", VersionNumber(3578), "minecraft", "water", {"level": StringTag("0")})
142
+ >>> water.java_blockstate
143
+ minecraft:water[level=0]
144
+
145
+ :return: The blockstate string
146
+ """
147
+
148
+ @property
149
+ def namespace(self) -> str:
150
+ """
151
+ The namespace of the blockstate represented by the :class:`Block` object.
152
+
153
+ >>> block: Block
154
+ >>> water.namespace
155
+
156
+ :return: The namespace of the blockstate
157
+ """
158
+
159
+ @property
160
+ def namespaced_name(self) -> str:
161
+ """
162
+ The namespace:base_name of the blockstate represented by the :class:`Block` object.
163
+
164
+ >>> block: Block
165
+ >>> block.namespaced_name
166
+
167
+ :return: The namespace:base_name of the blockstate
168
+ """
169
+
170
+ @property
171
+ def properties(
172
+ self,
173
+ ) -> dict[
174
+ str,
175
+ amulet_nbt.ByteTag
176
+ | amulet_nbt.ShortTag
177
+ | amulet_nbt.IntTag
178
+ | amulet_nbt.LongTag
179
+ | amulet_nbt.StringTag,
180
+ ]:
181
+ """
182
+ The properties of the blockstate represented by the :class:`Block` object as a dictionary.
183
+ >>> block: Block
184
+ >>> block.properties
185
+
186
+ :return: A mapping of the properties of the blockstate
187
+ """
188
+
189
+ class BlockStack:
190
+ """
191
+ A stack of block objects.
192
+
193
+ Java 1.13 added the concept of waterlogging blocks whereby some blocks have a `waterlogged` property.
194
+ Bedrock achieved the same behaviour by added a layering system which allows the second block to be any block.
195
+
196
+ Amulet supports both implementations with a stack of one or more block objects similar to how Bedrock handles it.
197
+ Amulet places no restrictions on which blocks can be extra blocks.
198
+ Extra block may be discarded if the format does not support them.
199
+
200
+ Create a waterlogged stone block.
201
+ >>> waterlogged_stone = BlockStack(
202
+ >>> Block("java", VersionNumber(3578), "minecraft", "stone"),
203
+ >>> Block("java", VersionNumber(3578), "minecraft", "water", {"level": StringTag("0")})
204
+ >>> )
205
+
206
+ Get a block at an index
207
+ >>> stone = waterlogged_stone[0]
208
+ >>> water = waterlogged_stone[1]
209
+
210
+ Get the blocks as a list
211
+ >>> blocks = list(waterlogged_stone)
212
+ """
213
+
214
+ def __contains__(self, arg0: typing.Any) -> bool: ...
215
+ @typing.overload
216
+ def __eq__(self, arg0: BlockStack) -> bool: ...
217
+ @typing.overload
218
+ def __eq__(self, arg0: typing.Any) -> bool | types.NotImplementedType: ...
219
+ def __ge__(self, arg0: BlockStack) -> bool: ...
220
+ @typing.overload
221
+ def __getitem__(self, arg0: int) -> Block: ...
222
+ @typing.overload
223
+ def __getitem__(self, arg0: slice) -> list: ...
224
+ def __gt__(self, arg0: BlockStack) -> bool: ...
225
+ def __hash__(self) -> int: ...
226
+ def __init__(self, block: Block, *extra_blocks: Block) -> None: ...
227
+ def __iter__(self) -> collections.abc.Iterator[Block]: ...
228
+ def __le__(self, arg0: BlockStack) -> bool: ...
229
+ def __len__(self) -> int: ...
230
+ def __lt__(self, arg0: BlockStack) -> bool: ...
231
+ def __repr__(self) -> str: ...
232
+ def __reversed__(self) -> collections.abc.Iterator[Block]: ...
233
+ def count(self, value: typing.Any) -> int: ...
234
+ def index(
235
+ self, value: typing.Any, start: int = 0, stop: int = 9223372036854775807
236
+ ) -> int: ...
237
+ @property
238
+ def base_block(self) -> Block:
239
+ """
240
+ The first block in the stack.
241
+
242
+ >>> waterlogged_stone = BlockStack(
243
+ >>> Block("java", VersionNumber(3578), "minecraft", "stone"),
244
+ >>> Block("java", VersionNumber(3578), "minecraft", "water", {"level": StringTag("0")})
245
+ >>> )
246
+ >>> waterlogged_stone.base_block
247
+ Block("java", VersionNumber(3578), "minecraft", "stone")
248
+
249
+ :return: A Block object
250
+ """
251
+
252
+ @property
253
+ def extra_blocks(self) -> tuple:
254
+ """
255
+ The extra blocks in the stack.
256
+
257
+ >>> waterlogged_stone = BlockStack(
258
+ >>> Block("java", VersionNumber(3578), "minecraft", "stone"),
259
+ >>> Block("java", VersionNumber(3578), "minecraft", "water", {"level": StringTag("0")})
260
+ >>> )
261
+ >>> waterlogged_stone.extra_blocks
262
+ (Block("java", VersionNumber(3578), "minecraft", "water", {"level": StringTag("0")}),)
263
+
264
+ :return: A tuple of :class:`Block` objects
265
+ """
266
+
267
+ PropertyValueType: typing.TypeAlias = (
268
+ amulet_nbt.ByteTag
269
+ | amulet_nbt.ShortTag
270
+ | amulet_nbt.IntTag
271
+ | amulet_nbt.LongTag
272
+ | amulet_nbt.StringTag
273
+ )
@@ -0,0 +1,12 @@
1
+ #include <amulet/block_entity.hpp>
2
+
3
+ namespace Amulet {
4
+
5
+ void BlockEntity::serialise(BinaryWriter&) const {
6
+ throw std::runtime_error("NotImplemented");
7
+ }
8
+ std::shared_ptr<BlockEntity> BlockEntity::deserialise(BinaryReader&) {
9
+ throw std::runtime_error("NotImplemented");
10
+ }
11
+
12
+ }
@@ -0,0 +1,56 @@
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/named_tag.hpp>
11
+ #include <amulet_nbt/tag/eq.hpp>
12
+
13
+
14
+ namespace Amulet {
15
+ class BlockEntity: public PlatformVersionContainer {
16
+ private:
17
+ std::string _namespace;
18
+ std::string _base_name;
19
+ std::shared_ptr<AmuletNBT::NamedTag> _nbt;
20
+
21
+ public:
22
+ const std::string& get_namespace() const { return _namespace; }
23
+ void set_namespace(const std::string& namespace_) { _namespace = namespace_; }
24
+
25
+ const std::string& get_base_name() const { return _base_name; }
26
+ void set_base_name(const std::string& base_name) { _base_name = base_name; }
27
+
28
+ std::shared_ptr<AmuletNBT::NamedTag> get_nbt() const { return _nbt; }
29
+ void set_nbt(std::shared_ptr<AmuletNBT::NamedTag> nbt) { _nbt = nbt; }
30
+
31
+ BlockEntity(
32
+ const PlatformType& platform,
33
+ std::shared_ptr<VersionNumber> version,
34
+ const std::string& namespace_,
35
+ const std::string& base_name,
36
+ std::shared_ptr<AmuletNBT::NamedTag> nbt
37
+ ):
38
+ PlatformVersionContainer(platform, version),
39
+ _namespace(namespace_),
40
+ _base_name(base_name),
41
+ _nbt(nbt)
42
+ {}
43
+
44
+ void serialise(BinaryWriter&) const;
45
+ static std::shared_ptr<BlockEntity> deserialise(BinaryReader&);
46
+
47
+ bool operator==(const BlockEntity& other) const {
48
+ return (
49
+ PlatformVersionContainer::operator==(other) &&
50
+ _namespace == other._namespace &&
51
+ _base_name == other._base_name &&
52
+ AmuletNBT::NBTTag_eq(*_nbt, *other._nbt)
53
+ );
54
+ };
55
+ };
56
+ }
@@ -0,0 +1,80 @@
1
+ from __future__ import annotations
2
+
3
+ import types
4
+ import typing
5
+
6
+ import amulet.version
7
+ import amulet_nbt
8
+
9
+ __all__ = ["BlockEntity"]
10
+
11
+ class BlockEntity(amulet.version.PlatformVersionContainer):
12
+ """
13
+ A class to contain all the data to define a BlockEntity.
14
+ """
15
+
16
+ @typing.overload
17
+ def __eq__(self, arg0: BlockEntity) -> bool: ...
18
+ @typing.overload
19
+ def __eq__(self, arg0: typing.Any) -> bool | types.NotImplementedType: ...
20
+ def __getstate__(self) -> bytes: ...
21
+ def __hash__(self) -> int: ...
22
+ def __init__(
23
+ self,
24
+ platform: str,
25
+ version: amulet.version.VersionNumber,
26
+ namespace: str,
27
+ base_name: str,
28
+ nbt: amulet_nbt.NamedTag,
29
+ ) -> None: ...
30
+ def __repr__(self) -> str: ...
31
+ def __setstate__(self, arg0: bytes) -> None: ...
32
+ @property
33
+ def base_name(self) -> str:
34
+ """
35
+ The base name of the block entity represented by the :class:`BlockEntity` object.
36
+
37
+ >>> block_entity: BlockEntity
38
+ >>> block_entity.base_name
39
+
40
+ :return: The base name of the block entity
41
+ """
42
+
43
+ @base_name.setter
44
+ def base_name(self, arg1: str) -> None: ...
45
+ @property
46
+ def namespace(self) -> str:
47
+ """
48
+ The namespace of the block entity represented by the :class:`BlockEntity` object.
49
+
50
+ >>> block_entity: BlockEntity
51
+ >>> block_entity.namespace
52
+
53
+ :return: The namespace of the block entity
54
+ """
55
+
56
+ @namespace.setter
57
+ def namespace(self, arg1: str) -> None: ...
58
+ @property
59
+ def namespaced_name(self) -> str:
60
+ """
61
+ The namespace:base_name of the block entity represented by the :class:`BlockEntity` object.
62
+
63
+ >>> block_entity: BlockEntity
64
+ >>> block_entity.namespaced_name
65
+
66
+ :return: The namespace:base_name of the block entity
67
+ """
68
+
69
+ @property
70
+ def nbt(self) -> amulet_nbt.NamedTag:
71
+ """
72
+ The nbt data for the block entity.
73
+ >>> block_entity: BlockEntity
74
+ >>> block_entity.nbt
75
+
76
+ :return: The NamedTag of the block entity
77
+ """
78
+
79
+ @nbt.setter
80
+ def nbt(self, arg1: amulet_nbt.NamedTag) -> None: ...
amulet/chunk.cpp ADDED
@@ -0,0 +1,16 @@
1
+ #include <string>
2
+ #include <unordered_map>
3
+ #include <optional>
4
+ #include <functional>
5
+ #include <memory>
6
+
7
+ #include <amulet/chunk.hpp>
8
+
9
+ namespace Amulet {
10
+ namespace detail {
11
+ std::unordered_map<std::string, std::function<std::shared_ptr<Chunk>()>> chunk_constructors;
12
+ }
13
+ std::shared_ptr<Chunk> get_null_chunk(std::string chunk_id) {
14
+ return detail::chunk_constructors.at(chunk_id)();
15
+ }
16
+ }
amulet/chunk.hpp ADDED
@@ -0,0 +1,99 @@
1
+ #pragma once
2
+
3
+ #include <string>
4
+ #include <unordered_map>
5
+ #include <optional>
6
+ #include <functional>
7
+ #include <memory>
8
+ #include <stdexcept>
9
+
10
+ // Requirements:
11
+ // Split chunk data into components that are orthogonal to each other.
12
+ // create a chunk with all components default initialised.
13
+ // reconstruct a chunk from a subset of its components.
14
+ // reconstruct a chunk with all components.
15
+ // query if a chunk has a component. (isinstance/is_base_of/dynamic_cast or has_component)
16
+ // get a component. (method/property or get_component)
17
+ // set and validate a component. (method/property or set_component)
18
+ // serialise loaded components.
19
+
20
+ namespace Amulet {
21
+ typedef std::unordered_map<std::string, std::optional<std::string>> SerialisedComponents;
22
+
23
+ // The abstract chunk class
24
+ class Chunk {
25
+ public:
26
+ virtual ~Chunk() {}
27
+ virtual std::string get_chunk_id() const = 0;
28
+ virtual std::vector<std::string> get_component_ids() const = 0;
29
+ //private:
30
+ // These are public but may become private one day
31
+ virtual SerialisedComponents serialise_chunk() const = 0;
32
+ virtual void reconstruct_chunk(SerialisedComponents) = 0;
33
+ };
34
+
35
+ namespace detail {
36
+ extern std::unordered_map<std::string, std::function<std::shared_ptr<Chunk>()>> chunk_constructors;
37
+ }
38
+
39
+ std::shared_ptr<Chunk> get_null_chunk(std::string chunk_id);
40
+
41
+ // An object that concrete chunk classes must be registered with.
42
+ // This enables reconstructing the chunk class.
43
+ template <typename ChunkT>
44
+ class ChunkNullConstructor {
45
+ public:
46
+ ChunkNullConstructor() {
47
+ if (detail::chunk_constructors.contains(ChunkT::ChunkID)) {
48
+ throw std::runtime_error("A chunk class has already been registered with ID " + ChunkT::ChunkID);
49
+ }
50
+ detail::chunk_constructors[ChunkT::ChunkID] = []() {
51
+ return std::make_shared<ChunkT>();
52
+ };
53
+ };
54
+ ~ChunkNullConstructor() {
55
+ detail::chunk_constructors.erase(ChunkT::ChunkID);
56
+ };
57
+ };
58
+
59
+ // A utility class to simplify component serialisation and deserialisation.
60
+ template <class ChunkBaseClass, class ... Components>
61
+ class ChunkComponentHelper: public ChunkBaseClass, public Components... {
62
+ public:
63
+ // Component list
64
+ std::vector<std::string> get_component_ids() const override {
65
+ std::vector<std::string> component_ids;
66
+ (
67
+ [&]{
68
+ component_ids.push_back(Components::ComponentID);
69
+ }(),
70
+ ...
71
+ );
72
+ return component_ids;
73
+ }
74
+ // These are public but may become private one day
75
+ // Null constructor
76
+ ChunkComponentHelper() : Components()... {}
77
+ //private:
78
+ // Serialiser
79
+ SerialisedComponents serialise_chunk() const override {
80
+ SerialisedComponents component_data;
81
+ (
82
+ [&]{
83
+ component_data[Components::ComponentID] = Components::serialise();
84
+ }(),
85
+ ...
86
+ );
87
+ return component_data;
88
+ }
89
+ // Deserialiser
90
+ void reconstruct_chunk(SerialisedComponents component_data) override {
91
+ (
92
+ [&]{
93
+ Components::deserialise(component_data.extract(Components::ComponentID).mapped());
94
+ }(),
95
+ ...
96
+ );
97
+ }
98
+ };
99
+ }
amulet/chunk.pyi ADDED
@@ -0,0 +1,30 @@
1
+ from __future__ import annotations
2
+
3
+ __all__ = ["Chunk", "get_null_chunk"]
4
+
5
+ class Chunk:
6
+ """
7
+ A base class for all chunk classes.
8
+ """
9
+
10
+ def __getstate__(self) -> tuple: ...
11
+ def __setstate__(self, arg0: tuple) -> None: ...
12
+ def reconstruct_chunk(self, arg0: dict[str, bytes | None]) -> None:
13
+ """
14
+ This is private. Do not use this. It will be removed in the future.
15
+ """
16
+
17
+ def serialise_chunk(self) -> dict[str, bytes | None]:
18
+ """
19
+ This is private. Do not use this. It will be removed in the future.
20
+ """
21
+
22
+ @property
23
+ def chunk_id(self) -> str: ...
24
+ @property
25
+ def component_ids(self) -> list[str]: ...
26
+
27
+ def get_null_chunk(arg0: str) -> Chunk:
28
+ """
29
+ This is a private function
30
+ """