mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Remove feature aliases, the one-option shorthand and reserved host fields
A setting has one JSON key, its feature id, and one shape, its settings object. Aliases were the only reason for reserved host fields (ids contain ':', host fields never do), so ModuleHost.reservingFields goes too.
This commit is contained in:
1 parent
99a914633d
commit
f6c078aade
26 files changed
+112
-305
No files matched your search
+6
-11
@@ -21,9 +21,9 @@ types that carry them and lists what the Iris adapter still owes.
|
||||
| Pack-load validation and diagnostics | host `StageGraphBuilder`, `ResolvedGraph`, `LoadedModules` |
|
||||
| Reference execution | host `PlacementRunner`, `ChunkRunner`, `MantleRunner` |
|
||||
| Work across chunks and mantle writes | `Stage.mantle`, `MantleStage`, `MantleStageContext`, `MantleGenerationContext`; chunk stages read the mantle only |
|
||||
| Annotated settings | `IrisFeature`, `@Feature` (id as JSON key, built-in alias), config annotations, `OptionsMetadata` |
|
||||
| Annotated settings | `IrisFeature`, `@Feature` (id as JSON key), config annotations, `OptionsMetadata` |
|
||||
| Area a stage writes | `reach(blocks)`, `reach(PackReach)`, `writesMantle(...)` on stage definitions, `PackSettings`, host `StageReach`, `ResolvedStage.reachBlocks`, `PipelineReach` |
|
||||
| Settings described for studio | `@Desc`, `@Required`, `@MinNumber`, `@MaxNumber`, `@Snippet`, `@Ref`/`Reference`, `FeatureRegistry.registerSettings`, host `LoadedPack.schema()` (`PackSchema`, `FeatureSchema` with `shorthand()`, `ObjectType`, `SchemaOption`, `ValueKind` with `HostKind`), `ModuleHost.describingHostTypesIn` |
|
||||
| Settings described for studio | `@Desc`, `@Required`, `@MinNumber`, `@MaxNumber`, `@Snippet`, `@Ref`/`Reference`, `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`, `BlockPalette`, `BlockSpec` (`BlockRegistry.resolve(BlockSpec)`, `blockEntity`) |
|
||||
| Noise from pack-described styles | `NoiseStyle`, `StyledRange`, `PackResources.noise()`, `NoiseFactory`, `NoiseSampler` |
|
||||
@@ -60,9 +60,8 @@ a working no-argument constructor, a bad or repeated snippet name, or a pack cla
|
||||
outside its module's folder. Defaults come from an instance made by that constructor. Options are in
|
||||
declaration order.
|
||||
|
||||
Packs write settings under the feature id. Only built-in modules may set an alias, a short key that
|
||||
existing pack JSON uses; a pack module setting one fails the load. Aliases are unique per target and
|
||||
may not equal a reserved host field. The description is in a fixed order and holds module entries only.
|
||||
Packs write settings under the feature id, as the settings object; there are no aliases and no bare-value
|
||||
shorthand. The description is in a fixed order and holds module entries only.
|
||||
|
||||
Modules compile against the API `compileOnly` and never ship it. At runtime they can use the API
|
||||
(`com.volmit.*`), the host packages the host chooses to expose, the JDK and the classes in their
|
||||
@@ -102,8 +101,6 @@ running Iris is the pack publisher's responsibility.
|
||||
that order. Never merge or override levels. Pass each placement's own declarations as
|
||||
`ConfiguredSettings.placement(...)`; the chunk and mantle runners collect a chunk's settings
|
||||
themselves.
|
||||
- Decode a value that is not a JSON object into settings with exactly one option
|
||||
(`FeatureSchema.shorthand()`), and render the schema to accept both forms.
|
||||
- Name the packages of the classes Iris describes itself with `ModuleHost.describingHostTypesIn(...)`,
|
||||
decode them as Iris does, and render each `HostKind` with Iris's own description of the class.
|
||||
- Hand modules heights above the dimension's bottom (0 = bottom block, whatever the platform's minimum
|
||||
@@ -142,11 +139,9 @@ running Iris is the pack publisher's responsibility.
|
||||
packs and is part of what packs can break on. Stage output types and settings types that pack
|
||||
code uses through those stages must be in exposed packages too. The API is always exposed.
|
||||
- Consider showing `PackModules.missingClasses()` in studio.
|
||||
- Decode module settings under the feature id and, for built-ins, the alias. Fail a JSON object that
|
||||
holds both, naming the two keys.
|
||||
- Decode module settings under the feature id, as a JSON object (or a snippet reference for a `@Snippet` type).
|
||||
- Render `pack.schema()` into studio's files: merge each target's `fields(target)` into the schema
|
||||
of the matching Iris file type (dimension, region, biome, object placement) under the key and the
|
||||
alias, write `types()` as definitions, a `/snippet/<name>` schema per entry of `snippets()`, and
|
||||
of the matching Iris file type (dimension, region, biome, object placement) under the key, write `types()` as definitions, a `/snippet/<name>` schema per entry of `snippets()`, and
|
||||
completion lists per `Reference` from the server registries and the pack's biome, region and
|
||||
object folders. `PACK_*` references are pack paths without a namespace, as Iris writes them. Pack
|
||||
snippet names are under their module's folder, so they cannot collide with Iris's own; built-in
|
||||
|
||||
@@ -47,7 +47,7 @@ name, version and optional packages; there is no separate descriptor. A pack kee
|
||||
|
||||
The host loads a pack with `LoadedPack.load(packRoot, host)`. `ModuleHost` is the host's fixed
|
||||
configuration, built once and the same for every pack: built-in modules, exposed host packages,
|
||||
reserved JSON fields. Each of its methods adds to what earlier calls
|
||||
host type packages and reserved folders. Each of its methods adds to what earlier calls
|
||||
configured, and all names are checked when it is built. `LoadedPack` runs `PackModules.load` (below), then
|
||||
`LoadedModules.load` on the built-ins followed by the pack's modules. If the second step fails it
|
||||
closes the first before rethrowing, so a failed load leaves no class loader or jar copy behind.
|
||||
@@ -557,37 +557,24 @@ as its reach. Terrain samples are computed, not prepared, and need nothing.
|
||||
|
||||
## Settings, geometry and storage
|
||||
|
||||
Settings types implement `IrisFeature` and carry `@Feature` (namespaced id, display name, optional
|
||||
alias, attachment targets). `when(type)` validates the annotation while the module installs. The id
|
||||
Settings types implement `IrisFeature` and carry `@Feature` (namespaced id, display name, attachment targets). `when(type)` validates the annotation while the module installs. The id
|
||||
must be owned by a module naming the type (see Namespaces), or the owner registers the type itself
|
||||
with `FeatureRegistry.registerSettings`. That is for settings no stage names, such as settings read
|
||||
only through `FeatureSettings.at(...)`; registering a type a stage also names changes nothing, and a
|
||||
type its owner registered may be named in `when(...)` by any module.
|
||||
`LoadedModules.load` catalogs those types with geometry generator settings and rejects duplicate
|
||||
ids and alias collisions per attachment target, including reserved host fields.
|
||||
ids. Two modules with one id never get that far: the load fails naming both ("Duplicate module").
|
||||
`OptionsMetadata` reads field metadata, in declaration order; it does not decode JSON.
|
||||
|
||||
### JSON keys and aliases
|
||||
### JSON keys
|
||||
|
||||
A feature whose settings class has exactly one option may be written as that option's value instead of
|
||||
an object holding it: `"snow": 0.5` for `"snow": {"amount": 0.5}`, or a bare JSON list for a class holding
|
||||
one list. Existing pack JSON writes several settings that way, and keeping the format meant either this
|
||||
rule or a compatibility layer per key. `FeatureSchema.shorthand()` returns the option when there is
|
||||
exactly one, the host decodes a value that is not a JSON object into it, and renders the schema to accept
|
||||
both forms. A `@Snippet` class written as a `"snippet/..."` string stays a snippet reference.
|
||||
|
||||
Packs write a feature's settings under its feature id at each of its targets:
|
||||
`"example:moss": {...}`. The id is unique, namespaced and owned by one module, so two modules can never
|
||||
claim the same key, and a key can never be one of the host's own fields: those have no `:`.
|
||||
|
||||
Built-in modules may also set `@Feature(alias = "stilt")`, a short key that existing pack JSON
|
||||
already uses, such as `"stilt": {...}`. An alias has no `:`, so it never equals an id. Aliases are
|
||||
unique per target and may not equal a reserved host field; reserved host fields therefore constrain
|
||||
aliases only. A pack module that sets an alias fails the load and is told to use its id: aliases are
|
||||
for keeping existing pack files working, and a pack module has no existing files to keep.
|
||||
|
||||
A JSON object that holds both a feature's alias and its id is ambiguous. That is a host decoding
|
||||
rule, since IrisApi does not decode JSON: the host fails such an object, naming both keys.
|
||||
Packs write a feature's settings under its feature id at each of its targets, always as the settings
|
||||
object: `"example:moss": {...}`. A single option is not written bare (`"example:moss": 0.5` and a bare list
|
||||
are not accepted); the object is the one shape, so a class gaining a second option never changes how packs
|
||||
read. A `@Snippet` class may be written as a `"snippet/..."` string instead of the object. The id is unique,
|
||||
namespaced and owned by one module, so two modules can never claim the same key, and a key can never be one of
|
||||
the host's own fields: those have no `:`. There are no short aliases; pack files written for an older
|
||||
shape are converted by the host's migration tooling, never by the loader.
|
||||
|
||||
`GeneratedObject` is sparse, immutable local geometry with bounds, an anchor, sorted blocks,
|
||||
optional block entity payloads and markers. `ObjectGenerator` produces it from settings and a
|
||||
@@ -610,14 +597,14 @@ classes. The pack load instead collects what modules declare in their settings c
|
||||
`LoadedModules.load` builds it right after freezing the catalog (`PackSchemaBuilder`), so a pack
|
||||
that loads has a complete description and a settings class the host could not render fails the
|
||||
load. It contains every catalogued settings type of every module, built-in ones too, because the
|
||||
core engine is modules as well. The host's own JSON fields are not in it; reserved host fields
|
||||
already keep module fields from colliding with them.
|
||||
core engine is modules as well. The host's own JSON fields are not in it; they have no `:`, so they can
|
||||
never equal a feature id.
|
||||
|
||||
### Shape
|
||||
|
||||
- A `FeatureSchema` per catalogued type: feature id and name, role (`SETTINGS` for types named in
|
||||
`when(...)` or registered with `registerSettings`, `OBJECT_GENERATOR` for `registerObject`), the
|
||||
owning module's `ModuleInfo`, the JSON key (the feature id), the alias if any, its targets and the
|
||||
owning module's `ModuleInfo`, the JSON key (the feature id), its targets and the
|
||||
settings `ObjectType`. `fields(target)` lists a target's features; a feature attached to several targets appears under
|
||||
each. The owner is the one module whose id owns the feature id; module ids are unique and contain
|
||||
no `/`, so there is never more than one.
|
||||
|
||||
@@ -399,12 +399,9 @@ public final class FloraSettings implements IrisFeature {
|
||||
- `@ResourceRef(Keep.class)` says that a `String`, or a list, set or array of them, names a resource of the
|
||||
module resource kind read into that class, by its key (see Pack resources of a module). The class must back a
|
||||
kind of the pack; anywhere else, or together with `@Ref`, it fails the load.
|
||||
- Packs write settings under the feature id. Built-in modules may also set `@Feature(alias = "stilt")`,
|
||||
a short key existing pack JSON uses; a pack module that sets one fails the load. One JSON object may
|
||||
not hold both.
|
||||
- Packs write settings under the feature id, as the settings object: `"example:moss": {"amount": 0.5}`. There
|
||||
are no aliases and no bare-value form.
|
||||
- Options keep the order the class declares them in, a superclass's first.
|
||||
- Settings with exactly one option have a shorthand: packs may write the option's value instead of an
|
||||
object, and `FeatureSchema.shorthand()` says so.
|
||||
- Built-in settings may hold classes the host describes itself, such as Iris's palettes, which the host
|
||||
names with `ModuleHost.describingHostTypesIn(...)`. They appear as `HostKind` and pack modules cannot
|
||||
use them.
|
||||
@@ -420,7 +417,6 @@ Field com.example.flora.FloraSettings.id of settings example:flora (module examp
|
||||
Field com.example.flora.FloraSettings.count of settings example:flora (module example:flora from modules/flora.jar) has @Ref(BLOCK) on int, but @Ref fits only String and ResourceId and lists, sets and arrays of them
|
||||
Class com.example.flora.Shape of settings example:flora (module example:flora from modules/flora.jar) has no no-argument constructor; the host creates settings with it and reads their defaults from it, so declare one, private if nothing else should use it
|
||||
Snippet name 'patch' of com.example.flora.Patch of settings example:flora (module example:flora from modules/flora.jar) is not under a module of the pack; snippets of pack modules start with their module's id as a folder path, such as 'example/flora/patch' (folder snippet/example/flora/patch/)
|
||||
Settings com.example.flora.FloraSettings of module example:flora from modules/flora.jar set alias 'flora'; only modules that ship with the host may set one, so remove it: packs write these settings under their id "example:flora"
|
||||
```
|
||||
|
||||
## Values in settings
|
||||
@@ -489,7 +485,6 @@ the result on every platform it runs on.
|
||||
// Once, at startup: the same for every pack.
|
||||
var host = ModuleHost.of(builtInModules)
|
||||
.exposing("art.arcane.iris.engine.modules") // besides the API
|
||||
.reservingFields(reservedHostFields)
|
||||
.describingHostTypesIn("art.arcane.iris.engine.object") // classes the host describes itself
|
||||
.reservingFolders("biomes", "regions", "objects") // pack folders the host reads itself
|
||||
.copyingJarsTo(cacheDirectory) // default: java.io.tmpdir
|
||||
@@ -512,9 +507,9 @@ try (var pack = LoadedPack.load(packRoot, host)) {
|
||||
```
|
||||
|
||||
`ModuleHost` holds what the host passes to every pack load: built-in modules (their `info()` is read
|
||||
once, here), the host packages pack modules may use, the JSON fields the host itself uses, the
|
||||
once, here), the host packages pack modules may use, the
|
||||
packages of the classes it describes itself and the pack folders it reads itself. Each method adds to what earlier calls configured. Package names and
|
||||
reserved field names are checked when it is built. `LoadedPack.load`
|
||||
reserved folders are checked when it is built. `LoadedPack.load`
|
||||
loads the pack's jars, installs them after the built-ins, catalogs settings and registrations,
|
||||
describes them for studio and resolves the three pipelines. It returns a complete pack or throws with nothing left open. `close()`
|
||||
releases the pack's class loader and its jar copies. `PackModules` and `LoadedModules`, which it
|
||||
@@ -607,7 +602,7 @@ no JSON. The host renders it and merges it with its own fields:
|
||||
|
||||
- `fields(target)`: the module features attached to a target, by JSON key. Each `FeatureSchema` has
|
||||
the feature id and name, its role (`SETTINGS` or `OBJECT_GENERATOR`), the owning module's
|
||||
`ModuleInfo`, the JSON key (the id), the alias of a built-in if it has one, its targets and the
|
||||
`ModuleInfo`, the JSON key (the id), its targets and the
|
||||
settings `ObjectType`.
|
||||
- `types()`: every class reachable from module settings, once each, by name. An `ObjectType` has the
|
||||
class name, description, snippet name and options. A `SchemaOption` has name, `ValueKind`,
|
||||
@@ -626,7 +621,7 @@ no JSON. The host renders it and merges it with its own fields:
|
||||
For the stilt example the host sees one `OBJECT_PLACEMENT` feature. The records are abridged:
|
||||
|
||||
```
|
||||
FeatureSchema[id=iris:stilt, name=Stilt, role=SETTINGS, module=Stilts (iris:stilt), key=iris:stilt, alias=Optional[stilt], targets=[OBJECT_PLACEMENT],
|
||||
FeatureSchema[id=iris:stilt, name=Stilt, role=SETTINGS, module=Stilts (iris:stilt), key=iris:stilt, targets=[OBJECT_PLACEMENT],
|
||||
settings=ObjectType[name=com.volmit.example.placement.StiltSettings, description=Fills the space below an object down to the ground,
|
||||
snippet=Optional.empty, options=[SchemaOption[name=maxDepth, kind=IntegerKind[], description=Maximum blocks filled below each
|
||||
lowest object block, required=false, minimum=OptionalDouble[1.0], maximum=OptionalDouble.empty, defaultValue=Optional[16]]]]]
|
||||
@@ -693,13 +688,13 @@ and the derivation is pinned to values computed from its specification (`StageSt
|
||||
independent Python reference (`python3 -B src/test/reference/world_random.py`; the build does not
|
||||
need Python) and fails if the type gains an unpinned method or implements `RandomGenerator`.
|
||||
`PackSchemaTest` loads module jars and checks their description: features under their targets by id,
|
||||
aliases of built-ins and the load error when a pack module sets one, options in declaration order,
|
||||
options in declaration order,
|
||||
descriptions, required, bounds, defaults (floats, nulls, sets, maps, objects, a field holding `this`),
|
||||
enums, collections, references, nested classes with a cycle, snippets, object generator settings,
|
||||
explicit registration, built-in modules, the same result whatever the jar order, and the load error
|
||||
for each unsupported field type, misplaced `@Ref` (pack kinds on `ResourceId` included), unusable
|
||||
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), and the one-option shorthand.
|
||||
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,
|
||||
`@ResourceRef` options as references to the kind, 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, and for a misplaced `@ResourceRef`.
|
||||
|
||||
@@ -1,33 +1,13 @@
|
||||
package com.volmit;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/** Where settings appear in pack JSON: the targets, and the optional short alias a built-in module
|
||||
* may set besides the feature id, which is always the JSON key.
|
||||
*/
|
||||
public record FeatureAttachment(Optional<String> alias, Set<Target> targets) {
|
||||
/** Where settings appear in pack JSON: the targets. The JSON key is always the feature id. */
|
||||
public record FeatureAttachment(Set<Target> targets) {
|
||||
public enum Target { DIMENSION, REGION, BIOME, OBJECT_PLACEMENT }
|
||||
|
||||
private static final char NAMESPACE_SEPARATOR = ':';
|
||||
|
||||
public FeatureAttachment {
|
||||
Objects.requireNonNull(alias, "alias");
|
||||
alias.ifPresent(FeatureAttachment::requireFieldName);
|
||||
targets = Set.copyOf(targets);
|
||||
if (targets.isEmpty()) throw new IllegalArgumentException("At least one target is required");
|
||||
}
|
||||
|
||||
/** Checks a JSON field name that is not a feature id: an alias or a field the host itself uses.
|
||||
* It is not blank and has no ':', which every feature id has, so the two never collide.
|
||||
*/
|
||||
public static String requireFieldName(String name) {
|
||||
Objects.requireNonNull(name, "name");
|
||||
if (name.isBlank()) throw new IllegalArgumentException("Field must not be blank");
|
||||
if (name.indexOf(NAMESPACE_SEPARATOR) >= 0) {
|
||||
throw new IllegalArgumentException("Field " + name + " contains ':', which only feature ids may contain");
|
||||
}
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@@ -4,16 +4,11 @@ import java.lang.annotation.*;
|
||||
|
||||
/** Identity and JSON attachment for an IrisFeature configuration class. Packs write the settings under
|
||||
* their feature id, such as {@code "example:moss": {...}}, at each of the targets.
|
||||
*
|
||||
* <p>{@code alias} is an optional short JSON key that only modules shipping with the host may set, so
|
||||
* existing pack JSON such as {@code "stilt": {...}} keeps loading. A pack module that sets one fails
|
||||
* the load. An alias contains no ':', so it never equals a feature id.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface Feature {
|
||||
String id();
|
||||
String name();
|
||||
String alias() default "";
|
||||
com.volmit.FeatureAttachment.Target[] targets();
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import com.volmit.config.OptionsMetadata;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/** Validated settings metadata. It describes configuration, not executable ordering. */
|
||||
@@ -42,7 +41,7 @@ public record FeatureDescriptor<F extends IrisFeature>(
|
||||
ResourceId.parse(annotation.id()),
|
||||
annotation.name(),
|
||||
type,
|
||||
new FeatureAttachment(alias(annotation), Set.of(annotation.targets())),
|
||||
new FeatureAttachment(Set.of(annotation.targets())),
|
||||
OptionsMetadata.inspect(type));
|
||||
}
|
||||
|
||||
@@ -51,15 +50,6 @@ public record FeatureDescriptor<F extends IrisFeature>(
|
||||
return id.toString();
|
||||
}
|
||||
|
||||
/** The short JSON key a built-in module may set besides {@link #key()}. */
|
||||
public Optional<String> alias() {
|
||||
return attachment.alias();
|
||||
}
|
||||
|
||||
private static Optional<String> alias(Feature annotation) {
|
||||
return annotation.alias().isEmpty() ? Optional.empty() : Optional.of(annotation.alias());
|
||||
}
|
||||
|
||||
private static void requireConcreteFeature(Class<?> type) {
|
||||
if (!IrisFeature.class.isAssignableFrom(type)
|
||||
|| type.isInterface()
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package com.volmit.host;
|
||||
|
||||
import com.volmit.FeatureAttachment;
|
||||
import com.volmit.host.schema.PackSchema;
|
||||
import com.volmit.stage.Pipeline;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -25,7 +23,6 @@ public record LoadedModules(
|
||||
|
||||
/** Pass the built-in modules together with {@link PackModules#modules()} of the pack.
|
||||
*
|
||||
* @param reservedHostFields JSON fields the host itself uses, per attachment target
|
||||
* @param hostTypePackages packages whose classes the host describes itself, each with its
|
||||
* subpackages; only built-in modules' settings may use them (see {@link ModuleHost#describingHostTypesIn})
|
||||
* @param reservedFolders pack folders the host reads itself, which no resource kind may read (see
|
||||
@@ -33,10 +30,9 @@ public record LoadedModules(
|
||||
*/
|
||||
public static LoadedModules load(
|
||||
List<DiscoveredModule> modules,
|
||||
Map<FeatureAttachment.Target, Set<String>> reservedHostFields,
|
||||
Collection<String> hostTypePackages,
|
||||
Collection<String> reservedFolders) {
|
||||
var registry = new ModuleRegistry(reservedHostFields, Set.copyOf(reservedFolders));
|
||||
var registry = new ModuleRegistry(Set.copyOf(reservedFolders));
|
||||
var stages = new StageGraphBuilder();
|
||||
for (var discovered : modules) {
|
||||
installModule(discovered, stages, registry);
|
||||
|
||||
@@ -37,7 +37,7 @@ public final class LoadedPack implements AutoCloseable {
|
||||
var packModules = PackModules.load(packRoot, host.exposedHostPackages(), host.jarCopyRoot(), host.logger());
|
||||
try {
|
||||
var loaded = LoadedModules.load(host.withPackModules(packModules.modules()),
|
||||
host.reservedHostFields(), host.hostTypePackages(), host.reservedFolders());
|
||||
host.hostTypePackages(), host.reservedFolders());
|
||||
return new LoadedPack(packModules, loaded);
|
||||
} catch (RuntimeException | Error failure) {
|
||||
closeAfterFailure(packModules, failure);
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
package com.volmit.host;
|
||||
|
||||
import com.volmit.FeatureAttachment;
|
||||
import com.volmit.IrisModule;
|
||||
import com.volmit.resource.ResourceKind;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
@@ -22,18 +19,17 @@ import java.util.TreeSet;
|
||||
* <pre>{@code
|
||||
* var host = ModuleHost.of(builtInModules)
|
||||
* .exposing("art.arcane.iris.engine.modules")
|
||||
* .reservingFields(reservedHostFields);
|
||||
* .reservingFolders("biomes", "regions");
|
||||
* }</pre>
|
||||
*
|
||||
* Every method adds to what earlier calls configured, so a host can build the configuration in steps.
|
||||
* Built-in modules' {@code info()} is read here, once. Exposed package names, host type packages,
|
||||
* reserved folders and reserved field names are checked here, so a mistake fails when the host starts rather than at the
|
||||
* Built-in modules' {@code info()} is read here, once. Exposed package names, host type packages
|
||||
* and reserved folders are checked here, so a mistake fails when the host starts rather than at the
|
||||
* first pack load.
|
||||
*/
|
||||
public record ModuleHost(
|
||||
List<DiscoveredModule> builtIns,
|
||||
Set<String> exposedHostPackages,
|
||||
Map<FeatureAttachment.Target, Set<String>> reservedHostFields,
|
||||
Set<String> hostTypePackages,
|
||||
Set<String> reservedFolders,
|
||||
Path jarCopyRoot,
|
||||
@@ -43,14 +39,12 @@ public record ModuleHost(
|
||||
public ModuleHost {
|
||||
builtIns = List.copyOf(builtIns);
|
||||
exposedHostPackages = Set.copyOf(exposedHostPackages);
|
||||
reservedHostFields = copyOf(reservedHostFields);
|
||||
hostTypePackages = Set.copyOf(hostTypePackages);
|
||||
reservedFolders = Set.copyOf(reservedFolders);
|
||||
Objects.requireNonNull(jarCopyRoot, "jarCopyRoot");
|
||||
Objects.requireNonNull(logger, "logger");
|
||||
ExposedPackages.apiAnd(exposedHostPackages);
|
||||
HostTypes.of(hostTypePackages);
|
||||
requireFieldNames(reservedHostFields);
|
||||
requireFolderNames(reservedFolders);
|
||||
}
|
||||
|
||||
@@ -59,7 +53,7 @@ public record ModuleHost(
|
||||
*/
|
||||
public static ModuleHost of(List<? extends IrisModule> builtInModules) {
|
||||
var builtIns = builtInModules.stream().map(DiscoveredModule::builtIn).toList();
|
||||
return new ModuleHost(builtIns, Set.of(), Map.of(), Set.of(), Set.of(), systemTemporaryDirectory(),
|
||||
return new ModuleHost(builtIns, Set.of(), Set.of(), Set.of(), systemTemporaryDirectory(),
|
||||
System.getLogger(PackModules.class.getName()));
|
||||
}
|
||||
|
||||
@@ -67,16 +61,7 @@ public record ModuleHost(
|
||||
* modules, such as the packages that hold built-in modules' stage constants.
|
||||
*/
|
||||
public ModuleHost exposing(String... packages) {
|
||||
return new ModuleHost(builtIns, union(exposedHostPackages, packages), reservedHostFields,
|
||||
hostTypePackages, reservedFolders, jarCopyRoot, logger);
|
||||
}
|
||||
|
||||
/** This configuration with {@code fields} also reserved as JSON fields the host itself uses,
|
||||
* merged per attachment target with the fields reserved before.
|
||||
*/
|
||||
public ModuleHost reservingFields(Map<FeatureAttachment.Target, Set<String>> fields) {
|
||||
return new ModuleHost(builtIns, exposedHostPackages, merge(reservedHostFields, fields),
|
||||
hostTypePackages, reservedFolders, jarCopyRoot, logger);
|
||||
return new ModuleHost(builtIns, union(exposedHostPackages, packages), hostTypePackages, reservedFolders, jarCopyRoot, logger);
|
||||
}
|
||||
|
||||
/** This configuration with the classes in {@code packages}, each with its subpackages, described by
|
||||
@@ -85,7 +70,7 @@ public record ModuleHost(
|
||||
* instead of describing their fields. Pack modules' settings cannot use them.
|
||||
*/
|
||||
public ModuleHost describingHostTypesIn(String... packages) {
|
||||
return new ModuleHost(builtIns, exposedHostPackages, reservedHostFields,
|
||||
return new ModuleHost(builtIns, exposedHostPackages,
|
||||
union(hostTypePackages, packages), reservedFolders, jarCopyRoot, logger);
|
||||
}
|
||||
|
||||
@@ -93,7 +78,7 @@ public record ModuleHost(
|
||||
* itself, such as its biome and object folders. A module resource kind that reads one fails the pack load.
|
||||
*/
|
||||
public ModuleHost reservingFolders(String... folders) {
|
||||
return new ModuleHost(builtIns, exposedHostPackages, reservedHostFields, hostTypePackages,
|
||||
return new ModuleHost(builtIns, exposedHostPackages, hostTypePackages,
|
||||
union(reservedFolders, folders), jarCopyRoot, logger);
|
||||
}
|
||||
|
||||
@@ -101,7 +86,7 @@ public record ModuleHost(
|
||||
* cache directory of the host, which is created when missing. The last call wins.
|
||||
*/
|
||||
public ModuleHost copyingJarsTo(Path directory) {
|
||||
return new ModuleHost(builtIns, exposedHostPackages, reservedHostFields, hostTypePackages,
|
||||
return new ModuleHost(builtIns, exposedHostPackages, hostTypePackages,
|
||||
reservedFolders, directory, logger);
|
||||
}
|
||||
|
||||
@@ -109,7 +94,7 @@ public record ModuleHost(
|
||||
* {@code logger}, such as an adapter to the host's own log. The last call wins.
|
||||
*/
|
||||
public ModuleHost loggingTo(System.Logger logger) {
|
||||
return new ModuleHost(builtIns, exposedHostPackages, reservedHostFields, hostTypePackages,
|
||||
return new ModuleHost(builtIns, exposedHostPackages, hostTypePackages,
|
||||
reservedFolders, jarCopyRoot, logger);
|
||||
}
|
||||
|
||||
@@ -124,17 +109,6 @@ public record ModuleHost(
|
||||
return Path.of(System.getProperty(TEMPORARY_DIRECTORY_PROPERTY));
|
||||
}
|
||||
|
||||
private static Map<FeatureAttachment.Target, Set<String>> copyOf(Map<FeatureAttachment.Target, Set<String>> fields) {
|
||||
var copy = new EnumMap<FeatureAttachment.Target, Set<String>>(FeatureAttachment.Target.class);
|
||||
fields.forEach((target, names) -> copy.put(target, Set.copyOf(names)));
|
||||
return Map.copyOf(copy);
|
||||
}
|
||||
|
||||
/** A blank field name, or one with ':' like a feature id, fails here, as it would as an alias. */
|
||||
private static void requireFieldNames(Map<FeatureAttachment.Target, Set<String>> fields) {
|
||||
fields.values().forEach(names -> names.forEach(FeatureAttachment::requireFieldName));
|
||||
}
|
||||
|
||||
private static void requireFolderNames(Set<String> folders) {
|
||||
for (var folder : folders) {
|
||||
if (!ResourceKind.isFolderName(folder)) {
|
||||
@@ -144,15 +118,6 @@ public record ModuleHost(
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<FeatureAttachment.Target, Set<String>> merge(
|
||||
Map<FeatureAttachment.Target, Set<String>> existing,
|
||||
Map<FeatureAttachment.Target, Set<String>> added) {
|
||||
var merged = new EnumMap<FeatureAttachment.Target, Set<String>>(FeatureAttachment.Target.class);
|
||||
existing.forEach((target, names) -> merged.put(target, new TreeSet<>(names)));
|
||||
added.forEach((target, names) -> merged.computeIfAbsent(target, ignored -> new TreeSet<>()).addAll(names));
|
||||
return merged;
|
||||
}
|
||||
|
||||
private static Set<String> union(Set<String> existing, String... added) {
|
||||
var names = new TreeSet<>(existing);
|
||||
names.addAll(Arrays.asList(added));
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.volmit.host;
|
||||
|
||||
import com.volmit.FeatureAttachment;
|
||||
import com.volmit.FeatureRegistry;
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.IrisModule;
|
||||
@@ -23,9 +22,7 @@ import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/** Reference host registry. Single-threaded registration ends with freeze(); the catalog is
|
||||
* immutable. IDs are unique across feature kinds, and every feature id is its JSON key. Aliases,
|
||||
* which only built-in modules may set, are unique per attachment target and may not equal the
|
||||
* host JSON fields passed in to reserve them. Modules register through
|
||||
* immutable. IDs are unique across feature kinds, and every feature id is its JSON key. Modules register through
|
||||
* {@link #register(DiscoveredModule)}; object feature ids, mantle keys, resource kind ids and explicitly registered
|
||||
* settings ids must be the registering module's id or start with it and '/' ({@link com.volmit.ModuleInfo#ownsId}).
|
||||
* Resource kinds have unique ids, types and folders, and no kind may read a folder the host reserves for its own
|
||||
@@ -41,28 +38,21 @@ public final class ModuleRegistry implements FeatureRegistry {
|
||||
private final Set<ResourceId> featureIds = new HashSet<>();
|
||||
private final Set<Class<?>> featureTypes = new HashSet<>();
|
||||
private final Set<Class<?>> registeredByOwner = new HashSet<>();
|
||||
private final Map<Field, String> fields = new HashMap<>();
|
||||
private final Map<ResourceId, ResourceKindRegistration> resourceKinds = new HashMap<>();
|
||||
private final List<ValidatorRegistration> validators = new ArrayList<>();
|
||||
private final List<LifecycleRegistration> lifecycles = new ArrayList<>();
|
||||
private final List<ServiceRegistration> services = new ArrayList<>();
|
||||
private final List<VanillaStructureHookRegistration> vanillaStructureHooks = new ArrayList<>();
|
||||
private final Set<String> reservedFolders;
|
||||
private final List<DiscoveredModule> registered = new ArrayList<>();
|
||||
private FeatureCatalog catalog;
|
||||
private DiscoveredModule registering;
|
||||
|
||||
public ModuleRegistry() {
|
||||
this(Map.of());
|
||||
}
|
||||
|
||||
public ModuleRegistry(Map<FeatureAttachment.Target, Set<String>> reservedFields) {
|
||||
this(reservedFields, Set.of());
|
||||
this(Set.of());
|
||||
}
|
||||
|
||||
/** @param reservedFolders folders below the pack root that the host reads itself, which no resource kind may read */
|
||||
public ModuleRegistry(Map<FeatureAttachment.Target, Set<String>> reservedFields, Set<String> reservedFolders) {
|
||||
reserveHostFields(reservedFields);
|
||||
public ModuleRegistry(Set<String> reservedFolders) {
|
||||
this.reservedFolders = Set.copyOf(reservedFolders);
|
||||
}
|
||||
|
||||
@@ -74,7 +64,6 @@ public final class ModuleRegistry implements FeatureRegistry {
|
||||
throw new IllegalStateException("Module " + discovered.info().id() + " registered during " + registering.info().id());
|
||||
}
|
||||
registering = discovered;
|
||||
registered.add(discovered);
|
||||
try {
|
||||
discovered.module().register(this);
|
||||
} finally {
|
||||
@@ -90,7 +79,7 @@ public final class ModuleRegistry implements FeatureRegistry {
|
||||
var descriptor = FeatureDescriptor.of(featureType);
|
||||
requireOwnedId("Object generator settings " + featureType.getName() + " with feature id", descriptor.id());
|
||||
var registration = new ObjectRegistration<>(descriptor, factory);
|
||||
claim(descriptor, registering);
|
||||
claim(descriptor);
|
||||
objects.put(featureType, registration);
|
||||
}
|
||||
|
||||
@@ -112,7 +101,7 @@ public final class ModuleRegistry implements FeatureRegistry {
|
||||
checkOpen();
|
||||
var descriptor = FeatureDescriptor.of(settingsType);
|
||||
requireOwnedId("Settings " + settingsType.getName() + " with feature id", descriptor.id());
|
||||
catalogSettings(descriptor, registering);
|
||||
catalogSettings(descriptor);
|
||||
registeredByOwner.add(settingsType);
|
||||
}
|
||||
|
||||
@@ -180,7 +169,7 @@ public final class ModuleRegistry implements FeatureRegistry {
|
||||
return;
|
||||
}
|
||||
var descriptor = FeatureDescriptor.of(settingsType);
|
||||
catalogSettings(descriptor, ownerOf(descriptor));
|
||||
catalogSettings(descriptor);
|
||||
}
|
||||
|
||||
/** Whether the module owning {@code settingsType} registered it through {@link #registerSettings}. */
|
||||
@@ -196,21 +185,14 @@ public final class ModuleRegistry implements FeatureRegistry {
|
||||
return catalog;
|
||||
}
|
||||
|
||||
private void catalogSettings(FeatureDescriptor<?> descriptor, DiscoveredModule owner) {
|
||||
private void catalogSettings(FeatureDescriptor<?> descriptor) {
|
||||
if (settings.containsKey(descriptor.type())) {
|
||||
return;
|
||||
}
|
||||
claim(descriptor, owner);
|
||||
claim(descriptor);
|
||||
settings.put(descriptor.type(), descriptor);
|
||||
}
|
||||
|
||||
private DiscoveredModule ownerOf(FeatureDescriptor<?> descriptor) {
|
||||
return registered.stream()
|
||||
.filter(module -> module.info().ownsId(descriptor.id()))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new IllegalStateException("No registered module owns feature id " + descriptor.id()));
|
||||
}
|
||||
|
||||
private void requireOwnedId(String registration, ResourceId id) {
|
||||
if (registering == null) {
|
||||
throw new IllegalStateException(registration + " " + id + " registered outside IrisModule.register");
|
||||
@@ -260,53 +242,12 @@ public final class ModuleRegistry implements FeatureRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
private void reserveHostFields(Map<FeatureAttachment.Target, Set<String>> reservedFields) {
|
||||
for (var entry : reservedFields.entrySet()) {
|
||||
for (var name : entry.getValue()) {
|
||||
reserveHostField(entry.getKey(), name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void reserveHostField(FeatureAttachment.Target target, String name) {
|
||||
fields.put(new Field(target, FeatureAttachment.requireFieldName(name)), "host");
|
||||
}
|
||||
|
||||
private void claim(FeatureDescriptor<?> descriptor, DiscoveredModule owner) {
|
||||
validateClaim(descriptor, owner);
|
||||
recordClaim(descriptor);
|
||||
}
|
||||
|
||||
private void validateClaim(FeatureDescriptor<?> descriptor, DiscoveredModule owner) {
|
||||
private void claim(FeatureDescriptor<?> descriptor) {
|
||||
if (featureTypes.contains(descriptor.type()) || featureIds.contains(descriptor.id())) {
|
||||
throw new IllegalArgumentException("Duplicate feature: " + descriptor.id());
|
||||
}
|
||||
descriptor.alias().ifPresent(alias -> validateAlias(descriptor, alias, owner));
|
||||
}
|
||||
|
||||
private void validateAlias(FeatureDescriptor<?> descriptor, String alias, DiscoveredModule owner) {
|
||||
if (owner.source() == DiscoveredModule.Source.PACK) {
|
||||
throw new IllegalArgumentException("Settings " + descriptor.type().getName() + " of module " + owner
|
||||
+ " set alias '" + alias + "'; only modules that ship with the host may set one, so remove it:"
|
||||
+ " packs write these settings under their id \"" + descriptor.key() + "\"");
|
||||
}
|
||||
for (var target : descriptor.attachment().targets()) {
|
||||
var field = new Field(target, alias);
|
||||
if (fields.containsKey(field)) {
|
||||
throw new IllegalArgumentException("Alias collision at " + field + " of " + descriptor.id()
|
||||
+ ": " + fields.get(field));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void recordClaim(FeatureDescriptor<?> descriptor) {
|
||||
featureTypes.add(descriptor.type());
|
||||
featureIds.add(descriptor.id());
|
||||
descriptor.alias().ifPresent(alias -> {
|
||||
for (var target : descriptor.attachment().targets()) {
|
||||
fields.put(new Field(target, alias), descriptor.id().toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void checkOpen() {
|
||||
@@ -314,6 +255,4 @@ public final class ModuleRegistry implements FeatureRegistry {
|
||||
throw new IllegalStateException("Registration has ended");
|
||||
}
|
||||
}
|
||||
|
||||
private record Field(FeatureAttachment.Target target, String name) {}
|
||||
}
|
||||
@@ -84,7 +84,7 @@ final class PackSchemaBuilder {
|
||||
FeatureSchema complete(Map<String, ObjectType> types) {
|
||||
var descriptor = catalogued.descriptor();
|
||||
return new FeatureSchema(descriptor.id(), descriptor.name(), catalogued.role(), owner.info(), descriptor.key(),
|
||||
descriptor.alias(), descriptor.attachment().targets(), types.get(descriptor.type().getName()));
|
||||
descriptor.attachment().targets(), types.get(descriptor.type().getName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import com.volmit.resource.ResourceId;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/** A module's settings type and the JSON keys it is written under at each of its targets.
|
||||
@@ -15,8 +14,6 @@ import java.util.Set;
|
||||
* @param name the feature's display name from {@code @Feature}
|
||||
* @param module the module that owns the feature id
|
||||
* @param key the JSON key the settings are written under, the feature id, the same at every target
|
||||
* @param alias the short JSON key a built-in module accepts instead of {@code key}; pack modules
|
||||
* have none. A JSON object may use one of the two, not both.
|
||||
* @param targets where the keys appear, in {@link FeatureAttachment.Target} order
|
||||
* @param settings the settings class; its description describes the value
|
||||
*/
|
||||
@@ -26,7 +23,6 @@ public record FeatureSchema(
|
||||
FeatureRole role,
|
||||
ModuleInfo module,
|
||||
String key,
|
||||
Optional<String> alias,
|
||||
Set<FeatureAttachment.Target> targets,
|
||||
ObjectType settings) {
|
||||
public FeatureSchema {
|
||||
@@ -35,16 +31,7 @@ public record FeatureSchema(
|
||||
Objects.requireNonNull(role, "role");
|
||||
Objects.requireNonNull(module, "module");
|
||||
Objects.requireNonNull(key, "key");
|
||||
Objects.requireNonNull(alias, "alias");
|
||||
Objects.requireNonNull(settings, "settings");
|
||||
targets = Collections.unmodifiableSet(EnumSet.copyOf(targets));
|
||||
}
|
||||
|
||||
/** The settings' only option, when they have exactly one. Packs may then write that option's value
|
||||
* directly instead of an object holding it, such as {@code "snow": 0.5} for {@code "snow": {"amount": 0.5}},
|
||||
* and the host decodes a value that is not a JSON object into it.
|
||||
*/
|
||||
public Optional<SchemaOption> shorthand() {
|
||||
return settings.options().size() == 1 ? Optional.of(settings.options().getFirst()) : Optional.empty();
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
class FeatureContractTest {
|
||||
@Desc("Example settings")
|
||||
@Snippet("fill-settings")
|
||||
@Feature(id = "example:fill", name = "Fill", alias = "fill", targets = FeatureAttachment.Target.BIOME)
|
||||
@Feature(id = "example:fill", name = "Fill", targets = FeatureAttachment.Target.BIOME)
|
||||
public static class FillOptions implements IrisFeature {
|
||||
@Desc("Replacement value")
|
||||
@MinNumber(0)
|
||||
@@ -40,7 +40,6 @@ class FeatureContractTest {
|
||||
var descriptor = FeatureDescriptor.of(FillOptions.class);
|
||||
assertEquals(ResourceId.parse("example:fill"), descriptor.id());
|
||||
assertEquals("example:fill", descriptor.key());
|
||||
assertEquals(java.util.Optional.of("fill"), descriptor.alias());
|
||||
assertEquals(java.util.Set.of(FeatureAttachment.Target.BIOME), descriptor.attachment().targets());
|
||||
assertEquals(1, descriptor.options().options().size());
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ class ChunkPipelineTest {
|
||||
|
||||
@Test
|
||||
void mantleStagesWriteBeyondTheirChunkAndChunkStagesReadTheirOwnPart() {
|
||||
var loaded = LoadedModules.load(List.of(DiscoveredModule.builtIn(new VeinModule())), Map.of(), Set.of(), Set.of());
|
||||
var loaded = LoadedModules.load(List.of(DiscoveredModule.builtIn(new VeinModule())), Set.of(), Set.of());
|
||||
var vein = new Entry<>(Target.BIOME, PLAINS, new VeinSettings(12, 4));
|
||||
int reach = loaded.mantle().stages().getFirst().reachBlocks(new DeclaredSettings(vein));
|
||||
assertEquals(3, reach, "a 12 block vein from the centre column runs 3 blocks into the next chunk");
|
||||
|
||||
@@ -202,7 +202,7 @@ class PlacementLifecyclePortTest {
|
||||
|
||||
@Test
|
||||
void loadingThePortCatalogsEveryConditioningSettingsType() {
|
||||
var loaded = LoadedModules.load(PlacementModules.builtIns(), Map.of(), Set.of(), Set.of());
|
||||
var loaded = LoadedModules.load(PlacementModules.builtIns(), Set.of(), Set.of());
|
||||
|
||||
assertEquals(List.of("example:moss", "iris:snow", "iris:stilt"),
|
||||
loaded.catalog().settings().stream().map(settings -> settings.id().toString()).toList());
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.volmit.config.Feature;
|
||||
import com.volmit.config.MaxNumber;
|
||||
import com.volmit.config.MinNumber;
|
||||
|
||||
@Feature(id = "iris:snow", name = "Snow", alias = "snow", targets = FeatureAttachment.Target.OBJECT_PLACEMENT)
|
||||
@Feature(id = "iris:snow", name = "Snow", targets = FeatureAttachment.Target.OBJECT_PLACEMENT)
|
||||
public final class SnowSettings implements IrisFeature {
|
||||
@MinNumber(1)
|
||||
@MaxNumber(8)
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.volmit.config.Feature;
|
||||
import com.volmit.config.MinNumber;
|
||||
|
||||
@Desc("Fills the space below an object down to the ground")
|
||||
@Feature(id = "iris:stilt", name = "Stilt", alias = "stilt", targets = FeatureAttachment.Target.OBJECT_PLACEMENT)
|
||||
@Feature(id = "iris:stilt", name = "Stilt", targets = FeatureAttachment.Target.OBJECT_PLACEMENT)
|
||||
public final class StiltSettings implements IrisFeature {
|
||||
@Desc("Maximum blocks filled below each lowest object block")
|
||||
@MinNumber(1)
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.volmit.example.hosttypes.Palette;
|
||||
import java.util.List;
|
||||
|
||||
/** Built-in settings holding host types, written in pack JSON as a bare list: {@code "layers": [...]}. */
|
||||
@Feature(id = "iris:layers", name = "Layers", alias = "layers", targets = FeatureAttachment.Target.BIOME)
|
||||
@Feature(id = "iris:layers", name = "Layers", targets = FeatureAttachment.Target.BIOME)
|
||||
public final class LayersSettings implements IrisFeature {
|
||||
@Desc("Rock layers from the surface down")
|
||||
private List<Palette> layers = List.of();
|
||||
|
||||
@@ -76,7 +76,7 @@ class WorldStateExampleTest {
|
||||
|
||||
@Test
|
||||
void stagesServicesAndHooksShareTheStateOfTheirWorldAndANewWorldStartsEmpty() {
|
||||
var pack = LoadedModules.load(List.of(DiscoveredModule.builtIn(new RuinsModule())), Map.of(), Set.of(), Set.of());
|
||||
var pack = LoadedModules.load(List.of(DiscoveredModule.builtIn(new RuinsModule())), Set.of(), Set.of());
|
||||
var lifecycles = new LifecycleRunner(pack.catalog());
|
||||
ObjectsAt objects = pack.catalog().services(ObjectsAt.class).getFirst();
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ class DiscoveredModuleTest {
|
||||
var module = new ShiftingIdentity();
|
||||
var discovered = DiscoveredModule.builtIn(module);
|
||||
|
||||
var loaded = LoadedModules.load(List.of(discovered), Map.of(), Set.of(), Set.of());
|
||||
var loaded = LoadedModules.load(List.of(discovered), Set.of(), Set.of());
|
||||
|
||||
assertEquals("first:core", discovered.info().id().toString());
|
||||
assertEquals(List.of("first:core/mark"),
|
||||
|
||||
@@ -43,7 +43,7 @@ class LifecycleRunnerTest {
|
||||
|
||||
private static LifecycleRunner runner(IrisModule... modules) {
|
||||
var discovered = Arrays.stream(modules).map(DiscoveredModule::builtIn).toList();
|
||||
return new LifecycleRunner(LoadedModules.load(discovered, Map.of(), Set.of(), Set.of()).catalog());
|
||||
return new LifecycleRunner(LoadedModules.load(discovered, Set.of(), Set.of()).catalog());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -84,7 +84,6 @@ class LoadedPackTest {
|
||||
void invalidHostConfigurationFailsWhenBuilt() {
|
||||
var host = ModuleHost.of(List.of());
|
||||
assertThrows(IllegalArgumentException.class, () -> host.exposing("org.*"));
|
||||
assertThrows(IllegalArgumentException.class, () -> host.reservingFields(Map.of(Target.BIOME, Set.of(" "))));
|
||||
assertEquals(List.of(), host.builtIns());
|
||||
assertEquals(Set.of(), host.exposedHostPackages());
|
||||
}
|
||||
@@ -94,11 +93,11 @@ class LoadedPackTest {
|
||||
var host = ModuleHost.of(List.of())
|
||||
.exposing("example.first")
|
||||
.exposing("example.second")
|
||||
.reservingFields(Map.of(Target.BIOME, Set.of("carving"), Target.REGION, Set.of("spawns")))
|
||||
.reservingFields(Map.of(Target.BIOME, Set.of("objects")));
|
||||
.reservingFolders("biomes")
|
||||
.reservingFolders("regions");
|
||||
|
||||
assertEquals(Set.of("example.first", "example.second"), host.exposedHostPackages());
|
||||
assertEquals(Map.of(Target.BIOME, Set.of("carving", "objects"), Target.REGION, Set.of("spawns")), host.reservedHostFields());
|
||||
assertEquals(Set.of("biomes", "regions"), host.reservedFolders());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -23,16 +23,14 @@ import java.util.function.Consumer;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class ModuleRegistryTest {
|
||||
@Feature(id = "test:core/one", name = "One", alias = "shared", targets = FeatureAttachment.Target.BIOME)
|
||||
@Feature(id = "test:core/one", name = "One", targets = FeatureAttachment.Target.BIOME)
|
||||
static class One implements IrisFeature {}
|
||||
@Feature(id = "test:core/two", name = "Two", alias = "shared", targets = FeatureAttachment.Target.DIMENSION)
|
||||
@Feature(id = "test:core/two", name = "Two", targets = FeatureAttachment.Target.DIMENSION)
|
||||
static class Two implements IrisFeature {}
|
||||
@Feature(id = "test:core/collision", name = "Collision", alias = "shared", targets = {FeatureAttachment.Target.DIMENSION, FeatureAttachment.Target.BIOME})
|
||||
static class Collision implements IrisFeature {}
|
||||
@Feature(id = "test:core/one", name = "Duplicate", alias = "different", targets = FeatureAttachment.Target.REGION)
|
||||
@Feature(id = "test:core/one", name = "Duplicate", targets = FeatureAttachment.Target.REGION)
|
||||
static class Duplicate implements IrisFeature {}
|
||||
static class MissingAnnotation implements IrisFeature {}
|
||||
@Feature(id = "test:core/abstract", name = "Abstract", alias = "abstract", targets = FeatureAttachment.Target.BIOME)
|
||||
@Feature(id = "test:core/abstract", name = "Abstract", targets = FeatureAttachment.Target.BIOME)
|
||||
abstract static class AbstractFeature implements IrisFeature {}
|
||||
|
||||
/** Runs {@code registrations} as the register(...) of a built-in module with the given id. */
|
||||
@@ -50,7 +48,6 @@ class ModuleRegistryTest {
|
||||
registerAs(registry, "test:core", settings -> settings.registerSettings(One.class));
|
||||
registry.registerStageSettings(One.class);
|
||||
registerAs(registry, "test:core", objects -> {
|
||||
assertThrows(IllegalArgumentException.class, () -> objects.registerObject(Collision.class, ignored -> context -> null));
|
||||
objects.registerObject(Two.class, ignored -> context -> null);
|
||||
assertThrows(IllegalArgumentException.class, () -> objects.registerObject(Duplicate.class, ignored -> context -> null));
|
||||
assertThrows(IllegalArgumentException.class, () -> objects.registerObject(One.class, ignored -> context -> null));
|
||||
@@ -61,12 +58,8 @@ class ModuleRegistryTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void reservesHostFieldsAndRejectsInvalidFeaturesOrFactories() {
|
||||
var registry = new ModuleRegistry(Map.of(FeatureAttachment.Target.BIOME, Set.of("shared")));
|
||||
assertThrows(IllegalStateException.class, () -> registry.registerStageSettings(One.class), "no module owns it yet");
|
||||
registerAs(registry, "test:core", nothing -> {});
|
||||
var reserved = assertThrows(IllegalArgumentException.class, () -> registry.registerStageSettings(One.class));
|
||||
assertTrue(reserved.getMessage().startsWith("Alias collision"), reserved.getMessage());
|
||||
void rejectsInvalidFeaturesOrFactories() {
|
||||
var registry = new ModuleRegistry();
|
||||
assertThrows(IllegalArgumentException.class, () -> registry.registerStageSettings(MissingAnnotation.class));
|
||||
assertThrows(IllegalArgumentException.class, () -> registry.registerStageSettings(AbstractFeature.class));
|
||||
registerAs(registry, "test:core", objects -> {
|
||||
@@ -135,14 +128,31 @@ class ModuleRegistryTest {
|
||||
public void install(StageGraph graph) { graph.define(WORK).when(One.class).run((context, one) -> {}); }
|
||||
public void register(FeatureRegistry registry) { registry.registerObject(Two.class, ignored -> context -> null); }
|
||||
};
|
||||
var loaded = LoadedModules.load(List.of(DiscoveredModule.builtIn(conditioned)), Map.of(), Set.of(), Set.of());
|
||||
var loaded = LoadedModules.load(List.of(DiscoveredModule.builtIn(conditioned)), Set.of(), Set.of());
|
||||
assertEquals(List.of("test:core/one"), loaded.catalog().settings().stream().map(value -> value.id().toString()).toList());
|
||||
assertEquals(1, loaded.catalog().objects().size());
|
||||
assertEquals(1, loaded.placement().stages().size());
|
||||
assertTrue(loaded.chunk().stages().isEmpty());
|
||||
}
|
||||
|
||||
var reserved = Map.of(FeatureAttachment.Target.BIOME, Set.of("shared"));
|
||||
assertThrows(IllegalArgumentException.class, () -> LoadedModules.load(List.of(DiscoveredModule.builtIn(conditioned)), reserved, Set.of(), Set.of()));
|
||||
@Test
|
||||
void twoModulesWithOneIdRefuseTheLoadNamingBothSoASettingsKeyIsNeverShared() {
|
||||
var first = ownerOfOne("First");
|
||||
var second = ownerOfOne("Second");
|
||||
|
||||
var clash = assertThrows(IllegalArgumentException.class,
|
||||
() -> LoadedModules.load(List.of(DiscoveredModule.builtIn(first), DiscoveredModule.builtIn(second)), Set.of(), Set.of()));
|
||||
|
||||
assertTrue(clash.getMessage().startsWith("Duplicate module test:core from "), clash.getMessage());
|
||||
assertTrue(clash.getMessage().contains("already loaded from "), clash.getMessage());
|
||||
}
|
||||
|
||||
private static IrisModule ownerOfOne(String name) {
|
||||
return new IrisModule() {
|
||||
public ModuleInfo info() { return ModuleInfo.of("test:core", name, "1"); }
|
||||
public void install(StageGraph graph) {}
|
||||
public void register(FeatureRegistry registry) { registry.registerSettings(One.class); }
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -169,8 +179,8 @@ class ModuleRegistryTest {
|
||||
|
||||
registerAs(registry, "test:core", settings -> settings.registerObject(Two.class, ignored -> context -> null));
|
||||
var collision = assertThrows(IllegalArgumentException.class,
|
||||
() -> registerAs(registry, "test:core", settings -> settings.registerSettings(Collision.class)));
|
||||
assertTrue(collision.getMessage().startsWith("Alias collision"), collision.getMessage());
|
||||
() -> registerAs(registry, "test:core", settings -> settings.registerSettings(Two.class)));
|
||||
assertEquals("Duplicate feature: test:core/two", collision.getMessage());
|
||||
assertTrue(registry.freeze().settings().isEmpty());
|
||||
}
|
||||
|
||||
@@ -187,11 +197,11 @@ class ModuleRegistryTest {
|
||||
public void install(StageGraph graph) { graph.define(WORK).when(One.class).run((context, one) -> {}); }
|
||||
};
|
||||
|
||||
var loaded = LoadedModules.load(List.of(DiscoveredModule.builtIn(owner), DiscoveredModule.builtIn(user)), Map.of(), Set.of(), Set.of());
|
||||
var loaded = LoadedModules.load(List.of(DiscoveredModule.builtIn(owner), DiscoveredModule.builtIn(user)), Set.of(), Set.of());
|
||||
assertEquals(List.of("test:core/one"), loaded.catalog().settings().stream().map(value -> value.id().toString()).toList());
|
||||
|
||||
var unowned = assertThrows(IllegalArgumentException.class,
|
||||
() -> LoadedModules.load(List.of(DiscoveredModule.builtIn(user)), Map.of(), Set.of(), Set.of()));
|
||||
() -> LoadedModules.load(List.of(DiscoveredModule.builtIn(user)), Set.of(), Set.of()));
|
||||
assertTrue(unowned.getMessage().contains("which none of the modules naming it in when(...) owns"), unowned.getMessage());
|
||||
}
|
||||
|
||||
@@ -200,7 +210,7 @@ class ModuleRegistryTest {
|
||||
|
||||
@Test
|
||||
void resourceKindsHaveOwnedIdsAndOneIdTypeAndFolderEach() {
|
||||
var registry = new ModuleRegistry(Map.of(), Set.of("biomes"));
|
||||
var registry = new ModuleRegistry(Set.of("biomes"));
|
||||
var castles = ResourceKind.of("test:core/castle", "castles", Castle.class);
|
||||
registerAs(registry, "test:core", kinds -> {
|
||||
kinds.registerResourceKind(castles);
|
||||
|
||||
@@ -43,7 +43,7 @@ class PackModulesTest {
|
||||
private static LoadedModules loadWithBuiltIns(PackModules packModules) {
|
||||
var modules = new ArrayList<>(PlacementModules.builtIns());
|
||||
modules.addAll(packModules.modules());
|
||||
return LoadedModules.load(modules, Map.of(), Set.of(), Set.of());
|
||||
return LoadedModules.load(modules, Set.of(), Set.of());
|
||||
}
|
||||
|
||||
/** Versioned entries of a multi-release jar are read like any class, so they must be real class files. */
|
||||
@@ -154,7 +154,7 @@ class PackModulesTest {
|
||||
packModules.modules().stream().map(found -> found.info().id().toString()).toList());
|
||||
assertEquals(List.of(origin("two.jar"), origin("two.jar")),
|
||||
packModules.modules().stream().map(DiscoveredModule::origin).toList());
|
||||
assertDoesNotThrow(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of()));
|
||||
assertDoesNotThrow(() -> LoadedModules.load(packModules.modules(), Set.of(), Set.of()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -378,7 +378,7 @@ class PackModulesTest {
|
||||
|
||||
try (var packModules = PackModules.load(pack)) {
|
||||
assertEquals(List.of(new MissingClasses(origin("user.jar"), List.of(OPTIONAL_CLASS))), packModules.missingClasses());
|
||||
assertDoesNotThrow(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of()));
|
||||
assertDoesNotThrow(() -> LoadedModules.load(packModules.modules(), Set.of(), Set.of()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -512,7 +512,7 @@ class PackModulesTest {
|
||||
.writeInto(pack, "beta.jar");
|
||||
|
||||
try (var packModules = PackModules.load(pack)) {
|
||||
var loaded = LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of());
|
||||
var loaded = LoadedModules.load(packModules.modules(), Set.of(), Set.of());
|
||||
assertTrue(loaded.placement().stages().stream().anyMatch(stage -> stage.stage().id().toString().equals("beta:core/size")));
|
||||
var beta = packModules.modules().getLast().module().getClass();
|
||||
assertEquals(0, beta.getDeclaredField("SHARED").getAnnotations().length,
|
||||
@@ -529,7 +529,7 @@ class PackModulesTest {
|
||||
try (var packModules = PackModules.load(pack, List.of(BUILT_IN_PACKAGE))) {
|
||||
var modules = new ArrayList<>(List.of(DiscoveredModule.builtIn(new CarveModule())));
|
||||
modules.addAll(packModules.modules());
|
||||
var order = LoadedModules.load(modules, Map.of(), Set.of(), Set.of()).placement().stages().stream()
|
||||
var order = LoadedModules.load(modules, Set.of(), Set.of()).placement().stages().stream()
|
||||
.map(stage -> stage.stage().id().toString()).toList();
|
||||
assertEquals(List.of("iris:carve/clear", "user:core/carved"), order);
|
||||
}
|
||||
@@ -607,7 +607,7 @@ class PackModulesTest {
|
||||
.writeInto(pack, "once.jar");
|
||||
|
||||
try (var packModules = PackModules.load(pack)) {
|
||||
var loaded = assertDoesNotThrow(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of()));
|
||||
var loaded = assertDoesNotThrow(() -> LoadedModules.load(packModules.modules(), Set.of(), Set.of()));
|
||||
assertEquals("once:core", packModules.modules().getFirst().info().id().toString());
|
||||
assertEquals(1, loaded.placement().stages().size());
|
||||
}
|
||||
@@ -626,7 +626,7 @@ class PackModulesTest {
|
||||
.writeInto(pack, "beta.jar");
|
||||
|
||||
try (var packModules = PackModules.load(pack)) {
|
||||
assertMentions(failure(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of())),
|
||||
assertMentions(failure(() -> LoadedModules.load(packModules.modules(), Set.of(), Set.of())),
|
||||
"Module beta:core from " + origin("beta.jar") + " failed to link or initialize a class while installing",
|
||||
"java.lang.NoSuchMethodError", "pack.lib.Lib.added()");
|
||||
}
|
||||
@@ -638,7 +638,7 @@ class PackModulesTest {
|
||||
module("pack.two.Duplicate", "dup:core", NO_MEMBERS, NO_STAGES).writeInto(pack, "two.jar");
|
||||
|
||||
try (var packModules = PackModules.load(pack)) {
|
||||
assertMentions(failure(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of())),
|
||||
assertMentions(failure(() -> LoadedModules.load(packModules.modules(), Set.of(), Set.of())),
|
||||
"Duplicate module dup:core from " + origin("two.jar") + " (pack.two.Duplicate); already loaded from "
|
||||
+ origin("one.jar") + " (pack.one.Duplicate)");
|
||||
}
|
||||
@@ -662,7 +662,7 @@ class PackModulesTest {
|
||||
.writeInto(pack, "foreign.jar");
|
||||
|
||||
try (var packModules = PackModules.load(pack)) {
|
||||
assertMentions(failure(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of())),
|
||||
assertMentions(failure(() -> LoadedModules.load(packModules.modules(), Set.of(), Set.of())),
|
||||
"Stage mine:other/work must start with mine:core/, the id of its defining module mine:core from " + origin("foreign.jar"));
|
||||
}
|
||||
}
|
||||
@@ -674,7 +674,7 @@ class PackModulesTest {
|
||||
.writeInto(pack, "both.jar");
|
||||
|
||||
try (var packModules = PackModules.load(pack)) {
|
||||
assertMentions(failure(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of())),
|
||||
assertMentions(failure(() -> LoadedModules.load(packModules.modules(), Set.of(), Set.of())),
|
||||
"Duplicate module dup:core from " + origin("both.jar") + " (pack.Two); already loaded from "
|
||||
+ origin("both.jar") + " (pack.One)");
|
||||
}
|
||||
@@ -687,7 +687,7 @@ class PackModulesTest {
|
||||
.writeInto(pack, "stilt.jar");
|
||||
|
||||
try (var packModules = PackModules.load(pack)) {
|
||||
assertDoesNotThrow(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of()));
|
||||
assertDoesNotThrow(() -> LoadedModules.load(packModules.modules(), Set.of(), Set.of()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -206,7 +206,6 @@ class PackSchemaTest {
|
||||
assertEquals(List.of("example:flora"), names(schema.fields(Target.REGION), FeatureSchema::key));
|
||||
assertEquals(List.of("example:flora/wind"), names(schema.fields(Target.DIMENSION), FeatureSchema::key));
|
||||
assertEquals(List.of("example:flora/bush"), names(schema.fields(Target.OBJECT_PLACEMENT), FeatureSchema::key));
|
||||
assertTrue(schema.features().stream().allMatch(feature -> feature.alias().isEmpty()), "pack modules have no alias");
|
||||
assertEquals(List.of("example:flora", "example:flora/bush", "example:flora/wind"), names(schema.features(), FeatureSchema::id));
|
||||
|
||||
var flora = schema.features().getFirst();
|
||||
@@ -333,8 +332,6 @@ class PackSchemaTest {
|
||||
|
||||
assertEquals(List.of("example:grass", "example:moss", "iris:snow", "iris:stilt"), names(schema.features(), FeatureSchema::id));
|
||||
assertEquals(List.of("example:moss", "iris:snow", "iris:stilt"), names(schema.fields(Target.OBJECT_PLACEMENT), FeatureSchema::key));
|
||||
assertEquals(List.of("", "snow", "stilt"), names(schema.fields(Target.OBJECT_PLACEMENT), feature -> feature.alias().orElse("")),
|
||||
"built-ins keep their short aliases");
|
||||
|
||||
var stilt = schema.fields(Target.OBJECT_PLACEMENT).get(2);
|
||||
assertEquals("Stilts", stilt.module().name());
|
||||
@@ -358,7 +355,6 @@ class PackSchemaTest {
|
||||
assertEquals(Optional.of(List.of()), option.defaultValue());
|
||||
assertTrue(schema.types().stream().noneMatch(type -> type.name().equals(Palette.class.getName())),
|
||||
"the host describes its own types, so their fields are never read");
|
||||
assertEquals(Optional.of(option), layers.shorthand(), "one option: packs may write the bare list");
|
||||
|
||||
var undeclared = assertThrows(IllegalArgumentException.class, () -> schemaOf(pack("layers"), ModuleHost.of(builtIns)));
|
||||
assertTrue(undeclared.getMessage().startsWith("Field " + Palette.class.getName() + ".anything of settings iris:layers"),
|
||||
@@ -375,12 +371,6 @@ class PackSchemaTest {
|
||||
loadFailure(host, "private " + Palette.class.getName() + " palette;").getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void onlySettingsWithOneOptionHaveAShorthand() {
|
||||
var flora = floraSchema().fields(Target.BIOME).getFirst();
|
||||
assertEquals(Optional.empty(), flora.shorthand());
|
||||
}
|
||||
|
||||
/** A pack whose module example:flora registers pack.flora.FloraSettings with {@code body} as its class body. */
|
||||
private IllegalArgumentException loadFailure(String body, String... otherSources) {
|
||||
return loadFailure(NO_BUILT_INS, body, otherSources);
|
||||
@@ -599,26 +589,6 @@ class PackSchemaTest {
|
||||
.map(type -> type.snippet().orElseThrow()).toList(), "the module's own folder is under its path");
|
||||
}
|
||||
|
||||
@Test
|
||||
void packModulesCannotSetAnAlias() {
|
||||
var pack = pack("alias");
|
||||
module("pack.flora.FloraModule", FLORA,
|
||||
"public void register(com.volmit.FeatureRegistry registry) { registry.registerSettings(FloraSettings.class); }", NO_STAGES)
|
||||
.source("pack.flora.FloraSettings", """
|
||||
package pack.flora;
|
||||
|
||||
@com.volmit.config.Feature(id = "example:flora", name = "Flora", alias = "flora", targets = com.volmit.FeatureAttachment.Target.BIOME)
|
||||
public final class FloraSettings implements com.volmit.IrisFeature {}
|
||||
""")
|
||||
.writeInto(pack, "flora.jar");
|
||||
|
||||
var failure = assertThrows(IllegalArgumentException.class, () -> LoadedPack.load(pack, NO_BUILT_INS));
|
||||
|
||||
assertEquals("Settings pack.flora.FloraSettings of module example:flora from modules/flora.jar set alias 'flora'; only modules"
|
||||
+ " that ship with the host may set one, so remove it: packs write these settings under their id \"example:flora\"",
|
||||
failure.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void packReferencesFitOnlyPlainText() {
|
||||
assertLoadFails("Field pack.flora.FloraSettings.home of " + FLORA_SOURCE + " has @Ref(PACK_BIOME) on ResourceId, but packs name"
|
||||
|
||||
@@ -45,7 +45,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
class StageGraphTest {
|
||||
private static final BlockState STONE = new BlockState("minecraft:stone");
|
||||
|
||||
@Feature(id = "test:owner/toggle", name = "Toggle", alias = "toggle", targets = FeatureAttachment.Target.OBJECT_PLACEMENT)
|
||||
@Feature(id = "test:owner/toggle", name = "Toggle", targets = FeatureAttachment.Target.OBJECT_PLACEMENT)
|
||||
static final class Toggle implements IrisFeature {}
|
||||
|
||||
static final class Unannotated implements IrisFeature {}
|
||||
@@ -478,7 +478,7 @@ class StageGraphTest {
|
||||
stages.define(plain).run(context -> {});
|
||||
stages.define(paint).reach(2).run(context -> {});
|
||||
});
|
||||
var loaded = LoadedModules.load(List.of(DiscoveredModule.builtIn(withMantle(reach, depth, marks))), Map.of(), Set.of(), Set.of());
|
||||
var loaded = LoadedModules.load(List.of(DiscoveredModule.builtIn(withMantle(reach, depth, marks))), Set.of(), Set.of());
|
||||
|
||||
assertEquals(new StageReach(24, List.of(depth)), loaded.mantle().stages().getFirst().reach());
|
||||
assertEquals(StageReach.NONE, loaded.mantle().stages().get(2).reach(), "an undeclared reach is 0 with no layers");
|
||||
@@ -496,7 +496,7 @@ class StageGraphTest {
|
||||
var loaded = LoadedModules.load(List.of(DiscoveredModule.builtIn(module("test:reach", stages -> {
|
||||
stages.define(carve).reach(settings -> settings.declared(Toggle.class).isEmpty() ? 4 : 40).run(context -> {});
|
||||
stages.define(mark).reach(2).run(context -> {});
|
||||
}))), Map.of(), Set.of(), Set.of());
|
||||
}))), Set.of(), Set.of());
|
||||
var computed = loaded.mantle().stages().getFirst();
|
||||
var toggled = new DeclaredSettings(new Entry<>(FeatureAttachment.Target.DIMENSION, ResourceId.parse("pack:dimension/main"), new Toggle()));
|
||||
|
||||
@@ -512,7 +512,7 @@ class StageGraphTest {
|
||||
@Test
|
||||
void onlyMantleStagesWorkOutTheirReachAndNeverANegativeOne() {
|
||||
var negative = LoadedModules.load(List.of(DiscoveredModule.builtIn(module("test:reach", stages ->
|
||||
stages.define(Stage.mantle("test:reach/carve")).reach(settings -> -1).run(context -> {})))), Map.of(), Set.of(), Set.of());
|
||||
stages.define(Stage.mantle("test:reach/carve")).reach(settings -> -1).run(context -> {})))), Set.of(), Set.of());
|
||||
var failure = assertThrows(IllegalStateException.class, () -> negative.mantle().stages().getFirst().reachBlocks(DeclaredSettings.NONE));
|
||||
assertEquals("Stage test:reach/carve of module test:reach worked out a negative reach of -1 blocks for this pack", failure.getMessage());
|
||||
|
||||
@@ -567,13 +567,13 @@ class StageGraphTest {
|
||||
module("test:reach", stages -> stages.define(carve).writesMantle(depth, depth).run(context -> {}))));
|
||||
|
||||
var unregistered = assertThrows(IllegalArgumentException.class, () -> LoadedModules.load(List.of(DiscoveredModule.builtIn(
|
||||
module("test:reach", stages -> stages.define(carve).writesMantle(depth).run(context -> {})))), Map.of(), Set.of(), Set.of()));
|
||||
module("test:reach", stages -> stages.define(carve).writesMantle(depth).run(context -> {})))), Set.of(), Set.of()));
|
||||
assertEquals("Stage test:reach/carve of module test:reach writes mantle layer test:reach/depth, which no module registers;"
|
||||
+ " its owner registers it with FeatureRegistry.registerMantle", unregistered.getMessage());
|
||||
|
||||
var asText = new MantleKey<>("test:reach/depth", String.class);
|
||||
var mismatch = assertThrows(IllegalArgumentException.class, () -> LoadedModules.load(List.of(DiscoveredModule.builtIn(withMantle(
|
||||
module("test:reach", stages -> stages.define(carve).writesMantle(asText).run(context -> {})), depth))), Map.of(), Set.of(), Set.of()));
|
||||
module("test:reach", stages -> stages.define(carve).writesMantle(asText).run(context -> {})), depth))), Set.of(), Set.of()));
|
||||
assertEquals("Stage test:reach/carve of module test:reach writes mantle layer test:reach/depth as java.lang.String,"
|
||||
+ " but it is registered as java.lang.Integer", mismatch.getMessage());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user