Host the batch 2 IrisApi: settings stacks, tool world, chunk scan

- ChunkModuleSettings returns SettingsStacks and keeps them per pack
  snapshot (SettingsStacks), so at() allocates nothing for a column
  whose region and biome were seen before.
- declaredInChunk is answered from the chunk's distinct regions and
  biomes, each asked for its settings once.
- A studio paste runs in a ToolWorld with the pack's resources and
  settings and its own state, so world() always answers.
- Level replaces FeatureAttachment.Target across decoding, schema and
  packaging; IrisTerrainSampler gives surfaceHeight.
- Tests: chunk scan parity and order, the stack cache, the tool world;
  engine mocks now serve pack resources as real engines do.
This commit is contained in:
piexel committed 2026-10-23 14:17:26 +02:00
1 parent 466d5149db
commit 7fc4445ab7
64 files changed
+844 -448

No files matched your search

@@ -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<T extends IrisRegistrant> implements MeteredCache {
PrecisionStopwatch p = PrecisionStopwatch.start();
rawText = IO.readAll(j);
JSONObject parsed = new JSONObject(rawText);
Optional<Target> moduleTarget = ModuleTargets.ofResource(objectClass);
Optional<Level> 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<T extends IrisRegistrant> implements MeteredCache {
}
/** The keys the pack's modules read at {@code target}; none for resources that hold no module settings. */
private Set<String> moduleKeys(Optional<Target> target) {
private Set<String> moduleKeys(Optional<Level> 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);
}
@@ -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 <F extends IrisFeature> List<Entry<F>> at(Class<F> featureType, int worldX, int worldZ) {
List<Entry<F>> 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 <F extends IrisFeature> SettingsStack<F> at(Class<F> 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<F> known = snapshotStacks.find(dimensionSettings, regionSettings, biomeSettings, featureType);
if (known != null) {
return known;
}
SettingsStack<F> 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 <F extends IrisFeature> SettingsStack<F> declaredInChunk(Class<F> featureType, int chunkX, int chunkZ) {
List<IrisRegistrant> regions = new ArrayList<>();
List<IrisRegistrant> 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<Entry<F>> entries = new ArrayList<>();
Set<ResourceId> 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 <F extends IrisFeature> void addEntry(List<Entry<F>> entries, Class<F> featureType, Target level, String kind,
IrisRegistrant owner) {
private <F extends IrisFeature> SettingsStack<F> stackOf(Class<F> featureType, IrisRegistrant dimension, IrisRegistrant region,
IrisRegistrant biome) {
List<Entry<F>> entries = new ArrayList<>(Level.values().length);
Set<ResourceId> 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 <F extends IrisFeature> void addEntry(List<Entry<F>> entries, Set<ResourceId> sources, Class<F> 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<F> 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<IrisRegistrant> 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();
}
}
}
@@ -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 <F extends IrisFeature> List<Entry<F>> declared(Class<F> featureType) {
public <F extends IrisFeature> SettingsStack<F> declared(Class<F> featureType) {
return IrisPackSettings.declaredBy(dimension, () -> data, ids, featureType);
}
}
@@ -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<T>) 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
@@ -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
@@ -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 <F extends IrisFeature> List<Declaration<F>> declarations(Class<F> type) {
List<Declaration<F>> 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 <F extends IrisFeature> void addDeclaration(List<Declaration<F>> found, Target level, IrisRegistrant owner, Class<F> type) {
private static <F extends IrisFeature> void addDeclaration(List<Declaration<F>> found, Level level, IrisRegistrant owner, Class<F> type) {
if (owner == null) {
return;
}
@@ -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.
@@ -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 <F extends IrisFeature> List<Entry<F>> declared(Class<F> featureType) {
public <F extends IrisFeature> SettingsStack<F> declared(Class<F> 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 <F extends IrisFeature> List<Entry<F>> declaredBy(IrisDimension dimension, DataProvider data, PackResourceIds ids,
static <F extends IrisFeature> SettingsStack<F> declaredBy(IrisDimension dimension, DataProvider data, PackResourceIds ids,
Class<F> featureType) {
List<Entry<F>> 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 <F extends IrisFeature> void addEntry(List<Entry<F>> entries, Class<F> featureType, Target level, ResourceId source,
static <F extends IrisFeature> void addEntry(List<Entry<F>> entries, Class<F> featureType, Level level, ResourceId source,
IrisRegistrant owner) {
owner.getModuleSettings().find(featureType).ifPresent(value -> entries.add(new Entry<>(level, source, value)));
}
@@ -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<PackWorld> 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<PackWorld> 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<PackWorld> 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;
}
@@ -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);
@@ -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();
}
}
}
@@ -49,8 +49,8 @@ import java.util.function.BiConsumer;
* rejects the placement.
* <p>
* 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. */
@@ -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<Target, List<FeatureDescriptor<?>>> settings = new EnumMap<>(Target.class);
private final Map<Target, Set<String>> keys = new EnumMap<>(Target.class);
private final Map<Level, List<FeatureDescriptor<?>>> settings = new EnumMap<>(Level.class);
private final Map<Level, Set<String>> keys = new EnumMap<>(Level.class);
private final Path packFolder;
private final Gson gson;
private final Supplier<Gson> 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<String> keys(Target target) {
public Set<String> 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<Class<? extends IrisFeature>, 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<FeatureDescriptor<?>> settingsAt(FeatureCatalog catalog, Target target) {
private static List<FeatureDescriptor<?>> 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<String> keysAt(FeatureCatalog catalog, Target target) {
private static Set<String> keysAt(FeatureCatalog catalog, Level target) {
Stream<FeatureDescriptor<?>> objects = catalog.objects().stream().map(ObjectRegistration::descriptor);
Set<String> 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);
}
@@ -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<Target, Class<?>> HOLDERS = Map.of(
Target.DIMENSION, IrisDimension.class,
Target.REGION, IrisRegion.class,
Target.BIOME, IrisBiome.class,
Target.OBJECT_PLACEMENT, IrisObjectPlacement.class);
private static final Map<Level, Class<?>> 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<Target> ofResource(Class<?> resourceType) {
public static Optional<Level> 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<Target, Set<String>> reservedFields() {
Map<Target, Set<String>> fields = new EnumMap<>(Target.class);
static Map<Level, Set<String>> reservedFields() {
Map<Level, Set<String>> fields = new EnumMap<>(Level.class);
HOLDERS.forEach((target, holder) -> fields.put(target, JsonFieldNames.of(holder)));
return fields;
}
@@ -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;
@@ -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 <F extends IrisFeature> List<Entry<F>> declared(Class<F> featureType) {
public <F extends IrisFeature> SettingsStack<F> declared(Class<F> featureType) {
List<Entry<F>> 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 <F extends IrisFeature, R extends IrisRegistrant> void addEntries(List<Entry<F>> entries, Class<F> featureType,
Target level, String kind, ResourceLoader<R> loader) {
Level level, String kind, ResourceLoader<R> loader) {
for (String key : Arrays.stream(loader.getPossibleKeys()).sorted().toList()) {
R owner = loader.load(key, false);
if (owner != null) {
@@ -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 <F extends IrisFeature> List<Entry<F>> at(Class<F> featureType, int worldX, int worldZ) {
return List.of();
public <F extends IrisFeature> SettingsStack<F> at(Class<F> featureType, int worldX, int worldZ) {
return SettingsStack.empty();
}
};
@@ -55,14 +56,14 @@ final class PlacementModuleSettings implements FeatureSettings {
}
@Override
public <F extends IrisFeature> List<Entry<F>> at(Class<F> featureType, int worldX, int worldZ) {
List<Entry<F>> worldEntries = world.at(featureType, worldX, worldZ);
public <F extends IrisFeature> SettingsStack<F> at(Class<F> featureType, int worldX, int worldZ) {
SettingsStack<F> worldEntries = world.at(featureType, worldX, worldZ);
Optional<F> own = placement.find(featureType);
if (own.isEmpty()) {
return worldEntries;
}
List<Entry<F>> entries = new ArrayList<>(worldEntries);
entries.add(new Entry<>(Target.OBJECT_PLACEMENT, source, own.get()));
return List.copyOf(entries);
List<Entry<F>> entries = new ArrayList<>(worldEntries.entries());
entries.add(new Entry<>(Level.PLACEMENT, source, own.get()));
return SettingsStack.of(entries);
}
}
@@ -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 <https://www.gnu.org/licenses/>.
*/
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<ModuleSettings, Map<ModuleSettings, Map<ModuleSettings, Map<Class<?>, SettingsStack<?>>>>> byDimension =
new ConcurrentHashMap<>();
/** The stack remembered for the combination, or null when none was yet. */
@SuppressWarnings("unchecked")
<F extends IrisFeature> SettingsStack<F> find(ModuleSettings dimension, ModuleSettings region, ModuleSettings biome, Class<F> 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<F>) byType.get(type);
}
<F extends IrisFeature> void remember(ModuleSettings dimension, ModuleSettings region, ModuleSettings biome, Class<F> type,
SettingsStack<F> stack) {
byDimension.computeIfAbsent(dimension, ignored -> new ConcurrentHashMap<>())
.computeIfAbsent(region, ignored -> new ConcurrentHashMap<>())
.computeIfAbsent(biome, ignored -> new ConcurrentHashMap<>())
.put(type, stack);
}
}
@@ -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 <https://www.gnu.org/licenses/>.
*/
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<ModuleLog, ToolWorld> 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<ModuleLog, ToolWorld> 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> T state(Class<T> type, Function<? super PackWorld, ? extends T> 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();
}
}
@@ -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)));
@@ -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));
}
@@ -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<String> 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());
@@ -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;
}
@@ -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<CarvingEntry> 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 {
@@ -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 <F extends IrisFeature> List<Entry<F>> declared(Class<F> featureType) {
return declared.stream().filter(entry -> featureType.isInstance(entry.value())).map(entry -> (Entry<F>) entry).toList();
public <F extends IrisFeature> SettingsStack<F> declared(Class<F> featureType) {
return SettingsStack.of(declared.stream().filter(entry -> featureType.isInstance(entry.value())).map(entry -> (Entry<F>) entry).toList());
}
};
}
@@ -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 <https://www.gnu.org/licenses/>.
*/
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<StackedSettings> 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<StackedSettings> 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 extends IrisRegistrant> 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;
}
}
}
@@ -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(); }
};
}
@@ -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<Decorator> 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();
}
}
@@ -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<DepositGenerator> 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();
}
}
@@ -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);
}
@@ -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<FloatingChildBiome> 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<String> 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 {
@@ -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<Object> 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));
@@ -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<BlockDrop> 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<AmbientEffect> 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));
@@ -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<PlatformBlockState> 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<BlockState> 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<Object> 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);
}
}
@@ -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<IrisPosition> 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<BlockSpec> 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,"
+ " {\"<option>\": ...}", refused.getMessage());
}
@@ -260,7 +260,7 @@ public class ModuleSettingsDecoderTest {
}).create();
ModuleSettingsDecoder withIrisGson = new ModuleSettingsDecoder(pack.catalog(), packFolder, () -> iris);
List<IrisPosition> marks = withIrisGson.decode(Target.BIOME, new JSONObject("{\"mossMarks\": {\"marks\": [\"a\", \"b\"]}}"), "biome desert/dunes")
List<IrisPosition> marks = withIrisGson.decode(Level.BIOME, new JSONObject("{\"mossMarks\": {\"marks\": [\"a\", \"b\"]}}"), "biome desert/dunes")
.find(MarksSettings.class).orElseThrow().marks;
assertEquals(List.of(marked, marked), marks);
@@ -26,10 +26,9 @@ import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
import com.volmit.ModuleLifecycle;
import com.volmit.ModuleSetup;
import com.volmit.config.PackSettings;
import com.volmit.PackContext;
import com.volmit.host.LoadedPack;
import com.volmit.host.ModuleHost;
import com.volmit.resource.PackResources;
import com.volmit.world.PackWorld;
import org.junit.After;
import org.junit.Before;
@@ -93,7 +92,7 @@ public class ModuleWorldsTest {
}
@Override
public void packLoaded(PackResources resources, PackSettings settings) {
public void packLoaded(PackContext pack) {
record("loaded");
}
@@ -31,7 +31,7 @@ import art.arcane.iris.spi.PlatformRegistries;
import art.arcane.volmlib.util.math.RNG;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.volmit.FeatureAttachment.Target;
import com.volmit.config.Level;
import com.volmit.IrisFeature;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
@@ -77,7 +77,7 @@ public class ObjectPlacementModuleSettingsTest {
private LoadedPack pack;
private Gson gson;
@Feature(id = "example:glow", name = "Glow", key = "glow", targets = Target.OBJECT_PLACEMENT)
@Feature(id = "example:glow", name = "Glow", key = "glow", targets = Level.PLACEMENT)
public static final class GlowSettings implements IrisFeature {
private String block = "minecraft:glowstone";
}
@@ -95,7 +95,7 @@ public class ObjectPlacementModuleSettingsTest {
public void setup(ModuleSetup setup) {
setup.stages().define(TOP).when(GlowSettings.class).requires(IrisStages.Blocks.COMPLETE, IrisStages.Anchor.FINAL).run(context -> {
int y = context.output(IrisStages.Anchor.FINAL).y() + 1;
String block = context.configured(GlowSettings.class).getFirst().value().block;
String block = context.configured(GlowSettings.class).values().getFirst().block;
context.access().set(new PlacedBlock(new BlockPosition(0, y, 0), com.volmit.block.BlockState.parse(block), Optional.empty()));
});
}
@@ -27,7 +27,7 @@ import art.arcane.iris.builtin.terrain.OreGenerator;
import art.arcane.iris.builtin.terrain.OreSettings;
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;
@@ -81,7 +81,7 @@ public class OreSettingsDecodingTest {
public void theOverworldReadsItsOresInTheOrderTheFileListsThem() throws IOException {
JSONObject dimension = new JSONObject(Files.readString(packFolder.resolve("dimensions/overworld.json")));
List<OreGenerator> ores = decoder.decode(Target.DIMENSION, dimension, "dimension overworld")
List<OreGenerator> ores = decoder.decode(Level.DIMENSION, dimension, "dimension overworld")
.find(OreSettings.class).orElseThrow().generators();
assertEquals(dimension.getJSONArray("ores").length(), ores.size());
@@ -113,7 +113,7 @@ public class OreSettingsDecodingTest {
]}
""");
for (Target target : List.of(Target.REGION, Target.BIOME)) {
for (Level target : List.of(Level.REGION, Level.BIOME)) {
List<OreGenerator> read = decoder.decode(target, ores, "test").find(OreSettings.class).orElseThrow().generators();
assertEquals(2, read.size());
@@ -130,12 +130,12 @@ public class OreSettingsDecodingTest {
@Test
public void hideOresForHiddenOreIsABooleanOnTheDimension() {
ModuleSettings hidden = decoder.decode(Target.DIMENSION, new JSONObject("{\"hideOresForHiddenOre\": true}"), "dimension test");
ModuleSettings shown = decoder.decode(Target.DIMENSION, new JSONObject("{\"hideOresForHiddenOre\": false}"), "dimension test");
ModuleSettings hidden = decoder.decode(Level.DIMENSION, new JSONObject("{\"hideOresForHiddenOre\": true}"), "dimension test");
ModuleSettings shown = decoder.decode(Level.DIMENSION, new JSONObject("{\"hideOresForHiddenOre\": false}"), "dimension test");
assertTrue(hidden.find(HideOresSettings.class).orElseThrow().hide());
assertFalse(shown.find(HideOresSettings.class).orElseThrow().hide());
assertTrue("a dimension that does not write it declares nothing", decoder.decode(Target.DIMENSION, new JSONObject("{}"), "dimension test").isEmpty());
assertTrue("a dimension that does not write it declares nothing", decoder.decode(Level.DIMENSION, new JSONObject("{}"), "dimension test").isEmpty());
}
@Test
@@ -147,7 +147,7 @@ public class OreSettingsDecodingTest {
]}
""");
for (Target target : List.of(Target.DIMENSION, Target.REGION, Target.BIOME)) {
for (Level target : List.of(Level.DIMENSION, Level.REGION, Level.BIOME)) {
List<DepositVariant> variants = decoder.decode(target, json, "test").find(DepositVariantSettings.class).orElseThrow().variants();
assertEquals(2, variants.size());
@@ -163,8 +163,8 @@ public class OreSettingsDecodingTest {
@Test
public void theTwoOreDepositMultipliersAreNumbersOnTheBiome() {
ModuleSettings tuned = decoder.decode(Target.BIOME, new JSONObject("{\"oreDepositFrequencyMultiplier\": 0.4, \"oreDepositSizeMultiplier\": 2}"), "biome test");
ModuleSettings plain = decoder.decode(Target.BIOME, new JSONObject("{}"), "biome test");
ModuleSettings tuned = decoder.decode(Level.BIOME, new JSONObject("{\"oreDepositFrequencyMultiplier\": 0.4, \"oreDepositSizeMultiplier\": 2}"), "biome test");
ModuleSettings plain = decoder.decode(Level.BIOME, new JSONObject("{}"), "biome test");
assertEquals(0.4, tuned.find(OreFrequencySettings.class).orElseThrow().multiplier(), 0);
assertEquals(2, tuned.find(OreSizeSettings.class).orElseThrow().multiplier(), 0);
@@ -174,10 +174,10 @@ public class OreSettingsDecodingTest {
@Test
public void everyKeyIsOnlyReadAtTheLevelsTheOldFieldExistedAt() {
assertTrue(decoder.keys(Target.DIMENSION).containsAll(List.of("ores", "hideOresForHiddenOre", "depositVariants")));
assertTrue(decoder.keys(Target.REGION).containsAll(List.of("ores", "depositVariants")));
assertFalse(decoder.keys(Target.REGION).contains("hideOresForHiddenOre"));
assertTrue(decoder.keys(Target.BIOME).containsAll(List.of("ores", "depositVariants", "oreDepositFrequencyMultiplier", "oreDepositSizeMultiplier")));
assertFalse(decoder.keys(Target.DIMENSION).contains("oreDepositFrequencyMultiplier"));
assertTrue(decoder.keys(Level.DIMENSION).containsAll(List.of("ores", "hideOresForHiddenOre", "depositVariants")));
assertTrue(decoder.keys(Level.REGION).containsAll(List.of("ores", "depositVariants")));
assertFalse(decoder.keys(Level.REGION).contains("hideOresForHiddenOre"));
assertTrue(decoder.keys(Level.BIOME).containsAll(List.of("ores", "depositVariants", "oreDepositFrequencyMultiplier", "oreDepositSizeMultiplier")));
assertFalse(decoder.keys(Level.DIMENSION).contains("oreDepositFrequencyMultiplier"));
}
}
@@ -32,7 +32,7 @@ import art.arcane.volmlib.util.json.JSONObject;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
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;
@@ -88,7 +88,7 @@ public class PackBeforeThePortDecodingTest {
public void aBiomeWithDecoratorsAndDepositsReadsBothUnderTheirOldKeys() throws IOException {
JSONObject biome = file("biomes/mesa/red.json");
ModuleSettings settings = decoder.decode(Target.BIOME, biome, "biome mesa/red");
ModuleSettings settings = decoder.decode(Level.BIOME, biome, "biome mesa/red");
List<Decorator> decorators = settings.find(DecorantSettings.class).orElseThrow().decorators();
assertEquals(biome.getJSONArray("decorators").length(), decorators.size());
@@ -110,7 +110,7 @@ public class PackBeforeThePortDecodingTest {
public void aBiomeWithManyDecoratorsAndDepositsReadsEveryEntry() throws IOException {
JSONObject biome = file("biomes/temperate/roughplains.json");
ModuleSettings settings = decoder.decode(Target.BIOME, biome, "biome temperate/roughplains");
ModuleSettings settings = decoder.decode(Level.BIOME, biome, "biome temperate/roughplains");
assertEquals(biome.getJSONArray("decorators").length(), settings.find(DecorantSettings.class).orElseThrow().decorators().size());
List<DepositGenerator> deposits = settings.find(DepositSettings.class).orElseThrow().generators();
@@ -123,7 +123,7 @@ public class PackBeforeThePortDecodingTest {
public void aRegionReadsItsDeposits() throws IOException {
JSONObject region = file("regions/magnetics.json");
List<DepositGenerator> deposits = decoder.decode(Target.REGION, region, "region magnetics")
List<DepositGenerator> deposits = decoder.decode(Level.REGION, region, "region magnetics")
.find(DepositSettings.class).orElseThrow().generators();
assertEquals(8, deposits.size());
@@ -136,7 +136,7 @@ public class PackBeforeThePortDecodingTest {
public void theDimensionReadsItsDepositsAndItsImportedStructures() throws IOException {
JSONObject dimension = file("dimensions/overworld.json");
ModuleSettings settings = decoder.decode(Target.DIMENSION, dimension, "dimension overworld");
ModuleSettings settings = decoder.decode(Level.DIMENSION, dimension, "dimension overworld");
List<DepositGenerator> deposits = settings.find(DepositSettings.class).orElseThrow().generators();
assertEquals(23, deposits.size());
@@ -155,7 +155,7 @@ public class PackBeforeThePortDecodingTest {
public void aBiomeReadsItsObjectPlacementsAndKeepsTheJsonIrisReadsThemFrom() throws IOException {
JSONObject biome = file("biomes/temperate/roughplains.json");
List<ObjectPlacement> objects = decoder.decode(Target.BIOME, biome, "biome temperate/roughplains")
List<ObjectPlacement> objects = decoder.decode(Level.BIOME, biome, "biome temperate/roughplains")
.find(ObjectSettings.class).orElseThrow().objects();
assertEquals(biome.getJSONArray("objects").length(), objects.size());
@@ -171,7 +171,7 @@ public class PackBeforeThePortDecodingTest {
public void aBiomeReadsItsProceduralTreesWithTheirPalettes() throws IOException {
JSONObject biome = file("biomes/estranged/bloomspire-orchard.json");
ProceduralObjectSettings procedural = decoder.decode(Target.BIOME, biome, "biome estranged/bloomspire-orchard")
ProceduralObjectSettings procedural = decoder.decode(Level.BIOME, biome, "biome estranged/bloomspire-orchard")
.find(ProceduralObjectSettings.class).orElseThrow();
assertEquals(biome.getJSONObject("proceduralObjects").getJSONArray("trees").length(), procedural.trees().size());
@@ -185,10 +185,10 @@ public class PackBeforeThePortDecodingTest {
@Test
public void everyTopLevelKeyOfTheseFilesIsAFieldOfIrisOrAKeyOfAModule() throws IOException {
Map<String, Target> files = Map.of("biomes/mesa/red.json", Target.BIOME, "biomes/temperate/roughplains.json", Target.BIOME,
"biomes/estranged/bloomspire-orchard.json", Target.BIOME, "regions/magnetics.json", Target.REGION, "dimensions/overworld.json", Target.DIMENSION);
Map<String, Level> files = Map.of("biomes/mesa/red.json", Level.BIOME, "biomes/temperate/roughplains.json", Level.BIOME,
"biomes/estranged/bloomspire-orchard.json", Level.BIOME, "regions/magnetics.json", Level.REGION, "dimensions/overworld.json", Level.DIMENSION);
for (Map.Entry<String, Target> file : files.entrySet()) {
for (Map.Entry<String, Level> file : files.entrySet()) {
Set<String> unknown = new TreeSet<>(file(file.getKey()).keySet());
unknown.removeAll(ModuleTargets.reservedFields().get(file.getValue()));
unknown.removeAll(decoder.keys(file.getValue()));
@@ -28,7 +28,7 @@ import art.arcane.iris.builtin.structure.StructureTerrainMode;
import art.arcane.iris.engine.framework.StructurePlacementGrid;
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;
@@ -137,7 +137,7 @@ public class StructurePlacementSettingsDecodingTest {
@Test
public void theOverworldPlacementReadsAsThePackWroteIt() {
StructurePlacement placement = placements(Target.DIMENSION, OVERWORLD).getFirst();
StructurePlacement placement = placements(Level.DIMENSION, OVERWORLD).getFirst();
assertEquals(List.of("minecraft:ancient_city"), placement.nativeStructures().stream().map(NativeStructureSource::structure).toList());
assertEquals(1, placement.nativeStructures().getFirst().weight());
@@ -160,8 +160,8 @@ public class StructurePlacementSettingsDecodingTest {
@Test
public void placementsKeepTheirIdentityAndStarts() {
StructurePlacement overworld = placements(Target.DIMENSION, OVERWORLD).getFirst();
StructurePlacement anonymous = placements(Target.BIOME, ANONYMOUS).getFirst();
StructurePlacement overworld = placements(Level.DIMENSION, OVERWORLD).getFirst();
StructurePlacement anonymous = placements(Level.BIOME, ANONYMOUS).getFirst();
assertEquals(-5401497891314909808L, StructurePlacementGrid.placementIdentity(overworld));
assertEquals(-2165116524116229836L, StructurePlacementGrid.placementRng(overworld, 7, -11, 123L).getSeed());
@@ -173,12 +173,12 @@ public class StructurePlacementSettingsDecodingTest {
@Test
public void regionsAndBiomesDeclarePlacementsUnderTheSameKey() {
assertTrue(decoder.keys(Target.REGION).contains("structures"));
assertTrue(decoder.keys(Target.BIOME).contains("structures"));
assertEquals(1, placements(Target.REGION, OVERWORLD).size());
assertTrue(decoder.keys(Level.REGION).contains("structures"));
assertTrue(decoder.keys(Level.BIOME).contains("structures"));
assertEquals(1, placements(Level.REGION, OVERWORLD).size());
}
private List<StructurePlacement> placements(Target target, String json) {
private List<StructurePlacement> placements(Level target, String json) {
return decoder.decode(target, new JSONObject(json), "test resource")
.find(StructurePlacementSettings.class).orElseThrow().placements();
}
@@ -6,7 +6,7 @@ import art.arcane.iris.builtin.structure.StructureTerrain;
import art.arcane.iris.builtin.structure.StructureTerrainMode;
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;
@@ -121,9 +121,9 @@ public class StructureSettingsDecodingTest {
public void theFeatureIdIsNotAKeyAndEmptySettingsHaveTheDefaults() {
JSONObject byId = new JSONObject("{\"iris:structure\": {\"disabled\": [\"minecraft:village\"]}}");
assertSame(ModuleSettings.NONE, decoder.decode(Target.DIMENSION, byId, "dimension overworld"));
assertTrue(decoder.keys(Target.DIMENSION).contains("importedStructures"));
assertFalse(decoder.keys(Target.DIMENSION).contains("iris:structure"));
assertSame(ModuleSettings.NONE, decoder.decode(Level.DIMENSION, byId, "dimension overworld"));
assertTrue(decoder.keys(Level.DIMENSION).contains("importedStructures"));
assertFalse(decoder.keys(Level.DIMENSION).contains("iris:structure"));
StructureSettings defaults = settings("{\"importedStructures\": {}}");
assertTrue(defaults.datapackOverrides());
assertEquals(List.of(), defaults.disabled());
@@ -136,14 +136,14 @@ public class StructureSettingsDecodingTest {
JSONObject list = new JSONObject("{\"importedStructures\": [\"minecraft:village\"]}");
IllegalArgumentException refused = assertThrows(IllegalArgumentException.class,
() -> decoder.decode(Target.DIMENSION, list, "dimension overworld"));
() -> decoder.decode(Level.DIMENSION, list, "dimension overworld"));
assertEquals("Cannot read settings iris:structure under \"importedStructures\" in dimension overworld:"
+ " write the settings as an object, {\"<option>\": ...}", refused.getMessage());
}
private StructureSettings settings(String dimensionJson) {
return decoder.decode(Target.DIMENSION, new JSONObject(dimensionJson), "dimension overworld")
return decoder.decode(Level.DIMENSION, new JSONObject(dimensionJson), "dimension overworld")
.find(StructureSettings.class).orElseThrow();
}
}
@@ -37,7 +37,7 @@ import art.arcane.iris.builtin.terrain.SlabSettings;
import art.arcane.iris.builtin.terrain.WallSettings;
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;
@@ -95,7 +95,7 @@ public class TerrainSettingsDecodingTest {
public void aLockedBiomeReadsItsLayersAndWall() throws IOException {
JSONObject biome = file("biomes/mesa/yellow.json");
ModuleSettings settings = decoder.decode(Target.BIOME, biome, "biome mesa/yellow");
ModuleSettings settings = decoder.decode(Level.BIOME, biome, "biome mesa/yellow");
List<PaletteLayer> layers = settings.find(LayersSettings.class).orElseThrow().layers();
assertEquals(biome.getJSONArray("layers").length(), layers.size());
@@ -118,7 +118,7 @@ public class TerrainSettingsDecodingTest {
@Test
public void aSlabIsOneLayerWithIrisDefaults() throws IOException {
ModuleSettings settings = decoder.decode(Target.BIOME, file("biomes/mountain/shore/beach.json"), "biome mountain/shore/beach");
ModuleSettings settings = decoder.decode(Level.BIOME, file("biomes/mountain/shore/beach.json"), "biome mountain/shore/beach");
PaletteLayer slab = settings.find(SlabSettings.class).orElseThrow().layer();
@@ -136,7 +136,7 @@ public class TerrainSettingsDecodingTest {
public void seaLayersKeepTheirNoiseAndWeights() throws IOException {
JSONObject biome = file("biomes/frozen/sea/river.json");
List<PaletteLayer> seaLayers = decoder.decode(Target.BIOME, biome, "biome frozen/sea/river").find(SeaLayersSettings.class).orElseThrow().layers();
List<PaletteLayer> seaLayers = decoder.decode(Level.BIOME, biome, "biome frozen/sea/river").find(SeaLayersSettings.class).orElseThrow().layers();
assertEquals(biome.getJSONArray("seaLayers").length(), seaLayers.size());
PaletteLayer first = seaLayers.getFirst();
@@ -154,7 +154,7 @@ public class TerrainSettingsDecodingTest {
public void caveCeilingLayersAreAListOfLayers() throws IOException {
JSONObject biome = file("biomes/carving/polarity-grotto.json");
List<PaletteLayer> ceiling = decoder.decode(Target.BIOME, biome, "biome carving/polarity-grotto")
List<PaletteLayer> ceiling = decoder.decode(Level.BIOME, biome, "biome carving/polarity-grotto")
.find(CaveCeilingLayersSettings.class).orElseThrow().layers();
assertEquals(1, ceiling.size());
@@ -166,7 +166,7 @@ public class TerrainSettingsDecodingTest {
@Test
public void lockLayersMaxIsANumberAndLockLayersABoolean() {
ModuleSettings settings = decoder.decode(Target.BIOME, new JSONObject("{\"lockLayers\": false, \"lockLayersMax\": 4}"), "biome mesa");
ModuleSettings settings = decoder.decode(Level.BIOME, new JSONObject("{\"lockLayers\": false, \"lockLayersMax\": 4}"), "biome mesa");
assertFalse(settings.find(LockLayersSettings.class).orElseThrow().locked());
assertEquals(4, settings.find(LockLayersMaxSettings.class).orElseThrow().layers());
@@ -175,7 +175,7 @@ public class TerrainSettingsDecodingTest {
@Test
public void aLayerWrittenWithoutOptionsHasIrisDefaults() {
ModuleSettings settings = decoder.decode(Target.BIOME, new JSONObject("{\"layers\": [{}], \"slab\": {}}"), "biome plain");
ModuleSettings settings = decoder.decode(Level.BIOME, new JSONObject("{\"layers\": [{}], \"slab\": {}}"), "biome plain");
PaletteLayer layer = settings.find(LayersSettings.class).orElseThrow().layers().getFirst();
assertEquals(List.of(BlockSpec.of("grass_block")), layer.palette());
@@ -195,7 +195,7 @@ public class TerrainSettingsDecodingTest {
Files.writeString(snippets.resolve("sandy.json"), "{\"minHeight\": 2, \"maxHeight\": 4, \"palette\": [{\"block\": \"sand\"}]}");
ModuleSettingsDecoder snippetDecoder = new ModuleSettingsDecoder(pack.catalog(), snippets.getParent().getParent(), Gson::new);
PaletteLayer layer = snippetDecoder.decode(Target.BIOME, new JSONObject("{\"layers\": [\"snippet/biome-palette/sandy\", \"snippet/sandy\"]}"), "biome dunes")
PaletteLayer layer = snippetDecoder.decode(Level.BIOME, new JSONObject("{\"layers\": [\"snippet/biome-palette/sandy\", \"snippet/sandy\"]}"), "biome dunes")
.find(LayersSettings.class).orElseThrow().layers().getFirst();
assertEquals(4, layer.maxHeight());
@@ -204,7 +204,7 @@ public class TerrainSettingsDecodingTest {
@Test
public void theDimensionReadsItsPalettesAndPostProcessingSwitches() {
ModuleSettings settings = decoder.decode(Target.DIMENSION, new JSONObject("""
ModuleSettings settings = decoder.decode(Level.DIMENSION, new JSONObject("""
{"rockPalette": {"style": {"style": "SIMPLEX", "zoom": 2}, "zoom": 9,
"palette": [{"block": "minecraft:stone", "weight": 3}, {"block": "minecraft:granite"}]},
"fluidPalette": {"palette": [{"block": "minecraft:lava"}]},
@@ -224,7 +224,7 @@ public class TerrainSettingsDecodingTest {
@Test
public void theDimensionReadsItsBedrockDecoratingAndExplodedPaletteKeysAsPacksWriteThem() {
ModuleSettings settings = decoder.decode(Target.DIMENSION, new JSONObject(
ModuleSettings settings = decoder.decode(Level.DIMENSION, new JSONObject(
"{\"bedrock\": false, \"decorate\": false, \"explodeBiomePalettes\": true, \"explodeBiomePaletteSize\": 5}"), "dimension flat");
assertFalse(settings.find(BedrockSettings.class).orElseThrow().bedrock());
@@ -232,14 +232,14 @@ public class TerrainSettingsDecodingTest {
assertTrue(settings.find(ExplodeBiomePalettesSettings.class).orElseThrow().explode());
assertEquals(5, settings.find(ExplodeBiomePaletteSizeSettings.class).orElseThrow().size());
for (String key : Set.of("bedrock", "decorate", "explodeBiomePalettes", "explodeBiomePaletteSize")) {
assertTrue(key, decoder.keys(Target.DIMENSION).contains(key));
assertFalse(key + " is no field of Iris any more", ModuleTargets.reservedFields().get(Target.DIMENSION).contains(key));
assertTrue(key, decoder.keys(Level.DIMENSION).contains(key));
assertFalse(key + " is no field of Iris any more", ModuleTargets.reservedFields().get(Level.DIMENSION).contains(key));
}
}
@Test
public void aDimensionThatWritesNothingIsStoneAndWaterWithPostProcessingOn() {
ModuleSettings settings = decoder.decode(Target.DIMENSION, new JSONObject("{}"), "dimension overworld");
ModuleSettings settings = decoder.decode(Level.DIMENSION, new JSONObject("{}"), "dimension overworld");
assertTrue(settings.find(RockPaletteSettings.class).isEmpty());
assertEquals(List.of(BlockSpec.of("stone")), new RockPaletteSettings().palette().palette());
@@ -254,7 +254,7 @@ public class TerrainSettingsDecodingTest {
@Test
public void aBooleanWrittenAsAnObjectIsRefused() {
IllegalArgumentException refused = assertThrows(IllegalArgumentException.class,
() -> decoder.decode(Target.BIOME, new JSONObject("{\"lockLayers\": {\"locked\": true}}"), "biome mesa"));
() -> decoder.decode(Level.BIOME, new JSONObject("{\"lockLayers\": {\"locked\": true}}"), "biome mesa"));
assertTrue(refused.getMessage(), refused.getMessage().startsWith("Cannot read settings iris:terrain/lock-layers under \"lockLayers\" in biome mesa:"));
}
@@ -262,7 +262,7 @@ public class TerrainSettingsDecodingTest {
@Test
public void layersWrittenAsAnObjectOfOptionsAreRefused() {
IllegalArgumentException refused = assertThrows(IllegalArgumentException.class,
() -> decoder.decode(Target.BIOME, new JSONObject("{\"layers\": {\"layers\": []}}"), "biome mesa"));
() -> decoder.decode(Level.BIOME, new JSONObject("{\"layers\": {\"layers\": []}}"), "biome mesa"));
assertEquals("Cannot read settings iris:terrain/layers under \"layers\" in biome mesa: write a list, [...], of the layers, not an object of options",
refused.getMessage());
@@ -270,22 +270,22 @@ public class TerrainSettingsDecodingTest {
@Test
public void theTerrainAndPostKeysAreModuleKeysAndNoLongerFieldsOfIris() {
assertTrue(decoder.keys(Target.BIOME).containsAll(Set.of("layers", "seaLayers", "caveCeilingLayers", "slab", "wall", "lockLayers", "lockLayersMax")));
assertTrue(decoder.keys(Target.DIMENSION).containsAll(Set.of("rockPalette", "fluidPalette", "postProcessing", "postProcessingSlabs", "postProcessingWalls")));
assertTrue(decoder.keys(Level.BIOME).containsAll(Set.of("layers", "seaLayers", "caveCeilingLayers", "slab", "wall", "lockLayers", "lockLayersMax")));
assertTrue(decoder.keys(Level.DIMENSION).containsAll(Set.of("rockPalette", "fluidPalette", "postProcessing", "postProcessingSlabs", "postProcessingWalls")));
for (String key : Set.of("layers", "seaLayers", "caveCeilingLayers", "slab", "wall", "lockLayers", "lockLayersMax")) {
assertFalse(key, ModuleTargets.reservedFields().get(Target.BIOME).contains(key));
assertFalse(key, ModuleTargets.reservedFields().get(Level.BIOME).contains(key));
}
for (String key : Set.of("rockPalette", "fluidPalette", "postProcessing", "postProcessingSlabs", "postProcessingWalls")) {
assertFalse(key, ModuleTargets.reservedFields().get(Target.DIMENSION).contains(key));
assertFalse(key, ModuleTargets.reservedFields().get(Level.DIMENSION).contains(key));
}
}
@Test
public void everyTopLevelKeyOfTheseFilesIsAFieldOfIrisOrAKeyOfAModule() throws IOException {
Map<String, Target> files = Map.of("biomes/mesa/yellow.json", Target.BIOME, "biomes/mountain/shore/beach.json", Target.BIOME,
"biomes/frozen/sea/river.json", Target.BIOME, "biomes/carving/polarity-grotto.json", Target.BIOME);
Map<String, Level> files = Map.of("biomes/mesa/yellow.json", Level.BIOME, "biomes/mountain/shore/beach.json", Level.BIOME,
"biomes/frozen/sea/river.json", Level.BIOME, "biomes/carving/polarity-grotto.json", Level.BIOME);
for (Map.Entry<String, Target> file : files.entrySet()) {
for (Map.Entry<String, Level> file : files.entrySet()) {
Set<String> unknown = new TreeSet<>(file(file.getKey()).keySet());
unknown.removeAll(ModuleTargets.reservedFields().get(file.getValue()));
unknown.removeAll(decoder.keys(file.getValue()));
@@ -0,0 +1,63 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.core.modules;
import com.volmit.ModuleLog;
import com.volmit.config.PackSettings;
import com.volmit.resource.PackResources;
import com.volmit.world.PackWorld;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
/** The world of a tool's placement shares its state with every log view and closes it with the placement. */
public class ToolWorldTest {
private static final long SEED = 42L;
static final class Tracked implements AutoCloseable {
private boolean closed;
@Override
public void close() {
closed = true;
}
}
@Test
public void everyLogViewSharesTheStateAndClosingTheWorldClosesIt() {
PackResources resources = mock(PackResources.class);
Tracked tracked;
try (ToolWorld world = new ToolWorld(SEED, resources, mock(PackSettings.class))) {
tracked = world.state(Tracked.class, ignored -> new Tracked());
PackWorld view = world.withLog(mock(ModuleLog.class));
assertSame(tracked, view.state(Tracked.class, ignored -> new Tracked()));
assertSame(resources, view.resources());
assertEquals(SEED, view.seed());
assertEquals(0, view.minHeight());
assertFalse(tracked.closed);
}
assertTrue(tracked.closed);
}
}
@@ -21,7 +21,7 @@ package art.arcane.iris.core.modules;
import art.arcane.iris.builtin.vanillafeatures.ImportedFeaturesSettings;
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 com.volmit.vanilla.DecorationStep;
@@ -90,8 +90,8 @@ public class VanillaFeaturesSettingsDecodingTest {
assertEquals(List.of(), defaults.disabled());
assertEquals(List.of(), defaults.steps());
assertEquals(List.of(), defaults.disabledSteps());
assertSame(ModuleSettings.NONE, decoder.decode(Target.DIMENSION, byId, "dimension overworld"));
assertTrue(decoder.keys(Target.DIMENSION).contains("importedFeatures"));
assertSame(ModuleSettings.NONE, decoder.decode(Level.DIMENSION, byId, "dimension overworld"));
assertTrue(decoder.keys(Level.DIMENSION).contains("importedFeatures"));
}
@Test
@@ -99,14 +99,14 @@ public class VanillaFeaturesSettingsDecodingTest {
JSONObject bare = new JSONObject("{\"importedFeatures\": true}");
IllegalArgumentException refused = assertThrows(IllegalArgumentException.class,
() -> decoder.decode(Target.DIMENSION, bare, "dimension overworld"));
() -> decoder.decode(Level.DIMENSION, bare, "dimension overworld"));
assertEquals("Cannot read settings iris:vanilla-features under \"importedFeatures\" in dimension overworld:"
+ " write the settings as an object, {\"<option>\": ...}", refused.getMessage());
}
private ImportedFeaturesSettings settings(String dimensionJson) {
return decoder.decode(Target.DIMENSION, new JSONObject(dimensionJson), "dimension overworld")
return decoder.decode(Level.DIMENSION, new JSONObject(dimensionJson), "dimension overworld")
.find(ImportedFeaturesSettings.class).orElseThrow();
}
}
@@ -62,7 +62,7 @@ import art.arcane.volmlib.util.json.JSONArray;
import art.arcane.volmlib.util.json.JSONObject;
import art.arcane.iris.core.modules.PackModuleSet;
import art.arcane.iris.core.modules.ModuleResourceFixture;
import com.volmit.FeatureAttachment.Target;
import com.volmit.config.Level;
import com.volmit.IrisFeature;
import art.arcane.iris.core.modules.BuiltInPack;
import art.arcane.iris.core.modules.IrisModuleHost;
@@ -874,7 +874,7 @@ public class SchemaBuilderParityTest {
}
}
@Feature(id = "example:tint", name = "Tint", key = "tint", targets = Target.OBJECT_PLACEMENT)
@Feature(id = "example:tint", name = "Tint", key = "tint", targets = Level.PLACEMENT)
public static final class TintSettings implements IrisFeature {
@com.volmit.config.MinItems(1)
private List<com.volmit.block.BlockSpec> palette = List.of();
@@ -902,7 +902,7 @@ public class SchemaBuilderParityTest {
}
}
@Feature(id = "example:glow", name = "Glow", key = "glow", targets = Target.OBJECT_PLACEMENT)
@Feature(id = "example:glow", name = "Glow", key = "glow", targets = Level.PLACEMENT)
public static final class GlowSettings implements IrisFeature {
@com.volmit.config.Desc("How bright the glow is")
@com.volmit.config.MinNumber(1)
@@ -3,7 +3,8 @@ package art.arcane.iris.engine.actuator;
import art.arcane.iris.builtin.terrain.OreSettings;
import art.arcane.iris.engine.modifier.ApiChunk;
import art.arcane.iris.engine.terrain.TestPackWorld;
import com.volmit.FeatureAttachment.Target;
import com.volmit.config.Level;
import com.volmit.config.SettingsStack;
import com.volmit.IrisFeature;
import com.volmit.config.FeatureSettings.Entry;
import com.volmit.config.PackSettings;
@@ -31,19 +32,19 @@ public class OreWarmUpTest {
TerrainOres ores = mock(TerrainOres.class);
List<Entry<OreSettings>> declared = new ArrayList<>();
// The pack lists the dimension first, then regions and biomes, in no particular order.
declared.add(entry(Target.DIMENSION, "dimension/overworld", ores, "d0"));
declared.add(entry(Target.REGION, "region/y", ores, "y0"));
declared.add(entry(Target.BIOME, "biome/b", ores, "b0", "b1"));
declared.add(entry(Target.REGION, "region/x", ores, "x0", "x1"));
declared.add(entry(Target.BIOME, "biome/a", ores, "a0"));
declared.add(entry(Level.DIMENSION, "dimension/overworld", ores, "d0"));
declared.add(entry(Level.REGION, "region/y", ores, "y0"));
declared.add(entry(Level.BIOME, "biome/b", ores, "b0", "b1"));
declared.add(entry(Level.REGION, "region/x", ores, "x0", "x1"));
declared.add(entry(Level.BIOME, "biome/a", ores, "a0"));
PackSettings settings = new PackSettings() {
@Override
@SuppressWarnings("unchecked")
public <F extends IrisFeature> List<Entry<F>> declared(Class<F> featureType) {
return (List<Entry<F>>) (List<?>) declared;
public <F extends IrisFeature> SettingsStack<F> declared(Class<F> featureType) {
return SettingsStack.of((List<Entry<F>>) (List<?>) declared);
}
};
TestPackWorld world = new TestPackWorld(new ApiChunk(0, 0, 16).resources(), settings, COMPONENT_SEED);
TestPackWorld world = new TestPackWorld(new ApiChunk(0, 0, 16).world().resources(), settings, COMPONENT_SEED);
new OreWarmUp(world, ores).warm();
@@ -51,7 +52,7 @@ public class OreWarmUpTest {
"x0@" + (ROOT_SEED + 3), "x1@" + (ROOT_SEED + 4), "y0@" + (ROOT_SEED + 5), "d0@" + (ROOT_SEED + 6)), warmed);
}
private Entry<OreSettings> entry(Target level, String source, TerrainOres ores, String... oreNames) {
private Entry<OreSettings> entry(Level level, String source, TerrainOres ores, String... oreNames) {
OreSettings settings = new OreSettings(List.of());
ResolvedOres declared = resolved(oreNames);
when(ores.of(settings)).thenReturn(declared);
@@ -91,7 +91,7 @@ public class BiomeDecoratorsTest {
public void warmingResolvesEveryDecoratorOfEveryBiomeThePackDeclares() {
decorators.warm();
assertEquals(2, decorators.decorators(new DecoratedBiome("plains", chunk.world().settings().declared(DecorantSettings.class).getFirst().value(),
assertEquals(2, decorators.decorators(new DecoratedBiome("plains", chunk.world().settings().declared(DecorantSettings.class).values().getFirst(),
BiomeKind.LAND), DecorationPart.NONE).length);
}
@@ -20,10 +20,11 @@ package art.arcane.iris.engine.framework.vanillafeatures;
import art.arcane.iris.builtin.vanillafeatures.ImportedFeaturesSettings;
import art.arcane.iris.engine.object.TestSettings;
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 com.volmit.vanilla.DecorationStep;
import com.volmit.world.PackWorld;
@@ -112,11 +113,11 @@ public class ImportedFeaturesTest {
when(world.settings()).thenReturn(new PackSettings() {
@Override
@SuppressWarnings("unchecked")
public <F extends IrisFeature> List<Entry<F>> declared(Class<F> featureType) {
public <F extends IrisFeature> SettingsStack<F> declared(Class<F> featureType) {
if (settings == null || featureType != ImportedFeaturesSettings.class) {
return List.of();
return SettingsStack.empty();
}
return List.of((Entry<F>) new Entry<>(Target.DIMENSION, ResourceId.parse("test:overworld"), settings));
return SettingsStack.of(List.of((Entry<F>) new Entry<>(Level.DIMENSION, ResourceId.parse("test:overworld"), settings)));
}
});
return world;
@@ -6,11 +6,12 @@ import art.arcane.iris.builtin.loot.LootTable;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.core.modules.ModuleResourceFixture;
import art.arcane.iris.engine.object.TestSettings;
import com.volmit.FeatureAttachment.Target;
import com.volmit.config.Level;
import com.volmit.IrisFeature;
import com.volmit.config.FeatureSettings.Entry;
import com.volmit.config.MaxNumber;
import com.volmit.config.PackSettings;
import com.volmit.config.SettingsStack;
import com.volmit.resource.PackResources;
import com.volmit.resource.ResourceId;
import com.volmit.validation.Problem;
@@ -44,14 +45,14 @@ public class LootValidatorTest {
public void acceptsValidLootTableAndReference() {
table("global/clutter", "{\"name\":\"Clutter\",\"minPicked\":1,\"maxPicked\":2,"
+ "\"loot\":[{\"type\":\"stick\",\"rarity\":2,\"minAmount\":1,\"maxAmount\":3}]}");
reference(Target.DIMENSION, "main", "{\"mode\":\"FALLBACK\",\"multiplier\":0.5,\"tables\":[\"global/clutter\"]}");
reference(Level.DIMENSION, "main", "{\"mode\":\"FALLBACK\",\"multiplier\":0.5,\"tables\":[\"global/clutter\"]}");
assertTrue(errors().isEmpty());
}
@Test
public void rejectsMissingLootReference() {
reference(Target.DIMENSION, "main", "{\"tables\":[\"missing\"]}");
reference(Level.DIMENSION, "main", "{\"tables\":[\"missing\"]}");
assertEquals(List.of("Dimension 'main'.loot.tables[0] references missing loot table 'missing'."), errors());
}
@@ -82,17 +83,17 @@ public class LootValidatorTest {
@Test
public void rejectsInvalidReferenceMultiplier() {
reference(Target.DIMENSION, "main", "{\"multiplier\":-1,\"tables\":[]}");
reference(Level.DIMENSION, "main", "{\"multiplier\":-1,\"tables\":[]}");
assertEquals(List.of("Dimension 'main'.loot.multiplier must be a finite number from 0 to 16."), errors());
}
@Test
public void enforcesPublishedLootMultiplierCap() {
reference(Target.DIMENSION, "accepted", "{\"multiplier\":16,\"tables\":[]}");
reference(Level.DIMENSION, "accepted", "{\"multiplier\":16,\"tables\":[]}");
assertTrue(errors().isEmpty());
reference(Target.DIMENSION, "rejected", "{\"multiplier\":16.01,\"tables\":[]}");
reference(Level.DIMENSION, "rejected", "{\"multiplier\":16.01,\"tables\":[]}");
assertEquals(List.of("Dimension 'rejected'.loot.multiplier must be a finite number from 0 to 16."), errors());
}
@@ -136,7 +137,7 @@ public class LootValidatorTest {
@Test
public void clearModeWithTablesWarnsWithoutBlocking() {
table("t", "{\"loot\":[{\"type\":\"minecraft:stone\"}]}");
reference(Target.BIOME, "x", "{\"mode\":\"CLEAR\",\"tables\":[\"t\"]}");
reference(Level.BIOME, "x", "{\"mode\":\"CLEAR\",\"tables\":[\"t\"]}");
assertTrue(errors().isEmpty());
assertEquals(List.of("Biome 'x'.loot uses mode CLEAR and lists 1 table(s); CLEAR clears parent tables"
@@ -146,7 +147,7 @@ public class LootValidatorTest {
@Test
public void clearModeWithMissingTableStillBlocksOnTheDanglingKey() {
reference(Target.BIOME, "x", "{\"mode\":\"CLEAR\",\"tables\":[\"missing\"]}");
reference(Level.BIOME, "x", "{\"mode\":\"CLEAR\",\"tables\":[\"missing\"]}");
assertTrue(errors().contains("Biome 'x'.loot.tables[0] references missing loot table 'missing'."));
}
@@ -163,7 +164,7 @@ public class LootValidatorTest {
@Test
public void referencesAreFoundByTheIdThePackGivesTheirKey() {
table("Global/Clutter", "{\"loot\":[{\"type\":\"stick\"}]}");
reference(Target.REGION, "plains", "{\"tables\":[\"Global/Clutter\"]}");
reference(Level.REGION, "plains", "{\"tables\":[\"Global/Clutter\"]}");
assertTrue(errors().isEmpty());
}
@@ -172,7 +173,7 @@ public class LootValidatorTest {
tables.resource(LootResources.TABLES, key, TestSettings.of(LootTable.class, json));
}
private void reference(Target level, String key, String json) {
private void reference(Level level, String key, String json) {
String folder = switch (level) {
case DIMENSION -> "dimension";
case REGION -> "region";
@@ -207,8 +208,8 @@ public class LootValidatorTest {
return new PackSettings() {
@Override
@SuppressWarnings("unchecked")
public <F extends IrisFeature> List<Entry<F>> declared(Class<F> featureType) {
return featureType == LootSettings.class ? (List<Entry<F>>) (List<?>) List.copyOf(references) : List.of();
public <F extends IrisFeature> SettingsStack<F> declared(Class<F> featureType) {
return featureType == LootSettings.class ? SettingsStack.of((List<Entry<F>>) (List<?>) List.copyOf(references)) : SettingsStack.empty();
}
};
}
@@ -75,7 +75,7 @@ public class CaveAnchorsTest {
private static TerrainSampler terrain() {
TerrainSampler terrain = mock(TerrainSampler.class);
when(terrain.surfaceY(anyInt(), anyInt())).thenReturn((double) SURFACE);
when(terrain.surfaceHeight(anyInt(), anyInt())).thenReturn(SURFACE);
when(terrain.biome(anyInt(), anyInt(), anyInt())).thenReturn(new BiomeSample(BIOME, BIOME, Optional.of(BIOME)));
return terrain;
}
@@ -27,7 +27,7 @@ import art.arcane.iris.engine.object.TestSettings;
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
import art.arcane.volmlib.util.matter.Matter;
import art.arcane.volmlib.util.matter.MatterCavern;
import com.volmit.FeatureAttachment.Target;
import com.volmit.config.Level;
import com.volmit.config.Range;
import com.volmit.noise.NoiseStyle;
import com.volmit.noise.StyledRange;
@@ -71,7 +71,7 @@ public class CaveCarvingTest {
public void aDisabledProfileDeclaresNothingAndTheDimensionsStillCarves() {
world.dimension(profile(true));
int dimensionOnly = carvedBlocks(BiomeSample::surfaceBiome);
world = newWorld().dimension(profile(true)).declare(Target.REGION, "region", profile(false));
world = newWorld().dimension(profile(true)).declare(Level.REGION, "region", profile(false));
assertTrue(dimensionOnly > 0);
assertEquals(dimensionOnly, carvedBlocks(BiomeSample::surfaceBiome));
@@ -79,7 +79,7 @@ public class CaveCarvingTest {
@Test
public void anEnabledProfileOfARegionReplacesTheDimensionsWithinItsOwnBounds() {
world.dimension(profile(true)).declare(Target.REGION, "region", TestSettings.with(profile(true), "verticalRange", Range.of(50D, 60D)));
world.dimension(profile(true)).declare(Level.REGION, "region", TestSettings.with(profile(true), "verticalRange", Range.of(50D, 60D)));
int carved = carvedBlocks(BiomeSample::surfaceBiome);
@@ -89,7 +89,7 @@ public class CaveCarvingTest {
@Test
public void theCaveBiomeOfAColumnCarvesWithItsOwnProfileWhereTheDimensionDeclaresNone() {
world.declare(Target.BIOME, "cave/lush", profile(true));
world.declare(Level.BIOME, "cave/lush", profile(true));
assertEquals("the surface biome declares none", 0, carvedBlocks(BiomeSample::surfaceBiome));
assertTrue(carvedBlocks(sample -> sample.caveBiome().orElseThrow()) > 0);
@@ -25,10 +25,11 @@ import art.arcane.iris.builtin.objects.ObjectHost;
import art.arcane.iris.builtin.objects.ObjectPlacement;
import art.arcane.iris.builtin.objects.ObjectSize;
import art.arcane.iris.engine.object.TestSettings;
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.host.ModuleLogs;
import com.volmit.resource.ResourceId;
import org.junit.Test;
@@ -58,8 +59,9 @@ public class FloatingObjectPlacingBoundaryRadiusTest {
return new FloatingPack() {
@Override
@SuppressWarnings("unchecked")
public <T extends IrisFeature> List<Entry<T>> declared(Class<T> featureType) {
return featureType == FloatingChildSettings.class ? List.of(new Entry<>(Target.BIOME, BIOME, (T) declared)) : List.of();
public <T extends IrisFeature> SettingsStack<T> declared(Class<T> featureType) {
return featureType == FloatingChildSettings.class ? SettingsStack.of(List.of(new Entry<>(Level.BIOME, BIOME, (T) declared)))
: SettingsStack.empty();
}
@Override
@@ -9,7 +9,7 @@ import art.arcane.iris.builtin.objects.ProceduralObjectSettings;
import art.arcane.iris.builtin.objects.ProceduralPlacement;
import art.arcane.iris.engine.object.TestSettings;
import art.arcane.volmlib.util.math.RNG;
import com.volmit.FeatureAttachment.Target;
import com.volmit.config.Level;
import com.volmit.world.PackWorld;
import org.junit.Test;
@@ -40,11 +40,11 @@ public class ObjectWarmUpTest {
when(host.procedural(eq(biomeProceduralSettings), any())).thenReturn(List.of(biomeTree));
when(host.procedural(eq(regionProceduralSettings), any())).thenReturn(List.of(regionTree));
when(host.declarations(ObjectSettings.class)).thenReturn(List.of(
new Declaration<>(Target.REGION, "region", objects(regionPlacement)),
new Declaration<>(Target.BIOME, "biome", objects(biomePlacement))));
new Declaration<>(Level.REGION, "region", objects(regionPlacement)),
new Declaration<>(Level.BIOME, "biome", objects(biomePlacement))));
when(host.declarations(ProceduralObjectSettings.class)).thenReturn(List.of(
new Declaration<>(Target.REGION, "region", regionProceduralSettings),
new Declaration<>(Target.BIOME, "biome", biomeProceduralSettings)));
new Declaration<>(Level.REGION, "region", regionProceduralSettings),
new Declaration<>(Level.BIOME, "biome", biomeProceduralSettings)));
new ObjectWarmUp(world).warm();
@@ -21,10 +21,11 @@ import art.arcane.volmlib.util.mantle.flag.ReservedFlag;
import art.arcane.volmlib.util.mantle.runtime.Mantle;
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
import art.arcane.volmlib.util.matter.Matter;
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.host.ModuleLogs;
import com.volmit.resource.ResourceId;
import org.junit.Test;
@@ -134,8 +135,8 @@ public class PlacementReachTest {
return new PackSettings() {
@Override
@SuppressWarnings("unchecked")
public <T extends IrisFeature> List<Entry<T>> declared(Class<T> featureType) {
return featureType == type ? List.of(new Entry<>(Target.BIOME, SOURCE, (T) settings)) : List.of();
public <T extends IrisFeature> SettingsStack<T> declared(Class<T> featureType) {
return featureType == type ? SettingsStack.of(List.of(new Entry<>(Level.BIOME, SOURCE, (T) settings))) : SettingsStack.empty();
}
};
}
@@ -23,7 +23,8 @@ import art.arcane.iris.builtin.objects.ObjectPlacement;
import art.arcane.iris.builtin.objects.ObjectSettings;
import art.arcane.iris.builtin.objects.TreeGrowthSettings;
import art.arcane.iris.engine.object.TestSettings;
import com.volmit.FeatureAttachment.Target;
import com.volmit.config.Level;
import com.volmit.config.SettingsStack;
import com.volmit.config.FeatureSettings;
import com.volmit.config.FeatureSettings.Entry;
import com.volmit.resource.ResourceId;
@@ -68,7 +69,7 @@ public class TreeGrowingTest {
@Test
public void aDimensionWithoutTreeOverridesLeavesTheGrowthToThePlatform() {
when(settings.at(TreeGrowthSettings.class, 10, 20)).thenReturn(List.of());
when(settings.at(TreeGrowthSettings.class, 10, 20)).thenReturn(SettingsStack.empty());
Optional<SaplingGrowth.Growth> growth = new TreeGrowing().grow(world, OAK_SAPLING, mock(SaplingGrowth.Surroundings.class));
@@ -79,7 +80,7 @@ public class TreeGrowingTest {
@Test
public void withoutAPlacementThatGrowsTheSpeciesTheGrowthIsLeftToThePlatform() {
TreeGrowthSettings enabled = TestSettings.of(TreeGrowthSettings.class, "{\"enabled\":true}");
when(settings.at(TreeGrowthSettings.class, 10, 20)).thenReturn(List.of(new Entry<>(Target.DIMENSION, SOURCE, enabled)));
when(settings.at(TreeGrowthSettings.class, 10, 20)).thenReturn(SettingsStack.of(List.of(new Entry<>(Level.DIMENSION, SOURCE, enabled))));
ObjectSettings objects = TestSettings.with(new ObjectSettings(), "objects",
List.of(TestSettings.of(ObjectPlacement.class, "{\"place\":[\"a\"]}")));
when(host.biomeAt(10, 70, 20)).thenReturn(BIOME);
@@ -34,7 +34,7 @@ import art.arcane.iris.builtin.terrain.PaletteLayer;
import art.arcane.iris.builtin.terrain.SlabSettings;
import art.arcane.iris.builtin.terrain.WallSettings;
import art.arcane.iris.engine.object.TestSettings;
import com.volmit.FeatureAttachment.Target;
import com.volmit.config.Level;
import com.volmit.IrisFeature;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
@@ -49,6 +49,7 @@ import com.volmit.block.PaletteSampler;
import com.volmit.block.PaletteSpec;
import com.volmit.config.FeatureSettings;
import com.volmit.config.PackSettings;
import com.volmit.config.SettingsStack;
import com.volmit.generation.GenerationContext;
import com.volmit.host.ArrayHunk;
import com.volmit.host.ChunkRunner;
@@ -321,12 +322,8 @@ public final class ApiChunk implements GenerationContext {
public FeatureSettings settings() {
return new FeatureSettings() {
@Override
public <F extends IrisFeature> List<Entry<F>> at(Class<F> featureType, int worldX, int worldZ) {
List<Entry<F>> entries = new ArrayList<>();
addEntries(entries, featureType, Target.DIMENSION, DIMENSION, dimensionSettings);
addEntries(entries, featureType, Target.REGION, REGION, regionSettings);
addEntries(entries, featureType, Target.BIOME, BIOME, biomeSettings);
return entries;
public <F extends IrisFeature> SettingsStack<F> at(Class<F> featureType, int worldX, int worldZ) {
return declaredAtEveryLevel(featureType);
}
@Override
@@ -350,22 +347,20 @@ public final class ApiChunk implements GenerationContext {
return (Hunk<T>) blocks;
}
@Override
public long worldSeed() {
return SEED;
}
@Override
public PackResources resources() {
return world.resources;
}
@Override
public PackWorld world() {
return world;
}
private static <F extends IrisFeature> void addEntries(List<Entry<F>> entries, Class<F> type, Target level, ResourceId source,
private <F extends IrisFeature> SettingsStack<F> declaredAtEveryLevel(Class<F> featureType) {
List<Entry<F>> entries = new ArrayList<>();
addEntries(entries, featureType, Level.DIMENSION, DIMENSION, dimensionSettings);
addEntries(entries, featureType, Level.REGION, REGION, regionSettings);
addEntries(entries, featureType, Level.BIOME, BIOME, biomeSettings);
return SettingsStack.of(entries);
}
private static <F extends IrisFeature> void addEntries(List<Entry<F>> entries, Class<F> type, Level level, ResourceId source,
List<IrisFeature> declared) {
declared.stream().filter(type::isInstance).map(type::cast).forEach(value -> entries.add(new Entry<>(level, source, value)));
}
@@ -604,12 +599,8 @@ public final class ApiChunk implements GenerationContext {
public PackSettings settings() {
return new PackSettings() {
@Override
public <F extends IrisFeature> List<Entry<F>> declared(Class<F> featureType) {
List<Entry<F>> entries = new ArrayList<>();
addEntries(entries, featureType, Target.DIMENSION, DIMENSION, dimensionSettings);
addEntries(entries, featureType, Target.REGION, REGION, regionSettings);
addEntries(entries, featureType, Target.BIOME, BIOME, biomeSettings);
return entries;
public <F extends IrisFeature> SettingsStack<F> declared(Class<F> featureType) {
return declaredAtEveryLevel(featureType);
}
};
}
@@ -23,7 +23,7 @@ import art.arcane.iris.builtin.carve.CarvingSettings;
import art.arcane.iris.builtin.carve.CaveDepthSettings;
import art.arcane.iris.core.modules.CarveTestWorld;
import com.google.gson.Gson;
import com.volmit.FeatureAttachment.Target;
import com.volmit.config.Level;
import org.junit.Before;
import org.junit.Test;
@@ -50,7 +50,7 @@ public class CaveBiomeBandsTest {
world = new CarveTestWorld()
.biome("band/shallow", 1).biome("band/padded", 1).biome("band/disabled", 1)
.dimension(new CarvingSettings(entries))
.declare(Target.BIOME, "band/shallow", new CaveDepthSettings(30));
.declare(Level.BIOME, "band/shallow", new CaveDepthSettings(30));
}
@Test
@@ -21,10 +21,11 @@ package art.arcane.iris.engine.modifier;
import art.arcane.iris.builtin.deposit.DepositSettings;
import art.arcane.iris.builtin.deposit.DepositGenerator;
import art.arcane.iris.engine.object.TestSettings;
import com.volmit.FeatureAttachment.Target;
import com.volmit.config.Level;
import com.volmit.IrisFeature;
import com.volmit.block.BlockState;
import com.volmit.config.FeatureSettings;
import com.volmit.config.SettingsStack;
import com.volmit.resource.ResourceId;
import org.junit.Test;
@@ -35,10 +36,11 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class DepositModuleTest {
private static final int CENTRE = 7;
private static final int COLUMN_X = 39;
private static final int COLUMN_Z = -9;
@Test
public void everyLevelAtTheCentreColumnStacksInLevelOrder() {
public void everyLevelAtTheColumnStacksInLevelOrder() {
DepositGenerator dimension = new DepositGenerator();
DepositGenerator region = new DepositGenerator();
DepositGenerator biome = new DepositGenerator();
@@ -46,20 +48,20 @@ public class DepositModuleTest {
FeatureSettings settings = new FeatureSettings() {
@Override
@SuppressWarnings("unchecked")
public <F extends IrisFeature> List<Entry<F>> at(Class<F> type, int worldX, int worldZ) {
if (worldX != 32 + CENTRE || worldZ != -16 + CENTRE) {
return List.of((Entry<F>) entry(Target.BIOME, "biome/other", elsewhere));
public <F extends IrisFeature> SettingsStack<F> at(Class<F> type, int worldX, int worldZ) {
if (worldX != COLUMN_X || worldZ != COLUMN_Z) {
return SettingsStack.of(List.of((Entry<F>) entry(Level.BIOME, "biome/other", elsewhere)));
}
return List.of((Entry<F>) entry(Target.DIMENSION, "dimension/overworld", dimension),
(Entry<F>) entry(Target.REGION, "region/hot", region),
(Entry<F>) entry(Target.BIOME, "biome/desert", biome));
return SettingsStack.of(List.of((Entry<F>) entry(Level.DIMENSION, "dimension/overworld", dimension),
(Entry<F>) entry(Level.REGION, "region/hot", region),
(Entry<F>) entry(Level.BIOME, "biome/desert", biome)));
}
};
assertEquals(List.of(dimension, region, biome), DepositModule.generatorsAtCentre(settings, 32, -16));
assertEquals(List.of(dimension, region, biome), DepositModule.generatorsAt(settings, COLUMN_X, COLUMN_Z));
}
private static FeatureSettings.Entry<DepositSettings> entry(Target level, String source, DepositGenerator generator) {
private static FeatureSettings.Entry<DepositSettings> entry(Level level, String source, DepositGenerator generator) {
return new FeatureSettings.Entry<>(level, ResourceId.parse("pack:" + source), new DepositSettings(List.of(generator)));
}
@@ -7,6 +7,7 @@ import art.arcane.iris.engine.decorator.BiomeDecorators;
import com.volmit.block.BlockState;
import com.volmit.config.FeatureSettings;
import com.volmit.config.PackSettings;
import com.volmit.config.SettingsStack;
import com.volmit.host.ModuleLogs;
import com.volmit.hunk.Hunk;
import com.volmit.resource.PackResources;
@@ -44,7 +45,9 @@ public class FloatingIslandsTest {
when(context.originZ()).thenReturn(CHUNK_ORIGIN);
when(context.world()).thenReturn(world);
when(context.hunk(BlockState.class)).thenReturn(output);
when(context.settings()).thenReturn(mock(FeatureSettings.class));
FeatureSettings nothingConfigured = mock(FeatureSettings.class);
when(nothingConfigured.at(any(), anyInt(), anyInt())).thenAnswer(invocation -> SettingsStack.empty());
when(context.settings()).thenReturn(nothingConfigured);
when(context.mantle()).thenReturn(null);
FloatingIslands islands = FloatingIslands.of(world, ModuleLogs.discarding());
@@ -61,7 +64,9 @@ public class FloatingIslandsTest {
when(((FloatingHost.Source) world).floating()).thenReturn(host);
when(((ObjectHost.Source) world).objects()).thenReturn(mock(ObjectHost.class));
when(world.resources()).thenReturn(mock(PackResources.class));
when(world.settings()).thenReturn(mock(PackSettings.class));
PackSettings nothingDeclared = mock(PackSettings.class);
when(nothingDeclared.declared(any())).thenAnswer(invocation -> SettingsStack.empty());
when(world.settings()).thenReturn(nothingDeclared);
when(world.state(any(), any())).thenAnswer(invocation -> {
Class<?> type = invocation.getArgument(0);
if (type == BiomeDecorators.class) {
@@ -103,6 +103,7 @@ public class IrisObjectPlacementRegressionTest {
BuiltInPack.seedWorld(engine, 7L);
data = mock(IrisData.class);
when(data.getEngine()).thenReturn(engine);
when(engine.getData()).thenReturn(data);
usePack(List.of());
solid = registryState("minecraft:stone");
schematicAir = registryState("minecraft:air");
@@ -438,17 +439,17 @@ public class IrisObjectPlacementRegressionTest {
@Override
public void setup(ModuleSetup setup) {
setup.stages().define(FIND).requires(IrisStages.Blocks.COMPLETE).run(context ->
found.add(context.resources().find(PackResourceFixture.oakKey(packFolder)).orElseThrow()));
found.add(context.world().resources().find(PackResourceFixture.oakKey(packFolder)).orElseThrow()));
}
}
@Test
public void aPlacementStageFindsTheSnapshotsPackResources() throws IOException {
PackResourceFixture.serve(data);
public void aPasteWithoutAnEngineFindsThePacksResourcesThroughItsWorld() throws IOException {
List<Object> found = new ArrayList<>();
usePack(List.of(new FindModule(folder.getRoot(), found)));
PackResourceFixture.serve(data);
ObjectPlacementResult result = place(placement(), ANCHOR_Y, new RecordingPlacer(engine), null);
ObjectPlacementResult result = place(placement(), ANCHOR_Y, new RecordingPlacer(null), null);
assertTrue(result.isPlaced());
assertEquals(List.of(PackResourceFixture.OAK), found);
@@ -526,18 +527,18 @@ public class IrisObjectPlacementRegressionTest {
@Override
public void setup(ModuleSetup setup) {
setup.stages().define(TURN).requires(IrisStages.Blocks.COMPLETE).run(context -> turned.add(context.objects().transform(
context.resources().require(PackResourceFixture.oakKey(packFolder)),
context.world().resources().require(PackResourceFixture.oakKey(packFolder)),
new ObjectTransform(90, 0, 0, 1, 1, 1, false, false, false))));
}
}
@Test
public void aPlacementStageTurnsAnObjectThroughTheObjectTransformer() throws IOException {
PackResourceFixture.serve(data);
List<GeneratedObject> turned = new ArrayList<>();
usePack(List.of(new TurnModule(folder.getRoot(), turned)));
PackResourceFixture.serve(data);
ObjectPlacementResult result = place(placement(), ANCHOR_Y, new RecordingPlacer(engine), null);
ObjectPlacementResult result = place(placement(), ANCHOR_Y, new RecordingPlacer(null), null);
assertTrue(result.isPlaced());
assertEquals(List.of(new BlockPosition(0, 0, 0), new BlockPosition(0, 0, 1)),
@@ -86,6 +86,7 @@ public class IrisObjectSurfaceSupportPlacementTest {
BuiltInPack.seedWorld(engine, 7L);
data = mock(IrisData.class);
when(data.getEngine()).thenReturn(engine);
when(engine.getData()).thenReturn(data);
pack = BuiltInPack.serve(data, folder, List.of());
}
@@ -78,6 +78,7 @@ public class ObjectPlaceModePinTest {
BuiltInPack.seedWorld(engine, WORLD_SEED);
data = mock(IrisData.class);
when(data.getEngine()).thenReturn(engine);
when(engine.getData()).thenReturn(data);
pack = BuiltInPack.serve(data, folder, List.of());
}
@@ -84,6 +84,7 @@ public class NativeStructureObjectVetoTest {
BuiltInPack.seedWorld(engine, 7L);
data = mock(IrisData.class);
when(data.getEngine()).thenReturn(engine);
when(engine.getData()).thenReturn(data);
pack = BuiltInPack.serve(data, folder, List.of());
}
@@ -20,12 +20,13 @@ package art.arcane.iris.engine.terrain;
import art.arcane.iris.builtin.IrisSeed;
import art.arcane.iris.core.modules.ModuleSettings;
import com.volmit.FeatureAttachment.Target;
import com.volmit.config.Level;
import com.volmit.IrisFeature;
import com.volmit.ModuleLog;
import com.volmit.config.FeatureSettings;
import com.volmit.config.FeatureSettings.Entry;
import com.volmit.config.PackSettings;
import com.volmit.config.SettingsStack;
import com.volmit.host.ModuleLogs;
import com.volmit.resource.PackResources;
import com.volmit.resource.ResourceId;
@@ -49,9 +50,8 @@ public final class TestPackWorld implements PackWorld, IrisSeed.Source {
public TestPackWorld(PackResources resources, ModuleSettings dimensionSettings, long seed) {
this(resources, new PackSettings() {
@Override
public <F extends IrisFeature> List<Entry<F>> declared(Class<F> featureType) {
Optional<F> found = dimensionSettings.find(featureType);
return found.map(value -> List.of(new Entry<>(Target.DIMENSION, DIMENSION, value))).orElse(List.of());
public <F extends IrisFeature> SettingsStack<F> declared(Class<F> featureType) {
return dimensionStack(dimensionSettings, featureType);
}
}, seed);
}
@@ -67,12 +67,17 @@ public final class TestPackWorld implements PackWorld, IrisSeed.Source {
public static FeatureSettings dimensionLevel(ModuleSettings settings) {
return new FeatureSettings() {
@Override
public <F extends IrisFeature> List<Entry<F>> at(Class<F> featureType, int worldX, int worldZ) {
return settings.find(featureType).map(value -> List.of(new Entry<>(Target.DIMENSION, DIMENSION, value))).orElse(List.of());
public <F extends IrisFeature> SettingsStack<F> at(Class<F> featureType, int worldX, int worldZ) {
return dimensionStack(settings, featureType);
}
};
}
private static <F extends IrisFeature> SettingsStack<F> dimensionStack(ModuleSettings settings, Class<F> featureType) {
return settings.find(featureType).map(value -> SettingsStack.of(List.of(new Entry<>(Level.DIMENSION, DIMENSION, value))))
.orElseGet(SettingsStack::empty);
}
@Override
public long seed() {
return seed;