From 2b6f96e5c26c8147e23f32e2dea050cf4d581246 Mon Sep 17 00:00:00 2001 From: piexel Date: Fri, 6 Nov 2026 05:55:48 +0100 Subject: [PATCH] Remove API surface no module or host uses The object generator registration (registerObject, ObjectGenerator, ObjectGeneratorFactory, ObjectGenerationContext, FeatureRole): the host catalogued generators but never called one. PlacementContext.objects() with ObjectTransformer and ObjectTransform, PlacementContext.blocks() (placementTerrain() answers the same), BlockPalette, EntitySpec.extensions and Reference.BIOME go too. --- .../main/java/com/volmit/FeatureRegistry.java | 3 - .../java/com/volmit/block/BlockPalette.java | 12 ---- .../java/com/volmit/config/Reference.java | 5 +- .../java/com/volmit/entity/EntitySpec.java | 9 +-- .../volmit/generation/InvocationContext.java | 2 +- .../object/ObjectGenerationContext.java | 12 ---- .../com/volmit/object/ObjectGenerator.java | 9 --- .../volmit/object/ObjectGeneratorFactory.java | 8 --- .../com/volmit/object/ObjectTransform.java | 20 ------ .../com/volmit/object/ObjectTransformer.java | 9 --- .../volmit/placement/PlacementContext.java | 7 +- .../java/com/volmit/random/WorldRandom.java | 3 +- .../com/volmit/ItemAndEntityValuesTest.java | 14 +--- .../java/com/volmit/host/FeatureCatalog.java | 18 ----- .../java/com/volmit/host/ModuleRegistry.java | 18 +---- .../com/volmit/host/ObjectRegistration.java | 20 ------ .../com/volmit/host/PackSchemaBuilder.java | 29 +++----- .../com/volmit/host/PlacementInvocation.java | 12 ---- .../com/volmit/host/schema/FeatureRole.java | 9 --- .../com/volmit/host/schema/FeatureSchema.java | 2 - .../com/volmit/host/schema/PackSchema.java | 5 -- .../example/placement/AnchorModule.java | 15 +--- .../com/volmit/host/ModuleRegistryTest.java | 50 +++++-------- .../java/com/volmit/host/PackSchemaTest.java | 16 ++--- .../com/volmit/support/ColumnTerrain.java | 72 +++++++++++++++++++ .../java/com/volmit/support/TestContexts.java | 9 +-- 26 files changed, 119 insertions(+), 269 deletions(-) delete mode 100644 api/src/main/java/com/volmit/block/BlockPalette.java delete mode 100644 api/src/main/java/com/volmit/object/ObjectGenerationContext.java delete mode 100644 api/src/main/java/com/volmit/object/ObjectGenerator.java delete mode 100644 api/src/main/java/com/volmit/object/ObjectGeneratorFactory.java delete mode 100644 api/src/main/java/com/volmit/object/ObjectTransform.java delete mode 100644 api/src/main/java/com/volmit/object/ObjectTransformer.java delete mode 100644 host/src/main/java/com/volmit/host/ObjectRegistration.java delete mode 100644 host/src/main/java/com/volmit/host/schema/FeatureRole.java create mode 100644 host/src/test/java/com/volmit/support/ColumnTerrain.java diff --git a/api/src/main/java/com/volmit/FeatureRegistry.java b/api/src/main/java/com/volmit/FeatureRegistry.java index b53546a22..54b980a43 100644 --- a/api/src/main/java/com/volmit/FeatureRegistry.java +++ b/api/src/main/java/com/volmit/FeatureRegistry.java @@ -3,7 +3,6 @@ package com.volmit; import com.volmit.mantle.MantleCodec; import com.volmit.mantle.MantleKey; import com.volmit.mantle.MantleLifetime; -import com.volmit.object.ObjectGeneratorFactory; import com.volmit.resource.ResourceKind; import com.volmit.service.Service; import com.volmit.stage.StageGraph; @@ -24,8 +23,6 @@ public interface FeatureRegistry { */ void registerMantle(MantleKey key, MantleLifetime lifetime, MantleCodec codec); - void registerObject(Class featureType, ObjectGeneratorFactory factory); - /** Catalogs settings types that no stage names in {@code when(...)}, such as ones read only * through {@link com.volmit.config.FeatureSettings#at}, so the host decodes them and studio * describes them: {@code registerSettings(WindSettings.class, GustSettings.class)}. Settings that a diff --git a/api/src/main/java/com/volmit/block/BlockPalette.java b/api/src/main/java/com/volmit/block/BlockPalette.java deleted file mode 100644 index c040f1072..000000000 --- a/api/src/main/java/com/volmit/block/BlockPalette.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.volmit.block; - -import com.volmit.random.WorldRandom; - -/** Resolved, immutable palette. X and Z are world coordinates, Y is the height above the - * dimension's bottom (0 = bottom); selection uses only the given stream. - * An empty/unresolvable palette is a pack-load error. Implementations must support concurrent calls. - */ -@FunctionalInterface -public interface BlockPalette { - BlockState select(int worldX, int y, int worldZ, WorldRandom random); -} diff --git a/api/src/main/java/com/volmit/config/Reference.java b/api/src/main/java/com/volmit/config/Reference.java index e2610d093..2bddcb553 100644 --- a/api/src/main/java/com/volmit/config/Reference.java +++ b/api/src/main/java/com/volmit/config/Reference.java @@ -2,8 +2,7 @@ package com.volmit.config; /** The platform registry a text option names, so studio can offer the matching completion list: entries of the * server's registries, such as {@code minecraft:stone}, including those that data packs and mods add, and the host's - * own noise generators. Resources of the pack are named by their kind instead, {@code @Ref(kind = ...)}. The set is - * closed: every registry is one the Iris host can list. + * own noise generators. Resources of the pack are named by their kind instead, {@code @Ref(kind = ...)}. */ public enum Reference { /** A block type, such as {@code minecraft:stone}. {@link com.volmit.block.BlockState} options are block references without {@link Ref}. */ @@ -12,8 +11,6 @@ public enum Reference { ITEM, /** An entity type, such as {@code minecraft:zombie}. */ ENTITY, - /** A platform biome, such as {@code minecraft:plains}; not a biome of the pack. */ - BIOME, /** A platform structure, such as {@code minecraft:village_plains}. */ STRUCTURE, /** A platform structure or a prefix naming a family of them: {@code minecraft:village_plains}, diff --git a/api/src/main/java/com/volmit/entity/EntitySpec.java b/api/src/main/java/com/volmit/entity/EntitySpec.java index 1313d5d07..af55690b7 100644 --- a/api/src/main/java/com/volmit/entity/EntitySpec.java +++ b/api/src/main/java/com/volmit/entity/EntitySpec.java @@ -23,11 +23,10 @@ import java.util.Optional; * @param arrival what happens where it appears * @param adjustsProvidedMob whether the rest of the spec also applies to a {@link ContentKey.Provided} mob, which is * otherwise left as its provider set it up - * @param extensions values for a particular host, which other hosts ignore; see {@link #extension} */ public record EntitySpec(ContentKey type, Appearance appearance, Behaviour behaviour, Equipment equipment, List attributes, Company company, Drops drops, Arrival arrival, - boolean adjustsProvidedMob, List extensions) { + boolean adjustsProvidedMob) { public EntitySpec { Objects.requireNonNull(type, "type"); Objects.requireNonNull(appearance, "appearance"); @@ -37,12 +36,6 @@ public record EntitySpec(ContentKey type, Appearance appearance, Behaviour behav Objects.requireNonNull(company, "company"); Objects.requireNonNull(drops, "drops"); Objects.requireNonNull(arrival, "arrival"); - extensions = List.copyOf(extensions); - } - - /** The extension of type {@code type} the module added for its host; empty when it added none. */ - public Optional extension(Class type) { - return extensions.stream().filter(type::isInstance).map(type::cast).findFirst(); } /** diff --git a/api/src/main/java/com/volmit/generation/InvocationContext.java b/api/src/main/java/com/volmit/generation/InvocationContext.java index 45b934c41..0951f8d50 100644 --- a/api/src/main/java/com/volmit/generation/InvocationContext.java +++ b/api/src/main/java/com/volmit/generation/InvocationContext.java @@ -7,7 +7,7 @@ import java.util.Optional; /** Host-owned invocation inputs. Views must not be retained or used by detached tasks. * *

There is no shared random stream. A stage draws from {@link com.volmit.stage.StageContext#random()}, - * a stream of its own, and an object generator from {@link com.volmit.object.ObjectGenerationContext#random()}. + * a stream of its own. */ public interface InvocationContext { /** The world this invocation generates: its seed, the pack snapshot's resources, its settings and the state modules diff --git a/api/src/main/java/com/volmit/object/ObjectGenerationContext.java b/api/src/main/java/com/volmit/object/ObjectGenerationContext.java deleted file mode 100644 index e54adc0b5..000000000 --- a/api/src/main/java/com/volmit/object/ObjectGenerationContext.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.volmit.object; - -import com.volmit.generation.InvocationContext; -import com.volmit.random.WorldRandom; - -/** Geometry-only invocation. The host chooses the variant seed and enforces size limits. - * Placement and terrain adaptation happen later; generators return reusable local geometry. - */ -public interface ObjectGenerationContext extends InvocationContext { - /** This generation's stream, seeded from the variant seed the host chose. Do not retain it. */ - WorldRandom random(); -} diff --git a/api/src/main/java/com/volmit/object/ObjectGenerator.java b/api/src/main/java/com/volmit/object/ObjectGenerator.java deleted file mode 100644 index 3b64d20e5..000000000 --- a/api/src/main/java/com/volmit/object/ObjectGenerator.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.volmit.object; - -/** Configured geometry generator. Snapshot settings; concurrent calls use only invocation-local - * state. Return a non-null object. The host owns variant selection and snapshot-scoped caching. - */ -@FunctionalInterface -public interface ObjectGenerator { - GeneratedObject generate(ObjectGenerationContext context); -} diff --git a/api/src/main/java/com/volmit/object/ObjectGeneratorFactory.java b/api/src/main/java/com/volmit/object/ObjectGeneratorFactory.java deleted file mode 100644 index c7da1c0ec..000000000 --- a/api/src/main/java/com/volmit/object/ObjectGeneratorFactory.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.volmit.object; - -import com.volmit.IrisFeature; - -@FunctionalInterface -public interface ObjectGeneratorFactory { - ObjectGenerator create(F feature); -} diff --git a/api/src/main/java/com/volmit/object/ObjectTransform.java b/api/src/main/java/com/volmit/object/ObjectTransform.java deleted file mode 100644 index 234025a91..000000000 --- a/api/src/main/java/com/volmit/object/ObjectTransform.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.volmit.object; - -/** Requested transform. The host owns rasterization, property orientation and interpolation. - * Rotation is in degrees about the object's anchor; mirrors precede scale, then X/Y/Z rotation. - * Unsupported transformations fail rather than silently changing the request. - */ -public record ObjectTransform(double rotationX, double rotationY, double rotationZ, - double scaleX, double scaleY, double scaleZ, - boolean mirrorX, boolean mirrorY, boolean mirrorZ) { - public ObjectTransform { - for (double angle : new double[]{rotationX, rotationY, rotationZ}) { - if (!Double.isFinite(angle)) throw new IllegalArgumentException("Non-finite rotation"); - } - for (double scale : new double[]{scaleX, scaleY, scaleZ}) { - if (!Double.isFinite(scale) || scale <= 0) throw new IllegalArgumentException("Scale must be finite and positive"); - } - } - - public static ObjectTransform identity() { return new ObjectTransform(0, 0, 0, 1, 1, 1, false, false, false); } -} diff --git a/api/src/main/java/com/volmit/object/ObjectTransformer.java b/api/src/main/java/com/volmit/object/ObjectTransformer.java deleted file mode 100644 index d83d4e6a6..000000000 --- a/api/src/main/java/com/volmit/object/ObjectTransformer.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.volmit.object; - -/** Host adapter returning immutable transformed geometry with updated bounds, block properties, - * block entities and markers. Cache keys include pack snapshot, source geometry and transform. - */ -@FunctionalInterface -public interface ObjectTransformer { - GeneratedObject transform(GeneratedObject object, ObjectTransform transform); -} diff --git a/api/src/main/java/com/volmit/placement/PlacementContext.java b/api/src/main/java/com/volmit/placement/PlacementContext.java index 42801b89e..fd26aa57d 100644 --- a/api/src/main/java/com/volmit/placement/PlacementContext.java +++ b/api/src/main/java/com/volmit/placement/PlacementContext.java @@ -2,9 +2,7 @@ package com.volmit.placement; import com.volmit.config.FeatureSettings; import com.volmit.generation.InvocationContext; -import com.volmit.object.ObjectTransformer; import com.volmit.world.TerrainSampler; -import com.volmit.world.BlockView; import java.util.Optional; @@ -14,12 +12,9 @@ import java.util.Optional; public interface PlacementContext extends InvocationContext { TerrainSampler terrain(); FeatureSettings settings(); - ObjectTransformer objects(); - /** Prepared blocks before this placement. Use stage access for reads of buffered changes. */ - BlockView blocks(); /** * The world the placement is made in, for the questions about a column the stages ask. Its blocks are the ones before - * this placement, like {@link #blocks()}; stages write through their access, never into it. + * this placement; stages write through their access, never into it. */ PlacementTerrain placementTerrain(); /** diff --git a/api/src/main/java/com/volmit/random/WorldRandom.java b/api/src/main/java/com/volmit/random/WorldRandom.java index 1c111fc83..8c348ea60 100644 --- a/api/src/main/java/com/volmit/random/WorldRandom.java +++ b/api/src/main/java/com/volmit/random/WorldRandom.java @@ -9,8 +9,7 @@ import java.util.RandomAccess; /** A random stream whose every value is defined here, so the same seed gives the same draws on * every machine and every JDK. World generation draws from it: stages through - * {@link com.volmit.stage.StageContext#random()}, object generators through - * {@link com.volmit.object.ObjectGenerationContext#random()}. + * {@link com.volmit.stage.StageContext#random()}. * *

It deliberately does not implement {@link java.util.random.RandomGenerator}: that interface's * default methods, and any a later JDK adds, use algorithms the JDK may change, which would change diff --git a/api/src/test/java/com/volmit/ItemAndEntityValuesTest.java b/api/src/test/java/com/volmit/ItemAndEntityValuesTest.java index cb6985190..e1760e609 100644 --- a/api/src/test/java/com/volmit/ItemAndEntityValuesTest.java +++ b/api/src/test/java/com/volmit/ItemAndEntityValuesTest.java @@ -70,14 +70,6 @@ class ItemAndEntityValuesTest { assertThrows(IllegalArgumentException.class, () -> ResourceId.ofPlatformKey("a:b:c")); } - @Test - void anEntityHandsAHostTheExtensionItReadsAndNothingForAnotherType() { - EntitySpec zombie = entity(List.of("iris extras")); - - assertEquals(Optional.of("iris extras"), zombie.extension(String.class)); - assertEquals(Optional.empty(), zombie.extension(Integer.class)); - } - @Test void anEntityCarriesWhatOnlyAPlatformHasANameForInsteadOfAnExtension() { EntitySpec.Appearance panda = new EntitySpec.Appearance(Optional.empty(), false, false, false, Optional.of("PLAYFUL"), @@ -125,7 +117,7 @@ class ItemAndEntityValuesTest { @Test void anAttemptSaysWhetherLightMatters() { BlockPosition at = new BlockPosition(1, 2, 3); - EntitySpec zombie = entity(List.of()); + EntitySpec zombie = zombie(); assertFalse(new EntitySpawns.Attempt(at, zombie, EntitySpawns.Surface.LAND, 0, 15, true).restrictsLight()); assertTrue(new EntitySpawns.Attempt(at, zombie, EntitySpawns.Surface.LAND, 0, 7, true).restrictsLight()); @@ -153,9 +145,9 @@ class ItemAndEntityValuesTest { assertThrows(NullPointerException.class, () -> new AmbientEffects.Command(null, 0, 0, 0)); } - private static EntitySpec entity(List extensions) { + private static EntitySpec zombie() { return new EntitySpec(new ContentKey.Registered(ResourceId.parse("minecraft:zombie")), EntitySpec.Appearance.PLAIN, EntitySpec.Behaviour.NATURAL, EntitySpec.Equipment.NONE, List.of(), EntitySpec.Company.NONE, - EntitySpec.Drops.PLATFORM, EntitySpec.Arrival.QUIET, false, extensions); + EntitySpec.Drops.PLATFORM, EntitySpec.Arrival.QUIET, false); } } diff --git a/host/src/main/java/com/volmit/host/FeatureCatalog.java b/host/src/main/java/com/volmit/host/FeatureCatalog.java index 73ac93d33..edf6ff33f 100644 --- a/host/src/main/java/com/volmit/host/FeatureCatalog.java +++ b/host/src/main/java/com/volmit/host/FeatureCatalog.java @@ -1,6 +1,5 @@ package com.volmit.host; -import com.volmit.IrisFeature; import com.volmit.service.Providers; import com.volmit.service.Service; import java.util.Collection; @@ -8,7 +7,6 @@ import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.NoSuchElementException; import java.util.Optional; import java.util.function.Function; import java.util.stream.Collectors; @@ -33,7 +31,6 @@ public final class FeatureCatalog { }; private final Map, FeatureDescriptor> settings; - private final Map, ObjectRegistration> objects; private final Map> mantle; private final List resourceKinds; private final List validators; @@ -45,7 +42,6 @@ public final class FeatureCatalog { FeatureCatalog( Map, FeatureDescriptor> settings, - Map, ObjectRegistration> objects, Map> mantle, Collection resourceKinds, List validators, @@ -56,7 +52,6 @@ public final class FeatureCatalog { this.placementType = Optional.ofNullable(placementType); this.studioViews = sorted(studioViews, registration -> registration.view().id()); this.settings = Map.copyOf(settings); - this.objects = Map.copyOf(objects); this.mantle = Map.copyOf(mantle); this.resourceKinds = sorted(resourceKinds, registration -> registration.kind().id()); this.validators = inModuleOrder(validators, ValidatorRegistration::module); @@ -70,10 +65,6 @@ public final class FeatureCatalog { return sorted(settings.values(), FeatureDescriptor::id); } - public List> objects() { - return sorted(objects.values(), registration -> registration.descriptor().id()); - } - public List> mantle() { return sorted(mantle.values(), registration -> registration.key().id()); } @@ -168,13 +159,4 @@ public final class FeatureCatalog { .sorted(Comparator.comparing(key)) .toList(); } - - @SuppressWarnings("unchecked") // The registry key is the factory's feature type. - public ObjectRegistration object(Class type) { - var registration = objects.get(type); - if (registration == null) { - throw new NoSuchElementException("No object feature: " + type.getName()); - } - return (ObjectRegistration) registration; - } } diff --git a/host/src/main/java/com/volmit/host/ModuleRegistry.java b/host/src/main/java/com/volmit/host/ModuleRegistry.java index 771bb59cc..b3987ec70 100644 --- a/host/src/main/java/com/volmit/host/ModuleRegistry.java +++ b/host/src/main/java/com/volmit/host/ModuleRegistry.java @@ -7,7 +7,6 @@ import com.volmit.config.Level; import com.volmit.mantle.MantleCodec; import com.volmit.mantle.MantleKey; import com.volmit.mantle.MantleLifetime; -import com.volmit.object.ObjectGeneratorFactory; import com.volmit.resource.ResourceId; import com.volmit.resource.ResourceKind; import com.volmit.service.Providers; @@ -27,7 +26,7 @@ import java.util.Set; * immutable. IDs are unique across feature kinds. A feature's JSON key (see {@link com.volmit.config.Feature#key}) * is unique per attachment target, and may not equal a host JSON field passed in to reserve it; a clash fails the * registration naming the key, the target and both claimants. Modules register during their setup - * ({@link ModuleSetups#run}); object feature ids, mantle keys, resource kind ids and explicitly registered + * ({@link ModuleSetups#run}); 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 * files. Lifecycle hooks and service providers are registered by the module that owns them; a service whose providers @@ -37,7 +36,6 @@ import java.util.Set; */ public final class ModuleRegistry implements FeatureRegistry, ToolingRegistry { private final Map, FeatureDescriptor> settings = new HashMap<>(); - private final Map, ObjectRegistration> objects = new HashMap<>(); private final Map> mantle = new HashMap<>(); private final Set featureIds = new HashSet<>(); private final Set> featureTypes = new HashSet<>(); @@ -82,18 +80,6 @@ public final class ModuleRegistry implements FeatureRegistry, ToolingRegistry { registering = null; } - @Override - public void registerObject( - Class featureType, - ObjectGeneratorFactory factory) { - checkOpen(); - 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); - objects.put(featureType, registration); - } - @Override public void registerMantle(MantleKey key, MantleLifetime lifetime, MantleCodec codec) { checkOpen(); @@ -233,7 +219,7 @@ public final class ModuleRegistry implements FeatureRegistry, ToolingRegistry { public FeatureCatalog freeze() { if (catalog == null) { - catalog = new FeatureCatalog(settings, objects, mantle, resourceKinds.values(), validators, lifecycles, services, + catalog = new FeatureCatalog(settings, mantle, resourceKinds.values(), validators, lifecycles, services, placementType, studioViews.values()); } return catalog; diff --git a/host/src/main/java/com/volmit/host/ObjectRegistration.java b/host/src/main/java/com/volmit/host/ObjectRegistration.java deleted file mode 100644 index f49d29d50..000000000 --- a/host/src/main/java/com/volmit/host/ObjectRegistration.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.volmit.host; - -import com.volmit.IrisFeature; -import com.volmit.object.ObjectGenerator; -import com.volmit.object.ObjectGeneratorFactory; -import java.util.Objects; - -public record ObjectRegistration( - FeatureDescriptor descriptor, - ObjectGeneratorFactory factory) { - public ObjectRegistration { - Objects.requireNonNull(descriptor, "descriptor"); - Objects.requireNonNull(factory, "factory"); - } - - public ObjectGenerator configure(F feature) { - var configuredFeature = descriptor.type().cast(Objects.requireNonNull(feature, "feature")); - return Objects.requireNonNull(factory.create(configuredFeature), "generator"); - } -} diff --git a/host/src/main/java/com/volmit/host/PackSchemaBuilder.java b/host/src/main/java/com/volmit/host/PackSchemaBuilder.java index ee3af8285..e627254db 100644 --- a/host/src/main/java/com/volmit/host/PackSchemaBuilder.java +++ b/host/src/main/java/com/volmit/host/PackSchemaBuilder.java @@ -1,6 +1,5 @@ package com.volmit.host; -import com.volmit.host.schema.FeatureRole; import com.volmit.host.schema.FeatureSchema; import com.volmit.host.schema.ObjectType; import com.volmit.host.schema.PackSchema; @@ -46,7 +45,7 @@ final class PackSchemaBuilder { } private PackSchema describe(FeatureCatalog catalog) { - var features = catalogued(catalog).map(this::draft).toList(); + var features = catalog.settings().stream().map(this::draft).toList(); var resources = catalog.resourceKinds().stream().map(this::describe).toList(); requireUniqueSnippets(); var types = completeTypes(); @@ -78,30 +77,18 @@ final class PackSchemaBuilder { + " the host may use; read the files into a class of the module"); } - /** One catalogued settings type and why it is in the catalog. */ - private record Catalogued(FeatureDescriptor descriptor, FeatureRole role) {} - /** A feature whose settings class is drafted but whose defaults are not converted yet. */ - private record FeatureDraft(Catalogued catalogued, DiscoveredModule owner) { + private record FeatureDraft(FeatureDescriptor descriptor, DiscoveredModule owner) { FeatureSchema complete(Map types) { - var descriptor = catalogued.descriptor(); - return new FeatureSchema(descriptor.id(), descriptor.name(), catalogued.role(), owner.info(), descriptor.key(), descriptor.root(), - descriptor.targets(),types.get(descriptor.type().getName())); + return new FeatureSchema(descriptor.id(), descriptor.name(), owner.info(), descriptor.key(), descriptor.root(), + descriptor.targets(), types.get(descriptor.type().getName())); } } - /** Ordered by feature id, so which settings an error names first never depends on discovery. */ - private static Stream catalogued(FeatureCatalog catalog) { - var settings = catalog.settings().stream().map(descriptor -> new Catalogued(descriptor, FeatureRole.SETTINGS)); - var objects = catalog.objects().stream() - .map(registration -> new Catalogued(registration.descriptor(), FeatureRole.OBJECT_GENERATOR)); - return Stream.concat(settings, objects).sorted(Comparator.comparing(catalogued -> catalogued.descriptor().id())); - } - - private FeatureDraft draft(Catalogued catalogued) { - var owner = ownerOf(catalogued.descriptor()); - drafts.settings(SchemaSource.settings(catalogued.descriptor(), owner)); - return new FeatureDraft(catalogued, owner); + private FeatureDraft draft(FeatureDescriptor descriptor) { + var owner = ownerOf(descriptor); + drafts.settings(SchemaSource.settings(descriptor, owner)); + return new FeatureDraft(descriptor, owner); } /** Registration checked that a module owns every catalogued id; module ids are unique and have no '/', so only one can. */ diff --git a/host/src/main/java/com/volmit/host/PlacementInvocation.java b/host/src/main/java/com/volmit/host/PlacementInvocation.java index fd339f641..36317b3f3 100644 --- a/host/src/main/java/com/volmit/host/PlacementInvocation.java +++ b/host/src/main/java/com/volmit/host/PlacementInvocation.java @@ -4,7 +4,6 @@ import com.volmit.IrisFeature; import com.volmit.config.FeatureSettings; import com.volmit.config.SettingsStack; import com.volmit.object.ObjectBlock; -import com.volmit.object.ObjectTransformer; import com.volmit.placement.PlacementAccess; import com.volmit.placement.PlacementContext; import com.volmit.placement.PlacementRequest; @@ -13,7 +12,6 @@ import com.volmit.random.WorldRandom; import com.volmit.world.PackWorld; import com.volmit.stage.BlockStageContext; import com.volmit.stage.Stage; -import com.volmit.world.BlockView; import com.volmit.world.TerrainSampler; import java.util.Objects; import java.util.Optional; @@ -140,16 +138,6 @@ final class PlacementInvocation implements BlockStageContext { return inputs.settings(); } - @Override - public ObjectTransformer objects() { - return inputs.objects(); - } - - @Override - public BlockView blocks() { - return inputs.blocks(); - } - @Override public PlacementTerrain placementTerrain() { return inputs.placementTerrain(); diff --git a/host/src/main/java/com/volmit/host/schema/FeatureRole.java b/host/src/main/java/com/volmit/host/schema/FeatureRole.java deleted file mode 100644 index 88bed4aa8..000000000 --- a/host/src/main/java/com/volmit/host/schema/FeatureRole.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.volmit.host.schema; - -/** Why a module catalogued a settings type. */ -public enum FeatureRole { - /** Settings that stages read: named in {@code when(...)} or registered with {@code registerSettings}. */ - SETTINGS, - /** Settings of an object generator, registered with {@code registerObject}. */ - OBJECT_GENERATOR -} diff --git a/host/src/main/java/com/volmit/host/schema/FeatureSchema.java b/host/src/main/java/com/volmit/host/schema/FeatureSchema.java index c03890810..f55eb115a 100644 --- a/host/src/main/java/com/volmit/host/schema/FeatureSchema.java +++ b/host/src/main/java/com/volmit/host/schema/FeatureSchema.java @@ -22,7 +22,6 @@ import java.util.Set; public record FeatureSchema( ResourceId id, String name, - FeatureRole role, ModuleInfo module, String key, Optional root, @@ -31,7 +30,6 @@ public record FeatureSchema( public FeatureSchema { Objects.requireNonNull(id, "id"); Objects.requireNonNull(name, "name"); - Objects.requireNonNull(role, "role"); Objects.requireNonNull(module, "module"); Objects.requireNonNull(key, "key"); Objects.requireNonNull(root, "root"); diff --git a/host/src/main/java/com/volmit/host/schema/PackSchema.java b/host/src/main/java/com/volmit/host/schema/PackSchema.java index b807f5c6d..48475a887 100644 --- a/host/src/main/java/com/volmit/host/schema/PackSchema.java +++ b/host/src/main/java/com/volmit/host/schema/PackSchema.java @@ -48,11 +48,6 @@ public record PackSchema(List features, List .toList(); } - /** The settings of object generators, by feature id. */ - public List objectGenerators() { - return features.stream().filter(feature -> feature.role() == FeatureRole.OBJECT_GENERATOR).toList(); - } - /** The type an {@link ValueKind.ObjectKind} names. */ public ObjectType type(String name) { return types.stream() diff --git a/host/src/test/java/com/volmit/example/placement/AnchorModule.java b/host/src/test/java/com/volmit/example/placement/AnchorModule.java index c6fa4b413..0dd466c42 100644 --- a/host/src/test/java/com/volmit/example/placement/AnchorModule.java +++ b/host/src/test/java/com/volmit/example/placement/AnchorModule.java @@ -7,7 +7,6 @@ import com.volmit.stage.PlacementStage; import com.volmit.stage.PlacementStageContext; import com.volmit.stage.Stage; import com.volmit.geometry.BlockPosition; -import com.volmit.world.BlockView; /** Port of PlacementModuleAnchor with center-height sampling: rest the anchor on the surface. */ public final class AnchorModule implements IrisModule { @@ -27,17 +26,7 @@ public final class AnchorModule implements IrisModule { private static AnchorResult restOnSurface(PlacementStageContext context) { var requested = context.request().anchor(); - int surfaceY = firstAirAboveGround(context.blocks(), requested.x(), requested.z()); - return new AnchorResult(new BlockPosition(requested.x(), surfaceY, requested.z())); - } - - private static int firstAirAboveGround(BlockView blocks, int x, int z) { - var bounds = blocks.bounds(); - for (int y = bounds.maxY() - 1; y >= bounds.minY(); y--) { - if (!ExampleBlocks.isAir(blocks.get(x, y, z))) { - return y + 1; - } - } - return bounds.minY(); + int firstAirAboveGround = context.placementTerrain().highest(requested.x(), requested.z(), false) + 1; + return new AnchorResult(new BlockPosition(requested.x(), firstAirAboveGround, requested.z())); } } diff --git a/host/src/test/java/com/volmit/host/ModuleRegistryTest.java b/host/src/test/java/com/volmit/host/ModuleRegistryTest.java index 0d00e4fc5..c359dafbe 100644 --- a/host/src/test/java/com/volmit/host/ModuleRegistryTest.java +++ b/host/src/test/java/com/volmit/host/ModuleRegistryTest.java @@ -57,25 +57,20 @@ class ModuleRegistryTest { var registry = new ModuleRegistry(); registerAs(registry, "test:core", settings -> settings.registerSettings(One.class)); registry.registerStageSettings(One.class); - registerAs(registry, "test:core", objects -> { - 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)); + registerAs(registry, "test:core", settings -> { + settings.registerSettings(Two.class); + assertThrows(IllegalArgumentException.class, () -> settings.registerSettings(Duplicate.class)); }); var catalog = registry.freeze(); - assertEquals(List.of("test:core/one"), catalog.settings().stream().map(value -> value.id().toString()).toList()); - assertEquals(List.of("test:core/two"), catalog.objects().stream().map(value -> value.descriptor().id().toString()).toList()); + assertEquals(List.of("test:core/one", "test:core/two"), catalog.settings().stream().map(value -> value.id().toString()).toList()); } @Test - void rejectsInvalidFeaturesOrFactories() { + void rejectsInvalidFeatures() { var registry = new ModuleRegistry(); assertThrows(IllegalArgumentException.class, () -> registry.registerStageSettings(MissingAnnotation.class)); assertThrows(IllegalArgumentException.class, () -> registry.registerStageSettings(AbstractFeature.class)); - registerAs(registry, "test:core", objects -> { - assertThrows(NullPointerException.class, () -> objects.registerObject(Two.class, null)); - objects.registerObject(Two.class, ignored -> context -> null); - }); + registerAs(registry, "test:core", settings -> settings.registerSettings(Two.class)); assertSame(registry.freeze(), registry.freeze()); assertThrows(IllegalStateException.class, () -> registry.registerStageSettings(One.class)); } @@ -95,16 +90,10 @@ class ModuleRegistryTest { } @Test - void objectFeatureIdsAndMantleKeysAreTheRegisteringModulesIdOrBelowIt() { + void settingsIdsAndMantleKeysAreTheRegisteringModulesIdOrBelowIt() { var registry = new ModuleRegistry(); - var object = assertThrows(IllegalArgumentException.class, () -> registerAs(registry, "other:objects", - objects -> objects.registerObject(Two.class, ignored -> context -> null))); - assertEquals("Object generator settings " + Two.class.getName() + " with feature id test:core/two must be " - + "other:objects or start with other:objects/, the id of its registering module other:objects from host classpath", - object.getMessage()); - var sameNamespace = assertThrows(IllegalArgumentException.class, () -> registerAs(registry, "test:other", - objects -> objects.registerObject(Two.class, ignored -> context -> null))); + settings -> settings.registerSettings(Two.class))); assertTrue(sameNamespace.getMessage().contains("must be test:other or start with test:other/"), sameNamespace.getMessage()); var mantle = assertThrows(IllegalArgumentException.class, () -> registerAs(registry, "iris:snow", @@ -114,7 +103,7 @@ class ModuleRegistryTest { assertThrows(IllegalStateException.class, () -> registry.registerMantle(new MantleKey<>("test:loose", String.class), MantleLifetime.GENERATION, codec(1))); - assertTrue(registry.freeze().objects().isEmpty()); + assertTrue(registry.freeze().settings().isEmpty()); assertTrue(registry.freeze().mantle().isEmpty()); } @@ -187,12 +176,11 @@ class ModuleRegistryTest { public ModuleInfo info() { return ModuleInfo.of("test:core", "Conditioned", "1"); } public void setup(ModuleSetup setup) { setup.stages().define(WORK).when(One.class).run(context -> {}); - setup.registry().registerObject(Two.class, ignored -> context -> null); + setup.registry().registerSettings(Two.class); } }; var loaded = LoadedModules.load(List.of(DiscoveredModule.builtIn(conditioned)), Map.of(), 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(List.of("test:core/one", "test:core/two"), loaded.catalog().settings().stream().map(value -> value.id().toString()).toList()); assertEquals(1, loaded.placement().stages().size()); assertTrue(loaded.chunk().stages().isEmpty()); } @@ -261,12 +249,12 @@ class ModuleRegistryTest { } @Test - void aClashingObjectGeneratorOrStageSettingsTypeClaimsTheKeyToo() { + void aClashingRegisteredOrStageSettingsTypeClaimsTheKeyToo() { var registry = new ModuleRegistry(); registerAs(registry, "test:ores", settings -> settings.registerSettings(Ores.class)); - var object = assertThrows(IllegalArgumentException.class, () -> registerAs(registry, "test:minerals", - objects -> objects.registerObject(Minerals.class, ignored -> context -> null))); - assertTrue(object.getMessage().startsWith("region key \"deposits\" is claimed by test:minerals (host classpath) and test:ores"), object.getMessage()); + var registered = assertThrows(IllegalArgumentException.class, () -> registerAs(registry, "test:minerals", + settings -> settings.registerSettings(Minerals.class))); + assertTrue(registered.getMessage().startsWith("region key \"deposits\" is claimed by test:minerals (host classpath) and test:ores"), registered.getMessage()); var conditioned = new IrisModule() { static final PlacementStage WORK = Stage.placement("test:minerals/work"); @@ -382,11 +370,11 @@ class ModuleRegistryTest { + "test:other/, the id of its registering module test:other from host classpath", foreign.getMessage()); assertThrows(IllegalStateException.class, () -> registry.registerSettings(One.class)); - registerAs(registry, "test:core", settings -> settings.registerObject(Two.class, ignored -> context -> null)); + registerAs(registry, "test:core", settings -> settings.registerSettings(One.class)); var collision = assertThrows(IllegalArgumentException.class, - () -> registerAs(registry, "test:core", settings -> settings.registerSettings(Two.class))); - assertEquals("Duplicate feature: test:core/two", collision.getMessage()); - assertTrue(registry.freeze().settings().isEmpty()); + () -> registerAs(registry, "test:core", settings -> settings.registerSettings(Duplicate.class))); + assertEquals("Duplicate feature: test:core/one", collision.getMessage()); + assertEquals(List.of(One.class), registry.freeze().settings().stream().map(FeatureDescriptor::type).toList()); } @Test diff --git a/host/src/test/java/com/volmit/host/PackSchemaTest.java b/host/src/test/java/com/volmit/host/PackSchemaTest.java index 670b17788..b3fb3ab3d 100644 --- a/host/src/test/java/com/volmit/host/PackSchemaTest.java +++ b/host/src/test/java/com/volmit/host/PackSchemaTest.java @@ -7,7 +7,6 @@ import com.volmit.example.chunk.TerrainModule; import com.volmit.example.hosttypes.Palette; import com.volmit.example.placement.PlacementModules; import com.volmit.example.terrain.LayersModule; -import com.volmit.host.schema.FeatureRole; import com.volmit.host.schema.FeatureSchema; import com.volmit.host.schema.ObjectType; import com.volmit.host.schema.PackSchema; @@ -61,7 +60,7 @@ class PackSchemaTest { private static final String FLORA_SETUP = """ registry.registerSettings(WindSettings.class); registry.registerSettings(FloraSettings.class); - registry.registerObject(BushSettings.class, bush -> context -> null); + registry.registerSettings(BushSettings.class); graph.define(Stage.chunk("example:flora/plant")).when(FloraSettings.class).run(context -> {}); """; @@ -208,7 +207,6 @@ class PackSchemaTest { var flora = schema.features().getFirst(); assertEquals("Flora", flora.name()); - assertEquals(FeatureRole.SETTINGS, flora.role()); assertEquals(FLORA, flora.module().id().toString()); assertEquals(displayName(FLORA), flora.module().name()); assertEquals(List.of(Level.REGION, Level.BIOME), List.copyOf(flora.targets())); @@ -289,19 +287,17 @@ class PackSchemaTest { } @Test - void listsSnippetsObjectGeneratorsAndExplicitlyRegisteredSettings() { + void listsSnippetsAndExplicitlyRegisteredSettings() { var schema = floraSchema(); assertEquals(List.of("example/flora/bush", "example/flora/patch"), schema.snippets().stream().map(type -> type.snippet().orElseThrow()).toList()); assertEquals(List.of("pack.flora.BushSettings", "pack.flora.Patch"), schema.snippets().stream().map(ObjectType::name).toList()); - var bush = schema.objectGenerators().getFirst(); - assertEquals(1, schema.objectGenerators().size()); - assertEquals(FeatureRole.OBJECT_GENERATOR, bush.role()); + var bush = schema.fields(Level.PLACEMENT).getFirst(); + assertEquals("example:flora/bush", bush.id().toString()); assertEquals(Optional.of(2L), option(bush.settings(), "height").defaultValue()); var wind = schema.fields(Level.DIMENSION).getFirst(); - assertEquals(FeatureRole.SETTINGS, wind.role()); assertEquals("example:flora/wind", wind.id().toString()); assertEquals(new SchemaOption("strength", new DecimalKind(), "How far plants sway", false, OptionalDouble.empty(), OptionalDouble.empty(), OptionalInt.empty(), Optional.of(1.5)), option(wind.settings(), "strength")); @@ -638,8 +634,8 @@ class PackSchemaTest { void referencesOnIncompatibleFieldsFailTheLoad() { assertLoadFails("Field pack.flora.FloraSettings.count of " + FLORA_SOURCE + " has @Ref(BLOCK) on int, but @Ref fits only String" + " and ResourceId and lists, sets and arrays of them", "@Ref(Reference.BLOCK) private int count;"); - assertLoadFails("Field pack.flora.FloraSettings.flower of " + FLORA_SOURCE + " has @Ref(BIOME) on BlockState, which always names" - + " a block; remove the @Ref or use String or ResourceId", "@Ref(Reference.BIOME) private BlockState flower;"); + assertLoadFails("Field pack.flora.FloraSettings.flower of " + FLORA_SOURCE + " has @Ref(ITEM) on BlockState, which always names" + + " a block; remove the @Ref or use String or ResourceId", "@Ref(Reference.ITEM) private BlockState flower;"); assertLoadFails("Field pack.flora.FloraSettings.blocks of " + FLORA_SOURCE + " has @Ref(BLOCK) on java.util.Map, but @Ref fits only String and ResourceId and lists, sets and arrays of them", "@Ref(Reference.BLOCK) private Map blocks;"); diff --git a/host/src/test/java/com/volmit/support/ColumnTerrain.java b/host/src/test/java/com/volmit/support/ColumnTerrain.java new file mode 100644 index 000000000..7f95af243 --- /dev/null +++ b/host/src/test/java/com/volmit/support/ColumnTerrain.java @@ -0,0 +1,72 @@ +package com.volmit.support; + +import com.volmit.block.BlockState; +import com.volmit.object.BlockEntityData; +import com.volmit.placement.PlacedMarker; +import com.volmit.placement.PlacementRecord; +import com.volmit.placement.PlacementTerrain; +import com.volmit.placement.StructureVolumes; +import com.volmit.world.BlockView; +import java.util.Optional; + +/** Placement terrain over test blocks that answers column heights and reads; anything else fails the test. */ +public final class ColumnTerrain implements PlacementTerrain { + private final BlockView blocks; + + public ColumnTerrain(BlockView blocks) { + this.blocks = blocks; + } + + @Override + public int highest(int x, int z, boolean ignoreFluid) { + var bounds = blocks.bounds(); + for (int y = bounds.maxY() - 1; y >= bounds.minY(); y--) { + if (!blocks.get(x, y, z).material().equals(TestTerrain.AIR.material())) { + return y; + } + } + return bounds.minY() - 1; + } + + @Override + public BlockState get(int x, int y, int z) { + return blocks.get(x, y, z); + } + + @Override + public void set(int x, int y, int z, BlockState state) { throw unused("set"); } + + @Override + public void set(int x, int y, int z, BlockState state, BlockEntityData blockEntity) { throw unused("set"); } + + @Override + public boolean isCarved(int x, int y, int z) { throw unused("isCarved"); } + + @Override + public boolean isSurfaceSolid(int x, int y, int z) { throw unused("isSurfaceSolid"); } + + @Override + public boolean isUnderwater(int x, int z) { throw unused("isUnderwater"); } + + @Override + public int fluidHeight() { throw unused("fluidHeight"); } + + @Override + public boolean preventsDecay() { throw unused("preventsDecay"); } + + @Override + public void recordPlacement(int x, int y, int z, PlacementRecord placement) { throw unused("recordPlacement"); } + + @Override + public Optional placementAt(int x, int y, int z) { throw unused("placementAt"); } + + @Override + public StructureVolumes structureVolumes(int minX, int minZ, int maxX, int maxZ) { throw unused("structureVolumes"); } + + @Override + public void mark(PlacedMarker marker) { throw unused("mark"); } + + private static AssertionError unused(String method) { + return new AssertionError("Unused placement terrain " + method); + } +} diff --git a/host/src/test/java/com/volmit/support/TestContexts.java b/host/src/test/java/com/volmit/support/TestContexts.java index a741ff4ed..0aa5d8955 100644 --- a/host/src/test/java/com/volmit/support/TestContexts.java +++ b/host/src/test/java/com/volmit/support/TestContexts.java @@ -6,7 +6,6 @@ import com.volmit.generation.GenerationContext; import com.volmit.generation.MantleGenerationContext; import com.volmit.hunk.Hunk; import com.volmit.mantle.Mantle; -import com.volmit.object.ObjectTransformer; import com.volmit.placement.PlacementContext; import com.volmit.placement.PlacementTerrain; import java.util.Optional; @@ -62,17 +61,13 @@ public final class TestContexts { return placement(null); } + /** A placement whose terrain answers from {@code blocks}; a null {@code blocks} fails when used. */ public static PlacementContext placement(BlockView blocks) { return new PlacementContext() { public PackWorld world() { throw new AssertionError("Unused world"); } public TerrainSampler terrain() { throw new AssertionError("Unused terrain"); } public FeatureSettings settings() { throw new AssertionError("Unused settings"); } - public ObjectTransformer objects() { throw new AssertionError("Unused transforms"); } - public BlockView blocks() { - if (blocks == null) throw new AssertionError("Unused blocks"); - return blocks; - } - public PlacementTerrain placementTerrain() { throw new AssertionError("Unused placement terrain"); } + public PlacementTerrain placementTerrain() { return new ColumnTerrain(used(blocks, "placement terrain")); } public Optional input(Class type) { return Optional.empty(); } }; }