amulet-core 2.0a5__cp312-cp312-win_amd64.whl → 2.0a7__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.
- amulet/__init__.cp312-win_amd64.pyd +0 -0
- amulet/__init__.py.cpp +43 -0
- amulet/__init__.pyi +0 -2
- amulet/_init.py +0 -2
- amulet/_version.py +3 -3
- amulet/biome.py.cpp +122 -0
- amulet/biome.pyi +0 -2
- amulet/block.py.cpp +377 -0
- amulet/block.pyi +0 -2
- amulet/block_entity.py.cpp +115 -0
- amulet/block_entity.pyi +0 -2
- amulet/chunk.py.cpp +80 -0
- amulet/chunk.pyi +0 -2
- amulet/chunk_components/biome_3d_component.cpp +5 -0
- amulet/chunk_components/biome_3d_component.hpp +79 -0
- amulet/chunk_components/block_component.cpp +41 -0
- amulet/chunk_components/block_component.hpp +88 -0
- amulet/chunk_components/block_entity_component.cpp +5 -0
- amulet/chunk_components/block_entity_component.hpp +147 -0
- amulet/chunk_components/section_array_map.cpp +129 -0
- amulet/chunk_components/section_array_map.hpp +147 -0
- amulet/chunk_components.pyi +20 -18
- amulet/collections/eq.py.hpp +37 -0
- amulet/collections/hash.py.hpp +27 -0
- amulet/collections/holder.py.hpp +37 -0
- amulet/collections/iterator.py.hpp +80 -0
- amulet/collections/mapping.py.hpp +199 -0
- amulet/collections/mutable_mapping.py.hpp +226 -0
- amulet/collections/sequence.py.hpp +163 -0
- amulet/collections.pyi +8 -5
- amulet/entity.py +22 -20
- amulet/game/translate/_functions/_code_functions/_text.py +2 -2
- amulet/game/translate/_functions/abc.py +10 -3
- amulet/img/__init__.py +10 -0
- amulet/img/missing_no.png +0 -0
- amulet/img/missing_pack.png +0 -0
- amulet/img/missing_world.png +0 -0
- amulet/io/binary_reader.hpp +45 -0
- amulet/io/binary_writer.hpp +30 -0
- amulet/level/__init__.pyi +2 -6
- amulet/level/abc/_level/_creatable_level.py +1 -2
- amulet/level/abc/_level/_level.py +1 -5
- amulet/level/java/__init__.pyi +0 -5
- amulet/level/java/_raw/__init__.pyi +0 -4
- amulet/level/java/_raw/java_chunk_decode.cpp +531 -0
- amulet/level/java/_raw/java_chunk_decode.hpp +23 -0
- amulet/level/java/_raw/java_chunk_encode.cpp +25 -0
- amulet/level/java/_raw/java_chunk_encode.hpp +23 -0
- amulet/level/java/chunk_components/data_version_component.cpp +32 -0
- amulet/level/java/chunk_components/data_version_component.hpp +31 -0
- amulet/level/java/chunk_components/java_raw_chunk_component.cpp +56 -0
- amulet/level/java/chunk_components/java_raw_chunk_component.hpp +45 -0
- amulet/level/java/java_chunk.cpp +170 -0
- amulet/level/java/java_chunk.hpp +141 -0
- amulet/level/java/long_array.hpp +175 -0
- amulet/level/java/long_array.pyi +2 -1
- amulet/mesh/block/__init__.py +1 -0
- amulet/mesh/block/block_mesh.py +369 -0
- amulet/mesh/block/cube.py +149 -0
- amulet/mesh/block/missing_block.py +20 -0
- amulet/mesh/util.py +17 -0
- amulet/palette/biome_palette.hpp +85 -0
- amulet/palette/block_palette.cpp +32 -0
- amulet/palette/block_palette.hpp +93 -0
- amulet/player.py +4 -6
- amulet/pybind11/collections.hpp +118 -0
- amulet/pybind11/numpy.hpp +26 -0
- amulet/pybind11/py_module.hpp +34 -0
- amulet/pybind11/type_hints.hpp +51 -0
- amulet/pybind11/types.hpp +25 -0
- amulet/pybind11/typing.hpp +7 -0
- amulet/resource_pack/__init__.py +62 -0
- amulet/resource_pack/abc/__init__.py +2 -0
- amulet/resource_pack/abc/resource_pack.py +38 -0
- amulet/resource_pack/abc/resource_pack_manager.py +87 -0
- amulet/resource_pack/bedrock/__init__.py +2 -0
- amulet/resource_pack/bedrock/bedrock_vanilla_fix/pack_icon.png +0 -0
- amulet/resource_pack/bedrock/bedrock_vanilla_fix/textures/blocks/grass_carried.png +0 -0
- amulet/resource_pack/bedrock/bedrock_vanilla_fix/textures/blocks/grass_side_carried.png +0 -0
- amulet/resource_pack/bedrock/bedrock_vanilla_fix/textures/blocks/water.png +0 -0
- amulet/resource_pack/bedrock/blockshapes/__init__.py +31 -0
- amulet/resource_pack/bedrock/blockshapes/air.py +35 -0
- amulet/resource_pack/bedrock/blockshapes/base_blockshape.py +29 -0
- amulet/resource_pack/bedrock/blockshapes/bubble_column.py +29 -0
- amulet/resource_pack/bedrock/blockshapes/cake.py +46 -0
- amulet/resource_pack/bedrock/blockshapes/chest.py +54 -0
- amulet/resource_pack/bedrock/blockshapes/comparator.py +51 -0
- amulet/resource_pack/bedrock/blockshapes/cross_texture.py +186 -0
- amulet/resource_pack/bedrock/blockshapes/cross_texture0.py +17 -0
- amulet/resource_pack/bedrock/blockshapes/cross_texture_green.py +16 -0
- amulet/resource_pack/bedrock/blockshapes/cube.py +38 -0
- amulet/resource_pack/bedrock/blockshapes/default.py +14 -0
- amulet/resource_pack/bedrock/blockshapes/door.py +38 -0
- amulet/resource_pack/bedrock/blockshapes/door1.py +14 -0
- amulet/resource_pack/bedrock/blockshapes/door2.py +14 -0
- amulet/resource_pack/bedrock/blockshapes/door3.py +14 -0
- amulet/resource_pack/bedrock/blockshapes/door4.py +14 -0
- amulet/resource_pack/bedrock/blockshapes/door5.py +14 -0
- amulet/resource_pack/bedrock/blockshapes/door6.py +14 -0
- amulet/resource_pack/bedrock/blockshapes/double_plant.py +40 -0
- amulet/resource_pack/bedrock/blockshapes/enchanting_table.py +22 -0
- amulet/resource_pack/bedrock/blockshapes/farmland.py +22 -0
- amulet/resource_pack/bedrock/blockshapes/fence.py +22 -0
- amulet/resource_pack/bedrock/blockshapes/flat.py +55 -0
- amulet/resource_pack/bedrock/blockshapes/flat_wall.py +55 -0
- amulet/resource_pack/bedrock/blockshapes/furnace.py +44 -0
- amulet/resource_pack/bedrock/blockshapes/furnace_lit.py +14 -0
- amulet/resource_pack/bedrock/blockshapes/green_cube.py +39 -0
- amulet/resource_pack/bedrock/blockshapes/ladder.py +36 -0
- amulet/resource_pack/bedrock/blockshapes/lilypad.py +14 -0
- amulet/resource_pack/bedrock/blockshapes/partial_block.py +57 -0
- amulet/resource_pack/bedrock/blockshapes/piston.py +44 -0
- amulet/resource_pack/bedrock/blockshapes/piston_arm.py +72 -0
- amulet/resource_pack/bedrock/blockshapes/portal_frame.py +22 -0
- amulet/resource_pack/bedrock/blockshapes/pressure_plate.py +29 -0
- amulet/resource_pack/bedrock/blockshapes/pumpkin.py +36 -0
- amulet/resource_pack/bedrock/blockshapes/pumpkin_carved.py +14 -0
- amulet/resource_pack/bedrock/blockshapes/pumpkin_lit.py +14 -0
- amulet/resource_pack/bedrock/blockshapes/red_dust.py +14 -0
- amulet/resource_pack/bedrock/blockshapes/repeater.py +53 -0
- amulet/resource_pack/bedrock/blockshapes/slab.py +33 -0
- amulet/resource_pack/bedrock/blockshapes/slab_double.py +15 -0
- amulet/resource_pack/bedrock/blockshapes/tree.py +41 -0
- amulet/resource_pack/bedrock/blockshapes/turtle_egg.py +15 -0
- amulet/resource_pack/bedrock/blockshapes/vine.py +52 -0
- amulet/resource_pack/bedrock/blockshapes/wall.py +22 -0
- amulet/resource_pack/bedrock/blockshapes/water.py +38 -0
- amulet/resource_pack/bedrock/download_resources.py +147 -0
- amulet/resource_pack/bedrock/resource_pack.py +40 -0
- amulet/resource_pack/bedrock/resource_pack_manager.py +361 -0
- amulet/resource_pack/bedrock/sort_blockshapes.py +15 -0
- amulet/resource_pack/java/__init__.py +2 -0
- amulet/resource_pack/java/download_resources.py +212 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_black.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_blue.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_brown.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_cyan.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_gray.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_green.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_light_blue.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_light_gray.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_lime.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_magenta.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_orange.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_pink.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_purple.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_red.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_white.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_yellow.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/barrier.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/end_portal.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/grass.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/lava.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/structure_void.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/water.png +0 -0
- amulet/resource_pack/java/java_vanilla_fix/pack.png +0 -0
- amulet/resource_pack/java/resource_pack.py +44 -0
- amulet/resource_pack/java/resource_pack_manager.py +551 -0
- amulet/resource_pack/unknown_resource_pack.py +10 -0
- amulet/utils/__init__.pyi +0 -5
- amulet/utils/call_spec/_call_spec.py +2 -7
- amulet/utils/comment_json.py +188 -0
- amulet/utils/matrix.py +3 -3
- amulet/utils/numpy.hpp +36 -0
- amulet/utils/numpy_helpers.py +2 -2
- amulet/utils/world_utils.py +2 -2
- amulet/version.py.cpp +281 -0
- amulet/version.pyi +0 -8
- {amulet_core-2.0a5.dist-info → amulet_core-2.0a7.dist-info}/METADATA +3 -3
- amulet_core-2.0a7.dist-info/RECORD +295 -0
- amulet/chunk_/components/biome.py +0 -155
- amulet/chunk_/components/block_entity.py +0 -117
- amulet/chunk_/components/entity.py +0 -64
- amulet/chunk_/components/height_2d.py +0 -16
- amulet/level/bedrock/__init__.py +0 -2
- amulet/level/bedrock/_chunk_handle.py +0 -19
- amulet/level/bedrock/_dimension.py +0 -22
- amulet/level/bedrock/_level.py +0 -187
- amulet/level/bedrock/_raw/__init__.py +0 -5
- amulet/level/bedrock/_raw/_actor_counter.py +0 -53
- amulet/level/bedrock/_raw/_chunk.py +0 -54
- amulet/level/bedrock/_raw/_chunk_decode.py +0 -668
- amulet/level/bedrock/_raw/_chunk_encode.py +0 -602
- amulet/level/bedrock/_raw/_constant.py +0 -9
- amulet/level/bedrock/_raw/_dimension.py +0 -343
- amulet/level/bedrock/_raw/_level.py +0 -463
- amulet/level/bedrock/_raw/_level_dat.py +0 -90
- amulet/level/bedrock/_raw/_typing.py +0 -6
- amulet/level/bedrock/_raw/leveldb_chunk_versions.py +0 -83
- amulet/level/bedrock/chunk/__init__.py +0 -1
- amulet/level/bedrock/chunk/_chunk.py +0 -126
- amulet/level/bedrock/chunk/components/chunk_version.py +0 -12
- amulet/level/bedrock/chunk/components/finalised_state.py +0 -13
- amulet/level/bedrock/chunk/components/raw_chunk.py +0 -15
- amulet/level/construction/__init__.py +0 -0
- amulet/level/java/_chunk_handle.pyi +0 -15
- amulet/level/java/_dimension.pyi +0 -13
- amulet/level/java/_level.pyi +0 -120
- amulet/level/java/_raw/_chunk_decode.py +0 -561
- amulet/level/java/_raw/_chunk_encode.py +0 -463
- amulet/level/java/_raw/_constant.pyi +0 -20
- amulet/level/java/_raw/_data_pack/__init__.pyi +0 -8
- amulet/level/java/_raw/_data_pack/data_pack.pyi +0 -197
- amulet/level/java/_raw/_data_pack/data_pack_manager.pyi +0 -75
- amulet/level/java/_raw/_dimension.pyi +0 -72
- amulet/level/java/_raw/_level.pyi +0 -238
- amulet/level/java/_raw/_typing.pyi +0 -5
- amulet/level/java/anvil/__init__.pyi +0 -11
- amulet/level/java/anvil/_dimension.pyi +0 -109
- amulet/level/java/anvil/_region.pyi +0 -197
- amulet/level/java/anvil/_sector_manager.pyi +0 -142
- amulet/level/java_forge/__init__.py +0 -0
- amulet/level/mcstructure/__init__.py +0 -0
- amulet/level/nbt/__init__.py +0 -0
- amulet/level/schematic/__init__.py +0 -0
- amulet/level/sponge_schematic/__init__.py +0 -0
- amulet/utils/call_spec/__init__.pyi +0 -53
- amulet/utils/call_spec/_call_spec.pyi +0 -272
- amulet/utils/matrix.pyi +0 -177
- amulet/utils/shareable_lock.pyi +0 -190
- amulet/utils/signal/__init__.pyi +0 -25
- amulet/utils/signal/_signal.pyi +0 -84
- amulet/utils/task_manager.pyi +0 -168
- amulet/utils/typing.py +0 -4
- amulet/utils/typing.pyi +0 -6
- amulet/utils/weakref.pyi +0 -50
- amulet/utils/world_utils.pyi +0 -109
- amulet_core-2.0a5.dist-info/RECORD +0 -210
- /amulet/{level/bedrock/chunk/components → mesh}/__init__.py +0 -0
- {amulet_core-2.0a5.dist-info → amulet_core-2.0a7.dist-info}/WHEEL +0 -0
- {amulet_core-2.0a5.dist-info → amulet_core-2.0a7.dist-info}/entry_points.txt +0 -0
- {amulet_core-2.0a5.dist-info → amulet_core-2.0a7.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
#include <string>
|
|
2
|
+
|
|
3
|
+
#include <amulet/io/binary_writer.hpp>
|
|
4
|
+
#include <amulet/io/binary_reader.hpp>
|
|
5
|
+
|
|
6
|
+
#include "section_array_map.hpp"
|
|
7
|
+
|
|
8
|
+
namespace Amulet {
|
|
9
|
+
void IndexArray3D::serialise(BinaryWriter& writer) const {
|
|
10
|
+
writer.writeNumeric<std::uint8_t>(1);
|
|
11
|
+
|
|
12
|
+
// Write array shape
|
|
13
|
+
const auto& array_shape = get_shape();
|
|
14
|
+
writer.writeNumeric<std::uint16_t>(std::get<0>(array_shape));
|
|
15
|
+
writer.writeNumeric<std::uint16_t>(std::get<1>(array_shape));
|
|
16
|
+
writer.writeNumeric<std::uint16_t>(std::get<2>(array_shape));
|
|
17
|
+
|
|
18
|
+
// Write array
|
|
19
|
+
const auto& size = get_size();
|
|
20
|
+
const auto* buffer = get_buffer();
|
|
21
|
+
for (auto i = 0; i < size; i++) {
|
|
22
|
+
writer.writeNumeric<std::uint32_t>(buffer[i]);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
std::shared_ptr<IndexArray3D> IndexArray3D::deserialise(BinaryReader& reader) {
|
|
26
|
+
auto version = reader.readNumeric<std::uint8_t>();
|
|
27
|
+
switch (version) {
|
|
28
|
+
case 1:
|
|
29
|
+
{
|
|
30
|
+
// Read array shape
|
|
31
|
+
auto array_shape = std::make_tuple(
|
|
32
|
+
reader.readNumeric<std::uint16_t>(),
|
|
33
|
+
reader.readNumeric<std::uint16_t>(),
|
|
34
|
+
reader.readNumeric<std::uint16_t>()
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
// Construct instance
|
|
38
|
+
auto self = std::make_shared<IndexArray3D>(array_shape);
|
|
39
|
+
|
|
40
|
+
// Read array
|
|
41
|
+
const auto& size = self->get_size();
|
|
42
|
+
auto* buffer = self->get_buffer();
|
|
43
|
+
for (auto i = 0; i < size; i++) {
|
|
44
|
+
buffer[i] = reader.readNumeric<std::uint32_t>();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return self;
|
|
48
|
+
}
|
|
49
|
+
default:
|
|
50
|
+
throw std::invalid_argument("Unsupported IndexArray3D version " + std::to_string(version));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
void SectionArrayMap::serialise(BinaryWriter& writer) const {
|
|
55
|
+
writer.writeNumeric<std::uint8_t>(1);
|
|
56
|
+
|
|
57
|
+
// Write array shape
|
|
58
|
+
const auto& array_shape = get_array_shape();
|
|
59
|
+
writer.writeNumeric<std::uint16_t>(std::get<0>(array_shape));
|
|
60
|
+
writer.writeNumeric<std::uint16_t>(std::get<1>(array_shape));
|
|
61
|
+
writer.writeNumeric<std::uint16_t>(std::get<2>(array_shape));
|
|
62
|
+
|
|
63
|
+
// Write default array
|
|
64
|
+
std::visit(
|
|
65
|
+
[&writer](auto&& arg) {
|
|
66
|
+
using T = std::decay_t<decltype(arg)>;
|
|
67
|
+
if constexpr (std::is_same_v<T, std::uint32_t>) {
|
|
68
|
+
writer.writeNumeric<std::uint8_t>(0);
|
|
69
|
+
writer.writeNumeric<std::uint32_t>(arg);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
writer.writeNumeric<std::uint8_t>(1);
|
|
73
|
+
arg->serialise(writer);
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
get_default_array()
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
// Write arrays
|
|
80
|
+
const auto& arrays = get_arrays();
|
|
81
|
+
writer.writeNumeric<std::uint64_t>(arrays.size());
|
|
82
|
+
for (const auto& [cy, arr] : arrays) {
|
|
83
|
+
writer.writeNumeric<std::int64_t>(cy);
|
|
84
|
+
arr->serialise(writer);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
std::shared_ptr<SectionArrayMap> SectionArrayMap::deserialise(BinaryReader& reader) {
|
|
88
|
+
auto version = reader.readNumeric<std::uint8_t>();
|
|
89
|
+
switch (version) {
|
|
90
|
+
case 1:
|
|
91
|
+
{
|
|
92
|
+
// Read array shape
|
|
93
|
+
auto array_shape = std::make_tuple(
|
|
94
|
+
reader.readNumeric<std::uint16_t>(),
|
|
95
|
+
reader.readNumeric<std::uint16_t>(),
|
|
96
|
+
reader.readNumeric<std::uint16_t>()
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
// Read default array
|
|
100
|
+
auto default_array_state = reader.readNumeric<std::uint8_t>();
|
|
101
|
+
std::variant<std::uint32_t, std::shared_ptr<IndexArray3D>> default_array;
|
|
102
|
+
switch (default_array_state) {
|
|
103
|
+
case 0:
|
|
104
|
+
default_array = reader.readNumeric<std::uint32_t>();
|
|
105
|
+
break;
|
|
106
|
+
case 1:
|
|
107
|
+
default_array = IndexArray3D::deserialise(reader);
|
|
108
|
+
break;
|
|
109
|
+
default:
|
|
110
|
+
throw std::invalid_argument("Invalid default array state value " + std::to_string(default_array_state));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Construct instance
|
|
114
|
+
auto self = std::make_shared<SectionArrayMap>(array_shape, default_array);
|
|
115
|
+
|
|
116
|
+
// Populate arrays
|
|
117
|
+
auto array_count = reader.readNumeric<std::uint64_t>();
|
|
118
|
+
for (auto i = 0; i < array_count; i++) {
|
|
119
|
+
auto cy = reader.readNumeric<std::int64_t>();
|
|
120
|
+
self->set_section(cy, IndexArray3D::deserialise(reader));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return self;
|
|
124
|
+
}
|
|
125
|
+
default:
|
|
126
|
+
throw std::invalid_argument("Unsupported BlockComponentData version " + std::to_string(version));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <tuple>
|
|
4
|
+
#include <unordered_map>
|
|
5
|
+
#include <variant>
|
|
6
|
+
#include <cstdint>
|
|
7
|
+
#include <vector>
|
|
8
|
+
#include <span>
|
|
9
|
+
#include <cstdlib>
|
|
10
|
+
#include <type_traits>
|
|
11
|
+
#include <memory>
|
|
12
|
+
#include <stdexcept>
|
|
13
|
+
|
|
14
|
+
#include <amulet/io/binary_writer.hpp>
|
|
15
|
+
#include <amulet/io/binary_reader.hpp>
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
namespace Amulet {
|
|
19
|
+
namespace detail {
|
|
20
|
+
template <typename T>
|
|
21
|
+
inline std::unique_ptr<T*> new_buffer(size_t count) {
|
|
22
|
+
T* buffer = (T*) std::malloc(sizeof(T) * count);
|
|
23
|
+
if (buffer == nullptr) {
|
|
24
|
+
throw std::runtime_error("Could not allocate buffer");
|
|
25
|
+
}
|
|
26
|
+
return std::make_unique<T*>(buffer);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
typedef std::tuple<std::uint16_t, std::uint16_t, std::uint16_t> SectionShape;
|
|
31
|
+
|
|
32
|
+
class IndexArray3D {
|
|
33
|
+
private:
|
|
34
|
+
SectionShape _shape;
|
|
35
|
+
size_t _size;
|
|
36
|
+
std::unique_ptr<std::uint32_t*> _buffer;
|
|
37
|
+
public:
|
|
38
|
+
IndexArray3D(const SectionShape& shape) :
|
|
39
|
+
_shape(shape),
|
|
40
|
+
_size(std::get<0>(shape)* std::get<1>(shape)* std::get<2>(shape)),
|
|
41
|
+
_buffer(detail::new_buffer<std::uint32_t>(_size))
|
|
42
|
+
{}
|
|
43
|
+
IndexArray3D(const SectionShape& shape, std::uint32_t value) :
|
|
44
|
+
IndexArray3D(shape) {
|
|
45
|
+
std::fill_n(*_buffer, _size, value);
|
|
46
|
+
}
|
|
47
|
+
IndexArray3D(const IndexArray3D& other):
|
|
48
|
+
IndexArray3D(other.get_shape())
|
|
49
|
+
{
|
|
50
|
+
std::memcpy(*_buffer, *other._buffer, sizeof(std::uint32_t) * other.get_size());
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
void serialise(BinaryWriter&) const;
|
|
54
|
+
static std::shared_ptr<IndexArray3D> deserialise(BinaryReader&);
|
|
55
|
+
|
|
56
|
+
const SectionShape& get_shape() const {
|
|
57
|
+
return _shape;
|
|
58
|
+
}
|
|
59
|
+
const size_t& get_size() const { return _size; }
|
|
60
|
+
std::uint32_t* get_buffer() const { return *_buffer; }
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
namespace detail {
|
|
64
|
+
inline void validate_array_shape(
|
|
65
|
+
const std::shared_ptr<IndexArray3D>& default_array,
|
|
66
|
+
const SectionShape& array_shape
|
|
67
|
+
) {
|
|
68
|
+
if (default_array->get_shape() != array_shape) {
|
|
69
|
+
throw std::invalid_argument("Array shape does not match required shape.");
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
inline void validate_array_shape(
|
|
74
|
+
const std::variant<std::uint32_t, std::shared_ptr<IndexArray3D>>& default_array,
|
|
75
|
+
const SectionShape& array_shape
|
|
76
|
+
) {
|
|
77
|
+
if (std::holds_alternative<std::shared_ptr<IndexArray3D>>(default_array)) {
|
|
78
|
+
validate_array_shape(std::get<std::shared_ptr<IndexArray3D>>(default_array), array_shape);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
class SectionArrayMap {
|
|
84
|
+
private:
|
|
85
|
+
SectionShape _array_shape;
|
|
86
|
+
std::variant<std::uint32_t, std::shared_ptr<IndexArray3D>> _default_array;
|
|
87
|
+
std::unordered_map<std::int64_t, std::shared_ptr<IndexArray3D>> _arrays;
|
|
88
|
+
public:
|
|
89
|
+
SectionArrayMap(
|
|
90
|
+
const SectionShape& array_shape,
|
|
91
|
+
std::variant<std::uint32_t, std::shared_ptr<IndexArray3D>> default_array
|
|
92
|
+
) : _array_shape(array_shape), _default_array(default_array), _arrays() {
|
|
93
|
+
detail::validate_array_shape(_default_array, _array_shape);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
void serialise(BinaryWriter&) const;
|
|
97
|
+
static std::shared_ptr<SectionArrayMap> deserialise(BinaryReader&);
|
|
98
|
+
|
|
99
|
+
const SectionShape& get_array_shape() const { return _array_shape; }
|
|
100
|
+
|
|
101
|
+
std::variant<std::uint32_t, std::shared_ptr<IndexArray3D>> get_default_array() const { return _default_array; }
|
|
102
|
+
|
|
103
|
+
void set_default_array(std::variant<std::uint32_t, std::shared_ptr<IndexArray3D>> default_array) {
|
|
104
|
+
detail::validate_array_shape(default_array, _array_shape);
|
|
105
|
+
_default_array = default_array;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const std::unordered_map<std::int64_t, std::shared_ptr<IndexArray3D>>& get_arrays() const {
|
|
109
|
+
return _arrays;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
size_t get_size() const { return _arrays.size(); }
|
|
113
|
+
|
|
114
|
+
bool contains_section(std::int64_t cy) const {
|
|
115
|
+
return _arrays.contains(cy);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
std::shared_ptr<IndexArray3D> get_section(std::int64_t cy) const {
|
|
119
|
+
return _arrays.at(cy);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
void set_section(std::int64_t cy, std::shared_ptr<IndexArray3D> section) {
|
|
123
|
+
detail::validate_array_shape(section, _array_shape);
|
|
124
|
+
_arrays[cy] = section;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
void populate_section(std::int64_t cy) {
|
|
128
|
+
if (_arrays.contains(cy)) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
std::visit([this, &cy](auto&& arg) {
|
|
132
|
+
using T = std::decay_t<decltype(arg)>;
|
|
133
|
+
if constexpr (std::is_same_v<T, std::uint32_t>) {
|
|
134
|
+
_arrays[cy] = std::make_shared<IndexArray3D>(_array_shape, arg);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
_arrays[cy] = std::make_shared<IndexArray3D>(*arg);
|
|
138
|
+
}
|
|
139
|
+
}, _default_array);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
void del_section(std::int64_t cy) {
|
|
143
|
+
_arrays.erase(cy);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
}
|
amulet/chunk_components.pyi
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
import collections.abc
|
|
3
4
|
import types
|
|
4
5
|
import typing
|
|
5
6
|
|
|
@@ -8,6 +9,7 @@ import amulet.collections
|
|
|
8
9
|
import amulet.palette.block_palette
|
|
9
10
|
import amulet.version
|
|
10
11
|
import numpy
|
|
12
|
+
import numpy.typing
|
|
11
13
|
import typing_extensions
|
|
12
14
|
|
|
13
15
|
__all__ = ["BlockComponent", "BlockComponentData", "IndexArray3D", "SectionArrayMap"]
|
|
@@ -33,11 +35,6 @@ class IndexArray3D:
|
|
|
33
35
|
A 3D index array.
|
|
34
36
|
"""
|
|
35
37
|
|
|
36
|
-
def __buffer__(self, flags):
|
|
37
|
-
"""
|
|
38
|
-
Return a buffer object that exposes the underlying memory of the object.
|
|
39
|
-
"""
|
|
40
|
-
|
|
41
38
|
@typing.overload
|
|
42
39
|
def __init__(self, shape: tuple[int, int, int]) -> None: ...
|
|
43
40
|
@typing.overload
|
|
@@ -46,11 +43,6 @@ class IndexArray3D:
|
|
|
46
43
|
def __init__(self, other: IndexArray3D) -> None: ...
|
|
47
44
|
@typing.overload
|
|
48
45
|
def __init__(self, arg0: typing_extensions.Buffer) -> None: ...
|
|
49
|
-
def __release_buffer__(self, buffer):
|
|
50
|
-
"""
|
|
51
|
-
Release the buffer object that exposes the underlying memory of the object.
|
|
52
|
-
"""
|
|
53
|
-
|
|
54
46
|
@property
|
|
55
47
|
def shape(self) -> tuple[int, int, int]: ...
|
|
56
48
|
@property
|
|
@@ -64,7 +56,7 @@ class SectionArrayMap:
|
|
|
64
56
|
def __contains__(self, arg0: int) -> bool: ...
|
|
65
57
|
def __delitem__(self, arg0: int) -> None: ...
|
|
66
58
|
def __eq__(self, arg0: typing.Any) -> bool | types.NotImplementedType: ...
|
|
67
|
-
def __getitem__(self, arg0: int) -> typing.
|
|
59
|
+
def __getitem__(self, arg0: int) -> numpy.typing.NDArray[numpy.uint32]: ...
|
|
68
60
|
def __hash__(self) -> int: ...
|
|
69
61
|
def __init__(
|
|
70
62
|
self,
|
|
@@ -76,15 +68,25 @@ class SectionArrayMap:
|
|
|
76
68
|
def __setitem__(
|
|
77
69
|
self, arg0: int, arg1: IndexArray3D | typing_extensions.Buffer
|
|
78
70
|
) -> None: ...
|
|
79
|
-
def get(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
def
|
|
83
|
-
|
|
71
|
+
def get(
|
|
72
|
+
self, arg0: int, arg1: numpy.typing.NDArray[numpy.uint32] | None
|
|
73
|
+
) -> numpy.typing.NDArray[numpy.uint32] | None: ...
|
|
74
|
+
def items(
|
|
75
|
+
self,
|
|
76
|
+
) -> collections.abc.ItemsView[int, numpy.typing.NDArray[numpy.uint32]]: ...
|
|
77
|
+
def keys(self) -> collections.abc.KeysView[int]: ...
|
|
78
|
+
def pop(
|
|
79
|
+
self, key: int, default: numpy.typing.NDArray[numpy.uint32] = ...
|
|
80
|
+
) -> numpy.typing.NDArray[numpy.uint32]: ...
|
|
81
|
+
def popitem(self) -> tuple[int, numpy.typing.NDArray[numpy.uint32]]: ...
|
|
84
82
|
def populate(self, arg0: int) -> None: ...
|
|
85
|
-
def setdefault(
|
|
83
|
+
def setdefault(
|
|
84
|
+
self, arg0: int, arg1: numpy.typing.NDArray[numpy.uint32] | None
|
|
85
|
+
) -> numpy.typing.NDArray[numpy.uint32] | None: ...
|
|
86
86
|
def update(self, other: typing.Any = (), **kwargs) -> None: ...
|
|
87
|
-
def values(
|
|
87
|
+
def values(
|
|
88
|
+
self,
|
|
89
|
+
) -> collections.abc.ValuesView[numpy.typing.NDArray[numpy.uint32]]: ...
|
|
88
90
|
@property
|
|
89
91
|
def array_shape(self) -> tuple[int, int, int]: ...
|
|
90
92
|
@property
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
// Better type hinting for equality methods that pybind11 has natively
|
|
3
|
+
|
|
4
|
+
#include <variant>
|
|
5
|
+
#include <amulet/pybind11/types.hpp>
|
|
6
|
+
|
|
7
|
+
#include <pybind11/pybind11.h>
|
|
8
|
+
|
|
9
|
+
namespace py = pybind11;
|
|
10
|
+
|
|
11
|
+
template <typename R, typename clsT>
|
|
12
|
+
void Eq(clsT cls) {
|
|
13
|
+
cls.def(
|
|
14
|
+
"__eq__",
|
|
15
|
+
[](const typename clsT::type& self, R other) {
|
|
16
|
+
return self == other;
|
|
17
|
+
}
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
template <typename clsT>
|
|
23
|
+
void Eq(clsT cls) {
|
|
24
|
+
Eq<const typename clsT::type&>(cls);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
template <typename clsT>
|
|
29
|
+
void Eq_default(clsT cls) {
|
|
30
|
+
py::object NotImplemented = py::module::import("builtins").attr("NotImplemented");
|
|
31
|
+
cls.def(
|
|
32
|
+
"__eq__",
|
|
33
|
+
[NotImplemented](const typename clsT::type& self, py::object other) -> std::variant<bool, Amulet::pybind11::types::NotImplementedType> {
|
|
34
|
+
return NotImplemented;
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <pybind11/pybind11.h>
|
|
4
|
+
|
|
5
|
+
namespace py = pybind11;
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
template <typename clsT>
|
|
9
|
+
void hash_default(clsT cls) {
|
|
10
|
+
cls.def(
|
|
11
|
+
"__hash__",
|
|
12
|
+
[](py::object self) -> py::int_ {
|
|
13
|
+
return py::module::import("builtins").attr("id")(self);
|
|
14
|
+
}
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
template <typename clsT>
|
|
20
|
+
void hash_disable(clsT cls) {
|
|
21
|
+
cls.def(
|
|
22
|
+
"__hash__",
|
|
23
|
+
[](py::object self) -> size_t {
|
|
24
|
+
throw py::type_error("This class is not hashable.");
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <memory>
|
|
4
|
+
#include <pybind11/pybind11.h>
|
|
5
|
+
|
|
6
|
+
namespace py = pybind11;
|
|
7
|
+
|
|
8
|
+
namespace Amulet {
|
|
9
|
+
namespace collections {
|
|
10
|
+
|
|
11
|
+
// A class to allow python to hold a reference to a smart pointer
|
|
12
|
+
class Holder {
|
|
13
|
+
public:
|
|
14
|
+
virtual ~Holder() {}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
template <typename T>
|
|
18
|
+
class HolderTemplate: public Holder {
|
|
19
|
+
private:
|
|
20
|
+
T value;
|
|
21
|
+
public:
|
|
22
|
+
HolderTemplate(T&& value): value(std::move(value)){}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
template <typename T>
|
|
26
|
+
static py::object make_holder(T&& value) {
|
|
27
|
+
return py::cast(
|
|
28
|
+
static_cast<std::unique_ptr<Holder>>(
|
|
29
|
+
std::make_unique<HolderTemplate<T>>(
|
|
30
|
+
std::move(value)
|
|
31
|
+
)
|
|
32
|
+
)
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#include <stdexcept>
|
|
3
|
+
|
|
4
|
+
#include <pybind11/pybind11.h>
|
|
5
|
+
|
|
6
|
+
namespace py = pybind11;
|
|
7
|
+
|
|
8
|
+
namespace Amulet {
|
|
9
|
+
namespace collections {
|
|
10
|
+
class Iterator {
|
|
11
|
+
public:
|
|
12
|
+
virtual ~Iterator() {};
|
|
13
|
+
virtual bool has_next() = 0;
|
|
14
|
+
virtual py::object next() = 0;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// An iterator for the collections.abc.Sequence protocol.
|
|
18
|
+
class PySequenceIterator: public Iterator {
|
|
19
|
+
private:
|
|
20
|
+
py::object obj;
|
|
21
|
+
size_t index;
|
|
22
|
+
std::ptrdiff_t step;
|
|
23
|
+
public:
|
|
24
|
+
PySequenceIterator(
|
|
25
|
+
py::object obj,
|
|
26
|
+
size_t start,
|
|
27
|
+
std::ptrdiff_t step
|
|
28
|
+
) : obj(obj), index(start), step(step) {};
|
|
29
|
+
bool has_next() override{
|
|
30
|
+
return 0 <= index && index < py::len(obj);
|
|
31
|
+
};
|
|
32
|
+
py::object next() override {
|
|
33
|
+
py::object item = obj.attr("__getitem__")(index);
|
|
34
|
+
index += step;
|
|
35
|
+
return item;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// An iterator for a C++ map-like object.
|
|
40
|
+
template <typename mapT>
|
|
41
|
+
class MapIterator: public Iterator {
|
|
42
|
+
private:
|
|
43
|
+
py::object owner;
|
|
44
|
+
const mapT& map;
|
|
45
|
+
typename mapT::const_iterator begin;
|
|
46
|
+
typename mapT::const_iterator end;
|
|
47
|
+
typename mapT::const_iterator pos;
|
|
48
|
+
size_t size;
|
|
49
|
+
|
|
50
|
+
public:
|
|
51
|
+
MapIterator(const mapT& map, py::object owner = py::none()) :
|
|
52
|
+
owner(owner),
|
|
53
|
+
map(map),
|
|
54
|
+
begin(map.begin()),
|
|
55
|
+
end(map.end()),
|
|
56
|
+
pos(map.begin()),
|
|
57
|
+
size(map.size())
|
|
58
|
+
{}
|
|
59
|
+
|
|
60
|
+
bool has_next() override {
|
|
61
|
+
return pos != end;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
bool is_valid() {
|
|
65
|
+
// This is not fool proof.
|
|
66
|
+
// There are cases where this is true but the iterator is invalid.
|
|
67
|
+
// The programmer should write good code and this will catch some of the bad cases.
|
|
68
|
+
return size == map.size() && begin == map.begin() && end == map.end();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
py::object next() override {
|
|
72
|
+
if (!is_valid()) {
|
|
73
|
+
throw std::runtime_error("map changed size during iteration.");
|
|
74
|
+
}
|
|
75
|
+
return py::cast((pos++)->first);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
}
|
|
80
|
+
}
|