mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 08:14:45 +00:00
Serve IrisApi's value types: BlockSpec resolution and block entities through Iris block data, noise from NoiseStyle through Iris generator styles, module snippets under their folder path, AnyKind, and studio rendering value types with Iris's own description of the same JSON
This commit is contained in:
1 parent
2f3ba3cebe
commit
49d90871fa
12 files changed
+556
-14
No files matched your search
@@ -18,26 +18,62 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.object.material.IrisBlockData;
|
||||
import art.arcane.iris.engine.object.prefab.TileData;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.spi.PlatformFace;
|
||||
import com.volmit.block.BlockFace;
|
||||
import com.volmit.block.BlockRegistry;
|
||||
import com.volmit.block.BlockSpec;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.block.BlockTrait;
|
||||
import com.volmit.object.BlockEntityData;
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* IrisApi's view of the bound platform's blocks. States convert through their keys, as {@link PlatformBlockStates}
|
||||
* does; the platform decides which blocks exist, so a key it does not know fails. Traits, tags and attachment to
|
||||
* a face are the platform's own answers: its block tags, its falling blocks and its face support.
|
||||
* <p>
|
||||
* {@link BlockSpec}s resolve as Iris resolves the block data packs write ({@link IrisValues#blockData}): a block of
|
||||
* the pack's {@code blocks} folder, the platform's block, the backup, then air. Each spec is converted once per
|
||||
* pack snapshot, so its resolution is too.
|
||||
*/
|
||||
final class IrisBlockRegistry implements BlockRegistry {
|
||||
private final IrisData data;
|
||||
private final Map<BlockSpec, IrisBlockData> specs = new ConcurrentHashMap<>();
|
||||
|
||||
/** @param data the pack whose {@code blocks} folder custom blocks come from */
|
||||
IrisBlockRegistry(IrisData data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState resolve(String key) {
|
||||
return BlockState.parse(PlatformBlockStates.namespaced(platformState(key).key()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState resolve(BlockSpec spec) {
|
||||
return BlockState.parse(PlatformBlockStates.namespaced(blockData(spec).getBlockData(data).key()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<BlockEntityData> blockEntity(BlockSpec spec) {
|
||||
TileData tile = blockData(spec).tryGetTile(data);
|
||||
return tile == null ? Optional.empty() : Optional.of(BlockEntities.of(tile));
|
||||
}
|
||||
|
||||
private IrisBlockData blockData(BlockSpec spec) {
|
||||
return specs.computeIfAbsent(spec, IrisValues::blockData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTrait(BlockState state, BlockTrait trait) {
|
||||
PlatformBlockState platform = platformState(state.key());
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.object.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.util.project.noise.CNG;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.noise.NoiseFactory;
|
||||
import com.volmit.noise.NoiseSampler;
|
||||
import com.volmit.noise.NoiseStyle;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Builds the noise of IrisApi noise styles with Iris's own generators: each style becomes the
|
||||
* {@link IrisGeneratorStyle} that reads the same JSON ({@link IrisValues#generatorStyle}), once per pack snapshot, and
|
||||
* builds its noise from an {@link RNG} of the seed exactly as Iris's own features do, with Iris's per-style cache of
|
||||
* built generators.
|
||||
*/
|
||||
final class IrisNoiseFactory implements NoiseFactory {
|
||||
private final IrisData data;
|
||||
private final Map<NoiseStyle, IrisGeneratorStyle> styles = new ConcurrentHashMap<>();
|
||||
|
||||
IrisNoiseFactory(IrisData data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NoiseSampler sampler(NoiseStyle style, long seed) {
|
||||
IrisGeneratorStyle iris = styles.computeIfAbsent(style, IrisValues::generatorStyle);
|
||||
try {
|
||||
return new CngSampler(iris.create(new RNG(seed), data));
|
||||
} catch (RuntimeException failure) {
|
||||
throw new IllegalArgumentException("Cannot build the noise of " + style + ": " + failure.getMessage(), failure);
|
||||
}
|
||||
}
|
||||
|
||||
/** Iris's noise as an IrisApi sampler; CNG is safe for the concurrent reads generation makes. */
|
||||
private record CngSampler(CNG noise) implements NoiseSampler {
|
||||
@Override
|
||||
public double sample(double worldX, double worldZ) {
|
||||
return noise.noise(worldX, worldZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double sample(double worldX, double y, double worldZ) {
|
||||
return noise.noise(worldX, y, worldZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@ import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import com.volmit.block.BlockRegistry;
|
||||
import com.volmit.host.ResourceKindRegistration;
|
||||
import com.volmit.noise.NoiseFactory;
|
||||
import com.volmit.object.GeneratedObject;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
@@ -57,6 +58,9 @@ import java.util.function.Supplier;
|
||||
* another namespace, is absent; any other type fails with {@link IllegalArgumentException}. A resource that exists
|
||||
* but cannot be loaded fails with {@link IllegalStateException}. Each resource is built once and kept for the
|
||||
* snapshot. The module kinds are looked up the first time one is asked for, which loads the pack's modules.
|
||||
* <p>
|
||||
* Blocks resolve through the platform and the pack's {@code blocks} folder ({@link IrisBlockRegistry}), and noise
|
||||
* styles through Iris's generators, expressions and image maps ({@link IrisNoiseFactory}), both kept per snapshot.
|
||||
*/
|
||||
public final class IrisPackResources implements PackResources {
|
||||
private static final String SERVED_TYPES = "GeneratedObject, PackBiome, PackRegion and the types of the pack's module resource kinds";
|
||||
@@ -64,7 +68,8 @@ public final class IrisPackResources implements PackResources {
|
||||
private final IrisData data;
|
||||
private final PackResourceIds ids;
|
||||
private final UUID snapshotId = UUID.randomUUID();
|
||||
private final BlockRegistry blocks = new IrisBlockRegistry();
|
||||
private final BlockRegistry blocks;
|
||||
private final NoiseFactory noise;
|
||||
private final Map<Class<?>, Kind<?>> irisKinds;
|
||||
private final Supplier<List<ResourceKind<?>>> moduleKindList;
|
||||
private volatile Map<Class<?>, Kind<?>> moduleKinds;
|
||||
@@ -81,6 +86,8 @@ public final class IrisPackResources implements PackResources {
|
||||
this.data = data;
|
||||
this.ids = new PackResourceIds(data.getDataFolder());
|
||||
this.moduleKindList = moduleKinds;
|
||||
this.blocks = new IrisBlockRegistry(data);
|
||||
this.noise = new IrisNoiseFactory(data);
|
||||
this.irisKinds = Map.of(
|
||||
GeneratedObject.class, Kind.<IrisObject, GeneratedObject>ofLoader(ids, data::getObjectLoader, (id, object) -> object.getGeometry()),
|
||||
PackBiome.class, Kind.<IrisBiome, PackBiome>ofLoader(ids, data::getBiomeLoader, this::biomeOf),
|
||||
@@ -102,6 +109,11 @@ public final class IrisPackResources implements PackResources {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NoiseFactory noise() {
|
||||
return noise;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked") // The kinds are keyed by the type they serve.
|
||||
public <T> Optional<T> find(ResourceKey<T> key) {
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.engine.object.material.IrisBlockData;
|
||||
import art.arcane.iris.engine.object.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.engine.object.noise.IrisStyledRange;
|
||||
import art.arcane.iris.engine.object.noise.NoiseStyle;
|
||||
import art.arcane.iris.engine.object.value.IrisPosition;
|
||||
import art.arcane.iris.engine.object.value.IrisRange;
|
||||
import art.arcane.volmlib.util.collection.KMap;
|
||||
import com.volmit.block.BlockSpec;
|
||||
import com.volmit.config.Range;
|
||||
import com.volmit.noise.StyledRange;
|
||||
import com.volmit.world.BlockPosition;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Iris's own classes for IrisApi's value types. Each pair reads the same pack JSON, so Iris resolves a value the way
|
||||
* it resolves its own class (a {@link BlockSpec} as an {@link IrisBlockData}, a noise style as an
|
||||
* {@link IrisGeneratorStyle}) and studio describes the value with Iris's own description of that class.
|
||||
*/
|
||||
public final class IrisValues {
|
||||
private static final Map<String, Class<?>> IRIS_CLASSES = Map.of(
|
||||
BlockSpec.class.getName(), IrisBlockData.class,
|
||||
com.volmit.noise.NoiseStyle.class.getName(), IrisGeneratorStyle.class,
|
||||
StyledRange.class.getName(), IrisStyledRange.class,
|
||||
Range.class.getName(), IrisRange.class,
|
||||
BlockPosition.class.getName(), IrisPosition.class);
|
||||
|
||||
private IrisValues() {
|
||||
}
|
||||
|
||||
/** The Iris class that reads the same JSON as the IrisApi value type named {@code apiTypeName}, if it is one. */
|
||||
public static Optional<Class<?>> irisClassOf(String apiTypeName) {
|
||||
return Optional.ofNullable(IRIS_CLASSES.get(apiTypeName));
|
||||
}
|
||||
|
||||
/** The IrisApi value types and the Iris classes that read the same JSON. */
|
||||
public static Map<String, Class<?>> irisClasses() {
|
||||
return IRIS_CLASSES;
|
||||
}
|
||||
|
||||
/** {@code spec} as the block data Iris resolves: its block, properties, weight, backup and tile data. */
|
||||
public static IrisBlockData blockData(BlockSpec spec) {
|
||||
IrisBlockData block = new IrisBlockData(spec.block());
|
||||
block.setData(irisMap(spec.data()));
|
||||
block.setWeight(spec.weight());
|
||||
block.setBackup(spec.backup().map(IrisValues::blockData).orElse(null));
|
||||
block.setTileData(irisMap(spec.tileData()));
|
||||
return block;
|
||||
}
|
||||
|
||||
/** Iris's maps hold no null values; a JSON null in a map reads as absent, as it does for Iris's own fields. */
|
||||
private static KMap<String, Object> irisMap(Map<String, ?> values) {
|
||||
KMap<String, Object> map = new KMap<>();
|
||||
values.forEach((key, value) -> {
|
||||
if (value != null) {
|
||||
map.put(key, value);
|
||||
}
|
||||
});
|
||||
return map;
|
||||
}
|
||||
|
||||
/** {@code style} as the generator style Iris builds noise from; a style name Iris does not know is flat. */
|
||||
public static IrisGeneratorStyle generatorStyle(com.volmit.noise.NoiseStyle style) {
|
||||
IrisGeneratorStyle iris = new IrisGeneratorStyle(irisStyle(style.style()));
|
||||
iris.setCellularFrequency(style.cellularFrequency());
|
||||
iris.setCellularZoom(style.cellularZoom());
|
||||
iris.setZoom(style.zoom());
|
||||
iris.setExpression(style.expression().orElse(null));
|
||||
iris.setImageMap(style.imageMap().orElse(null));
|
||||
iris.setMultiplier(style.multiplier());
|
||||
iris.setFracture(style.fracture().map(IrisValues::generatorStyle).orElse(null));
|
||||
iris.setExponent(style.exponent());
|
||||
iris.setCacheSize(style.cacheSize());
|
||||
return iris;
|
||||
}
|
||||
|
||||
private static NoiseStyle irisStyle(String name) {
|
||||
try {
|
||||
return NoiseStyle.valueOf(name);
|
||||
} catch (IllegalArgumentException unknown) {
|
||||
return NoiseStyle.FLAT;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,9 @@ import java.util.stream.Stream;
|
||||
* Reads the module settings a dimension, region or biome declares: each settings feature of the pack at
|
||||
* that target, under its id or, for built-ins, its alias. Settings are created with their no-argument
|
||||
* constructor and the JSON is read into them, so an omitted option keeps its default. A {@link Snippet}
|
||||
* type may be written as {@code "snippet/<name>"}, read from {@code snippet/<snippet folder>/<name>.json}.
|
||||
* type may be written as {@code "snippet/<name>"} or, as Iris's own snippets are, {@code "snippet/<snippet folder>/<name>"},
|
||||
* both read from {@code snippet/<snippet folder>/<name>.json}. IrisApi's value types ({@code BlockSpec},
|
||||
* {@code NoiseStyle} and the rest) are read like settings, and an {@code Object} as Gson reads any JSON value.
|
||||
* <p>
|
||||
* Settings with exactly one option may be written as that option's value: {@code "snow": 0.5} reads as
|
||||
* {@code "snow": {"amount": 0.5}}. Iris's own classes that built-in settings hold (see
|
||||
@@ -244,13 +246,20 @@ public final class ModuleSettingsDecoder {
|
||||
}
|
||||
}
|
||||
|
||||
/** The file name below the snippet folder: {@code snippet/<name>} and {@code snippet/<snippet folder>/<name>} name the same file. */
|
||||
private static String snippetName(String snippetFolder, String reference) {
|
||||
String name = reference.substring(SNIPPET_PREFIX.length());
|
||||
String folderPrefix = snippetFolder + "/";
|
||||
return name.startsWith(folderPrefix) ? name.substring(folderPrefix.length()) : name;
|
||||
}
|
||||
|
||||
private String readSnippet(String snippetFolder, String reference) {
|
||||
if (!reference.startsWith(SNIPPET_PREFIX)) {
|
||||
throw new JsonParseException("\"" + reference + "\" is neither an object nor a snippet reference; write the object,"
|
||||
+ " or snippet/<name> for the file " + SNIPPET_FOLDER + "/" + snippetFolder + "/<name>" + JSON_EXTENSION);
|
||||
}
|
||||
Path folder = packFolder.resolve(SNIPPET_FOLDER).resolve(snippetFolder).normalize();
|
||||
Path file = folder.resolve(reference.substring(SNIPPET_PREFIX.length()) + JSON_EXTENSION).normalize();
|
||||
Path file = folder.resolve(snippetName(snippetFolder, reference) + JSON_EXTENSION).normalize();
|
||||
if (!file.startsWith(folder) || !Files.isRegularFile(file)) {
|
||||
throw new JsonParseException("Snippet " + reference + " has no file " + packFolder.relativize(file));
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ package art.arcane.iris.core.project;
|
||||
import art.arcane.iris.core.IrisSettings;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.ResourceLoader;
|
||||
import art.arcane.iris.core.modules.IrisValues;
|
||||
import art.arcane.iris.core.modules.PackModulesException;
|
||||
import art.arcane.iris.engine.object.annotations.Snippet;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
@@ -230,6 +231,9 @@ public class IrisCodeWorkspace {
|
||||
}
|
||||
|
||||
for (ObjectType type : dm.getModules().pack().schema().snippets()) {
|
||||
if (IrisValues.irisClassOf(type.name()).isPresent()) {
|
||||
continue;
|
||||
}
|
||||
schemaEntries.add(moduleSnippetSchema(dm, type, immediateSchemas));
|
||||
}
|
||||
schemaEntries.addAll(ModuleResourceSchemas.entries(dm, immediateSchemas));
|
||||
@@ -252,7 +256,10 @@ public class IrisCodeWorkspace {
|
||||
return ws;
|
||||
}
|
||||
|
||||
/** A module's snippet type gets its own schema for the files under {@code snippet/<name>/}, as Iris's snippets do. */
|
||||
/**
|
||||
* A module's snippet type gets its own schema for the files under {@code snippet/<name>/}, as Iris's snippets do. IrisApi's
|
||||
* value types share their snippet folders with the Iris classes that read the same JSON, whose schemas Iris writes.
|
||||
*/
|
||||
private static JSONObject moduleSnippetSchema(IrisData data, ObjectType type, boolean immediate) {
|
||||
String name = type.snippet().orElseThrow();
|
||||
JSONObject entry = snippetSchemaEntry(name);
|
||||
|
||||
@@ -41,7 +41,8 @@ import java.util.function.Function;
|
||||
* schema studio writes: each feature as a property of its target under its id and, for built-ins, its
|
||||
* alias, each settings class once as a definition, references as completion lists (resource references as the keys
|
||||
* of the module resource kind they name). Settings with one option also accept that option's bare value; Iris's own
|
||||
* classes in built-in settings use Iris's own definitions.
|
||||
* classes in built-in settings use Iris's own definitions, and so do IrisApi's value types, which read the same JSON as
|
||||
* an Iris class ({@code BlockSpec} as Iris's block data), with the snippet references their {@code @Snippet} allows.
|
||||
*/
|
||||
final class ModuleSchemaRenderer {
|
||||
private static final String DEFINITION_PREFIX = "module-";
|
||||
@@ -70,16 +71,22 @@ final class ModuleSchemaRenderer {
|
||||
private final ReferenceCompletions references;
|
||||
private final ResourceCompletions resources;
|
||||
private final HostDefinitions hostDefinitions;
|
||||
private final Function<String, Optional<String>> sameJsonHostTypes;
|
||||
private final Function<String, List<String>> snippetFiles;
|
||||
|
||||
/** {@code snippetFiles} lists the snippet references a pack has for a snippet folder, such as {@code snippet/thick}. */
|
||||
/**
|
||||
* @param sameJsonHostTypes the Iris class that reads the same JSON as a module type, for IrisApi's value types
|
||||
* @param snippetFiles lists the snippet references a pack has for a snippet folder, such as {@code snippet/thick}
|
||||
*/
|
||||
ModuleSchemaRenderer(PackSchema schema, Map<String, JSONObject> definitions, ReferenceCompletions references,
|
||||
ResourceCompletions resources, HostDefinitions hostDefinitions, Function<String, List<String>> snippetFiles) {
|
||||
ResourceCompletions resources, HostDefinitions hostDefinitions,
|
||||
Function<String, Optional<String>> sameJsonHostTypes, Function<String, List<String>> snippetFiles) {
|
||||
this.schema = schema;
|
||||
this.definitions = definitions;
|
||||
this.references = references;
|
||||
this.resources = resources;
|
||||
this.hostDefinitions = hostDefinitions;
|
||||
this.sameJsonHostTypes = sameJsonHostTypes;
|
||||
this.snippetFiles = snippetFiles;
|
||||
}
|
||||
|
||||
@@ -137,22 +144,30 @@ final class ModuleSchemaRenderer {
|
||||
}
|
||||
definitions.put(key, new JSONObject());
|
||||
ObjectType type = schema.type(typeName);
|
||||
definitions.put(key, type.snippet().isPresent() ? objectOrSnippet(type) : objectSchema(type));
|
||||
JSONObject object = describedObject(type);
|
||||
definitions.put(key, type.snippet().isPresent() ? objectOrSnippet(object, type) : object);
|
||||
return key;
|
||||
}
|
||||
|
||||
private JSONObject objectOrSnippet(ObjectType type) {
|
||||
/** Iris's own description where an Iris class reads the same JSON, otherwise the module's. */
|
||||
private JSONObject describedObject(ObjectType type) {
|
||||
return sameJsonHostTypes.apply(type.name())
|
||||
.map(hostType -> new JSONObject().put("$ref", DEFINITION_REF + hostDefinitions.definition(hostType)))
|
||||
.orElseGet(() -> objectSchema(type));
|
||||
}
|
||||
|
||||
private JSONObject objectOrSnippet(JSONObject object, ObjectType type) {
|
||||
String folder = type.snippet().orElseThrow();
|
||||
JSONObject reference = new JSONObject();
|
||||
reference.put("type", "string");
|
||||
JSONArray files = new JSONArray(snippetFiles.apply(folder));
|
||||
JSONArray files = new JSONArray(List.<Object>copyOf(snippetFiles.apply(folder)));
|
||||
if (files.length() > 0) {
|
||||
reference.put("examples", files);
|
||||
}
|
||||
reference.put("pattern", SNIPPET_PATTERN);
|
||||
reference.put("description", "A snippet file under snippet/" + folder + "/, written as snippet/<name>");
|
||||
JSONObject either = new JSONObject();
|
||||
either.put("anyOf", new JSONArray(List.of(objectSchema(type), reference)));
|
||||
either.put("anyOf", new JSONArray(List.of(object, reference)));
|
||||
either.put("description", type.description());
|
||||
return either;
|
||||
}
|
||||
@@ -223,6 +238,8 @@ final class ModuleSchemaRenderer {
|
||||
}
|
||||
case ValueKind.ObjectKind object -> value.put("$ref", DEFINITION_REF + definition(object.type()));
|
||||
case ValueKind.HostKind host -> value.put("$ref", DEFINITION_REF + hostDefinitions.definition(host.type()));
|
||||
case ValueKind.AnyKind ignored -> {
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -25,9 +25,13 @@ import art.arcane.iris.spi.PlatformNumericRange;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.IrisRegistrant;
|
||||
import art.arcane.iris.core.loader.ResourceLoader;
|
||||
import art.arcane.iris.core.modules.IrisValues;
|
||||
import art.arcane.iris.core.modules.ModuleResourceFiles;
|
||||
import art.arcane.iris.core.modules.ModuleTargets;
|
||||
import art.arcane.iris.engine.framework.structure.StructureResources;
|
||||
import art.arcane.iris.engine.object.image.IrisImageMap;
|
||||
import art.arcane.iris.engine.object.noise.NoiseStyle;
|
||||
import art.arcane.iris.engine.object.noise.expression.IrisExpression;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
@@ -391,7 +395,8 @@ public class SchemaBuilder {
|
||||
private ModuleSchemaRenderer moduleSchemas() {
|
||||
if (moduleSchemas == null) {
|
||||
moduleSchemas = new ModuleSchemaRenderer(data.getModules().pack().schema(), definitions,
|
||||
this::completeReference, this::completeResourceReference, this::hostDefinition, data::getPossibleSnippets);
|
||||
this::completeReference, this::completeResourceReference, this::hostDefinition,
|
||||
typeName -> IrisValues.irisClassOf(typeName).map(Class::getName), data::getPossibleSnippets);
|
||||
}
|
||||
return moduleSchemas;
|
||||
}
|
||||
@@ -439,6 +444,9 @@ public class SchemaBuilder {
|
||||
case PACK_BIOME -> putPackResourceRef(property, IrisBiome.class);
|
||||
case PACK_REGION -> putPackResourceRef(property, IrisRegion.class);
|
||||
case PACK_OBJECT -> putPackResourceRef(property, IrisObject.class);
|
||||
case NOISE_STYLE -> addEnum(NoiseStyle.class, property, new KList<>(), enumNames(NoiseStyle.class), Function.identity());
|
||||
case PACK_EXPRESSION -> putPackResourceRef(property, IrisExpression.class);
|
||||
case PACK_IMAGE_MAP -> putPackResourceRef(property, IrisImageMap.class);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
/** IrisApi's blocks are the bound platform's, through their keys, and so are its traits, tags and face support. */
|
||||
public class IrisBlockRegistryTest {
|
||||
private final IrisBlockRegistry blocks = new IrisBlockRegistry();
|
||||
private final IrisBlockRegistry blocks = new IrisBlockRegistry(mock(art.arcane.iris.core.loader.IrisData.class));
|
||||
private PlatformRegistries registries;
|
||||
private PlatformBlockState stone;
|
||||
private PlatformBlockState sand;
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.ResourceLoader;
|
||||
import art.arcane.iris.engine.UsableBlockPlatform;
|
||||
import art.arcane.iris.engine.object.material.IrisBlockData;
|
||||
import art.arcane.iris.engine.object.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.engine.object.prefab.TileData;
|
||||
import art.arcane.iris.spi.IrisPlatform;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.spi.PlatformRegistries;
|
||||
import art.arcane.iris.util.project.noise.CNG;
|
||||
import art.arcane.volmlib.util.collection.KMap;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.google.gson.Gson;
|
||||
import com.volmit.block.BlockSpec;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.config.OptionsMetadata;
|
||||
import com.volmit.noise.NoiseSampler;
|
||||
import com.volmit.noise.NoiseStyle;
|
||||
import com.volmit.object.BlockEntityData;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/** IrisApi's value types read the JSON of Iris's own classes and resolve, and build noise, exactly as those do. */
|
||||
public class IrisValuesTest {
|
||||
private static final double[][] COLUMNS = {{0, 0}, {17.5, -3}, {-640, 1280}, {12345.25, 678.5}};
|
||||
private static final Map<Class<?>, Set<String>> IRIS_ONLY_FIELDS = Map.of(IrisBlockData.class, Set.of("debug"));
|
||||
|
||||
@After
|
||||
public void unbindPlatform() {
|
||||
UsableBlockPlatform.unbind();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void everyValueTypeHasTheJsonFieldsOfItsIrisClass() {
|
||||
IrisValues.irisClasses().forEach((apiType, irisClass) -> {
|
||||
Set<String> api = new TreeSet<>(OptionsMetadata.inspect(apiClass(apiType)).options().stream().map(OptionsMetadata.Option::name).toList());
|
||||
Set<String> iris = new TreeSet<>(jsonFields(irisClass));
|
||||
iris.removeAll(IRIS_ONLY_FIELDS.getOrDefault(irisClass, Set.of()));
|
||||
assertEquals(apiType + " and " + irisClass.getName(), iris, api);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void blockSpecsResolveThroughThePlatformWithTheirProperties() {
|
||||
UsableBlockPlatform.bind();
|
||||
IrisBlockRegistry blocks = new IrisBlockRegistry(packWithoutCustomBlocks());
|
||||
|
||||
assertEquals(BlockState.parse("minecraft:iron_ore"), blocks.resolve(BlockSpec.of("iron_ore")));
|
||||
assertEquals(BlockState.parse("minecraft:oak_log[axis=y]"), blocks.resolve(BlockSpec.of("minecraft:oak_log").withProperty("axis", "y")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aBlockSpecNamesTheCustomBlocksOfThePackAndFallsBackToItsBackup() {
|
||||
PlatformRegistries registries = mock(PlatformRegistries.class);
|
||||
when(registries.block(anyString())).thenAnswer(invocation -> {
|
||||
String key = invocation.getArgument(0);
|
||||
return key.contains("missing") ? null : UsableBlockPlatform.block(key);
|
||||
});
|
||||
when(registries.blockOrNull(anyString(), anyBoolean())).thenAnswer(invocation -> registries.block(invocation.getArgument(0)));
|
||||
bind(registries);
|
||||
IrisData data = packWithoutCustomBlocks();
|
||||
when(data.getBlockLoader().load("glowing_stone", false)).thenReturn(new IrisBlockData("minecraft:stone").setData(new KMap<String, Object>().qput("lit", true)));
|
||||
IrisBlockRegistry blocks = new IrisBlockRegistry(data);
|
||||
|
||||
assertEquals(BlockState.parse("minecraft:stone[lit=true]"), blocks.resolve(BlockSpec.of("glowing_stone")));
|
||||
assertEquals(BlockState.parse("minecraft:cobblestone"), blocks.resolve(BlockSpec.of("mod:missing").withBackup(BlockSpec.of("cobblestone"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tileDataBecomesIrisBlockEntities() {
|
||||
UsableBlockPlatform.bind();
|
||||
TileData.TileFactory previous = TileData.bindPlatformFactory((state, properties) -> new TileData(state.key(), properties));
|
||||
try {
|
||||
IrisBlockRegistry blocks = new IrisBlockRegistry(packWithoutCustomBlocks());
|
||||
BlockSpec spawner = BlockSpec.of("spawner").withTileData(Map.of("Delay", 20.0));
|
||||
|
||||
assertEquals(Optional.empty(), blocks.blockEntity(BlockSpec.of("stone")));
|
||||
assertEquals("the platform's stone-like spawner has no block entity", Optional.empty(), blocks.blockEntity(spawner));
|
||||
PlatformBlockState withEntity = UsableBlockPlatform.block("minecraft:chest");
|
||||
when(withEntity.hasTileEntity()).thenReturn(true);
|
||||
PlatformRegistries registries = mock(PlatformRegistries.class);
|
||||
when(registries.block(anyString())).thenReturn(withEntity);
|
||||
bind(registries);
|
||||
BlockEntityData entity = new IrisBlockRegistry(packWithoutCustomBlocks()).blockEntity(BlockSpec.of("chest").withTileData(Map.of("Lock", "key")))
|
||||
.orElseThrow();
|
||||
assertEquals(BlockEntities.TILE_FORMAT, entity.format());
|
||||
} finally {
|
||||
TileData.restorePlatformFactory(previous);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noiseStylesBuildTheNoiseOfTheirIrisGeneratorStyle() {
|
||||
String json = "{\"style\": \"SIMPLEX\", \"zoom\": 4, \"exponent\": 1.5, \"cellularFrequency\": 0.3,"
|
||||
+ " \"fracture\": {\"style\": \"PERLIN\", \"zoom\": 2, \"multiplier\": 3}}";
|
||||
IrisData data = packWithoutCustomBlocks();
|
||||
NoiseStyle style = new Gson().fromJson(json, NoiseStyle.class);
|
||||
CNG iris = new Gson().fromJson(json, IrisGeneratorStyle.class).create(new RNG(1337), data);
|
||||
NoiseSampler sampler = new IrisNoiseFactory(data).sampler(style, 1337);
|
||||
|
||||
for (double[] column : COLUMNS) {
|
||||
assertEquals(iris.noise(column[0], column[1]), sampler.sample(column[0], column[1]), 0);
|
||||
assertEquals(iris.noise(column[0], 64, column[1]), sampler.sample(column[0], 64, column[1]), 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aStyleNameIrisDoesNotKnowIsFlat() {
|
||||
IrisData data = packWithoutCustomBlocks();
|
||||
IrisNoiseFactory noise = new IrisNoiseFactory(data);
|
||||
NoiseSampler unknown = noise.sampler(NoiseStyle.of("NOT_A_STYLE"), 7);
|
||||
NoiseSampler flat = noise.sampler(NoiseStyle.of(NoiseStyle.FLAT), 7);
|
||||
|
||||
for (double[] column : COLUMNS) {
|
||||
assertEquals(flat.sample(column[0], column[1]), unknown.sample(column[0], column[1]), 0);
|
||||
}
|
||||
}
|
||||
|
||||
private static IrisData packWithoutCustomBlocks() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
ResourceLoader<IrisBlockData> blocks = mock(ResourceLoader.class);
|
||||
when(data.getBlockLoader()).thenReturn(blocks);
|
||||
return data;
|
||||
}
|
||||
|
||||
private static void bind(PlatformRegistries registries) {
|
||||
UsableBlockPlatform.unbind();
|
||||
IrisPlatform platform = mock(IrisPlatform.class);
|
||||
when(platform.registries()).thenReturn(registries);
|
||||
IrisPlatforms.bind(platform);
|
||||
}
|
||||
|
||||
private static Class<?> apiClass(String name) {
|
||||
try {
|
||||
return Class.forName(name);
|
||||
} catch (ClassNotFoundException missing) {
|
||||
throw new AssertionError(missing);
|
||||
}
|
||||
}
|
||||
|
||||
/** The fields Iris's Gson reads: instance fields that are not transient, a superclass's included. */
|
||||
private static List<String> jsonFields(Class<?> type) {
|
||||
List<String> names = new ArrayList<>();
|
||||
for (Class<?> current = type; current != null && current != Object.class; current = current.getSuperclass()) {
|
||||
for (Field field : current.getDeclaredFields()) {
|
||||
int modifiers = field.getModifiers();
|
||||
if (!Modifier.isStatic(modifiers) && !Modifier.isTransient(modifiers) && !field.isSynthetic()) {
|
||||
names.add(field.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
return names;
|
||||
}
|
||||
}
|
||||
@@ -30,14 +30,19 @@ import com.volmit.FeatureAttachment.Target;
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.IrisModule;
|
||||
import com.volmit.ModuleInfo;
|
||||
import com.volmit.block.BlockSpec;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.config.Range;
|
||||
import com.volmit.config.Feature;
|
||||
import com.volmit.config.Snippet;
|
||||
import com.volmit.host.LoadedPack;
|
||||
import com.volmit.host.ModuleHost;
|
||||
import com.volmit.noise.NoiseStyle;
|
||||
import com.volmit.noise.StyledRange;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.stage.Stage;
|
||||
import com.volmit.stage.StageGraph;
|
||||
import com.volmit.world.BlockPosition;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
@@ -48,6 +53,8 @@ import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -86,6 +93,16 @@ public class ModuleSettingsDecoderTest {
|
||||
private List<IrisPosition> marks = List.of();
|
||||
}
|
||||
|
||||
@Feature(id = "iris:moss/values", name = "Values", targets = Target.BIOME)
|
||||
public static final class ValuesSettings implements IrisFeature {
|
||||
private List<BlockSpec> palette = List.of();
|
||||
private NoiseStyle style = NoiseStyle.of("SIMPLEX");
|
||||
private StyledRange height = StyledRange.of(1, 2, NoiseStyle.of(NoiseStyle.FLAT));
|
||||
private Range light = Range.of(0, 15);
|
||||
private BlockPosition offset = new BlockPosition(0, 0, 0);
|
||||
private Map<String, Object> extra = Map.of();
|
||||
}
|
||||
|
||||
public static final class MossModule implements IrisModule {
|
||||
@Override
|
||||
public ModuleInfo info() {
|
||||
@@ -102,6 +119,7 @@ public class ModuleSettingsDecoderTest {
|
||||
public void register(FeatureRegistry registry) {
|
||||
registry.registerSettings(CoverSettings.class);
|
||||
registry.registerSettings(MarksSettings.class);
|
||||
registry.registerSettings(ValuesSettings.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,6 +180,50 @@ public class ModuleSettingsDecoderTest {
|
||||
assertTrue(missing.getMessage(), missing.getMessage().contains("Snippet snippet/narrow has no file snippet/moss-patch/narrow.json"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void snippetReferencesMayNameTheSnippetFolderAsIrisSnippetsDo() throws IOException {
|
||||
Path snippets = Files.createDirectories(packFolder.resolve("snippet/moss-patch"));
|
||||
Files.writeString(snippets.resolve("wide.json"), "{\"size\": 9}");
|
||||
|
||||
assertEquals(9, moss("{\"moss\": {\"patch\": \"snippet/moss-patch/wide\"}}").patch.size);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void apiValueTypesReadTheJsonIrisClassesRead() throws IOException {
|
||||
Path styles = Files.createDirectories(packFolder.resolve("snippet/style"));
|
||||
Files.writeString(styles.resolve("deepslate.json"), "{\"style\": \"STATIC\"}");
|
||||
ValuesSettings values = decoder.decode(Target.BIOME, new JSONObject("""
|
||||
{"iris:moss/values": {
|
||||
"palette": [{"block": "minecraft:oak_log", "data": {"axis": "y", "waterlogged": true, "level": 3}, "weight": 2,
|
||||
"backup": {"block": "stone"}, "tileData": {"Delay": 20, "SpawnData": {"entity": {"id": "zombie"}}}},
|
||||
{"block": "iron_ore"}],
|
||||
"style": "snippet/style/deepslate",
|
||||
"height": {"min": 4, "style": {"style": "SIMPLEX", "zoom": 8, "fracture": {"style": "PERLIN", "multiplier": 2}}},
|
||||
"light": {"max": 7},
|
||||
"offset": {"x": 1, "z": 3},
|
||||
"extra": {"list": [1, "a", true]}
|
||||
}}
|
||||
"""), "biome desert/dunes").find(ValuesSettings.class).orElseThrow();
|
||||
|
||||
BlockSpec log = values.palette.getFirst();
|
||||
assertEquals("minecraft:oak_log", log.block());
|
||||
assertEquals(Map.of("axis", "y", "waterlogged", "true", "level", "3"), log.data());
|
||||
assertEquals(2, log.weight());
|
||||
assertEquals(Optional.of(BlockSpec.of("stone")), log.backup());
|
||||
assertEquals(Map.of("Delay", 20.0, "SpawnData", Map.of("entity", Map.of("id", "zombie"))), log.tileData());
|
||||
assertEquals(BlockSpec.of("iron_ore"), values.palette.get(1));
|
||||
assertEquals(NoiseStyle.of("STATIC"), values.style);
|
||||
assertEquals(4, values.height.min(), 0);
|
||||
assertEquals(32, values.height.max(), 0);
|
||||
assertEquals("SIMPLEX", values.height.style().style());
|
||||
assertEquals(8, values.height.style().zoom(), 0);
|
||||
assertEquals("PERLIN", values.height.style().fracture().orElseThrow().style());
|
||||
assertEquals(2, values.height.style().fracture().orElseThrow().multiplier(), 0);
|
||||
assertEquals(Range.of(16, 7), values.light);
|
||||
assertEquals(new BlockPosition(1, 0, 3), values.offset);
|
||||
assertEquals(Map.of("list", List.of(1.0, "a", true)), values.extra);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void badValuesNameTheSettingsKeyAndResource() {
|
||||
IllegalArgumentException failure = assertThrows(IllegalArgumentException.class,
|
||||
@@ -172,7 +234,7 @@ public class ModuleSettingsDecoderTest {
|
||||
|
||||
@Test
|
||||
public void listsTheKeysModulesReadPerTarget() {
|
||||
assertEquals(Set.of("iris:moss", "moss", "iris:moss/cover", "cover", "iris:moss/marks", "marks"), decoder.keys(Target.BIOME));
|
||||
assertEquals(Set.of("iris:moss", "moss", "iris:moss/cover", "cover", "iris:moss/marks", "marks", "iris:moss/values"), decoder.keys(Target.BIOME));
|
||||
assertEquals(Set.of(), decoder.keys(Target.DIMENSION));
|
||||
}
|
||||
|
||||
|
||||
@@ -274,6 +274,22 @@ public class SchemaBuilderParityTest {
|
||||
assertTrue(schema.toString().contains("{\"not\":{\"required\":[\"glow\",\"example:glow\"]}}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void moduleSettingsHoldingApiValueTypesUseIrisDescriptionsOfTheSameJson() throws IOException {
|
||||
JSONObject schema = new SchemaBuilder(IrisObjectPlacement.class, structureSchemaData(tintModuleSchema())).construct();
|
||||
JSONObject definitions = schema.getJSONObject("definitions");
|
||||
JSONObject tint = definitions.getJSONObject(definitionKey(rootProperties(schema).getJSONObject("example:tint")))
|
||||
.getJSONObject("properties");
|
||||
|
||||
JSONObject spec = definitions.getJSONObject(definitionKey(tint.getJSONObject("palette").getJSONObject("items")));
|
||||
assertEquals("obj-art-arcane-iris-engine-object-material-irisblockdata", definitionKey(spec));
|
||||
assertTrue(definitions.getJSONObject("obj-art-arcane-iris-engine-object-material-irisblockdata").getJSONObject("properties").has("block"));
|
||||
JSONArray style = definitions.getJSONObject(definitionKey(tint.getJSONObject("style"))).getJSONArray("anyOf");
|
||||
assertEquals("obj-art-arcane-iris-engine-object-noise-irisgeneratorstyle", definitionKey(style.getJSONObject(0)));
|
||||
assertEquals("a style may be a snippet, as Iris's styles may", "^snippet/", style.getJSONObject(1).getString("pattern"));
|
||||
assertEquals("any JSON value", 0, tint.getJSONObject("extra").getJSONObject("additionalProperties").length());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dimensionSchemaExposesSurfaceSupportDefaults() {
|
||||
JSONObject properties = rootProperties(
|
||||
@@ -646,6 +662,34 @@ public class SchemaBuilderParityTest {
|
||||
}
|
||||
}
|
||||
|
||||
private static PackSchema tintModuleSchema() throws IOException {
|
||||
Path root = Files.createTempDirectory("tint-pack");
|
||||
try (LoadedPack pack = LoadedPack.load(Files.createDirectory(root.resolve("pack")),
|
||||
ModuleHost.of(List.of(new TintModule())).copyingJarsTo(Files.createDirectory(root.resolve("copies"))))) {
|
||||
return pack.schema();
|
||||
}
|
||||
}
|
||||
|
||||
@Feature(id = "example:tint", name = "Tint", targets = Target.OBJECT_PLACEMENT)
|
||||
public static final class TintSettings implements IrisFeature {
|
||||
private List<com.volmit.block.BlockSpec> palette = List.of();
|
||||
private com.volmit.noise.NoiseStyle style = com.volmit.noise.NoiseStyle.of("SIMPLEX");
|
||||
private java.util.Map<String, Object> extra = java.util.Map.of();
|
||||
}
|
||||
|
||||
public static final class TintModule implements IrisModule {
|
||||
@Override
|
||||
public ModuleInfo info() {
|
||||
return ModuleInfo.of("example:tint", "Tint", "1");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void install(StageGraph graph) {
|
||||
graph.define(Stage.placement("example:tint/paint")).when(TintSettings.class).run((context, tint) -> {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Feature(id = "example:glow", name = "Glow", alias = "glow", targets = Target.OBJECT_PLACEMENT)
|
||||
public static final class GlowSettings implements IrisFeature {
|
||||
@com.volmit.config.Desc("How bright the glow is")
|
||||
|
||||
Reference in new issue
Block a user