Skip to content

Commit

Permalink
feat: add worldgen support (#1)
Browse files Browse the repository at this point in the history
* worldgen

* don't test worldgen

- tests with worldgen files are broken in lectern snapshots: mcbeet/lectern#361

* Update TODO.md
  • Loading branch information
BPR02 authored Nov 24, 2024
1 parent b2674ea commit ef2ec84
Show file tree
Hide file tree
Showing 16 changed files with 167 additions and 7 deletions.
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## TODO:
- add worldgen support
- merge nested overlays (overlays in the target pack)
- create more tests
- allow separate dp and rp default formats
- restore worldgen tests once [lectern #361](https://github.com/mcbeet/lectern/issues/361) is fixed
68 changes: 64 additions & 4 deletions beet_observer/data_pack.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Any

import beet.contrib.worldgen as wg
from beet import Context, NamespaceProxy


Expand Down Expand Up @@ -48,6 +49,60 @@ def gen_dp_overlays(ctx: Context, ctx_overlay: Context, overlay_dir: str) -> Non
ctx.data.point_of_interest_type_tags,
ctx_overlay.data.point_of_interest_type_tags,
),
(ctx.data[wg.Dimension], ctx_overlay.data[wg.Dimension]),
(ctx.data[wg.DimensionType], ctx_overlay.data[wg.DimensionType]),
(ctx.data[wg.WorldgenBiome], ctx_overlay.data[wg.WorldgenBiome]),
(
ctx.data[wg.WorldgenConfiguredCarver],
ctx_overlay.data[wg.WorldgenConfiguredCarver],
),
(
ctx.data[wg.WorldgenConfiguredFeature],
ctx_overlay.data[wg.WorldgenConfiguredFeature],
),
(
ctx.data[wg.WorldgenDensityFunction],
ctx_overlay.data[wg.WorldgenDensityFunction],
),
(ctx.data[wg.WorldgenNoise], ctx_overlay.data[wg.WorldgenNoise]),
(
ctx.data[wg.WorldgenNoiseSettings],
ctx_overlay.data[wg.WorldgenNoiseSettings],
),
(
ctx.data[wg.WorldgenPlacedFeature],
ctx_overlay.data[wg.WorldgenPlacedFeature],
),
(
ctx.data[wg.WorldgenProcessorList],
ctx_overlay.data[wg.WorldgenProcessorList],
),
(ctx.data[wg.WorldgenStructure], ctx_overlay.data[wg.WorldgenStructure]),
(ctx.data[wg.WorldgenStructureSet], ctx_overlay.data[wg.WorldgenStructureSet]),
(
ctx.data[wg.WorldgenConfiguredSurfaceBuilder],
ctx_overlay.data[wg.WorldgenConfiguredSurfaceBuilder],
),
(ctx.data[wg.WorldgenTemplatePool], ctx_overlay.data[wg.WorldgenTemplatePool]),
(ctx.data[wg.WorldgenWorldPreset], ctx_overlay.data[wg.WorldgenWorldPreset]),
(
ctx.data[wg.WorldgenFlatLevelGeneratorPreset],
ctx_overlay.data[wg.WorldgenFlatLevelGeneratorPreset],
),
(ctx.data[wg.WorldgenBiomeTag], ctx_overlay.data[wg.WorldgenBiomeTag]),
(
ctx.data[wg.WorldgenStructureSetTag],
ctx_overlay.data[wg.WorldgenStructureSetTag],
),
(ctx.data[wg.WorldgenStructureTag], ctx_overlay.data[wg.WorldgenStructureTag]),
(
ctx.data[wg.WorldgenConfiguredCarverTag],
ctx_overlay.data[wg.WorldgenConfiguredCarverTag],
),
(
ctx.data[wg.WorldgenPlacedFeatureTag],
ctx_overlay.data[wg.WorldgenPlacedFeatureTag],
),
]
# for each file type, check for required overlays
for registry, registry_overlay in file_types:
Expand Down Expand Up @@ -155,13 +210,18 @@ def gen_registry_overlay(
ctx.data.overlays[default_dir][name] = registry[name]
del registry[name]
elif type == "addition":
# move function from overlay pack to overlay in build pack
# move file from overlay pack to overlay in build pack
ctx.data.overlays[overlay_dir][name] = registry_overlay[name]
else:
# check if files are exactly the same
if registry[name] != registry_overlay[name]:
# move function from overlay pack to overlay in build pack
ctx.data.overlays[overlay_dir][name] = registry_overlay[name]
try:
if registry[name].data != registry_overlay[name].data:
# move file from overlay pack to overlay in build pack
ctx.data.overlays[overlay_dir][name] = registry_overlay[name]
except AttributeError:
if registry[name] != registry_overlay[name]:
# move file from overlay pack to overlay in build pack
ctx.data.overlays[overlay_dir][name] = registry_overlay[name]

# remove file from overlay pack
if name in registry_overlay:
Expand Down
6 changes: 6 additions & 0 deletions demo_pack/data/demo/dimension/foo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "demo:this-is-the-same-in-both",
"generator": {
"type": "minecraft:debug"
}
}
6 changes: 6 additions & 0 deletions demo_pack/overlay_48/data/demo/dimension/demo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "demo:this-only-exists-in-the-overlay",
"generator": {
"type": "minecraft:debug"
}
}
18 changes: 18 additions & 0 deletions demo_pack/pack.mcmeta
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"pack": {
"pack_format": 57,
"description": "",
"supported_formats": [
48,
57
]
},
"overlays": {
"entries": [
{
"formats": 48,
"directory": "overlay_48"
}
]
}
}
12 changes: 12 additions & 0 deletions examples/overlay_adds_dimension1_nosnap/beet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
data_pack:
load: src
pack_format: 57
supported_formats: [48,57]

pipeline:
- beet_observer

meta:
observer:
overlays:
- process: proc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "demo:this-only-exists-in-the-overlay",
"generator": {
"type": "minecraft:debug"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "demo:this-is-the-same-in-both",
"generator": {
"type": "minecraft:debug"
}
}
6 changes: 6 additions & 0 deletions examples/overlay_adds_dimension1_nosnap/proc/pack.mcmeta
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"pack": {
"pack_format": 48,
"description": ""
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "demo:this-is-the-same-in-both",
"generator": {
"type": "minecraft:debug"
}
}
2 changes: 2 additions & 0 deletions examples/sanity_test_worldgen_nosnap/beet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
data_pack:
load: src
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "demo:in-the-base-pack",
"generator": {
"type": "minecraft:debug"
}
}
7 changes: 7 additions & 0 deletions examples/sanity_test_worldgen_overlay_nosnap/beet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
data_pack:
load: src
overlays:
- formats:
min_inclusive: 48
max_inclusive: 48
directory: overlay_48
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "demo:in-the-base-pack",
"generator": {
"type": "minecraft:debug"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "demo:in-the-overlay-pack",
"generator": {
"type": "minecraft:debug"
}
}
11 changes: 9 additions & 2 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@
from lectern import Document
from pytest_insta import SnapshotFixture

EXAMPLES = [f for f in os.listdir("examples") if not (f.startswith("nosnap_") or f.startswith("."))]
EXAMPLES = [
f
for f in os.listdir("examples")
if not (f.endswith("_nosnap") or f.startswith("."))
]


@pytest.mark.parametrize("directory", EXAMPLES)
def test_build(snapshot: SnapshotFixture, directory: str, tmp_path: Path):
with run_beet(
directory=f"examples/{directory}",
cache=ProjectCache(tmp_path / ".beet_cache", tmp_path / "generated"),
) as ctx:
assert snapshot("pack.md") == ctx.inject(Document)
expected: Document = snapshot("pack.md")
actual = ctx.inject(Document)
assert actual == expected

0 comments on commit ef2ec84

Please sign in to comment.