Add value types for settings (BlockSpec, NoiseStyle, StyledRange, Range, BlockPosition, Object as any JSON), host-built noise through PackResources.noise(), and VanillaStructureHook for the platform's own structures

This commit is contained in:
piexel committed 2026-10-09 14:20:10 +02:00
1 parent ef4b640867
commit 84969c74bd
28 files changed
+1012 -39

No files matched your search

@@ -2,6 +2,7 @@ package com.volmit.host;
import com.volmit.block.BlockState;
import com.volmit.host.schema.ValueKind;
import com.volmit.host.schema.ValueKind.AnyKind;
import com.volmit.host.schema.ValueKind.BooleanKind;
import com.volmit.host.schema.ValueKind.DecimalKind;
import com.volmit.host.schema.ValueKind.EnumKind;
@@ -47,7 +48,7 @@ final class DefaultValues {
case ListKind list -> list(elements(value), list);
case MapKind map -> map((Map<?, ?>) value, map.value());
case ObjectKind object -> object(value, types.get(object.type()));
case HostKind _ -> Optional.empty();
case HostKind _, AnyKind _ -> Optional.empty();
};
}
@@ -8,7 +8,8 @@ import java.util.Map;
import java.util.NoSuchElementException;
import java.util.function.Function;
/** Frozen registrations. Lists use lexical feature/layer/kind ID order, and validators are in module id order,
/** Frozen registrations. Lists use lexical feature/layer/kind ID order, and validators and vanilla structure hooks
* are in module id order,
* so nothing depends on discovery. Factory, codec and validator implementations must themselves obey their
* concurrency contracts.
*/
@@ -18,13 +19,15 @@ public final class FeatureCatalog {
private final Map<String, MantleRegistration<?>> mantle;
private final List<ResourceKindRegistration> resourceKinds;
private final List<ValidatorRegistration> validators;
private final List<VanillaStructureHookRegistration> vanillaStructureHooks;
FeatureCatalog(
Map<Class<?>, FeatureDescriptor<?>> settings,
Map<Class<?>, ObjectRegistration<?>> objects,
Map<String, MantleRegistration<?>> mantle,
Collection<ResourceKindRegistration> resourceKinds,
List<ValidatorRegistration> validators) {
List<ValidatorRegistration> validators,
List<VanillaStructureHookRegistration> vanillaStructureHooks) {
this.settings = Map.copyOf(settings);
this.objects = Map.copyOf(objects);
this.mantle = Map.copyOf(mantle);
@@ -32,6 +35,9 @@ public final class FeatureCatalog {
this.validators = validators.stream()
.sorted(Comparator.comparing(registration -> registration.module().info().id()))
.toList();
this.vanillaStructureHooks = vanillaStructureHooks.stream()
.sorted(Comparator.comparing(registration -> registration.module().info().id()))
.toList();
}
/** Settings types that activate stages; the host decodes them from pack JSON. */
@@ -57,6 +63,11 @@ public final class FeatureCatalog {
return validators;
}
/** The vanilla structure hooks modules registered, by module id, each module's in the order it registered them. */
public List<VanillaStructureHookRegistration> vanillaStructureHooks() {
return vanillaStructureHooks;
}
private static <T, K extends Comparable<? super K>> List<T> sorted(
Collection<T> registrations,
Function<? super T, ? extends K> key) {
@@ -11,6 +11,7 @@ import com.volmit.object.ObjectGeneratorFactory;
import com.volmit.resource.ResourceId;
import com.volmit.resource.ResourceKind;
import com.volmit.validation.Validator;
import com.volmit.vanilla.VanillaStructureHook;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -40,6 +41,7 @@ public final class ModuleRegistry implements FeatureRegistry {
private final Map<Field, String> fields = new HashMap<>();
private final Map<ResourceId, ResourceKindRegistration> resourceKinds = new HashMap<>();
private final List<ValidatorRegistration> validators = new ArrayList<>();
private final List<VanillaStructureHookRegistration> vanillaStructureHooks = new ArrayList<>();
private final Set<String> reservedFolders;
private final List<DiscoveredModule> registered = new ArrayList<>();
private FeatureCatalog catalog;
@@ -129,6 +131,16 @@ public final class ModuleRegistry implements FeatureRegistry {
validators.add(new ValidatorRegistration(validator, registering));
}
@Override
public void registerVanillaStructureHook(VanillaStructureHook hook) {
checkOpen();
Objects.requireNonNull(hook, "hook");
if (registering == null) {
throw new IllegalStateException("Vanilla structure hook " + hook + " registered outside IrisModule.register");
}
vanillaStructureHooks.add(new VanillaStructureHookRegistration(hook, registering));
}
/** Catalogs a settings type named by a stage's when(...), whose owner {@link StageGraphBuilder}
* has checked. Several stages, and the owner's {@link #registerSettings}, may name one type. Call
* it after every module has registered, so the owner is known.
@@ -149,7 +161,7 @@ public final class ModuleRegistry implements FeatureRegistry {
public FeatureCatalog freeze() {
if (catalog == null) {
catalog = new FeatureCatalog(settings, objects, mantle, resourceKinds.values(), validators);
catalog = new FeatureCatalog(settings, objects, mantle, resourceKinds.values(), validators, vanillaStructureHooks);
}
return catalog;
}
@@ -6,6 +6,7 @@ import com.volmit.config.OptionsMetadata;
import com.volmit.config.Reference;
import com.volmit.host.schema.TextFormat;
import com.volmit.host.schema.ValueKind;
import com.volmit.host.schema.ValueKind.AnyKind;
import com.volmit.host.schema.ValueKind.BooleanKind;
import com.volmit.host.schema.ValueKind.DecimalKind;
import com.volmit.host.schema.ValueKind.EnumConstant;
@@ -39,13 +40,14 @@ import java.util.function.Function;
*/
final class ValueKinds {
static final String SUPPORTED_TYPES = "settings fields can be booleans, numbers, String, ResourceId, BlockState, enums, "
+ "lists, sets and arrays of these, Map with String keys and classes with a no-argument constructor";
+ "lists, sets and arrays of these, Map with String keys, Object for any JSON value and classes with a no-argument constructor";
private static final Set<Class<?>> BOOLEANS = Set.of(boolean.class, Boolean.class);
private static final Set<Class<?>> INTEGERS = Set.of(byte.class, short.class, int.class, long.class,
Byte.class, Short.class, Integer.class, Long.class);
private static final Set<Class<?>> DECIMALS = Set.of(float.class, double.class, Float.class, Double.class);
private static final String DECLARE_COLLECTION = "declare it as List<...>, Set<...> or Map<String, ...>";
private static final Set<Reference> PACK_REFERENCES = EnumSet.of(Reference.PACK_BIOME, Reference.PACK_REGION, Reference.PACK_OBJECT);
private static final Set<Reference> PACK_REFERENCES = EnumSet.of(Reference.PACK_BIOME, Reference.PACK_REGION, Reference.PACK_OBJECT,
Reference.PACK_EXPRESSION, Reference.PACK_IMAGE_MAP);
private final Function<Class<?>, ObjectKind> objects;
private final HostTypes hostTypes;
@@ -99,6 +101,7 @@ final class ValueKinds {
if (INTEGERS.contains(type)) return new IntegerKind();
if (DECIMALS.contains(type)) return new DecimalKind();
if (type.isEnum()) return enumKind(type);
if (type == Object.class) return new AnyKind();
return objects.apply(type);
}
@@ -0,0 +1,12 @@
package com.volmit.host;
import com.volmit.vanilla.VanillaStructureHook;
import java.util.Objects;
/** A vanilla structure hook and the module that registered it, which the host names when the hook fails. */
public record VanillaStructureHookRegistration(VanillaStructureHook hook, DiscoveredModule module) {
public VanillaStructureHookRegistration {
Objects.requireNonNull(hook, "hook");
Objects.requireNonNull(module, "module");
}
}
@@ -83,6 +83,13 @@ public sealed interface ValueKind {
}
}
/** Any JSON value, which the module reads as it is: {@code Object} fields, and the values of {@code Map<String, Object>}
* and {@code List<Object>}. For data whose shape the module does not own, such as a block entity's data. The host
* decodes objects as maps with string keys, arrays as lists, numbers as {@code Double}, and strings and booleans
* as themselves.
*/
record AnyKind() implements ValueKind {}
/** An enum constant and its {@code @Desc}, or an empty description. */
record EnumConstant(String name, String description) {
public EnumConstant {