Host side for ported terrain, decorant and deposit: caverns layer, surface kind, image-map ground blocks, bottom world Y, the upper dimension, biomes' own settings, vanilla biome, ore variants, COMPLEX seed; deposit leaves the compiled-in list

This commit is contained in:
piexel committed 2026-10-12 02:01:13 +02:00
1 parent 48e328baef
commit 15a7250ffe
20 files changed
+769 -156

No files matched your search

@@ -20,12 +20,15 @@ package art.arcane.iris.core.modules;
import art.arcane.iris.core.loader.IrisRegistrant;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.object.world.biome.IrisBiome;
import com.volmit.FeatureAttachment.Target;
import com.volmit.IrisFeature;
import com.volmit.config.FeatureSettings;
import com.volmit.resource.ResourceId;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
/**
* Module settings at world columns, for one engine: the dimension's entry, then the entry of the column's
@@ -37,23 +40,45 @@ final class ChunkModuleSettings implements FeatureSettings {
private static final String REGION = "region";
private static final String BIOME = "biome";
private final Engine engine;
/** The registrants whose settings stack at a column. */
interface Levels {
IrisRegistrant dimension();
IrisRegistrant region(int worldX, int worldZ);
IrisRegistrant surfaceBiome(int worldX, int worldZ);
/** The biome a {@code BiomeSample} names by {@code id}, or null when the dimension has no such biome. */
IrisBiome biome(ResourceId id);
}
private final Levels levels;
private final PackResourceIds ids;
ChunkModuleSettings(Engine engine, PackResourceIds ids) {
this.engine = engine;
this(new EngineLevels(engine), ids);
}
ChunkModuleSettings(Levels levels, PackResourceIds ids) {
this.levels = levels;
this.ids = ids;
}
@Override
public <F extends IrisFeature> List<Entry<F>> at(Class<F> featureType, int worldX, int worldZ) {
List<Entry<F>> entries = new ArrayList<>(Target.values().length);
addEntry(entries, featureType, Target.DIMENSION, DIMENSION, engine.getDimension());
addEntry(entries, featureType, Target.REGION, REGION, engine.getRegion(worldX, worldZ));
addEntry(entries, featureType, Target.BIOME, BIOME, engine.getSurfaceBiome(worldX, worldZ));
addEntry(entries, featureType, Target.DIMENSION, DIMENSION, levels.dimension());
addEntry(entries, featureType, Target.REGION, REGION, levels.region(worldX, worldZ));
addEntry(entries, featureType, Target.BIOME, BIOME, levels.surfaceBiome(worldX, worldZ));
return entries.isEmpty() ? List.of() : List.copyOf(entries);
}
@Override
public <F extends IrisFeature> Optional<F> declaredBy(ResourceId biome, Class<F> featureType) {
IrisBiome declared = levels.biome(biome);
return declared == null ? Optional.empty() : declared.getModuleSettings().find(featureType);
}
private <F extends IrisFeature> void addEntry(List<Entry<F>> entries, Class<F> featureType, Target level, String kind,
IrisRegistrant owner) {
if (owner == null) {
@@ -62,4 +87,27 @@ final class ChunkModuleSettings implements FeatureSettings {
owner.getModuleSettings().find(featureType)
.ifPresent(value -> entries.add(new Entry<>(level, ids.of(kind, owner.getLoadKey()), value)));
}
/** The dimension, region and surface biome the engine generates a column with. */
private record EngineLevels(Engine engine) implements Levels {
@Override
public IrisRegistrant dimension() {
return engine.getDimension();
}
@Override
public IrisRegistrant region(int worldX, int worldZ) {
return engine.getRegion(worldX, worldZ);
}
@Override
public IrisRegistrant surfaceBiome(int worldX, int worldZ) {
return engine.getSurfaceBiome(worldX, worldZ);
}
@Override
public IrisBiome biome(ResourceId id) {
return ((IrisPackResources) engine.getData().getPackResources()).irisBiome(id).orElse(null);
}
}
}
@@ -100,6 +100,12 @@ final class IrisBlockRegistry implements BlockRegistry {
return specs.computeIfAbsent(spec, IrisValues::blockData);
}
@Override
public BlockState oreFor(BlockState rock, BlockState ore) {
PlatformBlockState suited = IrisPlatforms.get().registries().deepSlateOre(platformState(rock), platformState(ore));
return BlockState.parse(PlatformBlockStates.namespaced(suited.key()));
}
@Override
public boolean hasTrait(BlockState state, BlockTrait trait) {
PlatformBlockState platform = platformState(state);
@@ -59,7 +59,7 @@ final class IrisGenerationContext implements GenerationContext {
this.originX = originX;
this.originZ = originZ;
this.blocks = new BlockStateHunk(blocks, states);
this.terrain = new IrisTerrainSampler(engine, ids, originX, originZ, TERRAIN_MARGIN_BLOCKS);
this.terrain = new IrisTerrainSampler(engine, ids, originX, originZ, TERRAIN_MARGIN_BLOCKS, states);
this.settings = new ChunkModuleSettings(engine, ids);
BlockBox chunk = ApiHeights.columns(engine, originX, originZ, originX + CHUNK_WIDTH, originZ + CHUNK_WIDTH);
this.mantle = new IrisModuleMantle(chunk, mantleChunks, mantleLayers, PlannedBlocks.of(engine, chunk, mantleChunks, states));
@@ -26,7 +26,6 @@ import art.arcane.iris.engine.mantle.components.ObjectModule;
import art.arcane.iris.engine.spawn.SpawnModule;
import art.arcane.iris.engine.mantle.components.StructureModule;
import art.arcane.iris.engine.modifier.CarveModule;
import art.arcane.iris.engine.modifier.DepositModule;
import art.arcane.iris.engine.modifier.FloatingModule;
import art.arcane.iris.engine.object.placement.PlacementModules;
import art.arcane.iris.spi.IrisPlatforms;
@@ -63,7 +62,7 @@ public final class IrisModuleHost {
* {@code IrisModule/builtin-modules.txt}) instead of being compiled into Iris. A pack loads them from its {@code modules}
* folder, and {@link MissingBuiltInModules} warns when it loads none; a test keeps this equal to the jar's list.
*/
public static final List<String> JAR_MODULE_IDS = List.of("iris:post", "iris:perfection", "iris:matter");
public static final List<String> JAR_MODULE_IDS = List.of("iris:post", "iris:perfection", "iris:matter", "iris:deposit");
/** Iris's pack object model: built-in settings may hold these classes, which Iris reads and describes itself. */
public static final String HOST_TYPE_PACKAGE = "art.arcane.iris.engine.object";
private static final String[] JAR_COPY_FOLDER = {"cache", "module-jars"};
@@ -88,7 +87,7 @@ public final class IrisModuleHost {
private static List<IrisModule> generationModules() {
return List.of(new TerrainModule(), new CarveModule(), new ObjectModule(), new StructureModule(),
new FloatingModule(), new DepositModule(), new DecorantModule(), new LootModule(), new SpawnModule());
new FloatingModule(), new DecorantModule(), new LootModule(), new SpawnModule());
}
/** Iris's own log, labelled {@code [iris]}, for host code that calls module classes outside any module's stage, service or hook. */
@@ -95,6 +95,11 @@ final class IrisModuleMantle implements Mantle {
return plannedBlocks;
}
@Override
public MantleLayer<Boolean> caverns() {
return new MantleCaverns(bounds, chunks);
}
@Override
public MantleEdit edit() {
if (openEdit != null) {
@@ -240,6 +245,12 @@ final class IrisModuleMantle implements Mantle {
return plannedBlocks;
}
@Override
public MantleLayer<Boolean> caverns() {
requireOpen();
return new MantleCaverns(bounds, chunks);
}
@Override
public MantleEdit edit() {
throw new UnsupportedOperationException("Mantle edits cannot be nested; write through this edit");
@@ -192,8 +192,15 @@ public final class IrisPackResources implements PackResources {
return new Kind<>(ids, files::keys, (id, key) -> files.read(key));
}
/** Iris's own biome that {@code id}, as a {@code BiomeSample} gives it, names; for host code that reads what the biome declares. */
Optional<IrisBiome> irisBiome(ResourceId id) {
String key = irisKinds.get(PackBiome.class).keyOf(id);
return key == null ? Optional.empty() : Optional.ofNullable(data.getBiomeLoader().load(key));
}
private PackBiome biomeOf(ResourceId id, IrisBiome biome) {
return new PackBiome(id, biome.getName(), ResourceId.parse(biome.getDerivativeKey()), biome.getRarity(), idsOf(biome.getChildren()));
return new PackBiome(id, biome.getName(), ResourceId.parse(biome.getDerivativeKey()), ResourceId.parse(biome.getVanillaDerivativeKey()),
biome.getRarity(), idsOf(biome.getChildren()));
}
private PackRegion regionOf(ResourceId id, IrisRegion region) {
@@ -229,6 +236,11 @@ public final class IrisPackResources implements PackResources {
});
}
/** The pack key that has {@code id}, or null. */
String keyOf(ResourceId id) {
return keysById().get(id);
}
Optional<T> find(ResourceId id) {
T cached = built.get(id);
if (cached != null) {
@@ -105,6 +105,7 @@ public final class IrisPackWorld implements PackWorld, IrisSeed.Source {
return switch (seed) {
case BIOME -> seeds.getBiome();
case CARVE -> seeds.getCarve();
case COMPLEX -> seeds.getComplex();
case COMPONENT -> seeds.getComponent();
case DECORATOR -> seeds.getDecorator();
case DEPOSIT -> seeds.getDeposit();
@@ -24,6 +24,7 @@ import com.volmit.mantle.BlockBox;
import com.volmit.object.ObjectTransformer;
import com.volmit.placement.PlacementContext;
import com.volmit.resource.PackResources;
import com.volmit.world.BiomeKind;
import com.volmit.world.BiomeSample;
import com.volmit.world.BlockView;
import com.volmit.world.TerrainSample;
@@ -72,6 +73,16 @@ final class IrisPlacementInputs implements PlacementContext {
throw withoutEngine();
}
@Override
public BiomeKind surfaceKind(int worldX, int worldZ) {
throw withoutEngine();
}
@Override
public int minWorldY() {
throw withoutEngine();
}
@Override
public int fluidHeight() {
throw withoutEngine();
@@ -20,11 +20,17 @@ package art.arcane.iris.core.modules;
import art.arcane.iris.engine.UpperDimensionContext;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.object.world.biome.InferredType;
import art.arcane.iris.engine.object.world.biome.IrisBiome;
import art.arcane.iris.spi.PlatformBlockState;
import art.arcane.iris.util.common.data.B;
import com.volmit.block.BlockState;
import com.volmit.mantle.BlockBox;
import com.volmit.world.BiomeKind;
import com.volmit.world.BiomeSample;
import com.volmit.world.TerrainSample;
import com.volmit.world.TerrainSampler;
import com.volmit.world.UpperDimension;
import java.util.Optional;
import java.util.OptionalInt;
@@ -41,18 +47,29 @@ final class IrisTerrainSampler implements TerrainSampler {
private final Engine engine;
private final PackResourceIds ids;
private final BlockBox bounds;
private final PlatformBlockStates states;
/** The chunk at {@code originX}, {@code originZ} widened by {@code reachBlocks}, over the full world height. */
IrisTerrainSampler(Engine engine, PackResourceIds ids, int originX, int originZ, int reachBlocks) {
this(engine, ids, originX, originZ, reachBlocks, new PlatformBlockStates(B::getState));
}
/** The chunk at {@code originX}, {@code originZ} widened by {@code reachBlocks}, whose blocks convert with {@code states}. */
IrisTerrainSampler(Engine engine, PackResourceIds ids, int originX, int originZ, int reachBlocks, PlatformBlockStates states) {
this(engine, ids, originX - reachBlocks, originZ - reachBlocks,
originX + CHUNK_WIDTH_BLOCKS + reachBlocks, originZ + CHUNK_WIDTH_BLOCKS + reachBlocks);
originX + CHUNK_WIDTH_BLOCKS + reachBlocks, originZ + CHUNK_WIDTH_BLOCKS + reachBlocks, states);
}
/** Columns from the minima, inclusive, to the maxima, exclusive, over the full world height. */
IrisTerrainSampler(Engine engine, PackResourceIds ids, int minX, int minZ, int maxX, int maxZ) {
this(engine, ids, minX, minZ, maxX, maxZ, new PlatformBlockStates(B::getState));
}
private IrisTerrainSampler(Engine engine, PackResourceIds ids, int minX, int minZ, int maxX, int maxZ, PlatformBlockStates states) {
this.engine = engine;
this.ids = ids;
this.bounds = ApiHeights.columns(engine, minX, minZ, maxX, maxZ);
this.states = states;
}
@Override
@@ -104,6 +121,38 @@ final class IrisTerrainSampler implements TerrainSampler {
return OptionalInt.of(Math.max(upper.getUpperSurfaceY(worldX, worldZ), surfaceY + engine.getDimension().getUpperDimensionGap()));
}
@Override
public BiomeKind surfaceKind(int worldX, int worldZ) {
requireInside(worldX, bounds.minY(), worldZ);
return kindOf(engine.getSurfaceBiome(worldX, worldZ).getInferredType());
}
static BiomeKind kindOf(InferredType type) {
return switch (type) {
case LAND -> BiomeKind.LAND;
case SEA -> BiomeKind.SEA;
case SHORE -> BiomeKind.SHORE;
case CAVE -> BiomeKind.CAVE;
};
}
@Override
public Optional<BlockState> surfaceBlock(int worldX, int worldZ) {
requireInside(worldX, bounds.minY(), worldZ);
return Optional.ofNullable(engine.getComplex().getImageMapRuntime().sampleSurfaceBlock(worldX, worldZ)).map(states::toApi);
}
@Override
public int minWorldY() {
return engine.getMinHeight();
}
@Override
public Optional<UpperDimension> upperDimension() {
UpperDimensionContext upper = engine.getUpperContext();
return upper == null ? Optional.empty() : Optional.of(new IrisUpperDimension(engine, upper, new PackResourceIds(upper.getData().getDataFolder()), states));
}
private void requireInside(int worldX, int y, int worldZ) {
if (!bounds.contains(worldX, y, worldZ)) {
throw new IndexOutOfBoundsException("Block " + worldX + ", " + y + ", " + worldZ + " is outside the sampled area " + bounds);
@@ -0,0 +1,92 @@
/*
* 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.IrisRegistrant;
import art.arcane.iris.engine.UpperDimensionContext;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.object.world.biome.IrisBiome;
import com.volmit.block.BlockState;
import com.volmit.config.FeatureSettings;
import com.volmit.resource.PackResources;
import com.volmit.resource.ResourceId;
import com.volmit.world.UpperDimension;
import java.util.Optional;
/** The dimension Iris stacks above the one it generates, as IrisApi's {@link UpperDimension}: its own dimension, region and biome streams. */
final class IrisUpperDimension implements UpperDimension {
private final UpperDimensionContext upper;
private final PackResources resources;
private final PlatformBlockStates states;
private final ChunkModuleSettings settings;
IrisUpperDimension(Engine engine, UpperDimensionContext upper, PackResourceIds ids, PlatformBlockStates states) {
this.upper = upper;
this.resources = upper.getData().getPackResources();
this.states = states;
this.settings = new ChunkModuleSettings(new UpperLevels(upper, engine), ids);
}
@Override
public boolean isThisDimension() {
return upper.isSelfReferencing();
}
@Override
public String key() {
return upper.getDimension().getLoadKey();
}
@Override
public FeatureSettings settings() {
return settings;
}
@Override
public PackResources resources() {
return resources;
}
@Override
public Optional<BlockState> surfaceBlock(int worldX, int worldZ) {
return Optional.ofNullable(upper.getSurfaceBlock(worldX, worldZ)).map(states::toApi);
}
private record UpperLevels(UpperDimensionContext upper, Engine engine) implements ChunkModuleSettings.Levels {
@Override
public IrisRegistrant dimension() {
return upper.getDimension();
}
@Override
public IrisRegistrant region(int worldX, int worldZ) {
return upper.getUpperRegion(worldX, worldZ);
}
@Override
public IrisRegistrant surfaceBiome(int worldX, int worldZ) {
return upper.getUpperBiome(worldX, worldZ);
}
@Override
public IrisBiome biome(ResourceId id) {
return ((IrisPackResources) upper.getData().getPackResources()).irisBiome(id).orElse(null);
}
}
}
@@ -0,0 +1,141 @@
/*
* 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.volmlib.util.mantle.runtime.MantleChunk;
import art.arcane.volmlib.util.matter.Matter;
import art.arcane.volmlib.util.matter.MatterCavern;
import com.volmit.mantle.BlockBox;
import com.volmit.mantle.MantleLayer;
import com.volmit.mantle.MantleVisitor;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
/**
* The voids Iris's mantle holds for chunks to take over, IrisApi's {@link com.volmit.mantle.Mantle#caverns()}: where the cave
* planner marked a cavern in the mantle's cavern slice, whatever the cavern holds (air, fluid, lava). Stages only read them.
*/
final class MantleCaverns implements MantleLayer<Boolean> {
private static final int CHUNK_SHIFT = 4;
private static final int SECTION_SHIFT = 4;
private static final int LOCAL_MASK = 15;
private static final String READ_ONLY = "Stages read the caverns; the cave planner writes them";
private static final Comparator<Position> VISIT_ORDER = Comparator.comparingInt(Position::x)
.thenComparingInt(Position::y).thenComparingInt(Position::z);
private final BlockBox bounds;
private final IrisModuleMantle.Chunks chunks;
MantleCaverns(BlockBox bounds, IrisModuleMantle.Chunks chunks) {
this.bounds = bounds;
this.chunks = chunks;
}
@Override
public Boolean get(int x, int y, int z) {
requireInside(x, y, z);
return cavernAt(requireChunk(x >> CHUNK_SHIFT, z >> CHUNK_SHIFT), x, y, z) ? Boolean.TRUE : null;
}
@Override
public void visit(BlockBox area, MantleVisitor<Boolean> visitor) {
Objects.requireNonNull(visitor, "visitor");
requireInside(area);
for (Position carved : carvedIn(area)) {
visitor.accept(carved.x(), carved.y(), carved.z(), Boolean.TRUE);
}
}
@Override
public void set(int x, int y, int z, Boolean value) {
throw new UnsupportedOperationException(READ_ONLY);
}
@Override
public void remove(int x, int y, int z) {
throw new UnsupportedOperationException(READ_ONLY);
}
@Override
public void clear(BlockBox area) {
throw new UnsupportedOperationException(READ_ONLY);
}
/** The carved positions in {@code area}, ordered by x, then y, then z, as {@link MantleLayer#visit} promises. */
private List<Position> carvedIn(BlockBox area) {
List<Position> carved = new ArrayList<>();
for (int chunkX = area.minX() >> CHUNK_SHIFT; chunkX <= (area.maxX() - 1) >> CHUNK_SHIFT; chunkX++) {
for (int chunkZ = area.minZ() >> CHUNK_SHIFT; chunkZ <= (area.maxZ() - 1) >> CHUNK_SHIFT; chunkZ++) {
collect(chunkX, chunkZ, area, carved);
}
}
carved.sort(VISIT_ORDER);
return carved;
}
private void collect(int chunkX, int chunkZ, BlockBox area, List<Position> carved) {
int originX = chunkX << CHUNK_SHIFT;
int originZ = chunkZ << CHUNK_SHIFT;
requireChunk(chunkX, chunkZ).iterate(MatterCavern.class, (localX, y, localZ, cavern) -> {
int x = originX + localX;
int z = originZ + localZ;
if (cavern != null && area.contains(x, y, z)) {
carved.add(new Position(x, y, z));
}
});
}
private static boolean cavernAt(MantleChunk<Matter> chunk, int x, int y, int z) {
int section = y >> SECTION_SHIFT;
if (!chunk.exists(section)) {
return false;
}
Matter matter = chunk.get(section);
if (matter == null || !matter.hasSlice(MatterCavern.class)) {
return false;
}
return matter.<MatterCavern>getSlice(MatterCavern.class).get(x & LOCAL_MASK, y & LOCAL_MASK, z & LOCAL_MASK) != null;
}
private MantleChunk<Matter> requireChunk(int chunkX, int chunkZ) {
MantleChunk<Matter> chunk = chunks.chunk(chunkX, chunkZ);
if (chunk == null) {
throw new IllegalStateException("Mantle chunk " + chunkX + ", " + chunkZ + " is inside " + bounds + " but was not prepared");
}
return chunk;
}
private void requireInside(int x, int y, int z) {
if (!bounds.contains(x, y, z)) {
throw new IndexOutOfBoundsException("Block " + x + ", " + y + ", " + z + " is outside the mantle this invocation prepared, " + bounds);
}
}
private void requireInside(BlockBox area) {
Objects.requireNonNull(area, "area");
if (!bounds.contains(area)) {
throw new IndexOutOfBoundsException("Area " + area + " is not inside the mantle this invocation prepared, " + bounds);
}
}
private record Position(int x, int y, int z) {
}
}
@@ -70,6 +70,11 @@ final class PlacementMantle implements Mantle, AutoCloseable {
return new StoredRange<>(placement.blocks());
}
@Override
public MantleLayer<Boolean> caverns() {
return new StoredRange<>(placement.caverns());
}
@Override
public MantleEdit edit() {
throw new UnsupportedOperationException("The placement owns the mantle edit; write through layer()");
@@ -35,7 +35,8 @@ final class StageMetrics implements StageTimings {
private static final double NANOS_PER_MILLISECOND = 1_000_000D;
private static final Map<String, Function<EngineMetrics, AtomicRollingSequence>> NAMED = Map.of(
"iris:post/smooth", EngineMetrics::getPost,
"iris:perfection/surface", EngineMetrics::getPerfection);
"iris:perfection/surface", EngineMetrics::getPerfection,
"iris:deposit/ores", EngineMetrics::getDeposit);
private final EngineMetrics metrics;
@@ -21,6 +21,7 @@ package art.arcane.iris.core.modules;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.framework.SeedManager;
import art.arcane.iris.engine.modifier.DepositModule;
import art.arcane.iris.engine.modifier.MatterModule;
import art.arcane.iris.engine.modifier.PerfectionModule;
import art.arcane.iris.engine.modifier.PostModule;
@@ -51,7 +52,7 @@ public final class BuiltInPack {
* with Iris; {@code BuiltInModulesJarTest} loads the same modules from the jar instead.
*/
public static List<IrisModule> jarModules() {
return List.of(new PostModule(), new PerfectionModule(), new MatterModule());
return List.of(new PostModule(), new PerfectionModule(), new MatterModule(), new DepositModule());
}
/** Every built-in module: Iris's own and the compiled-in copies of the jar's ({@link #jarModules()}). */
@@ -41,14 +41,15 @@ public class IrisWorldFacadesTest {
SeedManager seeds = mock(SeedManager.class);
when(seeds.getBiome()).thenReturn(1L);
when(seeds.getCarve()).thenReturn(2L);
when(seeds.getComponent()).thenReturn(3L);
when(seeds.getDecorator()).thenReturn(4L);
when(seeds.getDeposit()).thenReturn(5L);
when(seeds.getEntity()).thenReturn(6L);
when(seeds.getLoot()).thenReturn(7L);
when(seeds.getMantle()).thenReturn(8L);
when(seeds.getPost()).thenReturn(9L);
when(seeds.getTerrain()).thenReturn(10L);
when(seeds.getComplex()).thenReturn(3L);
when(seeds.getComponent()).thenReturn(4L);
when(seeds.getDecorator()).thenReturn(5L);
when(seeds.getDeposit()).thenReturn(6L);
when(seeds.getEntity()).thenReturn(7L);
when(seeds.getLoot()).thenReturn(8L);
when(seeds.getMantle()).thenReturn(9L);
when(seeds.getPost()).thenReturn(10L);
when(seeds.getTerrain()).thenReturn(11L);
Engine engine = engine(new IrisDimension());
when(engine.getSeedManager()).thenReturn(seeds);
PackWorld world = new IrisPackWorld(engine);
@@ -65,6 +65,7 @@ import com.volmit.config.FeatureSettings.Entry;
import com.volmit.resource.ResourceKey;
import com.volmit.stage.Pipeline;
import com.volmit.stage.StageGraph;
import com.volmit.world.BiomeKind;
import com.volmit.world.BiomeSample;
import com.volmit.world.BlockPosition;
import com.volmit.world.PackWorld;
@@ -74,6 +75,7 @@ import com.volmit.world.TerrainSampler;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -93,7 +95,10 @@ public final class ApiChunk implements GenerationContext {
public static final int WIDTH = 16;
public static final BlockState AIR = new BlockState("minecraft:air");
private static final long SEED = 1337L;
/** A key that the fixture's pack has no block for. */
public static final String UNKNOWN_BLOCK = "unknown_block";
private static final ResourceId DIMENSION = ResourceId.parse("test:dimension/overworld");
private static final ResourceId REGION = ResourceId.parse("test:region/plains");
private static final ResourceId BIOME = ResourceId.parse("test:biome/plains");
private static final int TERRAIN_MARGIN = 16;
private static final Set<String> AIRS = Set.of("minecraft:air", "minecraft:cave_air", "minecraft:void_air");
@@ -112,8 +117,13 @@ public final class ApiChunk implements GenerationContext {
private final ArrayHunk<BlockState> blocks;
private final Map<BlockPosition, BlockState> planned = new HashMap<>();
private final World world = new World();
private final Set<BlockPosition> carved = new HashSet<>();
private final List<IrisFeature> dimensionSettings = new ArrayList<>();
private final List<IrisFeature> regionSettings = new ArrayList<>();
private final List<IrisFeature> biomeSettings = new ArrayList<>();
private BiomeSample biomeSample;
private BiomeKind surfaceKind = BiomeKind.LAND;
private int minWorldY;
private IntBinaryOperator surface = (x, z) -> 0;
private IntBinaryOperator upperDimension;
private double slope;
@@ -151,6 +161,53 @@ public final class ApiChunk implements GenerationContext {
return this;
}
/** The biomes every column and cave position of the chunk has. */
public ApiChunk biomes(ResourceId surfaceBiome, ResourceId caveBiome) {
this.biomeSample = new BiomeSample(ResourceId.parse("test:region/plains"), surfaceBiome, Optional.ofNullable(caveBiome));
return this;
}
/** What the surface biome of every column is generated as. */
public ApiChunk surfaceKind(BiomeKind kind) {
this.surfaceKind = kind;
return this;
}
/** The Y in the world of the dimension's bottom. */
public ApiChunk minWorldY(int minWorldY) {
this.minWorldY = minWorldY;
return this;
}
/** A void the mantle carved, in world coordinates. */
public ApiChunk carve(int x, int y, int z) {
carved.add(new BlockPosition(x, y, z));
return this;
}
/** Settings the dimension declares. */
public ApiChunk dimensionSettings(IrisFeature... settings) {
dimensionSettings.addAll(List.of(settings));
return this;
}
/** Settings every region of the chunk declares. */
public ApiChunk regionSettings(IrisFeature... settings) {
regionSettings.addAll(List.of(settings));
return this;
}
/** Settings every surface biome of the chunk declares. */
public ApiChunk biomeSettings(IrisFeature... settings) {
biomeSettings.addAll(List.of(settings));
return this;
}
/** The blocks the fixture's pack knows, by the rule in {@link Blocks}. */
public static BlockRegistry blocks() {
return new Blocks();
}
/** A block a placement planned in the mantle, in world coordinates. */
public ApiChunk plan(int x, int y, int z, BlockState block) {
planned.put(new BlockPosition(x, y, z), block);
@@ -197,9 +254,9 @@ public final class ApiChunk implements GenerationContext {
return TestSettings.with(new PaletteLayer(), "palette", List.of(BlockSpec.of(block.key())), "slopeCondition", slope);
}
/** Empty stand-ins for the built-in stages the ported modules order after: carving and floating islands. */
/** Empty stand-ins for the built-in stages the ported modules order after: terrain, carving and floating islands. */
public static List<IrisModule> standIns() {
return List.of(new CarveStandIn(), new FloatingStandIn());
return List.of(new TerrainStandIn(), new CarveStandIn(), new FloatingStandIn());
}
/** Runs {@code modules} as a pack's chunk graph, with the {@link #standIns()}. */
@@ -242,6 +299,7 @@ public final class ApiChunk implements GenerationContext {
public <F extends IrisFeature> List<Entry<F>> at(Class<F> featureType, int worldX, int worldZ) {
List<Entry<F>> entries = new ArrayList<>();
addEntries(entries, featureType, Target.DIMENSION, DIMENSION, dimensionSettings);
addEntries(entries, featureType, Target.REGION, REGION, regionSettings);
addEntries(entries, featureType, Target.BIOME, BIOME, biomeSettings);
return entries;
}
@@ -302,7 +360,21 @@ public final class ApiChunk implements GenerationContext {
@Override
public BiomeSample biome(int worldX, int y, int worldZ) {
throw new UnsupportedOperationException("The ported built-ins read biomes through their settings");
if (biomeSample == null) {
throw new UnsupportedOperationException("The ported built-ins read biomes through their settings");
}
return biomeSample;
}
@Override
public BiomeKind surfaceKind(int worldX, int worldZ) {
requireInside(worldX, worldZ);
return surfaceKind;
}
@Override
public int minWorldY() {
return minWorldY;
}
@Override
@@ -339,6 +411,11 @@ public final class ApiChunk implements GenerationContext {
return new PlannedLayer();
}
@Override
public MantleLayer<Boolean> caverns() {
return new CarvedLayer();
}
@Override
public MantleEdit edit() {
throw new UnsupportedOperationException("Chunk stages do not edit the mantle");
@@ -381,8 +458,41 @@ public final class ApiChunk implements GenerationContext {
}
}
private final class CarvedLayer implements MantleLayer<Boolean> {
@Override
public Boolean get(int x, int y, int z) {
return carved.contains(new BlockPosition(x, y, z)) ? Boolean.TRUE : null;
}
@Override
public void set(int x, int y, int z, Boolean value) {
throw new UnsupportedOperationException("Caverns are read-only");
}
@Override
public void remove(int x, int y, int z) {
throw new UnsupportedOperationException("Caverns are read-only");
}
@Override
public void visit(BlockBox area, MantleVisitor<Boolean> visitor) {
List<BlockPosition> positions = new ArrayList<>(carved);
positions.sort(VISIT_ORDER);
for (BlockPosition position : positions) {
if (area.contains(position.x(), position.y(), position.z())) {
visitor.accept(position.x(), position.y(), position.z(), Boolean.TRUE);
}
}
}
@Override
public void clear(BlockBox area) {
throw new UnsupportedOperationException("Caverns are read-only");
}
}
/** A world of the chunk: its pack's blocks, a state store and Iris's seeds, each the world seed plus its place. */
private static final class World implements PackWorld, IrisSeed.Source {
private final class World implements PackWorld, IrisSeed.Source {
private final Resources resources = new Resources();
private final Map<Class<?>, Object> states = new HashMap<>();
@@ -398,7 +508,16 @@ public final class ApiChunk implements GenerationContext {
@Override
public PackSettings settings() {
throw new UnsupportedOperationException("No pack settings here");
return new PackSettings() {
@Override
public <F extends IrisFeature> List<Entry<F>> declared(Class<F> featureType) {
List<Entry<F>> entries = new ArrayList<>();
addEntries(entries, featureType, Target.DIMENSION, DIMENSION, dimensionSettings);
addEntries(entries, featureType, Target.REGION, REGION, regionSettings);
addEntries(entries, featureType, Target.BIOME, BIOME, biomeSettings);
return entries;
}
};
}
@Override
@@ -473,7 +592,10 @@ public final class ApiChunk implements GenerationContext {
private static final class Blocks implements BlockRegistry {
@Override
public BlockState resolve(String key) {
return BlockState.parse(key);
if (key.contains(UNKNOWN_BLOCK)) {
throw new IllegalArgumentException("Unknown block: " + key);
}
return BlockState.parse(key.contains(":") ? key : "minecraft:" + key);
}
@Override
@@ -510,6 +632,7 @@ public final class ApiChunk implements GenerationContext {
case FOLIAGE -> FOLIAGE.contains(material);
case DECORATION -> DECORATIONS.contains(material);
case VINE -> vine;
case ORE -> material.endsWith("_ore");
default -> false;
};
}
@@ -535,6 +658,19 @@ public final class ApiChunk implements GenerationContext {
}
}
private static final class TerrainStandIn implements IrisModule {
@Override
public ModuleInfo info() {
return ModuleInfo.of("iris:terrain", "Terrain stand-in", "test");
}
@Override
public void install(StageGraph graph) {
graph.define(IrisStages.Terrain.SHAPE).run(context -> {
});
}
}
private static final class CarveStandIn implements IrisModule {
@Override
public ModuleInfo info() {
@@ -20,8 +20,10 @@ package art.arcane.iris.engine.modifier;
import art.arcane.iris.builtin.deposit.DepositSettings;
import art.arcane.iris.builtin.deposit.DepositGenerator;
import art.arcane.iris.engine.object.TestSettings;
import com.volmit.FeatureAttachment.Target;
import com.volmit.IrisFeature;
import com.volmit.block.BlockState;
import com.volmit.config.FeatureSettings;
import com.volmit.resource.ResourceId;
import org.junit.Test;
@@ -29,6 +31,8 @@ import org.junit.Test;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class DepositModuleTest {
private static final int CENTRE = 7;
@@ -58,4 +62,122 @@ public class DepositModuleTest {
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)));
}
private static final int HEIGHT = 128;
private static final int GROUND = 80;
private static final BlockState STONE = new BlockState("minecraft:stone");
@Test
public void aDimensionsDepositsReplaceStoneInsideTheirBandAndNothingElse() {
ApiChunk chunk = groundedChunk()
.dimensionSettings(depositsOf("{\"minHeight\": 10, \"maxHeight\": 40, \"minSize\": 6, \"maxSize\": 6, \"minPerChunk\": 4, \"maxPerChunk\": 4,"
+ " \"varience\": 1, \"palette\": [{\"block\": \"iron_ore\"}], \"replaceableBlocks\": [\"stone\"]}"));
chunk.set(8, 20, 8, new BlockState("minecraft:dirt"));
chunk.generate(new DepositModule());
int ores = countOf(chunk, new BlockState("minecraft:iron_ore"));
assertTrue("some ore was placed: " + ores, ores > 0);
assertEquals("the dirt is not stone", new BlockState("minecraft:dirt"), chunk.get(8, 20, 8));
for (int x = 0; x < ApiChunk.WIDTH; x++) {
for (int z = 0; z < ApiChunk.WIDTH; z++) {
for (int y = 0; y < HEIGHT; y++) {
if (chunk.get(x, y, z).equals(new BlockState("minecraft:iron_ore"))) {
assertTrue("ore at " + y + " is below the ground and inside the band's reach", y <= GROUND - 7);
}
}
}
}
}
@Test
public void depositsAreTheSameWheneverTheSameChunkIsGenerated() {
DepositSettings deposits = depositsOf("{\"minHeight\": 10, \"maxHeight\": 60, \"minSize\": 3, \"maxSize\": 9, \"minPerChunk\": 3, \"maxPerChunk\": 6,"
+ " \"palette\": [{\"block\": \"coal_ore\"}, {\"block\": \"iron_ore\"}]}");
ApiChunk first = groundedChunk().dimensionSettings(deposits);
ApiChunk second = groundedChunk().dimensionSettings(deposits);
first.generate(new DepositModule());
second.generate(new DepositModule());
for (int x = 0; x < ApiChunk.WIDTH; x++) {
for (int y = 0; y < HEIGHT; y++) {
for (int z = 0; z < ApiChunk.WIDTH; z++) {
assertEquals(x + " " + y + " " + z, first.get(x, y, z), second.get(x, y, z));
}
}
}
assertTrue(countOf(first, new BlockState("minecraft:coal_ore")) + countOf(first, new BlockState("minecraft:iron_ore")) > 0);
}
@Test
public void depositsLeaveCarvedVoidsAlone() {
DepositSettings deposits = depositsOf("{\"minHeight\": 10, \"maxHeight\": 60, \"minSize\": 40, \"maxSize\": 40, \"minPerChunk\": 6, \"maxPerChunk\": 6,"
+ " \"palette\": [{\"block\": \"iron_ore\"}]}");
ApiChunk free = groundedChunk().dimensionSettings(deposits);
ApiChunk carved = groundedChunk().dimensionSettings(deposits);
for (int x = 0; x < ApiChunk.WIDTH; x++) {
for (int z = 0; z < ApiChunk.WIDTH; z++) {
for (int y = 20; y < 40; y++) {
carved.carve(32 + x, y, -16 + z);
}
}
}
free.generate(new DepositModule());
carved.generate(new DepositModule());
assertTrue(countBetween(free, 20, 40) > 0);
assertEquals(0, countBetween(carved, 20, 40));
assertTrue("above and below the voids the same deposits grow", countBetween(carved, 0, 20) + countBetween(carved, 40, HEIGHT) > 0);
}
@Test
public void aChunkWithoutDepositsAtItsCentreIsLeftAlone() {
ApiChunk chunk = groundedChunk();
chunk.generate(new DepositModule());
assertEquals(0, countOf(chunk, new BlockState("minecraft:iron_ore")));
}
private static ApiChunk groundedChunk() {
ApiChunk chunk = new ApiChunk(32, -16, HEIGHT).surface((x, z) -> GROUND);
for (int x = 0; x < ApiChunk.WIDTH; x++) {
for (int z = 0; z < ApiChunk.WIDTH; z++) {
for (int y = 0; y <= GROUND; y++) {
chunk.set(x, y, z, STONE);
}
}
}
return chunk;
}
private static DepositSettings depositsOf(String generatorJson) {
return TestSettings.of(DepositSettings.class, "{\"generators\": [" + generatorJson + "]}");
}
private static int countOf(ApiChunk chunk, BlockState block) {
int count = 0;
for (int x = 0; x < ApiChunk.WIDTH; x++) {
for (int y = 0; y < HEIGHT; y++) {
for (int z = 0; z < ApiChunk.WIDTH; z++) {
count += chunk.get(x, y, z).equals(block) ? 1 : 0;
}
}
}
return count;
}
private static int countBetween(ApiChunk chunk, int from, int to) {
int count = 0;
for (int x = 0; x < ApiChunk.WIDTH; x++) {
for (int y = from; y < to; y++) {
for (int z = 0; z < ApiChunk.WIDTH; z++) {
count += chunk.get(x, y, z).equals(new BlockState("minecraft:iron_ore")) ? 1 : 0;
}
}
}
return count;
}
}
@@ -20,16 +20,19 @@ package art.arcane.iris.engine.modifier;
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;
import com.volmit.block.BlockRegistry;
import com.volmit.block.BlockState;
import com.volmit.block.BlockTrait;
import com.volmit.host.ArrayHunk;
import com.volmit.hunk.Hunk;
import org.junit.Test;
import java.util.function.Predicate;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class DepositPlacerContainmentTest {
@Test
@@ -63,16 +66,12 @@ public class DepositPlacerContainmentTest {
@Test
public void airAndFluidTargetsAreRejected() {
PlatformBlockState solid = mock(PlatformBlockState.class);
PlatformBlockState air = mock(PlatformBlockState.class);
PlatformBlockState fluid = mock(PlatformBlockState.class);
when(air.isAir()).thenReturn(true);
when(fluid.isFluid()).thenReturn(true);
BlockRegistry blocks = ApiChunk.blocks();
assertTrue(DepositPlacer.canReplaceDepositTarget(solid));
assertFalse(DepositPlacer.canReplaceDepositTarget(air));
assertFalse(DepositPlacer.canReplaceDepositTarget(fluid));
assertFalse(DepositPlacer.canReplaceDepositTarget(null));
assertTrue(DepositPlacer.canReplaceDepositTarget(blocks, new BlockState("minecraft:stone")));
assertFalse(DepositPlacer.canReplaceDepositTarget(blocks, ApiChunk.AIR));
assertFalse(DepositPlacer.canReplaceDepositTarget(blocks, new BlockState("minecraft:water")));
assertFalse(DepositPlacer.canReplaceDepositTarget(blocks, null));
}
@Test
@@ -155,21 +154,13 @@ public class DepositPlacerContainmentTest {
@Test
public void exposureProbeChecksOnlyInBoundsOrthogonalNeighbors() {
Hunk<PlatformBlockState> data = Hunk.newHunk(3, 3, 3);
PlatformBlockState solid = mock(PlatformBlockState.class);
PlatformBlockState air = mock(PlatformBlockState.class);
when(air.isAir()).thenReturn(true);
for (int x = 0; x < 3; x++) {
for (int y = 0; y < 3; y++) {
for (int z = 0; z < 3; z++) {
data.setRaw(x, y, z, solid);
}
}
}
BlockRegistry blocks = ApiChunk.blocks();
Hunk<BlockState> data = new ArrayHunk<>(BlockState.class, 3, 3, 3, new BlockState("minecraft:stone"));
Predicate<BlockState> isAir = state -> blocks.hasTrait(state, BlockTrait.AIR);
assertFalse(DepositPlacer.isAdjacentToAir(data, 1, 1, 1));
data.setRaw(2, 1, 1, air);
assertTrue(DepositPlacer.isAdjacentToAir(data, 1, 1, 1));
assertFalse(DepositPlacer.isAdjacentToAir(data, 0, 0, 0));
assertFalse(DepositPlacer.isAdjacentToAir(data, 1, 1, 1, isAir));
data.set(2, 1, 1, ApiChunk.AIR);
assertTrue(DepositPlacer.isAdjacentToAir(data, 1, 1, 1, isAir));
assertFalse(DepositPlacer.isAdjacentToAir(data, 0, 0, 0, isAir));
}
}
@@ -3,21 +3,12 @@ package art.arcane.iris.engine.modifier;
import art.arcane.iris.builtin.deposit.DepositGenerator;
import art.arcane.iris.builtin.deposit.OreFrequencySettings;
import art.arcane.iris.builtin.deposit.OreSizeSettings;
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.iris.engine.modifier.ResolvedDeposit.BiomeIdentity;
import art.arcane.volmlib.util.math.RNG;
import com.google.gson.Gson;
import com.volmit.block.BlockRegistry;
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;
@@ -27,40 +18,21 @@ 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();
private static final BlockRegistry BLOCKS = ApiChunk.blocks();
@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);
public void thePaletteResolvesThroughThePacksBlocks() {
ResolvedDeposit deposit = new ResolvedDeposit(generator("{\"minSize\": 1, \"maxSize\": 1, \"palette\": [{\"block\": \"iron_ore\"}]}"), DEPOSIT_SEED, BLOCKS);
DepositClump clump = deposit.clump(new RNG(3));
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();
}
List<String> keys = new java.util.ArrayList<>();
clump.blocks().values().forEachRemaining(block -> keys.add(block.key()));
assertEquals(List.of("minecraft:iron_ore"), keys);
}
@Test
@@ -100,28 +72,27 @@ public class ResolvedDepositTest {
@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)));
ResolvedDeposit firstWorld = new ResolvedDeposit(withPalette(generator, "granite"), DEPOSIT_SEED, BLOCKS);
ResolvedDeposit secondWorld = new ResolvedDeposit(withPalette(generator, "granite"), DEPOSIT_SEED + 1, BLOCKS);
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());
assertNotEquals(firstWorld.clump(new RNG(1)).blocks().keys().toString(), secondWorld.clump(new RNG(1)).blocks().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)));
ResolvedDeposit first = new ResolvedDeposit(withPalette(new DepositGenerator(), "granite"), DEPOSIT_SEED, BLOCKS);
ResolvedDeposit second = new ResolvedDeposit(withPalette(new DepositGenerator(), "granite"), DEPOSIT_SEED, BLOCKS);
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)));
ResolvedDeposit granite = new ResolvedDeposit(withPalette(new DepositGenerator(), "granite"), DEPOSIT_SEED, BLOCKS);
ResolvedDeposit andesite = new ResolvedDeposit(withPalette(new DepositGenerator(), "andesite"), DEPOSIT_SEED, BLOCKS);
ResolvedDeposit alteredShape = new ResolvedDeposit(withPalette(generator("{\"shape\": \"VANILLA_SCATTERED\"}"), "granite"), DEPOSIT_SEED, BLOCKS);
assertEquals("the salt Iris deposits always had", 3112546198474861350L, granite.stableClumpSalt());
assertNotEquals(granite.stableClumpSalt(), andesite.stableClumpSalt());
@@ -130,21 +101,21 @@ public class ResolvedDepositTest {
@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());
assertTrue(new ResolvedDeposit(withPalette(new DepositGenerator(), "iron_ore"), DEPOSIT_SEED, BLOCKS).isOre());
assertFalse(new ResolvedDeposit(withPalette(new DepositGenerator(), "stone"), DEPOSIT_SEED, BLOCKS).isOre());
}
@Test
public void vanillaEllipsoidSizeControlsGeometryRatherThanExactBlockCount() {
ResolvedDeposit deposit = new ResolvedDeposit(new DepositGenerator(), DEPOSIT_SEED, List.of(state("minecraft:iron_ore", true)));
ResolvedDeposit deposit = new ResolvedDeposit(withPalette(new DepositGenerator(), "iron_ore"), DEPOSIT_SEED, BLOCKS);
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();
smallBlocks += deposit.vanillaEllipsoid(new RNG(i), 4).blocks().size();
mediumBlocks += deposit.vanillaEllipsoid(new RNG(i), 8).blocks().size();
largeBlocks += deposit.vanillaEllipsoid(new RNG(i), 17).blocks().size();
}
assertTrue(smallBlocks > 0L);
@@ -155,12 +126,12 @@ public class ResolvedDepositTest {
@Test
public void vanillaScatteredSizeIsAnUpperCandidateBound() {
ResolvedDeposit deposit = new ResolvedDeposit(new DepositGenerator(), DEPOSIT_SEED, List.of(state("minecraft:iron_ore", true)));
ResolvedDeposit deposit = new ResolvedDeposit(withPalette(new DepositGenerator(), "iron_ore"), DEPOSIT_SEED, BLOCKS);
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();
int blocks = deposit.vanillaScattered(rng, 3).blocks().size();
assertTrue(blocks <= 3);
foundEmpty |= blocks == 0;
foundNonEmpty |= blocks > 0;
@@ -172,35 +143,59 @@ public class ResolvedDepositTest {
@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");
BiomeIdentity mountain = new BiomeIdentity("custom/mountain", "minecraft:stony_peaks", "minecraft:stony_peaks");
BiomeIdentity plains = new BiomeIdentity("custom/plains", "minecraft:plains", "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));
ResolvedDeposit surface = new ResolvedDeposit(included, DEPOSIT_SEED, BLOCKS);
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));
ResolvedDeposit excluding = new ResolvedDeposit(excluded, DEPOSIT_SEED, BLOCKS);
assertFalse(excluding.matchesBiome(() -> mountain, () -> plains));
assertTrue(excluding.matchesBiome(() -> plains, () -> mountain));
assertTrue(generator("{\"excludedBiomes\": [\"custom/mountain\"]}").usesCaveBiomeFilter());
}
@Test
public void aBiomeThatIsNoneMatchesNoKey() {
ResolvedDeposit including = new ResolvedDeposit(generator("{\"biomeScope\": \"CAVE\", \"includedBiomes\": [\"carving/drip\"]}"), DEPOSIT_SEED, BLOCKS);
ResolvedDeposit excluding = new ResolvedDeposit(generator("{\"biomeScope\": \"CAVE\", \"excludedBiomes\": [\"carving/drip\"]}"), DEPOSIT_SEED, BLOCKS);
assertFalse(including.matchesBiome(() -> null, () -> null));
assertTrue(excluding.matchesBiome(() -> null, () -> null));
}
@Test
public void noFilterAsksNoBiome() {
ResolvedDeposit unfiltered = new ResolvedDeposit(new DepositGenerator(), DEPOSIT_SEED, BLOCKS);
assertTrue(unfiltered.matchesBiome(() -> {
throw new AssertionError("The surface biome is asked for only when a filter reads it");
}, () -> {
throw new AssertionError("The cave biome is asked for only when a filter reads it");
}));
}
@Test
public void onlyTheBlocksTheServerKnowsAreReplaceable() {
ResolvedDeposit deposit = new ResolvedDeposit(generator("{\"replaceableBlocks\": [\"stone\", \"" + ApiChunk.UNKNOWN_BLOCK + "\"]}"), DEPOSIT_SEED, BLOCKS);
assertTrue(deposit.canReplace(new com.volmit.block.BlockState("minecraft:stone")));
assertFalse(deposit.canReplace(new com.volmit.block.BlockState("minecraft:dirt")));
assertTrue("a deposit that names no blocks replaces any", new ResolvedDeposit(new DepositGenerator(), DEPOSIT_SEED, BLOCKS)
.canReplace(new com.volmit.block.BlockState("minecraft:dirt")));
}
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;
/** {@code generator} with a palette of {@code block}, as its JSON would have it. */
private static DepositGenerator withPalette(DepositGenerator generator, String block) {
return art.arcane.iris.engine.object.TestSettings.with(generator, "palette", List.of(com.volmit.block.BlockSpec.of(block)));
}
}
@@ -1,42 +1,30 @@
package art.arcane.iris.engine.modifier;
import art.arcane.iris.builtin.deposit.DepositVariant;
import art.arcane.iris.engine.UsableBlockPlatform;
import art.arcane.iris.spi.IrisPlatforms;
import art.arcane.iris.spi.PlatformBlockState;
import com.google.gson.Gson;
import org.junit.After;
import com.volmit.ModuleLog;
import com.volmit.block.BlockState;
import com.volmit.host.ModuleLogs;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;
public class ResolvedDepositVariantTest {
private static final String DEEP_IRON = """
{"minHeight": -64, "maxHeight": 0, "remap": {"minecraft:iron_ore": "minecraft:deepslate_iron_ore", "unknown_block": "minecraft:stone"}}
""";
private static final ModuleLog LOG = ModuleLogs.discarding();
private static void knowEveryBlockButTheUnknownOne() {
UsableBlockPlatform.bind();
when(IrisPlatforms.get().registries().blockOrNull(anyString(), anyBoolean())).thenAnswer(call -> {
String name = call.getArgument(0);
return name.equals("unknown_block") ? null : UsableBlockPlatform.block(name);
});
}
@After
public void unbindPlatform() {
UsableBlockPlatform.unbind();
private static ResolvedDepositVariant variant(String json) {
return new ResolvedDepositVariant(new Gson().fromJson(json, DepositVariant.class), ApiChunk.blocks(), LOG);
}
@Test
public void aVariantAppliesWithinItsInclusiveBand() {
ResolvedDepositVariant variant = new ResolvedDepositVariant(new Gson().fromJson(DEEP_IRON, DepositVariant.class));
ResolvedDepositVariant variant = variant(DEEP_IRON);
assertTrue(variant.appliesAt(-64));
assertTrue(variant.appliesAt(0));
@@ -46,30 +34,33 @@ public class ResolvedDepositVariantTest {
@Test
public void anOreIsRemappedByItsMaterialAndOtherBlocksAreNot() {
knowEveryBlockButTheUnknownOne();
ResolvedDepositVariant variant = new ResolvedDepositVariant(new Gson().fromJson(DEEP_IRON, DepositVariant.class));
PlatformBlockState iron = UsableBlockPlatform.block("iron_ore");
ResolvedDepositVariant variant = variant(DEEP_IRON);
PlatformBlockState remapped = variant.remapOrNull(iron);
BlockState remapped = variant.remapOrNull(new BlockState("minecraft:iron_ore"));
assertEquals("minecraft:deepslate_iron_ore", remapped.key());
assertNull(variant.remapOrNull(UsableBlockPlatform.block("coal_ore")));
assertNull(variant.remapOrNull(new BlockState("minecraft:coal_ore")));
assertNull(variant.remapOrNull(null));
}
@Test
public void aRuleWhoseSourceTheServerDoesNotKnowRemapsNothing() {
knowEveryBlockButTheUnknownOne();
DepositVariant unknown = new Gson().fromJson("{\"remap\": {\"unknown_block\": \"minecraft:stone\"}}", DepositVariant.class);
ResolvedDepositVariant unknown = variant("{\"remap\": {\"unknown_block\": \"minecraft:stone\"}}");
assertNull(new ResolvedDepositVariant(unknown).remapOrNull(UsableBlockPlatform.block("unknown_block")));
assertNull(unknown.remapOrNull(new BlockState("minecraft:unknown_block")));
}
@Test
public void aRuleWhoseReplacementTheServerDoesNotKnowRemapsNothing() {
ResolvedDepositVariant unknown = variant("{\"remap\": {\"minecraft:iron_ore\": \"unknown_block\"}}");
assertNull(unknown.remapOrNull(new BlockState("minecraft:iron_ore")));
}
@Test
public void aVariantWithoutRemapsChangesNothing() {
UsableBlockPlatform.bind();
ResolvedDepositVariant variant = new ResolvedDepositVariant(new Gson().fromJson("{\"maxHeight\": 5}", DepositVariant.class));
ResolvedDepositVariant variant = variant("{\"maxHeight\": 5}");
assertNull(variant.remapOrNull(UsableBlockPlatform.block("iron_ore")));
assertNull(variant.remapOrNull(new BlockState("minecraft:iron_ore")));
}
}