mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
Key settings by feature id, order options as declared and declare stage reach
- Packs write settings under the feature id. @Feature(field) becomes an optional alias that only built-in modules may set, so existing pack JSON keeps loading; a pack module setting one fails the load. Reserved host fields now only constrain aliases. FeatureSchema exposes key and alias. - Pack snippet names live under their module's folder (snippet/<namespace>/<path>/...); snippet names are folder paths. - OptionsMetadata lists options in declaration order, read from the class file, a superclass's first. - @Ref(PACK_BIOME|PACK_REGION|PACK_OBJECT) fits String only. - Stage definitions declare reach(blocks) and writesMantle(layers); ResolvedGraph.reach() collects the pipeline and per-layer maximum, and the load fails on an unregistered or mistyped layer.
This commit is contained in:
1 parent
b12e7a8c49
commit
a325640d5d
38 files changed
+761
-138
No files matched your search
@@ -11,7 +11,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
class FeatureContractTest {
|
||||
@Desc("Example settings")
|
||||
@Snippet("fill-settings")
|
||||
@Feature(id = "example:fill", name = "Fill", field = "fill", targets = FeatureAttachment.Target.BIOME)
|
||||
@Feature(id = "example:fill", name = "Fill", alias = "fill", targets = FeatureAttachment.Target.BIOME)
|
||||
public static class FillOptions implements IrisFeature {
|
||||
@Desc("Replacement value")
|
||||
@MinNumber(0)
|
||||
@@ -39,7 +39,8 @@ class FeatureContractTest {
|
||||
void descriptorReadsFeatureIdentityAndAttachment() {
|
||||
var descriptor = FeatureDescriptor.of(FillOptions.class);
|
||||
assertEquals(ResourceId.parse("example:fill"), descriptor.id());
|
||||
assertEquals("fill", descriptor.attachment().field());
|
||||
assertEquals("example:fill", descriptor.key());
|
||||
assertEquals(java.util.Optional.of("fill"), descriptor.alias());
|
||||
assertEquals(java.util.Set.of(FeatureAttachment.Target.BIOME), descriptor.attachment().targets());
|
||||
assertEquals(1, descriptor.options().options().size());
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.volmit.config.Desc;
|
||||
import com.volmit.config.Feature;
|
||||
|
||||
@Desc("Covers the top of every terrain column")
|
||||
@Feature(id = "example:grass", name = "Grass", field = "grass", targets = FeatureAttachment.Target.BIOME)
|
||||
@Feature(id = "example:grass", name = "Grass", targets = FeatureAttachment.Target.BIOME)
|
||||
public final class GrassSettings implements IrisFeature {
|
||||
@Desc("Block placed on top of each column")
|
||||
private BlockState block = new BlockState("minecraft:grass_block");
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.volmit.IrisFeature;
|
||||
import com.volmit.config.Feature;
|
||||
import com.volmit.config.MinNumber;
|
||||
|
||||
@Feature(id = "example:moss", name = "Moss", field = "moss", targets = FeatureAttachment.Target.OBJECT_PLACEMENT)
|
||||
@Feature(id = "example:moss", name = "Moss", targets = FeatureAttachment.Target.OBJECT_PLACEMENT)
|
||||
public final class MossSettings implements IrisFeature {
|
||||
@MinNumber(0)
|
||||
private int radius;
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.volmit.config.Feature;
|
||||
import com.volmit.config.MaxNumber;
|
||||
import com.volmit.config.MinNumber;
|
||||
|
||||
@Feature(id = "iris:snow", name = "Snow", field = "snow", targets = FeatureAttachment.Target.OBJECT_PLACEMENT)
|
||||
@Feature(id = "iris:snow", name = "Snow", alias = "snow", targets = FeatureAttachment.Target.OBJECT_PLACEMENT)
|
||||
public final class SnowSettings implements IrisFeature {
|
||||
@MinNumber(1)
|
||||
@MaxNumber(8)
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.volmit.config.Feature;
|
||||
import com.volmit.config.MinNumber;
|
||||
|
||||
@Desc("Fills the space below an object down to the ground")
|
||||
@Feature(id = "iris:stilt", name = "Stilt", field = "stilt", targets = FeatureAttachment.Target.OBJECT_PLACEMENT)
|
||||
@Feature(id = "iris:stilt", name = "Stilt", alias = "stilt", targets = FeatureAttachment.Target.OBJECT_PLACEMENT)
|
||||
public final class StiltSettings implements IrisFeature {
|
||||
@Desc("Maximum blocks filled below each lowest object block")
|
||||
@MinNumber(1)
|
||||
|
||||
@@ -16,16 +16,16 @@ import java.util.function.Consumer;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class ModuleRegistryTest {
|
||||
@Feature(id = "test:core/one", name = "One", field = "shared", targets = FeatureAttachment.Target.BIOME)
|
||||
@Feature(id = "test:core/one", name = "One", alias = "shared", targets = FeatureAttachment.Target.BIOME)
|
||||
static class One implements IrisFeature {}
|
||||
@Feature(id = "test:core/two", name = "Two", field = "shared", targets = FeatureAttachment.Target.DIMENSION)
|
||||
@Feature(id = "test:core/two", name = "Two", alias = "shared", targets = FeatureAttachment.Target.DIMENSION)
|
||||
static class Two implements IrisFeature {}
|
||||
@Feature(id = "test:core/collision", name = "Collision", field = "shared", targets = {FeatureAttachment.Target.DIMENSION, FeatureAttachment.Target.BIOME})
|
||||
@Feature(id = "test:core/collision", name = "Collision", alias = "shared", targets = {FeatureAttachment.Target.DIMENSION, FeatureAttachment.Target.BIOME})
|
||||
static class Collision implements IrisFeature {}
|
||||
@Feature(id = "test:core/one", name = "Duplicate", field = "different", targets = FeatureAttachment.Target.REGION)
|
||||
@Feature(id = "test:core/one", name = "Duplicate", alias = "different", targets = FeatureAttachment.Target.REGION)
|
||||
static class Duplicate implements IrisFeature {}
|
||||
static class MissingAnnotation implements IrisFeature {}
|
||||
@Feature(id = "test:core/abstract", name = "Abstract", field = "abstract", targets = FeatureAttachment.Target.BIOME)
|
||||
@Feature(id = "test:core/abstract", name = "Abstract", alias = "abstract", targets = FeatureAttachment.Target.BIOME)
|
||||
abstract static class AbstractFeature implements IrisFeature {}
|
||||
|
||||
/** Runs {@code registrations} as the register(...) of a built-in module with the given id. */
|
||||
@@ -40,7 +40,7 @@ class ModuleRegistryTest {
|
||||
@Test
|
||||
void validatesIdsTypesAndFieldsAcrossFeatureKindsWithoutPartialRegistration() {
|
||||
var registry = new ModuleRegistry();
|
||||
registry.registerStageSettings(One.class);
|
||||
registerAs(registry, "test:core", settings -> settings.registerSettings(One.class));
|
||||
registry.registerStageSettings(One.class);
|
||||
registerAs(registry, "test:core", objects -> {
|
||||
assertThrows(IllegalArgumentException.class, () -> objects.registerObject(Collision.class, ignored -> context -> null));
|
||||
@@ -56,7 +56,10 @@ class ModuleRegistryTest {
|
||||
@Test
|
||||
void reservesHostFieldsAndRejectsInvalidFeaturesOrFactories() {
|
||||
var registry = new ModuleRegistry(Map.of(FeatureAttachment.Target.BIOME, Set.of("shared")));
|
||||
assertThrows(IllegalArgumentException.class, () -> registry.registerStageSettings(One.class));
|
||||
assertThrows(IllegalStateException.class, () -> registry.registerStageSettings(One.class), "no module owns it yet");
|
||||
registerAs(registry, "test:core", nothing -> {});
|
||||
var reserved = assertThrows(IllegalArgumentException.class, () -> registry.registerStageSettings(One.class));
|
||||
assertTrue(reserved.getMessage().startsWith("Alias collision"), reserved.getMessage());
|
||||
assertThrows(IllegalArgumentException.class, () -> registry.registerStageSettings(MissingAnnotation.class));
|
||||
assertThrows(IllegalArgumentException.class, () -> registry.registerStageSettings(AbstractFeature.class));
|
||||
registerAs(registry, "test:core", objects -> {
|
||||
@@ -160,7 +163,7 @@ class ModuleRegistryTest {
|
||||
registerAs(registry, "test:core", settings -> settings.registerObject(Two.class, ignored -> context -> null));
|
||||
var collision = assertThrows(IllegalArgumentException.class,
|
||||
() -> registerAs(registry, "test:core", settings -> settings.registerSettings(Collision.class)));
|
||||
assertTrue(collision.getMessage().startsWith("JSON field collision"), collision.getMessage());
|
||||
assertTrue(collision.getMessage().startsWith("Alias collision"), collision.getMessage());
|
||||
assertTrue(registry.freeze().settings().isEmpty());
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ class PackSchemaTest {
|
||||
import java.util.*;
|
||||
|
||||
@Desc("Plants flowers and bushes")
|
||||
@Feature(id = "example:flora", name = "Flora", field = "flora", targets = {Target.REGION, Target.BIOME})
|
||||
@Feature(id = "example:flora", name = "Flora", targets = {Target.REGION, Target.BIOME})
|
||||
public final class FloraSettings implements IrisFeature {
|
||||
@Desc("Plants per chunk") @Required @MinNumber(0) @MaxNumber(64)
|
||||
private int density = 4;
|
||||
@@ -114,7 +114,7 @@ class PackSchemaTest {
|
||||
import com.volmit.config.*;
|
||||
|
||||
@Desc("A patch of plants")
|
||||
@Snippet("flora-patch")
|
||||
@Snippet("example/flora/patch")
|
||||
final class Patch {
|
||||
@MinNumber(1)
|
||||
private int radius = 3;
|
||||
@@ -131,7 +131,7 @@ class PackSchemaTest {
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.config.*;
|
||||
|
||||
@Feature(id = "example:flora/wind", name = "Wind", field = "wind", targets = Target.DIMENSION)
|
||||
@Feature(id = "example:flora/wind", name = "Wind", targets = Target.DIMENSION)
|
||||
public final class WindSettings implements IrisFeature {
|
||||
@Desc("How far plants sway")
|
||||
private double strength = 1.5;
|
||||
@@ -145,8 +145,8 @@ class PackSchemaTest {
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.config.*;
|
||||
|
||||
@Snippet("bush")
|
||||
@Feature(id = "example:flora/bush", name = "Bush", field = "bush", targets = Target.OBJECT_PLACEMENT)
|
||||
@Snippet("example/flora/bush")
|
||||
@Feature(id = "example:flora/bush", name = "Bush", targets = Target.OBJECT_PLACEMENT)
|
||||
public final class BushSettings implements IrisFeature {
|
||||
private int height = 2;
|
||||
}
|
||||
@@ -190,13 +190,14 @@ class PackSchemaTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void attachesEveryModuleFieldToItsTargets() {
|
||||
void attachesEveryModuleFeatureToItsTargetsUnderItsId() {
|
||||
var schema = floraSchema();
|
||||
|
||||
assertEquals(List.of("flora"), names(schema.fields(Target.BIOME), FeatureSchema::field));
|
||||
assertEquals(List.of("flora"), names(schema.fields(Target.REGION), FeatureSchema::field));
|
||||
assertEquals(List.of("wind"), names(schema.fields(Target.DIMENSION), FeatureSchema::field));
|
||||
assertEquals(List.of("bush"), names(schema.fields(Target.OBJECT_PLACEMENT), FeatureSchema::field));
|
||||
assertEquals(List.of("example:flora"), names(schema.fields(Target.BIOME), FeatureSchema::key));
|
||||
assertEquals(List.of("example:flora"), names(schema.fields(Target.REGION), FeatureSchema::key));
|
||||
assertEquals(List.of("example:flora/wind"), names(schema.fields(Target.DIMENSION), FeatureSchema::key));
|
||||
assertEquals(List.of("example:flora/bush"), names(schema.fields(Target.OBJECT_PLACEMENT), FeatureSchema::key));
|
||||
assertTrue(schema.features().stream().allMatch(feature -> feature.alias().isEmpty()), "pack modules have no alias");
|
||||
assertEquals(List.of("example:flora", "example:flora/bush", "example:flora/wind"), names(schema.features(), FeatureSchema::id));
|
||||
|
||||
var flora = schema.features().getFirst();
|
||||
@@ -211,11 +212,11 @@ class PackSchemaTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void describesOptionsInNameOrderWithChecksAndDefaults() {
|
||||
void describesOptionsInDeclarationOrderWithChecksAndDefaults() {
|
||||
var settings = floraSchema().type("pack.flora.FloraSettings");
|
||||
|
||||
assertEquals(List.of("biomes", "chance", "density", "drops", "enabled", "extra", "flower", "ground", "label",
|
||||
"palette", "patch", "season", "seasons", "seedOffset", "spread", "weights"),
|
||||
assertEquals(List.of("density", "chance", "spread", "seedOffset", "enabled", "label", "palette", "ground", "biomes",
|
||||
"drops", "flower", "season", "seasons", "weights", "patch", "extra"),
|
||||
settings.options().stream().map(SchemaOption::name).toList());
|
||||
assertEquals(new SchemaOption("density", new IntegerKind(), "Plants per chunk", true,
|
||||
OptionalDouble.of(0), OptionalDouble.of(64), Optional.of(4L)), option(settings, "density"));
|
||||
@@ -273,7 +274,7 @@ class PackSchemaTest {
|
||||
assertEquals(Optional.of(Map.of("bloom", "SUMMER", "radius", 3L)), option(settings, "patch").defaultValue(),
|
||||
"an object default holds the options that have one");
|
||||
assertEquals("A patch of plants", patch.description());
|
||||
assertEquals(List.of("bloom", "child", "radius"), patch.options().stream().map(SchemaOption::name).toList());
|
||||
assertEquals(List.of("radius", "bloom", "child"), patch.options().stream().map(SchemaOption::name).toList());
|
||||
assertEquals(new ObjectKind("pack.flora.Patch"), option(patch, "child").kind());
|
||||
assertEquals("A smaller patch inside this one", option(patch, "child").description());
|
||||
assertEquals(OptionalDouble.of(1), option(patch, "radius").minimum());
|
||||
@@ -283,7 +284,7 @@ class PackSchemaTest {
|
||||
void listsSnippetsObjectGeneratorsAndExplicitlyRegisteredSettings() {
|
||||
var schema = floraSchema();
|
||||
|
||||
assertEquals(List.of("bush", "flora-patch"), schema.snippets().stream().map(type -> type.snippet().orElseThrow()).toList());
|
||||
assertEquals(List.of("example/flora/bush", "example/flora/patch"), schema.snippets().stream().map(type -> type.snippet().orElseThrow()).toList());
|
||||
assertEquals(List.of("pack.flora.BushSettings", "pack.flora.Patch"), schema.snippets().stream().map(ObjectType::name).toList());
|
||||
|
||||
var bush = schema.objectGenerators().getFirst();
|
||||
@@ -322,7 +323,9 @@ class PackSchemaTest {
|
||||
var schema = schemaOf(pack("empty"), ModuleHost.of(builtIns));
|
||||
|
||||
assertEquals(List.of("example:grass", "example:moss", "iris:snow", "iris:stilt"), names(schema.features(), FeatureSchema::id));
|
||||
assertEquals(List.of("moss", "snow", "stilt"), names(schema.fields(Target.OBJECT_PLACEMENT), FeatureSchema::field));
|
||||
assertEquals(List.of("example:moss", "iris:snow", "iris:stilt"), names(schema.fields(Target.OBJECT_PLACEMENT), FeatureSchema::key));
|
||||
assertEquals(List.of("", "snow", "stilt"), names(schema.fields(Target.OBJECT_PLACEMENT), feature -> feature.alias().orElse("")),
|
||||
"built-ins keep their short aliases");
|
||||
|
||||
var stilt = schema.fields(Target.OBJECT_PLACEMENT).get(2);
|
||||
assertEquals("Stilts", stilt.module().name());
|
||||
@@ -349,7 +352,7 @@ class PackSchemaTest {
|
||||
import com.volmit.resource.*;
|
||||
import java.util.*;
|
||||
|
||||
@Feature(id = "example:flora", name = "Flora", field = "flora", targets = Target.BIOME)
|
||||
@Feature(id = "example:flora", name = "Flora", targets = Target.BIOME)
|
||||
public final class FloraSettings implements IrisFeature {
|
||||
%s
|
||||
}
|
||||
@@ -379,7 +382,7 @@ class PackSchemaTest {
|
||||
import com.volmit.config.Feature;
|
||||
import java.util.*;
|
||||
|
||||
@Feature(id = "example:flora", name = "Flora", field = "flora", targets = Target.BIOME)
|
||||
@Feature(id = "example:flora", name = "Flora", targets = Target.BIOME)
|
||||
public final class FloraSettings implements IrisFeature {
|
||||
private Node node = new Node();
|
||||
private double ratio = Double.NaN;
|
||||
@@ -449,14 +452,90 @@ class PackSchemaTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void snippetNamesAreFolderNamesThatBelongToOneClass() {
|
||||
assertLoadFails("Snippet name 'Big Patch' of pack.flora.Patch of " + FLORA_SOURCE + " is not a folder name; packs write snippets under"
|
||||
+ " snippet/<name>/, so use lowercase letters, digits, '-' and '_'",
|
||||
"private Patch patch;", "pack.flora.Patch", "package pack.flora; @com.volmit.config.Snippet(\"Big Patch\") final class Patch {}");
|
||||
assertLoadFails("Snippet name 'patch' is used by pack.flora.Patch of " + FLORA_SOURCE + " and by pack.flora.Plot of " + FLORA_SOURCE
|
||||
+ "; studio describes snippet/patch/ by one class, so give each its own name",
|
||||
void snippetNamesAreFolderPathsThatBelongToOneClass() {
|
||||
var notAPath = "is not a folder path; packs write snippets under snippet/<name>/, so use lowercase letters, digits, '-', '_'"
|
||||
+ " and '.', with '/' between folders";
|
||||
assertLoadFails("Snippet name 'example/flora/Big Patch' of pack.flora.Patch of " + FLORA_SOURCE + " " + notAPath,
|
||||
"private Patch patch;", "pack.flora.Patch", "package pack.flora; @com.volmit.config.Snippet(\"example/flora/Big Patch\") final class Patch {}");
|
||||
assertLoadFails("Snippet name 'example/flora/../moss' of pack.flora.Patch of " + FLORA_SOURCE + " " + notAPath,
|
||||
"private Patch patch;", "pack.flora.Patch", "package pack.flora; @com.volmit.config.Snippet(\"example/flora/../moss\") final class Patch {}");
|
||||
assertLoadFails("Snippet name 'example/flora/patch' is used by pack.flora.Patch of " + FLORA_SOURCE + " and by pack.flora.Plot of " + FLORA_SOURCE
|
||||
+ "; studio describes snippet/example/flora/patch/ by one class, so give each its own name",
|
||||
"private Patch patch; private Plot plot;",
|
||||
"pack.flora.Patch", "package pack.flora; @com.volmit.config.Snippet(\"patch\") final class Patch {}",
|
||||
"pack.flora.Plot", "package pack.flora; @com.volmit.config.Snippet(\"patch\") final class Plot {}");
|
||||
"pack.flora.Patch", "package pack.flora; @com.volmit.config.Snippet(\"example/flora/patch\") final class Patch {}",
|
||||
"pack.flora.Plot", "package pack.flora; @com.volmit.config.Snippet(\"example/flora/patch\") final class Plot {}");
|
||||
}
|
||||
|
||||
@Test
|
||||
void packSnippetsLiveUnderTheirModulesFolder() {
|
||||
assertLoadFails("Snippet name 'patch' of pack.flora.Patch of " + FLORA_SOURCE + " is not under a module of the pack; snippets of pack"
|
||||
+ " modules start with their module's id as a folder path, such as 'example/flora/patch' (folder snippet/example/flora/patch/)",
|
||||
"private Patch patch;", "pack.flora.Patch", "package pack.flora; @com.volmit.config.Snippet(\"patch\") final class Patch {}");
|
||||
assertLoadFails("Snippet name 'example/florae/patch' of pack.flora.Patch of " + FLORA_SOURCE + " is not under a module of the pack;"
|
||||
+ " snippets of pack modules start with their module's id as a folder path, such as 'example/flora/patch'"
|
||||
+ " (folder snippet/example/flora/patch/)",
|
||||
"private Patch patch;", "pack.flora.Patch", "package pack.flora; @com.volmit.config.Snippet(\"example/florae/patch\") final class Patch {}");
|
||||
|
||||
var pack = pack("module-folder");
|
||||
module("pack.flora.FloraModule", FLORA,
|
||||
"public void register(com.volmit.FeatureRegistry registry) { registry.registerSettings(FloraSettings.class); }", NO_STAGES)
|
||||
.source("pack.flora.FloraSettings", """
|
||||
package pack.flora;
|
||||
|
||||
@com.volmit.config.Snippet("example/flora")
|
||||
@com.volmit.config.Feature(id = "example:flora", name = "Flora", targets = com.volmit.FeatureAttachment.Target.BIOME)
|
||||
public final class FloraSettings implements com.volmit.IrisFeature {}
|
||||
""")
|
||||
.writeInto(pack, "flora.jar");
|
||||
assertEquals(List.of("example/flora"), schemaOf(pack, NO_BUILT_INS).snippets().stream()
|
||||
.map(type -> type.snippet().orElseThrow()).toList(), "the module's own folder is under its path");
|
||||
}
|
||||
|
||||
@Test
|
||||
void packModulesCannotSetAnAlias() {
|
||||
var pack = pack("alias");
|
||||
module("pack.flora.FloraModule", FLORA,
|
||||
"public void register(com.volmit.FeatureRegistry registry) { registry.registerSettings(FloraSettings.class); }", NO_STAGES)
|
||||
.source("pack.flora.FloraSettings", """
|
||||
package pack.flora;
|
||||
|
||||
@com.volmit.config.Feature(id = "example:flora", name = "Flora", alias = "flora", targets = com.volmit.FeatureAttachment.Target.BIOME)
|
||||
public final class FloraSettings implements com.volmit.IrisFeature {}
|
||||
""")
|
||||
.writeInto(pack, "flora.jar");
|
||||
|
||||
var failure = assertThrows(IllegalArgumentException.class, () -> LoadedPack.load(pack, NO_BUILT_INS));
|
||||
|
||||
assertEquals("Settings pack.flora.FloraSettings of module example:flora from modules/flora.jar set alias 'flora'; only modules"
|
||||
+ " that ship with the host may set one, so remove it: packs write these settings under their id \"example:flora\"",
|
||||
failure.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void packReferencesFitOnlyPlainText() {
|
||||
assertLoadFails("Field pack.flora.FloraSettings.home of " + FLORA_SOURCE + " has @Ref(PACK_BIOME) on ResourceId, but packs name"
|
||||
+ " their biomes, regions and objects by path without a namespace, such as desert/dunes; use String",
|
||||
"@Ref(Reference.PACK_BIOME) private ResourceId home;");
|
||||
assertTrue(loadFailure("@Ref(Reference.PACK_OBJECT) private List<ResourceId> objects;").getMessage()
|
||||
.contains("has @Ref(PACK_OBJECT) on ResourceId"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void inheritedOptionsComeBeforeTheirSubclasssOwn() {
|
||||
var pack = pack("inherited");
|
||||
module("pack.flora.FloraModule", FLORA,
|
||||
"public void register(com.volmit.FeatureRegistry registry) { registry.registerSettings(FloraSettings.class); }", NO_STAGES)
|
||||
.source("pack.flora.Base", "package pack.flora; abstract class Base { private int zeta; private int alpha; }")
|
||||
.source("pack.flora.FloraSettings", """
|
||||
package pack.flora;
|
||||
|
||||
@com.volmit.config.Feature(id = "example:flora", name = "Flora", targets = com.volmit.FeatureAttachment.Target.BIOME)
|
||||
public final class FloraSettings extends Base implements com.volmit.IrisFeature { private int omega; private int beta; }
|
||||
""")
|
||||
.writeInto(pack, "flora.jar");
|
||||
|
||||
var settings = schemaOf(pack, NO_BUILT_INS).type("pack.flora.FloraSettings");
|
||||
|
||||
assertEquals(List.of("zeta", "alpha", "omega", "beta"), settings.options().stream().map(SchemaOption::name).toList());
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,16 @@
|
||||
package com.volmit.host;
|
||||
|
||||
import com.volmit.FeatureAttachment;
|
||||
import com.volmit.FeatureRegistry;
|
||||
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.mantle.BlockBox;
|
||||
import com.volmit.mantle.MantleCodec;
|
||||
import com.volmit.mantle.MantleKey;
|
||||
import com.volmit.mantle.MantleLifetime;
|
||||
import com.volmit.object.GeneratedObject;
|
||||
import com.volmit.object.ObjectBlock;
|
||||
import com.volmit.placement.PlacedBlock;
|
||||
@@ -29,14 +33,16 @@ import com.volmit.example.placement.SnowSettings;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class StageGraphTest {
|
||||
private static final BlockState STONE = new BlockState("minecraft:stone");
|
||||
|
||||
@Feature(id = "test:owner/toggle", name = "Toggle", field = "toggle", targets = FeatureAttachment.Target.OBJECT_PLACEMENT)
|
||||
@Feature(id = "test:owner/toggle", name = "Toggle", alias = "toggle", targets = FeatureAttachment.Target.OBJECT_PLACEMENT)
|
||||
static final class Toggle implements IrisFeature {}
|
||||
|
||||
static final class Unannotated implements IrisFeature {}
|
||||
@@ -452,4 +458,77 @@ class StageGraphTest {
|
||||
static final class Counter {
|
||||
int count;
|
||||
}
|
||||
|
||||
@Test
|
||||
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 paint = Stage.placementBlock("test:reach/paint");
|
||||
var reach = module("test:reach", stages -> {
|
||||
stages.define(carve).reach(24).writesMantle(depth).run(context -> {});
|
||||
stages.define(mark).reach(8).writesMantle(depth, marks).run(context -> {});
|
||||
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());
|
||||
|
||||
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 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"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void reachMustBeValidAndNameRegisteredLayers() {
|
||||
var depth = new MantleKey<>("test:reach/depth", Integer.class);
|
||||
var carve = Stage.chunk("test:reach/carve");
|
||||
|
||||
var negative = assertThrows(IllegalArgumentException.class, () -> resolve(Pipeline.CHUNK,
|
||||
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,
|
||||
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,
|
||||
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()));
|
||||
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()));
|
||||
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());
|
||||
}
|
||||
|
||||
/** {@code module}, also registering {@code layers}. */
|
||||
private static IrisModule withMantle(IrisModule module, MantleKey<?>... layers) {
|
||||
return new IrisModule() {
|
||||
public ModuleInfo info() { return module.info(); }
|
||||
public void install(StageGraph graph) { module.install(graph); }
|
||||
public void register(FeatureRegistry registry) {
|
||||
for (var layer : layers) registerLayer(registry, layer);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static <T> void registerLayer(FeatureRegistry registry, MantleKey<T> layer) {
|
||||
registry.registerMantle(layer, MantleLifetime.GENERATION, codec(layer));
|
||||
}
|
||||
|
||||
private static <T> MantleCodec<T> codec(MantleKey<T> layer) {
|
||||
return new MantleCodec<>() {
|
||||
public int version() { return 0; }
|
||||
public void write(java.io.DataOutput output, T value) {}
|
||||
public T read(java.io.DataInput input, int storedVersion) { throw new UnsupportedOperationException(); }
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user