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 diff --git a/beet_observer/data_pack.py b/beet_observer/data_pack.py index 27c030e..6fe9160 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,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: diff --git a/demo_pack/data/demo/dimension/foo.json b/demo_pack/data/demo/dimension/foo.json new file mode 100644 index 0000000..f799058 --- /dev/null +++ b/demo_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/demo_pack/overlay_48/data/demo/dimension/demo.json b/demo_pack/overlay_48/data/demo/dimension/demo.json new file mode 100644 index 0000000..f37f174 --- /dev/null +++ b/demo_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/demo_pack/pack.mcmeta b/demo_pack/pack.mcmeta new file mode 100644 index 0000000..8a457b0 --- /dev/null +++ b/demo_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_nosnap/beet.yaml b/examples/overlay_adds_dimension1_nosnap/beet.yaml new file mode 100644 index 0000000..41b69cb --- /dev/null +++ b/examples/overlay_adds_dimension1_nosnap/beet.yaml @@ -0,0 +1,12 @@ +data_pack: + load: src + pack_format: 57 + supported_formats: [48,57] + +pipeline: + - beet_observer + +meta: + observer: + overlays: + - process: proc diff --git a/examples/overlay_adds_dimension1_nosnap/proc/data/demo/dimension/demo.json b/examples/overlay_adds_dimension1_nosnap/proc/data/demo/dimension/demo.json new file mode 100644 index 0000000..f37f174 --- /dev/null +++ b/examples/overlay_adds_dimension1_nosnap/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_nosnap/proc/data/demo/dimension/foo.json b/examples/overlay_adds_dimension1_nosnap/proc/data/demo/dimension/foo.json new file mode 100644 index 0000000..f799058 --- /dev/null +++ b/examples/overlay_adds_dimension1_nosnap/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_nosnap/proc/pack.mcmeta b/examples/overlay_adds_dimension1_nosnap/proc/pack.mcmeta new file mode 100644 index 0000000..8b4f4d2 --- /dev/null +++ b/examples/overlay_adds_dimension1_nosnap/proc/pack.mcmeta @@ -0,0 +1,6 @@ +{ + "pack": { + "pack_format": 48, + "description": "" + } +} diff --git a/examples/overlay_adds_dimension1_nosnap/src/data/demo/dimension/foo.json b/examples/overlay_adds_dimension1_nosnap/src/data/demo/dimension/foo.json new file mode 100644 index 0000000..f799058 --- /dev/null +++ b/examples/overlay_adds_dimension1_nosnap/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/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/test_examples.py b/tests/test_examples.py index f8227e3..6488767 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.endswith("_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