amulet-core 2.0a9__1.MSVC.19.43.34808.0-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 (45) hide show
  1. amulet/core/__init__.py +36 -0
  2. amulet/core/__pyinstaller/__init__.py +2 -0
  3. amulet/core/__pyinstaller/hook-amulet.core.py +4 -0
  4. amulet/core/_amulet_core.cp311-win_amd64.pyd +0 -0
  5. amulet/core/_amulet_core.pyi +7 -0
  6. amulet/core/_version.py +21 -0
  7. amulet/core/amulet_core.dll +0 -0
  8. amulet/core/amulet_core.lib +0 -0
  9. amulet/core/amulet_coreConfig.cmake +18 -0
  10. amulet/core/biome/__init__.pyi +75 -0
  11. amulet/core/biome/biome.hpp +53 -0
  12. amulet/core/block/__init__.pyi +270 -0
  13. amulet/core/block/block.hpp +156 -0
  14. amulet/core/block_entity/__init__.pyi +78 -0
  15. amulet/core/block_entity/block_entity.hpp +84 -0
  16. amulet/core/chunk/__init__.pyi +67 -0
  17. amulet/core/chunk/chunk.hpp +126 -0
  18. amulet/core/chunk/component/__init__.pyi +18 -0
  19. amulet/core/chunk/component/biome_3d_component.hpp +96 -0
  20. amulet/core/chunk/component/block_component.hpp +101 -0
  21. amulet/core/chunk/component/block_component.pyi +28 -0
  22. amulet/core/chunk/component/block_entity_component.hpp +119 -0
  23. amulet/core/chunk/component/section_array_map.hpp +129 -0
  24. amulet/core/chunk/component/section_array_map.pyi +77 -0
  25. amulet/core/dll.hpp +21 -0
  26. amulet/core/entity/__init__.pyi +105 -0
  27. amulet/core/entity/entity.hpp +100 -0
  28. amulet/core/palette/__init__.pyi +8 -0
  29. amulet/core/palette/biome_palette.hpp +65 -0
  30. amulet/core/palette/biome_palette.pyi +45 -0
  31. amulet/core/palette/block_palette.hpp +71 -0
  32. amulet/core/palette/block_palette.pyi +47 -0
  33. amulet/core/py.typed +0 -0
  34. amulet/core/selection/__init__.pyi +8 -0
  35. amulet/core/selection/box.hpp +86 -0
  36. amulet/core/selection/box.pyi +215 -0
  37. amulet/core/selection/group.hpp +80 -0
  38. amulet/core/selection/group.pyi +213 -0
  39. amulet/core/version/__init__.pyi +134 -0
  40. amulet/core/version/version.hpp +204 -0
  41. amulet_core-2.0a9.dist-info/METADATA +109 -0
  42. amulet_core-2.0a9.dist-info/RECORD +45 -0
  43. amulet_core-2.0a9.dist-info/WHEEL +6 -0
  44. amulet_core-2.0a9.dist-info/entry_points.txt +2 -0
  45. amulet_core-2.0a9.dist-info/top_level.txt +1 -0
@@ -0,0 +1,119 @@
1
+ #pragma once
2
+
3
+ #include <cstdint>
4
+ #include <map>
5
+ #include <memory>
6
+ #include <optional>
7
+ #include <tuple>
8
+
9
+ #include <amulet/core/block_entity/block_entity.hpp>
10
+ #include <amulet/core/dll.hpp>
11
+ #include <amulet/core/version/version.hpp>
12
+
13
+ namespace Amulet {
14
+ typedef std::tuple<std::uint16_t, std::int64_t, std::uint16_t> BlockEntityChunkCoord;
15
+ class BlockEntityComponentData : public VersionRangeContainer {
16
+ private:
17
+ std::uint16_t _x_size;
18
+ std::uint16_t _z_size;
19
+ std::map<
20
+ BlockEntityChunkCoord,
21
+ std::shared_ptr<BlockEntity>>
22
+ _block_entities;
23
+
24
+ public:
25
+ template <typename VersionRangeT>
26
+ BlockEntityComponentData(
27
+ VersionRangeT&& version_range,
28
+ std::uint16_t x_size,
29
+ std::uint16_t z_size)
30
+ : VersionRangeContainer(std::forward<VersionRangeT>(version_range))
31
+ , _x_size(x_size)
32
+ , _z_size(z_size)
33
+ , _block_entities()
34
+ {
35
+ }
36
+
37
+ AMULET_CORE_EXPORT void serialise(BinaryWriter&) const;
38
+ AMULET_CORE_EXPORT static BlockEntityComponentData deserialise(BinaryReader&);
39
+
40
+ std::uint16_t get_x_size() const { return _x_size; }
41
+ std::uint16_t get_z_size() const { return _z_size; }
42
+
43
+ const std::map<BlockEntityChunkCoord, std::shared_ptr<BlockEntity>>&
44
+ get_block_entities() const
45
+ {
46
+ return _block_entities;
47
+ }
48
+
49
+ size_t get_size() const { return _block_entities.size(); }
50
+
51
+ bool contains(
52
+ const BlockEntityChunkCoord& coord) const
53
+ {
54
+ return _block_entities.contains(coord);
55
+ }
56
+
57
+ std::shared_ptr<BlockEntity> get(
58
+ const BlockEntityChunkCoord& coord) const
59
+ {
60
+ return _block_entities.at(coord);
61
+ }
62
+
63
+ template <typename BlockEntityT>
64
+ void set(
65
+ const BlockEntityChunkCoord& coord,
66
+ BlockEntityT&& block_entity)
67
+ {
68
+ std::shared_ptr<BlockEntity> block_entity_ptr;
69
+ if constexpr (std::is_same_v<std::shared_ptr<BlockEntity>, std::decay_t<BlockEntityT>>) {
70
+ block_entity_ptr = std::forward<BlockEntityT>(block_entity);
71
+ } else {
72
+ block_entity_ptr = std::make_shared<BlockEntity>(block_entity);
73
+ }
74
+
75
+ if (
76
+ std::get<0>(coord) < 0 || std::get<2>(coord) < 0 || _x_size <= std::get<0>(coord) || _z_size <= std::get<2>(coord)) {
77
+ throw std::invalid_argument(
78
+ "Coord must be 0 <= " + std::to_string(std::get<0>(coord)) + " < " + std::to_string(_x_size) + "and 0 <= " + std::to_string(std::get<1>(coord)) + " < " + std::to_string(_z_size));
79
+ }
80
+ if (!(
81
+ get_version_range().contains(
82
+ block_entity->get_platform(),
83
+ block_entity->get_version()))) {
84
+ throw std::invalid_argument(
85
+ "BlockEntity is incompatible with VersionRange.");
86
+ }
87
+ _block_entities.insert_or_assign(coord, std::move(block_entity));
88
+ }
89
+
90
+ void del(const BlockEntityChunkCoord& coord)
91
+ {
92
+ _block_entities.erase(coord);
93
+ }
94
+ };
95
+
96
+ class BlockEntityComponent {
97
+ private:
98
+ std::optional<std::shared_ptr<BlockEntityComponentData>> _value;
99
+
100
+ protected:
101
+ // Null constructor
102
+ BlockEntityComponent() = default;
103
+ // Default constructor
104
+ AMULET_CORE_EXPORT void init(
105
+ const VersionRange& version_range,
106
+ std::uint16_t x_size,
107
+ std::uint16_t z_size);
108
+
109
+ // Serialise the component data
110
+ AMULET_CORE_EXPORT std::optional<std::string> serialise() const;
111
+ // Deserialise the component
112
+ AMULET_CORE_EXPORT void deserialise(std::optional<std::string>);
113
+
114
+ public:
115
+ AMULET_CORE_EXPORT static const std::string ComponentID;
116
+ AMULET_CORE_EXPORT std::shared_ptr<BlockEntityComponentData> get_block_entity();
117
+ AMULET_CORE_EXPORT void set_block_entity(std::shared_ptr<BlockEntityComponentData> component);
118
+ };
119
+ }
@@ -0,0 +1,129 @@
1
+ #pragma once
2
+
3
+ #include <cstdint>
4
+ #include <cstdlib>
5
+ #include <memory>
6
+ #include <span>
7
+ #include <stdexcept>
8
+ #include <tuple>
9
+ #include <type_traits>
10
+ #include <unordered_map>
11
+ #include <variant>
12
+ #include <vector>
13
+
14
+ #include <amulet/io/binary_reader.hpp>
15
+ #include <amulet/io/binary_writer.hpp>
16
+
17
+ #include <amulet/core/dll.hpp>
18
+
19
+ namespace Amulet {
20
+
21
+ typedef std::tuple<std::uint16_t, std::uint16_t, std::uint16_t> SectionShape;
22
+
23
+ class IndexArray3D {
24
+ private:
25
+ SectionShape _shape;
26
+ size_t _size;
27
+ std::uint32_t* _buffer;
28
+
29
+ public:
30
+ AMULET_CORE_EXPORT IndexArray3D(const SectionShape& shape);
31
+ AMULET_CORE_EXPORT IndexArray3D(const SectionShape& shape, std::uint32_t value);
32
+
33
+ AMULET_CORE_EXPORT IndexArray3D(const IndexArray3D& other);
34
+ AMULET_CORE_EXPORT IndexArray3D(IndexArray3D&& other) noexcept;
35
+ AMULET_CORE_EXPORT IndexArray3D& operator=(const IndexArray3D& other);
36
+ AMULET_CORE_EXPORT IndexArray3D& operator=(IndexArray3D&& other) noexcept;
37
+
38
+ AMULET_CORE_EXPORT ~IndexArray3D();
39
+
40
+ AMULET_CORE_EXPORT void serialise(BinaryWriter&) const;
41
+ AMULET_CORE_EXPORT static IndexArray3D deserialise(BinaryReader&);
42
+
43
+ const SectionShape& get_shape() const { return _shape; }
44
+ const size_t& get_size() const { return _size; }
45
+ std::uint32_t* get_buffer() const { return _buffer; }
46
+ std::span<std::uint32_t> get_span() const { return { _buffer, _size }; }
47
+ };
48
+
49
+ class SectionArrayMap {
50
+ private:
51
+ SectionShape _array_shape;
52
+ std::variant<std::uint32_t, std::shared_ptr<IndexArray3D>> _default_array;
53
+ std::unordered_map<std::int64_t, std::shared_ptr<IndexArray3D>> _arrays;
54
+
55
+ void validate_array_shape(const IndexArray3D& array)
56
+ {
57
+ if (_array_shape != array.get_shape()) {
58
+ throw std::invalid_argument("Array shape does not match stored shape.");
59
+ }
60
+ }
61
+
62
+ void validate_array_shape(
63
+ const std::variant<std::uint32_t, std::shared_ptr<IndexArray3D>>& array)
64
+ {
65
+ if (auto* arr = std::get_if<std::shared_ptr<IndexArray3D>>(&array)) {
66
+ return validate_array_shape(**arr);
67
+ }
68
+ }
69
+
70
+ public:
71
+ template <typename DefaultArrayT>
72
+ SectionArrayMap(
73
+ const SectionShape& array_shape,
74
+ DefaultArrayT&& default_array)
75
+ : _array_shape(array_shape)
76
+ , _default_array(std::forward<DefaultArrayT>(default_array))
77
+ , _arrays()
78
+ {
79
+ validate_array_shape(_default_array);
80
+ }
81
+
82
+ AMULET_CORE_EXPORT void serialise(BinaryWriter&) const;
83
+ AMULET_CORE_EXPORT static SectionArrayMap deserialise(BinaryReader&);
84
+
85
+ const SectionShape& get_array_shape() const { return _array_shape; }
86
+
87
+ std::variant<std::uint32_t, std::shared_ptr<IndexArray3D>> get_default_array() const
88
+ {
89
+ return _default_array;
90
+ }
91
+
92
+ void set_default_array(std::variant<std::uint32_t, std::shared_ptr<IndexArray3D>> default_array)
93
+ {
94
+ validate_array_shape(default_array);
95
+ _default_array = std::move(default_array);
96
+ }
97
+
98
+ const std::unordered_map<std::int64_t, std::shared_ptr<IndexArray3D>>& get_arrays() const
99
+ {
100
+ return _arrays;
101
+ }
102
+
103
+ size_t get_size() const { return _arrays.size(); }
104
+
105
+ bool contains_section(std::int64_t cy) const
106
+ {
107
+ return _arrays.contains(cy);
108
+ }
109
+
110
+ std::shared_ptr<IndexArray3D> get_section(std::int64_t cy) const
111
+ {
112
+ return _arrays.at(cy);
113
+ }
114
+
115
+ void set_section(std::int64_t cy, std::shared_ptr<IndexArray3D> section)
116
+ {
117
+ validate_array_shape(*section);
118
+ _arrays.insert_or_assign(cy, std::move(section));
119
+ }
120
+
121
+ AMULET_CORE_EXPORT void populate_section(std::int64_t cy);
122
+
123
+ void del_section(std::int64_t cy)
124
+ {
125
+ _arrays.erase(cy);
126
+ }
127
+ };
128
+
129
+ } // namespace Amulet
@@ -0,0 +1,77 @@
1
+ from __future__ import annotations
2
+
3
+ import collections.abc
4
+ import types
5
+ import typing
6
+
7
+ import numpy
8
+ import numpy.typing
9
+ import typing_extensions
10
+
11
+ __all__ = ["IndexArray3D", "SectionArrayMap"]
12
+
13
+ class IndexArray3D:
14
+ """
15
+ A 3D index array.
16
+ """
17
+
18
+ @typing.overload
19
+ def __init__(self, shape: tuple[int, int, int]) -> None: ...
20
+ @typing.overload
21
+ def __init__(self, shape: tuple[int, int, int], value: int) -> None: ...
22
+ @typing.overload
23
+ def __init__(self, other: IndexArray3D) -> None: ...
24
+ @typing.overload
25
+ def __init__(self, arg0: typing_extensions.Buffer) -> None: ...
26
+ @property
27
+ def shape(self) -> tuple[int, int, int]: ...
28
+ @property
29
+ def size(self) -> int: ...
30
+
31
+ class SectionArrayMap:
32
+ """
33
+ A container of sub-chunk arrays.
34
+ """
35
+
36
+ def __contains__(self, arg0: int) -> bool: ...
37
+ def __delitem__(self, arg0: int) -> None: ...
38
+ def __eq__(self, arg0: typing.Any) -> bool | types.NotImplementedType: ...
39
+ def __getitem__(self, arg0: int) -> numpy.typing.NDArray[numpy.uint32]: ...
40
+ def __hash__(self) -> int: ...
41
+ def __init__(
42
+ self,
43
+ array_shape: tuple[int, int, int],
44
+ default_array: int | IndexArray3D | typing_extensions.Buffer,
45
+ ) -> None: ...
46
+ def __iter__(self) -> collections.abc.Iterator[int]: ...
47
+ def __len__(self) -> int: ...
48
+ def __setitem__(
49
+ self, arg0: int, arg1: IndexArray3D | typing_extensions.Buffer
50
+ ) -> None: ...
51
+ def get(
52
+ self, key: int, default: numpy.typing.NDArray[numpy.uint32] | None = None
53
+ ) -> numpy.typing.NDArray[numpy.uint32] | None: ...
54
+ def items(
55
+ self,
56
+ ) -> collections.abc.ItemsView[int, numpy.typing.NDArray[numpy.uint32]]: ...
57
+ def keys(self) -> collections.abc.KeysView[int]: ...
58
+ def pop(
59
+ self, key: int, default: numpy.typing.NDArray[numpy.uint32] = ...
60
+ ) -> numpy.typing.NDArray[numpy.uint32]: ...
61
+ def popitem(self) -> tuple[int, numpy.typing.NDArray[numpy.uint32]]: ...
62
+ def populate(self, arg0: int) -> None: ...
63
+ def setdefault(
64
+ self, arg0: int, arg1: numpy.typing.NDArray[numpy.uint32] | None
65
+ ) -> numpy.typing.NDArray[numpy.uint32] | None: ...
66
+ def update(self, other: typing.Any = (), **kwargs: typing.Any) -> None: ...
67
+ def values(
68
+ self,
69
+ ) -> collections.abc.ValuesView[numpy.typing.NDArray[numpy.uint32]]: ...
70
+ @property
71
+ def array_shape(self) -> tuple[int, int, int]: ...
72
+ @property
73
+ def default_array(self) -> int | numpy.ndarray: ...
74
+ @default_array.setter
75
+ def default_array(
76
+ self, arg1: int | IndexArray3D | typing_extensions.Buffer
77
+ ) -> None: ...
amulet/core/dll.hpp ADDED
@@ -0,0 +1,21 @@
1
+ #pragma once
2
+
3
+ #ifndef AMULET_CORE_EXPORT
4
+ #if defined(WIN32) || defined(_WIN32)
5
+ #ifdef ExportAmuletCore
6
+ #define AMULET_CORE_EXPORT __declspec(dllexport)
7
+ #else
8
+ #define AMULET_CORE_EXPORT __declspec(dllimport)
9
+ #endif
10
+ #else
11
+ #define AMULET_CORE_EXPORT
12
+ #endif
13
+ #endif
14
+
15
+ #if !defined(AMULET_CORE_EXPORT_EXCEPTION)
16
+ #if defined(_LIBCPP_EXCEPTION)
17
+ #define AMULET_CORE_EXPORT_EXCEPTION __attribute__((visibility("default")))
18
+ #else
19
+ #define AMULET_CORE_EXPORT_EXCEPTION
20
+ #endif
21
+ #endif
@@ -0,0 +1,105 @@
1
+ from __future__ import annotations
2
+
3
+ import types
4
+ import typing
5
+
6
+ import amulet.core.version
7
+ import amulet.nbt
8
+
9
+ __all__ = ["Entity"]
10
+
11
+ class Entity(amulet.core.version.PlatformVersionContainer):
12
+ """
13
+ A class to contain all the data to define an Entity.
14
+ """
15
+
16
+ @typing.overload
17
+ def __eq__(self, arg0: Entity) -> bool: ...
18
+ @typing.overload
19
+ def __eq__(self, arg0: typing.Any) -> bool | types.NotImplementedType: ...
20
+ def __hash__(self) -> int: ...
21
+ def __init__(
22
+ self,
23
+ platform: str,
24
+ version: amulet.core.version.VersionNumber,
25
+ namespace: str,
26
+ base_name: str,
27
+ x: float,
28
+ y: float,
29
+ z: float,
30
+ nbt: amulet.nbt.NamedTag,
31
+ ) -> None: ...
32
+ def __repr__(self) -> str: ...
33
+ @property
34
+ def base_name(self) -> str:
35
+ """
36
+ The base name of the entity represented by the :class:`Entity` object.
37
+
38
+ >>> entity: Entity
39
+ >>> entity.base_name
40
+
41
+ :return: The base name of the entity
42
+ """
43
+
44
+ @base_name.setter
45
+ def base_name(self, arg1: str) -> None: ...
46
+ @property
47
+ def namespace(self) -> str:
48
+ """
49
+ The namespace of the entity represented by the :class:`Entity` object.
50
+
51
+ >>> entity: Entity
52
+ >>> entity.namespace
53
+
54
+ :return: The namespace of the entity
55
+ """
56
+
57
+ @namespace.setter
58
+ def namespace(self, arg1: str) -> None: ...
59
+ @property
60
+ def namespaced_name(self) -> str:
61
+ """
62
+ The namespace:base_name of the entity represented by the :class:`Entity` object.
63
+
64
+ >>> entity: Entity
65
+ >>> entity.namespaced_name
66
+
67
+ :return: The namespace:base_name of the entity
68
+ """
69
+
70
+ @property
71
+ def nbt(self) -> amulet.nbt.NamedTag:
72
+ """
73
+ The nbt data for the entity.
74
+ >>> entity: Entity
75
+ >>> entity.nbt
76
+
77
+ :return: The NamedTag of the entity
78
+ """
79
+
80
+ @nbt.setter
81
+ def nbt(self, arg1: amulet.nbt.NamedTag) -> None: ...
82
+ @property
83
+ def x(self) -> float:
84
+ """
85
+ The x coordinate of the entity.
86
+ """
87
+
88
+ @x.setter
89
+ def x(self, arg1: float) -> None: ...
90
+ @property
91
+ def y(self) -> float:
92
+ """
93
+ The y coordinate of the entity.
94
+ """
95
+
96
+ @y.setter
97
+ def y(self, arg1: float) -> None: ...
98
+ @property
99
+ def z(self) -> float:
100
+ """
101
+ The z coordinate of the entity.
102
+ """
103
+
104
+ @z.setter
105
+ def z(self, arg1: float) -> None: ...
@@ -0,0 +1,100 @@
1
+ #pragma once
2
+
3
+ #include <map>
4
+ #include <string>
5
+ #include <variant>
6
+
7
+ #include <amulet/io/binary_reader.hpp>
8
+ #include <amulet/io/binary_writer.hpp>
9
+
10
+ #include <amulet/nbt/tag/eq.hpp>
11
+ #include <amulet/nbt/tag/named_tag.hpp>
12
+
13
+ #include <amulet/core/dll.hpp>
14
+ #include <amulet/core/version/version.hpp>
15
+
16
+ namespace Amulet {
17
+
18
+ class Entity : public PlatformVersionContainer {
19
+ private:
20
+ std::string _namespace;
21
+ std::string _base_name;
22
+ std::shared_ptr<Amulet::NBT::NamedTag> _nbt;
23
+ double _x;
24
+ double _y;
25
+ double _z;
26
+
27
+ public:
28
+ const std::string& get_namespace() const { return _namespace; }
29
+
30
+ template <typename NamespaceT>
31
+ void set_namespace(NamespaceT&& namespace_) { _namespace = std::forward<NamespaceT>(namespace_); }
32
+
33
+ const std::string& get_base_name() const { return _base_name; }
34
+
35
+ template <typename BaseNameT>
36
+ void set_base_name(BaseNameT&& base_name) { _base_name = std::forward<BaseNameT>(base_name); }
37
+
38
+ std::shared_ptr<Amulet::NBT::NamedTag> get_nbt() const { return _nbt; }
39
+
40
+ template <typename NBTT>
41
+ void set_nbt(NBTT&& nbt)
42
+ {
43
+ if constexpr (std::is_same_v<std::shared_ptr<Amulet::NBT::NamedTag>, std::decay_t<NBTT>>) {
44
+ _nbt = std::forward<NBTT>(nbt);
45
+ } else {
46
+ _nbt = std::make_shared<Amulet::NBT::NamedTag>(std::forward<NBTT>(nbt));
47
+ }
48
+ }
49
+
50
+ double get_x() const { return _x; }
51
+
52
+ double get_y() const { return _y; }
53
+
54
+ double get_z() const { return _z; }
55
+
56
+ void set_x(double x) { _x = x; }
57
+
58
+ void set_y(double y) { _y = y; }
59
+
60
+ void set_z(double z) { _z = z; }
61
+
62
+ template <
63
+ typename PlatformT,
64
+ typename VersionNumberT,
65
+ typename NamespaceT,
66
+ typename BaseNameT,
67
+ typename NBTT>
68
+ Entity(
69
+ PlatformT&& platform,
70
+ VersionNumberT&& version,
71
+ NamespaceT&& namespace_,
72
+ BaseNameT&& base_name,
73
+ double x,
74
+ double y,
75
+ double z,
76
+ NBTT&& nbt)
77
+ : PlatformVersionContainer(std::forward<PlatformT>(platform), std::forward<VersionNumberT>(version))
78
+ , _namespace(std::forward<NamespaceT>(namespace_))
79
+ , _base_name(std::forward<BaseNameT>(base_name))
80
+ , _nbt(
81
+ [&nbt]() {
82
+ if constexpr (std::is_same_v<std::shared_ptr<Amulet::NBT::NamedTag>, NBTT>) {
83
+ return std::forward<NBTT>(nbt);
84
+ } else {
85
+ return std::make_shared<Amulet::NBT::NamedTag>(std::forward<NBTT>(nbt));
86
+ }
87
+ }())
88
+ , _x(x)
89
+ , _y(y)
90
+ , _z(z)
91
+ {
92
+ }
93
+
94
+ AMULET_CORE_EXPORT void serialise(BinaryWriter&) const;
95
+ AMULET_CORE_EXPORT static Entity deserialise(BinaryReader&);
96
+
97
+ AMULET_CORE_EXPORT bool operator==(const Entity& other) const;
98
+ };
99
+
100
+ } // namespace Amulet
@@ -0,0 +1,8 @@
1
+ from __future__ import annotations
2
+
3
+ from amulet.core.palette.biome_palette import BiomePalette
4
+ from amulet.core.palette.block_palette import BlockPalette
5
+
6
+ from . import biome_palette, block_palette
7
+
8
+ __all__ = ["BiomePalette", "BlockPalette", "biome_palette", "block_palette"]
@@ -0,0 +1,65 @@
1
+ #pragma once
2
+
3
+ #include <map>
4
+ #include <stdexcept>
5
+
6
+ #include <amulet/core/biome/biome.hpp>
7
+ #include <amulet/core/version/version.hpp>
8
+
9
+ namespace Amulet {
10
+
11
+ class BiomePalette : public VersionRangeContainer {
12
+ private:
13
+ std::vector<Biome> _index_to_biome;
14
+ std::map<Biome, size_t> _biome_to_index;
15
+
16
+ public:
17
+ const std::vector<Biome>& get_biomes() const { return _index_to_biome; }
18
+
19
+ template <typename VersionRangeT>
20
+ BiomePalette(VersionRangeT&& version_range)
21
+ : VersionRangeContainer(std::forward<VersionRangeT>(version_range))
22
+ , _index_to_biome()
23
+ , _biome_to_index()
24
+ {
25
+ }
26
+
27
+ AMULET_CORE_EXPORT void serialise(BinaryWriter&) const;
28
+ AMULET_CORE_EXPORT static BiomePalette deserialise(BinaryReader&);
29
+
30
+ bool operator==(const BiomePalette& other) const
31
+ {
32
+ return _index_to_biome == other._index_to_biome;
33
+ }
34
+
35
+ size_t size() const { return _index_to_biome.size(); }
36
+
37
+ const Biome& index_to_biome(size_t index) const
38
+ {
39
+ return _index_to_biome.at(index);
40
+ }
41
+
42
+ size_t biome_to_index(const Biome& biome)
43
+ {
44
+ auto it = _biome_to_index.find(biome);
45
+ if (it != _biome_to_index.end()) {
46
+ return it->second;
47
+ }
48
+ const auto& version_range = get_version_range();
49
+ if (!version_range.contains(biome.get_platform(), biome.get_version())) {
50
+ throw std::invalid_argument(
51
+ "Biome(\"" + biome.get_platform() + "\", " + biome.get_version().toString() + ") is incompatible with VersionRange(\"" + version_range.get_platform() + "\", " + version_range.get_min_version().toString() + ", " + version_range.get_max_version().toString() + ").");
52
+ }
53
+ size_t index = _index_to_biome.size();
54
+ _index_to_biome.push_back(biome);
55
+ _biome_to_index[biome] = index;
56
+ return index;
57
+ }
58
+
59
+ bool contains_biome(const Biome& biome) const
60
+ {
61
+ return _biome_to_index.contains(biome);
62
+ }
63
+ };
64
+
65
+ }
@@ -0,0 +1,45 @@
1
+ from __future__ import annotations
2
+
3
+ import collections.abc
4
+ import typing
5
+
6
+ import amulet.core.biome
7
+ import amulet.core.version
8
+
9
+ __all__ = ["BiomePalette"]
10
+
11
+ class BiomePalette(amulet.core.version.VersionRangeContainer):
12
+ @typing.overload
13
+ def __contains__(self, arg0: int) -> bool: ...
14
+ @typing.overload
15
+ def __contains__(self, arg0: amulet.core.biome.Biome) -> bool: ...
16
+ @typing.overload
17
+ def __getitem__(self, arg0: int) -> amulet.core.biome.Biome: ...
18
+ @typing.overload
19
+ def __getitem__(self, arg0: slice) -> list: ...
20
+ def __init__(self, arg0: amulet.core.version.VersionRange) -> None: ...
21
+ def __iter__(self) -> collections.abc.Iterator[typing.Any]: ...
22
+ def __len__(self) -> int: ...
23
+ def __repr__(self) -> str: ...
24
+ def __reversed__(self) -> collections.abc.Iterator[typing.Any]: ...
25
+ def biome_to_index(self, arg0: amulet.core.biome.Biome) -> int:
26
+ """
27
+ Get the index of the biome in the palette.
28
+ If it is not in the palette already it will be added first.
29
+
30
+ :param biome: The biome to get the index of.
31
+ :return: The index of the biome in the palette.
32
+ """
33
+
34
+ def count(self, value: typing.Any) -> int: ...
35
+ def index(
36
+ self, value: typing.Any, start: int = 0, stop: int = 9223372036854775807
37
+ ) -> int: ...
38
+ def index_to_biome(self, arg0: int) -> amulet.core.biome.Biome:
39
+ """
40
+ Get the biome at the specified palette index.
41
+
42
+ :param index: The index to get
43
+ :return: The biome at that index
44
+ :raises IndexError if there is no biome at that index.
45
+ """