mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Merge wave1/a2
This commit is contained in:
commit
99a914633d
31 files changed
+1018
-42
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();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -11,9 +11,10 @@ import java.util.NoSuchElementException;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
/** Frozen registrations. Lists use lexical feature/layer/kind ID order, and validators, lifecycle hooks and service
|
||||
* providers are in module id order, each module's in the order it registered them, so nothing depends on discovery.
|
||||
* Factory, codec, validator, hook and provider implementations must themselves obey their concurrency contracts.
|
||||
/** Frozen registrations. Lists use lexical feature/layer/kind ID order, and validators, lifecycle hooks, service
|
||||
* providers and vanilla structure hooks are in module id order, each module's in the order it registered them, so
|
||||
* nothing depends on discovery. Factory, codec, validator, hook and provider implementations must themselves obey their
|
||||
* concurrency contracts.
|
||||
*/
|
||||
public final class FeatureCatalog {
|
||||
private final Map<Class<?>, FeatureDescriptor<?>> settings;
|
||||
@@ -23,6 +24,7 @@ public final class FeatureCatalog {
|
||||
private final List<ValidatorRegistration> validators;
|
||||
private final List<LifecycleRegistration> lifecycles;
|
||||
private final List<ServiceRegistration> services;
|
||||
private final List<VanillaStructureHookRegistration> vanillaStructureHooks;
|
||||
|
||||
FeatureCatalog(
|
||||
Map<Class<?>, FeatureDescriptor<?>> settings,
|
||||
@@ -31,7 +33,8 @@ public final class FeatureCatalog {
|
||||
Collection<ResourceKindRegistration> resourceKinds,
|
||||
List<ValidatorRegistration> validators,
|
||||
List<LifecycleRegistration> lifecycles,
|
||||
List<ServiceRegistration> services) {
|
||||
List<ServiceRegistration> services,
|
||||
List<VanillaStructureHookRegistration> vanillaStructureHooks) {
|
||||
this.settings = Map.copyOf(settings);
|
||||
this.objects = Map.copyOf(objects);
|
||||
this.mantle = Map.copyOf(mantle);
|
||||
@@ -39,6 +42,7 @@ public final class FeatureCatalog {
|
||||
this.validators = inModuleOrder(validators, ValidatorRegistration::module);
|
||||
this.lifecycles = inModuleOrder(lifecycles, LifecycleRegistration::module);
|
||||
this.services = inModuleOrder(services, ServiceRegistration::module);
|
||||
this.vanillaStructureHooks = inModuleOrder(vanillaStructureHooks, VanillaStructureHookRegistration::module);
|
||||
}
|
||||
|
||||
/** Settings types that activate stages; the host decodes them from pack JSON. */
|
||||
@@ -64,6 +68,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;
|
||||
}
|
||||
|
||||
/** The lifecycle hooks modules registered, by module id, each module's in the order it registered them. */
|
||||
public List<LifecycleRegistration> lifecycles() {
|
||||
return lifecycles;
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.volmit.resource.ResourceId;
|
||||
import com.volmit.resource.ResourceKind;
|
||||
import com.volmit.service.Providers;
|
||||
import com.volmit.validation.Validator;
|
||||
import com.volmit.vanilla.VanillaStructureHook;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@@ -45,6 +46,7 @@ public final class ModuleRegistry implements FeatureRegistry {
|
||||
private final List<ValidatorRegistration> validators = new ArrayList<>();
|
||||
private final List<LifecycleRegistration> lifecycles = new ArrayList<>();
|
||||
private final List<ServiceRegistration> services = new ArrayList<>();
|
||||
private final List<VanillaStructureHookRegistration> vanillaStructureHooks = new ArrayList<>();
|
||||
private final Set<String> reservedFolders;
|
||||
private final List<DiscoveredModule> registered = new ArrayList<>();
|
||||
private FeatureCatalog catalog;
|
||||
@@ -160,6 +162,14 @@ public final class ModuleRegistry implements FeatureRegistry {
|
||||
services.add(added);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerVanillaStructureHook(VanillaStructureHook hook) {
|
||||
checkOpen();
|
||||
Objects.requireNonNull(hook, "hook");
|
||||
requireRegistering("Vanilla structure hook " + hook);
|
||||
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.
|
||||
@@ -180,7 +190,8 @@ public final class ModuleRegistry implements FeatureRegistry {
|
||||
|
||||
public FeatureCatalog freeze() {
|
||||
if (catalog == null) {
|
||||
catalog = new FeatureCatalog(settings, objects, mantle, resourceKinds.values(), validators, lifecycles, services);
|
||||
catalog = new FeatureCatalog(settings, objects, mantle, resourceKinds.values(), validators, lifecycles, services,
|
||||
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 {
|
||||
|
||||
Reference in new issue
Block a user