amulet-core 2.0a6__cp311-cp311-win_amd64.whl → 2.0a8__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 (149) hide show
  1. amulet/__init__.cp311-win_amd64.pyd +0 -0
  2. amulet/__init__.py.cpp +6 -0
  3. amulet/__init__.pyi +2 -2
  4. amulet/_init.py +0 -2
  5. amulet/_version.py +3 -3
  6. amulet/biome.pyi +0 -2
  7. amulet/block.pyi +0 -2
  8. amulet/block_entity.pyi +0 -2
  9. amulet/chunk.hpp +2 -1
  10. amulet/chunk.pyi +0 -2
  11. amulet/chunk_components.pyi +20 -18
  12. amulet/collections/eq.py.hpp +1 -1
  13. amulet/collections/mapping.py.hpp +18 -11
  14. amulet/collections/mutable_mapping.py.hpp +17 -6
  15. amulet/collections/sequence.py.hpp +5 -6
  16. amulet/collections.pyi +8 -5
  17. amulet/entity.py +22 -20
  18. amulet/game/translate/_functions/_code_functions/_text.py +2 -2
  19. amulet/game/translate/_functions/abc.py +10 -3
  20. amulet/img/__init__.py +10 -0
  21. amulet/img/missing_no.png +0 -0
  22. amulet/img/missing_pack.png +0 -0
  23. amulet/level/__init__.pyi +2 -6
  24. amulet/level/abc/_chunk_handle.py +45 -22
  25. amulet/level/abc/_level/_creatable_level.py +1 -2
  26. amulet/level/abc/_level/_level.py +1 -5
  27. amulet/level/java/__init__.pyi +0 -5
  28. amulet/level/java/_raw/__init__.pyi +0 -4
  29. amulet/level/java/_raw/java_chunk_decode.cpp +2 -4
  30. amulet/level/java/long_array.pyi +2 -1
  31. amulet/mesh/block/__init__.pyi +301 -0
  32. amulet/mesh/block/_cube.py +198 -0
  33. amulet/mesh/block/_missing_block.py +20 -0
  34. amulet/mesh/block/block_mesh.cpp +107 -0
  35. amulet/mesh/block/block_mesh.hpp +207 -0
  36. amulet/mesh/util.py +17 -0
  37. amulet/player.py +4 -6
  38. amulet/pybind11/collections.hpp +80 -38
  39. amulet/pybind11/numpy.hpp +26 -0
  40. amulet/pybind11/py_module.hpp +16 -51
  41. amulet/pybind11/type_hints.hpp +51 -0
  42. amulet/pybind11/types.hpp +14 -6
  43. amulet/pybind11/typing.hpp +7 -0
  44. amulet/resource_pack/__init__.py +63 -0
  45. amulet/resource_pack/abc/__init__.py +2 -0
  46. amulet/resource_pack/abc/resource_pack.py +38 -0
  47. amulet/resource_pack/abc/resource_pack_manager.py +85 -0
  48. amulet/resource_pack/java/__init__.py +2 -0
  49. amulet/resource_pack/java/download_resources.py +212 -0
  50. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_black.png +0 -0
  51. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_blue.png +0 -0
  52. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_brown.png +0 -0
  53. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_cyan.png +0 -0
  54. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_gray.png +0 -0
  55. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_green.png +0 -0
  56. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_light_blue.png +0 -0
  57. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_light_gray.png +0 -0
  58. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_lime.png +0 -0
  59. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_magenta.png +0 -0
  60. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_orange.png +0 -0
  61. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_pink.png +0 -0
  62. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_purple.png +0 -0
  63. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_red.png +0 -0
  64. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_white.png +0 -0
  65. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_yellow.png +0 -0
  66. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/barrier.png +0 -0
  67. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/end_portal.png +0 -0
  68. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/grass.png +0 -0
  69. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/lava.png +0 -0
  70. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/structure_void.png +0 -0
  71. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/water.png +0 -0
  72. amulet/resource_pack/java/java_vanilla_fix/pack.png +0 -0
  73. amulet/resource_pack/java/resource_pack.py +44 -0
  74. amulet/resource_pack/java/resource_pack_manager.py +563 -0
  75. amulet/resource_pack/unknown_resource_pack.py +10 -0
  76. amulet/utils/__init__.pyi +0 -5
  77. amulet/utils/call_spec/_call_spec.py +2 -7
  78. amulet/utils/cast.py +10 -0
  79. amulet/utils/comment_json.py +188 -0
  80. amulet/utils/matrix.py +3 -3
  81. amulet/utils/numpy_helpers.py +2 -2
  82. amulet/utils/shareable_lock.py +2 -2
  83. amulet/utils/world_utils.py +2 -2
  84. amulet/version.pyi +0 -8
  85. {amulet_core-2.0a6.dist-info → amulet_core-2.0a8.dist-info}/METADATA +2 -2
  86. {amulet_core-2.0a6.dist-info → amulet_core-2.0a8.dist-info}/RECORD +91 -103
  87. {amulet_core-2.0a6.dist-info → amulet_core-2.0a8.dist-info}/WHEEL +1 -1
  88. amulet/chunk_/components/biome.py +0 -155
  89. amulet/chunk_/components/block_entity.py +0 -117
  90. amulet/chunk_/components/entity.py +0 -64
  91. amulet/chunk_/components/height_2d.py +0 -16
  92. amulet/level/bedrock/__init__.py +0 -2
  93. amulet/level/bedrock/_chunk_handle.py +0 -19
  94. amulet/level/bedrock/_dimension.py +0 -22
  95. amulet/level/bedrock/_level.py +0 -187
  96. amulet/level/bedrock/_raw/__init__.py +0 -5
  97. amulet/level/bedrock/_raw/_actor_counter.py +0 -53
  98. amulet/level/bedrock/_raw/_chunk.py +0 -54
  99. amulet/level/bedrock/_raw/_chunk_decode.py +0 -668
  100. amulet/level/bedrock/_raw/_chunk_encode.py +0 -602
  101. amulet/level/bedrock/_raw/_constant.py +0 -9
  102. amulet/level/bedrock/_raw/_dimension.py +0 -343
  103. amulet/level/bedrock/_raw/_level.py +0 -463
  104. amulet/level/bedrock/_raw/_level_dat.py +0 -90
  105. amulet/level/bedrock/_raw/_typing.py +0 -6
  106. amulet/level/bedrock/_raw/leveldb_chunk_versions.py +0 -83
  107. amulet/level/bedrock/chunk/__init__.py +0 -1
  108. amulet/level/bedrock/chunk/_chunk.py +0 -126
  109. amulet/level/bedrock/chunk/components/chunk_version.py +0 -12
  110. amulet/level/bedrock/chunk/components/finalised_state.py +0 -13
  111. amulet/level/bedrock/chunk/components/raw_chunk.py +0 -15
  112. amulet/level/construction/__init__.py +0 -0
  113. amulet/level/java/_chunk_handle.pyi +0 -15
  114. amulet/level/java/_dimension.pyi +0 -13
  115. amulet/level/java/_level.pyi +0 -120
  116. amulet/level/java/_raw/_chunk_decode.py +0 -561
  117. amulet/level/java/_raw/_chunk_encode.py +0 -463
  118. amulet/level/java/_raw/_constant.pyi +0 -20
  119. amulet/level/java/_raw/_data_pack/__init__.pyi +0 -8
  120. amulet/level/java/_raw/_data_pack/data_pack.pyi +0 -197
  121. amulet/level/java/_raw/_data_pack/data_pack_manager.pyi +0 -75
  122. amulet/level/java/_raw/_dimension.pyi +0 -72
  123. amulet/level/java/_raw/_level.pyi +0 -238
  124. amulet/level/java/_raw/_typing.pyi +0 -5
  125. amulet/level/java/anvil/__init__.pyi +0 -11
  126. amulet/level/java/anvil/_dimension.pyi +0 -109
  127. amulet/level/java/anvil/_region.pyi +0 -197
  128. amulet/level/java/anvil/_sector_manager.pyi +0 -142
  129. amulet/level/java_forge/__init__.py +0 -0
  130. amulet/level/mcstructure/__init__.py +0 -0
  131. amulet/level/nbt/__init__.py +0 -0
  132. amulet/level/schematic/__init__.py +0 -0
  133. amulet/level/sponge_schematic/__init__.py +0 -0
  134. amulet/pybind11/python.hpp +0 -14
  135. amulet/utils/call_spec/__init__.pyi +0 -53
  136. amulet/utils/call_spec/_call_spec.pyi +0 -272
  137. amulet/utils/matrix.pyi +0 -177
  138. amulet/utils/shareable_lock.pyi +0 -190
  139. amulet/utils/signal/__init__.pyi +0 -25
  140. amulet/utils/signal/_signal.pyi +0 -84
  141. amulet/utils/task_manager.pyi +0 -168
  142. amulet/utils/typing.py +0 -4
  143. amulet/utils/typing.pyi +0 -6
  144. amulet/utils/weakref.pyi +0 -50
  145. amulet/utils/world_utils.pyi +0 -109
  146. /amulet/img/{missing_world_icon.png → missing_world.png} +0 -0
  147. /amulet/{level/bedrock/chunk/components → mesh}/__init__.py +0 -0
  148. {amulet_core-2.0a6.dist-info → amulet_core-2.0a8.dist-info}/entry_points.txt +0 -0
  149. {amulet_core-2.0a6.dist-info → amulet_core-2.0a8.dist-info}/top_level.txt +0 -0
@@ -1,51 +1,76 @@
1
1
  #pragma once
2
2
  #include <pybind11/pybind11.h>
3
3
 
4
- namespace pybind11 {
5
- namespace collections {
6
- template <typename T>
7
- class Iterator : public object {
8
- PYBIND11_OBJECT_DEFAULT(Iterator, object, PyObject_Type)
4
+ namespace py = pybind11;
5
+
6
+ namespace Amulet {
7
+ namespace pybind11 {
8
+ namespace collections {
9
+ template <typename T>
10
+ class Iterator : public py::object {
11
+ PYBIND11_OBJECT_DEFAULT(Iterator, object, PyObject_Type)
9
12
  using object::object;
10
- };
13
+ };
14
+
15
+ template <typename T>
16
+ class Sequence : public py::object {
17
+ PYBIND11_OBJECT_DEFAULT(Sequence, object, PyObject_Type)
18
+ using object::object;
19
+ };
20
+
21
+ template <typename K, typename V>
22
+ class Mapping : public py::object {
23
+ PYBIND11_OBJECT_DEFAULT(Mapping, object, PyObject_Type)
24
+ using object::object;
25
+ };
26
+
27
+ template <typename K, typename V>
28
+ class MutableMapping : public py::object {
29
+ PYBIND11_OBJECT_DEFAULT(MutableMapping, object, PyObject_Type)
30
+ using object::object;
31
+ };
32
+
33
+ template <typename K>
34
+ class KeysView : public py::object {
35
+ PYBIND11_OBJECT_DEFAULT(KeysView, object, PyObject_Type)
36
+ using object::object;
37
+ };
38
+
39
+ template <typename V>
40
+ class ValuesView : public py::object {
41
+ PYBIND11_OBJECT_DEFAULT(ValuesView, object, PyObject_Type)
42
+ using object::object;
43
+ };
44
+
45
+ template <typename K, typename V>
46
+ class ItemsView : public py::object {
47
+ PYBIND11_OBJECT_DEFAULT(ItemsView, object, PyObject_Type)
48
+ using object::object;
49
+ };
50
+ }
11
51
  }
52
+ }
53
+
54
+ namespace pybind11 {
12
55
  namespace detail {
13
56
  template <typename T>
14
- struct handle_type_name<collections::Iterator<T>> {
57
+ struct handle_type_name<Amulet::pybind11::collections::Iterator<T>> {
15
58
  static constexpr auto name =
16
59
  const_name("collections.abc.Iterator[") +
17
60
  make_caster<T>::name +
18
61
  const_name("]");
19
62
  };
20
- }
21
-
22
- namespace collections {
23
- template <typename T>
24
- class Sequence : public object {
25
- PYBIND11_OBJECT_DEFAULT(Sequence, object, PyObject_Type)
26
- using object::object;
27
- };
28
- }
29
- namespace detail {
63
+
30
64
  template <typename T>
31
- struct handle_type_name<collections::Sequence<T>> {
65
+ struct handle_type_name<Amulet::pybind11::collections::Sequence<T>> {
32
66
  static constexpr auto name =
33
67
  const_name("collections.abc.Sequence[") +
34
68
  make_caster<T>::name +
35
69
  const_name("]");
36
70
  };
37
- }
38
-
39
- namespace collections {
40
- template <typename K, typename V>
41
- class Mapping : public object {
42
- PYBIND11_OBJECT_DEFAULT(Mapping, object, PyObject_Type)
43
- using object::object;
44
- };
45
- }
46
- namespace detail {
71
+
47
72
  template <typename K, typename V>
48
- struct handle_type_name<collections::Mapping<K, V>> {
73
+ struct handle_type_name<Amulet::pybind11::collections::Mapping<K, V>> {
49
74
  static constexpr auto name =
50
75
  const_name("collections.abc.Mapping[") +
51
76
  make_caster<K>::name +
@@ -53,20 +78,37 @@ namespace pybind11 {
53
78
  make_caster<V>::name +
54
79
  const_name("]");
55
80
  };
56
- }
57
81
 
58
- namespace collections {
59
82
  template <typename K, typename V>
60
- class MutableMapping : public object {
61
- PYBIND11_OBJECT_DEFAULT(MutableMapping, object, PyObject_Type)
62
- using object::object;
83
+ struct handle_type_name<Amulet::pybind11::collections::MutableMapping<K, V>> {
84
+ static constexpr auto name =
85
+ const_name("collections.abc.MutableMapping[") +
86
+ make_caster<K>::name +
87
+ const_name(", ")
88
+ + make_caster<V>::name +
89
+ const_name("]");
63
90
  };
64
- }
65
- namespace detail {
91
+
92
+ template <typename K>
93
+ struct handle_type_name<Amulet::pybind11::collections::KeysView<K>> {
94
+ static constexpr auto name =
95
+ const_name("collections.abc.KeysView[") +
96
+ make_caster<K>::name +
97
+ const_name("]");
98
+ };
99
+
100
+ template <typename V>
101
+ struct handle_type_name<Amulet::pybind11::collections::ValuesView<V>> {
102
+ static constexpr auto name =
103
+ const_name("collections.abc.ValuesView[") +
104
+ make_caster<V>::name +
105
+ const_name("]");
106
+ };
107
+
66
108
  template <typename K, typename V>
67
- struct handle_type_name<collections::MutableMapping<K, V>> {
109
+ struct handle_type_name<Amulet::pybind11::collections::ItemsView<K, V>> {
68
110
  static constexpr auto name =
69
- const_name("collections.abc.MutableMapping[") +
111
+ const_name("collections.abc.ItemsView[") +
70
112
  make_caster<K>::name +
71
113
  const_name(", ")
72
114
  + make_caster<V>::name +
@@ -0,0 +1,26 @@
1
+ #pragma once
2
+ #include <pybind11/pybind11.h>
3
+ #include <pybind11/numpy.h>
4
+
5
+ namespace py = pybind11;
6
+
7
+ namespace Amulet {
8
+ namespace pybind11 {
9
+ namespace numpy {
10
+ template <typename T, int ExtraFlags = py::array::forcecast>
11
+ class array_t : public py::array_t<T, ExtraFlags> {
12
+ using py::array_t<T, ExtraFlags>::array_t;
13
+ };
14
+ }
15
+ }
16
+ }
17
+
18
+ namespace pybind11 {
19
+ namespace detail {
20
+ template <typename T, int Flags>
21
+ struct handle_type_name<Amulet::pybind11::numpy::array_t<T, Flags>> {
22
+ static constexpr auto name
23
+ = const_name("numpy.typing.NDArray[") + npy_format_descriptor<T>::name + const_name("]");
24
+ };
25
+ }
26
+ }
@@ -7,63 +7,28 @@
7
7
  #include <utility>
8
8
 
9
9
  #include <pybind11/pybind11.h>
10
+ #include <amulet/pybind11/typing.hpp>
10
11
 
11
12
  namespace py = pybind11;
12
13
 
13
14
  namespace pybind11 {
14
- // Define deferred variables
15
- inline void def_deferred(
16
- py::module m,
17
- std::map<std::string, std::function<py::object()>> attrs
18
- ){
19
- m.def(
20
- "__getattr__",
21
- [attrs](py::object attr) -> py::object {
22
- if (py::isinstance<py::str>(attr)) {
23
- std::string attr_str = attr.cast<std::string>();
24
- auto it = attrs.find(attr_str);
25
- if (it != attrs.end()) {
26
- return it->second();
27
- }
28
- }
29
- throw py::attribute_error(py::repr(attr));
15
+ inline void def_package_path(py::module m_parent, py::module m, std::string name) {
16
+ py::list paths;
17
+ py::list parent_paths = m_parent.attr("__path__").cast<py::list>();
18
+ for (auto py_path : parent_paths) {
19
+ if (py::isinstance<py::str>(py_path)) {
20
+ std::string path = py_path.cast<std::string>();
21
+ path.push_back(std::filesystem::path::preferred_separator);
22
+ path.append(name);
23
+ paths.append(py::cast(path));
30
24
  }
31
- );
32
- m.def(
33
- "__dir__",
34
- [attrs, m]() {
35
- py::set names;
36
- // Add the variables defined in the module
37
- py::object dict = m.attr("__dict__");
38
- for (auto it = dict.begin(); it != dict.end(); it++) {
39
- names.add(*it);
40
- }
41
- // Add the deferred variables
42
- for (const auto& [name, _] : attrs) {
43
- names.add(py::str(name));
44
- }
45
- // Return as list
46
- return py::module::import("builtins").attr("list")(names);
47
- }
48
- );
49
- }
50
-
51
- inline std::pair<std::string, std::function<py::object()>> deferred_package_path(py::module m_parent, py::module m, std::string name) {
52
- auto getter = [m_parent, m, name]() {
53
- std::string path = m_parent.attr("__path__").attr("__getitem__")(0).cast<std::string>();
54
- path.push_back(std::filesystem::path::preferred_separator);
55
- path.append(name);
56
- py::list __path__;
57
- __path__.append(py::cast(path));
58
- return __path__;
59
- };
60
- return std::make_pair("__path__", getter);
25
+ }
26
+ m.attr("__path__") = paths;
61
27
  }
62
28
 
63
- inline std::pair<std::string, std::function<py::object()>> deferred_import(std::string module_name, std::string name) {
64
- auto getter = [module_name, name]() {
65
- return py::module::import(module_name.c_str()).attr(name.c_str());
66
- };
67
- return std::make_pair(name, getter);
29
+ inline module def_subpackage(py::module m_parent, std::string name) {
30
+ auto m = m_parent.def_submodule(name.c_str());
31
+ def_package_path(m_parent, m, name);
32
+ return m;
68
33
  }
69
34
  }
@@ -0,0 +1,51 @@
1
+ #pragma once
2
+ #include <pybind11/pybind11.h>
3
+ #include <pybind11/detail/descr.h>
4
+ #include <vector>
5
+
6
+ namespace py = pybind11;
7
+
8
+ namespace Amulet {
9
+ namespace pybind11 {
10
+ namespace detail {
11
+ template<size_t N>
12
+ struct FixedString {
13
+ char buf[N + 1]{};
14
+ constexpr FixedString(char const* s) {
15
+ for (unsigned i = 0; i != N; ++i) buf[i] = s[i];
16
+ }
17
+ };
18
+ template<unsigned N>
19
+ FixedString(char const (&)[N])->FixedString<N - 1>;
20
+ }
21
+
22
+ // Type hint for a native python object.
23
+ namespace type_hints {
24
+ template <detail::FixedString T>
25
+ class PyObjectStr : public py::object {
26
+ PYBIND11_OBJECT_DEFAULT(PyObjectStr, object, PyObject_Type)
27
+ using object::object;
28
+ };
29
+
30
+ template <typename cppT>
31
+ class PyObjectCpp : public py::object {
32
+ PYBIND11_OBJECT_DEFAULT(PyObjectCpp, object, PyObject_Type)
33
+ using object::object;
34
+ };
35
+ }
36
+ }
37
+ }
38
+
39
+ namespace pybind11 {
40
+ namespace detail {
41
+ template <Amulet::pybind11::detail::FixedString T>
42
+ struct handle_type_name<Amulet::pybind11::type_hints::PyObjectStr<T>> {
43
+ static constexpr auto name = pybind11::detail::const_name(T.buf);
44
+ };
45
+
46
+ template <typename cppT>
47
+ struct handle_type_name<Amulet::pybind11::type_hints::PyObjectCpp<cppT>> {
48
+ static constexpr auto name = make_caster<cppT>::name;
49
+ };
50
+ }
51
+ }
amulet/pybind11/types.hpp CHANGED
@@ -1,16 +1,24 @@
1
1
  #pragma once
2
2
  #include <pybind11/pybind11.h>
3
3
 
4
- namespace pybind11 {
5
- namespace types {
6
- class NotImplementedType : public object {
7
- PYBIND11_OBJECT_DEFAULT(NotImplementedType, object, PyObject_Type)
4
+ namespace py = pybind11;
5
+
6
+ namespace Amulet {
7
+ namespace pybind11 {
8
+ namespace types {
9
+ class NotImplementedType : public py::object {
10
+ PYBIND11_OBJECT_DEFAULT(NotImplementedType, object, PyObject_Type)
8
11
  using object::object;
9
- };
12
+ };
13
+ }
14
+
10
15
  }
16
+ }
17
+
18
+ namespace pybind11 {
11
19
  namespace detail {
12
20
  template <>
13
- struct handle_type_name<types::NotImplementedType> {
21
+ struct handle_type_name<Amulet::pybind11::types::NotImplementedType> {
14
22
  static constexpr auto name = const_name("types.NotImplementedType");
15
23
  };
16
24
  }
@@ -0,0 +1,7 @@
1
+ #pragma once
2
+ #include <pybind11/pybind11.h>
3
+ #include <vector>
4
+
5
+ namespace pybind11 {
6
+
7
+ }
@@ -0,0 +1,63 @@
1
+ from typing import Iterable, Union
2
+
3
+ from amulet.resource_pack.abc import (
4
+ BaseResourcePack,
5
+ BaseResourcePackManager,
6
+ )
7
+ from amulet.resource_pack.java import (
8
+ JavaResourcePack,
9
+ JavaResourcePackManager,
10
+ )
11
+
12
+ # from amulet.resource_pack.bedrock import (
13
+ # BedrockResourcePack,
14
+ # BedrockResourcePackManager,
15
+ # )
16
+ from .unknown_resource_pack import UnknownResourcePack
17
+
18
+
19
+ def load_resource_pack(resource_pack_path: str) -> BaseResourcePack:
20
+ if JavaResourcePack.is_valid(resource_pack_path):
21
+ return JavaResourcePack(resource_pack_path)
22
+ # elif BedrockResourcePack.is_valid(resource_pack_path):
23
+ # return BedrockResourcePack(resource_pack_path)
24
+ else:
25
+ return UnknownResourcePack(resource_pack_path)
26
+
27
+
28
+ def load_resource_pack_manager(
29
+ resource_packs: Iterable[Union[str, BaseResourcePack]], load: bool = True
30
+ ) -> BaseResourcePackManager:
31
+ resource_packs_out: list[BaseResourcePack] = []
32
+ for resource_pack in resource_packs:
33
+ if isinstance(resource_pack, str):
34
+ resource_pack = load_resource_pack(resource_pack)
35
+ if (
36
+ not isinstance(resource_pack, UnknownResourcePack)
37
+ and resource_pack.valid_pack
38
+ ):
39
+ if resource_packs_out:
40
+ if isinstance(resource_pack, resource_packs_out[0].__class__):
41
+ resource_packs_out.append(resource_pack)
42
+ else:
43
+ resource_packs_out.append(resource_pack)
44
+
45
+ resource_packs = resource_packs_out
46
+ if resource_packs:
47
+ if isinstance(resource_packs[0], JavaResourcePack):
48
+ return JavaResourcePackManager(
49
+ [pack for pack in resource_packs if isinstance(pack, JavaResourcePack)],
50
+ load,
51
+ )
52
+ # elif isinstance(resource_packs[0], BedrockResourcePack):
53
+ # return BedrockResourcePackManager(
54
+ # [
55
+ # pack
56
+ # for pack in resource_packs
57
+ # if isinstance(pack, BedrockResourcePack)
58
+ # ],
59
+ # load,
60
+ # )
61
+
62
+ raise NotImplementedError
63
+ # return UnknownResourcePackManager()
@@ -0,0 +1,2 @@
1
+ from .resource_pack import BaseResourcePack
2
+ from .resource_pack_manager import BaseResourcePackManager
@@ -0,0 +1,38 @@
1
+ from amulet.img import missing_pack_icon_path
2
+
3
+
4
+ class BaseResourcePack:
5
+ """The base class that all resource packs must inherit from. Defines the base api."""
6
+
7
+ def __init__(self, root_dir: str):
8
+ self._valid_pack = False
9
+ self._root_dir = root_dir
10
+ self._pack_description = ""
11
+ self._pack_icon = missing_pack_icon_path
12
+
13
+ def __repr__(self) -> str:
14
+ raise NotImplementedError
15
+
16
+ @staticmethod
17
+ def is_valid(pack_path: str) -> bool:
18
+ raise NotImplementedError
19
+
20
+ @property
21
+ def valid_pack(self) -> bool:
22
+ """bool - does the pack meet the minimum requirements to be a resource pack"""
23
+ return self._valid_pack
24
+
25
+ @property
26
+ def root_dir(self) -> str:
27
+ """str - the root directory of the pack"""
28
+ return self._root_dir
29
+
30
+ @property
31
+ def pack_description(self) -> str:
32
+ """str - the description as described in the pack"""
33
+ return self._pack_description
34
+
35
+ @property
36
+ def pack_icon(self) -> str:
37
+ """str - path to the pack icon"""
38
+ return self._pack_icon
@@ -0,0 +1,85 @@
1
+ from typing import Optional, Iterator, TypeVar, Generic
2
+ import json
3
+
4
+ from amulet.block import Block, BlockStack
5
+ from amulet.mesh.block import BlockMesh, merge_block_meshes, get_missing_block
6
+ from amulet.resource_pack.abc.resource_pack import BaseResourcePack
7
+ from amulet.img import missing_no_icon_path
8
+
9
+ PackT = TypeVar("PackT", bound=BaseResourcePack)
10
+
11
+
12
+ class BaseResourcePackManager(Generic[PackT]):
13
+ """The base class that all resource pack managers must inherit from. Defines the base api."""
14
+
15
+ def __init__(self) -> None:
16
+ self._packs: list[PackT] = []
17
+ self._missing_block: Optional[BlockMesh] = None
18
+ self._texture_is_transparent: dict[str, tuple[float, bool]] = {}
19
+ self._cached_models: dict[BlockStack, BlockMesh] = {}
20
+
21
+ @property
22
+ def pack_paths(self) -> list[str]:
23
+ return [pack.root_dir for pack in self._packs]
24
+
25
+ def _unload(self) -> None:
26
+ """Clear all loaded resources."""
27
+ self._texture_is_transparent.clear()
28
+ self._cached_models.clear()
29
+
30
+ def _load_transparency_cache(self, path: str) -> None:
31
+ try:
32
+ with open(path) as f:
33
+ self._texture_is_transparent = json.load(f)
34
+ except:
35
+ pass
36
+
37
+ def _load_iter(self) -> Iterator[float]:
38
+ """Load resources."""
39
+ raise NotImplementedError
40
+
41
+ def reload(self) -> Iterator[float]:
42
+ """Unload and reload resources"""
43
+ self._unload()
44
+ yield from self._load_iter()
45
+
46
+ @property
47
+ def missing_no(self) -> str:
48
+ """The path to the missing_no image"""
49
+ return missing_no_icon_path
50
+
51
+ @property
52
+ def missing_block(self) -> BlockMesh:
53
+ if self._missing_block is None:
54
+ self._missing_block = get_missing_block(self)
55
+ return self._missing_block
56
+
57
+ @property
58
+ def textures(self) -> tuple[str, ...]:
59
+ """Returns a tuple of all the texture paths in the resource pack."""
60
+ raise NotImplementedError
61
+
62
+ def get_texture_path(self, namespace: Optional[str], relative_path: str) -> str:
63
+ """Get the absolute texture path from the namespace and relative path pair"""
64
+ raise NotImplementedError
65
+
66
+ def get_block_model(self, block_stack: BlockStack) -> BlockMesh:
67
+ """Get a model for a block state.
68
+ The block should already be in the resource pack format"""
69
+ if block_stack not in self._cached_models:
70
+ if len(block_stack) == 1:
71
+ self._cached_models[block_stack] = self._get_model(
72
+ block_stack.base_block
73
+ )
74
+ else:
75
+ self._cached_models[block_stack] = merge_block_meshes(
76
+ (self._get_model(block_stack.base_block),)
77
+ + tuple(
78
+ self._get_model(block_) for block_ in block_stack.extra_blocks
79
+ )
80
+ )
81
+
82
+ return self._cached_models[block_stack]
83
+
84
+ def _get_model(self, block: Block) -> BlockMesh:
85
+ raise NotImplementedError
@@ -0,0 +1,2 @@
1
+ from .resource_pack import JavaResourcePack
2
+ from .resource_pack_manager import JavaResourcePackManager