mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
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.
This commit is contained in:
1 parent
c577b68c00
commit
264f754297
11 files changed
+89
-70
No files matched your search
+5
-4
@@ -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/<name>"` or `"snippet/<folder>/<name>"` string of a `@Snippet` type from
|
||||
`snippet/<folder>/<name>.json`. Complete `NOISE_STYLE` references and `@Ref(kind = ...)` of the host kinds
|
||||
`snippet/<folder>/<name>.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,
|
||||
|
||||
@@ -753,7 +753,7 @@ core engine is modules as well. The host's own JSON fields are not in it; no key
|
||||
| `List<E>`, `E[]` | `ListKind(E, false)` |
|
||||
| `Set<E>` | `ListKind(E, true)` |
|
||||
| `Map<String, V>` | `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
|
||||
|
||||
@@ -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<String> 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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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}. */
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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<Option> o
|
||||
var max = field.getAnnotation(MaxNumber.class);
|
||||
var minItems = field.getAnnotation(MinItems.class);
|
||||
var ref = field.getAnnotation(Ref.class);
|
||||
var resourceRef = field.getAnnotation(ResourceRef.class);
|
||||
if ((min != null || max != null) && !isNumeric(field.getType())) {
|
||||
throw new IllegalArgumentException("Numeric bounds on nonnumeric option: " + field.getName());
|
||||
}
|
||||
@@ -71,15 +73,15 @@ public record OptionsMetadata(String description, String snippet, List<Option> o
|
||||
throw new IllegalArgumentException("Invalid @MinItems on option: " + field.getName()
|
||||
+ "; it fits lists, sets and arrays, and its value is not negative");
|
||||
}
|
||||
if (ref != null && ref.value().length + (ref.kind() == void.class ? 0 : 1) != 1) {
|
||||
throw new IllegalArgumentException("Invalid @Ref on option: " + field.getName()
|
||||
+ "; give exactly one of a Reference or a kind");
|
||||
if (ref != null && resourceRef != null) {
|
||||
throw new IllegalArgumentException("Option " + field.getName()
|
||||
+ " has both @Ref and @ResourceRef; it names either a registry entry or a pack resource");
|
||||
}
|
||||
options.add(new Option(field, desc == null ? "" : desc.value(), field.isAnnotationPresent(Required.class),
|
||||
min == null ? null : min.value(), max == null ? null : max.value(),
|
||||
minItems == null ? null : minItems.value(),
|
||||
ref == null || ref.value().length == 0 ? null : ref.value()[0],
|
||||
ref == null || ref.kind() == void.class ? null : ref.kind()));
|
||||
ref == null ? null : ref.value(),
|
||||
resourceRef == null ? null : resourceRef.value()));
|
||||
}
|
||||
}
|
||||
var desc = type.getAnnotation(Desc.class);
|
||||
|
||||
@@ -32,7 +32,7 @@ final class TypeDrafts {
|
||||
private final HostTypes hostTypes;
|
||||
private final Function<Class<?>, Optional<ResourceId>> resourceKinds;
|
||||
|
||||
/** @param resourceKinds the id of the module resource kind read into a class, which {@code @Ref(kind = ...)} options name */
|
||||
/** @param resourceKinds the id of the module resource kind read into a class, which {@code @ResourceRef} options name */
|
||||
TypeDrafts(HostTypes hostTypes, Function<Class<?>, Optional<ResourceId>> resourceKinds) {
|
||||
this.hostTypes = hostTypes;
|
||||
this.resourceKinds = resourceKinds;
|
||||
|
||||
@@ -35,7 +35,7 @@ import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/** Maps a settings field's declared type and {@code @Ref} to the JSON it takes. Host types
|
||||
/** Maps a settings field's declared type and {@code @Ref} or {@code @ResourceRef} to the JSON it takes. Host types
|
||||
* become host kinds where the settings may use them; other classes that are none of the built-in kinds become
|
||||
* object kinds through the given function. Throws {@link SettingsTypeProblem} for a type or reference that does
|
||||
* not fit.
|
||||
@@ -73,7 +73,10 @@ final class ValueKinds {
|
||||
return kind(option.type(), new Naming(option.reference(), option.resource()));
|
||||
}
|
||||
|
||||
/** What a text option names: the registry or the kind's type of the field's {@code @Ref}, each null when absent. */
|
||||
/**
|
||||
* What a text option names: the registry of the field's {@code @Ref} or the kind's type of its {@code @ResourceRef},
|
||||
* each null when absent.
|
||||
*/
|
||||
private record Naming(Reference reference, Class<?> resource) {
|
||||
static final Naming NONE = new Naming(null, null);
|
||||
|
||||
@@ -81,10 +84,15 @@ final class ValueKinds {
|
||||
return reference == null && resource == null;
|
||||
}
|
||||
|
||||
/** The annotation's name, for messages. */
|
||||
String annotation() {
|
||||
return reference != null ? "@Ref" : "@ResourceRef";
|
||||
}
|
||||
|
||||
/** The annotation as written, for messages. */
|
||||
@Override
|
||||
public String toString() {
|
||||
return reference != null ? "@Ref(" + reference + ")" : "@Ref(kind = " + resource.getName() + ")";
|
||||
return reference != null ? "@Ref(" + reference + ")" : "@ResourceRef(" + resource.getName() + ")";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,7 +159,7 @@ final class ValueKinds {
|
||||
var hostKind = HOST_KINDS.get(resource);
|
||||
if (hostKind != null) return new ResourceReferenceKind(hostKind);
|
||||
return resourceKinds.apply(resource).map(ResourceReferenceKind::new).orElseThrow(() -> new SettingsTypeProblem(
|
||||
"has @Ref(kind = " + resource.getName() + "), but neither the host nor a module of the pack has a resource kind"
|
||||
"has @ResourceRef(" + resource.getName() + "), but neither the host nor a module of the pack has a resource kind"
|
||||
+ " read into that class; name the type of a PackResources kind or of a kind registered with"
|
||||
+ " FeatureRegistry.registerResourceKind"));
|
||||
}
|
||||
@@ -161,7 +169,7 @@ final class ValueKinds {
|
||||
return new ReferenceKind(Reference.BLOCK, TextFormat.BLOCK_STATE);
|
||||
}
|
||||
throw new SettingsTypeProblem("has " + naming + " on BlockState, which always names a block;"
|
||||
+ " remove the @Ref or use String or ResourceId");
|
||||
+ " remove the " + naming.annotation() + " or use String or ResourceId");
|
||||
}
|
||||
|
||||
private static EnumKind enumKind(Class<?> type) {
|
||||
@@ -184,7 +192,7 @@ final class ValueKinds {
|
||||
private static void requireNoNaming(Type type, Naming naming) {
|
||||
if (naming.isEmpty()) return;
|
||||
throw new SettingsTypeProblem("has " + naming + " on " + type.getTypeName()
|
||||
+ ", but @Ref fits only String and ResourceId and lists, sets and arrays of them");
|
||||
+ ", but " + naming.annotation() + " fits only String and ResourceId and lists, sets and arrays of them");
|
||||
}
|
||||
|
||||
private static boolean isCollection(Class<?> type) {
|
||||
|
||||
@@ -87,7 +87,7 @@ class PackSchemaTest {
|
||||
private ResourceId palette = ResourceId.parse("example:flora/default");
|
||||
@Ref(Reference.BLOCK)
|
||||
private String ground = "minecraft:grass_block";
|
||||
@Ref(kind = com.volmit.world.PackBiome.class) @MinItems(1)
|
||||
@ResourceRef(com.volmit.world.PackBiome.class) @MinItems(1)
|
||||
private List<String> biomes = List.of("plains", "forest");
|
||||
@Ref(Reference.ITEM)
|
||||
private ResourceId[] drops = {};
|
||||
@@ -697,8 +697,8 @@ class PackSchemaTest {
|
||||
|
||||
@Feature(id = "example:flora", name = "Flora", key = "flora", targets = Level.BIOME)
|
||||
public final class FloraSettings implements IrisFeature {
|
||||
@Ref(kind = com.volmit.world.PackBiome.class) private ResourceId home;
|
||||
@Ref(kind = com.volmit.object.GeneratedObject.class) private List<ResourceId> objects = List.of();
|
||||
@ResourceRef(com.volmit.world.PackBiome.class) private ResourceId home;
|
||||
@ResourceRef(com.volmit.object.GeneratedObject.class) private List<ResourceId> objects = List.of();
|
||||
}
|
||||
""")
|
||||
.writeInto(pack, "flora.jar");
|
||||
@@ -745,7 +745,7 @@ class PackSchemaTest {
|
||||
public final class Keep {
|
||||
@Desc("Towers on the walls") @MinNumber(1)
|
||||
private int towers = 4;
|
||||
@Ref(kind = Keep.class)
|
||||
@ResourceRef(Keep.class)
|
||||
private String next = "";
|
||||
}
|
||||
""")
|
||||
@@ -759,7 +759,7 @@ class PackSchemaTest {
|
||||
|
||||
@Feature(id = "example:castle", name = "Castle", key = "castle", targets = Level.BIOME)
|
||||
public final class CastleSettings implements IrisFeature {
|
||||
@Ref(kind = Keep.class)
|
||||
@ResourceRef(Keep.class)
|
||||
private List<String> keeps = List.of("main");
|
||||
}
|
||||
""");
|
||||
@@ -831,16 +831,15 @@ class PackSchemaTest {
|
||||
|
||||
@Test
|
||||
void resourceReferencesNameARegisteredKindOnPlainText() {
|
||||
assertLoadFails("Field pack.flora.FloraSettings.keep of " + FLORA_SOURCE + " has @Ref(kind = java.lang.Integer), but"
|
||||
assertLoadFails("Field pack.flora.FloraSettings.keep of " + FLORA_SOURCE + " has @ResourceRef(java.lang.Integer), but"
|
||||
+ " neither the host nor a module of the pack has a resource kind read into that class; name the type of a"
|
||||
+ " PackResources kind or of a kind registered with FeatureRegistry.registerResourceKind",
|
||||
"@Ref(kind = Integer.class) private String keep;");
|
||||
assertLoadFails("Field pack.flora.FloraSettings.count of " + FLORA_SOURCE + " has @Ref(kind = java.lang.Integer) on int,"
|
||||
+ " but @Ref fits only String and ResourceId and lists, sets and arrays of them",
|
||||
"@Ref(kind = Integer.class) private int count;");
|
||||
assertLoadFails("Invalid @Ref on option: keep; give exactly one of a Reference or a kind",
|
||||
"@Ref(value = Reference.BLOCK, kind = Integer.class) private String keep;");
|
||||
assertLoadFails("Invalid @Ref on option: keep; give exactly one of a Reference or a kind", "@Ref private String keep;");
|
||||
"@ResourceRef(Integer.class) private String keep;");
|
||||
assertLoadFails("Field pack.flora.FloraSettings.count of " + FLORA_SOURCE + " has @ResourceRef(java.lang.Integer) on int,"
|
||||
+ " but @ResourceRef fits only String and ResourceId and lists, sets and arrays of them",
|
||||
"@ResourceRef(Integer.class) private int count;");
|
||||
assertLoadFails("Option keep has both @Ref and @ResourceRef; it names either a registry entry or a pack resource",
|
||||
"@Ref(Reference.BLOCK) @ResourceRef(Integer.class) private String keep;");
|
||||
}
|
||||
|
||||
/** A built-in module {@code id} that registers {@code kind}. */
|
||||
|
||||
Reference in new issue
Block a user