Add FeatureRegistry.registerSettings and the @Ref annotation for value references

Modules register settings types that no stage names in when(...) explicitly; the
id must be the module's id or below it, and repeating it or also naming the type
in when(...) changes nothing. A type its owner registered may be named by any
module. OptionsMetadata.Option now carries its field and @Ref reference.
This commit is contained in:
piexel committed 2026-10-06 12:06:46 +02:00
1 parent 8b7accd19d
commit 93c755ffe4
9 files changed
+164 -23

No files matched your search

@@ -1,5 +1,6 @@
package com.volmit.config;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.ArrayList;
@@ -12,8 +13,17 @@ public record OptionsMetadata(String description, String snippet, List<Option> o
options = List.copyOf(options);
}
public record Option(String name, Type type, String description,
boolean required, Double minimum, Double maximum) {}
/** One field of a settings type. {@code minimum}, {@code maximum} and {@code reference} are null when not declared. */
public record Option(Field field, String description, boolean required,
Double minimum, Double maximum, Reference reference) {
public String name() {
return field.getName();
}
public Type type() {
return field.getGenericType();
}
}
/** Reads private and inherited fields without constructing settings or accessing values.
* Nested object types are preserved for the schema builder to inspect recursively.
@@ -34,6 +44,7 @@ public record OptionsMetadata(String description, String snippet, List<Option> o
var desc = field.getAnnotation(Desc.class);
var min = field.getAnnotation(MinNumber.class);
var max = field.getAnnotation(MaxNumber.class);
var ref = field.getAnnotation(Ref.class);
if ((min != null || max != null) && !isNumeric(field.getType())) {
throw new IllegalArgumentException("Numeric bounds on nonnumeric option: " + field.getName());
}
@@ -42,9 +53,9 @@ public record OptionsMetadata(String description, String snippet, List<Option> o
|| (min != null && max != null && min.value() > max.value())) {
throw new IllegalArgumentException("Invalid bounds for option: " + field.getName());
}
options.add(new Option(field.getName(), field.getGenericType(),
desc == null ? "" : desc.value(), field.isAnnotationPresent(Required.class),
min == null ? null : min.value(), max == null ? null : max.value()));
options.add(new Option(field, desc == null ? "" : desc.value(), field.isAnnotationPresent(Required.class),
min == null ? null : min.value(), max == null ? null : max.value(),
ref == null ? null : ref.value()));
}
}
var desc = type.getAnnotation(Desc.class);
+13
View File
@@ -0,0 +1,13 @@
package com.volmit.config;
import java.lang.annotation.*;
/** Says what an option's text names, such as {@code @Ref(Reference.BLOCK) String block}. Allowed on
* {@code String} and {@link com.volmit.resource.ResourceId} options and on lists, sets and arrays of
* them, where it applies to every element. Anywhere else it fails the pack load.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Ref {
Reference value();
}
@@ -0,0 +1,29 @@
package com.volmit.config;
/** What a text option names, so studio can offer the matching completion list. Platform kinds name
* entries of the server's registries, such as {@code minecraft:stone}, including those that data
* packs and mods add. Pack kinds name resources of the pack being edited. The set is closed: every
* kind is one the Iris host can list.
*/
public enum Reference {
/** A block type, such as {@code minecraft:stone}. {@link com.volmit.block.BlockState} options are block references without {@link Ref}. */
BLOCK,
/** An item type, such as {@code minecraft:stick}. */
ITEM,
/** An entity type, such as {@code minecraft:zombie}. */
ENTITY,
/** A platform biome, such as {@code minecraft:plains}; not a biome of the pack. */
BIOME,
/** A platform structure, such as {@code minecraft:village_plains}. */
STRUCTURE,
/** A potion effect type, such as {@code minecraft:speed}. */
POTION_EFFECT,
/** An enchantment, such as {@code minecraft:sharpness}. */
ENCHANTMENT,
/** A biome of the pack. */
PACK_BIOME,
/** A region of the pack. */
PACK_REGION,
/** An object of the pack. */
PACK_OBJECT
}