From c302d8c2b1272c04ec6766a009d1866b3191eb67 Mon Sep 17 00:00:00 2001 From: Andrea D'Amico Date: Tue, 27 Oct 2026 12:57:25 +0100 Subject: [PATCH 1/7] feat(plugin): let a pillar add optional entries to another pillar's tag A Touch Of's Pillars are now atouchofdarkness, atouchofmadness and atouchofwickedness. atouchofcold is shelved in favour of Tough As Nails, and retired, so none may name it (5thlayer/atouchof#5, #6). checkPlaysAlone lets a Pillar ship data//tags/** files whose replace is absent or false and whose every entry is an optional entry naming one of its own ids, as A Touch Of ADR-0002 now allows. Any other file under that namespace still fails, and the failure says why. FactoryWorks gets no such exception. ADR 0014 records the decision. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + ...has-its-own-module-list-found-by-mod-id.md | 4 ++ ...optional-entries-to-another-pillars-tag.md | 29 ++++++++ docs/plugin.md | 2 +- .../libworks/plugin/PlaysAlone.groovy | 64 ++++++++++++++--- .../libworks/plugin/ModulePluginTest.java | 14 +++- .../libworks/plugin/PlaysAloneTest.java | 69 ++++++++++++++++--- 7 files changed, 163 insertions(+), 20 deletions(-) create mode 100644 docs/adr/0014-a-pillar-may-add-optional-entries-to-another-pillars-tag.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 5268ec3..9fbc76f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Written for Consumers: what a mod building against Example Module can use, or wi ## Unreleased +- `libworks-plugin` 0.4.5: `checkPlaysAlone` knows A Touch Of's Pillars as `atouchofdarkness`, `atouchofmadness` and `atouchofwickedness`. The shelved `atouchofcold` is retired, so no Pillar or FactoryWorks Module may name it (A Touch Of #5, #6). A Pillar may add entries to another Pillar's tag with a file under `data//tags/` whose `replace` is absent or false and whose every entry is `{"id": "", "required": false}`. Any other file in that namespace still fails, and the failure says why (ADR 0014, A Touch Of ADR-0002). FactoryWorks Modules get no such exception. A Module edits nothing. - `libworks-plugin` 0.4.4: `checkPlaysAlone` also checks a Module against every other suite's Modules, bases included (ADR 0013): a Pillar may not name a FactoryWorks Module, Groundworks included, and a FactoryWorks Module may not name a Pillar or A Touch Of's Runtime, `atouchof`. 0.4.3 let a Pillar name a FactoryWorks Module and the reverse. A mod no suite lists is still checked against every suite's Modules but Groundworks and `atouchof`. A Module edits nothing: none names the other suite. - `libworks-plugin` 0.4.3: `checkPlaysAlone` checks a Module against its own suite's Modules, which its `mod_id` picks (ADR 0013). A Touch Of's Pillars, `atouchofcold`, `atouchofdarkness` and `atouchofmadness`, are checked against one another and may name their Runtime, `atouchof`, and no longer against FactoryWorks' Modules. A FactoryWorks Module's check is unchanged. A mod no suite lists is checked against every suite's Modules but Groundworks and `atouchof`. A Module edits nothing. - `libworks-runtime` 0.1.12: libworks-gametest's `GalleryCheck.MAX_SCENES` is 24, up from 16, so `builds` and `withPack` take a gallery of up to 24 scenes. diff --git a/docs/adr/0013-each-suite-has-its-own-module-list-found-by-mod-id.md b/docs/adr/0013-each-suite-has-its-own-module-list-found-by-mod-id.md index 45c5965..a05f6f7 100644 --- a/docs/adr/0013-each-suite-has-its-own-module-list-found-by-mod-id.md +++ b/docs/adr/0013-each-suite-has-its-own-module-list-found-by-mod-id.md @@ -32,3 +32,7 @@ template's own build would need an exception. **Amended 2026-10-25 (plugin 0.4.4).** Plugin 0.4.3 checked a Module only against its own suite, so a Pillar could name any FactoryWorks Module and a FactoryWorks Module any Pillar, which neither suite's rule allows. 0.4.4 adds every other suite's Modules, bases included, as above. + +**Amended 2026-10-27 (plugin 0.4.5, ADR 0014).** A Touch Of's Pillars are `atouchofdarkness`, `atouchofmadness` and +`atouchofwickedness` (A Touch Of #6). `atouchofcold` is shelved in favour of Tough As Nails (A Touch Of #5) and +retired, so none may name it. A Pillar may add optional entries to another Pillar's tag (ADR 0014). diff --git a/docs/adr/0014-a-pillar-may-add-optional-entries-to-another-pillars-tag.md b/docs/adr/0014-a-pillar-may-add-optional-entries-to-another-pillars-tag.md new file mode 100644 index 0000000..24e7ada --- /dev/null +++ b/docs/adr/0014-a-pillar-may-add-optional-entries-to-another-pillars-tag.md @@ -0,0 +1,29 @@ +--- +status: accepted +--- + +# A Pillar may add optional entries to another Pillar's tag + +A Touch Of ADR-0002, as amended by A Touch Of #6, lets one Pillar add an entry to another Pillar's +tag. It does this with a vanilla tag file that has `replace: false` and marks every entry +`required: false`. Without the other Pillar the tag is never read, so neither Pillar requires the +other. The first use is A Touch of Wickedness shipping +`data/atouchofmadness/tags/entity_type/unsettling.json`, which adds its Bailiff. `checkPlaysAlone` +(ADR 0005, ADR 0013) failed any `data/` folder in another Pillar's namespace, so that file failed. + +**Decision.** A suite may take optional tag entries. A Touch Of does and FactoryWorks does not, +since FactoryWorks ADR-0127 allows none. In such a suite, a Module other than the base may ship +files under another Module's `data//tags/`. Each must be a tag whose `replace` is absent or +false, and whose every entry is an object with `"required": false` naming one of the Module's own +ids or tags. The scan reads that namespace's data folder file by file. It reports each file outside +`tags/` and each file that is not a tag, and for a tag it names each bare or required entry, a +`replace: true` and each id that is not the Module's own. The exception does not cover an +`assets/` folder, the base, a retired id such as the shelved `atouchofcold`, or another +suite's namespace. + +**Considered.** Allowing any id an optional entry names, such as `minecraft:zombie`: a Pillar +could then retune another Pillar's tag with vanilla content, which goes further than ADR-0002's +"adds an entry" allows. The exception in every suite: FactoryWorks has not asked for it, and its +ADR-0127 forbids it. A list of allowed files in the plugin: narrower, but every new use would need +a plugin release. A Module declaring its tag files in `libworks { }`: every Module would carry a +line, and the plugin would still need the rule to check it. diff --git a/docs/plugin.md b/docs/plugin.md index 88b5de5..639f78d 100644 --- a/docs/plugin.md +++ b/docs/plugin.md @@ -31,7 +31,7 @@ The plugin adds a `gametest` source set to the mod, which the dev runs load and `buildGametestStructures` writes the default `gametest/platform.nbt` into `src/gametest/resources/data//structure/`, leaves an identical one alone, and fails naming the file when the Module has committed a different one: a Module needing another structure commits it (ADR 0003). -`checkPlaysAlone`, which `check` runs, fails when the Module ships something that names another Module of its suite (FactoryWorks ADR-0127, A Touch Of ADR-0002, ADR 0005, ADR 0013): an id in its namespace, such as `pipeworks:pipe`, in a resource or in Java source; an `assets/` or `data/` folder; the namespace as a string in Java source, `"pipeworks"`; or a required dependency on it in `neoforge.mods.toml`, where an optional one is allowed. A structure's `.nbt` is read unzipped, so the block ids saved in it count. The resources are read as `processResources` leaves them, so generated ones and the expanded mods.toml count; the code is `src/main`'s Java source, and the `gametest` source set is not read. The suites are `PlaysAlone.SUITES`, and the Module's suite is the one whose list holds its `mod_id`. FactoryWorks' Modules are Beltworks, Craftworks, Fieldworks, Gearworks, Groundworks, Pipeworks, Voidworks and Wireworks: every one but the Module built and Groundworks is forbidden, and the retired `factoryworks`. A Touch Of's are its Runtime, `atouchof`, and the Pillars `atouchofcold`, `atouchofdarkness` and `atouchofmadness`: every one but the Pillar built and the Runtime is forbidden. A Module is also checked against every other suite's Modules, bases included: a Pillar may not name `pipeworks:pipe` or `groundworks:wrench`, nor a FactoryWorks Module `atouchof:meter`. A mod no suite lists, such as the template's `examplelib`, is checked against every suite's Modules but Groundworks and `atouchof`. A new Module is added to its suite there, and reaches the others by a plugin release they move to. The failure lists each finding under its folder, such as `build/resources/main/data/beltworks/recipe/x.json names gearworks:gear`. +`checkPlaysAlone`, which `check` runs, fails when the Module ships something that names another Module of its suite (FactoryWorks ADR-0127, A Touch Of ADR-0002, ADR 0005, ADR 0013, ADR 0014): an id in its namespace, such as `pipeworks:pipe`, in a resource or in Java source; an `assets/` or `data/` folder; the namespace as a string in Java source, `"pipeworks"`; or a required dependency on it in `neoforge.mods.toml`, where an optional one is allowed. A structure's `.nbt` is read unzipped, so the block ids saved in it count. The resources are read as `processResources` leaves them, so generated ones and the expanded mods.toml count; the code is `src/main`'s Java source, and the `gametest` source set is not read. The suites are `PlaysAlone.SUITES`, and the Module's suite is the one whose list holds its `mod_id`. FactoryWorks' Modules are Beltworks, Craftworks, Fieldworks, Gearworks, Groundworks, Pipeworks, Voidworks and Wireworks: every one but the Module built and Groundworks is forbidden, and the retired `factoryworks`. A Touch Of's are its Runtime, `atouchof`, and the Pillars `atouchofdarkness`, `atouchofmadness` and `atouchofwickedness`: every one but the Pillar built and the Runtime is forbidden, and the shelved `atouchofcold` (A Touch Of #5). A Pillar may still ship a tag file under another Pillar's `data//tags/`, to add entries to that Pillar's tag, when `replace` is absent or false and every entry is an object with `"required": false` naming one of its own ids or tags, such as Wickedness's `data/atouchofmadness/tags/entity_type/unsettling.json` holding `{"id": "atouchofwickedness:bailiff", "required": false}` (A Touch Of ADR-0002, ADR 0014). Each other file in that folder is reported, with why: a bare or required entry, `replace: true`, an id not its own, or a file that is not a tag. FactoryWorks has no such exception, nor does the Runtime, the shelved `atouchofcold` or another suite's namespace. A Module is also checked against every other suite's Modules, bases included: a Pillar may not name `pipeworks:pipe` or `groundworks:wrench`, nor a FactoryWorks Module `atouchof:meter`. A mod no suite lists, such as the template's `examplelib`, is checked against every suite's Modules but Groundworks and `atouchof`. A new Module is added to its suite there, and reaches the others by a plugin release they move to. The failure lists each finding under its folder, such as `build/resources/main/data/beltworks/recipe/x.json names gearworks:gear`. ### Moving to 0.4.0 diff --git a/plugin/src/main/groovy/io/github/_5thlayer/libworks/plugin/PlaysAlone.groovy b/plugin/src/main/groovy/io/github/_5thlayer/libworks/plugin/PlaysAlone.groovy index 174bd33..57c2c8c 100644 --- a/plugin/src/main/groovy/io/github/_5thlayer/libworks/plugin/PlaysAlone.groovy +++ b/plugin/src/main/groovy/io/github/_5thlayer/libworks/plugin/PlaysAlone.groovy @@ -3,6 +3,8 @@ package io.github._5thlayer.libworks.plugin +import groovy.json.JsonSlurper + import java.nio.charset.StandardCharsets import java.nio.file.Files import java.nio.file.Path @@ -16,20 +18,25 @@ import java.util.zip.GZIPInputStream */ final class PlaysAlone { - /** One suite: what it calls its Modules, the ADR that has them play alone, its Modules, the base among them that every one may require, and the retired ids none may name. */ + /** + * One suite: what it calls its Modules, the ADR that has them play alone, its Modules, the base among them that every one may require, + * the retired ids none may name, and whether a Module may add optional entries to another Module's tags (ADR 0014). + */ static final class Suite { final String term final String rule final String base final List modules final List retired + final boolean optionalTagEntries - Suite(String term, String rule, String base, List modules, List retired) { + Suite(String term, String rule, String base, List modules, List retired, boolean optionalTagEntries = false) { this.term = term this.rule = rule this.base = base this.modules = modules this.retired = retired + this.optionalTagEntries = optionalTagEntries } /** Every Module but {@code modId} and the base, and the retired ids. */ @@ -45,13 +52,14 @@ final class PlaysAlone { /** * Every suite. FactoryWorks Core retired (FactoryWorks ADR-0128), so no Module may name {@code factoryworks}; - * the A Touch Of Runtime, {@code atouchof}, is the base every Pillar nests (A Touch Of ADR-0002). + * the A Touch Of Runtime, {@code atouchof}, is the base every Pillar nests (A Touch Of ADR-0002), and + * {@code atouchofcold} is shelved in favour of Tough As Nails, so no Pillar may come to depend on it (atouchof#5). */ static final List SUITES = [ new Suite('Module', 'FactoryWorks ADR-0127', 'groundworks', ['beltworks', 'craftworks', 'fieldworks', 'gearworks', 'groundworks', 'pipeworks', 'voidworks', 'wireworks'], ['factoryworks']), new Suite('Pillar', 'A Touch Of ADR-0002', 'atouchof', - ['atouchof', 'atouchofcold', 'atouchofdarkness', 'atouchofmadness'], []), + ['atouchof', 'atouchofdarkness', 'atouchofmadness', 'atouchofwickedness'], ['atouchofcold'], true), ] private static final Pattern DEPENDENCY_MOD_ID = ~/(?m)^\s*modId\s*=\s*"([^"]+)"/ @@ -60,6 +68,8 @@ final class PlaysAlone { /** The suite whose Modules hold {@code modId}, or null for a mod no suite lists, such as the template's own. */ final Suite suite + final String modId + /** * The namespaces {@code modId} may not name: its suite's but its base, and every other suite's, bases * included; or for a mod no suite lists every suite's but their bases, as its suite is not known (ADR 0013). @@ -67,6 +77,7 @@ final class PlaysAlone { final List forbidden PlaysAlone(String modId) { + this.modId = modId suite = SUITES.find { modId in it.modules } forbidden = (suite ? suite.forbiddenTo(modId) + (SUITES - suite).collectMany { it.forbiddenToOtherSuites() } @@ -100,20 +111,57 @@ final class PlaysAlone { found } - /** Each {@code assets/} or {@code data/} folder under {@code resources} that is forbidden. */ + /** + * Each {@code assets/} or {@code data/} folder under {@code resources} that is forbidden. Where the suite lets a + * Module add optional entries to another Module's tags, that Module's data folder is read file by file instead, and each file that is + * not such a tag is reported (ADR 0014). + */ List namespaces(Path resources) { def found = [] ['assets', 'data'].each { kind -> def dir = resources.resolve(kind) if (!Files.isDirectory(dir)) return - Files.list(dir).withCloseable { namespaces -> - namespaces.map { it.fileName.toString() }.filter { forbidden.contains(it) }.sorted() - .forEach { found << "$kind/$it".toString() } + def names = Files.list(dir).withCloseable { it.map { it.fileName.toString() }.filter { forbidden.contains(it) }.sorted().toList() } + names.each { namespace -> + if (kind == 'data' && mayTag(namespace)) found += optionalTags(resources, dir.resolve(namespace)) + else found << "$kind/$namespace".toString() } } found } + /** Whether this Module may add optional entries to {@code namespace}'s tags: another Module of its own suite that takes them, never the base building. */ + private boolean mayTag(String namespace) { + suite?.optionalTagEntries && modId != suite.base && namespace in suite.modules + } + + /** Each file under {@code namespace} that is not a tag of the Module's own ids, every entry optional, that keeps the tag's other entries. */ + private List optionalTags(Path resources, Path namespace) { + def tags = namespace.resolve('tags') + files(namespace).collectMany { file -> + def name = relative(resources, file) + if (!file.startsWith(tags) || !file.toString().endsWith('.json')) return [name] + def tag + try { + tag = new JsonSlurper().parse(file.toFile()) + } catch (ignored) { + return ["$name is not a tag".toString()] + } + if (!(tag instanceof Map) || !(tag.values instanceof List)) return ["$name is not a tag".toString()] + def found = [] + if (tag.replace) found << "$name replaces the tag".toString() + tag.values.each { entry -> + // A bare id, or an entry with no "required", is required: the tag fails to load without it. + def id = entry instanceof Map ? entry.id : entry + if (!(entry instanceof Map) || entry.required != false) found << "$name requires $id".toString() + else if (!(id instanceof String) || !(id - ~/^#/).startsWith("$modId:")) { + found << "$name adds $id, not $modId's own".toString() + } + } + found + } + } + /** Each string in the Java source under {@code code} that is a forbidden namespace, as an id built in code names it. */ List namespaceStrings(Path code) { def namespaces = Pattern.compile("\"(${forbidden.join('|')})\"") diff --git a/plugin/src/test/java/io/github/_5thlayer/libworks/plugin/ModulePluginTest.java b/plugin/src/test/java/io/github/_5thlayer/libworks/plugin/ModulePluginTest.java index 6b96dff..f1b00ae 100644 --- a/plugin/src/test/java/io/github/_5thlayer/libworks/plugin/ModulePluginTest.java +++ b/plugin/src/test/java/io/github/_5thlayer/libworks/plugin/ModulePluginTest.java @@ -456,11 +456,23 @@ void checkPlaysAloneChecksAPillarAgainstTheOtherPillarsAndFactoryWorks() throws write("src/main/java/dark/Dark.java", "package dark; class Dark { String sanity = \"atouchofmadness:sanity\"; String meter = \"atouchof:meter\"; String pipe = \"pipeworks:pipe\"; }\n"); String out = fail("checkPlaysAlone").getOutput(); assertTrue(out.contains("atouchofdarkness ships what names another Pillar or another suite's Module (A Touch Of ADR-0002, libworks ADR 0013), whose namespaces are " - + "atouchofcold, atouchofmadness, beltworks, craftworks, factoryworks, fieldworks, gearworks, groundworks, pipeworks, voidworks, wireworks:\n" + + "atouchofcold, atouchofmadness, atouchofwickedness, beltworks, craftworks, factoryworks, fieldworks, gearworks, groundworks, pipeworks, voidworks, wireworks:\n" + " src/main/java/dark/Dark.java names atouchofmadness:sanity\n" + " src/main/java/dark/Dark.java names pipeworks:pipe\n"), out); } + @Test + void checkPlaysAloneLetsAPillarAddOnlyOptionalEntriesToAnotherPillarsTag() throws IOException { + Files.writeString(module.resolve("gradle.properties"), Files.readString(module.resolve("gradle.properties")).replace("mod_id = beltworks", "mod_id = atouchofwickedness")); + buildScript(""); + write("src/main/resources/data/atouchofmadness/tags/entity_type/unsettling.json", + "{\"replace\": false, \"values\": [{\"id\": \"atouchofwickedness:bailiff\", \"required\": false}]}\n"); + build("checkPlaysAlone"); + write("src/main/resources/data/atouchofmadness/tags/entity_type/unsettling.json", "{\"values\": [\"atouchofwickedness:bailiff\"]}\n"); + String out = fail("checkPlaysAlone").getOutput(); + assertTrue(out.contains(" build/resources/main/data/atouchofmadness/tags/entity_type/unsettling.json requires atouchofwickedness:bailiff\n"), out); + } + @Test void checkPlaysAlonePassesAModuleWithNoResources() throws IOException { buildScript(""); diff --git a/plugin/src/test/java/io/github/_5thlayer/libworks/plugin/PlaysAloneTest.java b/plugin/src/test/java/io/github/_5thlayer/libworks/plugin/PlaysAloneTest.java index 3dc52f7..56b7711 100644 --- a/plugin/src/test/java/io/github/_5thlayer/libworks/plugin/PlaysAloneTest.java +++ b/plugin/src/test/java/io/github/_5thlayer/libworks/plugin/PlaysAloneTest.java @@ -18,21 +18,24 @@ /** Each rule of the plays-alone scan, on files written for it: Beltworks is the Module scanned unless a test names another. */ class PlaysAloneTest { private final PlaysAlone belt = new PlaysAlone("beltworks"); + private final PlaysAlone wicked = new PlaysAlone("atouchofwickedness"); @Test void forbidsEveryModuleButItselfAndGroundworksAndTheRetiredPackAndEveryPillar() { - assertEquals(List.of("atouchof", "atouchofcold", "atouchofdarkness", "atouchofmadness", "craftworks", "factoryworks", "fieldworks", - "gearworks", "pipeworks", "voidworks", "wireworks"), belt.getForbidden()); - assertEquals(List.of("atouchof", "atouchofcold", "atouchofdarkness", "atouchofmadness", "beltworks", "craftworks", "factoryworks", - "fieldworks", "gearworks", "pipeworks", "voidworks", "wireworks"), new PlaysAlone("groundworks").getForbidden()); + assertEquals(List.of("atouchof", "atouchofcold", "atouchofdarkness", "atouchofmadness", "atouchofwickedness", "craftworks", "factoryworks", + "fieldworks", "gearworks", "pipeworks", "voidworks", "wireworks"), belt.getForbidden()); + assertEquals(List.of("atouchof", "atouchofcold", "atouchofdarkness", "atouchofmadness", "atouchofwickedness", "beltworks", "craftworks", + "factoryworks", "fieldworks", "gearworks", "pipeworks", "voidworks", "wireworks"), new PlaysAlone("groundworks").getForbidden()); } @Test - void aPillarForbidsTheOtherPillarsAndEveryFactoryWorksModuleGroundworksIncluded() { - assertEquals(List.of("atouchofcold", "atouchofmadness", "beltworks", "craftworks", "factoryworks", "fieldworks", "gearworks", - "groundworks", "pipeworks", "voidworks", "wireworks"), new PlaysAlone("atouchofdarkness").getForbidden()); + void aPillarForbidsTheOtherPillarsTheShelvedColdAndEveryFactoryWorksModuleGroundworksIncluded() { + assertEquals(List.of("atouchofcold", "atouchofmadness", "atouchofwickedness", "beltworks", "craftworks", "factoryworks", "fieldworks", + "gearworks", "groundworks", "pipeworks", "voidworks", "wireworks"), new PlaysAlone("atouchofdarkness").getForbidden()); assertEquals(List.of("atouchofcold", "atouchofdarkness", "atouchofmadness", "beltworks", "craftworks", "factoryworks", "fieldworks", - "gearworks", "groundworks", "pipeworks", "voidworks", "wireworks"), new PlaysAlone("atouchof").getForbidden()); + "gearworks", "groundworks", "pipeworks", "voidworks", "wireworks"), new PlaysAlone("atouchofwickedness").getForbidden()); + assertEquals(List.of("atouchofcold", "atouchofdarkness", "atouchofmadness", "atouchofwickedness", "beltworks", "craftworks", "factoryworks", + "fieldworks", "gearworks", "groundworks", "pipeworks", "voidworks", "wireworks"), new PlaysAlone("atouchof").getForbidden()); } @Test @@ -52,8 +55,8 @@ void aFactoryWorksModuleMayNameNoPillarNorTheRuntime(@TempDir Path resources) th @Test void aModNoSuiteListsForbidsEverySuitesModulesButTheirBases() { - assertEquals(List.of("atouchofcold", "atouchofdarkness", "atouchofmadness", "beltworks", "craftworks", "factoryworks", "fieldworks", - "gearworks", "pipeworks", "voidworks", "wireworks"), new PlaysAlone("examplelib").getForbidden()); + assertEquals(List.of("atouchofcold", "atouchofdarkness", "atouchofmadness", "atouchofwickedness", "beltworks", "craftworks", "factoryworks", + "fieldworks", "gearworks", "pipeworks", "voidworks", "wireworks"), new PlaysAlone("examplelib").getForbidden()); } @Test @@ -65,6 +68,52 @@ void aDataOrAssetFolderInAnotherModulesNamespaceIsReported(@TempDir Path resourc assertEquals(List.of("assets/voidworks", "data/fieldworks"), belt.namespaces(resources)); } + @Test + void aPillarMayAddItsOwnOptionalEntriesToAnotherPillarsTag(@TempDir Path resources) throws IOException { + write(resources.resolve("data/atouchofmadness/tags/entity_type/unsettling.json"), + "{\"replace\": false, \"values\": [{\"id\": \"atouchofwickedness:bailiff\", \"required\": false}]}"); + write(resources.resolve("data/atouchofdarkness/tags/item/x.json"), "{\"values\": [{\"id\": \"#atouchofwickedness:seals\", \"required\": false}]}"); + assertEquals(List.of(), wicked.namespaces(resources)); + } + + @Test + void anOptionalTagFileThatRequiresReplacesOrAddsAnotherIdIsReported(@TempDir Path resources) throws IOException { + write(resources.resolve("data/atouchofmadness/tags/entity_type/a.json"), "{\"values\": [\"atouchofwickedness:bailiff\"]}"); + write(resources.resolve("data/atouchofmadness/tags/entity_type/b.json"), "{\"values\": [{\"id\": \"atouchofwickedness:bailiff\"}]}"); + write(resources.resolve("data/atouchofmadness/tags/entity_type/c.json"), + "{\"values\": [{\"id\": \"atouchofwickedness:bailiff\", \"required\": true}]}"); + write(resources.resolve("data/atouchofmadness/tags/entity_type/d.json"), + "{\"replace\": true, \"values\": [{\"id\": \"atouchofwickedness:bailiff\", \"required\": false}]}"); + write(resources.resolve("data/atouchofmadness/tags/entity_type/e.json"), "{\"values\": [{\"id\": \"minecraft:zombie\", \"required\": false}]}"); + write(resources.resolve("data/atouchofmadness/tags/entity_type/f.json"), "[]"); + assertEquals(List.of("data/atouchofmadness/tags/entity_type/a.json requires atouchofwickedness:bailiff", + "data/atouchofmadness/tags/entity_type/b.json requires atouchofwickedness:bailiff", + "data/atouchofmadness/tags/entity_type/c.json requires atouchofwickedness:bailiff", + "data/atouchofmadness/tags/entity_type/d.json replaces the tag", + "data/atouchofmadness/tags/entity_type/e.json adds minecraft:zombie, not atouchofwickedness's own", + "data/atouchofmadness/tags/entity_type/f.json is not a tag"), wicked.namespaces(resources)); + } + + @Test + void anotherPillarsDataOutsideItsTagsOrAssetsAreReported(@TempDir Path resources) throws IOException { + write(resources.resolve("data/atouchofmadness/tags/entity_type/unsettling.json"), + "{\"values\": [{\"id\": \"atouchofwickedness:bailiff\", \"required\": false}]}"); + write(resources.resolve("data/atouchofmadness/recipe/x.json"), "{}"); + write(resources.resolve("assets/atouchofmadness/lang/en_us.json"), "{}"); + assertEquals(List.of("assets/atouchofmadness", "data/atouchofmadness/recipe/x.json"), wicked.namespaces(resources)); + } + + @Test + void optionalTagEntriesAreNoExceptionForTheShelvedColdAnotherSuiteOrFactoryWorks(@TempDir Path resources) throws IOException { + String optional = "{\"values\": [{\"id\": \"%s:x\", \"required\": false}]}"; + write(resources.resolve("data/atouchofcold/tags/item/x.json"), optional.formatted("atouchofwickedness")); + write(resources.resolve("data/pipeworks/tags/item/x.json"), optional.formatted("atouchofwickedness")); + assertEquals(List.of("data/atouchofcold", "data/pipeworks"), wicked.namespaces(resources)); + write(resources.resolve("data/fieldworks/tags/item/x.json"), optional.formatted("beltworks")); + write(resources.resolve("data/atouchofmadness/tags/item/x.json"), optional.formatted("beltworks")); + assertEquals(List.of("data/atouchofcold", "data/atouchofmadness", "data/fieldworks", "data/pipeworks"), belt.namespaces(resources)); + } + @Test void anIdInDataIsReported(@TempDir Path resources) throws IOException { write(resources.resolve("data/beltworks/recipe/x.json"), "{\"key\":{\"a\":\"gearworks:gear\"}}"); From 9403fbd0e1b82b6c06ae9807223d0472e6e217a6 Mon Sep 17 00:00:00 2001 From: Andrea D'Amico Date: Tue, 27 Oct 2026 13:00:12 +0100 Subject: [PATCH 2/7] fix(plugin): report a tag that removes from another pillar's tag NeoForge reads a tag file's remove list, so a pillar could take entries out of another pillar's tag and still pass. checkPlaysAlone now reports it. Co-Authored-By: Claude Opus 5.5 --- ...optional-entries-to-another-pillars-tag.md | 3 +- docs/plugin.md | 2 +- .../libworks/plugin/PlaysAlone.groovy | 35 ++++++++++--------- .../libworks/plugin/PlaysAloneTest.java | 6 ++-- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/docs/adr/0014-a-pillar-may-add-optional-entries-to-another-pillars-tag.md b/docs/adr/0014-a-pillar-may-add-optional-entries-to-another-pillars-tag.md index 24e7ada..90d4972 100644 --- a/docs/adr/0014-a-pillar-may-add-optional-entries-to-another-pillars-tag.md +++ b/docs/adr/0014-a-pillar-may-add-optional-entries-to-another-pillars-tag.md @@ -17,7 +17,8 @@ files under another Module's `data//tags/`. Each must be a tag whose `replac false, and whose every entry is an object with `"required": false` naming one of the Module's own ids or tags. The scan reads that namespace's data folder file by file. It reports each file outside `tags/` and each file that is not a tag, and for a tag it names each bare or required entry, a -`replace: true` and each id that is not the Module's own. The exception does not cover an +`replace: true`, a NeoForge `remove` list, which would take entries out of the other tag, and each id +that is not the Module's own. The exception does not cover an `assets/` folder, the base, a retired id such as the shelved `atouchofcold`, or another suite's namespace. diff --git a/docs/plugin.md b/docs/plugin.md index 639f78d..6bbdf6a 100644 --- a/docs/plugin.md +++ b/docs/plugin.md @@ -31,7 +31,7 @@ The plugin adds a `gametest` source set to the mod, which the dev runs load and `buildGametestStructures` writes the default `gametest/platform.nbt` into `src/gametest/resources/data//structure/`, leaves an identical one alone, and fails naming the file when the Module has committed a different one: a Module needing another structure commits it (ADR 0003). -`checkPlaysAlone`, which `check` runs, fails when the Module ships something that names another Module of its suite (FactoryWorks ADR-0127, A Touch Of ADR-0002, ADR 0005, ADR 0013, ADR 0014): an id in its namespace, such as `pipeworks:pipe`, in a resource or in Java source; an `assets/` or `data/` folder; the namespace as a string in Java source, `"pipeworks"`; or a required dependency on it in `neoforge.mods.toml`, where an optional one is allowed. A structure's `.nbt` is read unzipped, so the block ids saved in it count. The resources are read as `processResources` leaves them, so generated ones and the expanded mods.toml count; the code is `src/main`'s Java source, and the `gametest` source set is not read. The suites are `PlaysAlone.SUITES`, and the Module's suite is the one whose list holds its `mod_id`. FactoryWorks' Modules are Beltworks, Craftworks, Fieldworks, Gearworks, Groundworks, Pipeworks, Voidworks and Wireworks: every one but the Module built and Groundworks is forbidden, and the retired `factoryworks`. A Touch Of's are its Runtime, `atouchof`, and the Pillars `atouchofdarkness`, `atouchofmadness` and `atouchofwickedness`: every one but the Pillar built and the Runtime is forbidden, and the shelved `atouchofcold` (A Touch Of #5). A Pillar may still ship a tag file under another Pillar's `data//tags/`, to add entries to that Pillar's tag, when `replace` is absent or false and every entry is an object with `"required": false` naming one of its own ids or tags, such as Wickedness's `data/atouchofmadness/tags/entity_type/unsettling.json` holding `{"id": "atouchofwickedness:bailiff", "required": false}` (A Touch Of ADR-0002, ADR 0014). Each other file in that folder is reported, with why: a bare or required entry, `replace: true`, an id not its own, or a file that is not a tag. FactoryWorks has no such exception, nor does the Runtime, the shelved `atouchofcold` or another suite's namespace. A Module is also checked against every other suite's Modules, bases included: a Pillar may not name `pipeworks:pipe` or `groundworks:wrench`, nor a FactoryWorks Module `atouchof:meter`. A mod no suite lists, such as the template's `examplelib`, is checked against every suite's Modules but Groundworks and `atouchof`. A new Module is added to its suite there, and reaches the others by a plugin release they move to. The failure lists each finding under its folder, such as `build/resources/main/data/beltworks/recipe/x.json names gearworks:gear`. +`checkPlaysAlone`, which `check` runs, fails when the Module ships something that names another Module of its suite (FactoryWorks ADR-0127, A Touch Of ADR-0002, ADR 0005, ADR 0013, ADR 0014): an id in its namespace, such as `pipeworks:pipe`, in a resource or in Java source; an `assets/` or `data/` folder; the namespace as a string in Java source, `"pipeworks"`; or a required dependency on it in `neoforge.mods.toml`, where an optional one is allowed. A structure's `.nbt` is read unzipped, so the block ids saved in it count. The resources are read as `processResources` leaves them, so generated ones and the expanded mods.toml count; the code is `src/main`'s Java source, and the `gametest` source set is not read. The suites are `PlaysAlone.SUITES`, and the Module's suite is the one whose list holds its `mod_id`. FactoryWorks' Modules are Beltworks, Craftworks, Fieldworks, Gearworks, Groundworks, Pipeworks, Voidworks and Wireworks: every one but the Module built and Groundworks is forbidden, and the retired `factoryworks`. A Touch Of's are its Runtime, `atouchof`, and the Pillars `atouchofdarkness`, `atouchofmadness` and `atouchofwickedness`: every one but the Pillar built and the Runtime is forbidden, and the shelved `atouchofcold` (A Touch Of #5). A Pillar may still ship a tag file under another Pillar's `data//tags/`, to add entries to that Pillar's tag, when `replace` is absent or false and every entry is an object with `"required": false` naming one of its own ids or tags, such as Wickedness's `data/atouchofmadness/tags/entity_type/unsettling.json` holding `{"id": "atouchofwickedness:bailiff", "required": false}` (A Touch Of ADR-0002, ADR 0014). Each other file in that folder is reported, with why: a bare or required entry, `replace: true`, a NeoForge `remove` list, an id not its own, or a file that is not a tag. FactoryWorks has no such exception, nor does the Runtime, the shelved `atouchofcold` or another suite's namespace. A Module is also checked against every other suite's Modules, bases included: a Pillar may not name `pipeworks:pipe` or `groundworks:wrench`, nor a FactoryWorks Module `atouchof:meter`. A mod no suite lists, such as the template's `examplelib`, is checked against every suite's Modules but Groundworks and `atouchof`. A new Module is added to its suite there, and reaches the others by a plugin release they move to. The failure lists each finding under its folder, such as `build/resources/main/data/beltworks/recipe/x.json names gearworks:gear`. ### Moving to 0.4.0 diff --git a/plugin/src/main/groovy/io/github/_5thlayer/libworks/plugin/PlaysAlone.groovy b/plugin/src/main/groovy/io/github/_5thlayer/libworks/plugin/PlaysAlone.groovy index 57c2c8c..ff89108 100644 --- a/plugin/src/main/groovy/io/github/_5thlayer/libworks/plugin/PlaysAlone.groovy +++ b/plugin/src/main/groovy/io/github/_5thlayer/libworks/plugin/PlaysAlone.groovy @@ -44,6 +44,11 @@ final class PlaysAlone { modules.findAll { it != modId && it != base } + retired } + /** Whether {@code modId} may add optional entries to {@code namespace}'s tags: another Module of this suite, the base never adding (ADR 0014). */ + boolean takesOptionalTagEntries(String modId, String namespace) { + optionalTagEntries && modId != base && namespace in modules + } + /** Every Module, the base included, and the retired ids: what a Module of another suite may not name. */ List forbiddenToOtherSuites() { modules + retired @@ -53,13 +58,13 @@ final class PlaysAlone { /** * Every suite. FactoryWorks Core retired (FactoryWorks ADR-0128), so no Module may name {@code factoryworks}; * the A Touch Of Runtime, {@code atouchof}, is the base every Pillar nests (A Touch Of ADR-0002), and - * {@code atouchofcold} is shelved in favour of Tough As Nails, so no Pillar may come to depend on it (atouchof#5). + * {@code atouchofcold} is shelved in favour of Tough As Nails, so no Pillar may come to depend on it (A Touch Of #5). */ static final List SUITES = [ new Suite('Module', 'FactoryWorks ADR-0127', 'groundworks', ['beltworks', 'craftworks', 'fieldworks', 'gearworks', 'groundworks', 'pipeworks', 'voidworks', 'wireworks'], ['factoryworks']), new Suite('Pillar', 'A Touch Of ADR-0002', 'atouchof', - ['atouchof', 'atouchofdarkness', 'atouchofmadness', 'atouchofwickedness'], ['atouchofcold'], true), + ['atouchof', 'atouchofdarkness', 'atouchofmadness', 'atouchofwickedness'], ['atouchofcold'], /* optionalTagEntries */ true), ] private static final Pattern DEPENDENCY_MOD_ID = ~/(?m)^\s*modId\s*=\s*"([^"]+)"/ @@ -68,6 +73,7 @@ final class PlaysAlone { /** The suite whose Modules hold {@code modId}, or null for a mod no suite lists, such as the template's own. */ final Suite suite + /** The Module built. */ final String modId /** @@ -114,7 +120,7 @@ final class PlaysAlone { /** * Each {@code assets/} or {@code data/} folder under {@code resources} that is forbidden. Where the suite lets a * Module add optional entries to another Module's tags, that Module's data folder is read file by file instead, and each file that is - * not such a tag is reported (ADR 0014). + * not such a tag is reported, with why (ADR 0014). */ List namespaces(Path resources) { def found = [] @@ -123,40 +129,37 @@ final class PlaysAlone { if (!Files.isDirectory(dir)) return def names = Files.list(dir).withCloseable { it.map { it.fileName.toString() }.filter { forbidden.contains(it) }.sorted().toList() } names.each { namespace -> - if (kind == 'data' && mayTag(namespace)) found += optionalTags(resources, dir.resolve(namespace)) + if (kind == 'data' && suite?.takesOptionalTagEntries(modId, namespace)) found += notOptionalTags(resources, dir.resolve(namespace)) else found << "$kind/$namespace".toString() } } found } - /** Whether this Module may add optional entries to {@code namespace}'s tags: another Module of its own suite that takes them, never the base building. */ - private boolean mayTag(String namespace) { - suite?.optionalTagEntries && modId != suite.base && namespace in suite.modules - } - - /** Each file under {@code namespace} that is not a tag of the Module's own ids, every entry optional, that keeps the tag's other entries. */ - private List optionalTags(Path resources, Path namespace) { + /** + * What the files under another Module's {@code namespace} folder ship beyond optional entries of this Module's own ids: each file + * outside {@code tags/} or not a tag, and in a tag each entry that is required or not its own, a {@code replace} and a {@code remove}. + */ + private List notOptionalTags(Path resources, Path namespace) { def tags = namespace.resolve('tags') files(namespace).collectMany { file -> def name = relative(resources, file) if (!file.startsWith(tags) || !file.toString().endsWith('.json')) return [name] - def tag + def tag = null try { tag = new JsonSlurper().parse(file.toFile()) } catch (ignored) { - return ["$name is not a tag".toString()] } if (!(tag instanceof Map) || !(tag.values instanceof List)) return ["$name is not a tag".toString()] def found = [] if (tag.replace) found << "$name replaces the tag".toString() + // NeoForge reads a tag's "remove" list too, which would take entries out of the other Module's tag. + if (tag.remove) found << "$name removes from the tag".toString() tag.values.each { entry -> // A bare id, or an entry with no "required", is required: the tag fails to load without it. def id = entry instanceof Map ? entry.id : entry if (!(entry instanceof Map) || entry.required != false) found << "$name requires $id".toString() - else if (!(id instanceof String) || !(id - ~/^#/).startsWith("$modId:")) { - found << "$name adds $id, not $modId's own".toString() - } + else if (!(id instanceof String) || !(id - ~/^#/).startsWith("$modId:")) found << "$name adds $id, not $modId's own".toString() } found } diff --git a/plugin/src/test/java/io/github/_5thlayer/libworks/plugin/PlaysAloneTest.java b/plugin/src/test/java/io/github/_5thlayer/libworks/plugin/PlaysAloneTest.java index 56b7711..3070ffd 100644 --- a/plugin/src/test/java/io/github/_5thlayer/libworks/plugin/PlaysAloneTest.java +++ b/plugin/src/test/java/io/github/_5thlayer/libworks/plugin/PlaysAloneTest.java @@ -86,16 +86,18 @@ void anOptionalTagFileThatRequiresReplacesOrAddsAnotherIdIsReported(@TempDir Pat "{\"replace\": true, \"values\": [{\"id\": \"atouchofwickedness:bailiff\", \"required\": false}]}"); write(resources.resolve("data/atouchofmadness/tags/entity_type/e.json"), "{\"values\": [{\"id\": \"minecraft:zombie\", \"required\": false}]}"); write(resources.resolve("data/atouchofmadness/tags/entity_type/f.json"), "[]"); + write(resources.resolve("data/atouchofmadness/tags/entity_type/g.json"), "{\"values\": [], \"remove\": [\"atouchofmadness:x\"]}"); assertEquals(List.of("data/atouchofmadness/tags/entity_type/a.json requires atouchofwickedness:bailiff", "data/atouchofmadness/tags/entity_type/b.json requires atouchofwickedness:bailiff", "data/atouchofmadness/tags/entity_type/c.json requires atouchofwickedness:bailiff", "data/atouchofmadness/tags/entity_type/d.json replaces the tag", "data/atouchofmadness/tags/entity_type/e.json adds minecraft:zombie, not atouchofwickedness's own", - "data/atouchofmadness/tags/entity_type/f.json is not a tag"), wicked.namespaces(resources)); + "data/atouchofmadness/tags/entity_type/f.json is not a tag", + "data/atouchofmadness/tags/entity_type/g.json removes from the tag"), wicked.namespaces(resources)); } @Test - void anotherPillarsDataOutsideItsTagsOrAssetsAreReported(@TempDir Path resources) throws IOException { + void anotherPillarsAssetsOrDataOutsideItsTagsAreReported(@TempDir Path resources) throws IOException { write(resources.resolve("data/atouchofmadness/tags/entity_type/unsettling.json"), "{\"values\": [{\"id\": \"atouchofwickedness:bailiff\", \"required\": false}]}"); write(resources.resolve("data/atouchofmadness/recipe/x.json"), "{}"); From 7aa2f9b7f5e018ad285412ed9726e12dab7d44e0 Mon Sep 17 00:00:00 2001 From: Andrea D'Amico Date: Tue, 27 Oct 2026 13:04:38 +0100 Subject: [PATCH 3/7] refactor(plugin): read other pillars' tags apart from the folder scan namespaces() reports forbidden folders again, and otherTags() reads the tags a pillar may add to. A file directly under tags/, outside any registry folder, is not a tag. Co-Authored-By: Claude Opus 5.5 --- .../libworks/plugin/PlaysAlone.groovy | 43 +++++++++++-------- .../libworks/plugin/PlaysAloneTest.java | 10 ++++- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/plugin/src/main/groovy/io/github/_5thlayer/libworks/plugin/PlaysAlone.groovy b/plugin/src/main/groovy/io/github/_5thlayer/libworks/plugin/PlaysAlone.groovy index ff89108..c37dbd7 100644 --- a/plugin/src/main/groovy/io/github/_5thlayer/libworks/plugin/PlaysAlone.groovy +++ b/plugin/src/main/groovy/io/github/_5thlayer/libworks/plugin/PlaysAlone.groovy @@ -95,9 +95,9 @@ final class PlaysAlone { suite ? "another ${suite.term} or another suite's Module (${suite.rule}, libworks ADR 0013)" : 'another Module (libworks ADR 0013)' } - /** What the processed resources under {@code resources} ship against the rules: ids, namespace folders and required mods. */ + /** What the processed resources under {@code resources} ship against the rules: ids, namespace folders, other Modules' tags and required mods. */ List resources(Path resources) { - ids(resources) + namespaces(resources) + required(resources) + ids(resources) + namespaces(resources) + otherTags(resources) + required(resources) } /** What the Java source under {@code code} names against the rules: ids and namespace strings. */ @@ -118,28 +118,36 @@ final class PlaysAlone { } /** - * Each {@code assets/} or {@code data/} folder under {@code resources} that is forbidden. Where the suite lets a - * Module add optional entries to another Module's tags, that Module's data folder is read file by file instead, and each file that is - * not such a tag is reported, with why (ADR 0014). + * Each {@code assets/} or {@code data/} folder under {@code resources} that is forbidden, but the data folders of + * Modules whose tags this one may add optional entries to, which {@link #otherTags} reads (ADR 0014). */ List namespaces(Path resources) { def found = [] ['assets', 'data'].each { kind -> - def dir = resources.resolve(kind) - if (!Files.isDirectory(dir)) return - def names = Files.list(dir).withCloseable { it.map { it.fileName.toString() }.filter { forbidden.contains(it) }.sorted().toList() } - names.each { namespace -> - if (kind == 'data' && suite?.takesOptionalTagEntries(modId, namespace)) found += notOptionalTags(resources, dir.resolve(namespace)) - else found << "$kind/$namespace".toString() - } + forbiddenFolders(resources, kind).findAll { kind != 'data' || !takesTagsOf(it) }.each { found << "$kind/$it".toString() } } found } /** - * What the files under another Module's {@code namespace} folder ship beyond optional entries of this Module's own ids: each file - * outside {@code tags/} or not a tag, and in a tag each entry that is required or not its own, a {@code replace} and a {@code remove}. + * What this Module ships under the data folders of Modules whose tags it may add optional entries to, beyond optional entries of its + * own ids (ADR 0014): each file outside {@code tags//} or not a tag, and in a tag each entry that is required or not its own, + * a {@code replace} and a {@code remove}. */ + List otherTags(Path resources) { + forbiddenFolders(resources, 'data').findAll { takesTagsOf(it) }.collectMany { notOptionalTags(resources, resources.resolve("data/$it")) } + } + + private List forbiddenFolders(Path resources, String kind) { + def dir = resources.resolve(kind) + if (!Files.isDirectory(dir)) return [] + Files.list(dir).withCloseable { it.map { it.fileName.toString() }.filter { forbidden.contains(it) }.sorted().toList() } + } + + private boolean takesTagsOf(String namespace) { + suite?.takesOptionalTagEntries(modId, namespace) + } + private List notOptionalTags(Path resources, Path namespace) { def tags = namespace.resolve('tags') files(namespace).collectMany { file -> @@ -150,13 +158,14 @@ final class PlaysAlone { tag = new JsonSlurper().parse(file.toFile()) } catch (ignored) { } - if (!(tag instanceof Map) || !(tag.values instanceof List)) return ["$name is not a tag".toString()] + // A tag file sits in its registry's folder, tags//; vanilla reads none directly under tags/. + if (file.parent == tags || !(tag instanceof Map) || !(tag.values instanceof List)) return ["$name is not a tag".toString()] def found = [] if (tag.replace) found << "$name replaces the tag".toString() - // NeoForge reads a tag's "remove" list too, which would take entries out of the other Module's tag. + // NeoForge reads a tag's "remove" list too, which would take entries out of the other Module's tag (ADR 0014). if (tag.remove) found << "$name removes from the tag".toString() tag.values.each { entry -> - // A bare id, or an entry with no "required", is required: the tag fails to load without it. + // A bare id, or an entry with no "required", is required: the tag fails to load without it (ADR 0014). def id = entry instanceof Map ? entry.id : entry if (!(entry instanceof Map) || entry.required != false) found << "$name requires $id".toString() else if (!(id instanceof String) || !(id - ~/^#/).startsWith("$modId:")) found << "$name adds $id, not $modId's own".toString() diff --git a/plugin/src/test/java/io/github/_5thlayer/libworks/plugin/PlaysAloneTest.java b/plugin/src/test/java/io/github/_5thlayer/libworks/plugin/PlaysAloneTest.java index 3070ffd..5c20f07 100644 --- a/plugin/src/test/java/io/github/_5thlayer/libworks/plugin/PlaysAloneTest.java +++ b/plugin/src/test/java/io/github/_5thlayer/libworks/plugin/PlaysAloneTest.java @@ -74,6 +74,7 @@ void aPillarMayAddItsOwnOptionalEntriesToAnotherPillarsTag(@TempDir Path resourc "{\"replace\": false, \"values\": [{\"id\": \"atouchofwickedness:bailiff\", \"required\": false}]}"); write(resources.resolve("data/atouchofdarkness/tags/item/x.json"), "{\"values\": [{\"id\": \"#atouchofwickedness:seals\", \"required\": false}]}"); assertEquals(List.of(), wicked.namespaces(resources)); + assertEquals(List.of(), wicked.otherTags(resources)); } @Test @@ -87,13 +88,15 @@ void anOptionalTagFileThatRequiresReplacesOrAddsAnotherIdIsReported(@TempDir Pat write(resources.resolve("data/atouchofmadness/tags/entity_type/e.json"), "{\"values\": [{\"id\": \"minecraft:zombie\", \"required\": false}]}"); write(resources.resolve("data/atouchofmadness/tags/entity_type/f.json"), "[]"); write(resources.resolve("data/atouchofmadness/tags/entity_type/g.json"), "{\"values\": [], \"remove\": [\"atouchofmadness:x\"]}"); + write(resources.resolve("data/atouchofmadness/tags/h.json"), "{\"values\": [{\"id\": \"atouchofwickedness:bailiff\", \"required\": false}]}"); assertEquals(List.of("data/atouchofmadness/tags/entity_type/a.json requires atouchofwickedness:bailiff", "data/atouchofmadness/tags/entity_type/b.json requires atouchofwickedness:bailiff", "data/atouchofmadness/tags/entity_type/c.json requires atouchofwickedness:bailiff", "data/atouchofmadness/tags/entity_type/d.json replaces the tag", "data/atouchofmadness/tags/entity_type/e.json adds minecraft:zombie, not atouchofwickedness's own", "data/atouchofmadness/tags/entity_type/f.json is not a tag", - "data/atouchofmadness/tags/entity_type/g.json removes from the tag"), wicked.namespaces(resources)); + "data/atouchofmadness/tags/entity_type/g.json removes from the tag", + "data/atouchofmadness/tags/h.json is not a tag"), wicked.otherTags(resources)); } @Test @@ -102,7 +105,8 @@ void anotherPillarsAssetsOrDataOutsideItsTagsAreReported(@TempDir Path resources "{\"values\": [{\"id\": \"atouchofwickedness:bailiff\", \"required\": false}]}"); write(resources.resolve("data/atouchofmadness/recipe/x.json"), "{}"); write(resources.resolve("assets/atouchofmadness/lang/en_us.json"), "{}"); - assertEquals(List.of("assets/atouchofmadness", "data/atouchofmadness/recipe/x.json"), wicked.namespaces(resources)); + assertEquals(List.of("assets/atouchofmadness"), wicked.namespaces(resources)); + assertEquals(List.of("data/atouchofmadness/recipe/x.json"), wicked.otherTags(resources)); } @Test @@ -111,9 +115,11 @@ void optionalTagEntriesAreNoExceptionForTheShelvedColdAnotherSuiteOrFactoryWorks write(resources.resolve("data/atouchofcold/tags/item/x.json"), optional.formatted("atouchofwickedness")); write(resources.resolve("data/pipeworks/tags/item/x.json"), optional.formatted("atouchofwickedness")); assertEquals(List.of("data/atouchofcold", "data/pipeworks"), wicked.namespaces(resources)); + assertEquals(List.of(), wicked.otherTags(resources)); write(resources.resolve("data/fieldworks/tags/item/x.json"), optional.formatted("beltworks")); write(resources.resolve("data/atouchofmadness/tags/item/x.json"), optional.formatted("beltworks")); assertEquals(List.of("data/atouchofcold", "data/atouchofmadness", "data/fieldworks", "data/pipeworks"), belt.namespaces(resources)); + assertEquals(List.of(), belt.otherTags(resources)); } @Test From a57c99ce47af82b0555f86fb4e70154abb0f9c61 Mon Sep 17 00:00:00 2001 From: Andrea D'Amico Date: Tue, 27 Oct 2026 13:13:44 +0100 Subject: [PATCH 4/7] fix(plugin): say why each file in another pillar's data folder fails A file outside tags/ now names that, an empty remove list fails as any remove does, and a test pins that the runtime takes no exception. Co-Authored-By: Claude Opus 5.5 --- docs/plugin.md | 2 +- .../libworks/plugin/PlaysAlone.groovy | 20 ++++++++----------- .../libworks/plugin/PlaysAloneTest.java | 14 ++++++++++++- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/docs/plugin.md b/docs/plugin.md index 6bbdf6a..889b90a 100644 --- a/docs/plugin.md +++ b/docs/plugin.md @@ -31,7 +31,7 @@ The plugin adds a `gametest` source set to the mod, which the dev runs load and `buildGametestStructures` writes the default `gametest/platform.nbt` into `src/gametest/resources/data//structure/`, leaves an identical one alone, and fails naming the file when the Module has committed a different one: a Module needing another structure commits it (ADR 0003). -`checkPlaysAlone`, which `check` runs, fails when the Module ships something that names another Module of its suite (FactoryWorks ADR-0127, A Touch Of ADR-0002, ADR 0005, ADR 0013, ADR 0014): an id in its namespace, such as `pipeworks:pipe`, in a resource or in Java source; an `assets/` or `data/` folder; the namespace as a string in Java source, `"pipeworks"`; or a required dependency on it in `neoforge.mods.toml`, where an optional one is allowed. A structure's `.nbt` is read unzipped, so the block ids saved in it count. The resources are read as `processResources` leaves them, so generated ones and the expanded mods.toml count; the code is `src/main`'s Java source, and the `gametest` source set is not read. The suites are `PlaysAlone.SUITES`, and the Module's suite is the one whose list holds its `mod_id`. FactoryWorks' Modules are Beltworks, Craftworks, Fieldworks, Gearworks, Groundworks, Pipeworks, Voidworks and Wireworks: every one but the Module built and Groundworks is forbidden, and the retired `factoryworks`. A Touch Of's are its Runtime, `atouchof`, and the Pillars `atouchofdarkness`, `atouchofmadness` and `atouchofwickedness`: every one but the Pillar built and the Runtime is forbidden, and the shelved `atouchofcold` (A Touch Of #5). A Pillar may still ship a tag file under another Pillar's `data//tags/`, to add entries to that Pillar's tag, when `replace` is absent or false and every entry is an object with `"required": false` naming one of its own ids or tags, such as Wickedness's `data/atouchofmadness/tags/entity_type/unsettling.json` holding `{"id": "atouchofwickedness:bailiff", "required": false}` (A Touch Of ADR-0002, ADR 0014). Each other file in that folder is reported, with why: a bare or required entry, `replace: true`, a NeoForge `remove` list, an id not its own, or a file that is not a tag. FactoryWorks has no such exception, nor does the Runtime, the shelved `atouchofcold` or another suite's namespace. A Module is also checked against every other suite's Modules, bases included: a Pillar may not name `pipeworks:pipe` or `groundworks:wrench`, nor a FactoryWorks Module `atouchof:meter`. A mod no suite lists, such as the template's `examplelib`, is checked against every suite's Modules but Groundworks and `atouchof`. A new Module is added to its suite there, and reaches the others by a plugin release they move to. The failure lists each finding under its folder, such as `build/resources/main/data/beltworks/recipe/x.json names gearworks:gear`. +`checkPlaysAlone`, which `check` runs, fails when the Module ships something that names another Module of its suite (FactoryWorks ADR-0127, A Touch Of ADR-0002, ADR 0005, ADR 0013, ADR 0014): an id in its namespace, such as `pipeworks:pipe`, in a resource or in Java source; an `assets/` or `data/` folder; the namespace as a string in Java source, `"pipeworks"`; or a required dependency on it in `neoforge.mods.toml`, where an optional one is allowed. A structure's `.nbt` is read unzipped, so the block ids saved in it count. The resources are read as `processResources` leaves them, so generated ones and the expanded mods.toml count; the code is `src/main`'s Java source, and the `gametest` source set is not read. The suites are `PlaysAlone.SUITES`, and the Module's suite is the one whose list holds its `mod_id`. FactoryWorks' Modules are Beltworks, Craftworks, Fieldworks, Gearworks, Groundworks, Pipeworks, Voidworks and Wireworks: every one but the Module built and Groundworks is forbidden, and the retired `factoryworks`. A Touch Of's are its Runtime, `atouchof`, and the Pillars `atouchofdarkness`, `atouchofmadness` and `atouchofwickedness`: every one but the Pillar built and the Runtime is forbidden, and the shelved `atouchofcold` (A Touch Of #5). A Pillar may still ship a tag file under another Pillar's `data//tags/`, to add entries to that Pillar's tag, when `replace` is absent or false and every entry is an object with `"required": false` naming one of its own ids or tags, such as Wickedness's `data/atouchofmadness/tags/entity_type/unsettling.json` holding `{"id": "atouchofwickedness:bailiff", "required": false}` (A Touch Of ADR-0002, ADR 0014). Each other file in that folder is reported, with why: a bare or required entry, `replace: true`, a NeoForge `remove` list, an id not its own, a file that is not a tag, or one outside `tags/`. FactoryWorks has no such exception, nor does the Runtime, the shelved `atouchofcold` or another suite's namespace. A Module is also checked against every other suite's Modules, bases included: a Pillar may not name `pipeworks:pipe` or `groundworks:wrench`, nor a FactoryWorks Module `atouchof:meter`. A mod no suite lists, such as the template's `examplelib`, is checked against every suite's Modules but Groundworks and `atouchof`. A new Module is added to its suite there, and reaches the others by a plugin release they move to. The failure lists each finding under its folder, such as `build/resources/main/data/beltworks/recipe/x.json names gearworks:gear`. ### Moving to 0.4.0 diff --git a/plugin/src/main/groovy/io/github/_5thlayer/libworks/plugin/PlaysAlone.groovy b/plugin/src/main/groovy/io/github/_5thlayer/libworks/plugin/PlaysAlone.groovy index c37dbd7..61cdb2f 100644 --- a/plugin/src/main/groovy/io/github/_5thlayer/libworks/plugin/PlaysAlone.groovy +++ b/plugin/src/main/groovy/io/github/_5thlayer/libworks/plugin/PlaysAlone.groovy @@ -73,7 +73,7 @@ final class PlaysAlone { /** The suite whose Modules hold {@code modId}, or null for a mod no suite lists, such as the template's own. */ final Suite suite - /** The Module built. */ + /** The Module built, whose own ids alone an optional entry in another Module's tag may name (ADR 0014). */ final String modId /** @@ -124,7 +124,7 @@ final class PlaysAlone { List namespaces(Path resources) { def found = [] ['assets', 'data'].each { kind -> - forbiddenFolders(resources, kind).findAll { kind != 'data' || !takesTagsOf(it) }.each { found << "$kind/$it".toString() } + forbiddenFolders(resources, kind).findAll { kind != 'data' || !suite?.takesOptionalTagEntries(modId, it) }.each { found << "$kind/$it".toString() } } found } @@ -135,7 +135,7 @@ final class PlaysAlone { * a {@code replace} and a {@code remove}. */ List otherTags(Path resources) { - forbiddenFolders(resources, 'data').findAll { takesTagsOf(it) }.collectMany { notOptionalTags(resources, resources.resolve("data/$it")) } + forbiddenFolders(resources, 'data').findAll { suite?.takesOptionalTagEntries(modId, it) }.collectMany { tagFindings(resources, resources.resolve("data/$it")) } } private List forbiddenFolders(Path resources, String kind) { @@ -144,26 +144,22 @@ final class PlaysAlone { Files.list(dir).withCloseable { it.map { it.fileName.toString() }.filter { forbidden.contains(it) }.sorted().toList() } } - private boolean takesTagsOf(String namespace) { - suite?.takesOptionalTagEntries(modId, namespace) - } - - private List notOptionalTags(Path resources, Path namespace) { + private List tagFindings(Path resources, Path namespace) { def tags = namespace.resolve('tags') files(namespace).collectMany { file -> def name = relative(resources, file) - if (!file.startsWith(tags) || !file.toString().endsWith('.json')) return [name] + if (!file.startsWith(tags)) return ["$name is outside tags/".toString()] def tag = null try { - tag = new JsonSlurper().parse(file.toFile()) + if (file.toString().endsWith('.json')) tag = new JsonSlurper().parse(file.toFile()) } catch (ignored) { } - // A tag file sits in its registry's folder, tags//; vanilla reads none directly under tags/. + // A tag file sits in its registry's folder, tags//; vanilla reads none directly under tags/ (ADR 0014). if (file.parent == tags || !(tag instanceof Map) || !(tag.values instanceof List)) return ["$name is not a tag".toString()] def found = [] if (tag.replace) found << "$name replaces the tag".toString() // NeoForge reads a tag's "remove" list too, which would take entries out of the other Module's tag (ADR 0014). - if (tag.remove) found << "$name removes from the tag".toString() + if (tag.containsKey('remove')) found << "$name removes from the tag".toString() tag.values.each { entry -> // A bare id, or an entry with no "required", is required: the tag fails to load without it (ADR 0014). def id = entry instanceof Map ? entry.id : entry diff --git a/plugin/src/test/java/io/github/_5thlayer/libworks/plugin/PlaysAloneTest.java b/plugin/src/test/java/io/github/_5thlayer/libworks/plugin/PlaysAloneTest.java index 5c20f07..a0dbdcf 100644 --- a/plugin/src/test/java/io/github/_5thlayer/libworks/plugin/PlaysAloneTest.java +++ b/plugin/src/test/java/io/github/_5thlayer/libworks/plugin/PlaysAloneTest.java @@ -88,6 +88,8 @@ void anOptionalTagFileThatRequiresReplacesOrAddsAnotherIdIsReported(@TempDir Pat write(resources.resolve("data/atouchofmadness/tags/entity_type/e.json"), "{\"values\": [{\"id\": \"minecraft:zombie\", \"required\": false}]}"); write(resources.resolve("data/atouchofmadness/tags/entity_type/f.json"), "[]"); write(resources.resolve("data/atouchofmadness/tags/entity_type/g.json"), "{\"values\": [], \"remove\": [\"atouchofmadness:x\"]}"); + write(resources.resolve("data/atouchofmadness/tags/entity_type/i.json"), "{\"values\": [], \"remove\": []}"); + write(resources.resolve("data/atouchofmadness/tags/entity_type/j.txt"), "atouchofwickedness:bailiff"); write(resources.resolve("data/atouchofmadness/tags/h.json"), "{\"values\": [{\"id\": \"atouchofwickedness:bailiff\", \"required\": false}]}"); assertEquals(List.of("data/atouchofmadness/tags/entity_type/a.json requires atouchofwickedness:bailiff", "data/atouchofmadness/tags/entity_type/b.json requires atouchofwickedness:bailiff", @@ -96,6 +98,8 @@ void anOptionalTagFileThatRequiresReplacesOrAddsAnotherIdIsReported(@TempDir Pat "data/atouchofmadness/tags/entity_type/e.json adds minecraft:zombie, not atouchofwickedness's own", "data/atouchofmadness/tags/entity_type/f.json is not a tag", "data/atouchofmadness/tags/entity_type/g.json removes from the tag", + "data/atouchofmadness/tags/entity_type/i.json removes from the tag", + "data/atouchofmadness/tags/entity_type/j.txt is not a tag", "data/atouchofmadness/tags/h.json is not a tag"), wicked.otherTags(resources)); } @@ -106,7 +110,15 @@ void anotherPillarsAssetsOrDataOutsideItsTagsAreReported(@TempDir Path resources write(resources.resolve("data/atouchofmadness/recipe/x.json"), "{}"); write(resources.resolve("assets/atouchofmadness/lang/en_us.json"), "{}"); assertEquals(List.of("assets/atouchofmadness"), wicked.namespaces(resources)); - assertEquals(List.of("data/atouchofmadness/recipe/x.json"), wicked.otherTags(resources)); + assertEquals(List.of("data/atouchofmadness/recipe/x.json is outside tags/"), wicked.otherTags(resources)); + } + + @Test + void theRuntimeMayAddNoEntryToAPillarsTag(@TempDir Path resources) throws IOException { + write(resources.resolve("data/atouchofmadness/tags/item/x.json"), "{\"values\": [{\"id\": \"atouchof:x\", \"required\": false}]}"); + PlaysAlone runtime = new PlaysAlone("atouchof"); + assertEquals(List.of("data/atouchofmadness"), runtime.namespaces(resources)); + assertEquals(List.of(), runtime.otherTags(resources)); } @Test From f23755647b48b36ee7cbbc35902fb4c5347c2d82 Mon Sep 17 00:00:00 2001 From: Andrea D'Amico Date: Tue, 27 Oct 2026 13:20:37 +0100 Subject: [PATCH 5/7] fix(plugin): name each malformed field in another pillar's tag The tag-file checks move to OptionalTagFile, and each suite names what a module may ship in another module's tags. Invalid JSON, a replace that is not a boolean, a remove with no values and an entry with no id each say so, and an optional entry of another pillar's id is reported once. Co-Authored-By: Claude Opus 5.5 --- .../libworks/plugin/OptionalTagFile.groovy | 52 +++++++++++++++++++ .../libworks/plugin/PlaysAlone.groovy | 48 ++++++----------- .../libworks/plugin/PlaysAloneTest.java | 33 ++++++++++++ 3 files changed, 101 insertions(+), 32 deletions(-) create mode 100644 plugin/src/main/groovy/io/github/_5thlayer/libworks/plugin/OptionalTagFile.groovy diff --git a/plugin/src/main/groovy/io/github/_5thlayer/libworks/plugin/OptionalTagFile.groovy b/plugin/src/main/groovy/io/github/_5thlayer/libworks/plugin/OptionalTagFile.groovy new file mode 100644 index 0000000..3e05a6f --- /dev/null +++ b/plugin/src/main/groovy/io/github/_5thlayer/libworks/plugin/OptionalTagFile.groovy @@ -0,0 +1,52 @@ +// SPDX-FileCopyrightText: 2026 5thlayer +// SPDX-License-Identifier: MIT + +package io.github._5thlayer.libworks.plugin + +import groovy.json.JsonOutput +import groovy.json.JsonSlurper + +import java.nio.file.Path + +/** + * A file a Module ships in another Module's data folder, which passes only as a tag of optional entries of the Module's own ids that keeps + * the tag's other entries (libworks ADR 0014, A Touch Of ADR-0002). + */ +final class OptionalTagFile { + + private OptionalTagFile() { + } + + /** Why {@code file}, under the other Module's {@code namespace} folder and shown as {@code name}, is not such a tag; empty when it is. */ + static List findings(Path namespace, Path file, String name, String modId, List forbidden) { + def tags = namespace.resolve('tags') + if (!file.startsWith(tags)) return ["$name is outside tags/".toString()] + // A tag file sits in its registry's folder, tags//; vanilla reads none directly under tags/. + if (file.parent == tags || !file.toString().endsWith('.json')) return ["$name is not a tag".toString()] + def tag + try { + tag = new JsonSlurper().parse(file.toFile()) + } catch (Exception ignored) { + return ["$name is not valid JSON".toString()] + } + if (!(tag instanceof Map)) return ["$name is not a tag".toString()] + def found = [] + // NeoForge reads a tag's "remove" list too, which would take entries out of the other Module's tag. + if (tag.containsKey('remove')) found << "$name removes from the tag".toString() + if (!(tag.values instanceof List)) return found ?: ["$name is not a tag".toString()] + if (tag.replace == true) found << "$name replaces the tag".toString() + else if (tag.containsKey('replace') && tag.replace != false) found << "$name sets replace to ${JsonOutput.toJson(tag.replace)}, not a boolean".toString() + tag.values.each { entry -> + def id = entry instanceof Map ? entry.id : entry + // A bare id, or an entry with no "required", is required: the tag fails to load without it. + if (!(entry instanceof Map) || entry.required != false) found << "$name requires $id".toString() + else if (!(id instanceof String)) found << "$name has an entry with no id".toString() + else { + def namespaceOf = (id - ~/^#/).split(':')[0] + // An id in a forbidden namespace is already named by PlaysAlone.ids. + if (namespaceOf != modId && !forbidden.contains(namespaceOf)) found << "$name adds $id, not $modId's own".toString() + } + } + found + } +} diff --git a/plugin/src/main/groovy/io/github/_5thlayer/libworks/plugin/PlaysAlone.groovy b/plugin/src/main/groovy/io/github/_5thlayer/libworks/plugin/PlaysAlone.groovy index 61cdb2f..c556144 100644 --- a/plugin/src/main/groovy/io/github/_5thlayer/libworks/plugin/PlaysAlone.groovy +++ b/plugin/src/main/groovy/io/github/_5thlayer/libworks/plugin/PlaysAlone.groovy @@ -3,8 +3,6 @@ package io.github._5thlayer.libworks.plugin -import groovy.json.JsonSlurper - import java.nio.charset.StandardCharsets import java.nio.file.Files import java.nio.file.Path @@ -18,9 +16,17 @@ import java.util.zip.GZIPInputStream */ final class PlaysAlone { + /** What a suite lets a Module ship in another Module's tags (ADR 0014). */ + static enum OtherModulesTags { + /** Nothing: another Module's data folder is forbidden whole. */ + NONE, + /** A tag of optional entries of the Module's own ids, which keeps the tag's other entries. */ + OPTIONAL_ENTRIES + } + /** * One suite: what it calls its Modules, the ADR that has them play alone, its Modules, the base among them that every one may require, - * the retired ids none may name, and whether a Module may add optional entries to another Module's tags (ADR 0014). + * the retired ids none may name, and what a Module may ship in another Module's tags (ADR 0014). */ static final class Suite { final String term @@ -28,15 +34,15 @@ final class PlaysAlone { final String base final List modules final List retired - final boolean optionalTagEntries + final OtherModulesTags otherModulesTags - Suite(String term, String rule, String base, List modules, List retired, boolean optionalTagEntries = false) { + Suite(String term, String rule, String base, List modules, List retired, OtherModulesTags otherModulesTags) { this.term = term this.rule = rule this.base = base this.modules = modules this.retired = retired - this.optionalTagEntries = optionalTagEntries + this.otherModulesTags = otherModulesTags } /** Every Module but {@code modId} and the base, and the retired ids. */ @@ -46,7 +52,7 @@ final class PlaysAlone { /** Whether {@code modId} may add optional entries to {@code namespace}'s tags: another Module of this suite, the base never adding (ADR 0014). */ boolean takesOptionalTagEntries(String modId, String namespace) { - optionalTagEntries && modId != base && namespace in modules + otherModulesTags == OtherModulesTags.OPTIONAL_ENTRIES && modId != base && namespace in modules } /** Every Module, the base included, and the retired ids: what a Module of another suite may not name. */ @@ -62,9 +68,9 @@ final class PlaysAlone { */ static final List SUITES = [ new Suite('Module', 'FactoryWorks ADR-0127', 'groundworks', - ['beltworks', 'craftworks', 'fieldworks', 'gearworks', 'groundworks', 'pipeworks', 'voidworks', 'wireworks'], ['factoryworks']), + ['beltworks', 'craftworks', 'fieldworks', 'gearworks', 'groundworks', 'pipeworks', 'voidworks', 'wireworks'], ['factoryworks'], OtherModulesTags.NONE), new Suite('Pillar', 'A Touch Of ADR-0002', 'atouchof', - ['atouchof', 'atouchofdarkness', 'atouchofmadness', 'atouchofwickedness'], ['atouchofcold'], /* optionalTagEntries */ true), + ['atouchof', 'atouchofdarkness', 'atouchofmadness', 'atouchofwickedness'], ['atouchofcold'], OtherModulesTags.OPTIONAL_ENTRIES), ] private static final Pattern DEPENDENCY_MOD_ID = ~/(?m)^\s*modId\s*=\s*"([^"]+)"/ @@ -145,29 +151,7 @@ final class PlaysAlone { } private List tagFindings(Path resources, Path namespace) { - def tags = namespace.resolve('tags') - files(namespace).collectMany { file -> - def name = relative(resources, file) - if (!file.startsWith(tags)) return ["$name is outside tags/".toString()] - def tag = null - try { - if (file.toString().endsWith('.json')) tag = new JsonSlurper().parse(file.toFile()) - } catch (ignored) { - } - // A tag file sits in its registry's folder, tags//; vanilla reads none directly under tags/ (ADR 0014). - if (file.parent == tags || !(tag instanceof Map) || !(tag.values instanceof List)) return ["$name is not a tag".toString()] - def found = [] - if (tag.replace) found << "$name replaces the tag".toString() - // NeoForge reads a tag's "remove" list too, which would take entries out of the other Module's tag (ADR 0014). - if (tag.containsKey('remove')) found << "$name removes from the tag".toString() - tag.values.each { entry -> - // A bare id, or an entry with no "required", is required: the tag fails to load without it (ADR 0014). - def id = entry instanceof Map ? entry.id : entry - if (!(entry instanceof Map) || entry.required != false) found << "$name requires $id".toString() - else if (!(id instanceof String) || !(id - ~/^#/).startsWith("$modId:")) found << "$name adds $id, not $modId's own".toString() - } - found - } + files(namespace).collectMany { OptionalTagFile.findings(namespace, it, relative(resources, it), modId, forbidden) } } /** Each string in the Java source under {@code code} that is a forbidden namespace, as an id built in code names it. */ diff --git a/plugin/src/test/java/io/github/_5thlayer/libworks/plugin/PlaysAloneTest.java b/plugin/src/test/java/io/github/_5thlayer/libworks/plugin/PlaysAloneTest.java index a0dbdcf..b360c17 100644 --- a/plugin/src/test/java/io/github/_5thlayer/libworks/plugin/PlaysAloneTest.java +++ b/plugin/src/test/java/io/github/_5thlayer/libworks/plugin/PlaysAloneTest.java @@ -103,6 +103,39 @@ void anOptionalTagFileThatRequiresReplacesOrAddsAnotherIdIsReported(@TempDir Pat "data/atouchofmadness/tags/h.json is not a tag"), wicked.otherTags(resources)); } + @Test + void aTagInASubfolderOfItsRegistryIsATag(@TempDir Path resources) throws IOException { + write(resources.resolve("data/atouchofmadness/tags/entity_type/sub/x.json"), + "{\"values\": [{\"id\": \"atouchofwickedness:bailiff\", \"required\": false}]}"); + assertEquals(List.of(), wicked.otherTags(resources)); + } + + @Test + void aFileThatIsNoTagOrHasAMalformedFieldSaysWhy(@TempDir Path resources) throws IOException { + Path tags = resources.resolve("data/atouchofmadness/tags/entity_type"); + write(tags.resolve("a.json"), "{\"values\": ["); + write(tags.resolve("b.json"), ""); + write(tags.resolve("c.json"), "{}"); + write(tags.resolve("d.json"), "{\"replace\": \"false\", \"values\": []}"); + write(tags.resolve("e.json"), "{\"remove\": [\"atouchofmadness:x\"]}"); + write(tags.resolve("f.json"), "{\"values\": [{\"required\": false}, {\"id\": null, \"required\": false}, {\"id\": 3, \"required\": false}]}"); + assertEquals(List.of("data/atouchofmadness/tags/entity_type/a.json is not valid JSON", + "data/atouchofmadness/tags/entity_type/b.json is not valid JSON", + "data/atouchofmadness/tags/entity_type/c.json is not a tag", + "data/atouchofmadness/tags/entity_type/d.json sets replace to \"false\", not a boolean", + "data/atouchofmadness/tags/entity_type/e.json removes from the tag", + "data/atouchofmadness/tags/entity_type/f.json has an entry with no id", + "data/atouchofmadness/tags/entity_type/f.json has an entry with no id", + "data/atouchofmadness/tags/entity_type/f.json has an entry with no id"), wicked.otherTags(resources)); + } + + @Test + void anOptionalEntryOfAnotherPillarsIdIsReportedOnce(@TempDir Path resources) throws IOException { + write(resources.resolve("data/atouchofmadness/tags/entity_type/x.json"), + "{\"values\": [{\"id\": \"atouchofdarkness:shade\", \"required\": false}]}"); + assertEquals(List.of("data/atouchofmadness/tags/entity_type/x.json names atouchofdarkness:shade"), wicked.resources(resources)); + } + @Test void anotherPillarsAssetsOrDataOutsideItsTagsAreReported(@TempDir Path resources) throws IOException { write(resources.resolve("data/atouchofmadness/tags/entity_type/unsettling.json"), From 0acf59092dd1b24745e21c527db8a2630022f97b Mon Sep 17 00:00:00 2001 From: Andrea D'Amico Date: Tue, 27 Oct 2026 13:20:37 +0100 Subject: [PATCH 6/7] docs(adr): say how a shelved cold returns and why 0.4.5 is a patch Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 +- ...optional-entries-to-another-pillars-tag.md | 32 ++++++++++++------- docs/plugin.md | 2 +- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9fbc76f..6d3dfeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ Written for Consumers: what a mod building against Example Module can use, or wi ## Unreleased -- `libworks-plugin` 0.4.5: `checkPlaysAlone` knows A Touch Of's Pillars as `atouchofdarkness`, `atouchofmadness` and `atouchofwickedness`. The shelved `atouchofcold` is retired, so no Pillar or FactoryWorks Module may name it (A Touch Of #5, #6). A Pillar may add entries to another Pillar's tag with a file under `data//tags/` whose `replace` is absent or false and whose every entry is `{"id": "", "required": false}`. Any other file in that namespace still fails, and the failure says why (ADR 0014, A Touch Of ADR-0002). FactoryWorks Modules get no such exception. A Module edits nothing. +- `libworks-plugin` 0.4.5: `checkPlaysAlone` knows A Touch Of's Pillars as `atouchofdarkness`, `atouchofmadness` and `atouchofwickedness`. The shelved `atouchofcold` is retired, so no Pillar or FactoryWorks Module may name it (A Touch Of #5, #6). A Pillar may add entries to another Pillar's tag with a file under `data//tags/` whose `replace` is absent or false and whose every entry is `{"id": "", "required": false}`. Any other file in that namespace still fails, and the failure says why (ADR 0014, A Touch Of ADR-0002). FactoryWorks Modules get no such exception. Forbidding `atouchofcold` and `atouchofwickedness` tightens the check, but no Module ships either, so it is a patch, as 0.4.4 was (ADR 0001). A Module edits nothing. - `libworks-plugin` 0.4.4: `checkPlaysAlone` also checks a Module against every other suite's Modules, bases included (ADR 0013): a Pillar may not name a FactoryWorks Module, Groundworks included, and a FactoryWorks Module may not name a Pillar or A Touch Of's Runtime, `atouchof`. 0.4.3 let a Pillar name a FactoryWorks Module and the reverse. A mod no suite lists is still checked against every suite's Modules but Groundworks and `atouchof`. A Module edits nothing: none names the other suite. - `libworks-plugin` 0.4.3: `checkPlaysAlone` checks a Module against its own suite's Modules, which its `mod_id` picks (ADR 0013). A Touch Of's Pillars, `atouchofcold`, `atouchofdarkness` and `atouchofmadness`, are checked against one another and may name their Runtime, `atouchof`, and no longer against FactoryWorks' Modules. A FactoryWorks Module's check is unchanged. A mod no suite lists is checked against every suite's Modules but Groundworks and `atouchof`. A Module edits nothing. - `libworks-runtime` 0.1.12: libworks-gametest's `GalleryCheck.MAX_SCENES` is 24, up from 16, so `builds` and `withPack` take a gallery of up to 24 scenes. diff --git a/docs/adr/0014-a-pillar-may-add-optional-entries-to-another-pillars-tag.md b/docs/adr/0014-a-pillar-may-add-optional-entries-to-another-pillars-tag.md index 90d4972..899aa32 100644 --- a/docs/adr/0014-a-pillar-may-add-optional-entries-to-another-pillars-tag.md +++ b/docs/adr/0014-a-pillar-may-add-optional-entries-to-another-pillars-tag.md @@ -9,18 +9,28 @@ tag. It does this with a vanilla tag file that has `replace: false` and marks ev `required: false`. Without the other Pillar the tag is never read, so neither Pillar requires the other. The first use is A Touch of Wickedness shipping `data/atouchofmadness/tags/entity_type/unsettling.json`, which adds its Bailiff. `checkPlaysAlone` -(ADR 0005, ADR 0013) failed any `data/` folder in another Pillar's namespace, so that file failed. +(ADR 0005, ADR 0013) failed any `data/` folder in another Pillar's namespace, so that file +failed. -**Decision.** A suite may take optional tag entries. A Touch Of does and FactoryWorks does not, -since FactoryWorks ADR-0127 allows none. In such a suite, a Module other than the base may ship -files under another Module's `data//tags/`. Each must be a tag whose `replace` is absent or -false, and whose every entry is an object with `"required": false` naming one of the Module's own -ids or tags. The scan reads that namespace's data folder file by file. It reports each file outside -`tags/` and each file that is not a tag, and for a tag it names each bare or required entry, a -`replace: true`, a NeoForge `remove` list, which would take entries out of the other tag, and each id -that is not the Module's own. The exception does not cover an -`assets/` folder, the base, a retired id such as the shelved `atouchofcold`, or another -suite's namespace. +**Decision.** Each suite states what a Module may ship in another Module's tags: A Touch Of takes +optional entries, and FactoryWorks takes none, since FactoryWorks ADR-0127 allows none. In a suite +that takes them, a Module other than the base may ship files under another Module's +`data//tags//`. Each must be a tag whose `replace` is absent or false, with no +NeoForge `remove` list, which would take entries out of the other tag, and whose every entry is an +object with `"required": false` naming one of the Module's own ids or tags. The scan reads that +namespace's data folder file by file, and reports each file that fails with why: outside `tags/`, +not a tag or not valid JSON, a bare or required entry, an entry with no id, a `replace` that is +true or not a boolean, a `remove`, or an id that is not the Module's own. The exception does not +cover an `assets/` folder, the base, a retired id such as the shelved `atouchofcold`, or +another suite's namespace. + +`atouchofcold` is retired while A Touch of Cold is shelved (A Touch Of #5), so its own build would +fail: no suite lists it, and its ids are forbidden. Reviving it means a patch release that moves it +from the suite's retired ids back to its Pillars. + +**Versioning.** Forbidding `atouchofcold` and `atouchofwickedness` tightens the check, but no +Module ships either, so none has to edit its build, and the release is a patch (ADR 0001), as +0.4.4's tightening was (ADR 0013). **Considered.** Allowing any id an optional entry names, such as `minecraft:zombie`: a Pillar could then retune another Pillar's tag with vanilla content, which goes further than ADR-0002's diff --git a/docs/plugin.md b/docs/plugin.md index 889b90a..6eb3883 100644 --- a/docs/plugin.md +++ b/docs/plugin.md @@ -31,7 +31,7 @@ The plugin adds a `gametest` source set to the mod, which the dev runs load and `buildGametestStructures` writes the default `gametest/platform.nbt` into `src/gametest/resources/data//structure/`, leaves an identical one alone, and fails naming the file when the Module has committed a different one: a Module needing another structure commits it (ADR 0003). -`checkPlaysAlone`, which `check` runs, fails when the Module ships something that names another Module of its suite (FactoryWorks ADR-0127, A Touch Of ADR-0002, ADR 0005, ADR 0013, ADR 0014): an id in its namespace, such as `pipeworks:pipe`, in a resource or in Java source; an `assets/` or `data/` folder; the namespace as a string in Java source, `"pipeworks"`; or a required dependency on it in `neoforge.mods.toml`, where an optional one is allowed. A structure's `.nbt` is read unzipped, so the block ids saved in it count. The resources are read as `processResources` leaves them, so generated ones and the expanded mods.toml count; the code is `src/main`'s Java source, and the `gametest` source set is not read. The suites are `PlaysAlone.SUITES`, and the Module's suite is the one whose list holds its `mod_id`. FactoryWorks' Modules are Beltworks, Craftworks, Fieldworks, Gearworks, Groundworks, Pipeworks, Voidworks and Wireworks: every one but the Module built and Groundworks is forbidden, and the retired `factoryworks`. A Touch Of's are its Runtime, `atouchof`, and the Pillars `atouchofdarkness`, `atouchofmadness` and `atouchofwickedness`: every one but the Pillar built and the Runtime is forbidden, and the shelved `atouchofcold` (A Touch Of #5). A Pillar may still ship a tag file under another Pillar's `data//tags/`, to add entries to that Pillar's tag, when `replace` is absent or false and every entry is an object with `"required": false` naming one of its own ids or tags, such as Wickedness's `data/atouchofmadness/tags/entity_type/unsettling.json` holding `{"id": "atouchofwickedness:bailiff", "required": false}` (A Touch Of ADR-0002, ADR 0014). Each other file in that folder is reported, with why: a bare or required entry, `replace: true`, a NeoForge `remove` list, an id not its own, a file that is not a tag, or one outside `tags/`. FactoryWorks has no such exception, nor does the Runtime, the shelved `atouchofcold` or another suite's namespace. A Module is also checked against every other suite's Modules, bases included: a Pillar may not name `pipeworks:pipe` or `groundworks:wrench`, nor a FactoryWorks Module `atouchof:meter`. A mod no suite lists, such as the template's `examplelib`, is checked against every suite's Modules but Groundworks and `atouchof`. A new Module is added to its suite there, and reaches the others by a plugin release they move to. The failure lists each finding under its folder, such as `build/resources/main/data/beltworks/recipe/x.json names gearworks:gear`. +`checkPlaysAlone`, which `check` runs, fails when the Module ships something that names another Module of its suite (FactoryWorks ADR-0127, A Touch Of ADR-0002, ADR 0005, ADR 0013, ADR 0014): an id in its namespace, such as `pipeworks:pipe`, in a resource or in Java source; an `assets/` or `data/` folder; the namespace as a string in Java source, `"pipeworks"`; or a required dependency on it in `neoforge.mods.toml`, where an optional one is allowed. A structure's `.nbt` is read unzipped, so the block ids saved in it count. The resources are read as `processResources` leaves them, so generated ones and the expanded mods.toml count; the code is `src/main`'s Java source, and the `gametest` source set is not read. The suites are `PlaysAlone.SUITES`, and the Module's suite is the one whose list holds its `mod_id`. FactoryWorks' Modules are Beltworks, Craftworks, Fieldworks, Gearworks, Groundworks, Pipeworks, Voidworks and Wireworks: every one but the Module built and Groundworks is forbidden, and the retired `factoryworks`. A Touch Of's are its Runtime, `atouchof`, and the Pillars `atouchofdarkness`, `atouchofmadness` and `atouchofwickedness`: every one but the Pillar built and the Runtime is forbidden, and the shelved `atouchofcold` (A Touch Of #5). A Pillar may still ship a tag file under another Pillar's `data//tags/`, to add entries to that Pillar's tag, when `replace` is absent or false and every entry is an object with `"required": false` naming one of its own ids or tags, such as Wickedness's `data/atouchofmadness/tags/entity_type/unsettling.json` holding `{"id": "atouchofwickedness:bailiff", "required": false}` (A Touch Of ADR-0002, ADR 0014). Each other file in that folder is reported, with why: outside `tags/`, not a tag or not valid JSON, a bare or required entry, an entry with no id, a `replace` that is true or not a boolean, a NeoForge `remove` list, or an id not its own. While `atouchofcold` is retired its own build would fail, so reviving it means a patch release moving it back to the Pillars. FactoryWorks has no such exception, nor does the Runtime, the shelved `atouchofcold` or another suite's namespace. A Module is also checked against every other suite's Modules, bases included: a Pillar may not name `pipeworks:pipe` or `groundworks:wrench`, nor a FactoryWorks Module `atouchof:meter`. A mod no suite lists, such as the template's `examplelib`, is checked against every suite's Modules but Groundworks and `atouchof`. A new Module is added to its suite there, and reaches the others by a plugin release they move to. The failure lists each finding under its folder, such as `build/resources/main/data/beltworks/recipe/x.json names gearworks:gear`. ### Moving to 0.4.0 From 0e2890aa558f94438a6953f3c48310068c3c7139 Mon Sep 17 00:00:00 2001 From: Andrea D'Amico Date: Tue, 27 Oct 2026 13:25:55 +0100 Subject: [PATCH 7/7] fix(plugin): read a bare tag entry id as minecraft's An id with no namespace names minecraft:, so it is no longer taken as the pillar's own. A missing or non-string id is reported as such before the required check. Co-Authored-By: Claude Opus 5.5 --- .../libworks/plugin/OptionalTagFile.groovy | 20 +++++++++++++------ .../libworks/plugin/PlaysAloneTest.java | 8 +++++++- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/plugin/src/main/groovy/io/github/_5thlayer/libworks/plugin/OptionalTagFile.groovy b/plugin/src/main/groovy/io/github/_5thlayer/libworks/plugin/OptionalTagFile.groovy index 3e05a6f..b26528f 100644 --- a/plugin/src/main/groovy/io/github/_5thlayer/libworks/plugin/OptionalTagFile.groovy +++ b/plugin/src/main/groovy/io/github/_5thlayer/libworks/plugin/OptionalTagFile.groovy @@ -38,14 +38,22 @@ final class OptionalTagFile { else if (tag.containsKey('replace') && tag.replace != false) found << "$name sets replace to ${JsonOutput.toJson(tag.replace)}, not a boolean".toString() tag.values.each { entry -> def id = entry instanceof Map ? entry.id : entry + if (!(id instanceof String)) { + found << "$name has an entry with no id".toString() + return + } // A bare id, or an entry with no "required", is required: the tag fails to load without it. - if (!(entry instanceof Map) || entry.required != false) found << "$name requires $id".toString() - else if (!(id instanceof String)) found << "$name has an entry with no id".toString() - else { - def namespaceOf = (id - ~/^#/).split(':')[0] - // An id in a forbidden namespace is already named by PlaysAlone.ids. - if (namespaceOf != modId && !forbidden.contains(namespaceOf)) found << "$name adds $id, not $modId's own".toString() + if (!(entry instanceof Map) || entry.required != false) { + found << "$name requires $id".toString() + return } + def tagRef = id.startsWith('#') ? '#' : '' + def path = id - ~/^#/ + // Vanilla reads an id with no namespace as minecraft's. + def full = path.contains(':') ? path : "minecraft:$path" + def namespaceOf = full.split(':')[0] + // An id in a forbidden namespace is already named by PlaysAlone.ids. + if (namespaceOf != modId && !forbidden.contains(namespaceOf)) found << "$name adds $tagRef$full, not $modId's own".toString() } found } diff --git a/plugin/src/test/java/io/github/_5thlayer/libworks/plugin/PlaysAloneTest.java b/plugin/src/test/java/io/github/_5thlayer/libworks/plugin/PlaysAloneTest.java index b360c17..fa754f0 100644 --- a/plugin/src/test/java/io/github/_5thlayer/libworks/plugin/PlaysAloneTest.java +++ b/plugin/src/test/java/io/github/_5thlayer/libworks/plugin/PlaysAloneTest.java @@ -119,6 +119,8 @@ void aFileThatIsNoTagOrHasAMalformedFieldSaysWhy(@TempDir Path resources) throws write(tags.resolve("d.json"), "{\"replace\": \"false\", \"values\": []}"); write(tags.resolve("e.json"), "{\"remove\": [\"atouchofmadness:x\"]}"); write(tags.resolve("f.json"), "{\"values\": [{\"required\": false}, {\"id\": null, \"required\": false}, {\"id\": 3, \"required\": false}]}"); + write(tags.resolve("g.json"), "{\"values\": [{}, {\"id\": 3}]}"); + write(tags.resolve("h.json"), "{\"values\": [{\"id\": \"atouchofwickedness\", \"required\": false}, {\"id\": \"#bailiffs\", \"required\": false}]}"); assertEquals(List.of("data/atouchofmadness/tags/entity_type/a.json is not valid JSON", "data/atouchofmadness/tags/entity_type/b.json is not valid JSON", "data/atouchofmadness/tags/entity_type/c.json is not a tag", @@ -126,7 +128,11 @@ void aFileThatIsNoTagOrHasAMalformedFieldSaysWhy(@TempDir Path resources) throws "data/atouchofmadness/tags/entity_type/e.json removes from the tag", "data/atouchofmadness/tags/entity_type/f.json has an entry with no id", "data/atouchofmadness/tags/entity_type/f.json has an entry with no id", - "data/atouchofmadness/tags/entity_type/f.json has an entry with no id"), wicked.otherTags(resources)); + "data/atouchofmadness/tags/entity_type/f.json has an entry with no id", + "data/atouchofmadness/tags/entity_type/g.json has an entry with no id", + "data/atouchofmadness/tags/entity_type/g.json has an entry with no id", + "data/atouchofmadness/tags/entity_type/h.json adds minecraft:atouchofwickedness, not atouchofwickedness's own", + "data/atouchofmadness/tags/entity_type/h.json adds #minecraft:bailiffs, not atouchofwickedness's own"), wicked.otherTags(resources)); } @Test