Baseline IrisApi draft before stage-graph redesign

This commit is contained in:
piexel committed 2026-10-05 17:01:18 +02:00
commit 9043d93fbd
91 files changed
+4045

No files matched your search

+10
View File
@@ -0,0 +1,10 @@
package com.volmit.config;
import java.lang.annotation.*;
/** Human-readable documentation for a settings type or field. */
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.FIELD})
public @interface Desc {
String value();
}
@@ -0,0 +1,13 @@
package com.volmit.config;
import java.lang.annotation.*;
/** Identity and JSON attachment for an IrisFeature configuration class. */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Feature {
String id();
String name();
String field();
com.volmit.FeatureAttachment.Target[] targets();
}
@@ -0,0 +1,26 @@
package com.volmit.config;
import com.volmit.FeatureAttachment;
import com.volmit.IrisFeature;
import com.volmit.resource.ResourceId;
import java.util.List;
/** 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.
*/
public interface FeatureSettings {
<F extends IrisFeature> List<Entry<F>> at(Class<F> featureType, FeatureAttachment.Target target,
int worldX, int worldY, 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) {
public Entry {
java.util.Objects.requireNonNull(source, "source");
java.util.Objects.requireNonNull(occurrence, "occurrence");
java.util.Objects.requireNonNull(value, "value");
}
}
}
@@ -0,0 +1,10 @@
package com.volmit.config;
import java.lang.annotation.*;
/** Inclusive numeric upper bound. Enforcement belongs to the configuration loader. */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface MaxNumber {
double value();
}
@@ -0,0 +1,10 @@
package com.volmit.config;
import java.lang.annotation.*;
/** Inclusive numeric lower bound. Enforcement belongs to the configuration loader. */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface MinNumber {
double value();
}
@@ -0,0 +1,60 @@
package com.volmit.config;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
/** Annotation metadata, independent of JSON libraries. Does not decode or validate values. */
public record OptionsMetadata(String description, String snippet, List<Option> options) {
public OptionsMetadata {
options = List.copyOf(options);
}
public record Option(String name, Type type, String description,
boolean required, Double minimum, Double maximum) {}
/** Reads private and inherited fields without constructing settings or accessing values.
* Nested object types are preserved for the schema builder to inspect recursively.
*/
public static OptionsMetadata inspect(Class<?> type) {
var options = new ArrayList<Option>();
var names = new HashSet<String>();
for (Class<?> current = type; current != null && current != Object.class;
current = current.getSuperclass()) {
for (var field : current.getDeclaredFields()) {
int modifiers = field.getModifiers();
if (field.isSynthetic() || Modifier.isStatic(modifiers) || Modifier.isTransient(modifiers)) {
continue;
}
if (!names.add(field.getName())) {
throw new IllegalArgumentException("Duplicate option: " + field.getName());
}
var desc = field.getAnnotation(Desc.class);
var min = field.getAnnotation(MinNumber.class);
var max = field.getAnnotation(MaxNumber.class);
if ((min != null || max != null) && !isNumeric(field.getType())) {
throw new IllegalArgumentException("Numeric bounds on nonnumeric option: " + field.getName());
}
if ((min != null && !Double.isFinite(min.value()))
|| (max != null && !Double.isFinite(max.value()))
|| (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()));
}
}
var desc = type.getAnnotation(Desc.class);
var snippet = type.getAnnotation(Snippet.class);
return new OptionsMetadata(desc == null ? "" : desc.value(),
snippet == null ? "" : snippet.value(), options);
}
private static boolean isNumeric(Class<?> type) {
return Number.class.isAssignableFrom(type) || type == byte.class || type == short.class
|| type == int.class || type == long.class || type == float.class || type == double.class;
}
}
@@ -0,0 +1,8 @@
package com.volmit.config;
import java.lang.annotation.*;
/** Declares that a field must be supplied in configuration. */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Required {}
@@ -0,0 +1,10 @@
package com.volmit.config;
import java.lang.annotation.*;
/** Identifies a reusable settings snippet. */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Snippet {
String value();
}