beet-datapack-utils 0.1.0__py3-none-any.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.
- beet_datapack_utils/__init__.py +37 -0
- beet_datapack_utils/density.py +39 -0
- beet_datapack_utils/fields.py +61 -0
- beet_datapack_utils/py.typed +0 -0
- beet_datapack_utils/registries.py +52 -0
- beet_datapack_utils/targets.py +126 -0
- beet_datapack_utils/trees.py +62 -0
- beet_datapack_utils/versions.py +61 -0
- beet_datapack_utils-0.1.0.dist-info/METADATA +104 -0
- beet_datapack_utils-0.1.0.dist-info/RECORD +12 -0
- beet_datapack_utils-0.1.0.dist-info/WHEEL +4 -0
- beet_datapack_utils-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""Helper functions for Minecraft datapacks using beet.
|
|
2
|
+
|
|
3
|
+
A datapack build has a base pack and overlays, each for a Minecraft version
|
|
4
|
+
(`meta.base_version` and `meta.overlay_versions` in the beet config). These
|
|
5
|
+
helpers copy the matching vanilla files, hide format differences between
|
|
6
|
+
versions and write the patched files back.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from .density import WRAPPER_TYPES, is_reference, unwrap
|
|
10
|
+
from .fields import octave_key, provider, resolve_key, set_range, worldgen_config
|
|
11
|
+
from .registries import CARVER, FEATURE, RegistryLike, VersionedRegistry, resolve_registry
|
|
12
|
+
from .targets import Target, Targets
|
|
13
|
+
from .trees import find_nodes, replace_nodes
|
|
14
|
+
from .versions import Version, VersionLike, parse_version
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
"CARVER",
|
|
18
|
+
"FEATURE",
|
|
19
|
+
"WRAPPER_TYPES",
|
|
20
|
+
"RegistryLike",
|
|
21
|
+
"Target",
|
|
22
|
+
"Targets",
|
|
23
|
+
"Version",
|
|
24
|
+
"VersionLike",
|
|
25
|
+
"VersionedRegistry",
|
|
26
|
+
"find_nodes",
|
|
27
|
+
"is_reference",
|
|
28
|
+
"octave_key",
|
|
29
|
+
"parse_version",
|
|
30
|
+
"provider",
|
|
31
|
+
"replace_nodes",
|
|
32
|
+
"resolve_key",
|
|
33
|
+
"resolve_registry",
|
|
34
|
+
"set_range",
|
|
35
|
+
"unwrap",
|
|
36
|
+
"worldgen_config",
|
|
37
|
+
]
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""Helpers for density functions."""
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
__all__ = ["WRAPPER_TYPES", "is_reference", "unwrap"]
|
|
6
|
+
|
|
7
|
+
#: Density function types that only wrap their input for caching/interpolation.
|
|
8
|
+
WRAPPER_TYPES = frozenset(
|
|
9
|
+
{
|
|
10
|
+
"minecraft:cache_2d",
|
|
11
|
+
"minecraft:cache_all_in_cell",
|
|
12
|
+
"minecraft:cache_once",
|
|
13
|
+
"minecraft:flat_cache",
|
|
14
|
+
"minecraft:interpolated",
|
|
15
|
+
}
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def unwrap(node: Any) -> Any:
|
|
20
|
+
"""Strip caching/interpolation wrappers and return the wrapped function.
|
|
21
|
+
|
|
22
|
+
The wrapped function is stored in `argument` before 26.3 and in `input`
|
|
23
|
+
since 26.3.
|
|
24
|
+
"""
|
|
25
|
+
while isinstance(node, dict) and node.get("type") in WRAPPER_TYPES:
|
|
26
|
+
inner = node.get("input", node.get("argument"))
|
|
27
|
+
if inner is None:
|
|
28
|
+
break
|
|
29
|
+
node = inner
|
|
30
|
+
return node
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def is_reference(node: Any, function_id: str) -> bool:
|
|
34
|
+
"""Return True if `node` references `function_id`, possibly through wrappers.
|
|
35
|
+
|
|
36
|
+
>>> is_reference({"type": "minecraft:cache_once", "argument": "minecraft:a"}, "minecraft:a")
|
|
37
|
+
True
|
|
38
|
+
"""
|
|
39
|
+
return unwrap(node) == function_id
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""Access to worldgen fields whose shape or name changed between versions."""
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
__all__ = ["octave_key", "provider", "resolve_key", "set_range", "worldgen_config"]
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def worldgen_config(data: dict) -> dict:
|
|
9
|
+
"""Return the object holding a carver's or feature's settings.
|
|
10
|
+
|
|
11
|
+
Before 26.3 the settings are wrapped in a `config` object. Since 26.3
|
|
12
|
+
they sit directly on the root object next to `type`.
|
|
13
|
+
"""
|
|
14
|
+
config = data.get("config")
|
|
15
|
+
return config if isinstance(config, dict) else data
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def resolve_key(data: dict, *candidates: str) -> str:
|
|
19
|
+
"""Return the first key from `candidates` that exists in `data`.
|
|
20
|
+
|
|
21
|
+
Used for fields that were renamed between versions, e.g.
|
|
22
|
+
`resolve_key(config, "room_vertical_radius_multiplier", "yScale")`.
|
|
23
|
+
"""
|
|
24
|
+
for key in candidates:
|
|
25
|
+
if key in data:
|
|
26
|
+
return key
|
|
27
|
+
raise KeyError(f"None of {list(candidates)} found in {sorted(data)}")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def octave_key(noise: dict) -> str:
|
|
31
|
+
"""Return the first-octave field of a noise (`firstOctave` became `base_octave` in 26.3)."""
|
|
32
|
+
return resolve_key(noise, "base_octave", "firstOctave")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def provider(config: dict, name: str) -> dict:
|
|
36
|
+
"""Return the int/float provider `name`, unwrapping the pre-1.20.5 `value` object.
|
|
37
|
+
|
|
38
|
+
Before 1.20.5 a uniform provider looked like
|
|
39
|
+
`{"type": "uniform", "value": {"min_inclusive": 0.7, "max_exclusive": 1.4}}`.
|
|
40
|
+
Since then the bounds sit directly next to `type`.
|
|
41
|
+
"""
|
|
42
|
+
node = config[name]
|
|
43
|
+
if not isinstance(node, dict):
|
|
44
|
+
raise TypeError(f"{name!r} is a constant ({node!r}), not a provider object")
|
|
45
|
+
value = node.get("value")
|
|
46
|
+
return value if isinstance(value, dict) else node
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def set_range(node: dict, minimum: Any, maximum: Any) -> None:
|
|
50
|
+
"""Set the bounds of a uniform-like provider.
|
|
51
|
+
|
|
52
|
+
Writes `min_inclusive` and whichever upper bound the provider uses:
|
|
53
|
+
`max_exclusive` (float providers) or `max_inclusive` (int providers).
|
|
54
|
+
"""
|
|
55
|
+
upper: str | None = next(
|
|
56
|
+
(key for key in ("max_exclusive", "max_inclusive") if key in node), None
|
|
57
|
+
)
|
|
58
|
+
if upper is None or "min_inclusive" not in node:
|
|
59
|
+
raise KeyError(f"Not a range provider: {node!r}")
|
|
60
|
+
node["min_inclusive"] = minimum
|
|
61
|
+
node[upper] = maximum
|
|
File without changes
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""Resource types whose folder changed between Minecraft versions."""
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
|
|
5
|
+
from beet import JsonFile
|
|
6
|
+
from beet.contrib.worldgen import (
|
|
7
|
+
WorldgenCarver,
|
|
8
|
+
WorldgenConfiguredCarver,
|
|
9
|
+
WorldgenConfiguredFeature,
|
|
10
|
+
WorldgenFeature,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
from .versions import Version, VersionLike
|
|
14
|
+
|
|
15
|
+
__all__ = ["CARVER", "FEATURE", "RegistryLike", "VersionedRegistry", "resolve_registry"]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@dataclass(frozen=True)
|
|
19
|
+
class VersionedRegistry:
|
|
20
|
+
"""A resource type that moved to another folder in some version.
|
|
21
|
+
|
|
22
|
+
`default` is used before the first entry of `changes`; each entry is
|
|
23
|
+
`(first_version, file_type)`.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
default: type[JsonFile]
|
|
27
|
+
changes: tuple[tuple[str, type[JsonFile]], ...] = ()
|
|
28
|
+
|
|
29
|
+
def resolve(self, version: VersionLike) -> type[JsonFile]:
|
|
30
|
+
"""Return the file type used by `version`."""
|
|
31
|
+
version = Version(version)
|
|
32
|
+
file_type = self.default
|
|
33
|
+
for since, candidate in sorted(self.changes, key=lambda change: Version(change[0])):
|
|
34
|
+
if version >= since:
|
|
35
|
+
file_type = candidate
|
|
36
|
+
return file_type
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
RegistryLike = type[JsonFile] | VersionedRegistry
|
|
40
|
+
|
|
41
|
+
#: `worldgen/configured_carver` became `worldgen/carver` in 26.3.
|
|
42
|
+
CARVER = VersionedRegistry(WorldgenConfiguredCarver, (("26.3", WorldgenCarver),))
|
|
43
|
+
|
|
44
|
+
#: `worldgen/configured_feature` became `worldgen/feature` in 26.3.
|
|
45
|
+
FEATURE = VersionedRegistry(WorldgenConfiguredFeature, (("26.3", WorldgenFeature),))
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def resolve_registry(registry: RegistryLike, version: VersionLike) -> type[JsonFile]:
|
|
49
|
+
"""Return the file type for `version`, accepting plain beet file types too."""
|
|
50
|
+
if isinstance(registry, VersionedRegistry):
|
|
51
|
+
return registry.resolve(version)
|
|
52
|
+
return registry
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"""Iterate over the base pack and its overlays and patch vanilla files."""
|
|
2
|
+
|
|
3
|
+
from collections.abc import Callable, Iterator
|
|
4
|
+
from contextlib import contextmanager
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from functools import cached_property
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from beet import Context, DataPack, JsonFile
|
|
10
|
+
from beet.contrib.vanilla import Vanilla
|
|
11
|
+
from beet.contrib.worldgen import WorldgenDensityFunction
|
|
12
|
+
|
|
13
|
+
from .registries import RegistryLike, resolve_registry
|
|
14
|
+
from .versions import Version, VersionLike
|
|
15
|
+
|
|
16
|
+
__all__ = ["Target", "Targets"]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@dataclass
|
|
20
|
+
class Target:
|
|
21
|
+
"""One output pack (the base pack or an overlay) and its Minecraft version."""
|
|
22
|
+
|
|
23
|
+
pack: DataPack
|
|
24
|
+
version: Version
|
|
25
|
+
directory: str | None = None
|
|
26
|
+
vanilla_provider: Callable[[], Vanilla] | None = field(default=None, repr=False)
|
|
27
|
+
|
|
28
|
+
@property
|
|
29
|
+
def is_overlay(self) -> bool:
|
|
30
|
+
return self.directory is not None
|
|
31
|
+
|
|
32
|
+
def at_least(self, version: VersionLike) -> bool:
|
|
33
|
+
"""Return True if this target's version is `version` or newer."""
|
|
34
|
+
return self.version >= version
|
|
35
|
+
|
|
36
|
+
@cached_property
|
|
37
|
+
def vanilla(self) -> DataPack:
|
|
38
|
+
"""The vanilla data pack of this target's version (mounted once).
|
|
39
|
+
|
|
40
|
+
Vanilla is only fetched on first access, so packs that never read
|
|
41
|
+
vanilla files build without network access.
|
|
42
|
+
"""
|
|
43
|
+
if self.vanilla_provider is None:
|
|
44
|
+
raise RuntimeError("Target was created without a Vanilla provider")
|
|
45
|
+
vanilla = self.vanilla_provider()
|
|
46
|
+
return vanilla.releases[str(self.version)].mount("data").data
|
|
47
|
+
|
|
48
|
+
def file_type(self, registry: RegistryLike) -> type[JsonFile]:
|
|
49
|
+
"""Resolve a (versioned) registry to the file type of this version."""
|
|
50
|
+
return resolve_registry(registry, self.version)
|
|
51
|
+
|
|
52
|
+
def copy(self, registry: RegistryLike, name: str) -> JsonFile:
|
|
53
|
+
"""Return an independent copy of the vanilla file `name`."""
|
|
54
|
+
file_type = self.file_type(registry)
|
|
55
|
+
try:
|
|
56
|
+
return self.vanilla[file_type][name].copy()
|
|
57
|
+
except KeyError:
|
|
58
|
+
raise KeyError(
|
|
59
|
+
f"{name} ({file_type.__name__}) not found in vanilla {self.version}"
|
|
60
|
+
) from None
|
|
61
|
+
|
|
62
|
+
def write(self, registry: RegistryLike, name: str, file: JsonFile) -> None:
|
|
63
|
+
"""Write `file` as `name` into this target's pack."""
|
|
64
|
+
self.pack[self.file_type(registry)][name] = file
|
|
65
|
+
|
|
66
|
+
@contextmanager
|
|
67
|
+
def patch(self, registry: RegistryLike, name: str) -> Iterator[Any]:
|
|
68
|
+
"""Copy a vanilla file, let the caller modify its JSON, then write it.
|
|
69
|
+
|
|
70
|
+
Nothing is written if the block raises.
|
|
71
|
+
|
|
72
|
+
with target.patch(CARVER, "minecraft:canyon") as carver:
|
|
73
|
+
worldgen_config(carver)["probability"] = 0
|
|
74
|
+
"""
|
|
75
|
+
file = self.copy(registry, name)
|
|
76
|
+
yield file.data
|
|
77
|
+
self.write(registry, name, file)
|
|
78
|
+
|
|
79
|
+
def inline_density_function(self, node: Any) -> Any:
|
|
80
|
+
"""Return a copy of the referenced vanilla density function if `node` is an id.
|
|
81
|
+
|
|
82
|
+
Useful because 26.3 moved most noise router functions into separate
|
|
83
|
+
files; inlining keeps a patch local to one noise settings file.
|
|
84
|
+
"""
|
|
85
|
+
if isinstance(node, str):
|
|
86
|
+
return self.copy(WorldgenDensityFunction, node).data
|
|
87
|
+
return node
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class Targets:
|
|
91
|
+
"""Beet service yielding a `Target` for the base pack and every overlay.
|
|
92
|
+
|
|
93
|
+
Reads `meta.base_version` and `meta.overlay_versions` (overlay directory
|
|
94
|
+
-> version). Inject it with `ctx.inject(Targets)`; the instance is shared
|
|
95
|
+
by all plugins of a build, so each vanilla version is mounted only once.
|
|
96
|
+
|
|
97
|
+
def beet_default(ctx: Context):
|
|
98
|
+
for target in ctx.inject(Targets):
|
|
99
|
+
...
|
|
100
|
+
"""
|
|
101
|
+
|
|
102
|
+
def __init__(self, ctx: Context):
|
|
103
|
+
self.ctx = ctx
|
|
104
|
+
|
|
105
|
+
@cached_property
|
|
106
|
+
def targets(self) -> list[Target]:
|
|
107
|
+
meta = self.ctx.meta
|
|
108
|
+
if "base_version" not in meta:
|
|
109
|
+
raise KeyError("Missing `meta.base_version` in the beet config")
|
|
110
|
+
|
|
111
|
+
def vanilla() -> Vanilla:
|
|
112
|
+
# Injected lazily: creating the Vanilla service downloads the
|
|
113
|
+
# version manifest. ctx.inject caches it for the whole build.
|
|
114
|
+
return self.ctx.inject(Vanilla)
|
|
115
|
+
|
|
116
|
+
targets = [Target(self.ctx.data, Version(meta["base_version"]), None, vanilla)]
|
|
117
|
+
for directory, version in meta.get("overlay_versions", {}).items():
|
|
118
|
+
overlay = self.ctx.data.overlays[directory]
|
|
119
|
+
targets.append(Target(overlay, Version(version), directory, vanilla))
|
|
120
|
+
return targets
|
|
121
|
+
|
|
122
|
+
def __iter__(self) -> Iterator[Target]:
|
|
123
|
+
return iter(self.targets)
|
|
124
|
+
|
|
125
|
+
def __len__(self) -> int:
|
|
126
|
+
return len(self.targets)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""Search and replace inside JSON trees such as density functions."""
|
|
2
|
+
|
|
3
|
+
from collections.abc import Callable, Iterator
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
__all__ = ["find_nodes", "replace_nodes"]
|
|
7
|
+
|
|
8
|
+
Matcher = Callable[[Any], bool]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _children(tree: Any) -> list[tuple[Any, Any]]:
|
|
12
|
+
if isinstance(tree, dict):
|
|
13
|
+
return list(tree.items())
|
|
14
|
+
if isinstance(tree, list):
|
|
15
|
+
return list(enumerate(tree))
|
|
16
|
+
return []
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def find_nodes(tree: Any, match: Matcher) -> Iterator[Any]:
|
|
20
|
+
"""Yield every node below `tree` (depth first) for which `match` is True."""
|
|
21
|
+
for _, child in _children(tree):
|
|
22
|
+
if match(child):
|
|
23
|
+
yield child
|
|
24
|
+
yield from find_nodes(child, match)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def replace_nodes(
|
|
28
|
+
tree: Any,
|
|
29
|
+
match: Matcher,
|
|
30
|
+
replacement: Any,
|
|
31
|
+
expected: int | None = None,
|
|
32
|
+
) -> int:
|
|
33
|
+
"""Replace every node below `tree` for which `match` is True.
|
|
34
|
+
|
|
35
|
+
Does not descend into replaced nodes and returns the number of
|
|
36
|
+
replacements. Pass `expected` to fail loudly when vanilla changed its
|
|
37
|
+
structure; nothing is modified in that case.
|
|
38
|
+
"""
|
|
39
|
+
if expected is not None:
|
|
40
|
+
found = sum(1 for _ in _matches_without_nesting(tree, match))
|
|
41
|
+
if found != expected:
|
|
42
|
+
raise ValueError(f"Expected {expected} matching node(s), found {found}")
|
|
43
|
+
return _replace(tree, match, replacement)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _matches_without_nesting(tree: Any, match: Matcher) -> Iterator[Any]:
|
|
47
|
+
for _, child in _children(tree):
|
|
48
|
+
if match(child):
|
|
49
|
+
yield child
|
|
50
|
+
else:
|
|
51
|
+
yield from _matches_without_nesting(child, match)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _replace(tree: Any, match: Matcher, replacement: Any) -> int:
|
|
55
|
+
count = 0
|
|
56
|
+
for key, child in _children(tree):
|
|
57
|
+
if match(child):
|
|
58
|
+
tree[key] = replacement
|
|
59
|
+
count += 1
|
|
60
|
+
else:
|
|
61
|
+
count += _replace(child, match, replacement)
|
|
62
|
+
return count
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""Minecraft version parsing and comparison."""
|
|
2
|
+
|
|
3
|
+
from functools import total_ordering
|
|
4
|
+
|
|
5
|
+
__all__ = ["Version", "VersionLike", "parse_version"]
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@total_ordering
|
|
9
|
+
class Version:
|
|
10
|
+
"""A release version like `1.21.9` or `26.3`, comparable with strings.
|
|
11
|
+
|
|
12
|
+
>>> Version("26.3") >= "26.3"
|
|
13
|
+
True
|
|
14
|
+
>>> Version("1.20.5") < Version("1.21")
|
|
15
|
+
True
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
__slots__ = ("parts",)
|
|
19
|
+
|
|
20
|
+
def __init__(self, version: VersionLike):
|
|
21
|
+
if isinstance(version, Version):
|
|
22
|
+
self.parts: tuple[int, ...] = version.parts
|
|
23
|
+
return
|
|
24
|
+
try:
|
|
25
|
+
parts = tuple(int(part) for part in version.split("."))
|
|
26
|
+
except ValueError:
|
|
27
|
+
raise ValueError(f"Invalid release version {version!r}") from None
|
|
28
|
+
# Treat "1.21" and "1.21.0" as the same version.
|
|
29
|
+
while len(parts) > 1 and parts[-1] == 0:
|
|
30
|
+
parts = parts[:-1]
|
|
31
|
+
self.parts = parts
|
|
32
|
+
|
|
33
|
+
def __eq__(self, other: object) -> bool:
|
|
34
|
+
if isinstance(other, str):
|
|
35
|
+
try:
|
|
36
|
+
other = Version(other)
|
|
37
|
+
except ValueError:
|
|
38
|
+
return False
|
|
39
|
+
if isinstance(other, Version):
|
|
40
|
+
return self.parts == other.parts
|
|
41
|
+
return NotImplemented
|
|
42
|
+
|
|
43
|
+
def __lt__(self, other: VersionLike) -> bool:
|
|
44
|
+
return self.parts < Version(other).parts
|
|
45
|
+
|
|
46
|
+
def __hash__(self) -> int:
|
|
47
|
+
return hash(self.parts)
|
|
48
|
+
|
|
49
|
+
def __str__(self) -> str:
|
|
50
|
+
return ".".join(map(str, self.parts))
|
|
51
|
+
|
|
52
|
+
def __repr__(self) -> str:
|
|
53
|
+
return f"Version({str(self)!r})"
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
VersionLike = Version | str
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def parse_version(version: VersionLike) -> Version:
|
|
60
|
+
"""Parse a release version string like `1.20.5`."""
|
|
61
|
+
return Version(version)
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: beet-datapack-utils
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Python library that provides helper functions for Minecraft datapacks using beet.
|
|
5
|
+
Keywords: minecraft,datapack,beet,worldgen,utility
|
|
6
|
+
Author: Fabian Arndt
|
|
7
|
+
Author-email: Fabian Arndt <fabian.arndt96@proton.me>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
16
|
+
Classifier: Topic :: Games/Entertainment
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Requires-Dist: beet>=0.119.0
|
|
20
|
+
Requires-Python: >=3.14
|
|
21
|
+
Project-URL: Repository, https://github.com/Neluxx/beet-datapack-utils
|
|
22
|
+
Project-URL: Issues, https://github.com/Neluxx/beet-datapack-utils/issues
|
|
23
|
+
Project-URL: Changelog, https://github.com/Neluxx/beet-datapack-utils/blob/main/CHANGELOG.md
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# beet-datapack-utils
|
|
27
|
+
|
|
28
|
+
A Python library with helpers for building multi-version Minecraft datapacks with [beet](https://github.com/mcbeet/beet).
|
|
29
|
+
|
|
30
|
+
Minecraft changes the datapack format regularly: folders are renamed, fields move or disappear. To support several Minecraft versions from one build, you need a base pack plus one overlay per version, and each of them needs its own patched copy of every vanilla file you change.
|
|
31
|
+
|
|
32
|
+
This library does that work for you. For the base pack and every overlay, it copies the matching vanilla file, smooths over the format differences and writes the patched file back. Your plugin only describes *what* to change.
|
|
33
|
+
|
|
34
|
+
## Features
|
|
35
|
+
|
|
36
|
+
- **One plugin for all versions:** loop over the base pack and all overlays with `Targets`.
|
|
37
|
+
- **Vanilla patching:** copy, edit and write a vanilla file in a single `with` block. Each vanilla version is downloaded once, and only when needed.
|
|
38
|
+
- **Version differences:** helpers for moved registries and renamed or restructured fields.
|
|
39
|
+
- **Safe density function edits:** search and replace nodes in JSON trees, and fail the build if the vanilla structure has changed.
|
|
40
|
+
|
|
41
|
+
## Quick start
|
|
42
|
+
|
|
43
|
+
**Requirements:** Python 3.14 or newer and a package manager. [uv](https://docs.astral.sh/uv/) is recommended.
|
|
44
|
+
|
|
45
|
+
**1. Install** the package in your datapack project:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
uv add beet-datapack-utils
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**2. Configure `beet.yml`.** Set the Minecraft version of the base pack and of each overlay:
|
|
52
|
+
|
|
53
|
+
```yaml
|
|
54
|
+
pipeline:
|
|
55
|
+
- src.plugins.canyon
|
|
56
|
+
|
|
57
|
+
meta:
|
|
58
|
+
base_version: "1.21.9"
|
|
59
|
+
overlay_versions:
|
|
60
|
+
v26_3: "26.3"
|
|
61
|
+
|
|
62
|
+
data_pack:
|
|
63
|
+
min_format: 88 # 1.21.9
|
|
64
|
+
max_format: 121 # 26.3
|
|
65
|
+
overlays:
|
|
66
|
+
- directory: v26_3
|
|
67
|
+
min_format: 121
|
|
68
|
+
max_format: 121
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**3. Write a plugin** in e.g. `src/plugins/canyon.py`:
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from beet import Context
|
|
75
|
+
|
|
76
|
+
from beet_datapack_utils import CARVER, Targets, worldgen_config
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def beet_default(ctx: Context):
|
|
80
|
+
for target in ctx.inject(Targets):
|
|
81
|
+
with target.patch(CARVER, "minecraft:canyon") as carver:
|
|
82
|
+
worldgen_config(carver)["probability"] = 0
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
**4. Build** the datapack:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
uv run beet build
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
This one plugin disables canyons in every version. Before 26.3 the file is `worldgen/configured_carver/canyon.json` and has a `config` object. From 26.3 on it is `worldgen/carver/canyon.json` and has no `config` object.
|
|
92
|
+
|
|
93
|
+
## Documentation
|
|
94
|
+
|
|
95
|
+
| Guide | Contents |
|
|
96
|
+
| --- | --- |
|
|
97
|
+
| [Installation](https://github.com/Neluxx/beet-datapack-utils/blob/main/docs/INSTALLATION.md) | Requirements, installing, building and updating |
|
|
98
|
+
| [Usage](https://github.com/Neluxx/beet-datapack-utils/blob/main/docs/USAGE.md) | Configuring `beet.yml` and an overview of all helpers |
|
|
99
|
+
| [Development](https://github.com/Neluxx/beet-datapack-utils/blob/main/docs/DEVELOPMENT.md) | Setup, tests, conventions and releasing |
|
|
100
|
+
| [Changelog](https://github.com/Neluxx/beet-datapack-utils/blob/main/CHANGELOG.md) | Changes in each release |
|
|
101
|
+
|
|
102
|
+
## License
|
|
103
|
+
|
|
104
|
+
[MIT](https://github.com/Neluxx/beet-datapack-utils/blob/main/LICENSE)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
beet_datapack_utils/__init__.py,sha256=vSUGJ_Ezl7s7KS7OukhNh3TCv8xrV4BjX7QC3fS8B7Y,1084
|
|
2
|
+
beet_datapack_utils/density.py,sha256=tsBI4eedFQGQfe8FFfR2c_ytiSn4Q2erjIo0F5zNRc0,1117
|
|
3
|
+
beet_datapack_utils/fields.py,sha256=3ZLVdVEsKEa9rM17nnJmXsoZUgEje06YMOdbTL8wER0,2254
|
|
4
|
+
beet_datapack_utils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
beet_datapack_utils/registries.py,sha256=nDy2H4meJk03hLxE457KWqW11GMIcq-5PvAcvIoYsnU,1738
|
|
6
|
+
beet_datapack_utils/targets.py,sha256=MlVapTev_5EfZL8IEn9mxXrELO7880QhpwfG4gcJg0g,4690
|
|
7
|
+
beet_datapack_utils/trees.py,sha256=r_mF7p00nJ432OWet-Ty-3Yz5K-EzOR3bHoL3pvAfyE,1867
|
|
8
|
+
beet_datapack_utils/versions.py,sha256=T4XLRjhBvPsUfJT_jyPMxbyaqIYKMFiVuOcdQYjRk4Y,1689
|
|
9
|
+
beet_datapack_utils-0.1.0.dist-info/licenses/LICENSE,sha256=Ju9GskhKBEW1WXbTFmhbjrLm-6Rodq1-BagGMyl9bvE,1069
|
|
10
|
+
beet_datapack_utils-0.1.0.dist-info/WHEEL,sha256=G_-rrEibZr7OEM7zdH1dSO6s-VdjfnS5PA4CLAdI9Vw,80
|
|
11
|
+
beet_datapack_utils-0.1.0.dist-info/METADATA,sha256=Lil1ByXAQ0ckCWO2SMdNztDKOB3tdmNes0xz01_TCbI,4107
|
|
12
|
+
beet_datapack_utils-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Fabian Arndt
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|