From bd00c7fa226654d2505a1e28af535d9baf15d19d Mon Sep 17 00:00:00 2001 From: BPR02 Date: Fri, 22 Nov 2024 19:39:14 -0800 Subject: [PATCH 1/3] worldgen --- beet_observer/data_pack.py | 69 +++++++++++++++++-- examples/overlay_adds_dimension1/beet.yaml | 15 ++++ .../data/demo/dimension/foo.json | 6 ++ .../overlay_48/data/demo/dimension/demo.json | 6 ++ .../pack.mcmeta | 18 +++++ .../proc/data/demo/dimension/demo.json | 6 ++ .../proc/data/demo/dimension/foo.json | 6 ++ .../overlay_adds_dimension1/proc/pack.mcmeta | 6 ++ .../src/data/demo/dimension/foo.json | 6 ++ ...__build_overlay_adds_dimension1__0.pack.md | 58 ++++++++++++++++ tests/test_examples.py | 11 ++- 11 files changed, 201 insertions(+), 6 deletions(-) create mode 100644 examples/overlay_adds_dimension1/beet.yaml create mode 100644 examples/overlay_adds_dimension1/out/overlay_adds_dimension1_data_pack/data/demo/dimension/foo.json create mode 100644 examples/overlay_adds_dimension1/out/overlay_adds_dimension1_data_pack/overlay_48/data/demo/dimension/demo.json create mode 100644 examples/overlay_adds_dimension1/out/overlay_adds_dimension1_data_pack/pack.mcmeta create mode 100644 examples/overlay_adds_dimension1/proc/data/demo/dimension/demo.json create mode 100644 examples/overlay_adds_dimension1/proc/data/demo/dimension/foo.json create mode 100644 examples/overlay_adds_dimension1/proc/pack.mcmeta create mode 100644 examples/overlay_adds_dimension1/src/data/demo/dimension/foo.json create mode 100644 tests/snapshots/examples__build_overlay_adds_dimension1__0.pack.md diff --git a/beet_observer/data_pack.py b/beet_observer/data_pack.py index 27c030e..33e50c8 100644 --- a/beet_observer/data_pack.py +++ b/beet_observer/data_pack.py @@ -1,5 +1,6 @@ from typing import Any +import beet.contrib.worldgen as wg from beet import Context, NamespaceProxy @@ -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: @@ -155,13 +210,19 @@ 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]: + print(registry[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: diff --git a/examples/overlay_adds_dimension1/beet.yaml b/examples/overlay_adds_dimension1/beet.yaml new file mode 100644 index 0000000..17b65b3 --- /dev/null +++ b/examples/overlay_adds_dimension1/beet.yaml @@ -0,0 +1,15 @@ +data_pack: + load: src + pack_format: 57 + supported_formats: [48,57] + +pipeline: + - beet_observer + +meta: + observer: + overlays: + - process: proc + +output: + out diff --git a/examples/overlay_adds_dimension1/out/overlay_adds_dimension1_data_pack/data/demo/dimension/foo.json b/examples/overlay_adds_dimension1/out/overlay_adds_dimension1_data_pack/data/demo/dimension/foo.json new file mode 100644 index 0000000..f799058 --- /dev/null +++ b/examples/overlay_adds_dimension1/out/overlay_adds_dimension1_data_pack/data/demo/dimension/foo.json @@ -0,0 +1,6 @@ +{ + "type": "demo:this-is-the-same-in-both", + "generator": { + "type": "minecraft:debug" + } +} diff --git a/examples/overlay_adds_dimension1/out/overlay_adds_dimension1_data_pack/overlay_48/data/demo/dimension/demo.json b/examples/overlay_adds_dimension1/out/overlay_adds_dimension1_data_pack/overlay_48/data/demo/dimension/demo.json new file mode 100644 index 0000000..f37f174 --- /dev/null +++ b/examples/overlay_adds_dimension1/out/overlay_adds_dimension1_data_pack/overlay_48/data/demo/dimension/demo.json @@ -0,0 +1,6 @@ +{ + "type": "demo:this-only-exists-in-the-overlay", + "generator": { + "type": "minecraft:debug" + } +} diff --git a/examples/overlay_adds_dimension1/out/overlay_adds_dimension1_data_pack/pack.mcmeta b/examples/overlay_adds_dimension1/out/overlay_adds_dimension1_data_pack/pack.mcmeta new file mode 100644 index 0000000..8a457b0 --- /dev/null +++ b/examples/overlay_adds_dimension1/out/overlay_adds_dimension1_data_pack/pack.mcmeta @@ -0,0 +1,18 @@ +{ + "pack": { + "pack_format": 57, + "description": "", + "supported_formats": [ + 48, + 57 + ] + }, + "overlays": { + "entries": [ + { + "formats": 48, + "directory": "overlay_48" + } + ] + } +} diff --git a/examples/overlay_adds_dimension1/proc/data/demo/dimension/demo.json b/examples/overlay_adds_dimension1/proc/data/demo/dimension/demo.json new file mode 100644 index 0000000..f37f174 --- /dev/null +++ b/examples/overlay_adds_dimension1/proc/data/demo/dimension/demo.json @@ -0,0 +1,6 @@ +{ + "type": "demo:this-only-exists-in-the-overlay", + "generator": { + "type": "minecraft:debug" + } +} diff --git a/examples/overlay_adds_dimension1/proc/data/demo/dimension/foo.json b/examples/overlay_adds_dimension1/proc/data/demo/dimension/foo.json new file mode 100644 index 0000000..f799058 --- /dev/null +++ b/examples/overlay_adds_dimension1/proc/data/demo/dimension/foo.json @@ -0,0 +1,6 @@ +{ + "type": "demo:this-is-the-same-in-both", + "generator": { + "type": "minecraft:debug" + } +} diff --git a/examples/overlay_adds_dimension1/proc/pack.mcmeta b/examples/overlay_adds_dimension1/proc/pack.mcmeta new file mode 100644 index 0000000..8b4f4d2 --- /dev/null +++ b/examples/overlay_adds_dimension1/proc/pack.mcmeta @@ -0,0 +1,6 @@ +{ + "pack": { + "pack_format": 48, + "description": "" + } +} diff --git a/examples/overlay_adds_dimension1/src/data/demo/dimension/foo.json b/examples/overlay_adds_dimension1/src/data/demo/dimension/foo.json new file mode 100644 index 0000000..f799058 --- /dev/null +++ b/examples/overlay_adds_dimension1/src/data/demo/dimension/foo.json @@ -0,0 +1,6 @@ +{ + "type": "demo:this-is-the-same-in-both", + "generator": { + "type": "minecraft:debug" + } +} diff --git a/tests/snapshots/examples__build_overlay_adds_dimension1__0.pack.md b/tests/snapshots/examples__build_overlay_adds_dimension1__0.pack.md new file mode 100644 index 0000000..9c2cbe8 --- /dev/null +++ b/tests/snapshots/examples__build_overlay_adds_dimension1__0.pack.md @@ -0,0 +1,58 @@ +# Lectern snapshot + +## Data pack + +`@data_pack pack.mcmeta` + +```json +{ + "pack": { + "pack_format": 57, + "description": "", + "supported_formats": [ + 48, + 57 + ] + }, + "overlays": { + "entries": [ + { + "formats": 48, + "directory": "overlay_48" + } + ] + } +} +``` + +### demo + +`@dimension demo:foo` + +```json +{ + "type": "demo:this-is-the-same-in-both", + "generator": { + "type": "minecraft:debug" + } +} +``` + +## Overlay `overlay_48` + +`@overlay overlay_48` + +### demo + +`@dimension demo:demo` + +```json +{ + "type": "demo:this-only-exists-in-the-overlay", + "generator": { + "type": "minecraft:debug" + } +} +``` + +`@endoverlay` diff --git a/tests/test_examples.py b/tests/test_examples.py index f8227e3..c65c696 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -6,7 +6,12 @@ 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.startswith("nosnap_") or f.startswith(".")) +] + @pytest.mark.parametrize("directory", EXAMPLES) def test_build(snapshot: SnapshotFixture, directory: str, tmp_path: Path): @@ -14,4 +19,6 @@ def test_build(snapshot: SnapshotFixture, directory: str, tmp_path: Path): 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 From e1132cb97f46248da5c401ccd558f6d733cd4ce2 Mon Sep 17 00:00:00 2001 From: BPR02 Date: Sun, 24 Nov 2024 10:35:01 -0800 Subject: [PATCH 2/3] don't test worldgen - tests with worldgen files are broken in lectern snapshots: https://github.com/mcbeet/lectern/issues/361 --- beet_observer/data_pack.py | 1 - .../data/demo/dimension/foo.json | 0 .../overlay_48/data/demo/dimension/demo.json | 0 .../pack.mcmeta | 0 .../beet.yaml | 3 - .../proc/data/demo/dimension/demo.json | 0 .../proc/data/demo/dimension/foo.json | 0 .../proc/pack.mcmeta | 0 .../src/data/demo/dimension/foo.json | 0 .../sanity_test_worldgen_nosnap/beet.yaml | 2 + .../src/data/demo/dimension/demo.json | 6 ++ .../beet.yaml | 7 +++ .../src/data/demo/dimension/demo.json | 6 ++ .../overlay_48/data/demo/dimension/demo.json | 6 ++ ...__build_overlay_adds_dimension1__0.pack.md | 58 ------------------- tests/test_examples.py | 2 +- 16 files changed, 28 insertions(+), 63 deletions(-) rename {examples/overlay_adds_dimension1/out/overlay_adds_dimension1_data_pack => demo_pack}/data/demo/dimension/foo.json (100%) rename {examples/overlay_adds_dimension1/out/overlay_adds_dimension1_data_pack => demo_pack}/overlay_48/data/demo/dimension/demo.json (100%) rename {examples/overlay_adds_dimension1/out/overlay_adds_dimension1_data_pack => demo_pack}/pack.mcmeta (100%) rename examples/{overlay_adds_dimension1 => overlay_adds_dimension1_nosnap}/beet.yaml (91%) rename examples/{overlay_adds_dimension1 => overlay_adds_dimension1_nosnap}/proc/data/demo/dimension/demo.json (100%) rename examples/{overlay_adds_dimension1 => overlay_adds_dimension1_nosnap}/proc/data/demo/dimension/foo.json (100%) rename examples/{overlay_adds_dimension1 => overlay_adds_dimension1_nosnap}/proc/pack.mcmeta (100%) rename examples/{overlay_adds_dimension1 => overlay_adds_dimension1_nosnap}/src/data/demo/dimension/foo.json (100%) create mode 100644 examples/sanity_test_worldgen_nosnap/beet.yaml create mode 100644 examples/sanity_test_worldgen_nosnap/src/data/demo/dimension/demo.json create mode 100644 examples/sanity_test_worldgen_overlay_nosnap/beet.yaml create mode 100644 examples/sanity_test_worldgen_overlay_nosnap/src/data/demo/dimension/demo.json create mode 100644 examples/sanity_test_worldgen_overlay_nosnap/src/overlay_48/data/demo/dimension/demo.json delete mode 100644 tests/snapshots/examples__build_overlay_adds_dimension1__0.pack.md diff --git a/beet_observer/data_pack.py b/beet_observer/data_pack.py index 33e50c8..6fe9160 100644 --- a/beet_observer/data_pack.py +++ b/beet_observer/data_pack.py @@ -220,7 +220,6 @@ def gen_registry_overlay( ctx.data.overlays[overlay_dir][name] = registry_overlay[name] except AttributeError: if registry[name] != registry_overlay[name]: - print(registry[name]) # move file from overlay pack to overlay in build pack ctx.data.overlays[overlay_dir][name] = registry_overlay[name] diff --git a/examples/overlay_adds_dimension1/out/overlay_adds_dimension1_data_pack/data/demo/dimension/foo.json b/demo_pack/data/demo/dimension/foo.json similarity index 100% rename from examples/overlay_adds_dimension1/out/overlay_adds_dimension1_data_pack/data/demo/dimension/foo.json rename to demo_pack/data/demo/dimension/foo.json diff --git a/examples/overlay_adds_dimension1/out/overlay_adds_dimension1_data_pack/overlay_48/data/demo/dimension/demo.json b/demo_pack/overlay_48/data/demo/dimension/demo.json similarity index 100% rename from examples/overlay_adds_dimension1/out/overlay_adds_dimension1_data_pack/overlay_48/data/demo/dimension/demo.json rename to demo_pack/overlay_48/data/demo/dimension/demo.json diff --git a/examples/overlay_adds_dimension1/out/overlay_adds_dimension1_data_pack/pack.mcmeta b/demo_pack/pack.mcmeta similarity index 100% rename from examples/overlay_adds_dimension1/out/overlay_adds_dimension1_data_pack/pack.mcmeta rename to demo_pack/pack.mcmeta diff --git a/examples/overlay_adds_dimension1/beet.yaml b/examples/overlay_adds_dimension1_nosnap/beet.yaml similarity index 91% rename from examples/overlay_adds_dimension1/beet.yaml rename to examples/overlay_adds_dimension1_nosnap/beet.yaml index 17b65b3..41b69cb 100644 --- a/examples/overlay_adds_dimension1/beet.yaml +++ b/examples/overlay_adds_dimension1_nosnap/beet.yaml @@ -10,6 +10,3 @@ meta: observer: overlays: - process: proc - -output: - out diff --git a/examples/overlay_adds_dimension1/proc/data/demo/dimension/demo.json b/examples/overlay_adds_dimension1_nosnap/proc/data/demo/dimension/demo.json similarity index 100% rename from examples/overlay_adds_dimension1/proc/data/demo/dimension/demo.json rename to examples/overlay_adds_dimension1_nosnap/proc/data/demo/dimension/demo.json diff --git a/examples/overlay_adds_dimension1/proc/data/demo/dimension/foo.json b/examples/overlay_adds_dimension1_nosnap/proc/data/demo/dimension/foo.json similarity index 100% rename from examples/overlay_adds_dimension1/proc/data/demo/dimension/foo.json rename to examples/overlay_adds_dimension1_nosnap/proc/data/demo/dimension/foo.json diff --git a/examples/overlay_adds_dimension1/proc/pack.mcmeta b/examples/overlay_adds_dimension1_nosnap/proc/pack.mcmeta similarity index 100% rename from examples/overlay_adds_dimension1/proc/pack.mcmeta rename to examples/overlay_adds_dimension1_nosnap/proc/pack.mcmeta diff --git a/examples/overlay_adds_dimension1/src/data/demo/dimension/foo.json b/examples/overlay_adds_dimension1_nosnap/src/data/demo/dimension/foo.json similarity index 100% rename from examples/overlay_adds_dimension1/src/data/demo/dimension/foo.json rename to examples/overlay_adds_dimension1_nosnap/src/data/demo/dimension/foo.json diff --git a/examples/sanity_test_worldgen_nosnap/beet.yaml b/examples/sanity_test_worldgen_nosnap/beet.yaml new file mode 100644 index 0000000..e0864c2 --- /dev/null +++ b/examples/sanity_test_worldgen_nosnap/beet.yaml @@ -0,0 +1,2 @@ +data_pack: + load: src diff --git a/examples/sanity_test_worldgen_nosnap/src/data/demo/dimension/demo.json b/examples/sanity_test_worldgen_nosnap/src/data/demo/dimension/demo.json new file mode 100644 index 0000000..4322496 --- /dev/null +++ b/examples/sanity_test_worldgen_nosnap/src/data/demo/dimension/demo.json @@ -0,0 +1,6 @@ +{ + "type": "demo:in-the-base-pack", + "generator": { + "type": "minecraft:debug" + } +} diff --git a/examples/sanity_test_worldgen_overlay_nosnap/beet.yaml b/examples/sanity_test_worldgen_overlay_nosnap/beet.yaml new file mode 100644 index 0000000..f086b29 --- /dev/null +++ b/examples/sanity_test_worldgen_overlay_nosnap/beet.yaml @@ -0,0 +1,7 @@ +data_pack: + load: src + overlays: + - formats: + min_inclusive: 48 + max_inclusive: 48 + directory: overlay_48 diff --git a/examples/sanity_test_worldgen_overlay_nosnap/src/data/demo/dimension/demo.json b/examples/sanity_test_worldgen_overlay_nosnap/src/data/demo/dimension/demo.json new file mode 100644 index 0000000..4322496 --- /dev/null +++ b/examples/sanity_test_worldgen_overlay_nosnap/src/data/demo/dimension/demo.json @@ -0,0 +1,6 @@ +{ + "type": "demo:in-the-base-pack", + "generator": { + "type": "minecraft:debug" + } +} diff --git a/examples/sanity_test_worldgen_overlay_nosnap/src/overlay_48/data/demo/dimension/demo.json b/examples/sanity_test_worldgen_overlay_nosnap/src/overlay_48/data/demo/dimension/demo.json new file mode 100644 index 0000000..dc83117 --- /dev/null +++ b/examples/sanity_test_worldgen_overlay_nosnap/src/overlay_48/data/demo/dimension/demo.json @@ -0,0 +1,6 @@ +{ + "type": "demo:in-the-overlay-pack", + "generator": { + "type": "minecraft:debug" + } +} diff --git a/tests/snapshots/examples__build_overlay_adds_dimension1__0.pack.md b/tests/snapshots/examples__build_overlay_adds_dimension1__0.pack.md deleted file mode 100644 index 9c2cbe8..0000000 --- a/tests/snapshots/examples__build_overlay_adds_dimension1__0.pack.md +++ /dev/null @@ -1,58 +0,0 @@ -# Lectern snapshot - -## Data pack - -`@data_pack pack.mcmeta` - -```json -{ - "pack": { - "pack_format": 57, - "description": "", - "supported_formats": [ - 48, - 57 - ] - }, - "overlays": { - "entries": [ - { - "formats": 48, - "directory": "overlay_48" - } - ] - } -} -``` - -### demo - -`@dimension demo:foo` - -```json -{ - "type": "demo:this-is-the-same-in-both", - "generator": { - "type": "minecraft:debug" - } -} -``` - -## Overlay `overlay_48` - -`@overlay overlay_48` - -### demo - -`@dimension demo:demo` - -```json -{ - "type": "demo:this-only-exists-in-the-overlay", - "generator": { - "type": "minecraft:debug" - } -} -``` - -`@endoverlay` diff --git a/tests/test_examples.py b/tests/test_examples.py index c65c696..6488767 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -9,7 +9,7 @@ EXAMPLES = [ f for f in os.listdir("examples") - if not (f.startswith("nosnap_") or f.startswith(".")) + if not (f.endswith("_nosnap") or f.startswith(".")) ] From 85d511d322bc31981e3d19735ef286d53c041a34 Mon Sep 17 00:00:00 2001 From: BPR02 Date: Sun, 24 Nov 2024 10:36:57 -0800 Subject: [PATCH 3/3] Update TODO.md --- TODO.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TODO.md b/TODO.md index 98a1731..fcb75a8 100644 --- a/TODO.md +++ b/TODO.md @@ -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