Merge branch 'wave2/e2'

This commit is contained in:
piexel committed 2026-10-09 22:33:28 +02:00
commit 1707bb95f6
12 files changed
+131 -3

No files matched your search

+1 -1
View File
@@ -23,7 +23,7 @@ types that carry them and lists what the Iris adapter still owes.
| 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), 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`, `@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`, `FeatureRegistry.registerSettings`, `FeatureRegistry.registerHeldType`, host `FeatureCatalog.heldTypes()`, 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`), `PaletteSpec` and `PaletteSampler` (`BlockRegistry.palette`) |
| Noise from pack-described styles | `NoiseStyle`, `StyledRange`, `PackResources.noise()`, `NoiseFactory`, `NoiseSampler` |
+3
View File
@@ -613,6 +613,9 @@ never equal a feature id.
inlined copy, so a class used in many places is described once, and a class that contains itself,
directly or through others, ends the walk at its own name. Two different classes with one name fail
the load; only a built-in class and a pack class can collide that way.
- Built-in modules may also register a class that Iris's own classes hold (`registerHeldType`, `FeatureCatalog.heldTypes()`):
it is described like any settings class reachable from a feature, but no `FeatureSchema` names it. This is for
settings that live in a host class until their feature owns them, such as the clamp of an object placement.
- A `SchemaOption` per field that `OptionsMetadata` selects, which means instance fields that are
not transient, inherited ones included, in declaration order. Each has its name, `ValueKind`,
`@Desc`, `@Required`, `@MinNumber`/`@MaxNumber`, `@MinItems` and the default value.
+3
View File
@@ -424,6 +424,9 @@ public final class FloraSettings implements IrisFeature {
that no stage names, such as ones read only through `FeatureSettings.at(...)`, are registered with
`registry.registerSettings(WindSettings.class)` in `register`. Their feature id follows the module
id like any other, and once registered, other modules may name them in `when(...)`.
- A class of a built-in module that Iris's own classes hold, such as the clamp field of an object placement, is
registered with `registry.registerHeldType(Clamp.class)`, so studio describes it from the class (as an
`ObjectType`, with no feature). Only built-in modules may; a pack module's class can never be a field of an Iris class.
A load error names the field, the settings and the module:
@@ -35,6 +35,14 @@ public interface FeatureRegistry {
*/
void registerSettings(Class<? extends IrisFeature> settingsType);
/** Describes a class that Iris's own classes hold, such as the clamp of an object placement, so studio shows
* its fields as this class declares them. Only built-in modules may register one: the host classes that hold
* the class are Iris's, so a pack module's class could never be a field of one. The host reads the class
* with its fields in pack JSON, and the class follows the rules of settings classes. Registering a class twice
* changes nothing.
*/
void registerHeldType(Class<?> type);
/** Declares a kind of pack resource this module reads: the JSON files under the kind's folder, served through
* {@link com.volmit.resource.PackResources} by the kind's type and described for studio from its class like
* settings. The pack load fails when another kind has the same id, type or folder, or the folder is one the
@@ -21,6 +21,7 @@ public final class FeatureCatalog {
private final Map<Class<?>, ObjectRegistration<?>> objects;
private final Map<String, MantleRegistration<?>> mantle;
private final List<ResourceKindRegistration> resourceKinds;
private final List<HeldTypeRegistration> heldTypes;
private final List<ValidatorRegistration> validators;
private final List<LifecycleRegistration> lifecycles;
private final List<ServiceRegistration> services;
@@ -31,6 +32,7 @@ public final class FeatureCatalog {
Map<Class<?>, ObjectRegistration<?>> objects,
Map<String, MantleRegistration<?>> mantle,
Collection<ResourceKindRegistration> resourceKinds,
Collection<HeldTypeRegistration> heldTypes,
List<ValidatorRegistration> validators,
List<LifecycleRegistration> lifecycles,
List<ServiceRegistration> services,
@@ -39,6 +41,7 @@ public final class FeatureCatalog {
this.objects = Map.copyOf(objects);
this.mantle = Map.copyOf(mantle);
this.resourceKinds = sorted(resourceKinds, registration -> registration.kind().id());
this.heldTypes = sorted(heldTypes, registration -> registration.type().getName());
this.validators = inModuleOrder(validators, ValidatorRegistration::module);
this.lifecycles = inModuleOrder(lifecycles, LifecycleRegistration::module);
this.services = inModuleOrder(services, ServiceRegistration::module);
@@ -63,6 +66,11 @@ public final class FeatureCatalog {
return resourceKinds;
}
/** The classes built-in modules described because Iris's own classes hold them, by class name. */
public List<HeldTypeRegistration> heldTypes() {
return heldTypes;
}
/** The validators modules registered, by module id, each module's in the order it registered them. */
public List<ValidatorRegistration> validators() {
return validators;
@@ -0,0 +1,16 @@
package com.volmit.host;
import java.util.Objects;
/** A class of a built-in module that Iris's own classes hold, and the module that registered it. */
public record HeldTypeRegistration(Class<?> type, DiscoveredModule module) {
public HeldTypeRegistration {
Objects.requireNonNull(type, "type");
Objects.requireNonNull(module, "module");
}
@Override
public String toString() {
return "held type " + type.getName() + " of module " + module;
}
}
@@ -39,6 +39,7 @@ public final class ModuleRegistry implements FeatureRegistry {
private final Set<Class<?>> featureTypes = new HashSet<>();
private final Set<Class<?>> registeredByOwner = new HashSet<>();
private final Map<ResourceId, ResourceKindRegistration> resourceKinds = new HashMap<>();
private final Map<Class<?>, HeldTypeRegistration> heldTypes = new HashMap<>();
private final List<ValidatorRegistration> validators = new ArrayList<>();
private final List<LifecycleRegistration> lifecycles = new ArrayList<>();
private final List<ServiceRegistration> services = new ArrayList<>();
@@ -105,6 +106,18 @@ public final class ModuleRegistry implements FeatureRegistry {
registeredByOwner.add(settingsType);
}
@Override
public void registerHeldType(Class<?> type) {
checkOpen();
Objects.requireNonNull(type, "type");
requireRegistering("Held type " + type.getName());
if (registering.source() != DiscoveredModule.Source.HOST) {
throw new IllegalArgumentException("Held type " + type.getName() + " of module " + registering + " is registered by a"
+ " pack module; only built-in modules may describe a class that Iris's own classes hold");
}
heldTypes.putIfAbsent(type, new HeldTypeRegistration(type, registering));
}
@Override
public <T> void registerResourceKind(ResourceKind<T> kind) {
checkOpen();
@@ -179,8 +192,8 @@ public final class ModuleRegistry implements FeatureRegistry {
public FeatureCatalog freeze() {
if (catalog == null) {
catalog = new FeatureCatalog(settings, objects, mantle, resourceKinds.values(), validators, lifecycles, services,
vanillaStructureHooks);
catalog = new FeatureCatalog(settings, objects, mantle, resourceKinds.values(), heldTypes.values(),
validators, lifecycles, services, vanillaStructureHooks);
}
return catalog;
}
@@ -47,6 +47,7 @@ final class PackSchemaBuilder {
private PackSchema describe(FeatureCatalog catalog) {
var features = catalogued(catalog).map(this::draft).toList();
var resources = catalog.resourceKinds().stream().map(this::describe).toList();
catalog.heldTypes().forEach(this::draft);
requireUniqueSnippets();
var types = completeTypes();
return new PackSchema(features.stream().map(feature -> feature.complete(types)).toList(), resources,
@@ -97,6 +98,10 @@ final class PackSchemaBuilder {
return Stream.concat(settings, objects).sorted(Comparator.comparing(catalogued -> catalogued.descriptor().id()));
}
private void draft(HeldTypeRegistration held) {
drafts.settings(SchemaSource.heldType(held));
}
private FeatureDraft draft(Catalogued catalogued) {
var owner = ownerOf(catalogued.descriptor());
drafts.settings(SchemaSource.settings(catalogued.descriptor(), owner));
@@ -16,6 +16,10 @@ record SchemaSource(String subject, Class<?> type, DiscoveredModule module) {
return new SchemaSource("resource kind " + kind.id(), kind.type(), module);
}
static SchemaSource heldType(HeldTypeRegistration held) {
return new SchemaSource("held type " + held.type().getName(), held.type(), held.module());
}
@Override
public String toString() {
return subject + " (module " + module + ")";
@@ -0,0 +1,19 @@
package com.volmit.example.held;
import com.volmit.config.Desc;
import com.volmit.config.MaxNumber;
import com.volmit.config.MinNumber;
import com.volmit.config.Snippet;
@Snippet("clamp")
@Desc("Limits a placement by height")
public final class ClampSettings {
@MinNumber(-2048)
@MaxNumber(2048)
@Desc("The lowest height")
private int minimumHeight = -2048;
public int minimumHeight() {
return minimumHeight;
}
}
@@ -0,0 +1,23 @@
package com.volmit.example.held;
import com.volmit.FeatureRegistry;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
import com.volmit.stage.StageGraph;
/** A built-in module whose settings class is held by a class of the host, not by a feature. */
public final class HeldModule implements IrisModule {
@Override
public ModuleInfo info() {
return ModuleInfo.of("iris:held", "Held", "test");
}
@Override
public void install(StageGraph graph) {}
@Override
public void register(FeatureRegistry registry) {
registry.registerHeldType(ClampSettings.class);
registry.registerHeldType(ClampSettings.class);
}
}
@@ -4,6 +4,8 @@ import com.volmit.FeatureAttachment.Target;
import com.volmit.config.Reference;
import com.volmit.example.chunk.GrassModule;
import com.volmit.example.chunk.TerrainModule;
import com.volmit.example.held.ClampSettings;
import com.volmit.example.held.HeldModule;
import com.volmit.example.hosttypes.Palette;
import com.volmit.example.placement.PlacementModules;
import com.volmit.example.terrain.LayersModule;
@@ -365,6 +367,30 @@ class PackSchemaTest {
assertThrows(IllegalArgumentException.class, () -> NO_BUILT_INS.describingHostTypesIn("not a package"));
}
@Test
void builtInModulesDescribeTheClassesTheHostsClassesHold() {
var schema = schemaOf(pack("held"), ModuleHost.of(List.<com.volmit.IrisModule>of(new HeldModule())));
assertEquals(List.of(), schema.features());
assertEquals(new ObjectType(ClampSettings.class.getName(), "Limits a placement by height", Optional.of("clamp"),
List.of(new SchemaOption("minimumHeight", new IntegerKind(), "The lowest height", false, OptionalDouble.of(-2048),
OptionalDouble.of(2048), OptionalInt.empty(), Optional.of(-2048L)))), schema.type(ClampSettings.class.getName()));
assertEquals(List.of(ClampSettings.class.getName()), schema.snippets().stream().map(ObjectType::name).toList());
}
@Test
void packModulesCannotRegisterHeldTypes() {
var jar = module("pack.flora.FloraModule", FLORA,
"public void register(com.volmit.FeatureRegistry registry) { registry.registerHeldType(pack.flora.Clamp.class); }", NO_STAGES)
.source("pack.flora.Clamp", "package pack.flora; public final class Clamp { private int minimum; }");
var pack = pack("held-by-pack");
jar.writeInto(pack, "flora.jar");
var failure = assertThrows(IllegalArgumentException.class, () -> LoadedPack.load(pack, NO_BUILT_INS));
assertTrue(failure.getMessage().contains("Held type pack.flora.Clamp") && failure.getMessage().contains("only built-in modules"),
failure.getMessage());
}
@Test
void packModulesCannotUseHostTypes() {
var host = NO_BUILT_INS.exposing(HOST_TYPES).describingHostTypesIn(HOST_TYPES);