mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 16:25:36 +00:00
Merge wave1/a2
This commit is contained in:
commit
25fd24b7c2
28 files changed
+1294
-263
No files matched your search
+2
-2
@@ -118,7 +118,7 @@ public class IrisStructureLocateCommandContractTest {
|
||||
@Test
|
||||
public void unregisteredDiagnosticExplainsEveryRejectedRoute() {
|
||||
assertEquals(
|
||||
"Native structure minecraft:village is disabled by this dimension's importedStructures settings.",
|
||||
"Native structure minecraft:village is disabled by this dimension's importedStructures settings or a module of the pack.",
|
||||
CommandFind.describeStructureExclusion(
|
||||
CommandFind.StructureLookupRoute.POLICY_DISABLED, "minecraft:village",
|
||||
NativeStructureGenerationStatus.DISABLED_BY_PACK,
|
||||
@@ -214,7 +214,7 @@ public class IrisStructureLocateCommandContractTest {
|
||||
@Test
|
||||
public void findNativePolicyMessagesMatchModdedDiagnostics() {
|
||||
assertEquals(
|
||||
"Native structure minecraft:village_plains is disabled by this dimension's importedStructures settings.",
|
||||
"Native structure minecraft:village_plains is disabled by this dimension's importedStructures settings or a module of the pack.",
|
||||
NativeStructureGenerationPolicy.generationStatusMessage(
|
||||
"minecraft:village_plains", NativeStructureGenerationStatus.DISABLED_BY_PACK));
|
||||
assertEquals(
|
||||
|
||||
+15
-1
@@ -43,6 +43,7 @@ import net.minecraft.world.level.levelgen.structure.structures.OceanMonumentStru
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
@@ -56,6 +57,9 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class NativeStructureReferenceRepairTest {
|
||||
@BeforeClass
|
||||
@@ -138,7 +142,7 @@ public class NativeStructureReferenceRepairTest {
|
||||
NativeStructureReferenceEnvelope.referenceBounds(start, structure, terrain));
|
||||
IrisDimension dimension = new IrisDimension();
|
||||
dimension.getImportedStructures().getDisabled().add(structureKey);
|
||||
IrisData data = allocateWithoutConstructor(IrisData.class);
|
||||
IrisData data = packWithoutModules();
|
||||
Engine engine = engine(dimension, data);
|
||||
IrisNativeStructureDecision currentDecision = NativeStructureGenerationPolicy.resolve(
|
||||
engine, structureKey, false);
|
||||
@@ -322,6 +326,16 @@ public class NativeStructureReferenceRepairTest {
|
||||
handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* A pack without modules: the generation policy asks the pack's vanilla structure hooks, and there are none. The
|
||||
* adapters' tests do not see IrisApi's host classes, so the catalog is a deep stub.
|
||||
*/
|
||||
private static IrisData packWithoutModules() {
|
||||
IrisData data = mock(IrisData.class, RETURNS_DEEP_STUBS);
|
||||
when(data.getDataFolder()).thenReturn(new File("pack"));
|
||||
return data;
|
||||
}
|
||||
|
||||
private static Engine engine(IrisDimension dimension, IrisData data) throws Exception {
|
||||
TestEngine engine = allocateWithoutConstructor(TestEngine.class);
|
||||
engine.dimension = dimension;
|
||||
|
||||
@@ -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;
|
||||
@@ -82,6 +87,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),
|
||||
@@ -115,6 +122,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) {
|
||||
|
||||
@@ -33,10 +33,9 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The settings an engine's pack declares, for working out mantle stage reaches when the pack loads: the
|
||||
* engine's dimension, then every region it can reach, then every biome. Iris's built-in mantle stages size
|
||||
* their reach from Iris's own pack data instead of module settings; they reach the engine through
|
||||
* {@link #of(PackSettings)}.
|
||||
* The settings an engine's pack declares, for working out mantle stage reaches when the pack loads and for vanilla
|
||||
* structure hooks: the engine's dimension, then every region it can reach, then every biome. Iris's built-in modules
|
||||
* decide from Iris's own pack data instead of module settings; they reach the engine through {@link #of(PackSettings)}.
|
||||
*/
|
||||
public final class IrisPackSettings implements PackSettings {
|
||||
static final String DIMENSION = "dimension";
|
||||
@@ -54,7 +53,7 @@ public final class IrisPackSettings implements PackSettings {
|
||||
/** Iris's own view of {@code settings}, which Iris hands to every reach it works out. */
|
||||
public static IrisPackSettings of(PackSettings settings) {
|
||||
if (!(settings instanceof IrisPackSettings irisSettings)) {
|
||||
throw new IllegalArgumentException("Built-in reaches are worked out from an Iris engine's pack, not " + settings);
|
||||
throw new IllegalArgumentException("Built-in modules read an Iris engine's pack, not " + settings);
|
||||
}
|
||||
return irisSettings;
|
||||
}
|
||||
|
||||
@@ -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. */
|
||||
static Map<String, Class<?>> irisClasses() {
|
||||
return IRIS_CLASSES;
|
||||
}
|
||||
|
||||
/** {@code spec} as the block data Iris resolves: its block, properties, weight, backup and tile data. */
|
||||
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. */
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* 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.framework.Engine;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.host.VanillaStructureHookRegistration;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.vanilla.VanillaStructureContext;
|
||||
import com.volmit.vanilla.VanillaStructureRule;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* What the pack's modules want for each of the platform's own structures in one engine's world: every vanilla structure
|
||||
* hook of the pack asked once per structure, the rules combined ({@link VanillaStructureRule#and}). Kept per engine and
|
||||
* pack snapshot, so a hotload or a reload of the pack's resources asks the hooks again. The platform side
|
||||
* ({@code NativeStructureGenerationPolicy}) applies the result on Bukkit and the modded platforms alike.
|
||||
*/
|
||||
public final class ModuleVanillaStructures {
|
||||
private static final Map<Engine, ModuleVanillaStructures> WORLDS = Collections.synchronizedMap(new WeakHashMap<>());
|
||||
|
||||
private final PackResources snapshot;
|
||||
private final List<VanillaStructureHookRegistration> hooks;
|
||||
private final VanillaStructureContext world;
|
||||
private final Map<String, VanillaStructureRule> rules = new ConcurrentHashMap<>();
|
||||
|
||||
private ModuleVanillaStructures(Engine engine, PackResources snapshot) {
|
||||
this.snapshot = snapshot;
|
||||
this.hooks = engine.getData().getModules().pack().catalog().vanillaStructureHooks();
|
||||
this.world = new World(snapshot, new IrisPackSettings(engine));
|
||||
}
|
||||
|
||||
/** The combined rule of the pack's modules for the platform structure {@code structureKey} in {@code engine}'s world. */
|
||||
public static VanillaStructureRule ruleFor(Engine engine, String structureKey) {
|
||||
return of(engine).rule(structureKey);
|
||||
}
|
||||
|
||||
private static ModuleVanillaStructures of(Engine engine) {
|
||||
PackResources current = engine.getData().getPackResources();
|
||||
ModuleVanillaStructures known = WORLDS.get(engine);
|
||||
if (known != null && known.snapshot == current) {
|
||||
return known;
|
||||
}
|
||||
ModuleVanillaStructures fresh = new ModuleVanillaStructures(engine, current);
|
||||
WORLDS.put(engine, fresh);
|
||||
return fresh;
|
||||
}
|
||||
|
||||
private VanillaStructureRule rule(String structureKey) {
|
||||
return rules.computeIfAbsent(structureKey, this::askHooks);
|
||||
}
|
||||
|
||||
/** A key that is no resource id names no structure a module could decide over. */
|
||||
private VanillaStructureRule askHooks(String structureKey) {
|
||||
ResourceId structure;
|
||||
try {
|
||||
structure = ResourceId.parse(structureKey);
|
||||
} catch (IllegalArgumentException notAnId) {
|
||||
return VanillaStructureRule.GENERATE;
|
||||
}
|
||||
VanillaStructureRule combined = VanillaStructureRule.GENERATE;
|
||||
for (VanillaStructureHookRegistration registration : hooks) {
|
||||
combined = combined.and(ask(registration, structure));
|
||||
}
|
||||
return combined;
|
||||
}
|
||||
|
||||
private VanillaStructureRule ask(VanillaStructureHookRegistration registration, ResourceId structure) {
|
||||
VanillaStructureRule rule;
|
||||
try {
|
||||
rule = registration.hook().rule(structure, world);
|
||||
} catch (RuntimeException failure) {
|
||||
throw new IllegalStateException("Module " + registration.module() + " failed deciding over vanilla structure "
|
||||
+ structure + ": " + failure, failure);
|
||||
}
|
||||
if (rule == null) {
|
||||
throw new IllegalStateException("Module " + registration.module() + " gave no rule for vanilla structure " + structure);
|
||||
}
|
||||
return rule;
|
||||
}
|
||||
|
||||
/** The world the hooks decide for: the engine's pack snapshot and the settings its dimension reaches. */
|
||||
private record World(PackResources resources, PackSettings settings) implements VanillaStructureContext {
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -207,8 +222,8 @@ final class ModuleSchemaRenderer {
|
||||
}
|
||||
case ValueKind.EnumKind enumKind -> {
|
||||
value.put("type", "string");
|
||||
value.put("enum", new JSONArray(enumKind.constants().stream().map(ValueKind.EnumConstant::name).toList()));
|
||||
value.put("enumDescriptions", new JSONArray(enumKind.constants().stream().map(ValueKind.EnumConstant::description).toList()));
|
||||
value.put("enum", new JSONArray(enumKind.constants().stream().<Object>map(ValueKind.EnumConstant::name).toList()));
|
||||
value.put("enumDescriptions", new JSONArray(enumKind.constants().stream().<Object>map(ValueKind.EnumConstant::description).toList()));
|
||||
}
|
||||
case ValueKind.ListKind list -> {
|
||||
value.put("type", "array");
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+21
-12
@@ -18,13 +18,21 @@
|
||||
|
||||
package art.arcane.iris.engine.framework;
|
||||
|
||||
import art.arcane.iris.core.modules.ModuleVanillaStructures;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisImportedStructureControl;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructureDecision;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.NativeStructureGenerationStatus;
|
||||
import com.volmit.vanilla.VanillaStructureRule;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Whether the platform generates one of its own structures in an engine's world, the same on every platform: the
|
||||
* dimension's {@code importedStructures} settings first, then the rule the pack's modules give the structure through
|
||||
* their vanilla structure hooks ({@link ModuleVanillaStructures}). A structure a module blocks does not generate; one a
|
||||
* module places itself is reported as replaced, so find, goto and verify locate the module's placement.
|
||||
*/
|
||||
public final class NativeStructureGenerationPolicy {
|
||||
private NativeStructureGenerationPolicy() {
|
||||
}
|
||||
@@ -38,20 +46,21 @@ public final class NativeStructureGenerationPolicy {
|
||||
dimension.getImportedStructures(),
|
||||
"Dimension importedStructures must not be null");
|
||||
IrisNativeStructureDecision decision = control.resolve(structureKey, undergroundStep);
|
||||
if (!decision.generate()) {
|
||||
// A disabled key with an active Iris placement is the "blanket-disable, re-place
|
||||
// explicitly" pattern: the placement planner ignores the disable list, so generation
|
||||
// places it — report REPLACED_BY_IRIS so find/goto/verify locate the placement.
|
||||
if (decision.status() == NativeStructureGenerationStatus.DISABLED_BY_PACK
|
||||
&& IrisStructureLocator.isPlaced(activeEngine, structureKey)) {
|
||||
return decision.withStatus(NativeStructureGenerationStatus.REPLACED_BY_IRIS);
|
||||
}
|
||||
if (decision.status() == NativeStructureGenerationStatus.INVALID_REGISTRY_KEY) {
|
||||
return decision;
|
||||
}
|
||||
if (IrisStructureLocator.suppressesVanilla(activeEngine, structureKey)) {
|
||||
return decision.withStatus(NativeStructureGenerationStatus.REPLACED_BY_IRIS);
|
||||
VanillaStructureRule modules = ModuleVanillaStructures.ruleFor(activeEngine, structureKey);
|
||||
if (!decision.generate()) {
|
||||
// A key the dimension disables that a module places is the "blanket-disable, re-place explicitly"
|
||||
// pattern: report REPLACED_BY_IRIS so find/goto/verify locate the module's placement.
|
||||
return modules.placedByModule() ? decision.withStatus(NativeStructureGenerationStatus.REPLACED_BY_IRIS) : decision;
|
||||
}
|
||||
return decision;
|
||||
if (!modules.blocksPlatform()) {
|
||||
return decision;
|
||||
}
|
||||
return decision.withStatus(modules.placedByModule()
|
||||
? NativeStructureGenerationStatus.REPLACED_BY_IRIS
|
||||
: NativeStructureGenerationStatus.DISABLED_BY_PACK);
|
||||
}
|
||||
|
||||
public static String generationStatusMessage(String structureKey,
|
||||
@@ -60,7 +69,7 @@ public final class NativeStructureGenerationPolicy {
|
||||
return switch (Objects.requireNonNull(status, "Native structure status must not be null")) {
|
||||
case GENERATE_NATIVE -> "Native structure " + key + " generates natively.";
|
||||
case DISABLED_BY_PACK -> "Native structure " + key
|
||||
+ " is disabled by this dimension's importedStructures settings.";
|
||||
+ " is disabled by this dimension's importedStructures settings or a module of the pack.";
|
||||
case REPLACED_BY_IRIS -> "Native structure " + key
|
||||
+ " is replaced by an Iris placement in this pack and locates through that explicit replacement.";
|
||||
case INVALID_REGISTRY_KEY -> "Native structure registry key is invalid: " + key;
|
||||
|
||||
@@ -20,6 +20,7 @@ package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.IrisStages;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.builtin.deposit.DepositGenerator;
|
||||
import art.arcane.iris.builtin.deposit.DepositSettings;
|
||||
import com.volmit.FeatureAttachment.Target;
|
||||
import com.volmit.IrisModule;
|
||||
@@ -98,9 +99,8 @@ public class BuiltInGenerationGraphTest {
|
||||
.findFirst().orElseThrow();
|
||||
assertEquals("deposits", deposits.alias().orElseThrow());
|
||||
ValueKind generators = deposits.shorthand().orElseThrow().kind();
|
||||
assertTrue(generators.toString(), generators instanceof ValueKind.ListKind list
|
||||
&& list.element() instanceof ValueKind.HostKind host
|
||||
&& host.type().equals("art.arcane.iris.engine.object.terrain.deposit.IrisDepositGenerator"));
|
||||
assertEquals("generators are a module class of IrisApi types, not an Iris class",
|
||||
new ValueKind.ListKind(new ValueKind.ObjectKind(DepositGenerator.class.getName()), false), generators);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,6 +67,13 @@ public final class BuiltInPack {
|
||||
return pack;
|
||||
}
|
||||
|
||||
/** {@link #serve} and the pack's resources ({@link PackResourceFixture#serve}), which a world's vanilla structure hooks read. */
|
||||
public static LoadedPack serveWithResources(IrisData data, TemporaryFolder folder, List<IrisModule> packModules) throws IOException {
|
||||
LoadedPack pack = serve(data, folder, packModules);
|
||||
PackResourceFixture.serve(data);
|
||||
return pack;
|
||||
}
|
||||
|
||||
/** Placements into a world of {@code engine} derive their seeds from its world seed. */
|
||||
public static void seedWorld(Engine engine, long seed) {
|
||||
SeedManager seeds = mock(SeedManager.class);
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.deposit.DepositBiomeScope;
|
||||
import art.arcane.iris.builtin.deposit.DepositGenerator;
|
||||
import art.arcane.iris.builtin.deposit.DepositHeightDistribution;
|
||||
import art.arcane.iris.builtin.deposit.DepositPlacementScope;
|
||||
import art.arcane.iris.builtin.deposit.DepositSettings;
|
||||
import art.arcane.iris.builtin.deposit.DepositShape;
|
||||
import art.arcane.volmlib.util.json.JSONObject;
|
||||
import com.google.gson.Gson;
|
||||
import com.volmit.FeatureAttachment.Target;
|
||||
import com.volmit.block.BlockSpec;
|
||||
import com.volmit.host.LoadedPack;
|
||||
import com.volmit.host.ModuleHost;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
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 static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* The deposits packs have always written read into {@link DepositGenerator}, a settings class of IrisApi types only,
|
||||
* with the values Iris's own deposit generator class read from the same JSON.
|
||||
*/
|
||||
public class DepositSettingsDecodingTest {
|
||||
private static final String REGION_DEPOSITS = """
|
||||
{"deposits": [
|
||||
{"minHeight": 15, "maxPerChunk": 26, "maxHeight": 410, "minPerChunk": 4, "minSize": 3, "maxSize": 8,
|
||||
"palette": [{"block": "minecraft:iron_ore"}, {"block": "minecraft:coal_ore"}], "varience": 4},
|
||||
{"heightDistribution": "TRIANGLE", "placementScope": "FULL_HEIGHT", "surfaceClearance": 0, "shape": "VANILLA_ELLIPSOID",
|
||||
"spawnChance": 0.5, "perClumpSpawnChance": 0.25, "discardChanceOnAirExposure": 0.7, "replaceableBlocks": ["stone", "deepslate"],
|
||||
"biomeScope": "SURFACE", "includedBiomes": ["plains"], "excludedBiomes": ["desert/dunes"], "replaceBedrock": true,
|
||||
"palette": [{"block": "oak_log", "data": {"axis": "y"}, "weight": 2, "backup": {"block": "stone"}}]},
|
||||
"snippet/deposit/diamonds",
|
||||
"snippet/diamonds",
|
||||
{}
|
||||
]}
|
||||
""";
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder folder = new TemporaryFolder();
|
||||
|
||||
private LoadedPack pack;
|
||||
private ModuleSettingsDecoder decoder;
|
||||
|
||||
@Before
|
||||
public void loadBuiltIns() throws IOException {
|
||||
Path packFolder = folder.newFolder("pack").toPath();
|
||||
Path snippets = Files.createDirectories(packFolder.resolve("snippet/deposit"));
|
||||
Files.writeString(snippets.resolve("diamonds.json"), "{\"maxHeight\": 16, \"palette\": [{\"block\": \"minecraft:diamond_ore\"}]}");
|
||||
pack = LoadedPack.load(packFolder, ModuleHost.of(IrisModuleHost.builtInModules())
|
||||
.describingHostTypesIn(IrisModuleHost.HOST_TYPE_PACKAGE).copyingJarsTo(folder.newFolder("copies").toPath()));
|
||||
decoder = new ModuleSettingsDecoder(pack.catalog(), packFolder, Gson::new);
|
||||
}
|
||||
|
||||
@After
|
||||
public void closePack() {
|
||||
pack.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void existingDepositJsonReadsTheValuesIrisReadFromIt() {
|
||||
List<DepositGenerator> deposits = deposits(REGION_DEPOSITS);
|
||||
|
||||
DepositGenerator ores = deposits.getFirst();
|
||||
assertEquals(15, ores.minHeight());
|
||||
assertEquals(410, ores.maxHeight());
|
||||
assertEquals(4, ores.minPerChunk());
|
||||
assertEquals(26, ores.maxPerChunk());
|
||||
assertEquals(3, ores.minSize());
|
||||
assertEquals(8, ores.maxSize());
|
||||
assertEquals(4, ores.varience());
|
||||
assertEquals(List.of(BlockSpec.of("minecraft:iron_ore"), BlockSpec.of("minecraft:coal_ore")), ores.palette());
|
||||
assertEquals(DepositHeightDistribution.CLIPPED_UNIFORM, ores.heightDistribution());
|
||||
assertEquals(DepositPlacementScope.TERRAIN, ores.placementScope());
|
||||
assertEquals(7, ores.surfaceClearance());
|
||||
assertEquals(DepositShape.IRIS, ores.shape());
|
||||
assertEquals(1, ores.spawnChance(), 0);
|
||||
assertEquals(DepositBiomeScope.CAVE, ores.biomeScope());
|
||||
assertEquals(List.of(), ores.replaceableBlocks());
|
||||
assertFalse(ores.replaceBedrock());
|
||||
assertEquals(2, ores.maxDimension());
|
||||
|
||||
DepositGenerator tuned = deposits.get(1);
|
||||
assertEquals(DepositHeightDistribution.TRIANGLE, tuned.heightDistribution());
|
||||
assertEquals(DepositPlacementScope.FULL_HEIGHT, tuned.placementScope());
|
||||
assertEquals(0, tuned.surfaceClearance());
|
||||
assertEquals(DepositShape.VANILLA_ELLIPSOID, tuned.shape());
|
||||
assertEquals(0.5, tuned.spawnChance(), 0);
|
||||
assertEquals(0.25, tuned.perClumpSpawnChance(), 0);
|
||||
assertEquals(0.7, tuned.discardChanceOnAirExposure(), 0);
|
||||
assertEquals(List.of("stone", "deepslate"), tuned.replaceableBlocks());
|
||||
assertEquals(DepositBiomeScope.SURFACE, tuned.biomeScope());
|
||||
assertEquals(List.of("plains"), tuned.includedBiomes());
|
||||
assertEquals(List.of("desert/dunes"), tuned.excludedBiomes());
|
||||
assertTrue(tuned.replaceBedrock());
|
||||
assertFalse(tuned.usesCaveBiomeFilter());
|
||||
BlockSpec log = tuned.palette().getFirst();
|
||||
assertEquals("oak_log", log.block());
|
||||
assertEquals(Map.of("axis", "y"), log.data());
|
||||
assertEquals(2, log.weight());
|
||||
assertEquals(Optional.of(BlockSpec.of("stone")), log.backup());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void snippetsReadUnderEitherReferenceForm() {
|
||||
List<DepositGenerator> deposits = deposits(REGION_DEPOSITS);
|
||||
|
||||
for (DepositGenerator diamonds : List.of(deposits.get(2), deposits.get(3))) {
|
||||
assertEquals(16, diamonds.maxHeight());
|
||||
assertEquals(1, diamonds.minHeight());
|
||||
assertEquals(List.of(BlockSpec.of("minecraft:diamond_ore")), diamonds.palette());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anEmptyGeneratorHasIrisDefaults() {
|
||||
DepositGenerator defaults = deposits(REGION_DEPOSITS).get(4);
|
||||
|
||||
assertEquals(1, defaults.minHeight());
|
||||
assertEquals(75, defaults.maxHeight());
|
||||
assertEquals(0, defaults.minSize());
|
||||
assertEquals(128, defaults.maxSize());
|
||||
assertEquals(0, defaults.minPerChunk());
|
||||
assertEquals(3, defaults.maxPerChunk());
|
||||
assertEquals(3, defaults.varience());
|
||||
assertEquals(List.of(), defaults.palette());
|
||||
assertEquals(6, defaults.maxDimension());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theFeatureIdReadsTheSameAsTheOldKey() {
|
||||
String byId = "{\"iris:deposit\": {\"generators\": [{\"maxHeight\": 16}]}}";
|
||||
|
||||
assertEquals(16, deposits(byId).getFirst().maxHeight());
|
||||
}
|
||||
|
||||
private List<DepositGenerator> deposits(String regionJson) {
|
||||
return decoder.decode(Target.REGION, new JSONObject(regionJson), "region forests")
|
||||
.find(DepositSettings.class).orElseThrow().generators();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import com.volmit.host.ModuleRegistry;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.resource.ResourceKind;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.IdentityHashMap;
|
||||
@@ -53,6 +54,20 @@ public final class ModuleResourceFixture {
|
||||
return served != null ? served : serve(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes {@code data} (a mock) a pack folder named {@code pack} whose modules are {@code modules}, as built-ins, so what
|
||||
* reads the pack's catalog (vanilla structure hooks, validators) finds their registrations.
|
||||
*/
|
||||
public static void serveModules(IrisData data, IrisModule... modules) {
|
||||
LoadedPack pack = mock(LoadedPack.class);
|
||||
PackModuleSet moduleSet = mock(PackModuleSet.class);
|
||||
FeatureCatalog catalog = catalogOf(modules);
|
||||
when(pack.catalog()).thenReturn(catalog);
|
||||
when(moduleSet.pack()).thenReturn(pack);
|
||||
when(data.getModules()).thenReturn(moduleSet);
|
||||
when(data.getDataFolder()).thenReturn(new File("pack"));
|
||||
}
|
||||
|
||||
/** The catalog of a pack with only {@code modules}, as built-ins: their resource kinds, validators and other registrations. */
|
||||
public static FeatureCatalog catalogOf(IrisModule... modules) {
|
||||
ModuleRegistry registry = new ModuleRegistry();
|
||||
|
||||
@@ -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,25 @@ 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());
|
||||
JSONObject mode = tint.getJSONObject("mode");
|
||||
assertEquals("\"SOFT\",\"HARD\"", mode.getJSONArray("enum").join(","));
|
||||
assertEquals("\"Blends into the ground\",\"\"", mode.getJSONArray("enumDescriptions").join(","));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dimensionSchemaExposesSurfaceSupportDefaults() {
|
||||
JSONObject properties = rootProperties(
|
||||
@@ -646,6 +665,40 @@ 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();
|
||||
private TintMode mode = TintMode.SOFT;
|
||||
}
|
||||
|
||||
public enum TintMode {
|
||||
@com.volmit.config.Desc("Blends into the ground") SOFT,
|
||||
HARD
|
||||
}
|
||||
|
||||
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")
|
||||
|
||||
+148
-16
@@ -1,6 +1,8 @@
|
||||
package art.arcane.iris.engine.framework;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.BuiltInPack;
|
||||
import art.arcane.iris.core.modules.IrisPackResources;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisImportedStructureControl;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructure;
|
||||
@@ -8,19 +10,47 @@ import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructureDecisi
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructurePlacement;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.NativeStructureGenerationStatus;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.NativeStructureSuppression;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import com.volmit.FeatureRegistry;
|
||||
import com.volmit.IrisModule;
|
||||
import com.volmit.ModuleInfo;
|
||||
import com.volmit.host.LoadedPack;
|
||||
import com.volmit.stage.StageGraph;
|
||||
import com.volmit.vanilla.VanillaStructureHook;
|
||||
import com.volmit.vanilla.VanillaStructureRule;
|
||||
import org.junit.After;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class NativeStructureGenerationPolicyTest {
|
||||
@Rule
|
||||
public TemporaryFolder folder = new TemporaryFolder();
|
||||
|
||||
private final List<LoadedPack> packs = new ArrayList<>();
|
||||
|
||||
@After
|
||||
public void closePacks() {
|
||||
packs.forEach(LoadedPack::close);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generationStatusMessagesAreSharedAcrossPlatforms() {
|
||||
assertEquals(
|
||||
"Native structure minecraft:village_plains is disabled by this dimension's importedStructures settings.",
|
||||
"Native structure minecraft:village_plains is disabled by this dimension's importedStructures settings or a module of the pack.",
|
||||
NativeStructureGenerationPolicy.generationStatusMessage(
|
||||
"minecraft:village_plains", NativeStructureGenerationStatus.DISABLED_BY_PACK));
|
||||
assertEquals(
|
||||
@@ -36,7 +66,7 @@ public class NativeStructureGenerationPolicyTest {
|
||||
* /iris structure verify locate the placement instead of claiming the key is disabled.
|
||||
*/
|
||||
@Test
|
||||
public void disabledKeyWithActivePlacementResolvesAsReplacedByIris() {
|
||||
public void disabledKeyWithActivePlacementResolvesAsReplacedByIris() throws IOException {
|
||||
Engine engine = engineWithDisabledNamespaceAndRegionPlacement("nova_structures:tavern_oak");
|
||||
|
||||
assertEquals(NativeStructureGenerationStatus.REPLACED_BY_IRIS,
|
||||
@@ -44,7 +74,7 @@ public class NativeStructureGenerationPolicyTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disabledKeyWithoutPlacementStaysDisabled() {
|
||||
public void disabledKeyWithoutPlacementStaysDisabled() throws IOException {
|
||||
Engine engine = engineWithDisabledNamespaceAndRegionPlacement("nova_structures:tavern_oak");
|
||||
|
||||
IrisNativeStructureDecision decision =
|
||||
@@ -54,10 +84,11 @@ public class NativeStructureGenerationPolicyTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exactDisabledKeyDoesNotDisableSiblingVariant() {
|
||||
public void exactDisabledKeyDoesNotDisableSiblingVariant() throws IOException {
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl();
|
||||
control.getDisabled().clear();
|
||||
control.getDisabledExact().add("minecraft:ruined_portal");
|
||||
Engine engine = engineWithControlAndRegionPlacement(control, "nova_structures:tavern_oak");
|
||||
Engine engine = engine(control, regionPlacement("nova_structures:tavern_oak"), new KList<>(), List.of());
|
||||
|
||||
assertEquals(NativeStructureGenerationStatus.DISABLED_BY_PACK,
|
||||
NativeStructureGenerationPolicy.resolve(engine, "minecraft:ruined_portal", false).status());
|
||||
@@ -65,32 +96,133 @@ public class NativeStructureGenerationPolicyTest {
|
||||
NativeStructureGenerationPolicy.resolve(engine, "minecraft:ruined_portal_nether", false).status());
|
||||
}
|
||||
|
||||
private Engine engineWithDisabledNamespaceAndRegionPlacement(String placedKey) {
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl();
|
||||
control.getDisabled().add("nova_structures:");
|
||||
return engineWithControlAndRegionPlacement(control, placedKey);
|
||||
/** The pilot of the vanilla structure hook: suppression now comes from the iris:structure module's rule. */
|
||||
@Test
|
||||
public void aStructureAnIrisPlacementReplacesIsBlockedByTheStructureModule() throws IOException {
|
||||
IrisStructurePlacement replacement = new IrisStructurePlacement().setNativeSuppression(NativeStructureSuppression.REPLACE_SOURCE);
|
||||
replacement.getNativeStructures().add(new IrisNativeStructure().setStructure("minecraft:village_plains"));
|
||||
KList<IrisStructurePlacement> dimensionPlacements = new KList<>();
|
||||
dimensionPlacements.add(replacement);
|
||||
Engine engine = engine(allowingEverything(), new KList<>(), dimensionPlacements, List.of());
|
||||
|
||||
IrisNativeStructureDecision decision = NativeStructureGenerationPolicy.resolve(engine, "minecraft:village_plains", false);
|
||||
assertEquals(NativeStructureGenerationStatus.REPLACED_BY_IRIS, decision.status());
|
||||
assertFalse(decision.generate());
|
||||
assertEquals(NativeStructureGenerationStatus.GENERATE_NATIVE,
|
||||
NativeStructureGenerationPolicy.resolve(engine, "minecraft:village_desert", false).status());
|
||||
}
|
||||
|
||||
private Engine engineWithControlAndRegionPlacement(IrisImportedStructureControl control, String placedKey) {
|
||||
@Test
|
||||
public void aStructureAPlacementAlsoPlacesStillGeneratesNatively() throws IOException {
|
||||
Engine engine = engine(allowingEverything(), regionPlacement("minecraft:village_plains"), new KList<>(), List.of());
|
||||
|
||||
assertTrue(NativeStructureGenerationPolicy.resolve(engine, "minecraft:village_plains", false).generate());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void packModulesBlockOrReplaceStructuresThroughTheirHooks() throws IOException {
|
||||
Engine engine = engine(allowingEverything(), new KList<>(), new KList<>(), List.of(new HookModule((structure, world) ->
|
||||
switch (structure.path()) {
|
||||
case "pillager_outpost" -> VanillaStructureRule.BLOCK;
|
||||
case "igloo" -> VanillaStructureRule.REPLACE;
|
||||
default -> VanillaStructureRule.GENERATE;
|
||||
})));
|
||||
|
||||
assertEquals(NativeStructureGenerationStatus.DISABLED_BY_PACK,
|
||||
NativeStructureGenerationPolicy.resolve(engine, "minecraft:pillager_outpost", false).status());
|
||||
assertEquals(NativeStructureGenerationStatus.REPLACED_BY_IRIS,
|
||||
NativeStructureGenerationPolicy.resolve(engine, "minecraft:igloo", false).status());
|
||||
assertEquals(NativeStructureGenerationStatus.GENERATE_NATIVE,
|
||||
NativeStructureGenerationPolicy.resolve(engine, "minecraft:mansion", false).status());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hooksAreAskedOncePerStructureAndPackSnapshot() throws IOException {
|
||||
AtomicInteger asked = new AtomicInteger();
|
||||
Engine engine = engine(allowingEverything(), new KList<>(), new KList<>(), List.of(new HookModule((structure, world) -> {
|
||||
asked.incrementAndGet();
|
||||
return VanillaStructureRule.GENERATE;
|
||||
})));
|
||||
|
||||
NativeStructureGenerationPolicy.resolve(engine, "minecraft:igloo", false);
|
||||
NativeStructureGenerationPolicy.resolve(engine, "minecraft:igloo", true);
|
||||
assertEquals(1, asked.get());
|
||||
|
||||
IrisData data = engine.getData();
|
||||
IrisPackResources reloaded = new IrisPackResources(data);
|
||||
when(data.getPackResources()).thenReturn(reloaded);
|
||||
NativeStructureGenerationPolicy.resolve(engine, "minecraft:igloo", false);
|
||||
assertEquals("a new snapshot asks again", 2, asked.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aHookThatFailsNamesItsModule() throws IOException {
|
||||
Engine engine = engine(allowingEverything(), new KList<>(), new KList<>(), List.of(new HookModule((structure, world) -> {
|
||||
throw new IllegalArgumentException("broken");
|
||||
})));
|
||||
|
||||
IllegalStateException failure = assertThrows(IllegalStateException.class,
|
||||
() -> NativeStructureGenerationPolicy.resolve(engine, "minecraft:igloo", false));
|
||||
assertTrue(failure.getMessage(), failure.getMessage().startsWith(
|
||||
"Module test:hook from host classpath failed deciding over vanilla structure minecraft:igloo: "));
|
||||
}
|
||||
|
||||
private Engine engineWithDisabledNamespaceAndRegionPlacement(String placedKey) throws IOException {
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl();
|
||||
control.getDisabled().add("nova_structures:");
|
||||
return engine(control, regionPlacement(placedKey), new KList<>(), List.of());
|
||||
}
|
||||
|
||||
private static IrisImportedStructureControl allowingEverything() {
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl();
|
||||
control.getDisabled().clear();
|
||||
control.getDisabledExact().clear();
|
||||
return control;
|
||||
}
|
||||
|
||||
private static KList<IrisStructurePlacement> regionPlacement(String placedKey) {
|
||||
IrisStructurePlacement placement = new IrisStructurePlacement();
|
||||
placement.getNativeStructures().add(new IrisNativeStructure().setStructure(placedKey));
|
||||
KList<IrisStructurePlacement> placements = new KList<>();
|
||||
placements.add(placement);
|
||||
return placements;
|
||||
}
|
||||
|
||||
/** An engine whose pack serves Iris's built-in modules and {@code packModules}, with the given structure placements. */
|
||||
private Engine engine(IrisImportedStructureControl control, KList<IrisStructurePlacement> regionPlacements,
|
||||
KList<IrisStructurePlacement> dimensionPlacements, List<IrisModule> packModules) throws IOException {
|
||||
IrisData data = mock(IrisData.class);
|
||||
Engine engine = mock(Engine.class);
|
||||
IrisDimension dimension = mock(IrisDimension.class);
|
||||
|
||||
IrisStructurePlacement placement = new IrisStructurePlacement();
|
||||
placement.getNativeStructures().add(new IrisNativeStructure().setStructure(placedKey));
|
||||
IrisRegion region = mock(IrisRegion.class);
|
||||
KList<IrisStructurePlacement> regionPlacements = new KList<>();
|
||||
regionPlacements.add(placement);
|
||||
when(region.getStructures()).thenReturn(regionPlacements);
|
||||
KList<IrisRegion> regions = new KList<>();
|
||||
regions.add(region);
|
||||
|
||||
packs.add(BuiltInPack.serveWithResources(data, folder, packModules));
|
||||
when(engine.getData()).thenReturn(data);
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
when(dimension.getImportedStructures()).thenReturn(control);
|
||||
when(dimension.getStructures()).thenReturn(new KList<>());
|
||||
when(dimension.getStructures()).thenReturn(dimensionPlacements);
|
||||
when(dimension.getAllRegions(engine)).thenReturn(regions);
|
||||
when(dimension.getReachableBiomes(engine)).thenReturn(new KList<>());
|
||||
return engine;
|
||||
}
|
||||
|
||||
/** A pack module whose only part is a vanilla structure hook. */
|
||||
private record HookModule(VanillaStructureHook hook) implements IrisModule {
|
||||
@Override
|
||||
public ModuleInfo info() {
|
||||
return ModuleInfo.of("test:hook", "Hook", "1");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void install(StageGraph graph) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(FeatureRegistry registry) {
|
||||
registry.registerVanillaStructureHook(hook);
|
||||
}
|
||||
}
|
||||
}
|
||||
+25
-4
@@ -1,13 +1,22 @@
|
||||
package art.arcane.iris.engine.framework;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.BuiltInPack;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisImportedStructureControl;
|
||||
import art.arcane.iris.engine.object.structure.vanilla.IrisNativeStructure;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructurePlacement;
|
||||
import art.arcane.iris.engine.object.structure.StructureDistribution;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import com.volmit.host.LoadedPack;
|
||||
import org.junit.After;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -19,8 +28,18 @@ import static org.mockito.Mockito.when;
|
||||
* contributes no piece volumes, so it can never veto an object placement.
|
||||
*/
|
||||
public class NativeStructureVolumeSuppressionTest {
|
||||
@Rule
|
||||
public TemporaryFolder folder = new TemporaryFolder();
|
||||
|
||||
private final List<LoadedPack> packs = new ArrayList<>();
|
||||
|
||||
@After
|
||||
public void closePacks() {
|
||||
packs.forEach(LoadedPack::close);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void packDisabledStructuresContributeNoVolumes() {
|
||||
public void packDisabledStructuresContributeNoVolumes() throws IOException {
|
||||
Engine engine = engine();
|
||||
|
||||
assertFalse(NativeStructureGenerationPolicy
|
||||
@@ -30,7 +49,7 @@ public class NativeStructureVolumeSuppressionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enabledStructuresContributeVolumes() {
|
||||
public void enabledStructuresContributeVolumes() throws IOException {
|
||||
Engine engine = engine();
|
||||
|
||||
assertTrue(NativeStructureGenerationPolicy
|
||||
@@ -51,12 +70,14 @@ public class NativeStructureVolumeSuppressionTest {
|
||||
assertTrue(NativeStructurePlacementPlanner.decisionFor(plan).generate());
|
||||
}
|
||||
|
||||
private Engine engine() {
|
||||
private Engine engine() throws IOException {
|
||||
IrisImportedStructureControl control = new IrisImportedStructureControl();
|
||||
control.getDisabled().add("minecraft:village");
|
||||
IrisDimension dimension = mock(IrisDimension.class);
|
||||
Engine engine = mock(Engine.class);
|
||||
when(engine.getData()).thenReturn(mock(IrisData.class));
|
||||
IrisData data = mock(IrisData.class);
|
||||
packs.add(BuiltInPack.serveWithResources(data, folder, List.of()));
|
||||
when(engine.getData()).thenReturn(data);
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
when(dimension.getImportedStructures()).thenReturn(control);
|
||||
when(dimension.getStructures()).thenReturn(new KList<>());
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
package art.arcane.iris.engine.modifier;
|
||||
|
||||
import art.arcane.iris.builtin.deposit.DepositSettings;
|
||||
import art.arcane.iris.engine.object.terrain.deposit.IrisDepositGenerator;
|
||||
import art.arcane.iris.builtin.deposit.DepositGenerator;
|
||||
import com.volmit.FeatureAttachment.Target;
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.config.FeatureSettings;
|
||||
@@ -35,10 +35,10 @@ public class DepositModuleTest {
|
||||
|
||||
@Test
|
||||
public void everyLevelAtTheCentreColumnStacksInLevelOrder() {
|
||||
IrisDepositGenerator dimension = new IrisDepositGenerator();
|
||||
IrisDepositGenerator region = new IrisDepositGenerator();
|
||||
IrisDepositGenerator biome = new IrisDepositGenerator();
|
||||
IrisDepositGenerator elsewhere = new IrisDepositGenerator();
|
||||
DepositGenerator dimension = new DepositGenerator();
|
||||
DepositGenerator region = new DepositGenerator();
|
||||
DepositGenerator biome = new DepositGenerator();
|
||||
DepositGenerator elsewhere = new DepositGenerator();
|
||||
FeatureSettings settings = new FeatureSettings() {
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -55,7 +55,7 @@ public class DepositModuleTest {
|
||||
assertEquals(List.of(dimension, region, biome), DepositModule.generatorsAtCentre(settings, 32, -16));
|
||||
}
|
||||
|
||||
private static FeatureSettings.Entry<DepositSettings> entry(Target level, String source, IrisDepositGenerator generator) {
|
||||
private static FeatureSettings.Entry<DepositSettings> entry(Target level, String source, DepositGenerator generator) {
|
||||
return new FeatureSettings.Entry<>(level, ResourceId.parse("pack:" + source), new DepositSettings(List.of(generator)));
|
||||
}
|
||||
}
|
||||
+12
-12
@@ -18,8 +18,8 @@
|
||||
|
||||
package art.arcane.iris.engine.modifier;
|
||||
|
||||
import art.arcane.iris.engine.object.terrain.deposit.IrisDepositHeightDistribution;
|
||||
import art.arcane.iris.engine.object.terrain.deposit.IrisDepositPlacementScope;
|
||||
import art.arcane.iris.builtin.deposit.DepositHeightDistribution;
|
||||
import art.arcane.iris.builtin.deposit.DepositPlacementScope;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
@@ -42,17 +42,17 @@ public class DepositPlacerContainmentTest {
|
||||
@Test
|
||||
public void placementScopeSeparatesTerrainFromFloatingSolids() {
|
||||
assertTrue(DepositPlacer.placementSurfaceAllows(
|
||||
IrisDepositPlacementScope.TERRAIN, 70, 80, 7));
|
||||
DepositPlacementScope.TERRAIN, 70, 80, 7));
|
||||
assertFalse(DepositPlacer.placementSurfaceAllows(
|
||||
IrisDepositPlacementScope.TERRAIN, 74, 80, 7));
|
||||
DepositPlacementScope.TERRAIN, 74, 80, 7));
|
||||
assertFalse(DepositPlacer.placementSurfaceAllows(
|
||||
IrisDepositPlacementScope.ABOVE_TERRAIN, 80, 80, 0));
|
||||
DepositPlacementScope.ABOVE_TERRAIN, 80, 80, 0));
|
||||
assertTrue(DepositPlacer.placementSurfaceAllows(
|
||||
IrisDepositPlacementScope.ABOVE_TERRAIN, 81, 80, 0));
|
||||
DepositPlacementScope.ABOVE_TERRAIN, 81, 80, 0));
|
||||
assertTrue(DepositPlacer.placementSurfaceAllows(
|
||||
IrisDepositPlacementScope.FULL_HEIGHT, 1, 80, 64));
|
||||
DepositPlacementScope.FULL_HEIGHT, 1, 80, 64));
|
||||
assertTrue(DepositPlacer.placementSurfaceAllows(
|
||||
IrisDepositPlacementScope.FULL_HEIGHT, 700, 80, 64));
|
||||
DepositPlacementScope.FULL_HEIGHT, 700, 80, 64));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -99,7 +99,7 @@ public class DepositPlacerContainmentTest {
|
||||
boolean sampledAboveBottom = false;
|
||||
for (int i = 0; i < 2_000; i++) {
|
||||
int y = DepositPlacer.sampleHeight(
|
||||
IrisDepositHeightDistribution.UNIFORM, uniform, -80, 80, 20);
|
||||
DepositHeightDistribution.UNIFORM, uniform, -80, 80, 20);
|
||||
sampledBelowBottom |= y < 0;
|
||||
sampledAboveBottom |= y > 20;
|
||||
}
|
||||
@@ -107,7 +107,7 @@ public class DepositPlacerContainmentTest {
|
||||
assertTrue(sampledBelowBottom);
|
||||
assertTrue(sampledAboveBottom);
|
||||
assertEquals(14, DepositPlacer.sampleHeight(
|
||||
IrisDepositHeightDistribution.UNIFORM, uniform, 14, 14, 10));
|
||||
DepositHeightDistribution.UNIFORM, uniform, 14, 14, 10));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -115,7 +115,7 @@ public class DepositPlacerContainmentTest {
|
||||
RNG rng = new RNG(44L);
|
||||
for (int i = 0; i < 2_000; i++) {
|
||||
int y = DepositPlacer.sampleHeight(
|
||||
IrisDepositHeightDistribution.CLIPPED_UNIFORM, rng, -80, 80, 20);
|
||||
DepositHeightDistribution.CLIPPED_UNIFORM, rng, -80, 80, 20);
|
||||
assertTrue(y >= 0);
|
||||
assertTrue(y <= 20);
|
||||
}
|
||||
@@ -130,7 +130,7 @@ public class DepositPlacerContainmentTest {
|
||||
int samples = 100_000;
|
||||
for (int i = 0; i < samples; i++) {
|
||||
int y = DepositPlacer.sampleHeight(
|
||||
IrisDepositHeightDistribution.TRIANGLE, rng, -32, 32, 32);
|
||||
DepositHeightDistribution.TRIANGLE, rng, -32, 32, 32);
|
||||
total += y;
|
||||
if (Math.abs(y) <= 4) {
|
||||
center++;
|
||||
|
||||
@@ -0,0 +1,206 @@
|
||||
package art.arcane.iris.engine.modifier;
|
||||
|
||||
import art.arcane.iris.builtin.deposit.DepositGenerator;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.ResourceLoader;
|
||||
import art.arcane.iris.core.modules.PackResourceFixture;
|
||||
import art.arcane.iris.engine.UsableBlockPlatform;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.SeedManager;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.google.gson.Gson;
|
||||
import com.volmit.config.Desc;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/** A deposit generator made ready for an engine: its clump shapes, ore tuning, replaceable blocks and biome filters. */
|
||||
public class ResolvedDepositTest {
|
||||
private static final long DEPOSIT_SEED = 41L;
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder folder = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void thePaletteResolvesThroughThePacksBlocks() throws Exception {
|
||||
UsableBlockPlatform.bind();
|
||||
try {
|
||||
IrisData data = mock(IrisData.class);
|
||||
when(data.getDataFolder()).thenReturn(folder.newFolder("pack"));
|
||||
when(data.getBlockLoader()).thenReturn(mock(ResourceLoader.class));
|
||||
PackResourceFixture.serve(data);
|
||||
Engine engine = mock(Engine.class);
|
||||
SeedManager seeds = mock(SeedManager.class);
|
||||
when(engine.getData()).thenReturn(data);
|
||||
when(engine.getSeedManager()).thenReturn(seeds);
|
||||
when(seeds.getDeposit()).thenReturn(DEPOSIT_SEED);
|
||||
|
||||
ResolvedDeposit deposit = ResolvedDeposit.of(generator("{\"minSize\": 1, \"maxSize\": 1, \"palette\": [{\"block\": \"iron_ore\"}]}"), engine);
|
||||
IrisObject clump = deposit.clump(new RNG(3));
|
||||
|
||||
List<String> keys = new java.util.ArrayList<>();
|
||||
clump.getBlocks().values().forEachRemaining(block -> keys.add(block.key()));
|
||||
assertEquals(List.of("minecraft:iron_ore"), keys);
|
||||
} finally {
|
||||
UsableBlockPlatform.unbind();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void everyDepositEnumAndValueHasSchemaDescription() throws ReflectiveOperationException {
|
||||
for (Field modelField : DepositGenerator.class.getDeclaredFields()) {
|
||||
Class<?> enumType = modelField.getType();
|
||||
if (!enumType.isEnum()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Desc typeDescription = enumType.getAnnotation(Desc.class);
|
||||
assertNotNull(enumType.getSimpleName(), typeDescription);
|
||||
assertFalse(typeDescription.value().isBlank());
|
||||
for (Object constant : enumType.getEnumConstants()) {
|
||||
String constantName = ((Enum<?>) constant).name();
|
||||
Desc constantDescription = enumType.getField(constantName).getAnnotation(Desc.class);
|
||||
assertNotNull(enumType.getSimpleName() + "." + constantName, constantDescription);
|
||||
assertFalse(constantDescription.value().isBlank());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void depositSizesScaleAndRemainWithinSchemaLimit() {
|
||||
assertEquals(8, ResolvedDeposit.scaledDepositSize(4, 2D));
|
||||
assertEquals(16, ResolvedDeposit.scaledDepositSize(8, 2D));
|
||||
assertEquals(0, ResolvedDeposit.scaledDepositSize(0, 2D));
|
||||
assertEquals(8192, ResolvedDeposit.scaledDepositSize(8192, 2D));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void biomeOreTuningDefaultsPreserveExistingGeneration() {
|
||||
IrisBiome biome = new IrisBiome();
|
||||
|
||||
assertEquals(1D, biome.getOreDepositFrequencyMultiplier(), 0D);
|
||||
assertEquals(1D, biome.getOreDepositSizeMultiplier(), 0D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clumpShapesAreBuiltOncePerSizeFromTheWorldsDepositSeed() {
|
||||
DepositGenerator generator = generator("{\"minSize\": 4, \"maxSize\": 8, \"varience\": 1}");
|
||||
ResolvedDeposit firstWorld = new ResolvedDeposit(generator, DEPOSIT_SEED, List.of(state("minecraft:granite", false)));
|
||||
ResolvedDeposit secondWorld = new ResolvedDeposit(generator, DEPOSIT_SEED + 1, List.of(state("minecraft:granite", false)));
|
||||
|
||||
assertTrue("one variant: every pick is the same shape", firstWorld.clump(new RNG(1)) == firstWorld.clump(new RNG(2)));
|
||||
assertNotEquals(firstWorld.clump(new RNG(1)).getBlocks().keys().toString(), secondWorld.clump(new RNG(1)).getBlocks().keys().toString());
|
||||
assertTrue("scaled sizes are their own shapes", firstWorld.clump(new RNG(1)) != firstWorld.clump(new RNG(1), 2D));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clumpSaltIsStableAcrossEquivalentConfigInstances() {
|
||||
ResolvedDeposit first = new ResolvedDeposit(new DepositGenerator(), DEPOSIT_SEED, List.of(state("minecraft:granite", false)));
|
||||
ResolvedDeposit second = new ResolvedDeposit(new DepositGenerator(), DEPOSIT_SEED, List.of(state("minecraft:granite", false)));
|
||||
|
||||
assertEquals(first.stableClumpSalt(), second.stableClumpSalt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clumpSaltIncludesAuthoredConfigAndPalette() {
|
||||
ResolvedDeposit granite = new ResolvedDeposit(new DepositGenerator(), DEPOSIT_SEED, List.of(state("minecraft:granite", false)));
|
||||
ResolvedDeposit andesite = new ResolvedDeposit(new DepositGenerator(), DEPOSIT_SEED, List.of(state("minecraft:andesite", false)));
|
||||
ResolvedDeposit alteredShape = new ResolvedDeposit(generator("{\"shape\": \"VANILLA_SCATTERED\"}"), DEPOSIT_SEED,
|
||||
List.of(state("minecraft:granite", false)));
|
||||
|
||||
assertEquals("the salt Iris deposits always had", 3112546198474861350L, granite.stableClumpSalt());
|
||||
assertNotEquals(granite.stableClumpSalt(), andesite.stableClumpSalt());
|
||||
assertNotEquals(granite.stableClumpSalt(), alteredShape.stableClumpSalt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onlyOreDepositPalettesReceiveBiomeTuning() {
|
||||
assertTrue(new ResolvedDeposit(new DepositGenerator(), DEPOSIT_SEED, List.of(state("minecraft:iron_ore", true))).isOre());
|
||||
assertFalse(new ResolvedDeposit(new DepositGenerator(), DEPOSIT_SEED, List.of(state("minecraft:stone", false))).isOre());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void vanillaEllipsoidSizeControlsGeometryRatherThanExactBlockCount() {
|
||||
ResolvedDeposit deposit = new ResolvedDeposit(new DepositGenerator(), DEPOSIT_SEED, List.of(state("minecraft:iron_ore", true)));
|
||||
long smallBlocks = 0L;
|
||||
long mediumBlocks = 0L;
|
||||
long largeBlocks = 0L;
|
||||
int samples = 500;
|
||||
for (int i = 0; i < samples; i++) {
|
||||
smallBlocks += deposit.vanillaEllipsoid(new RNG(i), 4).getBlocks().size();
|
||||
mediumBlocks += deposit.vanillaEllipsoid(new RNG(i), 8).getBlocks().size();
|
||||
largeBlocks += deposit.vanillaEllipsoid(new RNG(i), 17).getBlocks().size();
|
||||
}
|
||||
|
||||
assertTrue(smallBlocks > 0L);
|
||||
assertTrue(mediumBlocks > smallBlocks);
|
||||
assertTrue(largeBlocks > mediumBlocks);
|
||||
assertNotEquals(17L * samples, largeBlocks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void vanillaScatteredSizeIsAnUpperCandidateBound() {
|
||||
ResolvedDeposit deposit = new ResolvedDeposit(new DepositGenerator(), DEPOSIT_SEED, List.of(state("minecraft:iron_ore", true)));
|
||||
boolean foundEmpty = false;
|
||||
boolean foundNonEmpty = false;
|
||||
RNG rng = new RNG(991L);
|
||||
for (int i = 0; i < 200; i++) {
|
||||
int blocks = deposit.vanillaScattered(rng, 3).getBlocks().size();
|
||||
assertTrue(blocks <= 3);
|
||||
foundEmpty |= blocks == 0;
|
||||
foundNonEmpty |= blocks > 0;
|
||||
}
|
||||
|
||||
assertTrue(foundEmpty);
|
||||
assertTrue(foundNonEmpty);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void biomeFiltersAcceptResourceKeysAndVanillaDerivatives() {
|
||||
IrisBiome mountain = new IrisBiome();
|
||||
mountain.setLoadKey("custom/mountain");
|
||||
mountain.setDerivative("minecraft:stony_peaks");
|
||||
IrisBiome plains = new IrisBiome();
|
||||
plains.setLoadKey("custom/plains");
|
||||
plains.setDerivative("minecraft:plains");
|
||||
|
||||
DepositGenerator included = generator("{\"biomeScope\": \"SURFACE\", \"includedBiomes\": [\"minecraft:stony_peaks\"]}");
|
||||
ResolvedDeposit surface = new ResolvedDeposit(included, DEPOSIT_SEED, List.of());
|
||||
assertTrue(surface.matchesBiome(mountain, plains));
|
||||
assertFalse(surface.matchesBiome(plains, mountain));
|
||||
assertFalse(included.usesCaveBiomeFilter());
|
||||
|
||||
DepositGenerator excluded = generator("{\"biomeScope\": \"SURFACE\", \"excludedBiomes\": [\"custom/mountain\"]}");
|
||||
ResolvedDeposit excluding = new ResolvedDeposit(excluded, DEPOSIT_SEED, List.of());
|
||||
assertFalse(excluding.matchesBiome(mountain, plains));
|
||||
assertTrue(excluding.matchesBiome(plains, mountain));
|
||||
|
||||
assertTrue(generator("{\"excludedBiomes\": [\"custom/mountain\"]}").usesCaveBiomeFilter());
|
||||
}
|
||||
|
||||
private static DepositGenerator generator(String json) {
|
||||
return new Gson().fromJson(json, DepositGenerator.class);
|
||||
}
|
||||
|
||||
private static PlatformBlockState state(String key, boolean ore) {
|
||||
PlatformBlockState state = mock(PlatformBlockState.class);
|
||||
when(state.isOre()).thenReturn(ore);
|
||||
when(state.key()).thenReturn(key);
|
||||
return state;
|
||||
}
|
||||
}
|
||||
-186
@@ -1,186 +0,0 @@
|
||||
package art.arcane.iris.engine.object.terrain.deposit;
|
||||
|
||||
import art.arcane.iris.engine.object.material.IrisBlockData;
|
||||
import art.arcane.iris.engine.object.terrain.deposit.IrisDepositBiomeScope;
|
||||
import art.arcane.iris.engine.object.terrain.deposit.IrisDepositGenerator;
|
||||
import art.arcane.iris.engine.object.terrain.deposit.IrisDepositShape;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class IrisDepositTuningTest {
|
||||
@Test
|
||||
public void everyDepositEnumAndValueHasSchemaDescription() throws ReflectiveOperationException {
|
||||
for (Field modelField : IrisDepositGenerator.class.getDeclaredFields()) {
|
||||
Class<?> enumType = modelField.getType();
|
||||
if (!enumType.isEnum()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Desc typeDescription = enumType.getAnnotation(Desc.class);
|
||||
assertNotNull(enumType.getSimpleName(), typeDescription);
|
||||
assertFalse(typeDescription.value().isBlank());
|
||||
|
||||
Object[] constants = enumType.getEnumConstants();
|
||||
for (Object constant : constants) {
|
||||
String constantName = ((Enum<?>) constant).name();
|
||||
Desc constantDescription = enumType.getField(constantName).getAnnotation(Desc.class);
|
||||
assertNotNull(enumType.getSimpleName() + "." + constantName, constantDescription);
|
||||
assertFalse(constantDescription.value().isBlank());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void depositSizesScaleAndRemainWithinSchemaLimit() {
|
||||
assertEquals(8, IrisDepositGenerator.scaledDepositSize(4, 2D));
|
||||
assertEquals(16, IrisDepositGenerator.scaledDepositSize(8, 2D));
|
||||
assertEquals(0, IrisDepositGenerator.scaledDepositSize(0, 2D));
|
||||
assertEquals(8192, IrisDepositGenerator.scaledDepositSize(8192, 2D));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void biomeOreTuningDefaultsPreserveExistingGeneration() {
|
||||
IrisBiome biome = new IrisBiome();
|
||||
|
||||
assertEquals(1D, biome.getOreDepositFrequencyMultiplier(), 0D);
|
||||
assertEquals(1D, biome.getOreDepositSizeMultiplier(), 0D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clumpCachesAreScopedByWorldSeedAndSize() {
|
||||
IrisDepositGenerator.ClumpCacheKey firstWorld =
|
||||
new IrisDepositGenerator.ClumpCacheKey(41L, 4, 8);
|
||||
IrisDepositGenerator.ClumpCacheKey secondWorld =
|
||||
new IrisDepositGenerator.ClumpCacheKey(42L, 4, 8);
|
||||
IrisDepositGenerator.ClumpCacheKey largerVein =
|
||||
new IrisDepositGenerator.ClumpCacheKey(41L, 8, 16);
|
||||
|
||||
assertNotEquals(firstWorld, secondWorld);
|
||||
assertNotEquals(firstWorld, largerVein);
|
||||
assertEquals(firstWorld, new IrisDepositGenerator.ClumpCacheKey(41L, 4, 8));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clumpSaltIsStableAcrossEquivalentConfigInstances() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisDepositGenerator first = generatorWithState(data, false, "minecraft:granite");
|
||||
IrisDepositGenerator second = generatorWithState(data, false, "minecraft:granite");
|
||||
|
||||
assertEquals(first.stableClumpSalt(data), second.stableClumpSalt(data));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clumpSaltIncludesAuthoredConfigAndPalette() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisDepositGenerator granite = generatorWithState(data, false, "minecraft:granite");
|
||||
IrisDepositGenerator andesite = generatorWithState(data, false, "minecraft:andesite");
|
||||
IrisDepositGenerator alteredShape = generatorWithState(data, false, "minecraft:granite");
|
||||
alteredShape.setShape(IrisDepositShape.VANILLA_SCATTERED);
|
||||
|
||||
assertEquals(3112546198474861350L, granite.stableClumpSalt(data));
|
||||
assertNotEquals(granite.stableClumpSalt(data), andesite.stableClumpSalt(data));
|
||||
assertNotEquals(granite.stableClumpSalt(data), alteredShape.stableClumpSalt(data));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onlyOreDepositPalettesReceiveBiomeTuning() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisDepositGenerator oreGenerator = generatorWithState(data, true);
|
||||
IrisDepositGenerator stoneGenerator = generatorWithState(data, false);
|
||||
|
||||
assertTrue(oreGenerator.isOre(data));
|
||||
assertFalse(stoneGenerator.isOre(data));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void vanillaEllipsoidSizeControlsGeometryRatherThanExactBlockCount() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisDepositGenerator generator = generatorWithState(data, true);
|
||||
long smallBlocks = 0L;
|
||||
long mediumBlocks = 0L;
|
||||
long largeBlocks = 0L;
|
||||
int samples = 500;
|
||||
for (int i = 0; i < samples; i++) {
|
||||
smallBlocks += generator.generateVanillaEllipsoid(new RNG(i), data, 4).getBlocks().size();
|
||||
mediumBlocks += generator.generateVanillaEllipsoid(new RNG(i), data, 8).getBlocks().size();
|
||||
largeBlocks += generator.generateVanillaEllipsoid(new RNG(i), data, 17).getBlocks().size();
|
||||
}
|
||||
|
||||
assertTrue(smallBlocks > 0L);
|
||||
assertTrue(mediumBlocks > smallBlocks);
|
||||
assertTrue(largeBlocks > mediumBlocks);
|
||||
assertNotEquals(17L * samples, largeBlocks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void vanillaScatteredSizeIsAnUpperCandidateBound() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisDepositGenerator generator = generatorWithState(data, true);
|
||||
boolean foundEmpty = false;
|
||||
boolean foundNonEmpty = false;
|
||||
RNG rng = new RNG(991L);
|
||||
for (int i = 0; i < 200; i++) {
|
||||
int blocks = generator.generateVanillaScattered(rng, data, 3).getBlocks().size();
|
||||
assertTrue(blocks <= 3);
|
||||
foundEmpty |= blocks == 0;
|
||||
foundNonEmpty |= blocks > 0;
|
||||
}
|
||||
|
||||
assertTrue(foundEmpty);
|
||||
assertTrue(foundNonEmpty);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void biomeFiltersAcceptResourceKeysAndVanillaDerivatives() {
|
||||
IrisBiome mountain = new IrisBiome();
|
||||
mountain.setLoadKey("custom/mountain");
|
||||
mountain.setDerivative("minecraft:stony_peaks");
|
||||
IrisBiome plains = new IrisBiome();
|
||||
plains.setLoadKey("custom/plains");
|
||||
plains.setDerivative("minecraft:plains");
|
||||
IrisDepositGenerator generator = new IrisDepositGenerator();
|
||||
generator.setBiomeScope(IrisDepositBiomeScope.SURFACE);
|
||||
generator.getIncludedBiomes().add("minecraft:stony_peaks");
|
||||
|
||||
assertTrue(generator.matchesBiome(mountain, plains));
|
||||
assertFalse(generator.matchesBiome(plains, mountain));
|
||||
assertFalse(generator.usesCaveBiomeFilter());
|
||||
|
||||
generator.getIncludedBiomes().clear();
|
||||
generator.getExcludedBiomes().add("custom/mountain");
|
||||
assertFalse(generator.matchesBiome(mountain, plains));
|
||||
assertTrue(generator.matchesBiome(plains, mountain));
|
||||
|
||||
generator.setBiomeScope(IrisDepositBiomeScope.CAVE);
|
||||
assertTrue(generator.usesCaveBiomeFilter());
|
||||
}
|
||||
|
||||
private IrisDepositGenerator generatorWithState(IrisData data, boolean ore) {
|
||||
return generatorWithState(data, ore, ore ? "minecraft:iron_ore" : "minecraft:stone");
|
||||
}
|
||||
|
||||
private IrisDepositGenerator generatorWithState(IrisData data, boolean ore, String key) {
|
||||
IrisBlockData block = mock(IrisBlockData.class);
|
||||
PlatformBlockState state = mock(PlatformBlockState.class);
|
||||
when(block.getBlockData(data)).thenReturn(state);
|
||||
when(state.isOre()).thenReturn(ore);
|
||||
when(state.key()).thenReturn(key);
|
||||
IrisDepositGenerator generator = new IrisDepositGenerator();
|
||||
generator.getPalette().add(block);
|
||||
return generator;
|
||||
}
|
||||
}
|
||||
+3
@@ -2,6 +2,7 @@ package art.arcane.iris.util.common.director.specialhandlers;
|
||||
|
||||
import art.arcane.iris.engine.framework.structure.StructureResources;
|
||||
import art.arcane.iris.core.modules.ModuleResourceFixture;
|
||||
import art.arcane.iris.engine.mantle.components.StructureModule;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.EngineGeneration;
|
||||
@@ -106,6 +107,7 @@ public class StructureHandlerTest {
|
||||
custom.setLoadKey("iris:custom");
|
||||
IrisStructure collision = new IrisStructure();
|
||||
collision.setLoadKey("pack:collision");
|
||||
ModuleResourceFixture.serveModules(data, new StructureModule());
|
||||
ModuleResourceFixture.of(data).resource(StructureResources.STRUCTURES, "iris:custom_definition", custom);
|
||||
ModuleResourceFixture.of(data).resource(StructureResources.STRUCTURES, "iris:collision_definition", collision);
|
||||
when(engine.getData()).thenReturn(data);
|
||||
@@ -179,6 +181,7 @@ public class StructureHandlerTest {
|
||||
placements.add(editablePlacement("iris:replacement_definition"));
|
||||
placements.add(nativePlacement("minecraft:explicit", StructureDistribution.RANDOM_SPREAD, 1.0));
|
||||
|
||||
ModuleResourceFixture.serveModules(data, new StructureModule());
|
||||
ModuleResourceFixture.of(data).resource(StructureResources.STRUCTURES, "iris:editable_definition", editable);
|
||||
ModuleResourceFixture.of(data).resource(StructureResources.STRUCTURES, "iris:replacement_definition", replacement);
|
||||
when(engine.getData()).thenReturn(data);
|
||||
|
||||
Reference in new issue
Block a user