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

@@ -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);