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:
piexel committed 2026-10-08 11:31:03 +02:00
1 parent 09df1af88e
commit 97ac2a2982
61 files changed
+1316 -184

No files matched your search

@@ -4,23 +4,35 @@ import com.volmit.FeatureAttachment;
import com.volmit.IrisFeature;
import com.volmit.resource.ResourceId;
import java.util.List;
import java.util.Objects;
/** Invocation-scoped lookup of applicable settings by attachment and world position.
* Results are immutable lists in pack declaration order, after the host applies inheritance
* rules. Targets remain separate: this interface never silently merges dimension/region/biome
* values. OBJECT_PLACEMENT is read from the current placement, or returns an empty list.
* Values must be treated as read-only. Bounds and lifetime match the invocation's sampler.
/** Invocation-scoped lookup of the settings that apply at one world column.
*
* <p>Every level that declares the settings contributes its own entry: the dimension, the region and
* the biome of the column, and in a placement the placement itself. Levels stack: nothing is merged or
* overridden, and a module decides what several entries mean, such as running a deposit once per
* entry. Entries are immutable lists in level order ({@link FeatureAttachment.Target} order). The
* biome is the column's surface biome; cave biomes are not a level. Values must be treated as
* read-only. Bounds and lifetime match the invocation's sampler.
*
* <p>Something that spans several columns, such as a chunk-wide pass or a placed object, reads the
* settings at one column it treats as its origin; per-chunk behaviour reads the chunk's centre column
* (local 7, 7).
*/
public interface FeatureSettings {
<F extends IrisFeature> List<Entry<F>> at(Class<F> featureType, FeatureAttachment.Target target,
int worldX, int worldY, int worldZ);
<F extends IrisFeature> List<Entry<F>> at(Class<F> featureType, int worldX, int worldZ);
/** source identifies the configuration owner; occurrence is unique within the pack snapshot. */
record Entry<F extends IrisFeature>(ResourceId source, ResourceId occurrence, F value) {
/** One level's declaration of the settings.
*
* @param level where the settings are declared: the dimension, a region, a biome or the placement
* @param source the resource that declares them, such as {@code overworld:biome/desert/dunes}
* @param value the decoded settings
*/
record Entry<F extends IrisFeature>(FeatureAttachment.Target level, ResourceId source, F value) {
public Entry {
java.util.Objects.requireNonNull(source, "source");
java.util.Objects.requireNonNull(occurrence, "occurrence");
java.util.Objects.requireNonNull(value, "value");
Objects.requireNonNull(level, "level");
Objects.requireNonNull(source, "source");
Objects.requireNonNull(value, "value");
}
}
}
@@ -15,7 +15,9 @@ public interface GenerationContext extends InvocationContext {
TerrainSampler terrain();
FeatureSettings settings();
/** Non-null mantle access scoped to this invocation; the host owns its lifetime. */
/** Non-null mantle access scoped to this invocation; the host owns its lifetime. Chunk stages read it
* only: the mantle pipeline has finished around the chunk, and writes throw.
*/
Mantle mantle();
/** The host-owned local volume of the given value type, shared by all stages of this
@@ -0,0 +1,21 @@
package com.volmit.generation;
import com.volmit.config.FeatureSettings;
import com.volmit.mantle.Mantle;
import com.volmit.world.TerrainSampler;
/** Per-invocation inputs of the mantle pipeline for one chunk. Must not be retained after execution. */
public interface MantleGenerationContext extends InvocationContext {
/** The chunk's first block along X, in world coordinates. */
int originX();
/** The chunk's first block along Z, in world coordinates. */
int originZ();
TerrainSampler terrain();
FeatureSettings settings();
/** The mantle of the chunk widened by the pipeline's reach, full height. Writes outside it throw. */
Mantle mantle();
}
@@ -11,7 +11,7 @@ import com.volmit.stage.Stage;
import com.volmit.world.TerrainSampler;
import java.util.Objects;
/** The context every stage of one chunk invocation receives. */
/** The context every stage of one chunk invocation receives. The mantle is read-only. */
final class ChunkInvocation implements ChunkStageContext {
private final StageInvocation stages;
private final GenerationContext inputs;
@@ -57,7 +57,7 @@ final class ChunkInvocation implements ChunkStageContext {
@Override
public Mantle mantle() {
return inputs.mantle();
return new ReadOnlyMantle(inputs.mantle());
}
@Override
+10 -4
View File
@@ -6,7 +6,7 @@ import java.util.Objects;
/** Reference executor of a resolved chunk graph: active stages run once, in resolved order.
* It does not schedule neighbors or roll back hunks; a failed invocation must prevent the host
* from publishing the chunk.
* from publishing the chunk. Stages see the mantle read-only.
*/
public final class ChunkRunner {
private final ResolvedGraph graph;
@@ -18,10 +18,16 @@ public final class ChunkRunner {
}
}
/** Runs one chunk. The host derives {@code invocationSeed} from the world seed and the chunk
* position; each stage draws from its own stream of that seed ({@link StageStreams}).
/** Runs one chunk. A conditional stage is active when any of the chunk's 16 by 16 columns has an
* entry of its settings in {@code inputs.settings()}, and receives every distinct entry of those
* columns. The host derives {@code invocationSeed} from the world seed and the chunk position; each
* stage draws from its own stream of that seed ({@link StageStreams}).
*/
public void generate(GenerationContext inputs, long invocationSeed, ConfiguredSettings settings) {
public void generate(GenerationContext inputs, long invocationSeed) {
if (graph.size() == 0) {
return;
}
var settings = ChunkSettings.collect(graph, inputs::settings, inputs.originX(), inputs.originZ());
var chunk = new ChunkInvocation(new StageInvocation(graph, invocationSeed, settings), inputs);
for (int position = 0; position < graph.size(); position++) {
chunk.stages().runInvocationStage(position, chunk);
@@ -0,0 +1,51 @@
package com.volmit.host;
import com.volmit.FeatureAttachment;
import com.volmit.IrisFeature;
import com.volmit.config.FeatureSettings;
import com.volmit.config.FeatureSettings.Entry;
import com.volmit.resource.ResourceId;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.function.Supplier;
/** The settings one chunk's stages see: for every settings type the graph conditions on, each distinct
* entry of the chunk's 16 by 16 columns. A stage is therefore active when any column of the chunk
* configures its settings, also where a biome border crosses the chunk. Entries are distinct by level
* and source and keep the order their first column was read in, columns by X and then Z.
*/
final class ChunkSettings {
/** The chunk's width along X and Z, in blocks: the footprint of chunk and mantle stages. */
static final int CHUNK_WIDTH = 16;
private ChunkSettings() {}
/** {@code settings} is asked only when the graph conditions a stage on settings. */
static ConfiguredSettings collect(ResolvedGraph graph, Supplier<FeatureSettings> settings, int originX, int originZ) {
if (graph.settingsTypes().isEmpty()) {
return ConfiguredSettings.none();
}
var view = settings.get();
var entries = new ArrayList<Entry<?>>();
for (var type : graph.settingsTypes()) {
entries.addAll(distinctEntries(type.asSubclass(IrisFeature.class), view, originX, originZ));
}
return ConfiguredSettings.of(entries);
}
private static Collection<Entry<?>> distinctEntries(
Class<? extends IrisFeature> type, FeatureSettings view, int originX, int originZ) {
var distinct = new LinkedHashMap<Declaration, Entry<?>>();
for (int x = 0; x < CHUNK_WIDTH; x++) {
for (int z = 0; z < CHUNK_WIDTH; z++) {
for (var entry : view.at(type, originX + x, originZ + z)) {
distinct.putIfAbsent(new Declaration(entry.level(), entry.source()), entry);
}
}
}
return distinct.values();
}
private record Declaration(FeatureAttachment.Target level, ResourceId source) {}
}
@@ -1,41 +1,66 @@
package com.volmit.host;
import com.volmit.FeatureAttachment;
import com.volmit.IrisFeature;
import com.volmit.config.FeatureSettings.Entry;
import com.volmit.resource.ResourceId;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
/** Feature settings configured for one invocation: the placement's settings, or the settings
* the host resolved for a chunk. At most one value per type; merging and precedence between
* dimension/region/biome/placement declarations stay host policy. Build once and reuse it for
* every invocation with the same configuration.
/** The settings entries configured for one invocation, per settings type, in level order. A stage
* conditioned on a type is active when the type has at least one entry, and its body receives them
* all. For a placement these are the placement's own declarations; for a chunk the runners collect
* every distinct entry of the chunk's columns themselves. Build once and reuse it for every invocation
* with the same configuration.
*/
public final class ConfiguredSettings {
private static final ConfiguredSettings NONE = new ConfiguredSettings(Map.of());
private static final Comparator<Entry<?>> LEVEL_ORDER = Comparator.comparing(Entry::level);
private final Map<Class<?>, IrisFeature> values;
private final Map<Class<?>, List<Entry<?>>> entries;
private ConfiguredSettings(Map<Class<?>, IrisFeature> values) {
this.values = Map.copyOf(values);
private ConfiguredSettings(Map<Class<?>, List<Entry<?>>> entries) {
this.entries = Map.copyOf(entries);
}
public static ConfiguredSettings none() {
return NONE;
}
public static ConfiguredSettings of(IrisFeature... settings) {
var values = new HashMap<Class<?>, IrisFeature>();
for (var value : settings) {
Objects.requireNonNull(value, "settings");
if (values.putIfAbsent(value.getClass(), value) != null) {
throw new IllegalArgumentException("Settings configured twice: " + value.getClass().getName());
}
/** These entries, grouped by settings type, each group in level order and otherwise as given. */
public static ConfiguredSettings of(List<? extends Entry<?>> entries) {
var grouped = new HashMap<Class<?>, List<Entry<?>>>();
for (var entry : entries) {
Objects.requireNonNull(entry, "entry");
grouped.computeIfAbsent(entry.value().getClass(), ignored -> new ArrayList<>()).add(entry);
}
return new ConfiguredSettings(values);
grouped.replaceAll((type, group) -> group.stream().sorted(LEVEL_ORDER).toList());
return grouped.isEmpty() ? NONE : new ConfiguredSettings(grouped);
}
public <S extends IrisFeature> Optional<S> find(Class<S> type) {
return Optional.ofNullable(type.cast(values.get(type)));
/** One placement's own settings, at most one value per type, declared by {@code source}. */
public static ConfiguredSettings placement(ResourceId source, IrisFeature... settings) {
Objects.requireNonNull(source, "source");
var entries = new ArrayList<Entry<?>>();
var types = new HashMap<Class<?>, IrisFeature>();
for (var value : settings) {
Objects.requireNonNull(value, "settings");
if (types.putIfAbsent(value.getClass(), value) != null) {
throw new IllegalArgumentException("Settings configured twice: " + value.getClass().getName());
}
entries.add(new Entry<>(FeatureAttachment.Target.OBJECT_PLACEMENT, source, value));
}
return of(entries);
}
/** The entries of {@code type}, in level order; empty when nothing configures it. */
@SuppressWarnings("unchecked") // Entries are grouped by the class of their value.
public <S extends IrisFeature> List<Entry<S>> find(Class<S> type) {
var found = entries.get(type);
return found == null ? List.of() : (List<Entry<S>>) (List<?>) found;
}
}
@@ -5,6 +5,7 @@ import com.volmit.host.schema.ValueKind;
import com.volmit.host.schema.ValueKind.BooleanKind;
import com.volmit.host.schema.ValueKind.DecimalKind;
import com.volmit.host.schema.ValueKind.EnumKind;
import com.volmit.host.schema.ValueKind.HostKind;
import com.volmit.host.schema.ValueKind.IntegerKind;
import com.volmit.host.schema.ValueKind.ListKind;
import com.volmit.host.schema.ValueKind.MapKind;
@@ -45,6 +46,7 @@ final class DefaultValues {
case ListKind list -> list(elements(value), list);
case MapKind map -> map((Map<?, ?>) value, map.value());
case ObjectKind object -> object(value, types.get(object.type()));
case HostKind _ -> Optional.empty();
};
}
@@ -0,0 +1,32 @@
package com.volmit.host;
import com.volmit.PackageName;
import java.util.Collection;
import java.util.List;
/** Classes the host describes in studio itself, such as Iris's palettes and noise styles, which built-in
* settings may hold. Given as packages, each with its subpackages. Pack modules cannot use them.
*/
final class HostTypes {
static final HostTypes NONE = new HostTypes(List.of());
private final List<PackageName> packages;
private HostTypes(List<PackageName> packages) {
this.packages = packages;
}
static HostTypes of(Collection<String> packages) {
return new HostTypes(packages.stream().map(HostTypes::parse).toList());
}
boolean contains(Class<?> type) {
var name = type.getName();
return packages.stream().anyMatch(packageName -> packageName.contains(name));
}
private static PackageName parse(String name) {
return PackageName.tryParse(name).orElseThrow(() -> new IllegalArgumentException(
"Host type package '" + name + "' is not a package name, such as art.arcane.iris.engine.object"));
}
}
@@ -13,12 +13,14 @@ import java.util.Set;
* settings types stages are conditioned on), its description for studio and one resolved graph per
* pipeline.
*/
public record LoadedModules(FeatureCatalog catalog, PackSchema schema, ResolvedGraph placement, ResolvedGraph chunk) {
public record LoadedModules(
FeatureCatalog catalog, PackSchema schema, ResolvedGraph placement, ResolvedGraph chunk, ResolvedGraph mantle) {
public LoadedModules {
Objects.requireNonNull(catalog, "catalog");
Objects.requireNonNull(schema, "schema");
Objects.requireNonNull(placement, "placement");
Objects.requireNonNull(chunk, "chunk");
Objects.requireNonNull(mantle, "mantle");
}
/** Pass the built-in modules together with {@link PackModules#modules()} of the pack.
@@ -26,11 +28,14 @@ public record LoadedModules(FeatureCatalog catalog, PackSchema schema, ResolvedG
* @param reservedHostFields JSON fields the host itself uses, per attachment target
* @param reservedNamespaces namespaces only built-in modules may use, such as {@code iris}; a
* pack module whose id uses one fails the load
* @param hostTypePackages packages whose classes the host describes itself, each with its
* subpackages; only built-in modules' settings may use them (see {@link ModuleHost#describingHostTypesIn})
*/
public static LoadedModules load(
List<DiscoveredModule> modules,
Map<FeatureAttachment.Target, Set<String>> reservedHostFields,
Collection<String> reservedNamespaces) {
Collection<String> reservedNamespaces,
Collection<String> hostTypePackages) {
var reserved = ReservedNamespaces.of(reservedNamespaces);
modules.forEach(reserved::requireAllowed);
var registry = new ModuleRegistry(reservedHostFields);
@@ -40,12 +45,13 @@ public record LoadedModules(FeatureCatalog catalog, PackSchema schema, ResolvedG
}
stages.settingsTypes(registry::registeredByOwner).forEach(registry::registerStageSettings);
var catalog = registry.freeze();
var schema = PackSchemaBuilder.describe(catalog, modules);
var schema = PackSchemaBuilder.describe(catalog, modules, HostTypes.of(hostTypePackages));
var placement = stages.resolve(Pipeline.PLACEMENT);
var chunk = stages.resolve(Pipeline.CHUNK);
var mantle = stages.resolve(Pipeline.MANTLE);
requireRegisteredMantleLayers(catalog, placement);
requireRegisteredMantleLayers(catalog, chunk);
return new LoadedModules(catalog, schema, placement, chunk);
requireRegisteredMantleLayers(catalog, mantle);
return new LoadedModules(catalog, schema, placement, chunk, mantle);
}
/** A stage's reach names the layers it writes; a layer nobody registered has no codec or lifetime. */
@@ -29,7 +29,7 @@ public final class LoadedPack implements AutoCloseable {
this.loaded = loaded;
}
/** Loads the pack's module jars, installs them with the host's built-in modules and resolves both
/** Loads the pack's module jars, installs them with the host's built-in modules and resolves the
* pipelines. Fails with the first load error, naming the jar or module at fault.
*/
public static LoadedPack load(Path packRoot, ModuleHost host) {
@@ -37,7 +37,7 @@ public final class LoadedPack implements AutoCloseable {
var packModules = PackModules.load(packRoot, host.exposedHostPackages(), host.jarCopyRoot(), host.logger());
try {
var loaded = LoadedModules.load(host.withPackModules(packModules.modules()),
host.reservedHostFields(), host.reservedNamespaces());
host.reservedHostFields(), host.reservedNamespaces(), host.hostTypePackages());
return new LoadedPack(packModules, loaded);
} catch (RuntimeException | Error failure) {
closeAfterFailure(packModules, failure);
@@ -74,6 +74,10 @@ public final class LoadedPack implements AutoCloseable {
return loaded.chunk();
}
public ResolvedGraph mantle() {
return loaded.mantle();
}
@Override
public void close() {
packModules.close();
@@ -0,0 +1,71 @@
package com.volmit.host;
import com.volmit.config.FeatureSettings;
import com.volmit.generation.MantleGenerationContext;
import com.volmit.mantle.Mantle;
import com.volmit.random.WorldRandom;
import com.volmit.resource.PackResources;
import com.volmit.stage.MantleStageContext;
import com.volmit.stage.Stage;
import com.volmit.world.TerrainSampler;
import java.util.Objects;
/** The context every stage of one mantle invocation receives. */
final class MantleInvocation implements MantleStageContext {
private final StageInvocation stages;
private final MantleGenerationContext inputs;
MantleInvocation(StageInvocation stages, MantleGenerationContext inputs) {
this.stages = stages;
this.inputs = Objects.requireNonNull(inputs, "inputs");
}
StageInvocation stages() {
return stages;
}
@Override
public <O> O output(Stage<O> stage) {
return stages.output(stage);
}
@Override
public int originX() {
return inputs.originX();
}
@Override
public int originZ() {
return inputs.originZ();
}
@Override
public TerrainSampler terrain() {
return inputs.terrain();
}
@Override
public FeatureSettings settings() {
return inputs.settings();
}
@Override
public Mantle mantle() {
return inputs.mantle();
}
@Override
public long worldSeed() {
return inputs.worldSeed();
}
@Override
public PackResources resources() {
return inputs.resources();
}
@Override
public WorldRandom random() {
return stages.random();
}
}
@@ -0,0 +1,36 @@
package com.volmit.host;
import com.volmit.generation.MantleGenerationContext;
import com.volmit.stage.Pipeline;
import java.util.Objects;
/** Reference executor of a resolved mantle graph: active stages run once per chunk, in resolved order.
* The host runs it for every chunk within the pipeline's reach of a chunk before that chunk generates,
* each chunk once, and gives it the mantle around the chunk as far as that reach. It does not roll back
* mantle writes; a failed invocation must stop the host from generating the chunks it reaches.
*/
public final class MantleRunner {
private final ResolvedGraph graph;
public MantleRunner(ResolvedGraph graph) {
this.graph = Objects.requireNonNull(graph, "graph");
if (graph.pipeline() != Pipeline.MANTLE) {
throw new IllegalArgumentException("Expected a mantle graph, got " + graph.pipeline());
}
}
/** Runs the mantle stages of one chunk. A conditional stage is active when any of the chunk's
* 16 by 16 columns has an entry of its settings, and receives every distinct entry of those columns.
* The host derives {@code invocationSeed} from the world seed and the chunk position.
*/
public void generate(MantleGenerationContext inputs, long invocationSeed) {
if (graph.size() == 0) {
return;
}
var settings = ChunkSettings.collect(graph, inputs::settings, inputs.originX(), inputs.originZ());
var mantle = new MantleInvocation(new StageInvocation(graph, invocationSeed, settings), inputs);
for (int position = 0; position < graph.size(); position++) {
mantle.stages().runInvocationStage(position, mantle);
}
}
}
+25 -9
View File
@@ -14,7 +14,8 @@ import java.util.TreeSet;
/** The host's side of every pack load, the same for all packs: its built-in modules, the host
* packages pack modules may use besides the Iris API, the JSON fields the host itself uses (which no
* built-in alias may take), and the namespaces only built-in modules may use. Build it once and pass it to every
* built-in alias may take), the namespaces only built-in modules may use and the packages of the
* classes the host describes itself. Build it once and pass it to every
* {@link LoadedPack#load(java.nio.file.Path, ModuleHost)}.
*
* <pre>{@code
@@ -25,8 +26,8 @@ import java.util.TreeSet;
* }</pre>
*
* Every method adds to what earlier calls configured, so a host can build the configuration in steps.
* Built-in modules' {@code info()} is read here, once. Exposed package names, reserved namespaces and
* reserved field names are checked here, so a mistake fails when the host starts rather than at the
* Built-in modules' {@code info()} is read here, once. Exposed package names, reserved namespaces,
* host type packages and reserved field names are checked here, so a mistake fails when the host starts rather than at the
* first pack load.
*/
public record ModuleHost(
@@ -34,6 +35,7 @@ public record ModuleHost(
Set<String> exposedHostPackages,
Map<FeatureAttachment.Target, Set<String>> reservedHostFields,
Set<String> reservedNamespaces,
Set<String> hostTypePackages,
Path jarCopyRoot,
System.Logger logger) {
private static final String TEMPORARY_DIRECTORY_PROPERTY = "java.io.tmpdir";
@@ -43,10 +45,12 @@ public record ModuleHost(
exposedHostPackages = Set.copyOf(exposedHostPackages);
reservedHostFields = copyOf(reservedHostFields);
reservedNamespaces = Set.copyOf(reservedNamespaces);
hostTypePackages = Set.copyOf(hostTypePackages);
Objects.requireNonNull(jarCopyRoot, "jarCopyRoot");
Objects.requireNonNull(logger, "logger");
ExposedPackages.apiAnd(exposedHostPackages);
ReservedNamespaces.of(reservedNamespaces);
HostTypes.of(hostTypePackages);
requireFieldNames(reservedHostFields);
}
@@ -55,7 +59,7 @@ public record ModuleHost(
*/
public static ModuleHost of(List<? extends IrisModule> builtInModules) {
var builtIns = builtInModules.stream().map(DiscoveredModule::builtIn).toList();
return new ModuleHost(builtIns, Set.of(), Map.of(), Set.of(), systemTemporaryDirectory(),
return new ModuleHost(builtIns, Set.of(), Map.of(), Set.of(), Set.of(), systemTemporaryDirectory(),
System.getLogger(PackModules.class.getName()));
}
@@ -64,13 +68,13 @@ public record ModuleHost(
*/
public ModuleHost exposing(String... packages) {
return new ModuleHost(builtIns, union(exposedHostPackages, packages), reservedHostFields, reservedNamespaces,
jarCopyRoot, logger);
hostTypePackages, jarCopyRoot, logger);
}
/** This configuration with {@code namespaces} reserved for built-in modules. */
public ModuleHost reservingNamespaces(String... namespaces) {
return new ModuleHost(builtIns, exposedHostPackages, reservedHostFields, union(reservedNamespaces, namespaces),
jarCopyRoot, logger);
hostTypePackages, jarCopyRoot, logger);
}
/** This configuration with {@code fields} also reserved as JSON fields the host itself uses,
@@ -78,21 +82,33 @@ public record ModuleHost(
*/
public ModuleHost reservingFields(Map<FeatureAttachment.Target, Set<String>> fields) {
return new ModuleHost(builtIns, exposedHostPackages, merge(reservedHostFields, fields), reservedNamespaces,
jarCopyRoot, logger);
hostTypePackages, jarCopyRoot, logger);
}
/** This configuration with the classes in {@code packages}, each with its subpackages, described by
* the host itself: built-in settings may hold them, such as Iris's palettes, and the pack's
* {@link com.volmit.host.schema.PackSchema} names them as {@link com.volmit.host.schema.ValueKind.HostKind}
* instead of describing their fields. Pack modules' settings cannot use them.
*/
public ModuleHost describingHostTypesIn(String... packages) {
return new ModuleHost(builtIns, exposedHostPackages, reservedHostFields, reservedNamespaces,
union(hostTypePackages, packages), jarCopyRoot, logger);
}
/** This configuration copying module jars into new directories below {@code directory}, such as a
* cache directory of the host, which is created when missing. The last call wins.
*/
public ModuleHost copyingJarsTo(Path directory) {
return new ModuleHost(builtIns, exposedHostPackages, reservedHostFields, reservedNamespaces, directory, logger);
return new ModuleHost(builtIns, exposedHostPackages, reservedHostFields, reservedNamespaces, hostTypePackages,
directory, logger);
}
/** This configuration logging each pack load's module summary and missing-classes warning to
* {@code logger}, such as an adapter to the host's own log. The last call wins.
*/
public ModuleHost loggingTo(System.Logger logger) {
return new ModuleHost(builtIns, exposedHostPackages, reservedHostFields, reservedNamespaces, jarCopyRoot, logger);
return new ModuleHost(builtIns, exposedHostPackages, reservedHostFields, reservedNamespaces, hostTypePackages,
jarCopyRoot, logger);
}
/** The built-in modules followed by a pack's modules, in the order {@link LoadedModules} installs them. */
@@ -26,14 +26,15 @@ final class PackSchemaBuilder {
private static final char FOLDER_SEPARATOR = '/';
private final List<DiscoveredModule> modules;
private final TypeDrafts drafts = new TypeDrafts();
private final TypeDrafts drafts;
private PackSchemaBuilder(List<DiscoveredModule> modules) {
private PackSchemaBuilder(List<DiscoveredModule> modules, HostTypes hostTypes) {
this.modules = modules;
this.drafts = new TypeDrafts(hostTypes);
}
static PackSchema describe(FeatureCatalog catalog, List<DiscoveredModule> modules) {
return new PackSchemaBuilder(modules).describe(catalog);
static PackSchema describe(FeatureCatalog catalog, List<DiscoveredModule> modules, HostTypes hostTypes) {
return new PackSchemaBuilder(modules, hostTypes).describe(catalog);
}
private PackSchema describe(FeatureCatalog catalog) {
@@ -0,0 +1,64 @@
package com.volmit.host;
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;
/** The mantle as chunk stages see it: reads pass through, every write throws. The mantle pipeline has
* finished around the chunk by then, and its neighbors may already be generated.
*/
final class ReadOnlyMantle implements Mantle {
private static final String READ_ONLY = "Chunk stages read the mantle but do not write it;"
+ " write it from a mantle stage (Stage.mantle), which runs before the chunks it reaches";
private final Mantle mantle;
ReadOnlyMantle(Mantle mantle) {
this.mantle = mantle;
}
@Override
public BlockBox bounds() {
return mantle.bounds();
}
@Override
public <T> MantleLayer<T> layer(MantleKey<T> key) {
return new ReadOnlyLayer<>(mantle.layer(key));
}
@Override
public MantleEdit edit() {
throw new UnsupportedOperationException(READ_ONLY);
}
private record ReadOnlyLayer<T>(MantleLayer<T> layer) implements MantleLayer<T> {
@Override
public T get(int x, int y, int z) {
return layer.get(x, y, z);
}
@Override
public void set(int x, int y, int z, T value) {
throw new UnsupportedOperationException(READ_ONLY);
}
@Override
public void remove(int x, int y, int z) {
throw new UnsupportedOperationException(READ_ONLY);
}
@Override
public void visit(BlockBox area, MantleVisitor<T> visitor) {
layer.visit(area, visitor);
}
@Override
public void clear(BlockBox area) {
throw new UnsupportedOperationException(READ_ONLY);
}
}
}
@@ -3,6 +3,7 @@ package com.volmit.host;
import com.volmit.IrisFeature;
import com.volmit.mantle.MantleKey;
import com.volmit.resource.ResourceId;
import com.volmit.stage.Pipeline;
import com.volmit.stage.Stage;
import com.volmit.stage.StageRef;
import java.util.ArrayList;
@@ -54,6 +55,7 @@ final class StageDeclaration {
void reach(int blocks) {
checkOpen();
if (blocks > 0) requireOutsideChunkPipeline("a reach of " + blocks + " blocks");
if (reachBlocks != null) {
throw new IllegalStateException("Stage " + this + " already declares a reach of " + reachBlocks + " blocks");
}
@@ -65,6 +67,7 @@ final class StageDeclaration {
void writesMantle(MantleKey<?>... layers) {
checkOpen();
requireOutsideChunkPipeline("mantle writes");
for (var layer : layers) {
Objects.requireNonNull(layer, "mantle layer");
if (mantleLayers.stream().anyMatch(declared -> declared.id().equals(layer.id()))) {
@@ -147,6 +150,14 @@ final class StageDeclaration {
return "Stage " + this + " " + declared + "; define it with " + alternativeMethod + "(...)";
}
/** Chunk stages write only their own chunk: the host may already have generated its neighbors. */
private void requireOutsideChunkPipeline(String declared) {
if (stage.pipeline() != Pipeline.CHUNK) return;
throw new IllegalArgumentException("Stage " + this + " is a chunk stage and declares " + declared
+ ", but chunk stages write only their own chunk and read the mantle; define work that writes the"
+ " mantle or reaches beyond its chunk as a mantle stage (Stage.mantle), which runs before the chunks it reaches");
}
private void checkOpen() {
if (body != null) {
throw new IllegalStateException("Stage " + this + " is already complete");
@@ -6,6 +6,8 @@ import com.volmit.stage.BlockStage;
import com.volmit.stage.BlockStageDefinition;
import com.volmit.stage.ChunkStage;
import com.volmit.stage.ChunkStageContext;
import com.volmit.stage.MantleStage;
import com.volmit.stage.MantleStageContext;
import com.volmit.stage.Pipeline;
import com.volmit.stage.PlacementStage;
import com.volmit.stage.PlacementStageContext;
@@ -63,6 +65,11 @@ public final class StageGraphBuilder implements StageGraph {
return new InvocationStageDraft<>(declare(stage));
}
@Override
public <O> StageDefinition<MantleStageContext, O> define(MantleStage<O> stage) {
return new InvocationStageDraft<>(declare(stage));
}
public ResolvedGraph resolve(Pipeline pipeline) {
Objects.requireNonNull(pipeline, "pipeline");
return GraphResolver.resolve(pipeline, declarations.values());
@@ -10,7 +10,7 @@ import java.util.stream.IntStream;
/** Pipeline-independent state of one invocation: activation, settings, stage outputs and stage
* random streams, all indexed by resolved position. Activation is computed once up front in resolved
* order: a stage is active when its settings are configured (or it has no condition) and every
* order: a stage is active when its settings have an entry (or it has no condition) and every
* stage it requires is active, so inactivity cascades to dependents. Cost is one pass over stages
* and requirement edges plus one settings lookup per distinct settings type. A stage's stream is
* created when it first draws and depends only on the invocation seed and the stage id.
@@ -131,7 +131,8 @@ final class StageInvocation {
var types = graph.settingsTypes();
var values = new Object[types.size()];
for (int slot = 0; slot < values.length; slot++) {
values[slot] = settings.find((Class<? extends IrisFeature>) types.get(slot)).orElse(null);
var entries = settings.find((Class<? extends IrisFeature>) types.get(slot));
values[slot] = entries.isEmpty() ? null : entries;
}
return values;
}
@@ -8,8 +8,8 @@ import java.util.Objects;
/** What one stage declares it writes outside its footprint.
*
* @param blocks how far, in blocks along X and Z, the stage writes blocks or mantle values beyond its
* footprint: the chunk's 16 by 16 columns for a chunk stage, the X/Z bounds of the placed object
* for a placement stage. 0 means only inside it. Height is not limited: the footprint is whole
* footprint: the chunk's 16 by 16 columns for a mantle stage, the X/Z bounds of the placed object
* for a placement stage. 0 means only inside it, and is all a chunk stage may declare. Height is not limited: the footprint is whole
* columns.
* @param mantleLayers the mantle layers the stage writes, each once, in declaration order
*/
@@ -17,7 +17,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
/** Describes every class reachable from the settings of a pack, each once. A class is recorded before
/** Describes every class reachable from the settings of a pack, each once, except host types, which the
* host describes itself. A class is recorded before
* its fields are described, so a class that contains itself, directly or through others, ends the
* walk at its own name. Each class is instantiated once with its no-argument constructor, the way the
* host creates settings before decoding JSON into them, and its fields' values there are the defaults.
@@ -26,6 +27,11 @@ final class TypeDrafts {
private final Map<Class<?>, TypeDraft> drafts = new LinkedHashMap<>();
private final Set<Class<?>> describing = new HashSet<>();
private final Map<String, Class<?>> names = new HashMap<>();
private final HostTypes hostTypes;
TypeDrafts(HostTypes hostTypes) {
this.hostTypes = hostTypes;
}
/** One described class: its metadata and its options with their kinds and raw default values. */
record TypeDraft(Class<?> type, SchemaSource source, OptionsMetadata metadata, List<OptionDraft> options) {}
@@ -63,7 +69,8 @@ final class TypeDrafts {
private TypeDraft draft(Class<?> type, SchemaSource source) {
var metadata = inspect(type, source);
var instance = instantiate(type, source);
var kinds = new ValueKinds(nested -> object(nested, source));
var kinds = new ValueKinds(nested -> object(nested, source), hostTypes,
source.module().source() == DiscoveredModule.Source.HOST);
var options = metadata.options().stream()
.map(option -> new OptionDraft(option, kind(option, kinds, source), defaultValue(option.field(), instance, source)))
.toList();
+20 -4
View File
@@ -10,6 +10,7 @@ import com.volmit.host.schema.ValueKind.BooleanKind;
import com.volmit.host.schema.ValueKind.DecimalKind;
import com.volmit.host.schema.ValueKind.EnumConstant;
import com.volmit.host.schema.ValueKind.EnumKind;
import com.volmit.host.schema.ValueKind.HostKind;
import com.volmit.host.schema.ValueKind.IntegerKind;
import com.volmit.host.schema.ValueKind.ListKind;
import com.volmit.host.schema.ValueKind.MapKind;
@@ -29,9 +30,10 @@ import java.util.Map;
import java.util.Set;
import java.util.function.Function;
/** Maps a settings field's declared type and {@code @Ref} to the JSON it takes. Classes that are none
* of the built-in kinds become object kinds through the given function. Throws
* {@link SettingsTypeProblem} for a type or reference that does not fit.
/** Maps a settings field's declared type and {@code @Ref} to the JSON it takes. Host types become host
* kinds where the settings may use them; other classes that are none of the built-in kinds become object
* kinds through the given function. Throws {@link SettingsTypeProblem} for a type or reference that does
* not fit.
*/
final class ValueKinds {
static final String SUPPORTED_TYPES = "settings fields can be booleans, numbers, String, ResourceId, BlockState, enums, "
@@ -44,9 +46,14 @@ final class ValueKinds {
private static final Set<Reference> PACK_REFERENCES = EnumSet.of(Reference.PACK_BIOME, Reference.PACK_REGION, Reference.PACK_OBJECT);
private final Function<Class<?>, ObjectKind> objects;
private final HostTypes hostTypes;
private final boolean hostTypesAllowed;
ValueKinds(Function<Class<?>, ObjectKind> objects) {
/** {@code hostTypesAllowed} is whether the settings belong to a module that ships with the host. */
ValueKinds(Function<Class<?>, ObjectKind> objects, HostTypes hostTypes, boolean hostTypesAllowed) {
this.objects = objects;
this.hostTypes = hostTypes;
this.hostTypesAllowed = hostTypesAllowed;
}
ValueKind of(OptionsMetadata.Option option) {
@@ -64,6 +71,7 @@ final class ValueKinds {
}
private ValueKind classKind(Class<?> type, Reference reference) {
if (hostTypes.contains(type)) return hostKind(type, reference);
if (type == String.class) return text(TextFormat.PLAIN, reference);
if (type == ResourceId.class) return text(TextFormat.RESOURCE_ID, reference);
if (type == BlockState.class) return blockState(reference);
@@ -80,6 +88,7 @@ final class ValueKinds {
private ValueKind genericKind(ParameterizedType generic, Reference reference) {
var raw = (Class<?>) generic.getRawType();
if (hostTypes.contains(raw)) return hostKind(raw, reference);
var arguments = generic.getActualTypeArguments();
if (raw == List.class || raw == Set.class) return new ListKind(kind(arguments[0], reference), raw == Set.class);
if (raw == Map.class) return mapKind(generic, arguments, reference);
@@ -94,6 +103,13 @@ final class ValueKinds {
return new MapKind(kind(arguments[1], null));
}
private HostKind hostKind(Class<?> type, Reference reference) {
requireNoReference(type, reference);
if (hostTypesAllowed) return new HostKind(type.getName());
throw new SettingsTypeProblem("uses " + type.getName() + ", a class the host describes itself, which only settings of"
+ " modules that ship with the host may use; " + SUPPORTED_TYPES);
}
private static ValueKind text(TextFormat format, Reference reference) {
if (reference == null) return new TextKind(format);
if (format == TextFormat.RESOURCE_ID && PACK_REFERENCES.contains(reference)) throw packReferenceOnResourceId(reference);
@@ -39,4 +39,12 @@ public record FeatureSchema(
Objects.requireNonNull(settings, "settings");
targets = Collections.unmodifiableSet(EnumSet.copyOf(targets));
}
/** The settings' only option, when they have exactly one. Packs may then write that option's value
* directly instead of an object holding it, such as {@code "snow": 0.5} for {@code "snow": {"amount": 0.5}},
* and the host decodes a value that is not a JSON object into it.
*/
public Optional<SchemaOption> shorthand() {
return settings.options().size() == 1 ? Optional.of(settings.options().getFirst()) : Optional.empty();
}
}
@@ -63,6 +63,16 @@ public sealed interface ValueKind {
}
}
/** A value of the class named {@code type}, which the host describes itself, such as one of Iris's
* palettes or noise styles. Only built-in modules' settings use these (see
* {@link com.volmit.host.ModuleHost#describingHostTypesIn}); the host renders its own description.
*/
record HostKind(String type) implements ValueKind {
public HostKind {
Objects.requireNonNull(type, "type");
}
}
/** An enum constant and its {@code @Desc}, or an empty description. */
record EnumConstant(String name, String description) {
public EnumConstant {
@@ -15,9 +15,8 @@ public interface BlockStageDefinition<O> {
BlockStageDefinition<O> softBefore(StageRef... stages);
/** Declares how far, in blocks along X and Z, this stage writes blocks or mantle values beyond its
* footprint: the chunk for a chunk stage, the placed object's X/Z bounds for a placement stage. The
* host prepares that much around every chunk or placement of the pipeline. Leaving it out means 0.
/** Declares how far, in blocks along X and Z, this stage writes blocks or mantle values beyond the
* placed object's X/Z bounds. The host prepares that much around every placement. Leaving it out means 0.
*/
BlockStageDefinition<O> reach(int blocks);
@@ -1,6 +1,8 @@
package com.volmit.stage;
/** Runs once per chunk generation invocation. */
/** Runs once per chunk generation invocation and writes only its own chunk. It may read the mantle but
* not write it, and it declares no reach: such work belongs in a {@link MantleStage}.
*/
public final class ChunkStage<O> extends Stage<O> {
ChunkStage(String id, Class<O> outputType) {
super(id, outputType);
@@ -1,11 +1,12 @@
package com.volmit.stage;
import com.volmit.IrisFeature;
import com.volmit.mantle.MantleKey;
import java.util.function.Supplier;
/** A block stage active only where its settings are configured; bodies receive them. */
public interface ConditionalBlockStageDefinition<S, O> {
/** A block stage active only where its settings are configured; bodies receive every configured entry. */
public interface ConditionalBlockStageDefinition<S extends IrisFeature, O> {
ConditionalBlockStageDefinition<S, O> requires(Stage<?>... stages);
ConditionalBlockStageDefinition<S, O> softAfter(StageRef... stages);
@@ -1,9 +1,10 @@
package com.volmit.stage;
import com.volmit.IrisFeature;
import com.volmit.mantle.MantleKey;
/** An invocation stage active only where its settings are configured; bodies receive them. */
public interface ConditionalStageDefinition<C extends StageContext, S, O> {
/** An invocation stage active only where its settings are configured; bodies receive every configured entry. */
public interface ConditionalStageDefinition<C extends StageContext, S extends IrisFeature, O> {
ConditionalStageDefinition<C, S, O> requires(Stage<?>... stages);
ConditionalStageDefinition<C, S, O> softAfter(StageRef... stages);
@@ -0,0 +1,18 @@
package com.volmit.stage;
/** Runs once per chunk in the mantle pipeline, before the chunks it reaches generate. */
public final class MantleStage<O> extends Stage<O> {
MantleStage(String id, Class<O> outputType) {
super(id, outputType);
}
@Override
public Pipeline pipeline() {
return Pipeline.MANTLE;
}
@Override
public StageKind kind() {
return StageKind.INVOCATION;
}
}
@@ -0,0 +1,6 @@
package com.volmit.stage;
import com.volmit.generation.MantleGenerationContext;
/** One mantle invocation for one chunk: the mantle around it, without a block hunk. */
public interface MantleStageContext extends MantleGenerationContext, StageContext {}
+9 -2
View File
@@ -4,6 +4,13 @@ package com.volmit.stage;
public enum Pipeline {
/** Runs once per object placement attempt, against one buffered placement edit. */
PLACEMENT,
/** Runs once per chunk generation invocation, against host-owned local hunks. */
CHUNK
/** Runs once per chunk generation invocation, against host-owned local hunks. Its stages write only
* their own chunk and read the mantle.
*/
CHUNK,
/** Runs once per chunk before any chunk near it generates, against the mantle only: work that writes
* the mantle or reaches beyond its chunk. The host runs it around a chunk as far as the pipeline's
* reach, so a chunk's mantle is complete when the chunk pipeline reads it.
*/
MANTLE
}
@@ -1,6 +1,13 @@
package com.volmit.stage;
import com.volmit.IrisFeature;
import com.volmit.config.FeatureSettings.Entry;
import java.util.List;
/** Body of a conditional stage without output. {@code settings} holds every entry configured for the
* invocation, in level order, and is never empty.
*/
@FunctionalInterface
public interface SettingsAction<C, S> {
void run(C context, S settings);
public interface SettingsAction<C, S extends IrisFeature> {
void run(C context, List<Entry<S>> settings);
}
@@ -1,6 +1,13 @@
package com.volmit.stage;
import com.volmit.IrisFeature;
import com.volmit.config.FeatureSettings.Entry;
import java.util.List;
/** Body of a conditional accumulating block stage. {@code settings} holds every entry configured for
* the placement, in level order, and is never empty.
*/
@FunctionalInterface
public interface SettingsBlockCollector<S, O> {
void collect(BlockStageContext context, S settings, O accumulator);
public interface SettingsBlockCollector<S extends IrisFeature, O> {
void collect(BlockStageContext context, List<Entry<S>> settings, O accumulator);
}
@@ -1,6 +1,13 @@
package com.volmit.stage;
import com.volmit.IrisFeature;
import com.volmit.config.FeatureSettings.Entry;
import java.util.List;
/** Body of a conditional stage with output. {@code settings} holds every entry configured for the
* invocation, in level order, and is never empty.
*/
@FunctionalInterface
public interface SettingsFunction<C, S, O> {
O run(C context, S settings);
public interface SettingsFunction<C, S extends IrisFeature, O> {
O run(C context, List<Entry<S>> settings);
}
+9 -1
View File
@@ -9,7 +9,7 @@ import java.util.Objects;
* The output type is Void for stages that only act; otherwise dependents read it through
* {@link StageContext#output(Stage)}. Block stages accumulate their output across the pass.
*/
public abstract sealed class Stage<O> permits PlacementStage, BlockStage, ChunkStage {
public abstract sealed class Stage<O> permits PlacementStage, BlockStage, ChunkStage, MantleStage {
private final ResourceId id;
private final Class<O> outputType;
@@ -46,6 +46,14 @@ public abstract sealed class Stage<O> permits PlacementStage, BlockStage, ChunkS
return new ChunkStage<>(id, outputType);
}
public static MantleStage<Void> mantle(String id) {
return new MantleStage<>(id, Void.class);
}
public static <O> MantleStage<O> mantle(String id, Class<O> outputType) {
return new MantleStage<>(id, outputType);
}
public final ResourceId id() {
return id;
}
@@ -17,17 +17,22 @@ public interface StageDefinition<C extends StageContext, O> {
StageDefinition<C, O> softBefore(StageRef... stages);
/** Declares how far, in blocks along X and Z, this stage writes blocks or mantle values beyond its
* footprint: the chunk for a chunk stage, the placed object's X/Z bounds for a placement stage. The
* footprint: the chunk for a mantle stage, the placed object's X/Z bounds for a placement stage. The
* host prepares that much around every chunk or placement of the pipeline. Leaving it out means 0.
* Chunk stages write only their own chunk, so a reach above 0 on one fails the install.
*/
StageDefinition<C, O> reach(int blocks);
/** Declares the mantle layers this stage writes; each must be registered by some module. */
/** Declares the mantle layers this stage writes; each must be registered by some module. Chunk stages
* only read the mantle, so declaring layers on one fails the install.
*/
StageDefinition<C, O> writesMantle(MantleKey<?>... layers);
/** Activates the stage only where the given feature settings are configured. At least one module
* naming the type must own its feature id: the id is that module's id or starts with it and '/'.
* Other modules may name it too, such as moss conditioning on {@code iris:snow}.
/** Activates the stage only where the given feature settings are configured: in a placement where the
* placement declares them, in a chunk or mantle invocation where any column of the chunk has an entry.
* The body receives every configured entry, in level order. At least one module naming the type must
* own its feature id: the id is that module's id or starts with it and '/'. Other modules may name it
* too, such as moss conditioning on {@code iris:snow}.
*/
<S extends IrisFeature> ConditionalStageDefinition<C, S, O> when(Class<S> settingsType);
@@ -12,4 +12,6 @@ public interface StageGraph {
<O> BlockStageDefinition<O> define(BlockStage<O> stage);
<O> StageDefinition<ChunkStageContext, O> define(ChunkStage<O> stage);
<O> StageDefinition<MantleStageContext, O> define(MantleStage<O> stage);
}
@@ -1,28 +1,54 @@
package com.volmit.example;
import com.volmit.FeatureAttachment.Target;
import com.volmit.IrisFeature;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
import com.volmit.block.BlockState;
import com.volmit.config.Feature;
import com.volmit.config.FeatureSettings.Entry;
import com.volmit.example.chunk.GrassModule;
import com.volmit.example.chunk.GrassSettings;
import com.volmit.example.chunk.TerrainModule;
import com.volmit.example.chunk.VeinModule;
import com.volmit.example.chunk.VeinSettings;
import com.volmit.host.ArrayHunk;
import com.volmit.host.ChunkRunner;
import com.volmit.host.ConfiguredSettings;
import com.volmit.host.DiscoveredModule;
import com.volmit.host.LoadedModules;
import com.volmit.host.MantleRunner;
import com.volmit.host.StageGraphBuilder;
import com.volmit.hunk.Hunk;
import com.volmit.mantle.BlockBox;
import com.volmit.resource.ResourceId;
import com.volmit.stage.Pipeline;
import com.volmit.stage.Stage;
import com.volmit.stage.StageGraph;
import com.volmit.support.ColumnSettings;
import com.volmit.support.MemoryMantle;
import com.volmit.support.TestContexts;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/** The chunk pipeline runs on the same graph machinery as placement. */
/** The chunk pipeline runs on the same graph machinery as placement; the mantle pipeline feeds it. */
class ChunkPipelineTest {
private static final int SIZE = 4;
private static final int HEIGHT = 8;
private static final int CHUNK = 16;
private static final int MIN_Y = -64;
private static final int MAX_Y = 320;
private static final BlockState AIR = new BlockState("minecraft:air");
private static final BlockState GRASS = new BlockState("minecraft:grass_block");
private static final ResourceId DIMENSION = ResourceId.parse("pack:dimension/overworld");
private static final ResourceId PLAINS = ResourceId.parse("pack:biome/plains");
private static final ResourceId SWAMP = ResourceId.parse("pack:biome/swamp");
@Feature(id = "test:levels", name = "Levels", targets = {Target.DIMENSION, Target.BIOME})
static final class Marker implements IrisFeature {}
private static ChunkRunner runner() {
var builder = new StageGraphBuilder();
@@ -35,15 +61,19 @@ class ChunkPipelineTest {
return new ChunkRunner(graph);
}
private static Hunk<BlockState> generate(ConfiguredSettings settings) {
private static Hunk<BlockState> generate(ColumnSettings settings) {
var blocks = new ArrayHunk<>(BlockState.class, SIZE, HEIGHT, SIZE, AIR);
runner().generate(TestContexts.generation(Map.of(BlockState.class, blocks)), TestContexts.SEED, settings);
runner().generate(TestContexts.generation(Map.of(BlockState.class, blocks), settings, null), TestContexts.SEED);
return blocks;
}
private static Entry<GrassSettings> grass(ResourceId biome) {
return new Entry<>(Target.BIOME, biome, new GrassSettings());
}
@Test
void decorationReadsTerrainOutputWhenConfigured() {
var blocks = generate(ConfiguredSettings.of(new GrassSettings()));
var blocks = generate(ColumnSettings.everywhere(grass(PLAINS)));
for (int x = 0; x < SIZE; x++) {
for (int z = 0; z < SIZE; z++) {
@@ -57,9 +87,90 @@ class ChunkPipelineTest {
@Test
void decorationIsInactiveWithoutItsSettings() {
var blocks = generate(ConfiguredSettings.none());
var blocks = generate(ColumnSettings.NONE);
int height = TerrainModule.surfaceHeight(0, 0);
assertEquals(TerrainModule.STONE, blocks.get(0, height - 1, 0));
}
@Test
void aStageRunsWhenAnyColumnHasItsSettingsAndReadsThemPerColumn() {
var farCorner = new ColumnSettings((x, z) -> x == CHUNK - 1 && z == CHUNK - 1 ? List.of(grass(PLAINS)) : List.of());
var blocks = generate(farCorner);
assertEquals(TerrainModule.STONE, blocks.get(0, TerrainModule.surfaceHeight(0, 0) - 1, 0),
"the stage ran because one column has grass, but this column has none");
var border = new ColumnSettings((x, z) -> x < 2 ? List.of(grass(PLAINS)) : List.of());
blocks = generate(border);
assertEquals(GRASS, blocks.get(1, TerrainModule.surfaceHeight(1, 0) - 1, 0));
assertEquals(TerrainModule.STONE, blocks.get(2, TerrainModule.surfaceHeight(2, 0) - 1, 0));
}
@Test
void levelsStackAndTheBodyGetsEveryDistinctEntryOfTheChunkInLevelOrder() {
var dimension = new Entry<>(Target.DIMENSION, DIMENSION, new Marker());
var plains = new Entry<>(Target.BIOME, PLAINS, new Marker());
var swamp = new Entry<>(Target.BIOME, SWAMP, new Marker());
var received = new ArrayList<List<ResourceId>>();
var stage = Stage.chunk("test:levels/read");
IrisModule module = new IrisModule() {
public ModuleInfo info() { return ModuleInfo.of("test:levels", "Levels", "1"); }
public void install(StageGraph graph) {
graph.define(stage).when(Marker.class).run((context, entries) -> {
received.add(entries.stream().map(Entry::source).toList());
received.add(context.settings().at(Marker.class, 0, 0).stream().map(Entry::source).toList());
});
}
};
var builder = new StageGraphBuilder();
builder.install(DiscoveredModule.builtIn(module));
var settings = new ColumnSettings((x, z) -> List.of(dimension, x < 8 ? swamp : plains));
new ChunkRunner(builder.resolve(Pipeline.CHUNK)).generate(TestContexts.generation(Map.of(), settings, null), TestContexts.SEED);
assertEquals(List.of(List.of(DIMENSION, SWAMP, PLAINS), List.of(DIMENSION, SWAMP)), received,
"the body sees every level of every column, a column read that column's levels");
}
@Test
void mantleStagesWriteBeyondTheirChunkAndChunkStagesReadTheirOwnPart() {
var loaded = LoadedModules.load(List.of(DiscoveredModule.builtIn(new VeinModule())), Map.of(), Set.of(), Set.of());
assertEquals(VeinModule.REACH, loaded.mantle().reach().blocks());
assertEquals(Map.of(VeinModule.ORE.id(), VeinModule.REACH), loaded.mantle().reach().mantleLayers());
var mantle = new MemoryMantle();
var veins = ColumnSettings.everywhere(new Entry<>(Target.BIOME, PLAINS, new VeinSettings(12, -60)));
var reachArea = new BlockBox(-VeinModule.REACH, MIN_Y, -VeinModule.REACH, CHUNK + VeinModule.REACH, MAX_Y, CHUNK + VeinModule.REACH);
new MantleRunner(loaded.mantle()).generate(TestContexts.mantle(0, 0, veins, mantle.within(reachArea)), TestContexts.SEED);
assertEquals(1, mantle.get(VeinModule.ORE, 18, -60, 7), "the vein runs on into the next chunk");
var blocks = new ArrayHunk<>(BlockState.class, CHUNK, HEIGHT, CHUNK, AIR);
var chunkArea = new BlockBox(0, MIN_Y, 0, CHUNK, MAX_Y, CHUNK);
new ChunkRunner(loaded.chunk()).generate(
TestContexts.generation(Map.of(BlockState.class, blocks), ColumnSettings.NONE, mantle.within(chunkArea)), TestContexts.SEED);
assertEquals(VeinModule.ORE_BLOCK, blocks.get(7, 4, 7));
assertEquals(VeinModule.ORE_BLOCK, blocks.get(15, 4, 7));
assertEquals(AIR, blocks.get(6, 4, 7));
}
@Test
void chunkStagesReadTheMantleButCannotWriteIt() {
var stage = Stage.chunk("test:writer/work");
var mantle = new MemoryMantle();
IrisModule module = new IrisModule() {
public ModuleInfo info() { return ModuleInfo.of("test:writer", "Writer", "1"); }
public void install(StageGraph graph) {
graph.define(stage).run(context -> context.mantle().layer(VeinModule.ORE).set(0, 0, 0, 1));
}
};
var builder = new StageGraphBuilder();
builder.install(DiscoveredModule.builtIn(module));
var inputs = TestContexts.generation(Map.of(), ColumnSettings.NONE, mantle.within(new BlockBox(0, MIN_Y, 0, CHUNK, MAX_Y, CHUNK)));
var failure = assertThrows(UnsupportedOperationException.class,
() -> new ChunkRunner(builder.resolve(Pipeline.CHUNK)).generate(inputs, TestContexts.SEED));
assertEquals("Chunk stages read the mantle but do not write it; write it from a mantle stage (Stage.mantle),"
+ " which runs before the chunks it reaches", failure.getMessage());
assertNull(mantle.get(VeinModule.ORE, 0, 0, 0));
}
}
@@ -38,6 +38,7 @@ import static org.junit.jupiter.api.Assertions.*;
/** The ported slice of Iris's place() lifecycle, composed only from module-owned stages. */
class PlacementLifecyclePortTest {
private static final ResourceId PLACEMENT = ResourceId.parse("pack:object/tree");
private static final BlockState PLANKS = new BlockState("minecraft:oak_planks");
private static final int ANCHOR_GROUND = 10;
private static final int SURROUNDING_GROUND = 7;
@@ -149,7 +150,7 @@ class PlacementLifecyclePortTest {
@Test
void placesObjectThenStiltSnowAndMossFromTypedOutputs() {
var edit = place(resolve(PlacementModules.all()),
ConfiguredSettings.of(new StiltSettings(), new SnowSettings(2), new MossSettings()));
ConfiguredSettings.placement(PLACEMENT, new StiltSettings(), new SnowSettings(2), new MossSettings()));
var bottom = placed(0, 0, 0);
var corner = placed(1, 0, 0);
@@ -191,17 +192,17 @@ class PlacementLifecyclePortTest {
modules.add(capModule);
var graph = resolve(modules);
var withoutStilt = place(graph, ConfiguredSettings.of(new SnowSettings(), new MossSettings()));
var withoutStilt = place(graph, ConfiguredSettings.placement(PLACEMENT, new SnowSettings(), new MossSettings()));
assertEquals(TestTerrain.AIR, withoutStilt.publishedAt(5, 20, 5));
assertEquals(MossModule.MOSS, withoutStilt.publishedAt(0, ANCHOR_GROUND - 1, 0));
var withStilt = place(graph, ConfiguredSettings.of(new StiltSettings()));
var withStilt = place(graph, ConfiguredSettings.placement(PLACEMENT, new StiltSettings()));
assertEquals(PLANKS, withStilt.publishedAt(5, 20, 5));
}
@Test
void loadingThePortCatalogsEveryConditioningSettingsType() {
var loaded = LoadedModules.load(PlacementModules.builtIns(), Map.of(), Set.of());
var loaded = LoadedModules.load(PlacementModules.builtIns(), Map.of(), Set.of(), Set.of());
assertEquals(List.of("example:moss", "iris:snow", "iris:stilt"),
loaded.catalog().settings().stream().map(settings -> settings.id().toString()).toList());
@@ -3,12 +3,17 @@ package com.volmit.example.chunk;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
import com.volmit.block.BlockState;
import com.volmit.config.FeatureSettings.Entry;
import com.volmit.stage.ChunkStage;
import com.volmit.stage.ChunkStageContext;
import com.volmit.stage.Stage;
import com.volmit.stage.StageGraph;
import java.util.List;
/** Third-party decoration: tops terrain columns using the terrain module's typed output. */
/** Third-party decoration: tops terrain columns using the terrain module's typed output. It runs where any
* column of the chunk has grass and reads the settings per column, so a biome border inside the chunk
* keeps grass on its own side.
*/
public final class GrassModule implements IrisModule {
public static final ChunkStage<Void> TOP = Stage.chunk("example:grass/top");
@@ -25,16 +30,17 @@ public final class GrassModule implements IrisModule {
.run(GrassModule::cover);
}
private static void cover(ChunkStageContext context, GrassSettings grass) {
var top = grass.block();
private static void cover(ChunkStageContext context, List<Entry<GrassSettings>> inChunk) {
var heights = context.output(TerrainModule.SURFACE);
var blocks = context.hunk(BlockState.class);
for (int x = 0; x < blocks.getWidth(); x++) {
for (int z = 0; z < blocks.getDepth(); z++) {
var here = context.settings().at(GrassSettings.class, context.originX() + x, context.originZ() + z);
int height = heights.at(x, z);
if (height > 0) {
blocks.set(x, height - 1, z, top);
if (here.isEmpty() || height <= 0) {
continue;
}
blocks.set(x, height - 1, z, here.getLast().value().block()); // the most specific level wins here
}
}
}
@@ -0,0 +1,77 @@
package com.volmit.example.chunk;
import com.volmit.FeatureRegistry;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
import com.volmit.block.BlockState;
import com.volmit.config.FeatureSettings.Entry;
import com.volmit.mantle.BlockBox;
import com.volmit.mantle.MantleCodec;
import com.volmit.mantle.MantleKey;
import com.volmit.mantle.MantleLifetime;
import com.volmit.stage.ChunkStage;
import com.volmit.stage.ChunkStageContext;
import com.volmit.stage.MantleStage;
import com.volmit.stage.MantleStageContext;
import com.volmit.stage.Stage;
import com.volmit.stage.StageGraph;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.List;
/** Work across chunks: a mantle stage plans veins into the mantle, past its own chunk, and a chunk stage
* later turns its own chunk's part of the mantle into blocks. The two pipelines meet only in the mantle.
*/
public final class VeinModule implements IrisModule {
public static final MantleKey<Integer> ORE = new MantleKey<>("example:veins/ore", Integer.class);
public static final MantleStage<Void> PLAN = Stage.mantle("example:veins/plan");
public static final ChunkStage<Void> PLACE = Stage.chunk("example:veins/place");
public static final BlockState ORE_BLOCK = new BlockState("minecraft:iron_ore");
public static final int REACH = 16;
private static final int CHUNK_WIDTH = 16;
private static final int CHUNK_CENTRE = 7;
private static final int PLANNED = 1;
@Override
public ModuleInfo info() {
return ModuleInfo.of("example:veins", "Veins", "1.0.0");
}
@Override
public void install(StageGraph graph) {
graph.define(PLAN).when(VeinSettings.class).reach(REACH).writesMantle(ORE).run(VeinModule::plan);
graph.define(PLACE).run(VeinModule::place);
}
@Override
public void register(FeatureRegistry registry) {
registry.registerMantle(ORE, MantleLifetime.GENERATION, new IntegerCodec());
}
/** One vein per level that configures veins at the chunk's centre column: levels stack. */
private static void plan(MantleStageContext context, List<Entry<VeinSettings>> inChunk) {
int startX = context.originX() + CHUNK_CENTRE;
int z = context.originZ() + CHUNK_CENTRE;
var ore = context.mantle().layer(ORE);
for (var vein : context.settings().at(VeinSettings.class, startX, z)) {
for (int step = 0; step < Math.min(vein.value().length(), REACH + CHUNK_WIDTH - CHUNK_CENTRE); step++) {
ore.set(startX + step, vein.value().y(), z, PLANNED);
}
}
}
private static void place(ChunkStageContext context) {
var blocks = context.hunk(BlockState.class);
var chunk = new BlockBox(context.originX(), context.originY(), context.originZ(),
context.originX() + blocks.getWidth(), context.originY() + blocks.getHeight(), context.originZ() + blocks.getDepth());
context.mantle().layer(ORE).visit(chunk, (x, y, z, planned) ->
blocks.set(x - context.originX(), y - context.originY(), z - context.originZ(), ORE_BLOCK));
}
private static final class IntegerCodec implements MantleCodec<Integer> {
public int version() { return 0; }
public void write(DataOutput output, Integer value) throws IOException { output.writeInt(value); }
public Integer read(DataInput input, int storedVersion) throws IOException { return input.readInt(); }
}
}
@@ -0,0 +1,31 @@
package com.volmit.example.chunk;
import com.volmit.FeatureAttachment;
import com.volmit.IrisFeature;
import com.volmit.config.Desc;
import com.volmit.config.Feature;
@Desc("Plans a horizontal ore vein from the centre of each chunk, which may run into the next chunk")
@Feature(id = "example:veins", name = "Veins", targets = {FeatureAttachment.Target.DIMENSION, FeatureAttachment.Target.BIOME})
public final class VeinSettings implements IrisFeature {
@Desc("Blocks along X, starting at the chunk's centre column")
private int length = 12;
@Desc("World height of the vein")
private int y = -60;
public VeinSettings() {}
public VeinSettings(int length, int y) {
this.length = length;
this.y = y;
}
public int length() {
return length;
}
public int y() {
return y;
}
}
@@ -0,0 +1,13 @@
package com.volmit.example.hosttypes;
import java.util.List;
/** Stands for a host class such as Iris's material palette: the host describes it in studio itself. */
public final class Palette {
private List<String> blocks = List.of("minecraft:stone");
private Object anything;
public List<String> blocks() {
return blocks;
}
}
@@ -3,6 +3,7 @@ package com.volmit.example.placement;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
import com.volmit.block.BlockState;
import com.volmit.config.FeatureSettings.Entry;
import com.volmit.placement.PlacedBlock;
import com.volmit.stage.PlacementStage;
import com.volmit.stage.PlacementStageContext;
@@ -10,6 +11,7 @@ import com.volmit.stage.Stage;
import com.volmit.stage.StageGraph;
import com.volmit.stage.StageRef;
import com.volmit.world.BlockPosition;
import java.util.List;
import java.util.Optional;
/** Third-party module: turns the ground under the anchor into moss. It requires the core
@@ -33,7 +35,8 @@ public final class MossModule implements IrisModule {
.run(MossModule::spread);
}
private static void spread(PlacementStageContext context, MossSettings moss) {
private static void spread(PlacementStageContext context, List<Entry<MossSettings>> settings) {
var moss = settings.getFirst().value(); // a placement declares its settings once
var anchor = context.output(AnchorModule.HEIGHT).anchor();
var access = context.access();
int groundY = anchor.y() - 1;
@@ -3,6 +3,7 @@ package com.volmit.example.placement;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
import com.volmit.block.BlockState;
import com.volmit.config.FeatureSettings.Entry;
import com.volmit.placement.PlacedBlock;
import com.volmit.stage.BlockStage;
import com.volmit.stage.PlacementStage;
@@ -11,6 +12,7 @@ import com.volmit.stage.Stage;
import com.volmit.stage.StageGraph;
import com.volmit.stage.StageRef;
import com.volmit.world.BlockPosition;
import java.util.List;
import java.util.Optional;
/** Port of PlacementModuleSnow: collect written tops, then cover them after the finishing work
@@ -40,7 +42,8 @@ public final class SnowModule implements IrisModule {
.run(SnowModule::cover);
}
private static void cover(PlacementStageContext context, SnowSettings snow) {
private static void cover(PlacementStageContext context, List<Entry<SnowSettings>> settings) {
var snow = settings.getFirst().value(); // a placement declares its settings once
var layer = SNOW.withProperty("layers", Integer.toString(snow.layers()));
var access = context.access();
for (var top : context.output(COLLECT).tops()) {
@@ -2,6 +2,7 @@ package com.volmit.example.placement;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
import com.volmit.config.FeatureSettings.Entry;
import com.volmit.object.ObjectBlock;
import com.volmit.placement.PlacedBlock;
import com.volmit.stage.BlockStage;
@@ -10,6 +11,7 @@ import com.volmit.stage.PlacementStageContext;
import com.volmit.stage.Stage;
import com.volmit.stage.StageGraph;
import com.volmit.world.BlockPosition;
import java.util.List;
import java.util.Optional;
/** Port of PlacementModuleStilt: collect the lowest layer per block, then fill down after writes. */
@@ -34,7 +36,8 @@ public final class StiltModule implements IrisModule {
.run(StiltModule::fill);
}
private static void fill(PlacementStageContext context, StiltSettings stilt) {
private static void fill(PlacementStageContext context, List<Entry<StiltSettings>> settings) {
var stilt = settings.getFirst().value(); // a placement declares its settings once
var anchor = context.output(AnchorModule.HEIGHT);
for (var block : context.output(BOUNDS).lowestLayer()) {
var bottom = anchor.worldPosition(context.request(), block.position());
@@ -0,0 +1,22 @@
package com.volmit.example.terrain;
import com.volmit.FeatureRegistry;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
import com.volmit.stage.StageGraph;
/** A built-in module whose settings use host types; it only registers them. */
public final class LayersModule implements IrisModule {
@Override
public ModuleInfo info() {
return ModuleInfo.of("iris:layers", "Layers", "test");
}
@Override
public void install(StageGraph graph) {}
@Override
public void register(FeatureRegistry registry) {
registry.registerSettings(LayersSettings.class);
}
}
@@ -0,0 +1,19 @@
package com.volmit.example.terrain;
import com.volmit.FeatureAttachment;
import com.volmit.IrisFeature;
import com.volmit.config.Desc;
import com.volmit.config.Feature;
import com.volmit.example.hosttypes.Palette;
import java.util.List;
/** Built-in settings holding host types, written in pack JSON as a bare list: {@code "layers": [...]}. */
@Feature(id = "iris:layers", name = "Layers", alias = "layers", targets = FeatureAttachment.Target.BIOME)
public final class LayersSettings implements IrisFeature {
@Desc("Rock layers from the surface down")
private List<Palette> layers = List.of();
public List<Palette> layers() {
return layers;
}
}
@@ -0,0 +1,43 @@
package com.volmit.host;
import com.volmit.FeatureAttachment.Target;
import com.volmit.IrisFeature;
import com.volmit.config.Feature;
import com.volmit.config.FeatureSettings.Entry;
import com.volmit.resource.ResourceId;
import java.util.List;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class ConfiguredSettingsTest {
private static final ResourceId DIMENSION = ResourceId.parse("pack:dimension/overworld");
private static final ResourceId BIOME = ResourceId.parse("pack:biome/plains");
private static final ResourceId OBJECT = ResourceId.parse("pack:object/tree");
@Feature(id = "test:levels", name = "Levels", targets = {Target.DIMENSION, Target.BIOME, Target.OBJECT_PLACEMENT})
static final class Levels implements IrisFeature {}
@Feature(id = "test:other", name = "Other", targets = Target.BIOME)
static final class Other implements IrisFeature {}
@Test
void entriesAreGroupedByTypeInLevelOrderAndNeverMerged() {
var biome = new Entry<>(Target.BIOME, BIOME, new Levels());
var dimension = new Entry<>(Target.DIMENSION, DIMENSION, new Levels());
var settings = ConfiguredSettings.of(List.of(biome, dimension));
assertEquals(List.of(dimension, biome), settings.find(Levels.class));
assertEquals(List.of(), settings.find(Other.class));
assertEquals(List.of(), ConfiguredSettings.none().find(Levels.class));
}
@Test
void aPlacementDeclaresEachTypeOnce() {
var levels = new Levels();
assertEquals(List.of(new Entry<>(Target.OBJECT_PLACEMENT, OBJECT, levels)),
ConfiguredSettings.placement(OBJECT, levels).find(Levels.class));
var twice = assertThrows(IllegalArgumentException.class, () -> ConfiguredSettings.placement(OBJECT, new Levels(), new Levels()));
assertEquals("Settings configured twice: " + Levels.class.getName(), twice.getMessage());
}
}
@@ -30,7 +30,7 @@ class DiscoveredModuleTest {
var module = new ShiftingIdentity();
var discovered = DiscoveredModule.builtIn(module);
var loaded = LoadedModules.load(List.of(discovered), Map.of(), Set.of());
var loaded = LoadedModules.load(List.of(discovered), Map.of(), Set.of(), Set.of());
assertEquals("first:core", discovered.info().id().toString());
assertEquals(List.of("first:core/mark"),
@@ -128,14 +128,14 @@ class ModuleRegistryTest {
public void install(StageGraph graph) { graph.define(WORK).when(One.class).run((context, one) -> {}); }
public void register(FeatureRegistry registry) { registry.registerObject(Two.class, ignored -> context -> null); }
};
var loaded = LoadedModules.load(List.of(DiscoveredModule.builtIn(conditioned)), Map.of(), Set.of());
var loaded = LoadedModules.load(List.of(DiscoveredModule.builtIn(conditioned)), Map.of(), Set.of(), Set.of());
assertEquals(List.of("test:core/one"), loaded.catalog().settings().stream().map(value -> value.id().toString()).toList());
assertEquals(1, loaded.catalog().objects().size());
assertEquals(1, loaded.placement().stages().size());
assertTrue(loaded.chunk().stages().isEmpty());
var reserved = Map.of(FeatureAttachment.Target.BIOME, Set.of("shared"));
assertThrows(IllegalArgumentException.class, () -> LoadedModules.load(List.of(DiscoveredModule.builtIn(conditioned)), reserved, Set.of()));
assertThrows(IllegalArgumentException.class, () -> LoadedModules.load(List.of(DiscoveredModule.builtIn(conditioned)), reserved, Set.of(), Set.of()));
}
@Test
@@ -180,11 +180,11 @@ class ModuleRegistryTest {
public void install(StageGraph graph) { graph.define(WORK).when(One.class).run((context, one) -> {}); }
};
var loaded = LoadedModules.load(List.of(DiscoveredModule.builtIn(owner), DiscoveredModule.builtIn(user)), Map.of(), Set.of());
var loaded = LoadedModules.load(List.of(DiscoveredModule.builtIn(owner), DiscoveredModule.builtIn(user)), Map.of(), Set.of(), Set.of());
assertEquals(List.of("test:core/one"), loaded.catalog().settings().stream().map(value -> value.id().toString()).toList());
var unowned = assertThrows(IllegalArgumentException.class,
() -> LoadedModules.load(List.of(DiscoveredModule.builtIn(user)), Map.of(), Set.of()));
() -> LoadedModules.load(List.of(DiscoveredModule.builtIn(user)), Map.of(), Set.of(), Set.of()));
assertTrue(unowned.getMessage().contains("which none of the modules naming it in when(...) owns"), unowned.getMessage());
}
@@ -44,7 +44,7 @@ class PackModulesTest {
private static LoadedModules loadWithBuiltIns(PackModules packModules) {
var modules = new ArrayList<>(PlacementModules.builtIns());
modules.addAll(packModules.modules());
return LoadedModules.load(modules, Map.of(), Set.of());
return LoadedModules.load(modules, Map.of(), Set.of(), Set.of());
}
/** Versioned entries of a multi-release jar are read like any class, so they must be real class files. */
@@ -343,7 +343,7 @@ class PackModulesTest {
try (var packModules = PackModules.load(pack)) {
assertEquals(List.of(new MissingClasses(origin("user.jar"), List.of(OPTIONAL_CLASS))), packModules.missingClasses());
assertDoesNotThrow(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of()));
assertDoesNotThrow(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of()));
}
}
@@ -477,7 +477,7 @@ class PackModulesTest {
.writeInto(pack, "beta.jar");
try (var packModules = PackModules.load(pack)) {
var loaded = LoadedModules.load(packModules.modules(), Map.of(), Set.of());
var loaded = LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of());
assertTrue(loaded.placement().stages().stream().anyMatch(stage -> stage.stage().id().toString().equals("beta:core/size")));
var beta = packModules.modules().getLast().module().getClass();
assertEquals(0, beta.getDeclaredField("SHARED").getAnnotations().length,
@@ -494,7 +494,7 @@ class PackModulesTest {
try (var packModules = PackModules.load(pack, List.of(BUILT_IN_PACKAGE))) {
var modules = new ArrayList<>(List.of(DiscoveredModule.builtIn(new CarveModule())));
modules.addAll(packModules.modules());
var order = LoadedModules.load(modules, Map.of(), Set.of()).placement().stages().stream()
var order = LoadedModules.load(modules, Map.of(), Set.of(), Set.of()).placement().stages().stream()
.map(stage -> stage.stage().id().toString()).toList();
assertEquals(List.of("iris:carve/clear", "user:core/carved"), order);
}
@@ -572,7 +572,7 @@ class PackModulesTest {
.writeInto(pack, "once.jar");
try (var packModules = PackModules.load(pack)) {
var loaded = assertDoesNotThrow(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of()));
var loaded = assertDoesNotThrow(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of()));
assertEquals("once:core", packModules.modules().getFirst().info().id().toString());
assertEquals(1, loaded.placement().stages().size());
}
@@ -591,7 +591,7 @@ class PackModulesTest {
.writeInto(pack, "beta.jar");
try (var packModules = PackModules.load(pack)) {
assertMentions(failure(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of())),
assertMentions(failure(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of())),
"Module beta:core from " + origin("beta.jar") + " failed to link or initialize a class while installing",
"java.lang.NoSuchMethodError", "pack.lib.Lib.added()");
}
@@ -603,7 +603,7 @@ class PackModulesTest {
module("pack.two.Duplicate", "dup:core", NO_MEMBERS, NO_STAGES).writeInto(pack, "two.jar");
try (var packModules = PackModules.load(pack)) {
assertMentions(failure(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of())),
assertMentions(failure(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of())),
"Duplicate module dup:core from " + origin("two.jar") + "; already loaded from " + origin("one.jar"));
}
}
@@ -625,7 +625,7 @@ class PackModulesTest {
.writeInto(pack, "foreign.jar");
try (var packModules = PackModules.load(pack)) {
assertMentions(failure(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of())),
assertMentions(failure(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of())),
"Stage mine:other/work must start with mine:core/, the id of its defining module mine:core from " + origin("foreign.jar"));
}
}
@@ -640,8 +640,8 @@ class PackModulesTest {
assertEquals("Module iris:stilt from " + origin("stilt.jar") + " uses reserved namespace 'iris', which only "
+ "modules that ship with the host may use; give the module a namespace of its own, which its stages, "
+ "settings ids and mantle keys then use too",
failure(() -> LoadedModules.load(packModules.modules(), Map.of(), RESERVED_NAMESPACES)));
assertDoesNotThrow(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of()));
failure(() -> LoadedModules.load(packModules.modules(), Map.of(), RESERVED_NAMESPACES, Set.of())));
assertDoesNotThrow(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of()));
}
}
@@ -654,13 +654,13 @@ class PackModulesTest {
try (var packModules = PackModules.load(pack, List.of(BUILT_IN_PACKAGE))) {
var modules = new ArrayList<>(List.of(DiscoveredModule.builtIn(new CarveModule())));
modules.addAll(packModules.modules());
assertDoesNotThrow(() -> LoadedModules.load(modules, Map.of(), RESERVED_NAMESPACES));
assertDoesNotThrow(() -> LoadedModules.load(modules, Map.of(), RESERVED_NAMESPACES, Set.of()));
}
}
@Test
void invalidReservedNamespaceFails() {
assertEquals("Reserved namespace 'iris:core' is not a namespace; name one such as iris, without ':' or a path",
failure(() -> LoadedModules.load(List.of(), Map.of(), Set.of("iris:core"))));
failure(() -> LoadedModules.load(List.of(), Map.of(), Set.of("iris:core"), Set.of())));
}
}
@@ -4,7 +4,9 @@ import com.volmit.FeatureAttachment.Target;
import com.volmit.config.Reference;
import com.volmit.example.chunk.GrassModule;
import com.volmit.example.chunk.TerrainModule;
import com.volmit.example.hosttypes.Palette;
import com.volmit.example.placement.PlacementModules;
import com.volmit.example.terrain.LayersModule;
import com.volmit.host.schema.FeatureRole;
import com.volmit.host.schema.FeatureSchema;
import com.volmit.host.schema.ObjectType;
@@ -15,6 +17,7 @@ import com.volmit.host.schema.ValueKind.BooleanKind;
import com.volmit.host.schema.ValueKind.DecimalKind;
import com.volmit.host.schema.ValueKind.EnumConstant;
import com.volmit.host.schema.ValueKind.EnumKind;
import com.volmit.host.schema.ValueKind.HostKind;
import com.volmit.host.schema.ValueKind.IntegerKind;
import com.volmit.host.schema.ValueKind.ListKind;
import com.volmit.host.schema.ValueKind.MapKind;
@@ -40,6 +43,7 @@ import static org.junit.jupiter.api.Assertions.*;
class PackSchemaTest {
private static final ModuleHost NO_BUILT_INS = ModuleHost.of(List.of());
private static final String FLORA = "example:flora";
private static final String HOST_TYPES = "com.volmit.example.hosttypes";
private static final String FLORA_SOURCE = "settings example:flora (module example:flora from modules/flora.jar)";
private static final String NO_STAGES = "";
@@ -338,10 +342,49 @@ class PackSchemaTest {
false, OptionalDouble.empty(), OptionalDouble.empty(), Optional.of("minecraft:grass_block")), grass.settings().options().getFirst());
}
@Test
void builtInSettingsMayHoldHostTypesWhichTheHostDescribesItself() {
var builtIns = List.<com.volmit.IrisModule>of(new LayersModule());
var schema = schemaOf(pack("layers"), ModuleHost.of(builtIns).describingHostTypesIn(HOST_TYPES));
var layers = schema.fields(Target.BIOME).getFirst();
var option = layers.settings().options().getFirst();
assertEquals(new ListKind(new HostKind(Palette.class.getName()), false), option.kind());
assertEquals(Optional.of(List.of()), option.defaultValue());
assertTrue(schema.types().stream().noneMatch(type -> type.name().equals(Palette.class.getName())),
"the host describes its own types, so their fields are never read");
assertEquals(Optional.of(option), layers.shorthand(), "one option: packs may write the bare list");
var undeclared = assertThrows(IllegalArgumentException.class, () -> schemaOf(pack("layers"), ModuleHost.of(builtIns)));
assertTrue(undeclared.getMessage().startsWith("Field " + Palette.class.getName() + ".anything of settings iris:layers"),
undeclared.getMessage());
assertThrows(IllegalArgumentException.class, () -> NO_BUILT_INS.describingHostTypesIn("not a package"));
}
@Test
void packModulesCannotUseHostTypes() {
var host = NO_BUILT_INS.exposing(HOST_TYPES).describingHostTypesIn(HOST_TYPES);
assertEquals("Field pack.flora.FloraSettings.palette of " + FLORA_SOURCE + " uses " + Palette.class.getName()
+ ", a class the host describes itself, which only settings of modules that ship with the host may use; "
+ ValueKinds.SUPPORTED_TYPES,
loadFailure(host, "private " + Palette.class.getName() + " palette;").getMessage());
}
@Test
void onlySettingsWithOneOptionHaveAShorthand() {
var flora = floraSchema().fields(Target.BIOME).getFirst();
assertEquals(Optional.empty(), flora.shorthand());
}
/** A pack whose module example:flora registers pack.flora.FloraSettings with {@code body} as its class body. */
private IllegalArgumentException loadFailure(String body, String... otherSources) {
return loadFailure(NO_BUILT_INS, body, otherSources);
}
private IllegalArgumentException loadFailure(ModuleHost host, String body, String... otherSources) {
var jar = module("pack.flora.FloraModule", FLORA,
"public void register(com.volmit.FeatureRegistry registry) { registry.registerSettings(FloraSettings.class); }", NO_STAGES)
.compileAgainstHostOf(Palette.class)
.source("pack.flora.FloraSettings", """
package pack.flora;
@@ -362,7 +405,7 @@ class PackSchemaTest {
}
var pack = pack("broken-" + ++brokenPacks);
jar.writeInto(pack, "flora.jar");
return assertThrows(IllegalArgumentException.class, () -> LoadedPack.load(pack, NO_BUILT_INS));
return assertThrows(IllegalArgumentException.class, () -> LoadedPack.load(pack, host));
}
private void assertLoadFails(String expected, String body, String... otherSources) {
@@ -374,7 +374,7 @@ class StageGraphTest {
place(graph, flatEdit(), ConfiguredSettings.none());
assertEquals(List.of("unrelated"), events);
events.clear();
place(graph, flatEdit(), ConfiguredSettings.of(new Toggle()));
place(graph, flatEdit(), ConfiguredSettings.placement(ResourceId.parse("test:placement"), new Toggle()));
assertEquals(List.of("toggled", "dependent:1", "unrelated"), events);
}
@@ -452,6 +452,8 @@ class StageGraphTest {
var empty = resolve(Pipeline.CHUNK);
assertThrows(IllegalArgumentException.class, () -> new PlacementRunner(empty));
assertThrows(IllegalArgumentException.class, () -> new ChunkRunner(resolve(Pipeline.PLACEMENT)));
assertThrows(IllegalArgumentException.class, () -> new MantleRunner(empty));
assertThrows(IllegalArgumentException.class, () -> new ChunkRunner(resolve(Pipeline.MANTLE)));
assertTrue(empty.describe().contains("CHUNK pipeline: 0 stages, 0 block passes"));
}
@@ -463,9 +465,9 @@ class StageGraphTest {
void reachIsDeclaredPerStageAndCollectedPerPipelineAndLayer() {
var depth = new MantleKey<>("test:reach/depth", Integer.class);
var marks = new MantleKey<>("test:reach/marks", String.class);
var carve = Stage.chunk("test:reach/carve");
var mark = Stage.chunk("test:reach/mark");
var plain = Stage.chunk("test:reach/plain");
var carve = Stage.mantle("test:reach/carve");
var mark = Stage.mantle("test:reach/mark");
var plain = Stage.mantle("test:reach/plain");
var paint = Stage.placementBlock("test:reach/paint");
var reach = module("test:reach", stages -> {
stages.define(carve).reach(24).writesMantle(depth).run(context -> {});
@@ -473,42 +475,60 @@ class StageGraphTest {
stages.define(plain).run(context -> {});
stages.define(paint).reach(2).run(context -> {});
});
var loaded = LoadedModules.load(List.of(DiscoveredModule.builtIn(withMantle(reach, depth, marks))), Map.of(), Set.of());
var loaded = LoadedModules.load(List.of(DiscoveredModule.builtIn(withMantle(reach, depth, marks))), Map.of(), Set.of(), Set.of());
assertEquals(new StageReach(24, List.of(depth)), loaded.chunk().stages().getFirst().reach());
assertEquals(StageReach.NONE, loaded.chunk().stages().get(2).reach(), "an undeclared reach is 0 with no layers");
assertEquals(new PipelineReach(24, Map.of("test:reach/depth", 24, "test:reach/marks", 8)), loaded.chunk().reach());
assertEquals(new StageReach(24, List.of(depth)), loaded.mantle().stages().getFirst().reach());
assertEquals(StageReach.NONE, loaded.mantle().stages().get(2).reach(), "an undeclared reach is 0 with no layers");
assertEquals(new PipelineReach(24, Map.of("test:reach/depth", 24, "test:reach/marks", 8)), loaded.mantle().reach());
assertEquals(new PipelineReach(2, Map.of()), loaded.placement().reach());
assertTrue(loaded.chunk().describe().contains(" reach 24 blocks, writes mantle test:reach/depth\n"), loaded.chunk().describe());
assertTrue(loaded.chunk().describe().contains(" reach 8 blocks, writes mantle test:reach/depth, test:reach/marks\n"));
assertEquals(new PipelineReach(0, Map.of()), loaded.chunk().reach());
assertTrue(loaded.mantle().describe().contains(" reach 24 blocks, writes mantle test:reach/depth\n"), loaded.mantle().describe());
assertTrue(loaded.mantle().describe().contains(" reach 8 blocks, writes mantle test:reach/depth, test:reach/marks\n"));
}
@Test
void reachMustBeValidAndNameRegisteredLayers() {
var depth = new MantleKey<>("test:reach/depth", Integer.class);
var carve = Stage.chunk("test:reach/carve");
var carve = Stage.mantle("test:reach/carve");
var negative = assertThrows(IllegalArgumentException.class, () -> resolve(Pipeline.CHUNK,
var negative = assertThrows(IllegalArgumentException.class, () -> resolve(Pipeline.MANTLE,
module("test:reach", stages -> stages.define(carve).reach(-1).run(context -> {}))));
assertEquals("Stage test:reach/carve (module test:reach) declares a negative reach of -1 blocks", negative.getMessage());
var twice = assertThrows(IllegalStateException.class, () -> resolve(Pipeline.CHUNK,
var twice = assertThrows(IllegalStateException.class, () -> resolve(Pipeline.MANTLE,
module("test:reach", stages -> stages.define(carve).reach(1).reach(2).run(context -> {}))));
assertEquals("Stage test:reach/carve (module test:reach) already declares a reach of 1 blocks", twice.getMessage());
assertThrows(IllegalArgumentException.class, () -> resolve(Pipeline.CHUNK,
assertThrows(IllegalArgumentException.class, () -> resolve(Pipeline.MANTLE,
module("test:reach", stages -> stages.define(carve).writesMantle(depth, depth).run(context -> {}))));
var unregistered = assertThrows(IllegalArgumentException.class, () -> LoadedModules.load(List.of(DiscoveredModule.builtIn(
module("test:reach", stages -> stages.define(carve).writesMantle(depth).run(context -> {})))), Map.of(), Set.of()));
module("test:reach", stages -> stages.define(carve).writesMantle(depth).run(context -> {})))), Map.of(), Set.of(), Set.of()));
assertEquals("Stage test:reach/carve of module test:reach writes mantle layer test:reach/depth, which no module registers;"
+ " its owner registers it with FeatureRegistry.registerMantle", unregistered.getMessage());
var asText = new MantleKey<>("test:reach/depth", String.class);
var mismatch = assertThrows(IllegalArgumentException.class, () -> LoadedModules.load(List.of(DiscoveredModule.builtIn(withMantle(
module("test:reach", stages -> stages.define(carve).writesMantle(asText).run(context -> {})), depth))), Map.of(), Set.of()));
module("test:reach", stages -> stages.define(carve).writesMantle(asText).run(context -> {})), depth))), Map.of(), Set.of(), Set.of()));
assertEquals("Stage test:reach/carve of module test:reach writes mantle layer test:reach/depth as java.lang.String,"
+ " but it is registered as java.lang.Integer", mismatch.getMessage());
}
@Test
void chunkStagesNeitherReachBeyondTheirChunkNorWriteTheMantle() {
var depth = new MantleKey<>("test:reach/depth", Integer.class);
var carve = Stage.chunk("test:reach/carve");
var reach = assertThrows(IllegalArgumentException.class, () -> resolve(Pipeline.CHUNK,
module("test:reach", stages -> stages.define(carve).reach(8).run(context -> {}))));
assertEquals("Stage test:reach/carve (module test:reach) is a chunk stage and declares a reach of 8 blocks, but chunk"
+ " stages write only their own chunk and read the mantle; define work that writes the mantle or reaches beyond"
+ " its chunk as a mantle stage (Stage.mantle), which runs before the chunks it reaches", reach.getMessage());
var writes = assertThrows(IllegalArgumentException.class, () -> resolve(Pipeline.CHUNK,
module("test:reach", stages -> stages.define(carve).writesMantle(depth).run(context -> {}))));
assertTrue(writes.getMessage().startsWith("Stage test:reach/carve (module test:reach) is a chunk stage and declares mantle writes"),
writes.getMessage());
assertDoesNotThrow(() -> resolve(Pipeline.CHUNK, module("test:reach", stages -> stages.define(carve).reach(0).run(context -> {}))));
}
/** {@code module}, also registering {@code layers}. */
private static IrisModule withMantle(IrisModule module, MantleKey<?>... layers) {
return new IrisModule() {
@@ -131,7 +131,7 @@ class StageStreamsTest {
var graph = resolve(Pipeline.CHUNK, module("a:mod", stages -> stages.define(Stage.chunk("a:mod/ores"))
.run(context -> drawn.add((long) context.random().nextInt(BOUND)))));
new ChunkRunner(graph).generate(TestContexts.generation(Map.of()), TestContexts.SEED, ConfiguredSettings.none());
new ChunkRunner(graph).generate(TestContexts.generation(Map.of()), TestContexts.SEED);
assertEquals(firstDraws(TestContexts.SEED, "a:mod/ores", 1), drawn);
}
@@ -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;
}
}