diff --git a/core/src/main/java/art/arcane/iris/core/loader/ResourceLoader.java b/core/src/main/java/art/arcane/iris/core/loader/ResourceLoader.java index 33ab02d15..9f3076855 100644 --- a/core/src/main/java/art/arcane/iris/core/loader/ResourceLoader.java +++ b/core/src/main/java/art/arcane/iris/core/loader/ResourceLoader.java @@ -39,7 +39,7 @@ import art.arcane.volmlib.util.json.JSONArray; import art.arcane.volmlib.util.json.JSONObject; import art.arcane.iris.core.modules.ModuleSettings; import art.arcane.iris.core.modules.ModuleTargets; -import com.volmit.FeatureAttachment.Target; +import com.volmit.config.Level; import art.arcane.iris.util.common.parallel.BurstExecutor; import art.arcane.iris.util.common.parallel.MultiBurst; import art.arcane.volmlib.util.scheduling.ChronoLatch; @@ -418,7 +418,7 @@ public class ResourceLoader implements MeteredCache { PrecisionStopwatch p = PrecisionStopwatch.start(); rawText = IO.readAll(j); JSONObject parsed = new JSONObject(rawText); - Optional moduleTarget = ModuleTargets.ofResource(objectClass); + Optional moduleTarget = ModuleTargets.ofResource(objectClass); JsonSchemaValidator.validateTopLevelKeys(parsed, rawText, j, resourceTypeName, objectClass, moduleKeys(moduleTarget)); T t = getManager().getGson() .fromJson(preprocess(parsed).toString(0), objectClass); @@ -438,11 +438,11 @@ public class ResourceLoader implements MeteredCache { } /** The keys the pack's modules read at {@code target}; none for resources that hold no module settings. */ - private Set moduleKeys(Optional target) { + private Set moduleKeys(Optional target) { return target.map(found -> getManager().getModules().settings().keys(found)).orElse(Set.of()); } - private ModuleSettings decodeModuleSettings(Target target, JSONObject json, String name) { + private ModuleSettings decodeModuleSettings(Level target, JSONObject json, String name) { return getManager().getModules().settings().decode(target, json, resourceTypeName + " " + name); } diff --git a/core/src/main/java/art/arcane/iris/core/modules/ChunkModuleSettings.java b/core/src/main/java/art/arcane/iris/core/modules/ChunkModuleSettings.java index 8f0a81db3..bd5021b4e 100644 --- a/core/src/main/java/art/arcane/iris/core/modules/ChunkModuleSettings.java +++ b/core/src/main/java/art/arcane/iris/core/modules/ChunkModuleSettings.java @@ -21,26 +21,31 @@ package art.arcane.iris.core.modules; import art.arcane.iris.core.loader.IrisRegistrant; import art.arcane.iris.engine.framework.Engine; import art.arcane.iris.engine.object.world.biome.IrisBiome; -import com.volmit.FeatureAttachment.Target; import com.volmit.IrisFeature; import com.volmit.config.FeatureSettings; +import com.volmit.config.Level; +import com.volmit.config.SettingsStack; +import com.volmit.generation.ChunkContext; import com.volmit.resource.ResourceId; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Optional; +import java.util.Set; /** * Module settings at world columns, for one engine: the dimension's entry, then the entry of the column's * region, then the one of its surface biome. Each level that declares the settings is its own entry; levels - * stack and are never merged, so a module sees all of them and decides what several mean. + * stack and are never merged, so a module sees all of them and decides what several mean. The stacks are kept + * per pack snapshot ({@link SettingsStacks}), so a column whose region and biome were seen before costs no allocation. */ final class ChunkModuleSettings implements FeatureSettings { private static final String DIMENSION = "dimension"; private static final String REGION = "region"; private static final String BIOME = "biome"; - /** The registrants whose settings stack at a column. */ + /** The registrants whose settings stack at a column, and the snapshot that keeps their stacks. */ interface Levels { IrisRegistrant dimension(); @@ -50,10 +55,14 @@ final class ChunkModuleSettings implements FeatureSettings { /** The biome a {@code BiomeSample} names by {@code id}, or null when the dimension has no such biome. */ IrisBiome biome(ResourceId id); + + /** The stacks of the snapshot the registrants belong to. */ + SettingsStacks stacks(); } private final Levels levels; private final PackResourceIds ids; + private SettingsStacks stacks; ChunkModuleSettings(Engine engine, PackResourceIds ids) { this(new EngineLevels(engine), ids); @@ -65,12 +74,49 @@ final class ChunkModuleSettings implements FeatureSettings { } @Override - public List> at(Class featureType, int worldX, int worldZ) { - List> entries = new ArrayList<>(Target.values().length); - addEntry(entries, featureType, Target.DIMENSION, DIMENSION, levels.dimension()); - addEntry(entries, featureType, Target.REGION, REGION, levels.region(worldX, worldZ)); - addEntry(entries, featureType, Target.BIOME, BIOME, levels.surfaceBiome(worldX, worldZ)); - return entries.isEmpty() ? List.of() : List.copyOf(entries); + public SettingsStack at(Class featureType, int worldX, int worldZ) { + IrisRegistrant dimension = levels.dimension(); + IrisRegistrant region = levels.region(worldX, worldZ); + IrisRegistrant biome = levels.surfaceBiome(worldX, worldZ); + ModuleSettings dimensionSettings = settingsOf(dimension); + ModuleSettings regionSettings = settingsOf(region); + ModuleSettings biomeSettings = settingsOf(biome); + SettingsStacks snapshotStacks = snapshotStacks(); + SettingsStack known = snapshotStacks.find(dimensionSettings, regionSettings, biomeSettings, featureType); + if (known != null) { + return known; + } + SettingsStack stack = stackOf(featureType, dimension, region, biome); + snapshotStacks.remember(dimensionSettings, regionSettings, biomeSettings, featureType, stack); + return stack; + } + + private SettingsStacks snapshotStacks() { + if (stacks == null) { + stacks = levels.stacks(); + } + return stacks; + } + + /** Answered from the distinct regions and surface biomes of the chunk's columns, each asked for its settings once. */ + @Override + public SettingsStack declaredInChunk(Class featureType, int chunkX, int chunkZ) { + List regions = new ArrayList<>(); + List biomes = new ArrayList<>(); + int originX = chunkX * ChunkContext.CHUNK_WIDTH; + int originZ = chunkZ * ChunkContext.CHUNK_WIDTH; + for (int x = 0; x < ChunkContext.CHUNK_WIDTH; x++) { + for (int z = 0; z < ChunkContext.CHUNK_WIDTH; z++) { + addDistinct(regions, levels.region(originX + x, originZ + z)); + addDistinct(biomes, levels.surfaceBiome(originX + x, originZ + z)); + } + } + List> entries = new ArrayList<>(); + Set sources = new HashSet<>(); + addEntry(entries, sources, featureType, Level.DIMENSION, DIMENSION, levels.dimension()); + regions.forEach(region -> addEntry(entries, sources, featureType, Level.REGION, REGION, region)); + biomes.forEach(biome -> addEntry(entries, sources, featureType, Level.BIOME, BIOME, biome)); + return SettingsStack.of(entries); } @Override @@ -79,13 +125,45 @@ final class ChunkModuleSettings implements FeatureSettings { return declared == null ? Optional.empty() : declared.getModuleSettings().find(featureType); } - private void addEntry(List> entries, Class featureType, Target level, String kind, - IrisRegistrant owner) { + private SettingsStack stackOf(Class featureType, IrisRegistrant dimension, IrisRegistrant region, + IrisRegistrant biome) { + List> entries = new ArrayList<>(Level.values().length); + Set sources = new HashSet<>(); + addEntry(entries, sources, featureType, Level.DIMENSION, DIMENSION, dimension); + addEntry(entries, sources, featureType, Level.REGION, REGION, region); + addEntry(entries, sources, featureType, Level.BIOME, BIOME, biome); + return entries.isEmpty() ? SettingsStack.empty() : SettingsStack.of(entries); + } + + private void addEntry(List> entries, Set sources, Class featureType, Level level, + String kind, IrisRegistrant owner) { if (owner == null) { return; } - owner.getModuleSettings().find(featureType) - .ifPresent(value -> entries.add(new Entry<>(level, ids.of(kind, owner.getLoadKey()), value))); + Optional declared = owner.getModuleSettings().find(featureType); + if (declared.isEmpty()) { + return; + } + ResourceId source = ids.of(kind, owner.getLoadKey()); + if (sources.add(source)) { + entries.add(new Entry<>(level, source, declared.get())); + } + } + + private static ModuleSettings settingsOf(IrisRegistrant owner) { + return owner == null ? ModuleSettings.NONE : owner.getModuleSettings(); + } + + private static void addDistinct(List owners, IrisRegistrant owner) { + if (owner == null) { + return; + } + for (IrisRegistrant known : owners) { + if (known == owner) { + return; + } + } + owners.add(owner); } /** The dimension, region and surface biome the engine generates a column with. */ @@ -107,7 +185,16 @@ final class ChunkModuleSettings implements FeatureSettings { @Override public IrisBiome biome(ResourceId id) { - return ((IrisPackResources) engine.getData().getPackResources()).irisBiome(id).orElse(null); + return packResources().irisBiome(id).orElse(null); + } + + @Override + public SettingsStacks stacks() { + return packResources().settingsStacks(); + } + + private IrisPackResources packResources() { + return (IrisPackResources) engine.getData().getPackResources(); } } } diff --git a/core/src/main/java/art/arcane/iris/core/modules/DimensionSettings.java b/core/src/main/java/art/arcane/iris/core/modules/DimensionSettings.java index d074f39e0..8a701d3ed 100644 --- a/core/src/main/java/art/arcane/iris/core/modules/DimensionSettings.java +++ b/core/src/main/java/art/arcane/iris/core/modules/DimensionSettings.java @@ -21,8 +21,8 @@ package art.arcane.iris.core.modules; import art.arcane.iris.core.loader.IrisData; import art.arcane.iris.engine.object.world.dimension.IrisDimension; import com.volmit.IrisFeature; -import com.volmit.config.FeatureSettings.Entry; import com.volmit.config.PackSettings; +import com.volmit.config.SettingsStack; import java.util.List; @@ -43,7 +43,7 @@ final class DimensionSettings implements PackSettings { } @Override - public List> declared(Class featureType) { + public SettingsStack declared(Class featureType) { return IrisPackSettings.declaredBy(dimension, () -> data, ids, featureType); } } diff --git a/core/src/main/java/art/arcane/iris/core/modules/IrisGenerationContext.java b/core/src/main/java/art/arcane/iris/core/modules/IrisGenerationContext.java index 4d0668bff..8eb2f3f85 100644 --- a/core/src/main/java/art/arcane/iris/core/modules/IrisGenerationContext.java +++ b/core/src/main/java/art/arcane/iris/core/modules/IrisGenerationContext.java @@ -26,7 +26,6 @@ import com.volmit.generation.GenerationContext; import com.volmit.host.MantleRegistration; import com.volmit.mantle.BlockBox; import com.volmit.mantle.Mantle; -import com.volmit.resource.PackResources; import com.volmit.world.PackWorld; import com.volmit.world.TerrainSampler; @@ -102,15 +101,6 @@ final class IrisGenerationContext implements GenerationContext { return (com.volmit.hunk.Hunk) blocks; } - @Override - public long worldSeed() { - return engine.getSeedManager().getSeed(); - } - - @Override - public PackResources resources() { - return engine.getData().getPackResources(); - } /** The world this invocation first asked for; it keeps it if the world restarts meanwhile. */ @Override diff --git a/core/src/main/java/art/arcane/iris/core/modules/IrisMantleGenerationContext.java b/core/src/main/java/art/arcane/iris/core/modules/IrisMantleGenerationContext.java index d21dc60d8..738d85393 100644 --- a/core/src/main/java/art/arcane/iris/core/modules/IrisMantleGenerationContext.java +++ b/core/src/main/java/art/arcane/iris/core/modules/IrisMantleGenerationContext.java @@ -25,7 +25,6 @@ import com.volmit.generation.MantleGenerationContext; import com.volmit.host.MantleRegistration; import com.volmit.mantle.BlockBox; import com.volmit.mantle.Mantle; -import com.volmit.resource.PackResources; import com.volmit.world.PackWorld; import com.volmit.world.TerrainSampler; @@ -89,15 +88,6 @@ final class IrisMantleGenerationContext implements MantleGenerationContext { return mantle; } - @Override - public long worldSeed() { - return engine.getSeedManager().getSeed(); - } - - @Override - public PackResources resources() { - return engine.getData().getPackResources(); - } /** The world this invocation first asked for; it keeps it if the world restarts meanwhile. */ @Override diff --git a/core/src/main/java/art/arcane/iris/core/modules/IrisObjectHost.java b/core/src/main/java/art/arcane/iris/core/modules/IrisObjectHost.java index 3b363ac74..85157252d 100644 --- a/core/src/main/java/art/arcane/iris/core/modules/IrisObjectHost.java +++ b/core/src/main/java/art/arcane/iris/core/modules/IrisObjectHost.java @@ -44,7 +44,7 @@ import art.arcane.iris.util.project.noise.CNG; import art.arcane.iris.util.project.noise.NoiseType; import art.arcane.volmlib.util.cache.CacheKey; import art.arcane.volmlib.util.math.RNG; -import com.volmit.FeatureAttachment.Target; +import com.volmit.config.Level; import com.volmit.IrisFeature; import com.volmit.ModuleLog; import com.volmit.config.FeatureSettings; @@ -235,15 +235,15 @@ final class IrisObjectHost implements ObjectHost { public List> declarations(Class type) { List> found = new ArrayList<>(); for (IrisRegion region : engine.getDimension().getAllRegions(engine)) { - addDeclaration(found, Target.REGION, region, type); + addDeclaration(found, Level.REGION, region, type); } for (IrisBiome biome : engine.getDimension().getReachableBiomes(engine)) { - addDeclaration(found, Target.BIOME, biome, type); + addDeclaration(found, Level.BIOME, biome, type); } return found; } - private static void addDeclaration(List> found, Target level, IrisRegistrant owner, Class type) { + private static void addDeclaration(List> found, Level level, IrisRegistrant owner, Class type) { if (owner == null) { return; } diff --git a/core/src/main/java/art/arcane/iris/core/modules/IrisPackResources.java b/core/src/main/java/art/arcane/iris/core/modules/IrisPackResources.java index 2d904c73d..fb074dbdf 100644 --- a/core/src/main/java/art/arcane/iris/core/modules/IrisPackResources.java +++ b/core/src/main/java/art/arcane/iris/core/modules/IrisPackResources.java @@ -69,6 +69,7 @@ public final class IrisPackResources implements PackResources { private final IrisData data; private final PackResourceIds ids; private final UUID snapshotId = UUID.randomUUID(); + private final SettingsStacks settingsStacks = new SettingsStacks(); private final BlockRegistry blocks; private final ItemRegistry items = new IrisItemRegistry(); private final NoiseFactory noise; @@ -107,6 +108,11 @@ public final class IrisPackResources implements PackResources { return snapshotId; } + /** The settings stacks of this snapshot's columns, which every world generating with it shares. */ + SettingsStacks settingsStacks() { + return settingsStacks; + } + /** * Runs {@code announce}, which tells the pack's modules that this snapshot loaded, unless it ran successfully for * this snapshot before: modules hear of each snapshot once, however many worlds start with it. diff --git a/core/src/main/java/art/arcane/iris/core/modules/IrisPackSettings.java b/core/src/main/java/art/arcane/iris/core/modules/IrisPackSettings.java index 92e9c9130..29974a9be 100644 --- a/core/src/main/java/art/arcane/iris/core/modules/IrisPackSettings.java +++ b/core/src/main/java/art/arcane/iris/core/modules/IrisPackSettings.java @@ -27,10 +27,11 @@ import art.arcane.iris.engine.object.world.biome.IrisBiome; import art.arcane.iris.engine.object.world.dimension.IrisDimension; import art.arcane.iris.engine.object.world.region.IrisRegion; import art.arcane.iris.util.common.data.DataProvider; -import com.volmit.FeatureAttachment.Target; +import com.volmit.config.Level; import com.volmit.IrisFeature; import com.volmit.config.FeatureSettings.Entry; import com.volmit.config.PackSettings; +import com.volmit.config.SettingsStack; import com.volmit.resource.ResourceId; import java.util.ArrayList; @@ -83,26 +84,26 @@ public final class IrisPackSettings implements PackSettings, ObjectHost.Source, } @Override - public List> declared(Class featureType) { + public SettingsStack declared(Class featureType) { return declaredBy(engine.getDimension(), engine, ids, featureType); } /** The settings of {@code featureType} that {@code dimension} and every region and biome it reaches declare, in that order. */ - static List> declaredBy(IrisDimension dimension, DataProvider data, PackResourceIds ids, + static SettingsStack declaredBy(IrisDimension dimension, DataProvider data, PackResourceIds ids, Class featureType) { List> entries = new ArrayList<>(); - addEntry(entries, featureType, Target.DIMENSION, ids.of(DIMENSION, dimension.getLoadKey()), dimension); + addEntry(entries, featureType, Level.DIMENSION, ids.of(DIMENSION, dimension.getLoadKey()), dimension); for (IrisRegion region : dimension.getAllRegions(data)) { - addEntry(entries, featureType, Target.REGION, ids.of(REGION, region.getLoadKey()), region); + addEntry(entries, featureType, Level.REGION, ids.of(REGION, region.getLoadKey()), region); } for (IrisBiome biome : dimension.getReachableBiomes(data)) { - addEntry(entries, featureType, Target.BIOME, ids.of(BIOME, biome.getLoadKey()), biome); + addEntry(entries, featureType, Level.BIOME, ids.of(BIOME, biome.getLoadKey()), biome); } - return List.copyOf(entries); + return SettingsStack.of(entries); } /** Adds {@code owner}'s settings of {@code featureType}, if it declares them, as an entry from {@code source}. */ - static void addEntry(List> entries, Class featureType, Target level, ResourceId source, + static void addEntry(List> entries, Class featureType, Level level, ResourceId source, IrisRegistrant owner) { owner.getModuleSettings().find(featureType).ifPresent(value -> entries.add(new Entry<>(level, source, value))); } diff --git a/core/src/main/java/art/arcane/iris/core/modules/IrisPlacementInputs.java b/core/src/main/java/art/arcane/iris/core/modules/IrisPlacementInputs.java index 564fc6278..7028d73e4 100644 --- a/core/src/main/java/art/arcane/iris/core/modules/IrisPlacementInputs.java +++ b/core/src/main/java/art/arcane/iris/core/modules/IrisPlacementInputs.java @@ -23,7 +23,6 @@ import com.volmit.config.FeatureSettings; import com.volmit.mantle.BlockBox; import com.volmit.object.ObjectTransformer; import com.volmit.placement.PlacementContext; -import com.volmit.resource.PackResources; import com.volmit.world.BiomeKind; import com.volmit.world.BiomeSample; import com.volmit.world.BlockView; @@ -32,27 +31,28 @@ import com.volmit.world.PackWorld; import com.volmit.world.TerrainSampler; import java.util.OptionalInt; +import java.util.function.Supplier; /** The read-only IrisApi inputs of one Iris object placement. */ final class IrisPlacementInputs implements PlacementContext { private final ObjectTransformer objects = new IrisObjectTransformer(); - private final long worldSeed; private final TerrainSampler terrain; private final FeatureSettings settings; private final BlockView blocks; - private final PackResources resources; - private final Engine engine; + private final Supplier worldSource; private PackWorld world; - /** @param engine the engine whose world the placement generates in, or null for a placement without one */ - IrisPlacementInputs(long worldSeed, TerrainSampler terrain, FeatureSettings settings, BlockView blocks, PackResources resources, - Engine engine) { - this.resources = resources; - this.engine = engine; - this.worldSeed = worldSeed; + /** @param worldSource the world the placement generates in, asked for the first time a stage needs it */ + IrisPlacementInputs(TerrainSampler terrain, FeatureSettings settings, BlockView blocks, Supplier worldSource) { this.terrain = terrain; this.settings = settings; this.blocks = blocks; + this.worldSource = worldSource; + } + + /** The world of the engine's runtime, as it is when the placement first asks. */ + static Supplier worldOf(Engine engine) { + return () -> engine.getGeneration().world(); } /** For placements without an engine, such as pasting an object into a world Iris does not generate. */ @@ -119,24 +119,11 @@ final class IrisPlacementInputs implements PlacementContext { return blocks; } - @Override - public long worldSeed() { - return worldSeed; - } - - @Override - public PackResources resources() { - return resources; - } - /** The world this placement first asked for; it keeps it if the world restarts meanwhile. */ @Override public PackWorld world() { - if (engine == null) { - throw new IllegalStateException("This placement runs without an Iris engine, so it is not part of a world"); - } if (world == null) { - world = engine.getGeneration().world(); + world = worldSource.get(); } return world; } diff --git a/core/src/main/java/art/arcane/iris/core/modules/IrisTerrainSampler.java b/core/src/main/java/art/arcane/iris/core/modules/IrisTerrainSampler.java index 3f7394370..12edf0f7b 100644 --- a/core/src/main/java/art/arcane/iris/core/modules/IrisTerrainSampler.java +++ b/core/src/main/java/art/arcane/iris/core/modules/IrisTerrainSampler.java @@ -94,6 +94,11 @@ final class IrisTerrainSampler implements TerrainSampler { return engine.getComplex().getHeightStream().get(worldX, worldZ); } + @Override + public int surfaceHeight(int worldX, int worldZ) { + return (int) Math.round(surfaceY(worldX, worldZ)); + } + @Override public BiomeSample biome(int worldX, int y, int worldZ) { requireInside(worldX, y, worldZ); diff --git a/core/src/main/java/art/arcane/iris/core/modules/IrisUpperDimension.java b/core/src/main/java/art/arcane/iris/core/modules/IrisUpperDimension.java index 062590742..b4b019404 100644 --- a/core/src/main/java/art/arcane/iris/core/modules/IrisUpperDimension.java +++ b/core/src/main/java/art/arcane/iris/core/modules/IrisUpperDimension.java @@ -86,7 +86,16 @@ final class IrisUpperDimension implements UpperDimension { @Override public IrisBiome biome(ResourceId id) { - return ((IrisPackResources) upper.getData().getPackResources()).irisBiome(id).orElse(null); + return packResources().irisBiome(id).orElse(null); + } + + @Override + public SettingsStacks stacks() { + return packResources().settingsStacks(); + } + + private IrisPackResources packResources() { + return (IrisPackResources) upper.getData().getPackResources(); } } } diff --git a/core/src/main/java/art/arcane/iris/core/modules/ModuleObjectPlacement.java b/core/src/main/java/art/arcane/iris/core/modules/ModuleObjectPlacement.java index 3aa98276e..dc7c2ad8e 100644 --- a/core/src/main/java/art/arcane/iris/core/modules/ModuleObjectPlacement.java +++ b/core/src/main/java/art/arcane/iris/core/modules/ModuleObjectPlacement.java @@ -49,8 +49,8 @@ import java.util.function.BiConsumer; * rejects the placement. *

* Each stage draws from its own stream of one seed per placement, from the world seed and the placement's - * identity: the object and the requested position. Without an engine there is no world seed, so one draw - * from the caller's random stands in for it. + * identity: the object and the requested position. Without an engine, such as for a studio paste, the placement + * runs in a {@link ToolWorld} of its own, whose seed is one draw from the caller's random. */ public final class ModuleObjectPlacement { private static final String UNNAMED_OBJECT = "unnamed"; @@ -85,16 +85,18 @@ public final class ModuleObjectPlacement { ResourceId source = ids.of("object", objectKey); PlacementRequest request = new PlacementRequest(ids.of("placement/" + objectKey + "/" + x + "/" + requestedY + "/" + z), geometry, new BlockPosition(x, requestedY, z)); - IrisPlacementInputs inputs = new IrisPlacementInputs(worldSeed, terrain(engine, ids, area), - new PlacementModuleSettings(worldSettings(engine, ids), config.getModuleSettings(), source), - new PlacerBlockView(placer, area, states), data.getPackResources(), engine); long seed = ModuleSeeds.placement(worldSeed, objectKey, x, requestedY, z); StageMetrics metrics = new StageMetrics(engine != null ? engine.getMetrics() : null); - PlacementOutcome outcome = placement.runBound(() -> new PlacementRunner(graph) - .place(request, edit, inputs, seed, config.getModuleSettings().placement(source), metrics)); - return outcome.isPlaced() - ? ObjectPlacementResult.placed(placement.anchorY()) - : ObjectPlacementResult.rejected(outcome.rejection().orElseThrow()); + try (ToolWorld toolWorld = engine == null ? new ToolWorld(worldSeed, data.getPackResources(), new PackDeclaredSettings(data)) : null) { + IrisPlacementInputs inputs = new IrisPlacementInputs(terrain(engine, ids, area), + new PlacementModuleSettings(worldSettings(engine, ids), config.getModuleSettings(), source), + new PlacerBlockView(placer, area, states), engine != null ? IrisPlacementInputs.worldOf(engine) : () -> toolWorld); + PlacementOutcome outcome = placement.runBound(() -> new PlacementRunner(graph) + .place(request, edit, inputs, seed, config.getModuleSettings().placement(source), metrics)); + return outcome.isPlaced() + ? ObjectPlacementResult.placed(placement.anchorY()) + : ObjectPlacementResult.rejected(outcome.rejection().orElseThrow()); + } } /** Smart boring adds the object's bored air, so it has to happen before the geometry is read. */ diff --git a/core/src/main/java/art/arcane/iris/core/modules/ModuleSettingsDecoder.java b/core/src/main/java/art/arcane/iris/core/modules/ModuleSettingsDecoder.java index 35b012ce6..7b0271065 100644 --- a/core/src/main/java/art/arcane/iris/core/modules/ModuleSettingsDecoder.java +++ b/core/src/main/java/art/arcane/iris/core/modules/ModuleSettingsDecoder.java @@ -31,7 +31,7 @@ import com.google.gson.reflect.TypeToken; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonToken; import com.google.gson.stream.JsonWriter; -import com.volmit.FeatureAttachment.Target; +import com.volmit.config.Level; import com.volmit.IrisFeature; import com.volmit.block.BlockState; import com.volmit.config.OptionsMetadata; @@ -73,8 +73,8 @@ public final class ModuleSettingsDecoder { private static final String SNIPPET_FOLDER = "snippet"; private static final String JSON_EXTENSION = ".json"; - private final Map>> settings = new EnumMap<>(Target.class); - private final Map> keys = new EnumMap<>(Target.class); + private final Map>> settings = new EnumMap<>(Level.class); + private final Map> keys = new EnumMap<>(Level.class); private final Path packFolder; private final Gson gson; private final Supplier irisGson; @@ -89,14 +89,14 @@ public final class ModuleSettingsDecoder { .registerTypeAdapterFactory(new HostTypes()) .registerTypeAdapterFactory(new SnippetReferences()) .create(); - for (Target target : Target.values()) { + for (Level target : Level.values()) { settings.put(target, settingsAt(catalog, target)); keys.put(target, keysAt(catalog, target)); } } /** Every JSON key the pack's modules read at {@code target}: the keys of their features, object generators' included. */ - public Set keys(Target target) { + public Set keys(Level target) { return keys.get(target); } @@ -106,7 +106,7 @@ public final class ModuleSettingsDecoder { * @param resource names the file in errors, such as {@code biome desert/dunes} * @throws IllegalArgumentException when a value does not decode into its settings type */ - public ModuleSettings decode(Target target, JSONObject json, String resource) { + public ModuleSettings decode(Level target, JSONObject json, String resource) { Map, IrisFeature> values = new LinkedHashMap<>(); for (FeatureDescriptor feature : settings.get(target)) { if (json.has(feature.key())) { @@ -135,7 +135,7 @@ public final class ModuleSettingsDecoder { * The JSON that declares {@code values} at {@code target}: each settings feature under its key, in the shape the * feature is written in (a rooted feature as its root option's value), the inverse of {@link #decode}. */ - public JSONObject encode(Target target, ModuleSettings values) { + public JSONObject encode(Level target, ModuleSettings values) { JSONObject json = new JSONObject(); for (FeatureDescriptor feature : settings.get(target)) { values.find(feature.type()).ifPresent(value -> json.put(feature.key(), writtenShape(feature, value))); @@ -210,17 +210,17 @@ public final class ModuleSettingsDecoder { .orElseThrow(() -> new IllegalStateException("Root " + root + " is no option of " + feature.type().getName())); } - private static List> settingsAt(FeatureCatalog catalog, Target target) { + private static List> settingsAt(FeatureCatalog catalog, Level target) { return catalog.settings().stream() - .filter(feature -> feature.attachment().targets().contains(target)) + .filter(feature -> feature.targets().contains(target)) .toList(); } - private static Set keysAt(FeatureCatalog catalog, Target target) { + private static Set keysAt(FeatureCatalog catalog, Level target) { Stream> objects = catalog.objects().stream().map(ObjectRegistration::descriptor); Set found = new TreeSet<>(); Stream.concat(catalog.settings().stream(), objects) - .filter(feature -> feature.attachment().targets().contains(target)) + .filter(feature -> feature.targets().contains(target)) .forEach(feature -> found.add(feature.key())); return Set.copyOf(found); } diff --git a/core/src/main/java/art/arcane/iris/core/modules/ModuleTargets.java b/core/src/main/java/art/arcane/iris/core/modules/ModuleTargets.java index e42cf915a..03ed5a492 100644 --- a/core/src/main/java/art/arcane/iris/core/modules/ModuleTargets.java +++ b/core/src/main/java/art/arcane/iris/core/modules/ModuleTargets.java @@ -23,7 +23,7 @@ import art.arcane.iris.engine.object.placement.IrisObjectPlacement; import art.arcane.iris.engine.object.world.biome.IrisBiome; import art.arcane.iris.engine.object.world.dimension.IrisDimension; import art.arcane.iris.engine.object.world.region.IrisRegion; -import com.volmit.FeatureAttachment.Target; +import com.volmit.config.Level; import java.util.EnumMap; import java.util.Map; @@ -34,17 +34,17 @@ import java.util.Set; * Which Iris class holds the JSON of each attachment target that module settings can appear in. */ public final class ModuleTargets { - private static final Map> HOLDERS = Map.of( - Target.DIMENSION, IrisDimension.class, - Target.REGION, IrisRegion.class, - Target.BIOME, IrisBiome.class, - Target.OBJECT_PLACEMENT, IrisObjectPlacement.class); + private static final Map> HOLDERS = Map.of( + Level.DIMENSION, IrisDimension.class, + Level.REGION, IrisRegion.class, + Level.BIOME, IrisBiome.class, + Level.PLACEMENT, IrisObjectPlacement.class); private ModuleTargets() { } /** The target whose JSON a resource of {@code resourceType} is, if module settings can appear in it. */ - public static Optional ofResource(Class resourceType) { + public static Optional ofResource(Class resourceType) { return HOLDERS.entrySet().stream() .filter(entry -> entry.getValue() == resourceType) .map(Map.Entry::getKey) @@ -52,8 +52,8 @@ public final class ModuleTargets { } /** Iris's own JSON fields per target, which no settings key may take. */ - static Map> reservedFields() { - Map> fields = new EnumMap<>(Target.class); + static Map> reservedFields() { + Map> fields = new EnumMap<>(Level.class); HOLDERS.forEach((target, holder) -> fields.put(target, JsonFieldNames.of(holder))); return fields; } diff --git a/core/src/main/java/art/arcane/iris/core/modules/ObjectPlacementSettingsReader.java b/core/src/main/java/art/arcane/iris/core/modules/ObjectPlacementSettingsReader.java index c8d67fdcf..a5e0b259a 100644 --- a/core/src/main/java/art/arcane/iris/core/modules/ObjectPlacementSettingsReader.java +++ b/core/src/main/java/art/arcane/iris/core/modules/ObjectPlacementSettingsReader.java @@ -27,7 +27,7 @@ import com.google.gson.TypeAdapterFactory; import com.google.gson.reflect.TypeToken; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; -import com.volmit.FeatureAttachment.Target; +import com.volmit.config.Level; import java.io.IOException; import java.util.function.Supplier; @@ -66,7 +66,7 @@ public final class ObjectPlacementSettingsReader implements TypeAdapterFactory { JsonElement json = elements.read(in); IrisObjectPlacement placement = placements.fromJsonTree(json); if (placement != null && json.isJsonObject()) { - placement.setModuleSettings(decoder.get().decode(Target.OBJECT_PLACEMENT, + placement.setModuleSettings(decoder.get().decode(Level.PLACEMENT, new JSONObject(json.toString()), "object placement at " + path)); } return placement; diff --git a/core/src/main/java/art/arcane/iris/core/modules/PackDeclaredSettings.java b/core/src/main/java/art/arcane/iris/core/modules/PackDeclaredSettings.java index 6d7d1a515..f74d3ed0d 100644 --- a/core/src/main/java/art/arcane/iris/core/modules/PackDeclaredSettings.java +++ b/core/src/main/java/art/arcane/iris/core/modules/PackDeclaredSettings.java @@ -21,10 +21,11 @@ package art.arcane.iris.core.modules; import art.arcane.iris.core.loader.IrisData; import art.arcane.iris.core.loader.IrisRegistrant; import art.arcane.iris.core.loader.ResourceLoader; -import com.volmit.FeatureAttachment.Target; +import com.volmit.config.Level; import com.volmit.IrisFeature; import com.volmit.config.FeatureSettings.Entry; import com.volmit.config.PackSettings; +import com.volmit.config.SettingsStack; import java.util.ArrayList; import java.util.Arrays; @@ -45,16 +46,16 @@ final class PackDeclaredSettings implements PackSettings { } @Override - public List> declared(Class featureType) { + public SettingsStack declared(Class featureType) { List> entries = new ArrayList<>(); - addEntries(entries, featureType, Target.DIMENSION, IrisPackSettings.DIMENSION, data.getDimensionLoader()); - addEntries(entries, featureType, Target.REGION, IrisPackSettings.REGION, data.getRegionLoader()); - addEntries(entries, featureType, Target.BIOME, IrisPackSettings.BIOME, data.getBiomeLoader()); - return List.copyOf(entries); + addEntries(entries, featureType, Level.DIMENSION, IrisPackSettings.DIMENSION, data.getDimensionLoader()); + addEntries(entries, featureType, Level.REGION, IrisPackSettings.REGION, data.getRegionLoader()); + addEntries(entries, featureType, Level.BIOME, IrisPackSettings.BIOME, data.getBiomeLoader()); + return SettingsStack.of(entries); } private void addEntries(List> entries, Class featureType, - Target level, String kind, ResourceLoader loader) { + Level level, String kind, ResourceLoader loader) { for (String key : Arrays.stream(loader.getPossibleKeys()).sorted().toList()) { R owner = loader.load(key, false); if (owner != null) { diff --git a/core/src/main/java/art/arcane/iris/core/modules/PlacementModuleSettings.java b/core/src/main/java/art/arcane/iris/core/modules/PlacementModuleSettings.java index 35c7ef286..0e39e08a8 100644 --- a/core/src/main/java/art/arcane/iris/core/modules/PlacementModuleSettings.java +++ b/core/src/main/java/art/arcane/iris/core/modules/PlacementModuleSettings.java @@ -18,9 +18,10 @@ package art.arcane.iris.core.modules; -import com.volmit.FeatureAttachment.Target; import com.volmit.IrisFeature; import com.volmit.config.FeatureSettings; +import com.volmit.config.Level; +import com.volmit.config.SettingsStack; import com.volmit.resource.ResourceId; import java.util.ArrayList; @@ -34,8 +35,8 @@ import java.util.Optional; final class PlacementModuleSettings implements FeatureSettings { private static final FeatureSettings NO_WORLD = new FeatureSettings() { @Override - public List> at(Class featureType, int worldX, int worldZ) { - return List.of(); + public SettingsStack at(Class featureType, int worldX, int worldZ) { + return SettingsStack.empty(); } }; @@ -55,14 +56,14 @@ final class PlacementModuleSettings implements FeatureSettings { } @Override - public List> at(Class featureType, int worldX, int worldZ) { - List> worldEntries = world.at(featureType, worldX, worldZ); + public SettingsStack at(Class featureType, int worldX, int worldZ) { + SettingsStack worldEntries = world.at(featureType, worldX, worldZ); Optional own = placement.find(featureType); if (own.isEmpty()) { return worldEntries; } - List> entries = new ArrayList<>(worldEntries); - entries.add(new Entry<>(Target.OBJECT_PLACEMENT, source, own.get())); - return List.copyOf(entries); + List> entries = new ArrayList<>(worldEntries.entries()); + entries.add(new Entry<>(Level.PLACEMENT, source, own.get())); + return SettingsStack.of(entries); } } diff --git a/core/src/main/java/art/arcane/iris/core/modules/SettingsStacks.java b/core/src/main/java/art/arcane/iris/core/modules/SettingsStacks.java new file mode 100644 index 000000000..470cf00be --- /dev/null +++ b/core/src/main/java/art/arcane/iris/core/modules/SettingsStacks.java @@ -0,0 +1,59 @@ +/* + * Iris is a World Generator for Minecraft Servers + * Copyright (c) 2026 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package art.arcane.iris.core.modules; + +import com.volmit.IrisFeature; +import com.volmit.config.SettingsStack; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * The settings stacks of one pack snapshot, kept per settings type and per the module settings of the dimension, region + * and surface biome that make each one, so that a column whose combination was seen before gets its stack without + * allocating. Every registrant of a snapshot decodes its own module settings, so the instances, compared by identity, + * stand for the registrants; a missing level is {@link ModuleSettings#NONE}, which declares nothing either. + */ +final class SettingsStacks { + private final Map, SettingsStack>>>> byDimension = + new ConcurrentHashMap<>(); + + /** The stack remembered for the combination, or null when none was yet. */ + @SuppressWarnings("unchecked") + SettingsStack find(ModuleSettings dimension, ModuleSettings region, ModuleSettings biome, Class type) { + var byRegion = byDimension.get(dimension); + if (byRegion == null) { + return null; + } + var byBiome = byRegion.get(region); + if (byBiome == null) { + return null; + } + var byType = byBiome.get(biome); + return byType == null ? null : (SettingsStack) byType.get(type); + } + + void remember(ModuleSettings dimension, ModuleSettings region, ModuleSettings biome, Class type, + SettingsStack stack) { + byDimension.computeIfAbsent(dimension, ignored -> new ConcurrentHashMap<>()) + .computeIfAbsent(region, ignored -> new ConcurrentHashMap<>()) + .computeIfAbsent(biome, ignored -> new ConcurrentHashMap<>()) + .put(type, stack); + } +} diff --git a/core/src/main/java/art/arcane/iris/core/modules/ToolWorld.java b/core/src/main/java/art/arcane/iris/core/modules/ToolWorld.java new file mode 100644 index 000000000..f90689d75 --- /dev/null +++ b/core/src/main/java/art/arcane/iris/core/modules/ToolWorld.java @@ -0,0 +1,92 @@ +/* + * Iris is a World Generator for Minecraft Servers + * Copyright (c) 2026 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package art.arcane.iris.core.modules; + +import com.volmit.ModuleLog; +import com.volmit.config.PackSettings; +import com.volmit.host.WorldStates; +import com.volmit.resource.PackResources; +import com.volmit.world.PackWorld; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Function; + +/** + * The world of one placement a tool makes outside the worlds Iris generates, such as a studio paste: the pack's + * resources and settings, the seed the placement draws, and state that lives as long as the placement. It has no + * dimension, so its bottom is Y 0, and no lifecycle hook runs for it. Closing it closes the state modules kept. + */ +final class ToolWorld implements PackWorld, AutoCloseable { + private final long seed; + private final PackResources resources; + private final PackSettings settings; + private final WorldStates states; + private final ModuleLog log; + private final Map viewsByLog; + + ToolWorld(long seed, PackResources resources, PackSettings settings) { + this(seed, resources, settings, new WorldStates(), IrisApiLogger.hostLog(), new ConcurrentHashMap<>()); + } + + private ToolWorld(long seed, PackResources resources, PackSettings settings, WorldStates states, ModuleLog log, + Map viewsByLog) { + this.seed = seed; + this.resources = resources; + this.settings = settings; + this.states = states; + this.log = log; + this.viewsByLog = viewsByLog; + } + + @Override + public long seed() { + return seed; + } + + @Override + public PackResources resources() { + return resources; + } + + @Override + public PackSettings settings() { + return settings; + } + + @Override + public T state(Class type, Function create) { + return states.state(type, () -> create.apply(this)); + } + + @Override + public ModuleLog log() { + return log; + } + + @Override + public PackWorld withLog(ModuleLog log) { + return viewsByLog.computeIfAbsent(log, moduleLog -> new ToolWorld(seed, resources, settings, states, moduleLog, viewsByLog)); + } + + @Override + public void close() { + states.close(); + } +} diff --git a/core/src/main/java/art/arcane/iris/core/project/IrisPackageCompiler.java b/core/src/main/java/art/arcane/iris/core/project/IrisPackageCompiler.java index d4fe93148..a08a0fc72 100644 --- a/core/src/main/java/art/arcane/iris/core/project/IrisPackageCompiler.java +++ b/core/src/main/java/art/arcane/iris/core/project/IrisPackageCompiler.java @@ -48,7 +48,7 @@ import art.arcane.volmlib.util.localization.MessageArgument; import art.arcane.volmlib.util.math.M; import art.arcane.volmlib.util.scheduling.ChronoLatch; import art.arcane.volmlib.util.scheduling.O; -import com.volmit.FeatureAttachment.Target; +import com.volmit.config.Level; import org.zeroturnaround.zip.ZipUtil; import java.io.File; @@ -201,7 +201,7 @@ public class IrisPackageCompiler { } b.append(structureClosure.writeTo(folder, minify)); b.append(ImageMapPackageClosure.writeAll(dm, folder, minify)); - a = withModuleSettings(dimension, Target.DIMENSION, dm).toString(minify ? 0 : 4); + a = withModuleSettings(dimension, Level.DIMENSION, dm).toString(minify ? 0 : 4); IO.writeAll(new File(folder, "dimensions/" + dimension.getLoadKey() + ".json"), a); b.append(IO.hash(a)); @@ -215,7 +215,7 @@ public class IrisPackageCompiler { b = new StringBuilder(); for (IrisRegion i : regions) { - a = withModuleSettings(i, Target.REGION, dm).toString(minify ? 0 : 4); + a = withModuleSettings(i, Level.REGION, dm).toString(minify ? 0 : 4); IO.writeAll(new File(folder, "regions/" + i.getLoadKey() + ".json"), a); b.append(IO.hash(a)); } @@ -227,7 +227,7 @@ public class IrisPackageCompiler { } for (IrisBiome i : biomes) { - a = withModuleSettings(i, Target.BIOME, dm).toString(minify ? 0 : 4); + a = withModuleSettings(i, Level.BIOME, dm).toString(minify ? 0 : 4); IO.writeAll(new File(folder, "biomes/" + i.getLoadKey() + ".json"), a); b.append(IO.hash(a)); } @@ -256,7 +256,7 @@ public class IrisPackageCompiler { } /** The JSON of a dimension, region or biome with the settings its modules declare, which the resource itself does not hold. */ - private static JSONObject withModuleSettings(IrisRegistrant resource, Target target, IrisData data) { + private static JSONObject withModuleSettings(IrisRegistrant resource, Level target, IrisData data) { JSONObject json = new JSONObject(new Gson().toJson(resource)); JSONObject settings = data.getModules().settings().encode(target, resource.getModuleSettings()); settings.keySet().forEach(key -> json.put(key, settings.get(key))); diff --git a/core/src/main/java/art/arcane/iris/core/project/ModuleSchemaRenderer.java b/core/src/main/java/art/arcane/iris/core/project/ModuleSchemaRenderer.java index 5915781d9..aa50d004f 100644 --- a/core/src/main/java/art/arcane/iris/core/project/ModuleSchemaRenderer.java +++ b/core/src/main/java/art/arcane/iris/core/project/ModuleSchemaRenderer.java @@ -20,7 +20,7 @@ package art.arcane.iris.core.project; import art.arcane.volmlib.util.json.JSONArray; import art.arcane.volmlib.util.json.JSONObject; -import com.volmit.FeatureAttachment.Target; +import com.volmit.config.Level; import com.volmit.config.Reference; import com.volmit.host.schema.FeatureSchema; import com.volmit.host.schema.ObjectType; @@ -90,7 +90,7 @@ final class ModuleSchemaRenderer { } /** Adds every feature at {@code target} to {@code properties} under its key. */ - void addFeatures(Target target, JSONObject properties) { + void addFeatures(Level target, JSONObject properties) { for (FeatureSchema feature : schema.fields(target)) { properties.put(feature.key(), featureProperty(feature)); } diff --git a/core/src/test/java/art/arcane/iris/core/modules/BuiltInGenerationGraphTest.java b/core/src/test/java/art/arcane/iris/core/modules/BuiltInGenerationGraphTest.java index d79771de0..017845257 100644 --- a/core/src/test/java/art/arcane/iris/core/modules/BuiltInGenerationGraphTest.java +++ b/core/src/test/java/art/arcane/iris/core/modules/BuiltInGenerationGraphTest.java @@ -25,7 +25,7 @@ import art.arcane.iris.builtin.decorant.Decorator; import art.arcane.iris.builtin.deposit.DepositGenerator; import art.arcane.iris.builtin.deposit.DepositSettings; import art.arcane.iris.builtin.structure.StructureSettings; -import com.volmit.FeatureAttachment.Target; +import com.volmit.config.Level; import com.volmit.IrisFeature; import com.volmit.IrisModule; import com.volmit.ModuleInfo; @@ -103,7 +103,7 @@ public class BuiltInGenerationGraphTest { @Test public void depositsAreTheListOfGeneratorsOfEveryLevelWrittenUnderDeposits() throws IOException { try (LoadedPack pack = BuiltInPack.serve(mock(IrisData.class), folder, List.of())) { - for (Target level : List.of(Target.DIMENSION, Target.REGION, Target.BIOME)) { + for (Level level : List.of(Level.DIMENSION, Level.REGION, Level.BIOME)) { FeatureSchema deposits = pack.schema().fields(level).stream() .filter(feature -> feature.settings().name().equals(DepositSettings.class.getName())) .findFirst().orElseThrow(); @@ -121,7 +121,7 @@ public class BuiltInGenerationGraphTest { @Test public void importedStructuresAreAnObjectOfOptionsOfTheDimension() throws IOException { try (LoadedPack pack = BuiltInPack.serve(mock(IrisData.class), folder, List.of())) { - FeatureSchema structures = pack.schema().fields(Target.DIMENSION).stream() + FeatureSchema structures = pack.schema().fields(Level.DIMENSION).stream() .filter(feature -> feature.settings().name().equals(StructureSettings.class.getName())) .findFirst().orElseThrow(); @@ -135,7 +135,7 @@ public class BuiltInGenerationGraphTest { @Test public void theBuiltInKeysAreUniquePerTargetAndNoFieldOfIris() throws IOException { try (LoadedPack pack = BuiltInPack.serve(mock(IrisData.class), folder, List.of())) { - for (Target target : Target.values()) { + for (Level target : Level.values()) { List keys = pack.schema().fields(target).stream().map(FeatureSchema::key).toList(); assertEquals(target + " " + keys, keys.size(), keys.stream().distinct().count()); assertTrue(target + " " + keys, keys.stream().noneMatch(ModuleTargets.reservedFields().get(target)::contains)); @@ -156,11 +156,11 @@ public class BuiltInGenerationGraphTest { + " give one of the settings another key in its @Feature", field.getMessage()); } - @Feature(id = "test:rival/deposits", name = "Rival deposits", key = "deposits", targets = Target.REGION) + @Feature(id = "test:rival/deposits", name = "Rival deposits", key = "deposits", targets = Level.REGION) public static final class TakesDeposits implements IrisFeature { } - @Feature(id = "test:rival/generators", name = "Rival generators", key = "generators", targets = Target.BIOME) + @Feature(id = "test:rival/generators", name = "Rival generators", key = "generators", targets = Level.BIOME) public static final class TakesAHostField implements IrisFeature { } @@ -195,11 +195,11 @@ public class BuiltInGenerationGraphTest { @Test public void decoratorsAreTheBiomesListOfDecoratorsWrittenUnderDecorators() throws IOException { try (LoadedPack pack = BuiltInPack.serve(mock(IrisData.class), folder, List.of())) { - for (Target level : List.of(Target.DIMENSION, Target.REGION)) { + for (Level level : List.of(Level.DIMENSION, Level.REGION)) { assertTrue(level + " has no decorators", pack.schema().fields(level).stream() .noneMatch(feature -> feature.settings().name().equals(DecorantSettings.class.getName()))); } - FeatureSchema decorant = pack.schema().fields(Target.BIOME).stream() + FeatureSchema decorant = pack.schema().fields(Level.BIOME).stream() .filter(feature -> feature.settings().name().equals(DecorantSettings.class.getName())) .findFirst().orElseThrow(); assertEquals("decorators", decorant.key()); diff --git a/core/src/test/java/art/arcane/iris/core/modules/BuiltInPack.java b/core/src/test/java/art/arcane/iris/core/modules/BuiltInPack.java index 06f575003..d0a54a29c 100644 --- a/core/src/test/java/art/arcane/iris/core/modules/BuiltInPack.java +++ b/core/src/test/java/art/arcane/iris/core/modules/BuiltInPack.java @@ -110,6 +110,8 @@ public final class BuiltInPack { when(moduleSet.pack()).thenReturn(pack); when(data.getModules()).thenReturn(moduleSet); when(data.getDataFolder()).thenReturn(folder.getRoot()); + IrisPackResources resources = new IrisPackResources(data); + when(data.getPackResources()).thenReturn(resources); return pack; } diff --git a/core/src/test/java/art/arcane/iris/core/modules/CarveSettingsDecodingTest.java b/core/src/test/java/art/arcane/iris/core/modules/CarveSettingsDecodingTest.java index 8507d6c23..d96a8a7ac 100644 --- a/core/src/test/java/art/arcane/iris/core/modules/CarveSettingsDecodingTest.java +++ b/core/src/test/java/art/arcane/iris/core/modules/CarveSettingsDecodingTest.java @@ -29,7 +29,7 @@ import art.arcane.iris.builtin.carve.CaveProfile; import art.arcane.iris.builtin.carve.UpperDimensionCarvingSettings; import art.arcane.volmlib.util.json.JSONObject; import com.google.gson.Gson; -import com.volmit.FeatureAttachment.Target; +import com.volmit.config.Level; import com.volmit.host.LoadedPack; import com.volmit.host.ModuleHost; import org.junit.After; @@ -81,7 +81,7 @@ public class CarveSettingsDecodingTest { @Test public void theOverworldReadsItsCaveProfileItsCarvingBandsAndCarvingEnabled() throws IOException { - ModuleSettings settings = decoder.decode(Target.DIMENSION, file("dimensions/overworld.json"), "dimension overworld"); + ModuleSettings settings = decoder.decode(Level.DIMENSION, file("dimensions/overworld.json"), "dimension overworld"); CaveProfile profile = settings.find(CaveProfile.class).orElseThrow(); assertTrue(profile.enabled()); @@ -117,7 +117,7 @@ public class CarveSettingsDecodingTest { public void aRegionReadsItsCaveProfile() throws IOException { JSONObject region = file("regions/forests.json"); - CaveProfile profile = decoder.decode(Target.REGION, region, "region forests").find(CaveProfile.class).orElseThrow(); + CaveProfile profile = decoder.decode(Level.REGION, region, "region forests").find(CaveProfile.class).orElseThrow(); assertTrue(profile.enabled()); assertEquals(6, profile.verticalRange().min(), 0); @@ -130,7 +130,7 @@ public class CarveSettingsDecodingTest { public void aBiomeReadsItsCaveProfileAndItsMinimumDepth() throws IOException { JSONObject biome = file("biomes/carving/amethyst.json"); - ModuleSettings settings = decoder.decode(Target.BIOME, biome, "biome carving/amethyst"); + ModuleSettings settings = decoder.decode(Level.BIOME, biome, "biome carving/amethyst"); CaveProfile profile = settings.find(CaveProfile.class).orElseThrow(); assertTrue(profile.enabled()); @@ -144,7 +144,7 @@ public class CarveSettingsDecodingTest { @Test public void aCaveProfileMayBeWrittenAsASnippetReference() { - ModuleSettings settings = decoder.decode(Target.BIOME, new JSONObject("{\"caveProfile\": \"snippet/cave-profile/shallow\"}"), "biome test"); + ModuleSettings settings = decoder.decode(Level.BIOME, new JSONObject("{\"caveProfile\": \"snippet/cave-profile/shallow\"}"), "biome test"); CaveProfile profile = settings.find(CaveProfile.class).orElseThrow(); assertTrue(profile.enabled()); @@ -163,7 +163,7 @@ public class CarveSettingsDecodingTest { ], "carvingEnabled": false} """); - ModuleSettings settings = decoder.decode(Target.DIMENSION, json, "dimension test"); + ModuleSettings settings = decoder.decode(Level.DIMENSION, json, "dimension test"); List bands = settings.find(CarvingSettings.class).orElseThrow().entries(); assertEquals(3, bands.size()); @@ -183,7 +183,7 @@ public class CarveSettingsDecodingTest { @Test public void carvingBiomeIsABiomeKeyAndRegistersItWithTheBiomeTree() { - ModuleSettings settings = decoder.decode(Target.BIOME, new JSONObject("{\"carvingBiome\": \"carving/mushroom\"}"), "biome test"); + ModuleSettings settings = decoder.decode(Level.BIOME, new JSONObject("{\"carvingBiome\": \"carving/mushroom\"}"), "biome test"); assertEquals("carving/mushroom", settings.find(CarvingBiomeSettings.class).orElseThrow().biome()); assertEquals(Set.of("carving/mushroom"), settings.treeBiomes()); @@ -192,11 +192,11 @@ public class CarveSettingsDecodingTest { @Test public void theOverworldReadsItsUpperDimensionCarvingAndANumberIsTheCaveLavaHeight() throws IOException { - ModuleSettings overworld = decoder.decode(Target.DIMENSION, file("dimensions/overworld.json"), "dimension overworld"); + ModuleSettings overworld = decoder.decode(Level.DIMENSION, file("dimensions/overworld.json"), "dimension overworld"); assertFalse(overworld.find(UpperDimensionCarvingSettings.class).orElseThrow().enabled()); assertTrue("the overworld writes no cave lava height", overworld.find(CaveLavaHeightSettings.class).isEmpty()); - ModuleSettings written = decoder.decode(Target.DIMENSION, new JSONObject("{\"caveLavaHeight\": 18, \"upperDimensionCarving\": true}"), "dimension test"); + ModuleSettings written = decoder.decode(Level.DIMENSION, new JSONObject("{\"caveLavaHeight\": 18, \"upperDimensionCarving\": true}"), "dimension test"); assertEquals(18, written.find(CaveLavaHeightSettings.class).orElseThrow().height()); assertTrue(written.find(UpperDimensionCarvingSettings.class).orElseThrow().enabled()); assertEquals(8, CaveLavaHeightSettings.DEFAULT_HEIGHT); @@ -204,12 +204,12 @@ public class CarveSettingsDecodingTest { @Test public void everyKeyIsOnlyReadAtTheLevelsTheOldFieldExistedAt() { - assertTrue(decoder.keys(Target.DIMENSION).containsAll(List.of("caveProfile", "carving", "carvingEnabled", "caveLavaHeight", "upperDimensionCarving"))); - assertTrue(decoder.keys(Target.REGION).contains("caveProfile")); - assertTrue(decoder.keys(Target.BIOME).containsAll(List.of("caveProfile", "carvingBiome", "caveMinDepthBelowSurface"))); - assertFalse(decoder.keys(Target.REGION).contains("carving")); - assertFalse(decoder.keys(Target.DIMENSION).contains("carvingBiome")); - assertFalse(decoder.keys(Target.DIMENSION).contains("caveMinDepthBelowSurface")); + assertTrue(decoder.keys(Level.DIMENSION).containsAll(List.of("caveProfile", "carving", "carvingEnabled", "caveLavaHeight", "upperDimensionCarving"))); + assertTrue(decoder.keys(Level.REGION).contains("caveProfile")); + assertTrue(decoder.keys(Level.BIOME).containsAll(List.of("caveProfile", "carvingBiome", "caveMinDepthBelowSurface"))); + assertFalse(decoder.keys(Level.REGION).contains("carving")); + assertFalse(decoder.keys(Level.DIMENSION).contains("carvingBiome")); + assertFalse(decoder.keys(Level.DIMENSION).contains("caveMinDepthBelowSurface")); } private JSONObject file(String name) throws IOException { diff --git a/core/src/test/java/art/arcane/iris/core/modules/CarveTestWorld.java b/core/src/test/java/art/arcane/iris/core/modules/CarveTestWorld.java index 732f0990a..f8b6130ee 100644 --- a/core/src/test/java/art/arcane/iris/core/modules/CarveTestWorld.java +++ b/core/src/test/java/art/arcane/iris/core/modules/CarveTestWorld.java @@ -22,7 +22,8 @@ import art.arcane.iris.builtin.IrisSeed; import art.arcane.iris.core.loader.IrisData; import art.arcane.iris.core.loader.ResourceLoader; import art.arcane.iris.engine.object.material.IrisBlockData; -import com.volmit.FeatureAttachment.Target; +import com.volmit.config.Level; +import com.volmit.config.SettingsStack; import com.volmit.IrisFeature; import com.volmit.ModuleLog; import com.volmit.block.BlockFace; @@ -76,14 +77,14 @@ public final class CarveTestWorld implements PackWorld, IrisSeed.Source { private final Resources resources = new Resources(); private long carveSeed = 1337L; - public CarveTestWorld declare(Target level, String key, IrisFeature value) { + public CarveTestWorld declare(Level level, String key, IrisFeature value) { String kind = level.name().toLowerCase(); declared.add(new Entry<>(level, new ResourceId(NAMESPACE, kind + "/" + key), value)); return this; } public CarveTestWorld dimension(IrisFeature value) { - return declare(Target.DIMENSION, "overworld", value); + return declare(Level.DIMENSION, "overworld", value); } public CarveTestWorld biome(String key, int rarity) { @@ -121,8 +122,8 @@ public final class CarveTestWorld implements PackWorld, IrisSeed.Source { return new PackSettings() { @Override @SuppressWarnings("unchecked") - public List> declared(Class featureType) { - return declared.stream().filter(entry -> featureType.isInstance(entry.value())).map(entry -> (Entry) entry).toList(); + public SettingsStack declared(Class featureType) { + return SettingsStack.of(declared.stream().filter(entry -> featureType.isInstance(entry.value())).map(entry -> (Entry) entry).toList()); } }; } diff --git a/core/src/test/java/art/arcane/iris/core/modules/ChunkModuleSettingsTest.java b/core/src/test/java/art/arcane/iris/core/modules/ChunkModuleSettingsTest.java new file mode 100644 index 000000000..55b0161c8 --- /dev/null +++ b/core/src/test/java/art/arcane/iris/core/modules/ChunkModuleSettingsTest.java @@ -0,0 +1,139 @@ +/* + * Iris is a World Generator for Minecraft Servers + * Copyright (c) 2026 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package art.arcane.iris.core.modules; + +import art.arcane.iris.core.loader.IrisRegistrant; +import art.arcane.iris.engine.object.world.biome.IrisBiome; +import art.arcane.iris.engine.object.world.dimension.IrisDimension; +import art.arcane.iris.engine.object.world.region.IrisRegion; +import com.volmit.IrisFeature; +import com.volmit.config.Feature; +import com.volmit.config.FeatureSettings; +import com.volmit.config.Level; +import com.volmit.config.SettingsStack; +import com.volmit.resource.ResourceId; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; + +/** Iris answers a chunk's settings from its distinct regions and biomes, and keeps a column's stack per pack snapshot. */ +public class ChunkModuleSettingsTest { + private static final int CHUNK_X = 3; + private static final int CHUNK_Z = -2; + private static final int CHUNK_MIDDLE = 8; + + @Rule + public TemporaryFolder folder = new TemporaryFolder(); + + @Feature(id = "test:stacked", name = "Stacked", key = "stacked", targets = {Level.DIMENSION, Level.REGION, Level.BIOME}) + static final class StackedSettings implements IrisFeature { + } + + private final SettingsStacks snapshotStacks = new SettingsStacks(); + private PackResourceIds ids; + private IrisDimension dimension; + private IrisRegion westRegion; + private IrisRegion eastRegion; + private IrisBiome northBiome; + private IrisBiome southBiome; + + @Before + public void createLevels() { + ids = new PackResourceIds(folder.getRoot()); + dimension = configured(new IrisDimension(), "overworld"); + westRegion = configured(new IrisRegion(), "west"); + eastRegion = configured(new IrisRegion(), "east"); + northBiome = configured(new IrisBiome(), "north"); + southBiome = new IrisBiome(); + southBiome.setLoadKey("south"); + } + + @Test + public void aChunksSettingsAreTheDimensionThenItsRegionsThenItsBiomesEachOnceInTheOrderTheScanMeetsThem() { + SettingsStack declared = settings().declaredInChunk(StackedSettings.class, CHUNK_X, CHUNK_Z); + + assertEquals(List.of(Level.DIMENSION, Level.REGION, Level.REGION, Level.BIOME), + declared.entries().stream().map(FeatureSettings.Entry::level).toList()); + assertEquals(List.of(ids.of("dimension", "overworld"), ids.of("region", "west"), ids.of("region", "east"), ids.of("biome", "north")), + declared.entries().stream().map(FeatureSettings.Entry::source).toList()); + } + + @Test + public void aChunksSettingsMatchTheColumnByColumnScanOfTheApi() { + ChunkModuleSettings settings = settings(); + FeatureSettings columnByColumn = settings::at; + + assertEquals(columnByColumn.declaredInChunk(StackedSettings.class, CHUNK_X, CHUNK_Z).entries(), + settings.declaredInChunk(StackedSettings.class, CHUNK_X, CHUNK_Z).entries()); + } + + @Test + public void aColumnWhoseLevelsWereSeenBeforeGetsTheSameStackInAnyChunkOfTheSnapshot() { + int worldX = CHUNK_X * 16; + int worldZ = CHUNK_Z * 16; + SettingsStack first = settings().at(StackedSettings.class, worldX, worldZ); + + assertSame(first, settings().at(StackedSettings.class, worldX + 1, worldZ + 1)); + } + + private ChunkModuleSettings settings() { + return new ChunkModuleSettings(new SplitLevels(), ids); + } + + private static T configured(T owner, String key) { + owner.setLoadKey(key); + owner.setModuleSettings(ModuleSettings.of(Map.of(StackedSettings.class, new StackedSettings()))); + return owner; + } + + /** One region west of each chunk's middle and one east of it; a configured biome north of the middle, a bare one south. */ + private final class SplitLevels implements ChunkModuleSettings.Levels { + @Override + public IrisRegistrant dimension() { + return dimension; + } + + @Override + public IrisRegistrant region(int worldX, int worldZ) { + return Math.floorMod(worldX, 16) < CHUNK_MIDDLE ? westRegion : eastRegion; + } + + @Override + public IrisRegistrant surfaceBiome(int worldX, int worldZ) { + return Math.floorMod(worldZ, 16) < CHUNK_MIDDLE ? northBiome : southBiome; + } + + @Override + public IrisBiome biome(ResourceId id) { + return null; + } + + @Override + public SettingsStacks stacks() { + return snapshotStacks; + } + } +} diff --git a/core/src/test/java/art/arcane/iris/core/modules/ChunkSettingsScanTimingTest.java b/core/src/test/java/art/arcane/iris/core/modules/ChunkSettingsScanTimingTest.java index 68a54b3a0..989dbe3f4 100644 --- a/core/src/test/java/art/arcane/iris/core/modules/ChunkSettingsScanTimingTest.java +++ b/core/src/test/java/art/arcane/iris/core/modules/ChunkSettingsScanTimingTest.java @@ -22,7 +22,7 @@ import art.arcane.iris.engine.framework.Engine; import art.arcane.iris.engine.object.world.biome.IrisBiome; import art.arcane.iris.engine.object.world.dimension.IrisDimension; import art.arcane.iris.engine.object.world.region.IrisRegion; -import com.volmit.FeatureAttachment.Target; +import com.volmit.config.Level; import com.volmit.IrisFeature; import com.volmit.IrisModule; import com.volmit.ModuleInfo; @@ -35,7 +35,6 @@ import com.volmit.host.MantleRunner; import com.volmit.host.ModuleHost; import com.volmit.host.StageTimings; import com.volmit.mantle.Mantle; -import com.volmit.resource.PackResources; import com.volmit.stage.MantleStage; import com.volmit.stage.Stage; import com.volmit.world.PackWorld; @@ -71,7 +70,7 @@ public class ChunkSettingsScanTimingTest { @Rule public TemporaryFolder folder = new TemporaryFolder(); - @Feature(id = "test:scan", name = "Scan", key = "scan", targets = {Target.DIMENSION, Target.REGION, Target.BIOME}) + @Feature(id = "test:scan", name = "Scan", key = "scan", targets = {Level.DIMENSION, Level.REGION, Level.BIOME}) static final class ScanSettings implements IrisFeature { } @@ -131,11 +130,9 @@ public class ChunkSettingsScanTimingTest { return new MantleGenerationContext() { public int originX() { return originX; } public int originZ() { return 0; } - public long worldSeed() { return 0L; } public TerrainSampler terrain() { throw new UnsupportedOperationException(); } public FeatureSettings settings() { return settings; } public Mantle mantle() { throw new UnsupportedOperationException(); } - public PackResources resources() { throw new UnsupportedOperationException(); } public PackWorld world() { throw new UnsupportedOperationException(); } }; } diff --git a/core/src/test/java/art/arcane/iris/core/modules/DecorantSettingsDecodingTest.java b/core/src/test/java/art/arcane/iris/core/modules/DecorantSettingsDecodingTest.java index c19695601..675d2e5f7 100644 --- a/core/src/test/java/art/arcane/iris/core/modules/DecorantSettingsDecodingTest.java +++ b/core/src/test/java/art/arcane/iris/core/modules/DecorantSettingsDecodingTest.java @@ -5,7 +5,7 @@ import art.arcane.iris.builtin.decorant.DecorationPart; import art.arcane.iris.builtin.decorant.Decorator; import art.arcane.volmlib.util.json.JSONObject; import com.google.gson.Gson; -import com.volmit.FeatureAttachment.Target; +import com.volmit.config.Level; import com.volmit.block.BlockSpec; import com.volmit.host.LoadedPack; import com.volmit.host.ModuleHost; @@ -136,23 +136,23 @@ public class DecorantSettingsDecodingTest { public void theFeatureIdIsNotAKey() { JSONObject byId = new JSONObject("{\"iris:decorant\": [{\"chance\": 1}]}"); - assertSame(ModuleSettings.NONE, decoder.decode(Target.BIOME, byId, "biome meadow")); - assertTrue(decoder.keys(Target.BIOME).containsAll(Set.of("decorators", "deposits"))); - assertFalse(decoder.keys(Target.BIOME).contains("iris:decorant")); + assertSame(ModuleSettings.NONE, decoder.decode(Level.BIOME, byId, "biome meadow")); + assertTrue(decoder.keys(Level.BIOME).containsAll(Set.of("decorators", "deposits"))); + assertFalse(decoder.keys(Level.BIOME).contains("iris:decorant")); } @Test public void anObjectOfOptionsUnderDecoratorsIsRefused() { JSONObject object = new JSONObject("{\"decorators\": {\"decorators\": [{\"chance\": 1}]}}"); - IllegalArgumentException refused = assertThrows(IllegalArgumentException.class, () -> decoder.decode(Target.BIOME, object, "biome meadow")); + IllegalArgumentException refused = assertThrows(IllegalArgumentException.class, () -> decoder.decode(Level.BIOME, object, "biome meadow")); assertEquals("Cannot read settings iris:decorant under \"decorators\" in biome meadow: write a list, [...], of the decorators," + " not an object of options", refused.getMessage()); } private List decorators(String biomeJson) { - return decoder.decode(Target.BIOME, new JSONObject(biomeJson), "biome meadow") + return decoder.decode(Level.BIOME, new JSONObject(biomeJson), "biome meadow") .find(DecorantSettings.class).orElseThrow().decorators(); } } diff --git a/core/src/test/java/art/arcane/iris/core/modules/DepositSettingsDecodingTest.java b/core/src/test/java/art/arcane/iris/core/modules/DepositSettingsDecodingTest.java index 652707526..c7f441d2c 100644 --- a/core/src/test/java/art/arcane/iris/core/modules/DepositSettingsDecodingTest.java +++ b/core/src/test/java/art/arcane/iris/core/modules/DepositSettingsDecodingTest.java @@ -8,7 +8,7 @@ import art.arcane.iris.builtin.deposit.DepositSettings; import art.arcane.iris.builtin.deposit.DepositShape; import art.arcane.volmlib.util.json.JSONObject; import com.google.gson.Gson; -import com.volmit.FeatureAttachment.Target; +import com.volmit.config.Level; import com.volmit.block.BlockSpec; import com.volmit.host.LoadedPack; import com.volmit.host.ModuleHost; @@ -146,16 +146,16 @@ public class DepositSettingsDecodingTest { public void theFeatureIdIsNotAKey() { JSONObject byId = new JSONObject("{\"iris:deposit\": [{\"maxHeight\": 16}]}"); - assertSame(ModuleSettings.NONE, decoder.decode(Target.REGION, byId, "region forests")); - assertTrue(decoder.keys(Target.REGION).contains("deposits")); - assertFalse(decoder.keys(Target.REGION).contains("iris:deposit")); + assertSame(ModuleSettings.NONE, decoder.decode(Level.REGION, byId, "region forests")); + assertTrue(decoder.keys(Level.REGION).contains("deposits")); + assertFalse(decoder.keys(Level.REGION).contains("iris:deposit")); } @Test public void anObjectOfOptionsUnderDepositsIsRefused() { JSONObject object = new JSONObject("{\"deposits\": {\"generators\": [{\"maxHeight\": 16}]}}"); - IllegalArgumentException refused = assertThrows(IllegalArgumentException.class, () -> decoder.decode(Target.REGION, object, "region forests")); + IllegalArgumentException refused = assertThrows(IllegalArgumentException.class, () -> decoder.decode(Level.REGION, object, "region forests")); assertEquals("Cannot read settings iris:deposit under \"deposits\" in region forests: write a list, [...], of the generators," + " not an object of options", refused.getMessage()); @@ -165,7 +165,7 @@ public class DepositSettingsDecodingTest { public void nullUnderDepositsIsRefused() { JSONObject nothing = new JSONObject("{\"deposits\": null}"); - IllegalArgumentException refused = assertThrows(IllegalArgumentException.class, () -> decoder.decode(Target.REGION, nothing, "region forests")); + IllegalArgumentException refused = assertThrows(IllegalArgumentException.class, () -> decoder.decode(Level.REGION, nothing, "region forests")); assertTrue(refused.getMessage(), refused.getMessage().contains("under \"deposits\" in region forests: the value is null; write a list")); } @@ -174,13 +174,13 @@ public class DepositSettingsDecodingTest { public void aWronglyShapedGeneratorNamesTheKeyAndTheFile() { JSONObject broken = new JSONObject("{\"deposits\": [{\"maxHeight\": \"tall\"}]}"); - IllegalArgumentException refused = assertThrows(IllegalArgumentException.class, () -> decoder.decode(Target.REGION, broken, "region forests")); + IllegalArgumentException refused = assertThrows(IllegalArgumentException.class, () -> decoder.decode(Level.REGION, broken, "region forests")); assertTrue(refused.getMessage(), refused.getMessage().startsWith("Cannot read settings iris:deposit under \"deposits\" in region forests: ")); } private List deposits(String regionJson) { - return decoder.decode(Target.REGION, new JSONObject(regionJson), "region forests") + return decoder.decode(Level.REGION, new JSONObject(regionJson), "region forests") .find(DepositSettings.class).orElseThrow().generators(); } } diff --git a/core/src/test/java/art/arcane/iris/core/modules/DimensionBottomTest.java b/core/src/test/java/art/arcane/iris/core/modules/DimensionBottomTest.java index cfac4a43c..d6f1b711e 100644 --- a/core/src/test/java/art/arcane/iris/core/modules/DimensionBottomTest.java +++ b/core/src/test/java/art/arcane/iris/core/modules/DimensionBottomTest.java @@ -158,6 +158,8 @@ public class DimensionBottomTest { when(moduleSet.pack()).thenReturn(pack); when(data.getModules()).thenReturn(moduleSet); when(data.getDataFolder()).thenReturn(folder.getRoot()); + IrisPackResources resources = new IrisPackResources(data, List::of); + when(data.getPackResources()).thenReturn(resources); when(data.getEngine()).thenReturn(engine); storage.bindTo(engine); } diff --git a/core/src/test/java/art/arcane/iris/core/modules/FloatingSettingsDecodingTest.java b/core/src/test/java/art/arcane/iris/core/modules/FloatingSettingsDecodingTest.java index 39e1f4fb9..c3f27d9ef 100644 --- a/core/src/test/java/art/arcane/iris/core/modules/FloatingSettingsDecodingTest.java +++ b/core/src/test/java/art/arcane/iris/core/modules/FloatingSettingsDecodingTest.java @@ -27,7 +27,7 @@ import art.arcane.iris.builtin.floating.MergeFloatingChildrenSettings; import art.arcane.iris.builtin.floating.TopShapeMode; import art.arcane.volmlib.util.json.JSONObject; import com.google.gson.Gson; -import com.volmit.FeatureAttachment.Target; +import com.volmit.config.Level; import com.volmit.host.LoadedPack; import com.volmit.host.ModuleHost; import org.junit.After; @@ -81,7 +81,7 @@ public class FloatingSettingsDecodingTest { public void aBiomeReadsItsFloatingChildrenAndTheMergeFlag() throws IOException { JSONObject biome = file("biomes/magnetics/plains.json"); - ModuleSettings settings = decoder.decode(Target.BIOME, biome, "biome magnetics/plains"); + ModuleSettings settings = decoder.decode(Level.BIOME, biome, "biome magnetics/plains"); List children = settings.find(FloatingChildSettings.class).orElseThrow().children(); assertEquals(biome.getJSONArray("floatingChildBiomes").length(), children.size()); @@ -106,19 +106,19 @@ public class FloatingSettingsDecodingTest { @Test public void aBiomeWithoutFloatingChildrenDeclaresNone() { - ModuleSettings settings = decoder.decode(Target.BIOME, new JSONObject("{\"mergeFloatingChildBiomes\": false, \"floatingChildBiomes\": [{}]}"), "biome test"); + ModuleSettings settings = decoder.decode(Level.BIOME, new JSONObject("{\"mergeFloatingChildBiomes\": false, \"floatingChildBiomes\": [{}]}"), "biome test"); assertFalse(settings.find(MergeFloatingChildrenSettings.class).orElseThrow().merge()); assertEquals(1, settings.find(FloatingChildSettings.class).orElseThrow().children().size()); assertEquals("an empty child keeps Iris's defaults", 160, settings.find(FloatingChildSettings.class).orElseThrow().children().getFirst().minHeightAboveSurface()); - assertTrue(decoder.decode(Target.BIOME, new JSONObject("{}"), "biome test").isEmpty()); + assertTrue(decoder.decode(Level.BIOME, new JSONObject("{}"), "biome test").isEmpty()); } @Test public void theTargetAndTheCarvingOfEveryChildAreBiomesTheDimensionUses() throws IOException { JSONObject biome = file("biomes/magnetics/plains.json"); - ModuleSettings biomeSettings = decoder.decode(Target.BIOME, biome, "biome magnetics/plains"); - ModuleSettings dimensionSettings = decoder.decode(Target.DIMENSION, file("dimensions/overworld.json"), "dimension overworld"); + ModuleSettings biomeSettings = decoder.decode(Level.BIOME, biome, "biome magnetics/plains"); + ModuleSettings dimensionSettings = decoder.decode(Level.DIMENSION, file("dimensions/overworld.json"), "dimension overworld"); Set used = biomeSettings.usedBiomes(dimensionSettings); @@ -140,9 +140,9 @@ public class FloatingSettingsDecodingTest { @Test public void bothKeysAreOnlyReadAtBiomes() { - assertTrue(decoder.keys(Target.BIOME).containsAll(List.of("floatingChildBiomes", "mergeFloatingChildBiomes"))); - assertFalse(decoder.keys(Target.REGION).contains("floatingChildBiomes")); - assertFalse(decoder.keys(Target.DIMENSION).contains("mergeFloatingChildBiomes")); + assertTrue(decoder.keys(Level.BIOME).containsAll(List.of("floatingChildBiomes", "mergeFloatingChildBiomes"))); + assertFalse(decoder.keys(Level.REGION).contains("floatingChildBiomes")); + assertFalse(decoder.keys(Level.DIMENSION).contains("mergeFloatingChildBiomes")); } private JSONObject file(String name) throws IOException { diff --git a/core/src/test/java/art/arcane/iris/core/modules/IrisModuleMantleTest.java b/core/src/test/java/art/arcane/iris/core/modules/IrisModuleMantleTest.java index e47c268ed..54c8ae34e 100644 --- a/core/src/test/java/art/arcane/iris/core/modules/IrisModuleMantleTest.java +++ b/core/src/test/java/art/arcane/iris/core/modules/IrisModuleMantleTest.java @@ -288,6 +288,8 @@ public class IrisModuleMantleTest { SeedManager seeds = mock(SeedManager.class); when(engine.getData()).thenReturn(data); when(data.getDataFolder()).thenReturn(folder.getRoot()); + IrisPackResources resources = new IrisPackResources(data, List::of); + when(data.getPackResources()).thenReturn(resources); when(engine.getSeedManager()).thenReturn(seeds); when(engine.getDimension()).thenReturn(new IrisDimension()); when(engine.getRegion(anyInt(), anyInt())).thenReturn(new IrisRegion()); @@ -306,37 +308,6 @@ public class IrisModuleMantleTest { assertTrue(chunks.containsKey(1L << 32)); } - @Test - public void aMantleStageFindsTheSnapshotsPackResources() throws IOException { - List found = new ArrayList<>(); - IrisModule finder = new IrisModule() { - public ModuleInfo info() { return ModuleInfo.of("iris:finder", "Finder", "1"); } - public void setup(ModuleSetup setup) { - setup.stages().define(Stage.mantle("iris:finder/oak")).reach(0).run(context -> - found.add(context.resources().find(PackResourceFixture.oakKey(folder.getRoot())).orElseThrow())); - } - }; - Engine engine = mock(Engine.class); - IrisData data = mock(IrisData.class); - SeedManager seeds = mock(SeedManager.class); - when(engine.getData()).thenReturn(data); - when(data.getDataFolder()).thenReturn(folder.getRoot()); - PackResourceFixture.serve(data); - when(engine.getSeedManager()).thenReturn(seeds); - when(engine.getDimension()).thenReturn(new IrisDimension()); - when(engine.getRegion(anyInt(), anyInt())).thenReturn(new IrisRegion()); - when(engine.getSurfaceBiome(anyInt(), anyInt())).thenReturn(new IrisBiome()); - when(engine.getMinHeight()).thenReturn(WORLD_MIN_HEIGHT); - when(engine.getHeight()).thenReturn(SECTIONS * 16); - - try (LoadedPack pack = LoadedPack.load(folder.newFolder("finder-pack").toPath(), - ModuleHost.of(List.of(finder)).copyingJarsTo(folder.newFolder("finder-copies").toPath()))) { - ModuleMantleComponent.forPack(engine, pack, Set.of()).getFirst().generate(0, 0, this::chunk); - } - - assertEquals(List.of(PackResourceFixture.OAK), found); - } - private static byte[] bytes(ModuleLayerValues values) throws IOException { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); values.write(new DataOutputStream(bytes)); diff --git a/core/src/test/java/art/arcane/iris/core/modules/LootAndSpawnPackDecodingTest.java b/core/src/test/java/art/arcane/iris/core/modules/LootAndSpawnPackDecodingTest.java index b3b10f41a..b4b423d9f 100644 --- a/core/src/test/java/art/arcane/iris/core/modules/LootAndSpawnPackDecodingTest.java +++ b/core/src/test/java/art/arcane/iris/core/modules/LootAndSpawnPackDecodingTest.java @@ -35,7 +35,7 @@ import art.arcane.iris.core.loader.IrisData; import art.arcane.iris.engine.loot.LootResources; import art.arcane.volmlib.util.json.JSONObject; import com.google.gson.Gson; -import com.volmit.FeatureAttachment.Target; +import com.volmit.config.Level; import com.volmit.block.BlockSpec; import com.volmit.host.LoadedPack; import com.volmit.host.ModuleHost; @@ -93,7 +93,7 @@ public class LootAndSpawnPackDecodingTest { @Test public void theDimensionReadsItsLootReference() throws IOException { - ModuleSettings settings = decoder.decode(Target.DIMENSION, file("dimensions/overworld.json"), "dimension overworld"); + ModuleSettings settings = decoder.decode(Level.DIMENSION, file("dimensions/overworld.json"), "dimension overworld"); LootSettings loot = settings.find(LootSettings.class).orElseThrow(); assertEquals(LootMode.FALLBACK, loot.mode()); @@ -105,7 +105,7 @@ public class LootAndSpawnPackDecodingTest { @Test public void aRegionReadsItsLootAndItsSpawners() throws IOException { - ModuleSettings settings = decoder.decode(Target.REGION, file("regions/terralost.json"), "region terralost"); + ModuleSettings settings = decoder.decode(Level.REGION, file("regions/terralost.json"), "region terralost"); LootSettings loot = settings.find(LootSettings.class).orElseThrow(); assertEquals(LootMode.FALLBACK, loot.mode()); @@ -117,7 +117,7 @@ public class LootAndSpawnPackDecodingTest { @Test public void aRegionReadsItsBlockDrops() throws IOException { - ModuleSettings settings = decoder.decode(Target.REGION, file("regions/swamp.json"), "region swamp"); + ModuleSettings settings = decoder.decode(Level.REGION, file("regions/swamp.json"), "region swamp"); List drops = settings.find(BlockDropSettings.class).orElseThrow().drops(); assertEquals(1, drops.size()); @@ -135,7 +135,7 @@ public class LootAndSpawnPackDecodingTest { public void aRegionReadsItsEffectsLootAndBlockDropsTogether() throws IOException { JSONObject region = file("regions/mushroom.json"); - ModuleSettings settings = decoder.decode(Target.REGION, region, "region mushroom"); + ModuleSettings settings = decoder.decode(Level.REGION, region, "region mushroom"); List effects = settings.find(EffectSettings.class).orElseThrow().effects(); assertEquals(region.getJSONArray("effects").length(), effects.size()); @@ -162,7 +162,7 @@ public class LootAndSpawnPackDecodingTest { @Test public void aRegionsPotionEffectKeepsItsStrengthAndTicks() throws IOException { - ModuleSettings settings = decoder.decode(Target.REGION, file("regions/hot.json"), "region hot"); + ModuleSettings settings = decoder.decode(Level.REGION, file("regions/hot.json"), "region hot"); AmbientEffect potion = settings.find(EffectSettings.class).orElseThrow().effects().getFirst(); assertEquals("CONFUSION", potion.potionEffect()); @@ -175,7 +175,7 @@ public class LootAndSpawnPackDecodingTest { @Test public void aBiomeReadsItsEffects() throws IOException { - ModuleSettings settings = decoder.decode(Target.BIOME, file("biomes/tropical/volcanoes.json"), "biome tropical/volcanoes"); + ModuleSettings settings = decoder.decode(Level.BIOME, file("biomes/tropical/volcanoes.json"), "biome tropical/volcanoes"); AmbientEffect smoke = settings.find(EffectSettings.class).orElseThrow().effects().getFirst(); assertEquals("CAMPFIRE_SIGNAL_SMOKE", smoke.particleEffect()); @@ -191,12 +191,12 @@ public class LootAndSpawnPackDecodingTest { public void aDimensionHasNoEffects() throws IOException { JSONObject dimension = new JSONObject("{\"effects\": [{\"chance\": 1}], \"loot\": {}}"); - ModuleSettings settings = decoder.decode(Target.DIMENSION, dimension, "dimension overworld"); + ModuleSettings settings = decoder.decode(Level.DIMENSION, dimension, "dimension overworld"); assertTrue(settings.find(EffectSettings.class).isEmpty()); - assertFalse(decoder.keys(Target.DIMENSION).contains("effects")); - assertTrue(decoder.keys(Target.REGION).contains("effects")); - assertTrue(decoder.keys(Target.BIOME).containsAll(Set.of("loot", "blockDrops", "entitySpawners", "effects"))); + assertFalse(decoder.keys(Level.DIMENSION).contains("effects")); + assertTrue(decoder.keys(Level.REGION).contains("effects")); + assertTrue(decoder.keys(Level.BIOME).containsAll(Set.of("loot", "blockDrops", "entitySpawners", "effects"))); } @Test @@ -241,15 +241,15 @@ public class LootAndSpawnPackDecodingTest { public void theFeatureIdsAreNotKeys() { JSONObject byId = new JSONObject("{\"iris:loot\": {\"tables\": [\"a\"]}, \"iris:spawn\": [\"a\"]}"); - assertSame(ModuleSettings.NONE, decoder.decode(Target.REGION, byId, "region forests")); + assertSame(ModuleSettings.NONE, decoder.decode(Level.REGION, byId, "region forests")); } @Test public void aWrongShapeNamesTheKeyAndTheFile() { IllegalArgumentException list = assertThrows(IllegalArgumentException.class, - () -> decoder.decode(Target.REGION, new JSONObject("{\"entitySpawners\": {\"spawners\": [\"a\"]}}"), "region forests")); + () -> decoder.decode(Level.REGION, new JSONObject("{\"entitySpawners\": {\"spawners\": [\"a\"]}}"), "region forests")); IllegalArgumentException object = assertThrows(IllegalArgumentException.class, - () -> decoder.decode(Target.REGION, new JSONObject("{\"loot\": [\"a\"]}"), "region forests")); + () -> decoder.decode(Level.REGION, new JSONObject("{\"loot\": [\"a\"]}"), "region forests")); assertTrue(list.getMessage(), list.getMessage().contains("under \"entitySpawners\" in region forests")); assertTrue(object.getMessage(), object.getMessage().contains("under \"loot\" in region forests")); @@ -259,9 +259,9 @@ public class LootAndSpawnPackDecodingTest { public void settingsEncodeBackToTheJsonThePackWrote() throws IOException { for (String file : List.of("regions/terralost.json", "regions/swamp.json", "regions/mushroom.json", "regions/hot.json")) { JSONObject region = this.file(file); - ModuleSettings settings = decoder.decode(Target.REGION, region, "region " + file); + ModuleSettings settings = decoder.decode(Level.REGION, region, "region " + file); - JSONObject written = decoder.encode(Target.REGION, settings); + JSONObject written = decoder.encode(Level.REGION, settings); for (String key : List.of("loot", "blockDrops", "entitySpawners", "effects")) { assertEquals(file + " " + key, region.has(key), written.has(key)); diff --git a/core/src/test/java/art/arcane/iris/core/modules/ModuleChunkGenerationTest.java b/core/src/test/java/art/arcane/iris/core/modules/ModuleChunkGenerationTest.java index 0df2dd21b..9b373e2b7 100644 --- a/core/src/test/java/art/arcane/iris/core/modules/ModuleChunkGenerationTest.java +++ b/core/src/test/java/art/arcane/iris/core/modules/ModuleChunkGenerationTest.java @@ -26,7 +26,7 @@ import art.arcane.iris.engine.object.world.dimension.IrisDimension; import art.arcane.iris.engine.object.world.region.IrisRegion; import art.arcane.iris.spi.PlatformBlockState; import art.arcane.iris.util.project.hunk.Hunk; -import com.volmit.FeatureAttachment.Target; +import com.volmit.config.Level; import com.volmit.IrisFeature; import com.volmit.IrisModule; import com.volmit.ModuleInfo; @@ -65,7 +65,7 @@ public class ModuleChunkGenerationTest { private Engine engine; private Hunk blocks; - @Feature(id = "iris:pillar", name = "Pillar", key = "pillar", targets = {Target.BIOME, Target.REGION, Target.DIMENSION}) + @Feature(id = "iris:pillar", name = "Pillar", key = "pillar", targets = {Level.BIOME, Level.REGION, Level.DIMENSION}) public static final class PillarSettings implements IrisFeature { private BlockState block = BlockState.parse("minecraft:stone"); private int x; @@ -81,7 +81,7 @@ public class ModuleChunkGenerationTest { @Override public void setup(ModuleSetup setup) { setup.stages().define(Stage.chunk("iris:pillar/raise")).when(PillarSettings.class).run(context -> { - PillarSettings pillar = context.configured(PillarSettings.class).getLast().value(); + PillarSettings pillar = context.configured(PillarSettings.class).mostSpecific().orElseThrow(); com.volmit.hunk.Hunk chunk = context.hunk(BlockState.class); chunk.set(0, 1, 0, chunk.get(0, 0, 0)); chunk.set(pillar.x, 2, 0, pillar.block); @@ -98,6 +98,8 @@ public class ModuleChunkGenerationTest { SeedManager seeds = mock(SeedManager.class); when(engine.getData()).thenReturn(data); when(data.getDataFolder()).thenReturn(folder.getRoot()); + IrisPackResources resources = new IrisPackResources(data, List::of); + when(data.getPackResources()).thenReturn(resources); when(engine.getSeedManager()).thenReturn(seeds); when(seeds.getSeed()).thenReturn(1L); when(engine.getDimension()).thenReturn(new IrisDimension()); @@ -195,28 +197,4 @@ public class ModuleChunkGenerationTest { when(state.key()).thenReturn(key); return state; } - - @Test - public void aChunkStageFindsTheSnapshotsPackResources() throws IOException { - IrisData data = engine.getData(); - PackResourceFixture.serve(data); - List found = new ArrayList<>(); - IrisModule finder = new IrisModule() { - public ModuleInfo info() { return ModuleInfo.of("test:finder", "Finder", "1"); } - public void setup(ModuleSetup setup) { - setup.stages().define(Stage.chunk("test:finder/oak")).run(context -> - found.add(context.resources().find(PackResourceFixture.oakKey(folder.getRoot())).orElseThrow())); - } - }; - - try (LoadedPack finderPack = LoadedPack.load(folder.newFolder("finder-pack").toPath(), - ModuleHost.of(List.of(finder)).copyingJarsTo(folder.newFolder("finder-copies").toPath()))) { - when(engine.getRegion(anyInt(), anyInt())).thenReturn(new IrisRegion()); - when(engine.getSurfaceBiome(anyInt(), anyInt())).thenReturn(new IrisBiome()); - - ModuleChunkGeneration.generate(finderPack, engine, 0, 0, blocks, null, false, null, ModuleChunkGenerationTest::platformState); - } - - assertEquals(List.of(PackResourceFixture.OAK), found); - } } diff --git a/core/src/test/java/art/arcane/iris/core/modules/ModuleSettingsDecoderTest.java b/core/src/test/java/art/arcane/iris/core/modules/ModuleSettingsDecoderTest.java index 6d6da360b..2422d4e24 100644 --- a/core/src/test/java/art/arcane/iris/core/modules/ModuleSettingsDecoderTest.java +++ b/core/src/test/java/art/arcane/iris/core/modules/ModuleSettingsDecoderTest.java @@ -25,7 +25,7 @@ import com.google.gson.GsonBuilder; import com.google.gson.TypeAdapter; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; -import com.volmit.FeatureAttachment.Target; +import com.volmit.config.Level; import com.volmit.IrisFeature; import com.volmit.IrisModule; import com.volmit.ModuleInfo; @@ -69,7 +69,7 @@ public class ModuleSettingsDecoderTest { private LoadedPack pack; private ModuleSettingsDecoder decoder; - @Feature(id = "iris:moss", name = "Moss", key = "moss", targets = {Target.BIOME, Target.REGION}) + @Feature(id = "iris:moss", name = "Moss", key = "moss", targets = {Level.BIOME, Level.REGION}) public static final class MossSettings implements IrisFeature { private int radius = 3; private BlockState block = new BlockState("minecraft:moss_block"); @@ -82,17 +82,17 @@ public class ModuleSettingsDecoderTest { private int size = 1; } - @Feature(id = "iris:moss/cover", name = "Cover", key = "mossCover", targets = Target.BIOME) + @Feature(id = "iris:moss/cover", name = "Cover", key = "mossCover", targets = Level.BIOME) public static final class CoverSettings implements IrisFeature { private double amount = 1; } - @Feature(id = "iris:moss/marks", name = "Marks", key = "mossMarks", targets = Target.BIOME) + @Feature(id = "iris:moss/marks", name = "Marks", key = "mossMarks", targets = Level.BIOME) public static final class MarksSettings implements IrisFeature { private List marks = List.of(); } - @Feature(id = "iris:moss/values", name = "Values", key = "mossValues", targets = Target.BIOME) + @Feature(id = "iris:moss/values", name = "Values", key = "mossValues", targets = Level.BIOME) public static final class ValuesSettings implements IrisFeature { private List palette = List.of(); private NoiseStyle style = NoiseStyle.of("SIMPLEX"); @@ -133,7 +133,7 @@ public class ModuleSettingsDecoderTest { } private MossSettings moss(String json) { - return decoder.decode(Target.BIOME, new JSONObject(json), "biome desert/dunes").find(MossSettings.class).orElseThrow(); + return decoder.decode(Level.BIOME, new JSONObject(json), "biome desert/dunes").find(MossSettings.class).orElseThrow(); } @Test @@ -151,13 +151,13 @@ public class ModuleSettingsDecoderTest { @Test public void declaresNothingWhereNoKeyIsPresent() { - assertSame(ModuleSettings.NONE, decoder.decode(Target.BIOME, new JSONObject("{\"name\": \"Dunes\"}"), "biome desert/dunes")); - assertSame(ModuleSettings.NONE, decoder.decode(Target.DIMENSION, new JSONObject("{\"moss\": {}}"), "dimension overworld")); + assertSame(ModuleSettings.NONE, decoder.decode(Level.BIOME, new JSONObject("{\"name\": \"Dunes\"}"), "biome desert/dunes")); + assertSame(ModuleSettings.NONE, decoder.decode(Level.DIMENSION, new JSONObject("{\"moss\": {}}"), "dimension overworld")); } @Test public void theFeatureIdIsNotAKeyOfTheSettings() { - assertSame(ModuleSettings.NONE, decoder.decode(Target.BIOME, new JSONObject("{\"iris:moss\": {\"radius\": 7}}"), "biome desert/dunes")); + assertSame(ModuleSettings.NONE, decoder.decode(Level.BIOME, new JSONObject("{\"iris:moss\": {\"radius\": 7}}"), "biome desert/dunes")); } @Test @@ -184,7 +184,7 @@ public class ModuleSettingsDecoderTest { public void apiValueTypesReadTheJsonIrisClassesRead() throws IOException { Path styles = Files.createDirectories(packFolder.resolve("snippet/style")); Files.writeString(styles.resolve("deepslate.json"), "{\"style\": \"STATIC\"}"); - ValuesSettings values = decoder.decode(Target.BIOME, new JSONObject(""" + ValuesSettings values = decoder.decode(Level.BIOME, new JSONObject(""" {"mossValues": { "palette": [{"block": "minecraft:oak_log", "data": {"axis": "y", "waterlogged": true, "level": 3}, "weight": 2, "backup": {"block": "stone"}, "tileData": {"Delay": 20, "SpawnData": {"entity": {"id": "zombie"}}}}, @@ -226,18 +226,18 @@ public class ModuleSettingsDecoderTest { @Test public void listsTheKeysModulesReadPerTarget() { - assertEquals(Set.of("moss", "mossCover", "mossMarks", "mossValues"), decoder.keys(Target.BIOME)); - assertEquals(Set.of(), decoder.keys(Target.DIMENSION)); + assertEquals(Set.of("moss", "mossCover", "mossMarks", "mossValues"), decoder.keys(Level.BIOME)); + assertEquals(Set.of(), decoder.keys(Level.DIMENSION)); } @Test public void settingsAreAlwaysAnObjectEvenWithOneOption() { - assertEquals(0.25, decoder.decode(Target.BIOME, new JSONObject("{\"mossCover\": {\"amount\": 0.25}}"), "biome desert/dunes") + assertEquals(0.25, decoder.decode(Level.BIOME, new JSONObject("{\"mossCover\": {\"amount\": 0.25}}"), "biome desert/dunes") .find(CoverSettings.class).orElseThrow().amount, 0); for (String bare : List.of("0.5", "[1, 2]", "true")) { IllegalArgumentException refused = assertThrows(IllegalArgumentException.class, - () -> decoder.decode(Target.BIOME, new JSONObject("{\"mossCover\": " + bare + "}"), "biome desert/dunes")); + () -> decoder.decode(Level.BIOME, new JSONObject("{\"mossCover\": " + bare + "}"), "biome desert/dunes")); assertEquals("Cannot read settings iris:moss/cover under \"mossCover\" in biome desert/dunes: write the settings as an object," + " {\"