mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
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.
This commit is contained in:
1 parent
d0b57a4886
commit
2b6f96e5c2
26 files changed
+119
-269
No files matched your search
@@ -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 {
|
||||
*/
|
||||
<T> void registerMantle(MantleKey<T> key, MantleLifetime lifetime, MantleCodec<T> codec);
|
||||
|
||||
<F extends IrisFeature> void registerObject(Class<F> featureType, ObjectGeneratorFactory<F> 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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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},
|
||||
|
||||
@@ -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<ItemAttribute> attributes, Company company, Drops drops, Arrival arrival,
|
||||
boolean adjustsProvidedMob, List<Object> 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 <T> Optional<T> extension(Class<T> type) {
|
||||
return extensions.stream().filter(type::isInstance).map(type::cast).findFirst();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.util.Optional;
|
||||
/** Host-owned invocation inputs. Views must not be retained or used by detached tasks.
|
||||
*
|
||||
* <p>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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package com.volmit.object;
|
||||
|
||||
import com.volmit.IrisFeature;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ObjectGeneratorFactory<F extends IrisFeature> {
|
||||
ObjectGenerator create(F feature);
|
||||
}
|
||||
@@ -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); }
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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();
|
||||
/**
|
||||
|
||||
@@ -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()}.
|
||||
*
|
||||
* <p>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
|
||||
|
||||
@@ -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<Object> 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);
|
||||
}
|
||||
}
|
||||
@@ -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<Class<?>, FeatureDescriptor<?>> settings;
|
||||
private final Map<Class<?>, ObjectRegistration<?>> objects;
|
||||
private final Map<String, MantleRegistration<?>> mantle;
|
||||
private final List<ResourceKindRegistration> resourceKinds;
|
||||
private final List<ValidatorRegistration> validators;
|
||||
@@ -45,7 +42,6 @@ public final class FeatureCatalog {
|
||||
|
||||
FeatureCatalog(
|
||||
Map<Class<?>, FeatureDescriptor<?>> settings,
|
||||
Map<Class<?>, ObjectRegistration<?>> objects,
|
||||
Map<String, MantleRegistration<?>> mantle,
|
||||
Collection<ResourceKindRegistration> resourceKinds,
|
||||
List<ValidatorRegistration> 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<ObjectRegistration<?>> objects() {
|
||||
return sorted(objects.values(), registration -> registration.descriptor().id());
|
||||
}
|
||||
|
||||
public List<MantleRegistration<?>> 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 <F extends IrisFeature> ObjectRegistration<F> object(Class<F> type) {
|
||||
var registration = objects.get(type);
|
||||
if (registration == null) {
|
||||
throw new NoSuchElementException("No object feature: " + type.getName());
|
||||
}
|
||||
return (ObjectRegistration<F>) registration;
|
||||
}
|
||||
}
|
||||
@@ -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<Class<?>, FeatureDescriptor<?>> settings = new HashMap<>();
|
||||
private final Map<Class<?>, ObjectRegistration<?>> objects = new HashMap<>();
|
||||
private final Map<String, MantleRegistration<?>> mantle = new HashMap<>();
|
||||
private final Set<ResourceId> featureIds = new HashSet<>();
|
||||
private final Set<Class<?>> featureTypes = new HashSet<>();
|
||||
@@ -82,18 +80,6 @@ public final class ModuleRegistry implements FeatureRegistry, ToolingRegistry {
|
||||
registering = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <F extends IrisFeature> void registerObject(
|
||||
Class<F> featureType,
|
||||
ObjectGeneratorFactory<F> 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 <T> void registerMantle(MantleKey<T> key, MantleLifetime lifetime, MantleCodec<T> 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;
|
||||
|
||||
@@ -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<F extends IrisFeature>(
|
||||
FeatureDescriptor<F> descriptor,
|
||||
ObjectGeneratorFactory<F> 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");
|
||||
}
|
||||
}
|
||||
@@ -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<String, ObjectType> 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> 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. */
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -22,7 +22,6 @@ import java.util.Set;
|
||||
public record FeatureSchema(
|
||||
ResourceId id,
|
||||
String name,
|
||||
FeatureRole role,
|
||||
ModuleInfo module,
|
||||
String key,
|
||||
Optional<String> 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");
|
||||
|
||||
@@ -48,11 +48,6 @@ public record PackSchema(List<FeatureSchema> features, List<ResourceKindSchema>
|
||||
.toList();
|
||||
}
|
||||
|
||||
/** The settings of object generators, by feature id. */
|
||||
public List<FeatureSchema> 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()
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
}
|
||||
@@ -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<Void> 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
|
||||
|
||||
@@ -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<java.lang.String,"
|
||||
+ " java.lang.String>, but @Ref fits only String and ResourceId and lists, sets and arrays of them",
|
||||
"@Ref(Reference.BLOCK) private Map<String, String> blocks;");
|
||||
|
||||
@@ -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<PlacementRecord> 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);
|
||||
}
|
||||
}
|
||||
@@ -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 <T> Optional<T> input(Class<T> type) { return Optional.empty(); }
|
||||
};
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user