From 264f75429729a68d56c3287f78774f3904c75bb7 Mon Sep 17 00:00:00 2001 From: piexel Date: Fri, 6 Nov 2026 07:16:25 +0100 Subject: [PATCH] Split @Ref into @Ref(Reference) and @ResourceRef(Kind.class) @Ref had two attributes of which exactly one had to be given, checked only at pack load. One annotation per concept makes a wrong combination a compile error; giving both still fails the load. --- CONTRACTS.md | 9 +++--- DESIGN.md | 30 +++++++++---------- README.md | 20 ++++++------- api/src/main/java/com/volmit/config/Ref.java | 18 ++++------- .../java/com/volmit/config/Reference.java | 2 +- .../java/com/volmit/config/ResourceRef.java | 16 ++++++++++ .../java/com/volmit/noise/NoiseStyle.java | 5 ++-- .../java/com/volmit/host/OptionsMetadata.java | 12 ++++---- .../main/java/com/volmit/host/TypeDrafts.java | 2 +- .../main/java/com/volmit/host/ValueKinds.java | 20 +++++++++---- .../java/com/volmit/host/PackSchemaTest.java | 25 ++++++++-------- 11 files changed, 89 insertions(+), 70 deletions(-) create mode 100644 api/src/main/java/com/volmit/config/ResourceRef.java diff --git a/CONTRACTS.md b/CONTRACTS.md index 06651b19a..ec0a742f9 100644 --- a/CONTRACTS.md +++ b/CONTRACTS.md @@ -26,7 +26,7 @@ types that carry them and lists what the Iris adapter still owes. | Annotated settings | `IrisFeature`, `@Feature` (id, short JSON `key`, optional `root`), config annotations, host `OptionsMetadata`, `LinkedBiomes` (`treeBiomes`, `usedBiomes`: pack biomes the settings bring into the layout) | | Host facades for the host's own modules | `PackWorld.extension(type)`, `InvocationContext.extension(type)`, `PackSettings.extension(type)` (each an `Optional`, empty by default) | | Area a stage writes | `reach(blocks)`, `reach(PackReach)`, `writesMantle(...)` on stage definitions, `PackSettings` (with `resources()`, for a reach that depends on the size of the pack's objects), host `StageReach`, `ResolvedStage.reachBlocks`, `PipelineReach` | -| Settings described for studio | `@Desc`, `@Required`, `@MinNumber`, `@MaxNumber`, `@MinItems`, `@Snippet`, `@Ref`/`Reference`, `FeatureRegistry.registerSettings`, host `LoadedPack.schema()` (`PackSchema`, `FeatureSchema`, `ObjectType`, `SchemaOption`, `ValueKind` with `HostKind`), `ModuleHost.describingHostTypesIn` | +| Settings described for studio | `@Desc`, `@Required`, `@MinNumber`, `@MaxNumber`, `@MinItems`, `@Snippet`, `@Ref`/`Reference`, `@ResourceRef`, `FeatureRegistry.registerSettings`, host `LoadedPack.schema()` (`PackSchema`, `FeatureSchema`, `ObjectType`, `SchemaOption`, `ValueKind` with `HostKind`), `ModuleHost.describingHostTypesIn` | | Geometry and mantle registration | `FeatureRegistry`, host `ModuleRegistry`, `FeatureCatalog` | | Block states and palettes | `BlockState`, `BlockRegistry` (`resolve(BlockSpec)`, `find(key)`, `blockEntity`, `hasTrait`, `oreFor`, `rotate(state, BlockTurn)`, `merge`, `withPropertyIfAccepted`, `matches`), `BlockTurn`, `BlockTrait` (with `STORAGE`), `BlockSpec`, `PaletteSpec` and `PaletteSampler` (`BlockRegistry.palette`) | | A pack's objects | `PlaceableObject` (`name`, size, `center`, `geometry`), `PackObjects` (`object`, `sizeOf`, `scaled` with `ScaleMethod`, `smartBored`, `build`), `PackResources.objects()` | @@ -35,7 +35,7 @@ types that carry them and lists what the Iris adapter still owes. | Values in settings | `BlockSpec`, `PaletteSpec`, `NoiseStyle`, `StyledRange`, `Range`, `BlockPosition`, `JigsawOverrides`, `Object` as `ValueKind.AnyKind` | | Decisions over and fit of the platform's own structures | service `VanillaStructures` (`rule`, `starts`, `shift`, `reach`, `beforePieces`, `afterPieces`, `setup`), `VanillaStructureRule`, `VanillaStructureContext`, `VanillaStructureStart`, `VanillaStructureStartContext`, `VanillaStructureSetup`, `PlatformStart`, `StartMemo`, `StartReach`, `StructureFit` (`Start`, `Piece`, `ColumnVisitor`), `DecorationStep`, `TerrainAdaptation`, `PieceKind`, `TemplateCells`, `world.BlockAccess`, host `FeatureCatalog.registrations(service)` | | Pack-scoped resolution | `ResourceId` (`ofPackKey`, `ofPlatformKey`), `ContentKey`, `PackResources` (`find(kind, id)`, `require`, `ids(kind)`, `idOf`; kinds `BIOMES`, `REGIONS`, `OBJECTS`, `EXPRESSIONS`, `IMAGE_MAPS`), `PackBiome`, `PackRegion`, `PackExpression`, `PackImageMap` | -| Module-owned pack resources | `ResourceKind`, `FeatureRegistry.registerResourceKind`, `@Ref(kind = ...)`, host `ModuleHost.reservingFolders`, `FeatureCatalog.resourceKinds()`, `ResourceKindSchema`, `ValueKind.ResourceReferenceKind` | +| Module-owned pack resources | `ResourceKind`, `FeatureRegistry.registerResourceKind`, `@ResourceRef`, host `ModuleHost.reservingFolders`, `FeatureCatalog.resourceKinds()`, `ResourceKindSchema`, `ValueKind.ResourceReferenceKind` | | Module-owned pack checks | `Validator`, `ValidationContext`, `Problem`, `Severity`, `Subject`, `FeatureRegistry.registerValidator`, host `FeatureCatalog.validators()` | | Per-world module state | `PackWorld` (`state`), `InvocationContext.world()`, host `WorldStates` | | Module lifecycle across loads, hotloads and reloads | `ModuleLifecycle`, `PackContext`, `FeatureRegistry.registerLifecycle`, host `FeatureCatalog.lifecycles()`, `LifecycleRunner` | @@ -62,7 +62,8 @@ A pack load works on copies of the module jars, so the originals are never held Modules describe their settings only through their settings classes; jars ship no schema files. The pack load turns every catalogued settings type into a `PackSchema` and fails, naming field, settings -and module, on a field type it cannot describe, a `@Ref` on a field that is not text, a class without +and module, on a field type it cannot describe, a `@Ref` or `@ResourceRef` on a field that is not text, both on +one field, a class without a working no-argument constructor (a `@JsonForms` class needs none: it is described as any JSON value), a bad or repeated snippet name, or a pack class's snippet name outside its module's folder. Defaults come from an instance made by that constructor. Options are in declaration order. @@ -254,7 +255,7 @@ running Iris is the pack publisher's responsibility. Read and write a `@JsonForms` class through its codec, created once with its no-argument constructor, handing it those same plain values; a member written as `null` stays left out and never reaches the codec. Read a `"snippet/"` or `"snippet//"` string of a `@Snippet` type from - `snippet//.json`. Complete `NOISE_STYLE` references and `@Ref(kind = ...)` of the host kinds + `snippet//.json`. Complete `NOISE_STYLE` references and `@ResourceRef` of the host kinds (`EXPRESSIONS`, `IMAGE_MAPS` among them); rendering a value type with the host's own description of the same JSON is allowed. - Serve `PackResources.noise()`: build each style's noise from the host's generators, expressions and image maps, diff --git a/DESIGN.md b/DESIGN.md index 07f679155..2e301dfd0 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -753,7 +753,7 @@ core engine is modules as well. The host's own JSON fields are not in it; no key | `List`, `E[]` | `ListKind(E, false)` | | `Set` | `ListKind(E, true)` | | `Map` | `MapKind(V)` | -| `String` with `@Ref(kind = Type.class)` | `ResourceReferenceKind(id of the kind read into Type)` | +| `String` with `@ResourceRef(Type.class)` | `ResourceReferenceKind(id of the kind read into Type)` | | a class in a host type package, in built-in settings | `HostKind(class name)` | | `Object` | `AnyKind`: any JSON value | | any other concrete class | `ObjectKind(class name)` | @@ -786,17 +786,17 @@ adding anything a pack can write. ### References -`@Ref` says what a text value names, in one of two ways, and exactly one of them. `@Ref(Reference.X)` names -something of the platform: the kinds are a closed enum of what the Iris host can list today through its -`RegistryList*` annotations: blocks, items, entities, platform biomes, structures, potion effects and -enchantments from the server registries, and the host's noise styles. More come when a module needs one and the -host can serve it. `@Ref(kind = Type.class)` names a pack resource of the kind read into `Type`, the host's -(`PackBiome`, `PackRegion`, `GeneratedObject`, `PackExpression`, `PackImageMap`) or a module's, so one mechanism covers -every resource of the pack (see Module-owned pack resources). It replaced both the `PACK_*` constants of `Reference` -and a separate `@ResourceRef`: two spellings for "a resource of the pack" made a module author guess which one a kind -needed. `@Ref` fits `String` and `ResourceId` and lists, sets and -arrays of them, where it applies to the elements. On any other field, a map included, it fails the -load. Pack resources are +Two annotations say what a text value names, one per concept. `@Ref(Reference.X)` names something of the platform: +the kinds are a closed enum of what the Iris host can list today through its `RegistryList*` annotations: blocks, +items, entities, platform biomes, structures, potion effects and enchantments from the server registries, and the +host's noise styles. More come when a module needs one and the host can serve it. `@ResourceRef(Type.class)` names a +pack resource of the kind read into `Type`, the host's (`PackBiome`, `PackRegion`, `GeneratedObject`, +`PackExpression`, `PackImageMap`) or a module's, so one mechanism covers every resource of the pack (see Module-owned +pack resources). There are no `PACK_*` constants in `Reference`, so each concept has one spelling. The split replaced +an `@Ref` with two attributes, of which exactly one had to be given: a rule checked only at pack load, with an array +`value` that existed only so it could default to empty. Now a wrong combination does not compile, except giving +both annotations, which fails the load. Both fit `String` and `ResourceId` and lists, sets and arrays of them, +where they apply to the elements. On any other field, a map included, they fail the load. Pack resources are plain text in the JSON either way: packs name their biomes, regions and objects by path without a namespace, such as `desert/dunes`. On a `ResourceId` field the host reads that path as the pack's id of it (`PackResources.idOf`), and a value with a namespace as written, so a module can hand the value straight to `PackResources.find`. A resource the @@ -1034,7 +1034,7 @@ the resources it serves itself. - **Lookup.** `PackResources.find(KEEPS, id)` and `ids(KEEPS)` take the kind itself, the constant the module registered, and return its type. The host's own kinds are constants of `PackResources` (`BIOMES`, `REGIONS`, `OBJECTS`, `EXPRESSIONS`, `IMAGE_MAPS`), so one call shape serves both, and no second key type (it used to be `ResourceKey`, a - pair of id and class). One class still backs at most one kind, because `@Ref(kind = ...)` names the kind by its class. The class must be concrete; like settings it + pair of id and class). One class still backs at most one kind, because `@ResourceRef(...)` names the kind by its class. The class must be concrete; like settings it needs a no-argument constructor, checked when the pack's description is built. - **Reading.** The host creates the instance with that constructor and reads the JSON into it under the decoding contract, exactly as it decodes settings, so a missing field keeps its default and studio's defaults are what packs get. @@ -1046,10 +1046,10 @@ the resources it serves itself. then renders the host's own description of the class. A pack module's kind of a host type fails the load. - **Studio.** `PackSchema.resources()` lists each kind with its folder and the files' type, an `ObjectKind` described in `types()` or a `HostKind`. The host writes a schema per kind for the files below its folder. An - option that names a resource of a kind carries `@Ref(kind = Keep.class)`: a class, not a kind id, so the + option that names a resource of a kind carries `@ResourceRef(Keep.class)`: a class, not a kind id, so the reference is checked by the compiler (an annotation cannot hold the kind constant). It becomes `ResourceReferenceKind(kindId)`, and studio completes the kind's keys. Keys are pack paths without a - namespace in the JSON, like the pack references of `@Ref`; the field may be a `String` or a `ResourceId`, which the + namespace in the JSON; the field may be a `String` or a `ResourceId`, which the host reads as the pack's id of the key. A class that backs no kind of the host or the pack fails the load. ## Validators diff --git a/README.md b/README.md index 91ecf8dc5..a6a955059 100644 --- a/README.md +++ b/README.md @@ -248,14 +248,14 @@ PackBiome dunes = resources.require(PackResources.BIOMES, resources.idOf("desert field names. - The kind's id follows the module id. The folder is one folder name directly below the pack root; the module chooses it, so a kind that replaces one of Iris's own keeps the folder and file format packs already have. -- One folder holds one kind and one class backs one kind, which `@Ref(kind = ...)` names by its class. Two kinds +- One folder holds one kind and one class backs one kind, which `@ResourceRef(...)` names by its class. Two kinds claiming one folder, or a folder the host reads itself (`ModuleHost.reservingFolders`), fail the pack load, naming both owners. - The host creates each resource with the class's no-argument constructor and reads the JSON into it, as it does settings, so an omitted field keeps its default. It reads a resource once per pack load and hands every caller the same instance, so resources are values nobody may change. A reload (studio hotload) reads them again. - Studio describes the files from the class like settings: `@Desc`, `@MinNumber`, `@Required` and the rest. An - option that names a resource of a kind carries `@Ref(kind = Keep.class)` on a `String` or `ResourceId`, or a + option that names a resource of a kind carries `@ResourceRef(Keep.class)` on a `String` or `ResourceId`, or a list, set or array of them, and studio completes the kind's keys. Packs write the key either way; a `ResourceId` field holds the pack's id of it. Built-in kinds may read into a class the host describes itself, as built-in settings may hold one. @@ -594,7 +594,7 @@ public final class FloraSettings implements IrisFeature { @Desc("Plants per chunk") @Required @MinNumber(0) @MaxNumber(64) private int density = 4; // default 4 - @Ref(kind = PackBiome.class) + @ResourceRef(PackBiome.class) private List biomes = List.of(); // completes the pack's biomes private BlockState flower = new BlockState("minecraft:poppy"); // completes blocks without @Ref @@ -621,12 +621,12 @@ public final class FloraSettings implements IrisFeature { (a structure or a family prefix such as `minecraft:village`), `STRUCTURE_SET`, `TEMPLATE_POOL` (a jigsaw template pool), `POTION_EFFECT`, `ENCHANTMENT`, `LOOT_TABLE` or `SPECIAL_ENTITY` (a mob of another plugin) from the server's registries, or `NOISE_STYLE` from the host's noise styles. `BlockState` fields name blocks without it. `@Ref` on any other field fails the load. -- `@Ref(kind = Keep.class)` says that a `String` or `ResourceId`, or a list, set or array of them, names a pack resource - of the kind read into that class, by its key: a host kind of `PackResources` (`PackBiome`, `PackRegion`, +- `@ResourceRef(Keep.class)` says that a `String` or `ResourceId`, or a list, set or array of them, names a pack + resource of the kind read into that class, by its key: a host kind of `PackResources` (`PackBiome`, `PackRegion`, `GeneratedObject`, `PackExpression`, `PackImageMap`) or a module resource kind (see Pack resources of a module). Packs write the key in the form they always have (`desert/dunes`); on a `ResourceId` field the host reads that as - the pack's id (`resources.idOf(...)`), so the value goes straight to `PackResources.find`. A `@Ref` gives exactly - one of a `Reference` and a kind; a class no kind of the host or the pack reads into fails the load. + the pack's id (`resources.idOf(...)`), so the value goes straight to `PackResources.find`. A class no kind of the + host or the pack reads into fails the load, and so does an option with both `@Ref` and `@ResourceRef`. - Packs write settings under the short `key` the feature declares, which is required: a plain JSON field name (not blank, no `:`), the same at every target: `"moss": {"amount": 0.5}`. The id (`example:moss`) stays the feature's identity in the stage graph, logs and `settings.declared(MossSettings.class)`; packs never write it. @@ -1057,9 +1057,9 @@ for each unsupported field type, misplaced `@Ref` (pack kinds on `ResourceId` in class, bad or repeated snippet name and pack snippet outside its module's folder, host types in built-in settings (and the load error when a pack module uses one). `PackSchemaTest` also loads a module jar with a resource kind: the kind's files described from its class, -`@Ref(kind = ...)` options as references to the kind (host kinds included), built-in kinds of host types, the load error for a pack kind -of a host type, for a folder two kinds claim or the host reserves, for a `@Ref` that gives both or neither of a -reference and a kind, and for a misplaced `@Ref(kind = ...)`. +`@ResourceRef` options as references to the kind (host kinds included), built-in kinds of host types, the load error for a pack kind +of a host type, for a folder two kinds claim or the host reserves, for an option with both `@Ref` and `@ResourceRef`, +and for a misplaced `@ResourceRef`. `ModuleRegistryTest` checks kind ids, types and folders, the validator and lifecycle order, service providers in module order, the load error for a second provider of a `ONE` service and for providers of unmarked interfaces or of the wrong type. `WorldStatesTest` checks that each state is created once (also when threads race), nested creation, the diff --git a/api/src/main/java/com/volmit/config/Ref.java b/api/src/main/java/com/volmit/config/Ref.java index bdac17c3a..dcf587953 100644 --- a/api/src/main/java/com/volmit/config/Ref.java +++ b/api/src/main/java/com/volmit/config/Ref.java @@ -2,21 +2,13 @@ package com.volmit.config; import java.lang.annotation.*; -/** Says what an option's text names: an entry of a platform registry, {@code @Ref(Reference.BLOCK) String block}, or - * a resource of the pack by its key, {@code @Ref(kind = LootTable.class) String table}, where {@code kind} is the type - * of a {@link com.volmit.resource.ResourceKind}: a host kind, the constants of - * {@link com.volmit.resource.PackResources}, or a kind some module of the pack registers. Studio then offers the - * registry's entries or the pack's keys of that kind. Give exactly one of the two. Allowed on {@code String} and - * {@link com.volmit.resource.ResourceId} options and on lists, sets and arrays of them, where it applies to every - * element; a {@code ResourceId} option naming a pack resource holds the id the pack gives the key it writes. - * Anything else fails the pack load. +/** Says that an option's text names an entry of a platform registry, {@code @Ref(Reference.BLOCK) String block}, so + * studio offers the registry's entries. Allowed on {@code String} and {@link com.volmit.resource.ResourceId} options + * and on lists, sets and arrays of them, where it applies to every element. A resource of the pack is named with + * {@link ResourceRef} instead; an option with both, or with either on any other type, fails the pack load. */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface Ref { - /** The platform registry the text names; give one, or none when {@link #kind} is given. */ - Reference[] value() default {}; - - /** The type of the resource kind the text names by key; {@code void.class}, the default, when {@link #value} is given. */ - Class kind() default void.class; + Reference value(); } diff --git a/api/src/main/java/com/volmit/config/Reference.java b/api/src/main/java/com/volmit/config/Reference.java index 2bddcb553..7766d8d86 100644 --- a/api/src/main/java/com/volmit/config/Reference.java +++ b/api/src/main/java/com/volmit/config/Reference.java @@ -2,7 +2,7 @@ package com.volmit.config; /** The platform registry a text option names, so studio can offer the matching completion list: entries of the * server's registries, such as {@code minecraft:stone}, including those that data packs and mods add, and the host's - * own noise generators. Resources of the pack are named by their kind instead, {@code @Ref(kind = ...)}. + * own noise generators. Resources of the pack are named by their kind instead, with {@link ResourceRef}. */ public enum Reference { /** A block type, such as {@code minecraft:stone}. {@link com.volmit.block.BlockState} options are block references without {@link Ref}. */ diff --git a/api/src/main/java/com/volmit/config/ResourceRef.java b/api/src/main/java/com/volmit/config/ResourceRef.java new file mode 100644 index 000000000..ad8d86a74 --- /dev/null +++ b/api/src/main/java/com/volmit/config/ResourceRef.java @@ -0,0 +1,16 @@ +package com.volmit.config; + +import java.lang.annotation.*; + +/** Says that an option's text names a resource of the pack by its key, {@code @ResourceRef(LootTable.class) String table}, + * where the value is the type of a {@link com.volmit.resource.ResourceKind}: a host kind, the constants of + * {@link com.volmit.resource.PackResources}, or a kind some module of the pack registers. Studio then offers the pack's + * keys of that kind. Allowed on {@code String} and {@link com.volmit.resource.ResourceId} options and on lists, sets and + * arrays of them, where it applies to every element; a {@code ResourceId} option holds the id the pack gives the key it + * writes. An option with both this and {@link Ref}, or with either on any other type, fails the pack load. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface ResourceRef { + Class value(); +} diff --git a/api/src/main/java/com/volmit/noise/NoiseStyle.java b/api/src/main/java/com/volmit/noise/NoiseStyle.java index 922572a9f..7de7e0ccc 100644 --- a/api/src/main/java/com/volmit/noise/NoiseStyle.java +++ b/api/src/main/java/com/volmit/noise/NoiseStyle.java @@ -5,6 +5,7 @@ import com.volmit.config.MaxNumber; import com.volmit.config.MinNumber; import com.volmit.config.Ref; import com.volmit.config.Reference; +import com.volmit.config.ResourceRef; import com.volmit.config.Snippet; import com.volmit.resource.PackResources; import com.volmit.resource.ResourceId; @@ -40,11 +41,11 @@ public final class NoiseStyle { @Desc("How far the noise is stretched: above 1 wider, below 1 tighter.") private double zoom = 1; - @Ref(kind = PackExpression.class) + @ResourceRef(PackExpression.class) @Desc("An expression of the pack that gives the noise instead of the style.") private ResourceId expression; - @Ref(kind = PackImageMap.class) + @ResourceRef(PackImageMap.class) @Desc("An image map of the pack that gives the noise instead of the style, when there is no expression.") private ResourceId imageMap; diff --git a/host/src/main/java/com/volmit/host/OptionsMetadata.java b/host/src/main/java/com/volmit/host/OptionsMetadata.java index 74bd0e73d..ab12ad88e 100644 --- a/host/src/main/java/com/volmit/host/OptionsMetadata.java +++ b/host/src/main/java/com/volmit/host/OptionsMetadata.java @@ -7,6 +7,7 @@ import com.volmit.config.MinNumber; import com.volmit.config.Ref; import com.volmit.config.Reference; import com.volmit.config.Required; +import com.volmit.config.ResourceRef; import com.volmit.config.Snippet; import java.lang.reflect.Field; import java.lang.reflect.Modifier; @@ -59,6 +60,7 @@ public record OptionsMetadata(String description, String snippet, List