Merge branch 'wave3b/6'

This commit is contained in:
piexel committed 2026-10-15 07:06:52 +02:00
commit 1ea5d70eaa
10 files changed
+61 -11

No files matched your search

+1 -1
View File
@@ -29,7 +29,7 @@ types that carry them and lists what the Iris adapter still owes.
| Noise from pack-described styles | `NoiseStyle`, `StyledRange`, `PackResources.noise()`, `NoiseFactory`, `NoiseSampler` |
| Values in settings | `BlockSpec`, `PaletteSpec`, `NoiseStyle`, `StyledRange`, `Range`, `BlockPosition`, `JigsawOverrides`, `Object` as `ValueKind.AnyKind` |
| Decisions over and fit of the platform's own structures | service `VanillaStructures` (`rule`, `starts`, `shift`, `reach`, `beforePieces`, `afterPieces`, `setup`), `VanillaStructureRule`, `VanillaStructureContext`, `VanillaStructureStart`, `VanillaStructureStartContext`, `VanillaStructureSetup`, `PlatformStart`, `StartMemo`, `StartReach`, `StructureFit` (`Start`, `Piece`, `ColumnVisitor`), `StructureStep`, `TerrainAdaptation`, `PieceKind`, `TemplateCells`, `world.BlockAccess`, host `FeatureCatalog.registrations(service)` |
| Pack-scoped resolution | `ResourceId`, `ResourceKey<T>`, `PackResources` (`find`, `ids`), `PackBiome`, `PackRegion` |
| Pack-scoped resolution | `ResourceId` (`ofPackKey`), `ResourceKey<T>`, `PackResources` (`find`, `ids`, `idOf`), `PackBiome`, `PackRegion` |
| Module-owned pack resources | `ResourceKind`, `FeatureRegistry.registerResourceKind`, `@ResourceRef`, host `ModuleHost.reservingFolders`, `FeatureCatalog.resourceKinds()`, `ResourceKindSchema`, `ValueKind.ResourceReferenceKind` |
| Module-owned pack checks | `Validator`, `ValidationContext`, `Problem`, `Severity`, `Subject`, `FeatureRegistry.registerValidator`, host `FeatureCatalog.validators()` |
| Per-world module state | `PackWorld` (`state`), `InvocationContext.world()`, host `WorldStates` |
+4 -2
View File
@@ -650,9 +650,11 @@ core engine is modules as well. The host's own JSON fields are not in it; no key
inlined copy, so a class used in many places is described once, and a class that contains itself,
directly or through others, ends the walk at its own name. Two different classes with one name fail
the load; only a built-in class and a pack class can collide that way.
- Built-in modules may also register a class that Iris's own classes hold (`registerHeldType`, `FeatureCatalog.heldTypes()`):
- Modules may also register a class that Iris's own classes hold (`registerHeldType`, `FeatureCatalog.heldTypes()`):
it is described like any settings class reachable from a feature, but no `FeatureSchema` names it. This is for
settings that live in a host class until their feature owns them, such as the clamp of an object placement.
settings that live in a host class until their feature owns them, such as the clamp of an object placement. The class
must be loaded by the host: a built-in module's, or one of a package the host exposes (the built-ins jar's modules
register the classes of `art.arcane.iris.builtin`); a class from the registering pack module's own jar fails the load.
- A `SchemaOption` per field that `OptionsMetadata` selects, which means instance fields that are
not transient, inherited ones included, in declaration order. Each has its name, `ValueKind`,
`@Desc`, `@Required`, `@MinNumber`/`@MaxNumber`, `@MinItems` and the default value.
+4 -2
View File
@@ -178,7 +178,9 @@ List<ResourceId> all = resources.ids(Keep.class); // every keep of the pack, in
```
- A file's key is its path below the folder without `.json` (`towers/north`), and its id is
`<pack namespace>:<key>`, like every pack resource. JSON keys inside the file are the class's field names.
`<pack namespace>:<key>`, like every pack resource (`resources.idOf("towers/north")` makes it, in lower case with
characters outside `[a-z0-9_./-]` replaced by `_`: `ResourceId.ofPackKey`). JSON keys inside the file are the class's
field names.
- The kind's id follows the module id. The folder is one folder name directly below the pack root; the module
chooses it, so a kind that replaces one of Iris's own keeps the folder and file format packs already have.
- One folder holds one kind and one class backs one kind: `PackResources` finds resources by type. Two kinds
@@ -453,7 +455,7 @@ public final class FloraSettings implements IrisFeature {
- `@Ref(Reference.X)` says what a `String` or `ResourceId` names, also on lists, sets and arrays of
them, so studio offers the right list: `BLOCK`, `ITEM`, `ENTITY`, `BIOME`, `STRUCTURE`, `STRUCTURE_PREFIX`
(a structure or a family prefix such as `minecraft:village`), `STRUCTURE_SET`, `TEMPLATE_POOL` (a jigsaw template pool),
`POTION_EFFECT`, `ENCHANTMENT` or `SPECIAL_ENTITY` (a mob of another plugin) from the server's registries, `NOISE_STYLE` from the host's noise
`POTION_EFFECT`, `ENCHANTMENT`, `LOOT_TABLE` or `SPECIAL_ENTITY` (a mob of another plugin) from the server's registries, `NOISE_STYLE` from the host's noise
styles, or `PACK_BIOME`, `PACK_REGION`, `PACK_OBJECT`, `PACK_EXPRESSION` or `PACK_IMAGE_MAP` of the pack.
The pack kinds fit `String` only, in the form packs use (`desert/dunes`), never `ResourceId`. `BlockState` fields name blocks without it. `@Ref` on any other field fails
the load.
@@ -40,8 +40,9 @@ public interface FeatureRegistry {
void registerSettings(Class<? extends IrisFeature> settingsType);
/** Describes a class that Iris's own classes hold, such as the clamp of an object placement, so studio shows
* its fields as this class declares them. Only built-in modules may register one: the host classes that hold
* the class are Iris's, so a pack module's class could never be a field of one. The host reads the class
* its fields as this class declares them. The class must be one the host loads: a built-in module's class, or a
* class of a package the host exposes to pack modules (a pack module's own classes could never be a field of
* one of the host's classes, so registering one fails the load). The host reads the class
* with its fields in pack JSON, and the class follows the rules of settings classes. Registering a class twice
* changes nothing.
*/
@@ -27,6 +27,8 @@ public enum Reference {
POTION_EFFECT,
/** An enchantment, such as {@code minecraft:sharpness}. */
ENCHANTMENT,
/** A loot table of the platform, such as {@code minecraft:chests/simple_dungeon}; not a loot table of the pack. */
LOOT_TABLE,
/** A mob of another plugin or content provider, such as {@code mythicmobs:skeleton_king}. */
SPECIAL_ENTITY,
/** A biome of the pack. */
@@ -129,9 +129,9 @@ public final class ModuleRegistry implements FeatureRegistry {
checkOpen();
Objects.requireNonNull(type, "type");
requireRegistering("Held type " + type.getName());
if (registering.source() != DiscoveredModule.Source.HOST) {
throw new IllegalArgumentException("Held type " + type.getName() + " of module " + registering + " is registered by a"
+ " pack module; only built-in modules may describe a class that Iris's own classes hold");
if (registering.source() != DiscoveredModule.Source.HOST && type.getClassLoader() == registering.module().getClass().getClassLoader()) {
throw new IllegalArgumentException("Held type " + type.getName() + " of module " + registering + " is a class of the pack module's"
+ " own jar; only a class the host loads, such as one of an exposed package, can be held by Iris's own classes");
}
heldTypes.putIfAbsent(type, new HeldTypeRegistration(type, registering));
}
@@ -35,6 +35,15 @@ public interface PackResources {
*/
List<ResourceId> ids(Class<?> type);
/** The id of the resource the pack's files name by {@code key} (the file path inside the kind's folder, without
* {@code .json}), such as {@code overworld:dungeon/chest} for {@code dungeon/chest}; see
* {@link ResourceId#ofPackKey}. Settings that name a resource, such as a {@link com.volmit.config.ResourceRef},
* hold such a key.
*/
default ResourceId idOf(String key) {
return ResourceId.ofPackKey(packId().namespace(), key);
}
default <T> T require(ResourceKey<T> key) {
return find(key).orElseThrow(() -> new NoSuchElementException("Missing resource: " + key.id()));
}
@@ -1,5 +1,6 @@
package com.volmit.resource;
import java.util.Locale;
import java.util.Objects;
import java.util.regex.Pattern;
@@ -7,6 +8,8 @@ import java.util.regex.Pattern;
public record ResourceId(String namespace, String path) implements Comparable<ResourceId> {
private static final Pattern NAMESPACE = Pattern.compile("[a-z0-9_.-]+");
private static final Pattern PATH = Pattern.compile("[a-z0-9_./-]+");
private static final Pattern NOT_PATH = Pattern.compile("[^a-z0-9_./-]");
private static final String PATH_REPLACEMENT = "_";
public ResourceId {
Objects.requireNonNull(namespace, "namespace");
@@ -28,6 +31,17 @@ public record ResourceId(String namespace, String path) implements Comparable<Re
return new ResourceId(value.substring(0, separator), value.substring(separator + 1));
}
/**
* The id a pack gives the resource its files name by {@code key}, such as {@code dungeon/chest} for
* {@code loot/dungeon/chest.json}: the pack's namespace and the key as the path, lower-cased, with every
* character outside {@code [a-z0-9_./-]} replaced by {@code _}. Keys that differ only in such characters share
* an id.
*/
public static ResourceId ofPackKey(String namespace, String key) {
Objects.requireNonNull(key, "key");
return new ResourceId(namespace, NOT_PATH.matcher(key.toLowerCase(Locale.ROOT)).replaceAll(PATH_REPLACEMENT));
}
@Override
public String toString() { return namespace + ":" + path; }
@@ -19,6 +19,13 @@ import java.util.OptionalInt;
import static org.junit.jupiter.api.Assertions.*;
class ApiValuesTest {
@Test
void aPackKeyBecomesTheIdOfItsResource() {
assertEquals(ResourceId.parse("overworld:dungeon/chest"), ResourceId.ofPackKey("overworld", "dungeon/chest"));
assertEquals(ResourceId.parse("overworld:dungeon/chest_1"), ResourceId.ofPackKey("overworld", "Dungeon/Chest 1"));
assertEquals(ResourceId.parse("test:a/b"), new com.volmit.support.EmptyResources().idOf("a/b"));
}
@Test
void idsAndStateKeysAreExplicitCanonicalImmutableValues() {
for (String invalid : List.of("stone", "Minecraft:stone", "a:b:c", "a:", ":a")) {
@@ -387,10 +387,23 @@ class PackSchemaTest {
jar.writeInto(pack, "flora.jar");
var failure = assertThrows(IllegalArgumentException.class, () -> LoadedPack.load(pack, NO_BUILT_INS));
assertTrue(failure.getMessage().contains("Held type pack.flora.Clamp") && failure.getMessage().contains("only built-in modules"),
assertTrue(failure.getMessage().contains("Held type pack.flora.Clamp") && failure.getMessage().contains("own jar"),
failure.getMessage());
}
@Test
void packModulesMayDescribeAHostClassOfAnExposedPackage() {
var jar = module("pack.flora.FloraModule", FLORA,
"public void register(com.volmit.FeatureRegistry registry) { registry.registerHeldType(com.volmit.example.held.ClampSettings.class); }", NO_STAGES)
.compileAgainstHostOf(ClampSettings.class);
var pack = pack("held-exposed");
jar.writeInto(pack, "flora.jar");
var schema = LoadedPack.load(pack, NO_BUILT_INS.exposing("com.volmit.example.held")).schema();
assertEquals("Limits a placement by height", schema.type(ClampSettings.class.getName()).description());
}
@Test
void packModulesCannotUseHostTypes() {
var host = NO_BUILT_INS.exposing(HOST_TYPES).describingHostTypesIn(HOST_TYPES);