mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Read settings per column with every level as its own entry, add the mantle pipeline, host types and the one-option shorthand
Settings no longer resolve to one value per type. FeatureSettings.at(type, x, z) returns one entry per level that declares the type at that column (dimension, region, surface biome, placement), each with its level, source and value; levels stack and a module decides what several mean. Conditional stage bodies receive every configured entry. Chunk and mantle runners collect a chunk's settings themselves, so a stage runs when any column of the chunk configures it. Work that writes the mantle or reaches beyond its chunk moves to a new MANTLE pipeline (Stage.mantle, MantleRunner) that the host runs around a chunk before it generates. Chunk stages may no longer declare a reach or mantle writes and see the mantle read-only. Built-in settings may hold host types the host describes itself (ModuleHost.describingHostTypesIn, ValueKind.HostKind); pack modules cannot. FeatureSchema.shorthand() names the only option of settings packs may write as a bare value.
This commit is contained in:
1 parent
09df1af88e
commit
97ac2a2982
61 files changed
+1316
-184
No files matched your search
@@ -0,0 +1,32 @@
|
||||
package com.volmit.support;
|
||||
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.config.FeatureSettings;
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
/** Settings declared per world column by a function, for chunk and mantle tests. */
|
||||
public final class ColumnSettings implements FeatureSettings {
|
||||
public static final ColumnSettings NONE = new ColumnSettings((x, z) -> List.of());
|
||||
|
||||
private final BiFunction<Integer, Integer, List<Entry<?>>> columns;
|
||||
|
||||
public ColumnSettings(BiFunction<Integer, Integer, List<Entry<?>>> columns) {
|
||||
this.columns = columns;
|
||||
}
|
||||
|
||||
/** The same entries at every column. */
|
||||
public static ColumnSettings everywhere(Entry<?>... entries) {
|
||||
var all = List.of(entries);
|
||||
return new ColumnSettings((x, z) -> all);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked") // Filtered by the requested type.
|
||||
public <F extends IrisFeature> List<Entry<F>> at(Class<F> featureType, int worldX, int worldZ) {
|
||||
return columns.apply(worldX, worldZ).stream()
|
||||
.filter(entry -> featureType.isInstance(entry.value()))
|
||||
.map(entry -> (Entry<F>) entry)
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.volmit.support;
|
||||
|
||||
import com.volmit.mantle.BlockBox;
|
||||
import com.volmit.mantle.Mantle;
|
||||
import com.volmit.mantle.MantleEdit;
|
||||
import com.volmit.mantle.MantleKey;
|
||||
import com.volmit.mantle.MantleLayer;
|
||||
import com.volmit.mantle.MantleVisitor;
|
||||
import com.volmit.world.BlockPosition;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/** An in-memory mantle over fixed bounds; an invocation sees it through {@link #within(BlockBox)}. */
|
||||
public final class MemoryMantle {
|
||||
private static final Comparator<BlockPosition> VISIT_ORDER = Comparator.comparingInt(BlockPosition::x)
|
||||
.thenComparingInt(BlockPosition::y).thenComparingInt(BlockPosition::z);
|
||||
|
||||
private final Map<String, TreeMap<BlockPosition, Object>> layers = new HashMap<>();
|
||||
|
||||
/** A view that accepts reads and writes inside {@code bounds} only. */
|
||||
public Mantle within(BlockBox bounds) {
|
||||
return new Mantle() {
|
||||
public BlockBox bounds() { return bounds; }
|
||||
public <T> MantleLayer<T> layer(MantleKey<T> key) { return new Layer<>(key, bounds); }
|
||||
public MantleEdit edit() { throw new UnsupportedOperationException("Edits are not used in these tests"); }
|
||||
};
|
||||
}
|
||||
|
||||
public <T> T get(MantleKey<T> key, int x, int y, int z) {
|
||||
return key.type().cast(values(key).get(new BlockPosition(x, y, z)));
|
||||
}
|
||||
|
||||
private TreeMap<BlockPosition, Object> values(MantleKey<?> key) {
|
||||
return layers.computeIfAbsent(key.id(), ignored -> new TreeMap<>(VISIT_ORDER));
|
||||
}
|
||||
|
||||
private final class Layer<T> implements MantleLayer<T> {
|
||||
private final MantleKey<T> key;
|
||||
private final BlockBox bounds;
|
||||
|
||||
Layer(MantleKey<T> key, BlockBox bounds) {
|
||||
this.key = key;
|
||||
this.bounds = bounds;
|
||||
}
|
||||
|
||||
public T get(int x, int y, int z) {
|
||||
requireInside(x, y, z);
|
||||
return MemoryMantle.this.get(key, x, y, z);
|
||||
}
|
||||
|
||||
public void set(int x, int y, int z, T value) {
|
||||
requireInside(x, y, z);
|
||||
values(key).put(new BlockPosition(x, y, z), key.type().cast(value));
|
||||
}
|
||||
|
||||
public void remove(int x, int y, int z) {
|
||||
requireInside(x, y, z);
|
||||
values(key).remove(new BlockPosition(x, y, z));
|
||||
}
|
||||
|
||||
public void visit(BlockBox area, MantleVisitor<T> visitor) {
|
||||
if (!bounds.contains(area)) throw new IndexOutOfBoundsException("Outside the mantle view: " + area);
|
||||
values(key).forEach((position, value) -> {
|
||||
if (area.contains(position.x(), position.y(), position.z())) {
|
||||
visitor.accept(position.x(), position.y(), position.z(), key.type().cast(value));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void clear(BlockBox area) {
|
||||
if (!bounds.contains(area)) throw new IndexOutOfBoundsException("Outside the mantle view: " + area);
|
||||
values(key).keySet().removeIf(position -> area.contains(position.x(), position.y(), position.z()));
|
||||
}
|
||||
|
||||
private void requireInside(int x, int y, int z) {
|
||||
if (!bounds.contains(x, y, z)) throw new IndexOutOfBoundsException("Outside the mantle view: " + x + "," + y + "," + z);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.volmit.support;
|
||||
|
||||
import com.volmit.config.FeatureSettings;
|
||||
import com.volmit.generation.GenerationContext;
|
||||
import com.volmit.generation.MantleGenerationContext;
|
||||
import com.volmit.hunk.Hunk;
|
||||
import com.volmit.mantle.Mantle;
|
||||
import com.volmit.object.ObjectTransformer;
|
||||
@@ -18,6 +19,11 @@ public final class TestContexts {
|
||||
private TestContexts() {}
|
||||
|
||||
public static GenerationContext generation(Map<Class<?>, Hunk<?>> hunks) {
|
||||
return generation(hunks, null, null);
|
||||
}
|
||||
|
||||
/** The chunk at the origin; a null {@code settings} or {@code mantle} fails when used. */
|
||||
public static GenerationContext generation(Map<Class<?>, Hunk<?>> hunks, FeatureSettings settings, Mantle mantle) {
|
||||
return new GenerationContext() {
|
||||
public int originX() { return 0; }
|
||||
public int originY() { return -64; }
|
||||
@@ -25,8 +31,8 @@ public final class TestContexts {
|
||||
public long worldSeed() { return SEED; }
|
||||
public PackResources resources() { throw new AssertionError("Unused resources"); }
|
||||
public TerrainSampler terrain() { throw new AssertionError("Unused terrain"); }
|
||||
public FeatureSettings settings() { throw new AssertionError("Unused settings"); }
|
||||
public Mantle mantle() { throw new AssertionError("Unused mantle"); }
|
||||
public FeatureSettings settings() { return used(settings, "settings"); }
|
||||
public Mantle mantle() { return used(mantle, "mantle"); }
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> Hunk<T> hunk(Class<T> type) {
|
||||
var hunk = hunks.get(type);
|
||||
@@ -36,6 +42,19 @@ public final class TestContexts {
|
||||
};
|
||||
}
|
||||
|
||||
/** The mantle invocation of the chunk whose first block is ({@code originX}, {@code originZ}). */
|
||||
public static MantleGenerationContext mantle(int originX, int originZ, FeatureSettings settings, Mantle mantle) {
|
||||
return new MantleGenerationContext() {
|
||||
public int originX() { return originX; }
|
||||
public int originZ() { return originZ; }
|
||||
public long worldSeed() { return SEED; }
|
||||
public PackResources resources() { throw new AssertionError("Unused resources"); }
|
||||
public TerrainSampler terrain() { throw new AssertionError("Unused terrain"); }
|
||||
public FeatureSettings settings() { return settings; }
|
||||
public Mantle mantle() { return mantle; }
|
||||
};
|
||||
}
|
||||
|
||||
public static PlacementContext placement() {
|
||||
return placement(null);
|
||||
}
|
||||
@@ -53,4 +72,9 @@ public final class TestContexts {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static <T> T used(T value, String name) {
|
||||
if (value == null) throw new AssertionError("Unused " + name);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user