mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 08:14:45 +00:00
Remove feature aliases, the one-option shorthand and reserved host fields
A setting has one JSON key, its feature id, and one shape, its settings object. Aliases were the only reason for reserved host fields (ids contain ':', host fields never do), so ModuleHost.reservingFields goes too.
This commit is contained in:
1 parent
99a914633d
commit
f6c078aade
26 files changed
+112
-305
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", alias = "fill", targets = FeatureAttachment.Target.BIOME)
|
||||
@Feature(id = "example:fill", name = "Fill", targets = FeatureAttachment.Target.BIOME)
|
||||
public static class FillOptions implements IrisFeature {
|
||||
@Desc("Replacement value")
|
||||
@MinNumber(0)
|
||||
@@ -40,7 +40,6 @@ class FeatureContractTest {
|
||||
var descriptor = FeatureDescriptor.of(FillOptions.class);
|
||||
assertEquals(ResourceId.parse("example:fill"), descriptor.id());
|
||||
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());
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ class ChunkPipelineTest {
|
||||
|
||||
@Test
|
||||
void mantleStagesWriteBeyondTheirChunkAndChunkStagesReadTheirOwnPart() {
|
||||
var loaded = LoadedModules.load(List.of(DiscoveredModule.builtIn(new VeinModule())), Map.of(), Set.of(), Set.of());
|
||||
var loaded = LoadedModules.load(List.of(DiscoveredModule.builtIn(new VeinModule())), Set.of(), Set.of());
|
||||
var vein = new Entry<>(Target.BIOME, PLAINS, new VeinSettings(12, 4));
|
||||
int reach = loaded.mantle().stages().getFirst().reachBlocks(new DeclaredSettings(vein));
|
||||
assertEquals(3, reach, "a 12 block vein from the centre column runs 3 blocks into the next chunk");
|
||||
|
||||
@@ -202,7 +202,7 @@ class PlacementLifecyclePortTest {
|
||||
|
||||
@Test
|
||||
void loadingThePortCatalogsEveryConditioningSettingsType() {
|
||||
var loaded = LoadedModules.load(PlacementModules.builtIns(), Map.of(), Set.of(), Set.of());
|
||||
var loaded = LoadedModules.load(PlacementModules.builtIns(), Set.of(), Set.of());
|
||||
|
||||
assertEquals(List.of("example:moss", "iris:snow", "iris:stilt"),
|
||||
loaded.catalog().settings().stream().map(settings -> settings.id().toString()).toList());
|
||||
|
||||
@@ -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", alias = "snow", targets = FeatureAttachment.Target.OBJECT_PLACEMENT)
|
||||
@Feature(id = "iris:snow", name = "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", alias = "stilt", targets = FeatureAttachment.Target.OBJECT_PLACEMENT)
|
||||
@Feature(id = "iris:stilt", name = "Stilt", targets = FeatureAttachment.Target.OBJECT_PLACEMENT)
|
||||
public final class StiltSettings implements IrisFeature {
|
||||
@Desc("Maximum blocks filled below each lowest object block")
|
||||
@MinNumber(1)
|
||||
|
||||
@@ -8,7 +8,7 @@ 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)
|
||||
@Feature(id = "iris:layers", name = "Layers", targets = FeatureAttachment.Target.BIOME)
|
||||
public final class LayersSettings implements IrisFeature {
|
||||
@Desc("Rock layers from the surface down")
|
||||
private List<Palette> layers = List.of();
|
||||
|
||||
@@ -76,7 +76,7 @@ class WorldStateExampleTest {
|
||||
|
||||
@Test
|
||||
void stagesServicesAndHooksShareTheStateOfTheirWorldAndANewWorldStartsEmpty() {
|
||||
var pack = LoadedModules.load(List.of(DiscoveredModule.builtIn(new RuinsModule())), Map.of(), Set.of(), Set.of());
|
||||
var pack = LoadedModules.load(List.of(DiscoveredModule.builtIn(new RuinsModule())), Set.of(), Set.of());
|
||||
var lifecycles = new LifecycleRunner(pack.catalog());
|
||||
ObjectsAt objects = pack.catalog().services(ObjectsAt.class).getFirst();
|
||||
|
||||
|
||||
@@ -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(), Set.of());
|
||||
var loaded = LoadedModules.load(List.of(discovered), Set.of(), Set.of());
|
||||
|
||||
assertEquals("first:core", discovered.info().id().toString());
|
||||
assertEquals(List.of("first:core/mark"),
|
||||
|
||||
@@ -43,7 +43,7 @@ class LifecycleRunnerTest {
|
||||
|
||||
private static LifecycleRunner runner(IrisModule... modules) {
|
||||
var discovered = Arrays.stream(modules).map(DiscoveredModule::builtIn).toList();
|
||||
return new LifecycleRunner(LoadedModules.load(discovered, Map.of(), Set.of(), Set.of()).catalog());
|
||||
return new LifecycleRunner(LoadedModules.load(discovered, Set.of(), Set.of()).catalog());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -84,7 +84,6 @@ class LoadedPackTest {
|
||||
void invalidHostConfigurationFailsWhenBuilt() {
|
||||
var host = ModuleHost.of(List.of());
|
||||
assertThrows(IllegalArgumentException.class, () -> host.exposing("org.*"));
|
||||
assertThrows(IllegalArgumentException.class, () -> host.reservingFields(Map.of(Target.BIOME, Set.of(" "))));
|
||||
assertEquals(List.of(), host.builtIns());
|
||||
assertEquals(Set.of(), host.exposedHostPackages());
|
||||
}
|
||||
@@ -94,11 +93,11 @@ class LoadedPackTest {
|
||||
var host = ModuleHost.of(List.of())
|
||||
.exposing("example.first")
|
||||
.exposing("example.second")
|
||||
.reservingFields(Map.of(Target.BIOME, Set.of("carving"), Target.REGION, Set.of("spawns")))
|
||||
.reservingFields(Map.of(Target.BIOME, Set.of("objects")));
|
||||
.reservingFolders("biomes")
|
||||
.reservingFolders("regions");
|
||||
|
||||
assertEquals(Set.of("example.first", "example.second"), host.exposedHostPackages());
|
||||
assertEquals(Map.of(Target.BIOME, Set.of("carving", "objects"), Target.REGION, Set.of("spawns")), host.reservedHostFields());
|
||||
assertEquals(Set.of("biomes", "regions"), host.reservedFolders());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -23,16 +23,14 @@ import java.util.function.Consumer;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class ModuleRegistryTest {
|
||||
@Feature(id = "test:core/one", name = "One", alias = "shared", targets = FeatureAttachment.Target.BIOME)
|
||||
@Feature(id = "test:core/one", name = "One", targets = FeatureAttachment.Target.BIOME)
|
||||
static class One implements IrisFeature {}
|
||||
@Feature(id = "test:core/two", name = "Two", alias = "shared", targets = FeatureAttachment.Target.DIMENSION)
|
||||
@Feature(id = "test:core/two", name = "Two", targets = FeatureAttachment.Target.DIMENSION)
|
||||
static class Two implements IrisFeature {}
|
||||
@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", alias = "different", targets = FeatureAttachment.Target.REGION)
|
||||
@Feature(id = "test:core/one", name = "Duplicate", targets = FeatureAttachment.Target.REGION)
|
||||
static class Duplicate implements IrisFeature {}
|
||||
static class MissingAnnotation implements IrisFeature {}
|
||||
@Feature(id = "test:core/abstract", name = "Abstract", alias = "abstract", targets = FeatureAttachment.Target.BIOME)
|
||||
@Feature(id = "test:core/abstract", name = "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. */
|
||||
@@ -50,7 +48,6 @@ class ModuleRegistryTest {
|
||||
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));
|
||||
objects.registerObject(Two.class, ignored -> context -> null);
|
||||
assertThrows(IllegalArgumentException.class, () -> objects.registerObject(Duplicate.class, ignored -> context -> null));
|
||||
assertThrows(IllegalArgumentException.class, () -> objects.registerObject(One.class, ignored -> context -> null));
|
||||
@@ -61,12 +58,8 @@ class ModuleRegistryTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void reservesHostFieldsAndRejectsInvalidFeaturesOrFactories() {
|
||||
var registry = new ModuleRegistry(Map.of(FeatureAttachment.Target.BIOME, Set.of("shared")));
|
||||
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());
|
||||
void rejectsInvalidFeaturesOrFactories() {
|
||||
var registry = new ModuleRegistry();
|
||||
assertThrows(IllegalArgumentException.class, () -> registry.registerStageSettings(MissingAnnotation.class));
|
||||
assertThrows(IllegalArgumentException.class, () -> registry.registerStageSettings(AbstractFeature.class));
|
||||
registerAs(registry, "test:core", objects -> {
|
||||
@@ -135,14 +128,31 @@ 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(), Set.of());
|
||||
var loaded = LoadedModules.load(List.of(DiscoveredModule.builtIn(conditioned)), 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(), Set.of()));
|
||||
@Test
|
||||
void twoModulesWithOneIdRefuseTheLoadNamingBothSoASettingsKeyIsNeverShared() {
|
||||
var first = ownerOfOne("First");
|
||||
var second = ownerOfOne("Second");
|
||||
|
||||
var clash = assertThrows(IllegalArgumentException.class,
|
||||
() -> LoadedModules.load(List.of(DiscoveredModule.builtIn(first), DiscoveredModule.builtIn(second)), Set.of(), Set.of()));
|
||||
|
||||
assertTrue(clash.getMessage().startsWith("Duplicate module test:core from "), clash.getMessage());
|
||||
assertTrue(clash.getMessage().contains("already loaded from "), clash.getMessage());
|
||||
}
|
||||
|
||||
private static IrisModule ownerOfOne(String name) {
|
||||
return new IrisModule() {
|
||||
public ModuleInfo info() { return ModuleInfo.of("test:core", name, "1"); }
|
||||
public void install(StageGraph graph) {}
|
||||
public void register(FeatureRegistry registry) { registry.registerSettings(One.class); }
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -169,8 +179,8 @@ 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("Alias collision"), collision.getMessage());
|
||||
() -> registerAs(registry, "test:core", settings -> settings.registerSettings(Two.class)));
|
||||
assertEquals("Duplicate feature: test:core/two", collision.getMessage());
|
||||
assertTrue(registry.freeze().settings().isEmpty());
|
||||
}
|
||||
|
||||
@@ -187,11 +197,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(), Set.of());
|
||||
var loaded = LoadedModules.load(List.of(DiscoveredModule.builtIn(owner), DiscoveredModule.builtIn(user)), 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(), Set.of()));
|
||||
() -> LoadedModules.load(List.of(DiscoveredModule.builtIn(user)), Set.of(), Set.of()));
|
||||
assertTrue(unowned.getMessage().contains("which none of the modules naming it in when(...) owns"), unowned.getMessage());
|
||||
}
|
||||
|
||||
@@ -200,7 +210,7 @@ class ModuleRegistryTest {
|
||||
|
||||
@Test
|
||||
void resourceKindsHaveOwnedIdsAndOneIdTypeAndFolderEach() {
|
||||
var registry = new ModuleRegistry(Map.of(), Set.of("biomes"));
|
||||
var registry = new ModuleRegistry(Set.of("biomes"));
|
||||
var castles = ResourceKind.of("test:core/castle", "castles", Castle.class);
|
||||
registerAs(registry, "test:core", kinds -> {
|
||||
kinds.registerResourceKind(castles);
|
||||
|
||||
@@ -43,7 +43,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(), Set.of());
|
||||
return LoadedModules.load(modules, Set.of(), Set.of());
|
||||
}
|
||||
|
||||
/** Versioned entries of a multi-release jar are read like any class, so they must be real class files. */
|
||||
@@ -154,7 +154,7 @@ class PackModulesTest {
|
||||
packModules.modules().stream().map(found -> found.info().id().toString()).toList());
|
||||
assertEquals(List.of(origin("two.jar"), origin("two.jar")),
|
||||
packModules.modules().stream().map(DiscoveredModule::origin).toList());
|
||||
assertDoesNotThrow(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of()));
|
||||
assertDoesNotThrow(() -> LoadedModules.load(packModules.modules(), Set.of(), Set.of()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -378,7 +378,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(), Set.of()));
|
||||
assertDoesNotThrow(() -> LoadedModules.load(packModules.modules(), Set.of(), Set.of()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -512,7 +512,7 @@ class PackModulesTest {
|
||||
.writeInto(pack, "beta.jar");
|
||||
|
||||
try (var packModules = PackModules.load(pack)) {
|
||||
var loaded = LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of());
|
||||
var loaded = LoadedModules.load(packModules.modules(), 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,
|
||||
@@ -529,7 +529,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(), Set.of()).placement().stages().stream()
|
||||
var order = LoadedModules.load(modules, Set.of(), Set.of()).placement().stages().stream()
|
||||
.map(stage -> stage.stage().id().toString()).toList();
|
||||
assertEquals(List.of("iris:carve/clear", "user:core/carved"), order);
|
||||
}
|
||||
@@ -607,7 +607,7 @@ class PackModulesTest {
|
||||
.writeInto(pack, "once.jar");
|
||||
|
||||
try (var packModules = PackModules.load(pack)) {
|
||||
var loaded = assertDoesNotThrow(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of()));
|
||||
var loaded = assertDoesNotThrow(() -> LoadedModules.load(packModules.modules(), Set.of(), Set.of()));
|
||||
assertEquals("once:core", packModules.modules().getFirst().info().id().toString());
|
||||
assertEquals(1, loaded.placement().stages().size());
|
||||
}
|
||||
@@ -626,7 +626,7 @@ class PackModulesTest {
|
||||
.writeInto(pack, "beta.jar");
|
||||
|
||||
try (var packModules = PackModules.load(pack)) {
|
||||
assertMentions(failure(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of())),
|
||||
assertMentions(failure(() -> LoadedModules.load(packModules.modules(), 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()");
|
||||
}
|
||||
@@ -638,7 +638,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(), Set.of())),
|
||||
assertMentions(failure(() -> LoadedModules.load(packModules.modules(), Set.of(), Set.of())),
|
||||
"Duplicate module dup:core from " + origin("two.jar") + " (pack.two.Duplicate); already loaded from "
|
||||
+ origin("one.jar") + " (pack.one.Duplicate)");
|
||||
}
|
||||
@@ -662,7 +662,7 @@ class PackModulesTest {
|
||||
.writeInto(pack, "foreign.jar");
|
||||
|
||||
try (var packModules = PackModules.load(pack)) {
|
||||
assertMentions(failure(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of())),
|
||||
assertMentions(failure(() -> LoadedModules.load(packModules.modules(), 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"));
|
||||
}
|
||||
}
|
||||
@@ -674,7 +674,7 @@ class PackModulesTest {
|
||||
.writeInto(pack, "both.jar");
|
||||
|
||||
try (var packModules = PackModules.load(pack)) {
|
||||
assertMentions(failure(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of())),
|
||||
assertMentions(failure(() -> LoadedModules.load(packModules.modules(), Set.of(), Set.of())),
|
||||
"Duplicate module dup:core from " + origin("both.jar") + " (pack.Two); already loaded from "
|
||||
+ origin("both.jar") + " (pack.One)");
|
||||
}
|
||||
@@ -687,7 +687,7 @@ class PackModulesTest {
|
||||
.writeInto(pack, "stilt.jar");
|
||||
|
||||
try (var packModules = PackModules.load(pack)) {
|
||||
assertDoesNotThrow(() -> LoadedModules.load(packModules.modules(), Map.of(), Set.of(), Set.of()));
|
||||
assertDoesNotThrow(() -> LoadedModules.load(packModules.modules(), Set.of(), Set.of()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -206,7 +206,6 @@ class PackSchemaTest {
|
||||
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();
|
||||
@@ -333,8 +332,6 @@ class PackSchemaTest {
|
||||
|
||||
assertEquals(List.of("example:grass", "example:moss", "iris:snow", "iris:stilt"), names(schema.features(), FeatureSchema::id));
|
||||
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());
|
||||
@@ -358,7 +355,6 @@ class PackSchemaTest {
|
||||
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"),
|
||||
@@ -375,12 +371,6 @@ class PackSchemaTest {
|
||||
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);
|
||||
@@ -599,26 +589,6 @@ class PackSchemaTest {
|
||||
.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"
|
||||
|
||||
@@ -45,7 +45,7 @@ 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", alias = "toggle", targets = FeatureAttachment.Target.OBJECT_PLACEMENT)
|
||||
@Feature(id = "test:owner/toggle", name = "Toggle", targets = FeatureAttachment.Target.OBJECT_PLACEMENT)
|
||||
static final class Toggle implements IrisFeature {}
|
||||
|
||||
static final class Unannotated implements IrisFeature {}
|
||||
@@ -478,7 +478,7 @@ 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(), Set.of());
|
||||
var loaded = LoadedModules.load(List.of(DiscoveredModule.builtIn(withMantle(reach, depth, marks))), Set.of(), Set.of());
|
||||
|
||||
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");
|
||||
@@ -496,7 +496,7 @@ class StageGraphTest {
|
||||
var loaded = LoadedModules.load(List.of(DiscoveredModule.builtIn(module("test:reach", stages -> {
|
||||
stages.define(carve).reach(settings -> settings.declared(Toggle.class).isEmpty() ? 4 : 40).run(context -> {});
|
||||
stages.define(mark).reach(2).run(context -> {});
|
||||
}))), Map.of(), Set.of(), Set.of());
|
||||
}))), Set.of(), Set.of());
|
||||
var computed = loaded.mantle().stages().getFirst();
|
||||
var toggled = new DeclaredSettings(new Entry<>(FeatureAttachment.Target.DIMENSION, ResourceId.parse("pack:dimension/main"), new Toggle()));
|
||||
|
||||
@@ -512,7 +512,7 @@ class StageGraphTest {
|
||||
@Test
|
||||
void onlyMantleStagesWorkOutTheirReachAndNeverANegativeOne() {
|
||||
var negative = LoadedModules.load(List.of(DiscoveredModule.builtIn(module("test:reach", stages ->
|
||||
stages.define(Stage.mantle("test:reach/carve")).reach(settings -> -1).run(context -> {})))), Map.of(), Set.of(), Set.of());
|
||||
stages.define(Stage.mantle("test:reach/carve")).reach(settings -> -1).run(context -> {})))), Set.of(), Set.of());
|
||||
var failure = assertThrows(IllegalStateException.class, () -> negative.mantle().stages().getFirst().reachBlocks(DeclaredSettings.NONE));
|
||||
assertEquals("Stage test:reach/carve of module test:reach worked out a negative reach of -1 blocks for this pack", failure.getMessage());
|
||||
|
||||
@@ -567,13 +567,13 @@ class StageGraphTest {
|
||||
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(), Set.of()));
|
||||
module("test:reach", stages -> stages.define(carve).writesMantle(depth).run(context -> {})))), 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(), Set.of()));
|
||||
module("test:reach", stages -> stages.define(carve).writesMantle(asText).run(context -> {})), depth))), 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());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user