mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 16:54:04 +00:00
Merge terrain, decorant and deposit (wave3b/4) with carve and placement: one pinned mantle chunks set with loaded-chunk lookup, both mantle margins, placement terrain reads BedrockSettings and TerrainPalettes, IrisCaveDressing goes
This commit is contained in:
commit
eca3908ec1
62 files changed
+1652
-1417
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) {
|
||||
return hasTrait(platformState(state), trait);
|
||||
|
||||
@@ -1,160 +0,0 @@
|
||||
/*
|
||||
* 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.builtin.CaveDressing;
|
||||
import art.arcane.iris.builtin.decorant.DecorationPart;
|
||||
import art.arcane.iris.engine.decorator.BiomeDecorators;
|
||||
import art.arcane.iris.engine.decorator.IrisCeilingDecorator;
|
||||
import art.arcane.iris.engine.decorator.IrisSurfaceDecorator;
|
||||
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.engine.terrain.BiomeLayers;
|
||||
import art.arcane.iris.engine.terrain.TerrainPalettes;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.common.data.B;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.hunk.Hunk;
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* {@link CaveDressing} over Iris's biome layers, decorators and terrain palettes: what the carve module asks of the features that
|
||||
* are not modules yet, in IrisApi's types. Transitional, like the interface.
|
||||
*/
|
||||
final class IrisCaveDressing implements CaveDressing {
|
||||
private final Engine engine;
|
||||
private final IrisPackResources resources;
|
||||
private final BiomeLayers layers;
|
||||
private final BiomeDecorators decorators;
|
||||
private final TerrainPalettes palettes;
|
||||
private final IrisSurfaceDecorator surfaceDecorator;
|
||||
private final IrisCeilingDecorator ceilingDecorator;
|
||||
|
||||
IrisCaveDressing(Engine engine, IrisPackResources resources, ModuleLog log) {
|
||||
this.engine = engine;
|
||||
this.resources = resources;
|
||||
this.layers = BiomeLayers.of(engine, log);
|
||||
this.decorators = BiomeDecorators.of(engine);
|
||||
this.palettes = TerrainPalettes.of(engine);
|
||||
this.surfaceDecorator = new IrisSurfaceDecorator(engine);
|
||||
this.ceilingDecorator = new IrisCeilingDecorator(engine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fluidPresentAt(int x, int z) {
|
||||
return B.isFluid(palettes.fluidAt(x, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState fluidAt(Hunk<BlockState> chunk, int x, int z) {
|
||||
return nullable(states(chunk), palettes.fluidAt(x, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState wall(Hunk<BlockState> chunk, ResourceId biome, RNG rng, int x, int y, int z) {
|
||||
IrisBiome irisBiome = resources.irisBiome(biome);
|
||||
if (irisBiome == null) {
|
||||
return null;
|
||||
}
|
||||
return nullable(states(chunk), layers.wall(irisBiome).get(rng, x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockState> floorLayers(Hunk<BlockState> chunk, ResourceId biome, int x, int z, RNG rng, int depth, int floorY) {
|
||||
IrisBiome irisBiome = resources.irisBiome(biome);
|
||||
if (irisBiome == null) {
|
||||
return List.of();
|
||||
}
|
||||
return toApi(chunk, layers.generateLayers(irisBiome, engine.getDimension(), x, z, rng, depth, floorY, engine.getData(), engine.getComplex()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockState> ceilingLayers(Hunk<BlockState> chunk, ResourceId biome, int x, int z, RNG rng, int depth, int ceilingY) {
|
||||
IrisBiome irisBiome = resources.irisBiome(biome);
|
||||
if (irisBiome == null) {
|
||||
return List.of();
|
||||
}
|
||||
return toApi(chunk, layers.generateCeilingLayers(irisBiome, engine.getDimension(), x, z, rng, depth, ceilingY, engine.getData(), engine.getComplex()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDecorators(ResourceId biome, DecorationPart part) {
|
||||
IrisBiome irisBiome = resources.irisBiome(biome);
|
||||
return irisBiome != null && decorators.hasDecorators(irisBiome, part);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decorateFloor(Hunk<BlockState> chunk, int localX, int localZ, int x, int z, ResourceId biome, int floorY, int airThickness) {
|
||||
IrisBiome irisBiome = resources.irisBiome(biome);
|
||||
if (irisBiome == null) {
|
||||
return;
|
||||
}
|
||||
surfaceDecorator.decorate(localX, localZ, x, x, x, z, z, z, platform(chunk), irisBiome, InferredType.CAVE, floorY, airThickness);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decorateCeiling(Hunk<BlockState> chunk, int localX, int localZ, int x, int z, ResourceId biome, int ceilingY, int airThickness) {
|
||||
IrisBiome irisBiome = resources.irisBiome(biome);
|
||||
if (irisBiome == null) {
|
||||
return;
|
||||
}
|
||||
ceilingDecorator.decorate(localX, localZ, x, x, x, z, z, z, platform(chunk), irisBiome, InferredType.CAVE, ceilingY, airThickness);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState deepSlateOre(Hunk<BlockState> chunk, BlockState existing, BlockState layer) {
|
||||
PlatformBlockStates states = states(chunk);
|
||||
return states.toApi(B.toDeepSlateOre(states.toPlatform(existing), states.toPlatform(layer)));
|
||||
}
|
||||
|
||||
private List<BlockState> toApi(Hunk<BlockState> chunk, List<PlatformBlockState> blocks) {
|
||||
PlatformBlockStates states = states(chunk);
|
||||
List<BlockState> converted = new ArrayList<>(blocks.size());
|
||||
for (PlatformBlockState block : blocks) {
|
||||
converted.add(nullable(states, block));
|
||||
}
|
||||
return converted;
|
||||
}
|
||||
|
||||
/** A state or null where the layer gave none; IrisApi's conversion reads null as air. */
|
||||
private static BlockState nullable(PlatformBlockStates states, PlatformBlockState block) {
|
||||
return block == null ? null : states.toApi(block);
|
||||
}
|
||||
|
||||
private static PlatformBlockStates states(Hunk<BlockState> chunk) {
|
||||
return hunk(chunk).states();
|
||||
}
|
||||
|
||||
private static art.arcane.iris.util.project.hunk.Hunk<PlatformBlockState> platform(Hunk<BlockState> chunk) {
|
||||
return hunk(chunk).platform();
|
||||
}
|
||||
|
||||
private static BlockStateHunk hunk(Hunk<BlockState> chunk) {
|
||||
if (chunk instanceof BlockStateHunk hunk) {
|
||||
return hunk;
|
||||
}
|
||||
throw new IllegalArgumentException("Built-in modules dress the chunks Iris hands to them, not " + chunk);
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,8 @@ import java.util.Collection;
|
||||
final class IrisGenerationContext implements GenerationContext {
|
||||
/** Chunk stages write only their own chunk, but see the terrain this far around it (IrisApi's promise). */
|
||||
private static final int TERRAIN_MARGIN_BLOCKS = 16;
|
||||
/** The mantle too reaches this far around the chunk; chunks beyond its own are pinned when a stage first reads them. */
|
||||
private static final int MANTLE_MARGIN_BLOCKS = 16;
|
||||
private static final int CHUNK_WIDTH = 16;
|
||||
|
||||
private final Engine engine;
|
||||
@@ -59,9 +61,10 @@ 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);
|
||||
BlockBox chunk = ApiHeights.columns(engine, originX - MANTLE_MARGIN_BLOCKS, originZ - MANTLE_MARGIN_BLOCKS,
|
||||
originX + CHUNK_WIDTH + MANTLE_MARGIN_BLOCKS, originZ + CHUNK_WIDTH + MANTLE_MARGIN_BLOCKS);
|
||||
this.mantle = new IrisModuleMantle(chunk, mantleChunks, mantleLayers, PlannedBlocks.of(engine, chunk, mantleChunks, states));
|
||||
}
|
||||
|
||||
|
||||
@@ -19,11 +19,8 @@
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.actuator.DecorantModule;
|
||||
import art.arcane.iris.engine.actuator.TerrainModule;
|
||||
import art.arcane.iris.engine.mantle.components.ObjectModule;
|
||||
import art.arcane.iris.engine.mantle.components.StructureModule;
|
||||
import art.arcane.iris.engine.modifier.DepositModule;
|
||||
import art.arcane.iris.engine.modifier.FloatingModule;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import com.volmit.IrisModule;
|
||||
@@ -61,7 +58,7 @@ public final class IrisModuleHost {
|
||||
*/
|
||||
public static final List<String> JAR_MODULE_IDS = List.of("iris:post", "iris:perfection", "iris:matter", "iris:loot",
|
||||
"iris:spawn", "iris:prepare", "iris:anchor", "iris:validate", "iris:bore", "iris:blocks", "iris:stilt", "iris:vacuum",
|
||||
"iris:snow", "iris:vanilla-features", "iris:carve");
|
||||
"iris:snow", "iris:vanilla-features", "iris:carve", "iris:deposit", "iris:decorant", "iris:terrain");
|
||||
/** 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"};
|
||||
@@ -85,8 +82,7 @@ public final class IrisModuleHost {
|
||||
}
|
||||
|
||||
private static List<IrisModule> generationModules() {
|
||||
return List.of(new TerrainModule(), new ObjectModule(), new StructureModule(),
|
||||
new FloatingModule(), new DepositModule(), new DecorantModule());
|
||||
return List.of(new ObjectModule(), new StructureModule(), new FloatingModule());
|
||||
}
|
||||
|
||||
/** Iris's own log, labelled {@code [iris]}, for host code that calls module classes outside any module's stage, service or hook. */
|
||||
|
||||
@@ -111,6 +111,11 @@ final class IrisModuleMantle implements Mantle, MatterMantle {
|
||||
return plannedBlocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleLayer<Boolean> caverns() {
|
||||
return new MantleCaverns(bounds, chunks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleEdit edit() {
|
||||
if (openEdit != null) {
|
||||
@@ -256,6 +261,12 @@ final class IrisModuleMantle implements Mantle, MatterMantle {
|
||||
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");
|
||||
|
||||
@@ -145,12 +145,6 @@ public final class IrisPackResources implements PackResources {
|
||||
return kindOf(type).ids();
|
||||
}
|
||||
|
||||
/** The biome of the pack with this id as Iris's own class, for the built-ins that decorate with it; null when the pack has none. */
|
||||
public IrisBiome irisBiome(ResourceId id) {
|
||||
String key = kindOf(PackBiome.class).keyOf(id);
|
||||
return key == null ? null : data.getBiomeLoader().load(key);
|
||||
}
|
||||
|
||||
/** The id of the resource the pack names by {@code packKey}, such as {@code overworld:castle/keep} for {@code castle/keep}. */
|
||||
@Override
|
||||
public ResourceId idOf(String packKey) {
|
||||
@@ -199,8 +193,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) {
|
||||
@@ -236,6 +237,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) {
|
||||
@@ -253,11 +259,6 @@ public final class IrisPackResources implements PackResources {
|
||||
return Optional.of(raced != null ? raced : made);
|
||||
}
|
||||
|
||||
/** The key of the resource with this id; null when the pack has none. */
|
||||
String keyOf(ResourceId id) {
|
||||
return keysById().get(id);
|
||||
}
|
||||
|
||||
List<ResourceId> ids() {
|
||||
return keysById().keySet().stream().sorted().toList();
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.CaveDressing;
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.LiveWorld;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
@@ -37,7 +36,7 @@ import java.util.function.Function;
|
||||
* pack's resources reload under it. Iris's built-in modules reach the engine through {@link #of(PackWorld)}, as built-in
|
||||
* reaches do through {@link IrisPackSettings#of}.
|
||||
*/
|
||||
public final class IrisPackWorld implements PackWorld, IrisSeed.Source, LiveWorld.Source, CaveDressing.Source {
|
||||
public final class IrisPackWorld implements PackWorld, IrisSeed.Source, LiveWorld.Source {
|
||||
private final Engine engine;
|
||||
private final IrisPackResources resources;
|
||||
private final WorldStates states;
|
||||
@@ -113,17 +112,13 @@ public final class IrisPackWorld implements PackWorld, IrisSeed.Source, LiveWorl
|
||||
return liveWorld;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CaveDressing caveDressing() {
|
||||
return state(IrisCaveDressing.class, world -> new IrisCaveDressing(engine, resources, log));
|
||||
}
|
||||
|
||||
@Override
|
||||
public long seed(IrisSeed seed) {
|
||||
SeedManager seeds = engine.getSeedManager();
|
||||
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();
|
||||
|
||||
@@ -24,7 +24,8 @@ import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.NativeStructureVolume;
|
||||
import art.arcane.iris.engine.object.placement.IObjectPlacer;
|
||||
import art.arcane.iris.engine.terrain.TerrainPalettes;
|
||||
import art.arcane.iris.builtin.terrain.BedrockSettings;
|
||||
import art.arcane.iris.builtin.terrain.TerrainPalettes;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import com.volmit.block.BlockState;
|
||||
|
||||
@@ -115,7 +116,7 @@ final class IrisPlacementTerrain implements PlacementTerrain {
|
||||
|
||||
@Override
|
||||
public boolean hasBedrock() {
|
||||
return engine().getDimension().isBedrock();
|
||||
return engine().getDimension().getModuleSettings().find(BedrockSettings.class).map(BedrockSettings::bedrock).orElse(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -134,7 +135,8 @@ final class IrisPlacementTerrain implements PlacementTerrain {
|
||||
if (engine.getComplex() == null) {
|
||||
return PlatformBlockStates.AIR;
|
||||
}
|
||||
return states.toApi(TerrainPalettes.of(engine).rockAt(x, z));
|
||||
BlockState rock = TerrainPalettes.of(engine.getGeneration().world()).rockAt(x, z);
|
||||
return rock == null ? PlatformBlockStates.AIR : rock;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,12 +20,18 @@ 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.resource.ResourceId;
|
||||
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;
|
||||
@@ -42,18 +48,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
|
||||
@@ -94,6 +111,12 @@ final class IrisTerrainSampler implements TerrainSampler {
|
||||
return Optional.ofNullable(engine.getCaveBiome(worldX, y, worldZ)).map(biome -> ids.of(biome.getLoadKey()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceId surfaceBiome(int worldX, int worldZ) {
|
||||
requireInside(worldX, bounds.minY(), worldZ);
|
||||
return ids.of(engine.getSurfaceBiome(worldX, worldZ).getLoadKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fluidHeight() {
|
||||
return engine.getDimension().getFluidHeight();
|
||||
@@ -111,6 +134,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.terrain.LayerLoad;
|
||||
import art.arcane.iris.builtin.terrain.LayersSettings;
|
||||
import art.arcane.iris.engine.object.material.IrisBlockData;
|
||||
import art.arcane.iris.engine.object.material.IrisMaterialPalette;
|
||||
import art.arcane.iris.engine.object.noise.IrisGeneratorStyle;
|
||||
@@ -33,6 +35,7 @@ import com.volmit.config.Range;
|
||||
import com.volmit.noise.StyledRange;
|
||||
import com.volmit.world.BlockPosition;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -109,6 +112,12 @@ public final class IrisValues {
|
||||
return iris;
|
||||
}
|
||||
|
||||
/** The noise style of each layer of the biome's surface, top first, as Iris's generators know them. */
|
||||
public static List<art.arcane.iris.engine.object.noise.NoiseStyle> layerStyles(art.arcane.iris.engine.object.world.biome.IrisBiome biome) {
|
||||
return LayerLoad.layersOf(biome.getModuleSettings().find(LayersSettings.class).orElse(null)).stream()
|
||||
.map(layer -> generatorStyle(layer.style()).getStyle()).toList();
|
||||
}
|
||||
|
||||
/** {@code range} as the range Iris reads the same JSON into. */
|
||||
public static IrisRange range(Range range) {
|
||||
return new IrisRange(range.min(), range.max());
|
||||
|
||||
@@ -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) {
|
||||
}
|
||||
}
|
||||
@@ -60,7 +60,7 @@ public final class ModuleChunkGeneration {
|
||||
int chunkX = x >> CHUNK_SHIFT;
|
||||
int chunkZ = z >> CHUNK_SHIFT;
|
||||
long seed = ModuleSeeds.chunk(engine.getSeedManager().getSeed(), chunkX, chunkZ);
|
||||
try (PinnedMantleChunk mantle = new PinnedMantleChunk(engine, chunkX, chunkZ)) {
|
||||
try (PinnedMantleChunks mantle = new PinnedMantleChunks(engine)) {
|
||||
IrisGenerationContext inputs = new IrisGenerationContext(engine, x, z, blocks, new PlatformBlockStates(platformStates), mantle,
|
||||
pack.catalog().mantle());
|
||||
StageMetrics metrics = new StageMetrics(engine.getMetrics());
|
||||
|
||||
@@ -71,4 +71,8 @@ final class PackResourceIds {
|
||||
ResourceId of(String type, String key) {
|
||||
return of(type + "/" + key);
|
||||
}
|
||||
|
||||
private ResourceId idOf(String key) {
|
||||
return new ResourceId(namespace, NOT_PATH.matcher(key.toLowerCase(Locale.ROOT)).replaceAll(REPLACEMENT));
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* 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 art.arcane.volmlib.util.mantle.runtime.Mantle;
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.mantle.runtime.TectonicPlate;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
|
||||
/**
|
||||
* The one mantle chunk a generating chunk's stages may read: pinned the first time a stage asks for it and
|
||||
* released once the chunk's stages are done.
|
||||
*/
|
||||
final class PinnedMantleChunk implements IrisModuleMantle.Chunks, AutoCloseable {
|
||||
/** A tectonic plate holds 32 by 32 chunks. */
|
||||
private static final int PLATE_SHIFT = 5;
|
||||
private static final int PLATE_MASK = (1 << PLATE_SHIFT) - 1;
|
||||
|
||||
private final Engine engine;
|
||||
private final int chunkX;
|
||||
private final int chunkZ;
|
||||
private MantleChunk<Matter> pinned;
|
||||
|
||||
PinnedMantleChunk(Engine engine, int chunkX, int chunkZ) {
|
||||
this.engine = engine;
|
||||
this.chunkX = chunkX;
|
||||
this.chunkZ = chunkZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized MantleChunk<Matter> chunk(int x, int z) {
|
||||
if (x != chunkX || z != chunkZ) {
|
||||
return null;
|
||||
}
|
||||
if (pinned == null) {
|
||||
pinned = engine.getMantle().getMantle().getChunk(chunkX, chunkZ).use();
|
||||
}
|
||||
return pinned;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleChunk<Matter> loadedChunk(int x, int z) {
|
||||
Mantle<Matter> mantle = engine.getMantle().getMantle();
|
||||
TectonicPlate<Matter> plate = mantle.getLoadedRegions().get(Mantle.key(x >> PLATE_SHIFT, z >> PLATE_SHIFT));
|
||||
if (plate == null || plate.isClosed()) {
|
||||
return null;
|
||||
}
|
||||
return plate.get(x & PLATE_MASK, z & PLATE_MASK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void close() {
|
||||
if (pinned != null) {
|
||||
pinned.release();
|
||||
pinned = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,9 @@
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.volmlib.util.mantle.runtime.Mantle;
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.mantle.runtime.TectonicPlate;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -30,6 +32,10 @@ import java.util.Map;
|
||||
* released together once the placement is committed or discarded.
|
||||
*/
|
||||
final class PinnedMantleChunks implements IrisModuleMantle.Chunks, AutoCloseable {
|
||||
/** A tectonic plate holds 32 by 32 chunks. */
|
||||
private static final int PLATE_SHIFT = 5;
|
||||
private static final int PLATE_MASK = (1 << PLATE_SHIFT) - 1;
|
||||
|
||||
private final Engine engine;
|
||||
private final Map<Long, MantleChunk<Matter>> pinned = new HashMap<>();
|
||||
|
||||
@@ -42,6 +48,16 @@ final class PinnedMantleChunks implements IrisModuleMantle.Chunks, AutoCloseable
|
||||
return pinned.computeIfAbsent(key(chunkX, chunkZ), ignored -> engine.getMantle().getMantle().getChunk(chunkX, chunkZ).use());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleChunk<Matter> loadedChunk(int chunkX, int chunkZ) {
|
||||
Mantle<Matter> mantle = engine.getMantle().getMantle();
|
||||
TectonicPlate<Matter> plate = mantle.getLoadedRegions().get(Mantle.key(chunkX >> PLATE_SHIFT, chunkZ >> PLATE_SHIFT));
|
||||
if (plate == null || plate.isClosed()) {
|
||||
return null;
|
||||
}
|
||||
return plate.get(chunkX & PLATE_MASK, chunkZ & PLATE_MASK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void close() {
|
||||
pinned.values().forEach(MantleChunk::release);
|
||||
|
||||
@@ -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()");
|
||||
|
||||
@@ -49,6 +49,9 @@ public final class PlatformBlockStates {
|
||||
/** The state read last: scans over a chunk read long runs of one state, such as stone or air, so most reads hit it. */
|
||||
private PlatformBlockState lastRead;
|
||||
private BlockState lastReadAsApi;
|
||||
/** The state written last: a stage fills long runs of one block, such as rock, so most writes hit it. */
|
||||
private BlockState lastWritten;
|
||||
private PlatformBlockState lastWrittenAsPlatform;
|
||||
|
||||
/** {@code platformStates} turns a block state key into the platform's state, such as {@code B::getState}. */
|
||||
public PlatformBlockStates(Function<String, PlatformBlockState> platformStates) {
|
||||
@@ -82,11 +85,14 @@ public final class PlatformBlockStates {
|
||||
}
|
||||
|
||||
public PlatformBlockState toPlatform(BlockState state) {
|
||||
PlatformBlockState origin = origins.get(state);
|
||||
if (origin != null) {
|
||||
return origin;
|
||||
if (state == lastWritten) {
|
||||
return lastWrittenAsPlatform;
|
||||
}
|
||||
return written.computeIfAbsent(state, api -> platformStates.apply(api.key()));
|
||||
PlatformBlockState origin = origins.get(state);
|
||||
PlatformBlockState platform = origin != null ? origin : written.computeIfAbsent(state, api -> platformStates.apply(api.key()));
|
||||
lastWritten = state;
|
||||
lastWrittenAsPlatform = platform;
|
||||
return platform;
|
||||
}
|
||||
|
||||
/** {@code key} with Minecraft's namespace when it names none, as Minecraft reads such keys. */
|
||||
|
||||
@@ -36,7 +36,10 @@ final class StageMetrics implements StageTimings {
|
||||
private static final Map<String, Function<EngineMetrics, AtomicRollingSequence>> NAMED = Map.of(
|
||||
"iris:post/smooth", EngineMetrics::getPost,
|
||||
"iris:perfection/surface", EngineMetrics::getPerfection,
|
||||
"iris:carve/apply", EngineMetrics::getCave);
|
||||
"iris:carve/apply", EngineMetrics::getCave,
|
||||
"iris:deposit/ores", EngineMetrics::getDeposit,
|
||||
"iris:decorant/decorate", EngineMetrics::getDecoration,
|
||||
"iris:terrain/shape", EngineMetrics::getTerrain);
|
||||
|
||||
private final EngineMetrics metrics;
|
||||
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 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.engine.framework;
|
||||
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.common.data.B;
|
||||
import art.arcane.volmlib.util.documentation.BlockCoordinates;
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
|
||||
public interface EngineDecorator extends EngineComponent {
|
||||
|
||||
@BlockCoordinates
|
||||
void decorate(int x, int z, int realX, int realX1, int realX_1, int realZ, int realZ1, int realZ_1, Hunk<PlatformBlockState> data, IrisBiome biome, int height, int max);
|
||||
|
||||
@BlockCoordinates
|
||||
default void decorate(int x, int z, int realX, int realZ, Hunk<PlatformBlockState> data, IrisBiome biome, int height, int max) {
|
||||
decorate(x, z, realX, realX, realX, realZ, realZ, realZ, data, biome, height, max);
|
||||
}
|
||||
|
||||
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||
default boolean canGoOn(PlatformBlockState decorant, PlatformBlockState atop) {
|
||||
if (atop == null || atop.isAir()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return B.canPlaceOnto(decorant, atop);
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@
|
||||
package art.arcane.iris.engine.mantle;
|
||||
|
||||
|
||||
import art.arcane.iris.builtin.terrain.BedrockSettings;
|
||||
import art.arcane.iris.engine.object.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.util.project.matter.TileWrapper;
|
||||
@@ -198,7 +199,7 @@ public class MantleWriter implements IObjectPlacer, AutoCloseable {
|
||||
return;
|
||||
}
|
||||
|
||||
if (y == 0 && t instanceof PlatformBlockState && engineMantle.getEngine().getDimension().isBedrock()) {
|
||||
if (y == 0 && t instanceof PlatformBlockState && engineMantle.getEngine().getDimension().getModuleSettings().find(BedrockSettings.class).map(BedrockSettings::bedrock).orElse(true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,9 +21,12 @@ 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.actuator.DecorantModule;
|
||||
import art.arcane.iris.engine.actuator.TerrainModule;
|
||||
import art.arcane.iris.engine.framework.vanillafeatures.VanillaFeaturesModule;
|
||||
import art.arcane.iris.engine.loot.LootModule;
|
||||
import art.arcane.iris.engine.modifier.CarveModule;
|
||||
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;
|
||||
@@ -65,7 +68,8 @@ public final class BuiltInPack {
|
||||
public static List<IrisModule> jarModules() {
|
||||
return List.of(new PostModule(), new PerfectionModule(), new MatterModule(), new LootModule(), new SpawnModule(),
|
||||
new PrepareModule(), new AnchorModule(), new ValidateModule(), new BoreModule(), new BlocksModule(),
|
||||
new StiltModule(), new VacuumModule(), new SnowModule(), new VanillaFeaturesModule(), new CarveModule());
|
||||
new StiltModule(), new VacuumModule(), new SnowModule(), new VanillaFeaturesModule(), new CarveModule(),
|
||||
new DepositModule(), new DecorantModule(), new TerrainModule());
|
||||
}
|
||||
|
||||
/** Every built-in module: Iris's own and the compiled-in copies of the jar's ({@link #jarModules()}). */
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.volmit.mantle.BlockBox;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.BiomeSample;
|
||||
import com.volmit.world.TerrainSample;
|
||||
import com.volmit.world.BiomeKind;
|
||||
import com.volmit.world.TerrainSampler;
|
||||
|
||||
import java.util.Optional;
|
||||
@@ -69,6 +70,16 @@ public final class CarveTestTerrain implements TerrainSampler {
|
||||
return new BlockBox(originX - MARGIN, 0, originZ - MARGIN, originX + 16 + MARGIN, height, originZ + 16 + MARGIN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeKind surfaceKind(int worldX, int worldZ) {
|
||||
return BiomeKind.LAND;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int minWorldY() {
|
||||
return CarveTestWorld.MIN_HEIGHT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerrainSample column(int worldX, int worldZ) {
|
||||
int surfaceY = surface.applyAsInt(worldX, worldZ);
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.CaveDressing;
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.ResourceLoader;
|
||||
@@ -62,7 +61,7 @@ import static org.mockito.Mockito.when;
|
||||
* own noise over an empty pack, a few blocks by name and the world's seeds, all in memory, so the module is tested through IrisApi alone.
|
||||
* Biomes and regions have the ids {@code test:<key>}; a declaration made for {@code <key>} has the source {@code test:<kind>/<key>}.
|
||||
*/
|
||||
public final class CarveTestWorld implements PackWorld, IrisSeed.Source, CaveDressing.Source {
|
||||
public final class CarveTestWorld implements PackWorld, IrisSeed.Source {
|
||||
public static final String NAMESPACE = "test";
|
||||
public static final int MIN_HEIGHT = -64;
|
||||
private static final Set<String> AIRS = Set.of("minecraft:air", "minecraft:cave_air", "minecraft:void_air");
|
||||
@@ -76,7 +75,6 @@ public final class CarveTestWorld implements PackWorld, IrisSeed.Source, CaveDre
|
||||
private final IrisData data = packData();
|
||||
private final Resources resources = new Resources();
|
||||
private long carveSeed = 1337L;
|
||||
private CaveDressing dressing;
|
||||
|
||||
public CarveTestWorld declare(Target level, String key, IrisFeature value) {
|
||||
String kind = level.name().toLowerCase();
|
||||
@@ -99,11 +97,6 @@ public final class CarveTestWorld implements PackWorld, IrisSeed.Source, CaveDre
|
||||
return this;
|
||||
}
|
||||
|
||||
public CarveTestWorld dressing(CaveDressing dressing) {
|
||||
this.dressing = dressing;
|
||||
return this;
|
||||
}
|
||||
|
||||
/** The pack data under the noise: nothing in it, as the tests of Iris's value types have it. */
|
||||
public IrisData data() {
|
||||
return data;
|
||||
@@ -164,14 +157,6 @@ public final class CarveTestWorld implements PackWorld, IrisSeed.Source, CaveDre
|
||||
return seed == IrisSeed.CARVE ? carveSeed : carveSeed + seed.ordinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CaveDressing caveDressing() {
|
||||
if (dressing == null) {
|
||||
throw new UnsupportedOperationException("This world has no cave dressing");
|
||||
}
|
||||
return dressing;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static IrisData packData() {
|
||||
IrisData pack = mock(IrisData.class);
|
||||
|
||||
@@ -180,7 +180,7 @@ public class DimensionBottomTest {
|
||||
assertEquals("minecraft:stone", blocks.get(0, BOTTOM, 0).key());
|
||||
assertEquals("the chunk's block hunk starts at the bottom, not at the world's minimum height", 1, countBlocks(blocks));
|
||||
assertEquals(List.of(WHOLE_HEIGHT_AROUND_ONE_CHUNK), terrainBounds);
|
||||
assertEquals(List.of(WHOLE_HEIGHT_OF_ONE_CHUNK), viewBounds);
|
||||
assertEquals("the mantle reaches as far around the chunk as the terrain", List.of(WHOLE_HEIGHT_AROUND_ONE_CHUNK), viewBounds);
|
||||
assertEquals("the terrain samples count from the same bottom", List.of(Double.valueOf(SURFACE_HEIGHT)), surfaces);
|
||||
}
|
||||
|
||||
|
||||
@@ -365,6 +365,11 @@ public class IrisModuleMantleTest {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleLayer<Boolean> caverns() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleEdit edit() {
|
||||
throw new UnsupportedOperationException();
|
||||
|
||||
@@ -158,6 +158,23 @@ public class IrisValuesTest {
|
||||
.createNoCache(new RNG(4242), data).noise(9, 4), plain.sample(9, 4), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theIrisStyleIsTheSignatureNoiseOfTheSeedThatSetsTheThicknessOfBiomeLayers() {
|
||||
IrisNoiseFactory factory = new IrisNoiseFactory(packWithoutCustomBlocks());
|
||||
long mismatches = 0;
|
||||
for (long seed : new long[]{1, 7235, -3999281L, 1337L * 31, 987654321987L}) {
|
||||
CNG signature = CNG.signature(new RNG(seed));
|
||||
NoiseSampler sampler = factory.sampler(NoiseStyle.of("IRIS"), seed);
|
||||
for (int x = -2000; x < 2000; x += 7) {
|
||||
for (int z = -1000; z < 1000; z += 11) {
|
||||
double zoom = 5;
|
||||
mismatches += signature.noiseFast2D(x / zoom, z / zoom) == sampler.sample(x / zoom, z / zoom) ? 0 : 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
assertEquals(0, mismatches);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aStyleNameIrisDoesNotKnowIsFlat() {
|
||||
IrisData data = packWithoutCustomBlocks();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -21,7 +21,11 @@ package art.arcane.iris.core.modules;
|
||||
import art.arcane.iris.builtin.post.PostProcessingSettings;
|
||||
import art.arcane.iris.builtin.post.PostProcessingSlabsSettings;
|
||||
import art.arcane.iris.builtin.post.PostProcessingWallsSettings;
|
||||
import art.arcane.iris.builtin.decorant.DecorateSettings;
|
||||
import art.arcane.iris.builtin.terrain.BedrockSettings;
|
||||
import art.arcane.iris.builtin.terrain.CaveCeilingLayersSettings;
|
||||
import art.arcane.iris.builtin.terrain.ExplodeBiomePaletteSizeSettings;
|
||||
import art.arcane.iris.builtin.terrain.ExplodeBiomePalettesSettings;
|
||||
import art.arcane.iris.builtin.terrain.FluidPaletteSettings;
|
||||
import art.arcane.iris.builtin.terrain.LayersSettings;
|
||||
import art.arcane.iris.builtin.terrain.LockLayersMaxSettings;
|
||||
@@ -218,6 +222,21 @@ public class TerrainSettingsDecodingTest {
|
||||
assertTrue(settings.find(PostProcessingWallsSettings.class).orElseThrow().enabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theDimensionReadsItsBedrockDecoratingAndExplodedPaletteKeysAsPacksWriteThem() {
|
||||
ModuleSettings settings = decoder.decode(Target.DIMENSION, new JSONObject(
|
||||
"{\"bedrock\": false, \"decorate\": false, \"explodeBiomePalettes\": true, \"explodeBiomePaletteSize\": 5}"), "dimension flat");
|
||||
|
||||
assertFalse(settings.find(BedrockSettings.class).orElseThrow().bedrock());
|
||||
assertFalse(settings.find(DecorateSettings.class).orElseThrow().decorate());
|
||||
assertTrue(settings.find(ExplodeBiomePalettesSettings.class).orElseThrow().explode());
|
||||
assertEquals(5, settings.find(ExplodeBiomePaletteSizeSettings.class).orElseThrow().size());
|
||||
for (String key : Set.of("bedrock", "decorate", "explodeBiomePalettes", "explodeBiomePaletteSize")) {
|
||||
assertTrue(key, decoder.keys(Target.DIMENSION).contains(key));
|
||||
assertFalse(key + " is no field of Iris any more", ModuleTargets.reservedFields().get(Target.DIMENSION).contains(key));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aDimensionThatWritesNothingIsStoneAndWaterWithPostProcessingOn() {
|
||||
ModuleSettings settings = decoder.decode(Target.DIMENSION, new JSONObject("{}"), "dimension overworld");
|
||||
@@ -228,6 +247,8 @@ public class TerrainSettingsDecodingTest {
|
||||
assertTrue(new PostProcessingSettings().enabled());
|
||||
assertTrue(new PostProcessingSlabsSettings().enabled());
|
||||
assertTrue(new PostProcessingWallsSettings().enabled());
|
||||
assertTrue("bedrock and decorating are on, and the palettes unexploded, unless written", new BedrockSettings().bedrock()
|
||||
&& new DecorateSettings().decorate() && !new ExplodeBiomePalettesSettings().explode());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,98 +1,72 @@
|
||||
package art.arcane.iris.engine.actuator;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.ModuleSettings;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.EngineGeneration;
|
||||
import art.arcane.iris.engine.framework.EngineMetrics;
|
||||
import art.arcane.iris.engine.framework.SeedManager;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.project.context.ChunkContext;
|
||||
import art.arcane.iris.util.project.context.ChunkedDataCache;
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
import com.volmit.world.PackWorld;
|
||||
import art.arcane.iris.builtin.decorant.DecorantSettings;
|
||||
import art.arcane.iris.builtin.decorant.DecorateSettings;
|
||||
import art.arcane.iris.builtin.decorant.Decorator;
|
||||
import art.arcane.iris.engine.modifier.ApiChunk;
|
||||
import art.arcane.iris.engine.object.TestSettings;
|
||||
import com.google.gson.Gson;
|
||||
import com.volmit.block.BlockState;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Decorating reads nothing of the chunk when the dimension does not decorate, skips biomes without decorators, and is
|
||||
* kept per world in the world's state store.
|
||||
*/
|
||||
/** Decorating puts a biome's decorators on its surface, unless the dimension says not to or the biome has none. */
|
||||
public class DecorantModuleTest {
|
||||
private static final int GROUND = 8;
|
||||
private static final BlockState GRASS_BLOCK = new BlockState("minecraft:grass_block");
|
||||
private static final BlockState POPPY = new BlockState("minecraft:poppy");
|
||||
private static final DecorantSettings POPPIES = new DecorantSettings(List.of(new Gson().fromJson("{\"chance\": 1, \"palette\": [{\"block\": \"poppy\"}]}", Decorator.class)));
|
||||
|
||||
@Test
|
||||
public void eachWorldKeepsOneDecoratingInItsStateStore() {
|
||||
Engine engine = engine(true);
|
||||
when(engine.getData()).thenReturn(mock(IrisData.class));
|
||||
EngineGeneration generation = new EngineGeneration(engine);
|
||||
when(engine.getGeneration()).thenReturn(generation);
|
||||
PackWorld world = generation.world();
|
||||
public void everyColumnOfABiomeWithDecoratorsGetsOne() {
|
||||
ApiChunk chunk = ground().biomeSettings(POPPIES);
|
||||
|
||||
DecorantModule.Decorating decorating = DecorantModule.decorating(world);
|
||||
chunk.generate(new DecorantModule());
|
||||
|
||||
assertSame(decorating, DecorantModule.decorating(world));
|
||||
assertSame("built-in stages share the store", decorating,
|
||||
generation.state(DecorantModule.Decorating.class, DecorantModule.Decorating::new));
|
||||
EngineGeneration otherGeneration = new EngineGeneration(engine);
|
||||
when(engine.getGeneration()).thenReturn(otherGeneration);
|
||||
assertNotSame(decorating, DecorantModule.decorating(otherGeneration.world()));
|
||||
assertEquals(256, countAt(chunk, GROUND + 1, POPPY));
|
||||
assertEquals("on top of the ground, not in it", 0, countAt(chunk, GROUND, POPPY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aDimensionThatDoesNotDecorateIsLeftAlone() {
|
||||
DecorantModule.Decorating decorating = new DecorantModule.Decorating(engineWithGeneration(false));
|
||||
ChunkContext context = mock(ChunkContext.class);
|
||||
ApiChunk chunk = ground().biomeSettings(POPPIES).dimensionSettings(TestSettings.of(DecorateSettings.class, "{\"decorate\": false}"));
|
||||
|
||||
decorating.decorate(0, 0, Hunk.newArrayHunk(16, 16, 16), context);
|
||||
chunk.generate(new DecorantModule());
|
||||
|
||||
verifyNoInteractions(context);
|
||||
assertEquals(0, countAt(chunk, GROUND + 1, POPPY));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void aBiomeWithoutDecoratorsGetsNothingPlaced() {
|
||||
DecorantModule.Decorating decorating = new DecorantModule.Decorating(engineWithGeneration(true));
|
||||
IrisBiome biome = mock(IrisBiome.class);
|
||||
when(biome.getModuleSettings()).thenReturn(ModuleSettings.NONE);
|
||||
ChunkedDataCache<IrisBiome> biomes = mock(ChunkedDataCache.class);
|
||||
when(biomes.get(anyInt(), anyInt())).thenReturn(biome);
|
||||
ChunkContext context = mock(ChunkContext.class);
|
||||
when(context.getBiome()).thenReturn(biomes);
|
||||
Hunk<PlatformBlockState> output = mock(Hunk.class);
|
||||
when(output.getWidth()).thenReturn(16);
|
||||
when(output.getDepth()).thenReturn(16);
|
||||
ApiChunk chunk = ground();
|
||||
|
||||
decorating.decorate(0, 0, output, context);
|
||||
chunk.generate(new DecorantModule());
|
||||
|
||||
verify(output, never()).set(anyInt(), anyInt(), anyInt(), org.mockito.ArgumentMatchers.any());
|
||||
verify(biomes, org.mockito.Mockito.times(16 * 16)).get(anyInt(), anyInt());
|
||||
assertEquals(0, countAt(chunk, GROUND + 1, POPPY));
|
||||
}
|
||||
|
||||
private Engine engineWithGeneration(boolean decorate) {
|
||||
Engine engine = engine(decorate);
|
||||
when(engine.getData()).thenReturn(mock(IrisData.class));
|
||||
when(engine.getGeneration()).thenReturn(new EngineGeneration(engine));
|
||||
return engine;
|
||||
private static ApiChunk ground() {
|
||||
ApiChunk chunk = new ApiChunk(0, 0, 32).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, GRASS_BLOCK);
|
||||
}
|
||||
}
|
||||
}
|
||||
return chunk;
|
||||
}
|
||||
|
||||
private Engine engine(boolean decorate) {
|
||||
IrisDimension dimension = mock(IrisDimension.class);
|
||||
when(dimension.isDecorate()).thenReturn(decorate);
|
||||
SeedManager seeds = mock(SeedManager.class);
|
||||
Engine engine = mock(Engine.class);
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
when(engine.getSeedManager()).thenReturn(seeds);
|
||||
when(engine.getMetrics()).thenReturn(new EngineMetrics(16));
|
||||
return engine;
|
||||
private static int countAt(ApiChunk chunk, int y, BlockState block) {
|
||||
int count = 0;
|
||||
for (int x = 0; x < ApiChunk.WIDTH; x++) {
|
||||
for (int z = 0; z < ApiChunk.WIDTH; z++) {
|
||||
count += chunk.get(x, y, z).equals(block) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
package art.arcane.iris.engine.actuator;
|
||||
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.SeedManager;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.iris.builtin.terrain.OreSettings;
|
||||
import art.arcane.iris.engine.modifier.ApiChunk;
|
||||
import art.arcane.iris.engine.terrain.TestPackWorld;
|
||||
import com.volmit.FeatureAttachment.Target;
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.config.FeatureSettings.Entry;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -26,28 +28,36 @@ public class OreWarmUpTest {
|
||||
|
||||
@Test
|
||||
public void biomesByKeyThenRegionsByKeyThenTheDimensionWarmWithConsecutiveSeedsOfTheWorld() {
|
||||
SeedManager seeds = mock(SeedManager.class);
|
||||
when(seeds.getComponent()).thenReturn(COMPONENT_SEED);
|
||||
IrisDimension dimension = mock(IrisDimension.class);
|
||||
Engine engine = mock(Engine.class);
|
||||
when(engine.getSeedManager()).thenReturn(seeds);
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
TerrainOres ores = mock(TerrainOres.class);
|
||||
IrisBiome biomeB = biome("b", ores, "b0", "b1");
|
||||
IrisBiome biomeA = biome("a", ores, "a0");
|
||||
IrisRegion regionY = region("y", ores, "y0");
|
||||
IrisRegion regionX = region("x", ores, "x0", "x1");
|
||||
ResolvedOres dimensionOres = resolved("d0");
|
||||
when(ores.of(dimension)).thenReturn(dimensionOres);
|
||||
when(engine.getAllBiomes()).thenReturn(new KList<>(List.of(biomeB, biomeA)));
|
||||
when(dimension.getAllRegions(engine)).thenReturn(new KList<>(List.of(regionY, regionX)));
|
||||
List<Entry<OreSettings>> declared = new ArrayList<>();
|
||||
// The pack lists the dimension first, then regions and biomes, in no particular order.
|
||||
declared.add(entry(Target.DIMENSION, "dimension/overworld", ores, "d0"));
|
||||
declared.add(entry(Target.REGION, "region/y", ores, "y0"));
|
||||
declared.add(entry(Target.BIOME, "biome/b", ores, "b0", "b1"));
|
||||
declared.add(entry(Target.REGION, "region/x", ores, "x0", "x1"));
|
||||
declared.add(entry(Target.BIOME, "biome/a", ores, "a0"));
|
||||
PackSettings settings = new PackSettings() {
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <F extends IrisFeature> List<Entry<F>> declared(Class<F> featureType) {
|
||||
return (List<Entry<F>>) (List<?>) declared;
|
||||
}
|
||||
};
|
||||
TestPackWorld world = new TestPackWorld(new ApiChunk(0, 0, 16).resources(), settings, COMPONENT_SEED);
|
||||
|
||||
new OreWarmUp(engine, ores).warm();
|
||||
new OreWarmUp(world, ores).warm();
|
||||
|
||||
assertEquals(List.of("a0@" + ROOT_SEED, "b0@" + (ROOT_SEED + 1), "b1@" + (ROOT_SEED + 2),
|
||||
"x0@" + (ROOT_SEED + 3), "x1@" + (ROOT_SEED + 4), "y0@" + (ROOT_SEED + 5), "d0@" + (ROOT_SEED + 6)), warmed);
|
||||
}
|
||||
|
||||
private Entry<OreSettings> entry(Target level, String source, TerrainOres ores, String... oreNames) {
|
||||
OreSettings settings = new OreSettings(List.of());
|
||||
ResolvedOres declared = resolved(oreNames);
|
||||
when(ores.of(settings)).thenReturn(declared);
|
||||
return new Entry<>(level, ResourceId.parse("test:" + source), settings);
|
||||
}
|
||||
|
||||
private ResolvedOres resolved(String... names) {
|
||||
List<ResolvedOre> ores = new ArrayList<>();
|
||||
for (String name : names) {
|
||||
@@ -57,20 +67,4 @@ public class OreWarmUpTest {
|
||||
}
|
||||
return new ResolvedOres(ores);
|
||||
}
|
||||
|
||||
private IrisBiome biome(String key, TerrainOres ores, String... oreNames) {
|
||||
IrisBiome biome = mock(IrisBiome.class);
|
||||
when(biome.getLoadKey()).thenReturn(key);
|
||||
ResolvedOres declared = resolved(oreNames);
|
||||
when(ores.of(biome)).thenReturn(declared);
|
||||
return biome;
|
||||
}
|
||||
|
||||
private IrisRegion region(String key, TerrainOres ores, String... oreNames) {
|
||||
IrisRegion region = mock(IrisRegion.class);
|
||||
when(region.getLoadKey()).thenReturn(key);
|
||||
ResolvedOres declared = resolved(oreNames);
|
||||
when(ores.of(region)).thenReturn(declared);
|
||||
return region;
|
||||
}
|
||||
}
|
||||
@@ -5,16 +5,16 @@ import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.ResourceLoader;
|
||||
import art.arcane.iris.core.modules.IrisPackResources;
|
||||
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.material.IrisBlockData;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import com.google.gson.Gson;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.noise.NoiseSampler;
|
||||
import com.volmit.resource.PackResources;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -48,15 +48,15 @@ public class ResolvedOreTest {
|
||||
@Test
|
||||
public void everyOreGeneratesAsIrisOreGeneratorDid() {
|
||||
UsableBlockPlatform.bind();
|
||||
Engine engine = engine();
|
||||
PackResources resources = resources();
|
||||
StringBuilder transcript = new StringBuilder();
|
||||
for (String json : ORES) {
|
||||
ResolvedOre ore = ResolvedOre.of(new Gson().fromJson(json, OreGenerator.class), engine);
|
||||
ResolvedOre ore = ResolvedOre.of(new Gson().fromJson(json, OreGenerator.class), resources, TERRAIN_SEED);
|
||||
ore.warm(WARM_SEED);
|
||||
for (int x = -30; x < 30; x += 3) {
|
||||
for (int z = -30; z < 30; z += 4) {
|
||||
for (int y = -20; y < 70; y += 5) {
|
||||
PlatformBlockState state = ore.generate(x, y, z);
|
||||
BlockState state = ore.generate(x, y, z);
|
||||
transcript.append(state == null ? "-" : state.key()).append(';');
|
||||
}
|
||||
}
|
||||
@@ -71,13 +71,12 @@ public class ResolvedOreTest {
|
||||
|
||||
@Test
|
||||
public void theNoiseKeepsTheFirstSeedItIsBuiltFrom() {
|
||||
UsableBlockPlatform.bind();
|
||||
OreGenerator settings = new Gson().fromJson(ORES[1], OreGenerator.class);
|
||||
List<Long> seeds = new ArrayList<>();
|
||||
ResolvedOre ore = new ResolvedOre(settings, (style, seed) -> {
|
||||
seeds.add(seed);
|
||||
return constant(0);
|
||||
}, null, TERRAIN_SEED, List.of(UsableBlockPlatform.block("iron_ore")));
|
||||
}, null, TERRAIN_SEED, List.of(new BlockState("minecraft:iron_ore")));
|
||||
|
||||
ore.warm(WARM_SEED);
|
||||
ore.warm(WARM_SEED + 1);
|
||||
@@ -88,13 +87,12 @@ public class ResolvedOreTest {
|
||||
|
||||
@Test
|
||||
public void anOreNothingWarmedBuildsItsNoiseFromTheTerrainSeed() {
|
||||
UsableBlockPlatform.bind();
|
||||
OreGenerator settings = new Gson().fromJson(ORES[1], OreGenerator.class);
|
||||
List<Long> seeds = new ArrayList<>();
|
||||
ResolvedOre ore = new ResolvedOre(settings, (style, seed) -> {
|
||||
seeds.add(seed);
|
||||
return constant(0);
|
||||
}, null, TERRAIN_SEED, List.of(UsableBlockPlatform.block("iron_ore")));
|
||||
}, null, TERRAIN_SEED, List.of(new BlockState("minecraft:iron_ore")));
|
||||
|
||||
ore.generate(0, 0, 0);
|
||||
ore.generate(1, 1, 1);
|
||||
@@ -104,8 +102,7 @@ public class ResolvedOreTest {
|
||||
|
||||
@Test
|
||||
public void nothingGeneratesOutsideTheBandOrWithAnEmptyPaletteOrAboveTheThreshold() {
|
||||
UsableBlockPlatform.bind();
|
||||
PlatformBlockState iron = UsableBlockPlatform.block("iron_ore");
|
||||
BlockState iron = new BlockState("minecraft:iron_ore");
|
||||
OreGenerator settings = new Gson().fromJson(ORES[1], OreGenerator.class);
|
||||
ResolvedOre atThreshold = new ResolvedOre(settings, (style, seed) -> constant(0.5), null, TERRAIN_SEED, List.of(iron));
|
||||
ResolvedOre aboveThreshold = new ResolvedOre(settings, (style, seed) -> constant(0.51), null, TERRAIN_SEED, List.of(iron));
|
||||
@@ -148,7 +145,7 @@ public class ResolvedOreTest {
|
||||
};
|
||||
}
|
||||
|
||||
private static Engine engine() {
|
||||
private static PackResources resources() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
ResourceLoader<IrisBlockData> blocks = mock(ResourceLoader.class);
|
||||
@@ -156,11 +153,6 @@ public class ResolvedOreTest {
|
||||
when(data.getDataFolder()).thenReturn(new File("pack"));
|
||||
IrisPackResources resources = new IrisPackResources(data);
|
||||
when(data.getPackResources()).thenReturn(resources);
|
||||
SeedManager seeds = mock(SeedManager.class);
|
||||
when(seeds.getTerrain()).thenReturn(TERRAIN_SEED);
|
||||
Engine engine = mock(Engine.class);
|
||||
when(engine.getData()).thenReturn(data);
|
||||
when(engine.getSeedManager()).thenReturn(seeds);
|
||||
return engine;
|
||||
return resources;
|
||||
}
|
||||
}
|
||||
@@ -3,19 +3,20 @@ package art.arcane.iris.engine.actuator;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.ResourceLoader;
|
||||
import art.arcane.iris.core.modules.IrisPackResources;
|
||||
import art.arcane.iris.engine.IrisComplex;
|
||||
import art.arcane.iris.engine.UsableBlockPlatform;
|
||||
import art.arcane.iris.engine.object.material.IrisBlockData;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.core.modules.ModuleSettings;
|
||||
import art.arcane.iris.builtin.terrain.PaletteLayer;
|
||||
import art.arcane.iris.builtin.terrain.SlabSettings;
|
||||
import art.arcane.iris.engine.terrain.BiomeLayers;
|
||||
import art.arcane.iris.engine.terrain.TestLayerBlocks;
|
||||
import art.arcane.iris.engine.terrain.ResolvedLayer;
|
||||
import art.arcane.iris.builtin.terrain.BiomeLayers;
|
||||
import art.arcane.iris.builtin.terrain.ColumnSlope;
|
||||
import art.arcane.iris.builtin.terrain.LayeredBiome;
|
||||
import art.arcane.iris.builtin.terrain.PaletteExplosion;
|
||||
import art.arcane.iris.builtin.terrain.ResolvedLayer;
|
||||
import art.arcane.iris.engine.terrain.TerrainTestSettings;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.project.stream.ProceduralStream;
|
||||
import art.arcane.iris.engine.terrain.TestLayerBlocks;
|
||||
import art.arcane.iris.engine.terrain.TestLayeredBiomes;
|
||||
import com.volmit.block.BlockState;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.host.ModuleLogs;
|
||||
@@ -86,7 +87,7 @@ public class TerrainLayersPinTest {
|
||||
private static final String[] BIOMES = {MESA, MEADOW, OCEAN, DEFAULTS};
|
||||
|
||||
private IrisData data;
|
||||
private IrisComplex complex;
|
||||
private final ColumnSlope slope = (x, z) -> Math.abs((x * 3 + z * 5) % 11);
|
||||
|
||||
@Before
|
||||
public void bindPlatform() {
|
||||
@@ -98,8 +99,6 @@ public class TerrainLayersPinTest {
|
||||
when(data.getDataFolder()).thenReturn(new File("pack"));
|
||||
IrisPackResources resources = new IrisPackResources(data);
|
||||
when(data.getPackResources()).thenReturn(resources);
|
||||
complex = mock(IrisComplex.class);
|
||||
when(complex.getSlopeStream()).thenReturn(ProceduralStream.ofDouble((x, z) -> Math.abs((x * 3 + z * 5) % 11)));
|
||||
}
|
||||
|
||||
private static final PaletteLayer NO_LAYER = PaletteLayer.withoutBlocks();
|
||||
@@ -126,44 +125,42 @@ public class TerrainLayersPinTest {
|
||||
}
|
||||
|
||||
private void record(StringBuilder transcript, String biomeJson, boolean exploded) {
|
||||
IrisDimension dimension = new IrisDimension();
|
||||
dimension.setExplodeBiomePalettes(exploded);
|
||||
dimension.setExplodeBiomePaletteSize(2);
|
||||
PaletteExplosion explosion = new PaletteExplosion(exploded, 2);
|
||||
RNG rng = new RNG(TERRAIN_SEED);
|
||||
IrisBiome biome = new IrisBiome();
|
||||
biome.setModuleSettings(TerrainTestSettings.of(biomeJson));
|
||||
BiomeLayers layers = new BiomeLayers(TestLayerBlocks.of(data.getPackResources()), ModuleLogs.discarding());
|
||||
ModuleSettings settings = TerrainTestSettings.of(biomeJson);
|
||||
LayeredBiome biome = TestLayeredBiomes.of(settings);
|
||||
BiomeLayers layers = new BiomeLayers(TestLayerBlocks.of(data.getPackResources()), () -> data.getPackResources().noise(), ModuleLogs.discarding());
|
||||
for (int x = -COLUMN_RANGE; x < COLUMN_RANGE; x += COLUMN_STEP_X) {
|
||||
for (int z = -COLUMN_RANGE; z < COLUMN_RANGE; z += COLUMN_STEP_Z) {
|
||||
transcript.append('|').append(keys(layers.generateLayers(biome, dimension, x, z, rng, 14, 70 + Math.floorMod(x + z, 9), data, complex)));
|
||||
transcript.append('|').append(keys(layers.generateCeilingLayers(biome, dimension, x, z, rng, 12, 40, data, complex)));
|
||||
transcript.append('|').append(keys(layers.generateSeaLayers(biome, x, z, rng, 7, data)));
|
||||
transcript.append('|').append(smoothing(layers, biome, rng, x, z));
|
||||
transcript.append('|').append(keys(layers.generateLayers(biome, explosion, x, z, rng, 14, 70 + Math.floorMod(x + z, 9), slope)));
|
||||
transcript.append('|').append(keys(layers.generateCeilingLayers(biome, explosion, x, z, rng, 12)));
|
||||
transcript.append('|').append(keys(layers.generateSeaLayers(biome, x, z, rng, 7)));
|
||||
transcript.append('|').append(smoothing(layers, settings, biome, rng, x, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The block a slab and a wall place in post processing at the column, as the smoothing stage asks the biome. */
|
||||
private String smoothing(BiomeLayers layers, IrisBiome biome, RNG rng, int x, int z) {
|
||||
private String smoothing(BiomeLayers layers, ModuleSettings settings, LayeredBiome biome, RNG rng, int x, int z) {
|
||||
int height = 60 + Math.floorMod(x - z, 7);
|
||||
double slope = complex.getSlopeStream().get(x, z);
|
||||
ResolvedLayer slabLayer = layers.resolve(biome.getModuleSettings().find(SlabSettings.class).map(SlabSettings::layer).orElse(NO_LAYER));
|
||||
double columnSlope = slope.at(x, z);
|
||||
ResolvedLayer slabLayer = layers.resolve(settings.find(SlabSettings.class).map(SlabSettings::layer).orElse(NO_LAYER));
|
||||
ResolvedLayer wallLayer = layers.wall(biome);
|
||||
String slab = slabLayer.slopeCondition().isValid(slope) ? key(slabLayer.get(rng, x, height, z)) : "-";
|
||||
String slab = slabLayer.slopeCondition().isValid(columnSlope) ? key(slabLayer.get(rng, x, height, z)) : "-";
|
||||
String wall = !wallLayer.hasPalette() ? "-" : key(wallLayer.get(rng, x + height, height + height, z + height));
|
||||
return slab + "," + wall;
|
||||
}
|
||||
|
||||
private static String keys(KList<PlatformBlockState> states) {
|
||||
private static String keys(KList<BlockState> states) {
|
||||
StringBuilder keys = new StringBuilder();
|
||||
for (PlatformBlockState state : states) {
|
||||
for (BlockState state : states) {
|
||||
keys.append(key(state)).append(' ');
|
||||
}
|
||||
return keys.toString();
|
||||
}
|
||||
|
||||
/** The block's key without its namespace and with its properties in name order, which is how the platform identifies a state whatever order a pack lists them in. */
|
||||
private static String key(PlatformBlockState state) {
|
||||
private static String key(BlockState state) {
|
||||
if (state == null) {
|
||||
return "null";
|
||||
}
|
||||
|
||||
@@ -1,165 +1,107 @@
|
||||
package art.arcane.iris.engine.actuator;
|
||||
|
||||
import art.arcane.iris.engine.IrisComplex;
|
||||
import art.arcane.iris.engine.UsableBlockPlatform;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.EngineMetrics;
|
||||
import art.arcane.iris.engine.framework.SeedManager;
|
||||
import art.arcane.iris.engine.image.IrisImageMapRuntime;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import art.arcane.iris.engine.terrain.BiomeLayers;
|
||||
import art.arcane.iris.engine.terrain.TerrainPalettes;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.project.context.ChunkContext;
|
||||
import art.arcane.iris.util.project.context.ChunkedDataCache;
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.iris.builtin.terrain.BedrockSettings;
|
||||
import art.arcane.iris.builtin.terrain.HideOresSettings;
|
||||
import art.arcane.iris.core.modules.BuiltInPack;
|
||||
import org.junit.After;
|
||||
import art.arcane.iris.builtin.terrain.LayersSettings;
|
||||
import art.arcane.iris.builtin.terrain.OreSettings;
|
||||
import art.arcane.iris.engine.modifier.ApiChunk;
|
||||
import art.arcane.iris.engine.object.TestSettings;
|
||||
import com.volmit.block.BlockState;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyDouble;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
|
||||
/** Terrain fills a column from bedrock to its height with the biome's layers over rock, and the fluid above it up to the fluid height. */
|
||||
public class TerrainModuleTest {
|
||||
private static final int HEIGHT = 20;
|
||||
private static final int FLUID_HEIGHT = 25;
|
||||
|
||||
private final PlatformBlockState grass = mock(PlatformBlockState.class);
|
||||
private final PlatformBlockState dirt = mock(PlatformBlockState.class);
|
||||
private final PlatformBlockState rock = mock(PlatformBlockState.class);
|
||||
private final PlatformBlockState water = mock(PlatformBlockState.class);
|
||||
|
||||
@After
|
||||
public void unbindPlatform() {
|
||||
UsableBlockPlatform.unbind();
|
||||
}
|
||||
private static final int WORLD_HEIGHT = 64;
|
||||
private static final BlockState GRASS = new BlockState("minecraft:grass_block");
|
||||
private static final BlockState DIRT = new BlockState("minecraft:dirt");
|
||||
private static final BlockState STONE = new BlockState("minecraft:stone");
|
||||
private static final BlockState WATER = new BlockState("minecraft:water");
|
||||
private static final BlockState BEDROCK = new BlockState("minecraft:bedrock");
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void aColumnIsBedrockThenRockThenLayersThenFluid() {
|
||||
UsableBlockPlatform.bind();
|
||||
IrisBiome biome = mock(IrisBiome.class);
|
||||
TerrainModule.TerrainShaper shaper = new TerrainModule.TerrainShaper(engine(true), palettes(), layersOf(biome), mock(TerrainOres.class));
|
||||
Hunk<PlatformBlockState> blocks = Hunk.newArrayHunk(16, 64, 16);
|
||||
ApiChunk chunk = world().biomeSettings(TestSettings.of(LayersSettings.class,
|
||||
"{\"layers\": [{\"palette\": [{\"block\": \"grass_block\"}]}, {\"palette\": [{\"block\": \"dirt\"}]}]}"));
|
||||
|
||||
shaper.shape(0, 0, blocks, context(biome));
|
||||
chunk.generate(new TerrainModule());
|
||||
|
||||
PlatformBlockState floor = blocks.get(3, 0, 4);
|
||||
assertNotNull("bedrock at the bottom", floor);
|
||||
assertNotSame(rock, floor);
|
||||
assertSame("rock below the layers", rock, blocks.get(3, 5, 4));
|
||||
assertSame("the second layer", dirt, blocks.get(3, HEIGHT - 1, 4));
|
||||
assertSame("the first layer is the surface", grass, blocks.get(3, HEIGHT, 4));
|
||||
assertSame("fluid above the surface", water, blocks.get(3, HEIGHT + 1, 4));
|
||||
assertSame("fluid up to the fluid height", water, blocks.get(3, FLUID_HEIGHT, 4));
|
||||
assertNull("nothing above the fluid", blocks.get(3, FLUID_HEIGHT + 1, 4));
|
||||
assertEquals("bedrock at the bottom", BEDROCK, chunk.get(3, 0, 4));
|
||||
assertEquals("rock below the layers", STONE, chunk.get(3, 5, 4));
|
||||
assertEquals("the second layer", DIRT, chunk.get(3, HEIGHT - 1, 4));
|
||||
assertEquals("the first layer is the surface", GRASS, chunk.get(3, HEIGHT, 4));
|
||||
assertEquals("fluid above the surface", WATER, chunk.get(3, HEIGHT + 1, 4));
|
||||
assertEquals("fluid up to the fluid height", WATER, chunk.get(3, FLUID_HEIGHT, 4));
|
||||
assertEquals("nothing above the fluid", ApiChunk.AIR, chunk.get(3, FLUID_HEIGHT + 1, 4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aBiomeWithoutLayersHasOneLayerOfGrass() {
|
||||
ApiChunk chunk = world();
|
||||
|
||||
chunk.generate(new TerrainModule());
|
||||
|
||||
assertEquals(GRASS, chunk.get(3, HEIGHT, 4));
|
||||
assertEquals(STONE, chunk.get(3, HEIGHT - 1, 4));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void oresOfTheBiomeThenTheRegionThenTheDimensionReplaceTheBlocksTheirBandsReach() {
|
||||
UsableBlockPlatform.bind();
|
||||
Engine engine = engine(false);
|
||||
IrisDimension dimension = engine.getDimension();
|
||||
IrisBiome biome = mock(IrisBiome.class);
|
||||
ChunkContext context = context(biome);
|
||||
IrisRegion region = context.getRegion().get(0, 0);
|
||||
PlatformBlockState biomeOre = mock(PlatformBlockState.class);
|
||||
PlatformBlockState regionOre = mock(PlatformBlockState.class);
|
||||
PlatformBlockState dimensionOre = mock(PlatformBlockState.class);
|
||||
TerrainOres ores = mock(TerrainOres.class);
|
||||
ResolvedOres biomeOres = oresAt(2, biomeOre);
|
||||
ResolvedOres regionOres = oresAt(2, regionOre, 3, regionOre);
|
||||
ResolvedOres dimensionOres = oresAt(2, dimensionOre, 3, dimensionOre, 4, dimensionOre);
|
||||
when(ores.of(biome)).thenReturn(biomeOres);
|
||||
when(ores.of(region)).thenReturn(regionOres);
|
||||
when(ores.of(dimension)).thenReturn(dimensionOres);
|
||||
Hunk<PlatformBlockState> blocks = Hunk.newArrayHunk(16, 64, 16);
|
||||
ApiChunk chunk = world()
|
||||
.biomeSettings(ores("coal_ore", 2, 2))
|
||||
.regionSettings(ores("iron_ore", 2, 3))
|
||||
.dimensionSettings(ores("gold_ore", 2, 4));
|
||||
|
||||
new TerrainModule.TerrainShaper(engine, palettes(), layersOf(biome, new KList<>()), ores).shape(0, 0, blocks, context);
|
||||
chunk.generate(new TerrainModule());
|
||||
|
||||
assertSame("the biome's ore comes first", biomeOre, blocks.get(3, 2, 4));
|
||||
assertSame("then the region's", regionOre, blocks.get(3, 3, 4));
|
||||
assertSame("then the dimension's", dimensionOre, blocks.get(3, 4, 4));
|
||||
assertSame("rock where no ore reaches", rock, blocks.get(3, 5, 4));
|
||||
assertEquals("the biome's ore comes first", new BlockState("minecraft:coal_ore"), chunk.get(3, 2, 4));
|
||||
assertEquals("then the region's", new BlockState("minecraft:iron_ore"), chunk.get(3, 3, 4));
|
||||
assertEquals("then the dimension's", new BlockState("minecraft:gold_ore"), chunk.get(3, 4, 4));
|
||||
assertEquals("rock where no ore reaches", STONE, chunk.get(3, 5, 4));
|
||||
}
|
||||
|
||||
/** Underground ores that give {@code block} at each listed height and nothing elsewhere. */
|
||||
private static ResolvedOres oresAt(Object... heightsAndBlocks) {
|
||||
ResolvedOre ore = mock(ResolvedOre.class);
|
||||
when(ore.generatesSurface()).thenReturn(false);
|
||||
when(ore.minY()).thenReturn(0D);
|
||||
when(ore.maxY()).thenReturn(10D);
|
||||
for (int index = 0; index < heightsAndBlocks.length; index += 2) {
|
||||
when(ore.generate(anyInt(), eq((int) heightsAndBlocks[index]), anyInt())).thenReturn((PlatformBlockState) heightsAndBlocks[index + 1]);
|
||||
}
|
||||
return new ResolvedOres(List.of(ore));
|
||||
@Test
|
||||
public void aDimensionThatHidesOresPlacesNone() {
|
||||
ApiChunk chunk = world().dimensionSettings(ores("gold_ore", 2, 4), new HideOresSettings(true));
|
||||
|
||||
chunk.generate(new TerrainModule());
|
||||
|
||||
assertEquals(STONE, chunk.get(3, 3, 4));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private ChunkContext context(IrisBiome biome) {
|
||||
ChunkedDataCache<IrisBiome> biomes = mock(ChunkedDataCache.class);
|
||||
when(biomes.get(anyInt(), anyInt())).thenReturn(biome);
|
||||
ChunkedDataCache<IrisRegion> regions = mock(ChunkedDataCache.class);
|
||||
when(regions.get(anyInt(), anyInt())).thenReturn(mock(IrisRegion.class));
|
||||
ChunkContext context = mock(ChunkContext.class);
|
||||
when(context.getBiome()).thenReturn(biomes);
|
||||
when(context.getRegion()).thenReturn(regions);
|
||||
when(context.getRoundedHeight(anyInt(), anyInt())).thenReturn(HEIGHT);
|
||||
return context;
|
||||
@Test
|
||||
public void aDimensionWithoutBedrockHasRockAtItsBottom() {
|
||||
ApiChunk chunk = world().dimensionSettings(TestSettings.of(BedrockSettings.class, "{\"bedrock\": false}"));
|
||||
|
||||
chunk.generate(new TerrainModule());
|
||||
|
||||
assertEquals(STONE, chunk.get(3, 0, 4));
|
||||
assertNotEquals(BEDROCK, chunk.get(0, 0, 0));
|
||||
}
|
||||
|
||||
private TerrainPalettes palettes() {
|
||||
TerrainPalettes palettes = mock(TerrainPalettes.class);
|
||||
when(palettes.rockAt(anyDouble(), anyDouble())).thenReturn(rock);
|
||||
when(palettes.fluidAt(anyDouble(), anyDouble())).thenReturn(water);
|
||||
return palettes;
|
||||
@Test
|
||||
public void aDimensionStackedOnItselfHangsItsGroundFromTheTop() {
|
||||
ApiChunk chunk = new ApiChunk(0, 0, WORLD_HEIGHT).surface((x, z) -> HEIGHT).upperDimension((x, z) -> 50).stackedOnItself();
|
||||
|
||||
chunk.generate(new TerrainModule());
|
||||
|
||||
assertEquals("bedrock caps the upper ground", BEDROCK, chunk.get(3, WORLD_HEIGHT - 1, 4));
|
||||
assertEquals("rock under the upper surface", STONE, chunk.get(3, 55, 4));
|
||||
assertEquals("the upper ground's face is the biome's layer", GRASS, chunk.get(3, 50, 4));
|
||||
assertEquals("nothing between the grounds", ApiChunk.AIR, chunk.get(3, 49, 4));
|
||||
}
|
||||
|
||||
private BiomeLayers layersOf(IrisBiome biome) {
|
||||
KList<PlatformBlockState> layers = new KList<>();
|
||||
layers.add(grass, dirt);
|
||||
return layersOf(biome, layers);
|
||||
private static ApiChunk world() {
|
||||
return new ApiChunk(0, 0, WORLD_HEIGHT).surface((x, z) -> HEIGHT).fluidHeight(FLUID_HEIGHT);
|
||||
}
|
||||
|
||||
private BiomeLayers layersOf(IrisBiome biome, KList<PlatformBlockState> layers) {
|
||||
BiomeLayers biomeLayers = mock(BiomeLayers.class);
|
||||
when(biomeLayers.generateLayers(eq(biome), any(), anyDouble(), anyDouble(), any(RNG.class), anyInt(), anyInt(), any(), any())).thenReturn(layers);
|
||||
when(biomeLayers.generateSeaLayers(eq(biome), anyDouble(), anyDouble(), any(RNG.class), anyInt(), any())).thenReturn(new KList<>());
|
||||
return biomeLayers;
|
||||
}
|
||||
|
||||
private Engine engine(boolean hidesOres) {
|
||||
IrisDimension dimension = mock(IrisDimension.class);
|
||||
when(dimension.getFluidHeight()).thenReturn(FLUID_HEIGHT);
|
||||
when(dimension.isBedrock()).thenReturn(true);
|
||||
when(dimension.getModuleSettings()).thenReturn(BuiltInPack.settings(new HideOresSettings(hidesOres)));
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
when(complex.getImageMapRuntime()).thenReturn(mock(IrisImageMapRuntime.class));
|
||||
SeedManager seeds = mock(SeedManager.class);
|
||||
when(seeds.getTerrain()).thenReturn(1337L);
|
||||
Engine engine = mock(Engine.class);
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
when(engine.getSeedManager()).thenReturn(seeds);
|
||||
when(engine.getMetrics()).thenReturn(new EngineMetrics(16));
|
||||
return engine;
|
||||
/** Ore generators of one block that give it at every height from {@code min} to {@code max}. */
|
||||
private static OreSettings ores(String block, int min, int max) {
|
||||
return TestSettings.of(OreSettings.class, "{\"generators\": [{\"palette\": {\"palette\": [{\"block\": \"" + block
|
||||
+ "\"}]}, \"chanceStyle\": {\"style\": \"STATIC\"}, \"threshold\": 0.5, \"range\": {\"min\": " + min + ", \"max\": " + max + "}}]}");
|
||||
}
|
||||
}
|
||||
@@ -3,15 +3,15 @@ package art.arcane.iris.engine.actuator;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.ResourceLoader;
|
||||
import art.arcane.iris.core.modules.IrisPackResources;
|
||||
import art.arcane.iris.engine.UpperDimensionContext;
|
||||
import art.arcane.iris.core.modules.ModuleSettings;
|
||||
import art.arcane.iris.engine.UsableBlockPlatform;
|
||||
import art.arcane.iris.engine.decorator.DecoratorTestEngines;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.SeedManager;
|
||||
import art.arcane.iris.engine.object.material.IrisBlockData;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.terrain.TerrainPalettes;
|
||||
import art.arcane.iris.builtin.terrain.TerrainPalettes;
|
||||
import art.arcane.iris.engine.terrain.TerrainTestSettings;
|
||||
import art.arcane.iris.engine.terrain.TestPackWorld;
|
||||
import com.volmit.config.FeatureSettings;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.world.UpperDimension;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -72,9 +72,9 @@ public class TerrainPalettesPinTest {
|
||||
public void rockAndFluidPickAsTheyDidInTheComplex() {
|
||||
StringBuilder transcript = new StringBuilder();
|
||||
for (String json : List.of(STYLED, DEFAULTS, SINGLE)) {
|
||||
IrisDimension dimension = dimension(json);
|
||||
record(transcript, TerrainPalettes.of(engine(dimension, COMPLEX_SEED)));
|
||||
record(transcript, TerrainPalettes.of(engine(dimension, UPPER_DIMENSION_SEED)));
|
||||
ModuleSettings dimension = TerrainTestSettings.of(json);
|
||||
record(transcript, TerrainPalettes.of(world(dimension, COMPLEX_SEED)));
|
||||
record(transcript, TerrainPalettes.of(world(dimension, UPPER_DIMENSION_SEED)));
|
||||
}
|
||||
|
||||
for (String picked : List.of("granite", "andesite", "diorite", "tuff", "lava", "packed_ice", "netherrack")) {
|
||||
@@ -86,15 +86,10 @@ public class TerrainPalettesPinTest {
|
||||
|
||||
@Test
|
||||
public void anUpperDimensionPicksItsRockFromTheSeedItDerivesFromTheWorldsAndItsOwnKey() {
|
||||
IrisDimension upperDimension = dimension(STYLED);
|
||||
upperDimension.setLoadKey(UPPER_DIMENSION_KEY);
|
||||
UpperDimensionContext upper = mock(UpperDimensionContext.class);
|
||||
when(upper.isSelfReferencing()).thenReturn(false);
|
||||
when(upper.getDimension()).thenReturn(upperDimension);
|
||||
when(upper.getData()).thenReturn(data);
|
||||
TerrainPalettes world = TerrainPalettes.of(engine(dimension(DEFAULTS), COMPLEX_SEED));
|
||||
TerrainPalettes derived = TerrainPalettes.of(engine(upperDimension, UPPER_DIMENSION_SEED));
|
||||
|
||||
ModuleSettings upperDimension = TerrainTestSettings.of(STYLED);
|
||||
UpperDimension upper = upper(false, upperDimension);
|
||||
TerrainPalettes world = TerrainPalettes.of(world(TerrainTestSettings.of(DEFAULTS), COMPLEX_SEED));
|
||||
TerrainPalettes derived = TerrainPalettes.of(world(upperDimension, UPPER_DIMENSION_SEED));
|
||||
for (int x = -COLUMN_RANGE; x < COLUMN_RANGE; x += COLUMN_STEP_X) {
|
||||
for (int z = -COLUMN_RANGE; z < COLUMN_RANGE; z += COLUMN_STEP_Z) {
|
||||
assertEquals(derived.rockAt(x, z).key(), world.upperRockAt(upper, x, z).key());
|
||||
@@ -104,28 +99,43 @@ public class TerrainPalettesPinTest {
|
||||
|
||||
@Test
|
||||
public void aDimensionThatIsItsOwnUpperDimensionSharesItsRock() {
|
||||
TerrainPalettes world = TerrainPalettes.of(engine(dimension(STYLED), COMPLEX_SEED));
|
||||
UpperDimensionContext upper = mock(UpperDimensionContext.class);
|
||||
when(upper.isSelfReferencing()).thenReturn(true);
|
||||
|
||||
TerrainPalettes world = TerrainPalettes.of(world(TerrainTestSettings.of(STYLED), COMPLEX_SEED));
|
||||
UpperDimension upper = upper(true, TerrainTestSettings.of(DEFAULTS));
|
||||
assertEquals(world.rockAt(17, -90).key(), world.upperRockAt(upper, 17, -90).key());
|
||||
}
|
||||
|
||||
private IrisDimension dimension(String json) {
|
||||
IrisDimension dimension = new IrisDimension();
|
||||
dimension.setModuleSettings(TerrainTestSettings.of(json));
|
||||
return dimension;
|
||||
private TestPackWorld world(ModuleSettings dimension, long complexSeed) {
|
||||
return new TestPackWorld(data.getPackResources(), dimension, complexSeed);
|
||||
}
|
||||
|
||||
private Engine engine(IrisDimension dimension, long complexSeed) {
|
||||
SeedManager seeds = mock(SeedManager.class);
|
||||
when(seeds.getComplex()).thenReturn(complexSeed);
|
||||
Engine engine = mock(Engine.class);
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
when(engine.getData()).thenReturn(data);
|
||||
when(engine.getSeedManager()).thenReturn(seeds);
|
||||
DecoratorTestEngines.withGeneration(engine);
|
||||
return engine;
|
||||
private UpperDimension upper(boolean thisDimension, ModuleSettings dimension) {
|
||||
PackResources resources = data.getPackResources();
|
||||
return new UpperDimension() {
|
||||
@Override
|
||||
public boolean isThisDimension() {
|
||||
return thisDimension;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String key() {
|
||||
return UPPER_DIMENSION_KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureSettings settings() {
|
||||
return TestPackWorld.dimensionLevel(dimension);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackResources resources() {
|
||||
return resources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.Optional<com.volmit.block.BlockState> surfaceBlock(int worldX, int worldZ) {
|
||||
return java.util.Optional.empty();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static void record(StringBuilder transcript, TerrainPalettes palettes) {
|
||||
|
||||
@@ -1,40 +1,27 @@
|
||||
package art.arcane.iris.engine.decorator;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.decorant.DecorantSettings;
|
||||
import art.arcane.iris.builtin.decorant.DecorationPart;
|
||||
import art.arcane.iris.builtin.decorant.Decorator;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.ResourceLoader;
|
||||
import art.arcane.iris.core.modules.IrisPackResources;
|
||||
import art.arcane.iris.core.modules.ModuleSettings;
|
||||
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.material.IrisBlockData;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.iris.engine.modifier.ApiChunk;
|
||||
import com.google.gson.Gson;
|
||||
import com.volmit.host.ModuleLogs;
|
||||
import org.junit.After;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.BiomeKind;
|
||||
import com.volmit.world.PackWorld;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/** The decorators of a world's biomes, sorted into the places they decorate and seeded from the world. */
|
||||
public class BiomeDecoratorsTest {
|
||||
private static final long DECORATOR_SEED = 5000L;
|
||||
private static final String MEADOW_DECORATORS = """
|
||||
[{"chance": 0.5, "palette": [{"block": "poppy"}]},
|
||||
{"partOf": "SHORE_LINE", "chance": 1, "stackMax": 3, "palette": [{"block": "sugar_cane"}]},
|
||||
@@ -42,36 +29,21 @@ public class BiomeDecoratorsTest {
|
||||
{"partOf": "CEILING", "chance": 1, "palette": [{"block": "glow_lichen"}]}]
|
||||
""";
|
||||
|
||||
private Engine engine;
|
||||
private IrisBiome meadow;
|
||||
private IrisBiome bare;
|
||||
private ApiChunk chunk;
|
||||
private PackWorld world;
|
||||
private DecoratedBiome meadow;
|
||||
private DecoratedBiome bare;
|
||||
private BiomeDecorators decorators;
|
||||
|
||||
@Before
|
||||
public void createWorld() {
|
||||
UsableBlockPlatform.bind();
|
||||
IrisData data = mock(IrisData.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
ResourceLoader<IrisBlockData> blocks = mock(ResourceLoader.class);
|
||||
when(data.getBlockLoader()).thenReturn(blocks);
|
||||
when(data.getDataFolder()).thenReturn(new File("pack"));
|
||||
IrisPackResources resources = new IrisPackResources(data);
|
||||
when(data.getPackResources()).thenReturn(resources);
|
||||
SeedManager seeds = mock(SeedManager.class);
|
||||
when(seeds.getDecorator()).thenReturn(DECORATOR_SEED);
|
||||
engine = mock(Engine.class);
|
||||
when(engine.getData()).thenReturn(data);
|
||||
when(engine.getSeedManager()).thenReturn(seeds);
|
||||
meadow = biome("meadow", MEADOW_DECORATORS);
|
||||
bare = mock(IrisBiome.class);
|
||||
when(bare.getLoadKey()).thenReturn("bare");
|
||||
when(bare.getModuleSettings()).thenReturn(ModuleSettings.NONE);
|
||||
decorators = new BiomeDecorators(engine, ModuleLogs.discarding());
|
||||
}
|
||||
|
||||
@After
|
||||
public void unbindPlatform() {
|
||||
UsableBlockPlatform.unbind();
|
||||
List<Decorator> list = List.of(new Gson().fromJson(MEADOW_DECORATORS, Decorator[].class));
|
||||
DecorantSettings settings = new DecorantSettings(list);
|
||||
chunk = new ApiChunk(0, 0, 16).biomeSettings(settings);
|
||||
world = chunk.world();
|
||||
meadow = new DecoratedBiome("meadow", settings, BiomeKind.LAND);
|
||||
bare = new DecoratedBiome("bare", null, BiomeKind.LAND);
|
||||
decorators = BiomeDecorators.of(world);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -87,65 +59,43 @@ public class BiomeDecoratorsTest {
|
||||
@Test
|
||||
public void aBiomeWithoutTheSettingsHasNoDecorators() {
|
||||
assertFalse(decorators.hasDecorators(bare));
|
||||
assertFalse(decorators.hasDecorators(null));
|
||||
assertEquals(0, decorators.decorators(bare, DecorationPart.NONE).length);
|
||||
assertEquals(0D, decorators.load(bare), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decoratorsAreResolvedOnceAndKeptForTheWorld() {
|
||||
assertSame(decorators.decorators(meadow, DecorationPart.NONE)[0], decorators.decorators(meadow, DecorationPart.NONE)[0]);
|
||||
assertSame(decorators, BiomeDecorators.of(world));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void everyDecoratorNoiseSeedIsAFunctionOfTheWorldsDecoratorSeedItsBiomeAndItsPlace() {
|
||||
long first = seedOf(decorators.decorators(meadow, DecorationPart.NONE)[0]);
|
||||
long second = seedOf(decorators.decorators(meadow, DecorationPart.NONE)[1]);
|
||||
long decoratorSeed = IrisSeed.DECORATOR.of(world);
|
||||
long first = decorators.decorators(meadow, DecorationPart.NONE)[0].seed();
|
||||
long second = decorators.decorators(meadow, DecorationPart.NONE)[1].seed();
|
||||
|
||||
assertEquals("biome meadow, index 0", DECORATOR_SEED + "meadow".hashCode() * 0x9E3779B97F4A7C15L, first);
|
||||
assertEquals("biome meadow, index 2", DECORATOR_SEED + "meadow".hashCode() * 0x9E3779B97F4A7C15L + 2 * 0xC2B2AE3D27D4EB4FL, second);
|
||||
assertEquals("biome meadow, index 0", decoratorSeed + "meadow".hashCode() * 0x9E3779B97F4A7C15L, first);
|
||||
assertEquals("biome meadow, index 2", decoratorSeed + "meadow".hashCode() * 0x9E3779B97F4A7C15L + 2 * 0xC2B2AE3D27D4EB4FL, second);
|
||||
assertNotEquals(first, second);
|
||||
assertEquals("another build of the same world draws the same seeds", first,
|
||||
seedOf(new BiomeDecorators(engine, ModuleLogs.discarding()).decorators(meadow, DecorationPart.NONE)[0]));
|
||||
new BiomeDecorators(world).decorators(meadow, DecorationPart.NONE)[0].seed());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void warmingResolvesEveryDecoratorOfEveryReachableBiome() {
|
||||
IrisDimension dimension = mock(IrisDimension.class);
|
||||
when(dimension.getReachableBiomes(engine)).thenReturn(new KList<>(List.of(meadow, bare)));
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
when(engine.getAllBiomes()).thenCallRealMethod();
|
||||
public void aBiomesKeyIsTheRestOfTheIdOfTheSettingsItDeclared() {
|
||||
assertEquals("desert/dunes", BiomeDecorators.biomeKey(ResourceId.parse("overworld:biome/desert/dunes")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void warmingResolvesEveryDecoratorOfEveryBiomeThePackDeclares() {
|
||||
decorators.warm();
|
||||
|
||||
assertEquals(2, decorators.decorators(meadow, DecorationPart.NONE).length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theBusiestBiomeSetsTheScaleOfTheLoadViews() {
|
||||
IrisDimension dimension = mock(IrisDimension.class);
|
||||
when(dimension.getReachableBiomes(engine)).thenReturn(new KList<>(List.of(meadow, bare)));
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
|
||||
assertEquals(0.5 + 3 * 1.0 + 0.25 + 1.0, decorators.load(meadow), 1e-9);
|
||||
assertEquals(decorators.load(meadow), decorators.busiestBiomeLoad(), 0);
|
||||
assertEquals((0.5 + 1.0 + 0.25 + 1.0) * 256, decorators.colourLoad(meadow), 1e-9);
|
||||
}
|
||||
|
||||
private IrisBiome biome(String key, String decoratorsJson) {
|
||||
List<Decorator> list = List.of(new Gson().fromJson(decoratorsJson, Decorator[].class));
|
||||
ModuleSettings settings = mock(ModuleSettings.class);
|
||||
when(settings.find(DecorantSettings.class)).thenReturn(Optional.of(new DecorantSettings(list)));
|
||||
IrisBiome biome = mock(IrisBiome.class);
|
||||
when(biome.getLoadKey()).thenReturn(key);
|
||||
when(biome.getModuleSettings()).thenReturn(settings);
|
||||
return biome;
|
||||
assertEquals(2, decorators.decorators(new DecoratedBiome("plains", chunk.world().settings().declared(DecorantSettings.class).getFirst().value(),
|
||||
BiomeKind.LAND), DecorationPart.NONE).length);
|
||||
}
|
||||
|
||||
private static List<Double> chances(ResolvedDecorator[] bucket) {
|
||||
return java.util.Arrays.stream(bucket).map(decorator -> decorator.settings().chance()).toList();
|
||||
}
|
||||
|
||||
private static long seedOf(ResolvedDecorator decorator) {
|
||||
return decorator.seed();
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,19 @@
|
||||
package art.arcane.iris.engine.decorator;
|
||||
|
||||
import art.arcane.iris.builtin.decorant.DecorationPart;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
import art.arcane.iris.engine.modifier.ApiChunk;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.host.ArrayHunk;
|
||||
import com.volmit.host.ModuleLogs;
|
||||
import org.bukkit.block.BlockSupport;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import com.volmit.hunk.Hunk;
|
||||
import com.volmit.mantle.BlockBox;
|
||||
import com.volmit.mantle.MantleLayer;
|
||||
import com.volmit.mantle.MantleVisitor;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
@@ -16,13 +21,16 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyDouble;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class DecoratorCoreTest {
|
||||
private static final BlockState AIR = ApiChunk.AIR;
|
||||
private static final BlockState GRASS_BLOCK = new BlockState("minecraft:grass_block");
|
||||
private static final BlockState STONE = new BlockState("minecraft:stone");
|
||||
private static final BlockState POPPY = new BlockState("minecraft:poppy");
|
||||
private static final BlockState TALL_GRASS = BlockState.parse("minecraft:tall_grass[half=lower]");
|
||||
|
||||
@Test
|
||||
public void partSeed_differsByPartOrdinal() {
|
||||
@@ -121,252 +129,182 @@ public class DecoratorCoreTest {
|
||||
@Test
|
||||
public void singleStackTargetsBlockAboveSupport() {
|
||||
ResolvedDecorator decorator = mock(ResolvedDecorator.class);
|
||||
PlatformBlockState support = sturdyState();
|
||||
PlatformBlockState air = mock(PlatformBlockState.class);
|
||||
PlatformBlockState decorant = mock(PlatformBlockState.class);
|
||||
when(air.isAir()).thenReturn(true);
|
||||
when(decorant.key()).thenReturn("minecraft:stone");
|
||||
when(decorant.canPlaceOnto(support)).thenReturn(true);
|
||||
when(decorator.stackHeight(anyDouble(), anyDouble())).thenReturn(1);
|
||||
when(decorator.pickTopBlock(anyDouble(), anyDouble())).thenReturn(decorant);
|
||||
when(decorator.pickTopBlock(anyDouble(), anyDouble())).thenReturn(POPPY);
|
||||
|
||||
Hunk<PlatformBlockState> output = Hunk.newArrayHunk(1, 4, 1);
|
||||
output.set(0, 1, 0, support);
|
||||
output.set(0, 2, 0, air);
|
||||
Hunk<BlockState> output = hunk(1, 4, 1);
|
||||
output.set(0, 1, 0, GRASS_BLOCK);
|
||||
DecoratorCore.PlaceOpts opts = new DecoratorCore.PlaceOpts();
|
||||
|
||||
DecoratorCore.placeStackUp(decorator, 0, 0, 0, 0, 1, 3, output, opts);
|
||||
DecoratorCore.placeStackUp(decorator, scene(output), 0, 0, 0, 0, 1, 3, opts);
|
||||
|
||||
assertSame(support, output.get(0, 1, 0));
|
||||
assertSame(decorant, output.get(0, 2, 0));
|
||||
assertSame(GRASS_BLOCK, output.get(0, 1, 0));
|
||||
assertSame(POPPY, output.get(0, 2, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleStackDoesNotOverwriteOccupiedTarget() {
|
||||
ResolvedDecorator decorator = mock(ResolvedDecorator.class);
|
||||
PlatformBlockState support = sturdyState();
|
||||
PlatformBlockState occupied = mock(PlatformBlockState.class);
|
||||
PlatformBlockState decorant = mock(PlatformBlockState.class);
|
||||
when(occupied.isAir()).thenReturn(false);
|
||||
when(occupied.isFluid()).thenReturn(false);
|
||||
when(decorator.stackHeight(anyDouble(), anyDouble())).thenReturn(1);
|
||||
when(decorator.pickTopBlock(anyDouble(), anyDouble())).thenReturn(decorant);
|
||||
when(decorator.pickTopBlock(anyDouble(), anyDouble())).thenReturn(POPPY);
|
||||
|
||||
Hunk<PlatformBlockState> output = Hunk.newArrayHunk(1, 4, 1);
|
||||
output.set(0, 1, 0, support);
|
||||
output.set(0, 2, 0, occupied);
|
||||
DecoratorCore.PlaceOpts opts = new DecoratorCore.PlaceOpts();
|
||||
Hunk<BlockState> output = hunk(1, 4, 1);
|
||||
output.set(0, 1, 0, GRASS_BLOCK);
|
||||
output.set(0, 2, 0, STONE);
|
||||
|
||||
DecoratorCore.placeStackUp(decorator, 0, 0, 0, 0, 1, 3, output, opts);
|
||||
DecoratorCore.placeStackUp(decorator, scene(output), 0, 0, 0, 0, 1, 3, new DecoratorCore.PlaceOpts());
|
||||
|
||||
assertSame(support, output.get(0, 1, 0));
|
||||
assertSame(occupied, output.get(0, 2, 0));
|
||||
assertSame(GRASS_BLOCK, output.get(0, 1, 0));
|
||||
assertSame(STONE, output.get(0, 2, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multiStackStopsBeforeOccupiedTarget() {
|
||||
ResolvedDecorator decorator = mock(ResolvedDecorator.class);
|
||||
PlatformBlockState support = sturdyState();
|
||||
PlatformBlockState air = mock(PlatformBlockState.class);
|
||||
PlatformBlockState occupied = mock(PlatformBlockState.class);
|
||||
PlatformBlockState decorant = mock(PlatformBlockState.class);
|
||||
when(air.isAir()).thenReturn(true);
|
||||
when(occupied.isAir()).thenReturn(false);
|
||||
when(occupied.isFluid()).thenReturn(false);
|
||||
when(decorant.key()).thenReturn("minecraft:tall_grass");
|
||||
when(decorant.canPlaceOnto(support)).thenReturn(true);
|
||||
BlockState decorant = new BlockState("minecraft:tall_grass");
|
||||
when(decorator.stackHeight(anyDouble(), anyDouble())).thenReturn(3);
|
||||
when(decorator.topThreshold()).thenReturn(0.75);
|
||||
when(decorator.pickBlock(anyDouble(), anyDouble())).thenReturn(decorant);
|
||||
when(decorator.pickTopBlock(anyDouble(), anyDouble())).thenReturn(decorant);
|
||||
|
||||
Hunk<PlatformBlockState> output = Hunk.newArrayHunk(1, 5, 1);
|
||||
output.set(0, 1, 0, support);
|
||||
output.set(0, 2, 0, air);
|
||||
output.set(0, 3, 0, occupied);
|
||||
output.set(0, 4, 0, air);
|
||||
DecoratorCore.PlaceOpts opts = new DecoratorCore.PlaceOpts();
|
||||
Hunk<BlockState> output = hunk(1, 5, 1);
|
||||
output.set(0, 1, 0, GRASS_BLOCK);
|
||||
output.set(0, 3, 0, STONE);
|
||||
|
||||
DecoratorCore.placeStackUp(decorator, 0, 0, 0, 0, 1, 4, output, opts);
|
||||
DecoratorCore.placeStackUp(decorator, scene(output), 0, 0, 0, 0, 1, 4, new DecoratorCore.PlaceOpts());
|
||||
|
||||
assertSame(decorant, output.get(0, 2, 0));
|
||||
assertSame(occupied, output.get(0, 3, 0));
|
||||
assertSame(air, output.get(0, 4, 0));
|
||||
assertSame(STONE, output.get(0, 3, 0));
|
||||
assertSame(AIR, output.get(0, 4, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void descendingStackStopsAtLocalWorldFloor() {
|
||||
ResolvedDecorator decorator = mock(ResolvedDecorator.class);
|
||||
PlatformBlockState decorant = mock(PlatformBlockState.class);
|
||||
when(decorant.key()).thenReturn("minecraft:stone");
|
||||
when(decorator.stackHeight(anyDouble(), anyDouble())).thenReturn(2);
|
||||
when(decorator.topThreshold()).thenReturn(1.0);
|
||||
when(decorator.pickBlock(anyDouble(), anyDouble())).thenReturn(decorant);
|
||||
when(decorator.pickTopBlock(anyDouble(), anyDouble())).thenReturn(decorant);
|
||||
when(decorator.pickBlock(anyDouble(), anyDouble())).thenReturn(STONE);
|
||||
when(decorator.pickTopBlock(anyDouble(), anyDouble())).thenReturn(STONE);
|
||||
|
||||
Hunk<PlatformBlockState> output = Hunk.newArrayHunk(1, 2, 1);
|
||||
DecoratorCore.PlaceOpts opts = new DecoratorCore.PlaceOpts();
|
||||
Hunk<BlockState> output = hunk(1, 2, 1);
|
||||
|
||||
DecoratorCore.placeStackDown(
|
||||
decorator, 0, 0, 0, 0, 0, -64, output, 2, opts, null);
|
||||
DecoratorCore.placeStackDown(decorator, scene(output), 0, 0, 0, 0, 0, -64, 2, new DecoratorCore.PlaceOpts());
|
||||
|
||||
assertSame(decorant, output.get(0, 0, 0));
|
||||
assertSame(STONE, output.get(0, 0, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleDescendingStackPreservesTargetWhenPickIsNull() {
|
||||
ResolvedDecorator decorator = mock(ResolvedDecorator.class);
|
||||
PlatformBlockState existing = mock(PlatformBlockState.class);
|
||||
when(decorator.stackHeight(anyDouble(), anyDouble())).thenReturn(1);
|
||||
|
||||
Hunk<PlatformBlockState> output = Hunk.newArrayHunk(1, 2, 1);
|
||||
output.set(0, 0, 0, existing);
|
||||
DecoratorCore.PlaceOpts opts = new DecoratorCore.PlaceOpts();
|
||||
Hunk<BlockState> output = hunk(1, 2, 1);
|
||||
output.set(0, 0, 0, STONE);
|
||||
|
||||
DecoratorCore.placeStackDown(
|
||||
decorator, 0, 0, 0, 0, 0, 0, output, 1, opts, null);
|
||||
DecoratorCore.placeStackDown(decorator, scene(output), 0, 0, 0, 0, 0, 0, 1, new DecoratorCore.PlaceOpts());
|
||||
|
||||
assertSame(existing, output.get(0, 0, 0));
|
||||
assertSame(STONE, output.get(0, 0, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multiDescendingStackStopsWhenPickIsNull() {
|
||||
ResolvedDecorator decorator = mock(ResolvedDecorator.class);
|
||||
PlatformBlockState lowerExisting = mock(PlatformBlockState.class);
|
||||
PlatformBlockState upperExisting = mock(PlatformBlockState.class);
|
||||
when(decorator.stackHeight(anyDouble(), anyDouble())).thenReturn(2);
|
||||
when(decorator.topThreshold()).thenReturn(1.0);
|
||||
|
||||
Hunk<PlatformBlockState> output = Hunk.newArrayHunk(1, 2, 1);
|
||||
output.set(0, 0, 0, lowerExisting);
|
||||
output.set(0, 1, 0, upperExisting);
|
||||
DecoratorCore.PlaceOpts opts = new DecoratorCore.PlaceOpts();
|
||||
Hunk<BlockState> output = hunk(1, 2, 1);
|
||||
output.set(0, 0, 0, STONE);
|
||||
output.set(0, 1, 0, GRASS_BLOCK);
|
||||
|
||||
DecoratorCore.placeStackDown(
|
||||
decorator, 0, 0, 0, 0, 1, 0, output, 2, opts, null);
|
||||
DecoratorCore.placeStackDown(decorator, scene(output), 0, 0, 0, 0, 1, 0, 2, new DecoratorCore.PlaceOpts());
|
||||
|
||||
assertSame(lowerExisting, output.get(0, 0, 0));
|
||||
assertSame(upperExisting, output.get(0, 1, 0));
|
||||
assertSame(STONE, output.get(0, 0, 0));
|
||||
assertSame(GRASS_BLOCK, output.get(0, 1, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void floatingStackStopsAtHunkCeiling() {
|
||||
ResolvedDecorator decorator = mock(ResolvedDecorator.class);
|
||||
PlatformBlockState decorant = mock(PlatformBlockState.class);
|
||||
when(decorant.key()).thenReturn("minecraft:stone");
|
||||
when(decorator.stackHeight(anyDouble(), anyDouble())).thenReturn(3);
|
||||
when(decorator.topThreshold()).thenReturn(1.0);
|
||||
when(decorator.pickBlock(anyDouble(), anyDouble())).thenReturn(decorant);
|
||||
when(decorator.pickTopBlock(anyDouble(), anyDouble())).thenReturn(decorant);
|
||||
when(decorator.pickBlock(anyDouble(), anyDouble())).thenReturn(STONE);
|
||||
when(decorator.pickTopBlock(anyDouble(), anyDouble())).thenReturn(STONE);
|
||||
|
||||
Hunk<PlatformBlockState> output = Hunk.newArrayHunk(1, 2, 1);
|
||||
int placed = DecoratorCore.placeFloatingStacked(
|
||||
decorator, 0, 0, 0, 0, 0, 3, output);
|
||||
Hunk<BlockState> output = hunk(1, 2, 1);
|
||||
int placed = DecoratorCore.placeFloatingStacked(decorator, scene(output), 0, 0, 0, 0, 0, 3);
|
||||
|
||||
assertEquals(1, placed);
|
||||
assertSame(decorant, output.get(0, 1, 0));
|
||||
assertSame(STONE, output.get(0, 1, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tallSurfacePlantDoesNotPlaceWhenUpperTargetIsOccupied() {
|
||||
ResolvedDecorator decorator = mock(ResolvedDecorator.class);
|
||||
PlatformBlockState support = sturdyState();
|
||||
PlatformBlockState air = airState();
|
||||
PlatformBlockState occupied = mock(PlatformBlockState.class);
|
||||
PlatformBlockState plant = tallPlantState();
|
||||
when(decorator.pickBlock(anyDouble(), anyDouble())).thenReturn(plant);
|
||||
when(decorator.pickBlock(anyDouble(), anyDouble())).thenReturn(TALL_GRASS);
|
||||
|
||||
Hunk<PlatformBlockState> output = Hunk.newArrayHunk(1, 4, 1);
|
||||
output.set(0, 0, 0, support);
|
||||
output.set(0, 1, 0, air);
|
||||
output.set(0, 2, 0, occupied);
|
||||
Hunk<BlockState> output = hunk(1, 4, 1);
|
||||
output.set(0, 0, 0, GRASS_BLOCK);
|
||||
output.set(0, 2, 0, STONE);
|
||||
|
||||
DecoratorCore.placeSurfaceSingle(
|
||||
decorator, 0, 0, 0, 0, 0, output, false, false, null, ModuleLogs.discarding());
|
||||
DecoratorCore.placeSurfaceSingle(decorator, scene(output), 0, 0, 0, 0, 0, false, false);
|
||||
|
||||
assertSame(air, output.get(0, 1, 0));
|
||||
assertSame(occupied, output.get(0, 2, 0));
|
||||
assertSame(AIR, output.get(0, 1, 0));
|
||||
assertSame(STONE, output.get(0, 2, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tallFloatingPlantDoesNotPlaceWhenUpperTargetIsOccupied() {
|
||||
ResolvedDecorator decorator = mock(ResolvedDecorator.class);
|
||||
PlatformBlockState air = airState();
|
||||
PlatformBlockState occupied = mock(PlatformBlockState.class);
|
||||
PlatformBlockState plant = tallPlantState();
|
||||
when(decorator.pickBlock(anyDouble(), anyDouble())).thenReturn(plant);
|
||||
when(decorator.pickBlock(anyDouble(), anyDouble())).thenReturn(TALL_GRASS);
|
||||
|
||||
Hunk<PlatformBlockState> output = Hunk.newArrayHunk(1, 4, 1);
|
||||
output.set(0, 1, 0, air);
|
||||
output.set(0, 2, 0, occupied);
|
||||
Hunk<BlockState> output = hunk(1, 4, 1);
|
||||
output.set(0, 2, 0, STONE);
|
||||
|
||||
DecoratorCore.placeFloatingSimple(
|
||||
decorator, 0, 0, 0, 0, 0, 3, output, ModuleLogs.discarding());
|
||||
DecoratorCore.placeFloatingSimple(decorator, scene(output), 0, 0, 0, 0, 0, 3);
|
||||
|
||||
assertSame(air, output.get(0, 1, 0));
|
||||
assertSame(occupied, output.get(0, 2, 0));
|
||||
assertSame(AIR, output.get(0, 1, 0));
|
||||
assertSame(STONE, output.get(0, 2, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tallSurfacePlantPlacesBothHalvesTogether() {
|
||||
ResolvedDecorator decorator = mock(ResolvedDecorator.class);
|
||||
PlatformBlockState support = sturdyState();
|
||||
PlatformBlockState lowerAir = airState();
|
||||
PlatformBlockState upperAir = airState();
|
||||
PlatformBlockState lower = mock(PlatformBlockState.class);
|
||||
PlatformBlockState upper = mock(PlatformBlockState.class);
|
||||
PlatformBlockState plant = tallPlantState(lower, upper);
|
||||
when(plant.canPlaceOnto(support)).thenReturn(true);
|
||||
when(decorator.pickBlock(anyDouble(), anyDouble())).thenReturn(plant);
|
||||
when(decorator.pickBlock(anyDouble(), anyDouble())).thenReturn(TALL_GRASS);
|
||||
|
||||
Hunk<PlatformBlockState> output = Hunk.newArrayHunk(1, 4, 1);
|
||||
output.set(0, 0, 0, support);
|
||||
output.set(0, 1, 0, lowerAir);
|
||||
output.set(0, 2, 0, upperAir);
|
||||
Hunk<BlockState> output = hunk(1, 4, 1);
|
||||
output.set(0, 0, 0, GRASS_BLOCK);
|
||||
|
||||
DecoratorCore.placeSurfaceSingle(
|
||||
decorator, 0, 0, 0, 0, 0, output, false, false, null, ModuleLogs.discarding());
|
||||
DecoratorCore.placeSurfaceSingle(decorator, scene(output), 0, 0, 0, 0, 0, false, false);
|
||||
|
||||
assertSame(lower, output.get(0, 1, 0));
|
||||
assertSame(upper, output.get(0, 2, 0));
|
||||
assertEquals(BlockState.parse("minecraft:tall_grass[half=lower]"), output.get(0, 1, 0));
|
||||
assertEquals(BlockState.parse("minecraft:tall_grass[half=upper]"), output.get(0, 2, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void surfaceDecorantRejectsInvalidNativeSupport() {
|
||||
public void surfaceDecorantRejectsInvalidSupport() {
|
||||
ResolvedDecorator decorator = mock(ResolvedDecorator.class);
|
||||
PlatformBlockState support = sturdyState();
|
||||
PlatformBlockState air = airState();
|
||||
PlatformBlockState decorant = mock(PlatformBlockState.class);
|
||||
when(decorant.canPlaceOnto(support)).thenReturn(false);
|
||||
when(decorator.pickBlock(anyDouble(), anyDouble())).thenReturn(decorant);
|
||||
when(decorator.pickBlock(anyDouble(), anyDouble())).thenReturn(POPPY);
|
||||
|
||||
Hunk<PlatformBlockState> output = Hunk.newArrayHunk(1, 3, 1);
|
||||
output.set(0, 0, 0, support);
|
||||
output.set(0, 1, 0, air);
|
||||
Hunk<BlockState> output = hunk(1, 3, 1);
|
||||
output.set(0, 0, 0, STONE);
|
||||
|
||||
DecoratorCore.placeSurfaceSingle(
|
||||
decorator, 0, 0, 0, 0, 0, output, false, false, null, ModuleLogs.discarding());
|
||||
DecoratorCore.placeSurfaceSingle(decorator, scene(output), 0, 0, 0, 0, 0, false, false);
|
||||
|
||||
assertSame(air, output.get(0, 1, 0));
|
||||
assertSame(AIR, output.get(0, 1, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forcedSurfaceBlockStillPlacesDecorantAboveIt() {
|
||||
ResolvedDecorator decorator = mock(ResolvedDecorator.class);
|
||||
PlatformBlockState support = sturdyState();
|
||||
PlatformBlockState farmland = sturdyState();
|
||||
PlatformBlockState air = airState();
|
||||
PlatformBlockState wheat = mock(PlatformBlockState.class);
|
||||
when(wheat.key()).thenReturn("minecraft:wheat[age=7]");
|
||||
BlockState farmland = new BlockState("minecraft:farmland");
|
||||
BlockState wheat = BlockState.parse("minecraft:wheat[age=7]");
|
||||
when(decorator.forceBlock()).thenReturn(farmland);
|
||||
when(decorator.pickBlock(anyDouble(), anyDouble())).thenReturn(wheat);
|
||||
|
||||
Hunk<PlatformBlockState> output = Hunk.newArrayHunk(1, 3, 1);
|
||||
output.set(0, 0, 0, support);
|
||||
output.set(0, 1, 0, air);
|
||||
Hunk<BlockState> output = hunk(1, 3, 1);
|
||||
output.set(0, 0, 0, STONE);
|
||||
|
||||
DecoratorCore.placeSurfaceSingle(
|
||||
decorator, 0, 0, 0, 0, 0, output, false, false, null, ModuleLogs.discarding());
|
||||
DecoratorCore.placeSurfaceSingle(decorator, scene(output), 0, 0, 0, 0, 0, false, false);
|
||||
|
||||
assertSame(farmland, output.get(0, 0, 0));
|
||||
assertSame(wheat, output.get(0, 1, 0));
|
||||
@@ -374,69 +312,104 @@ public class DecoratorCoreTest {
|
||||
|
||||
@Test
|
||||
public void descendingWeepingVinesUsePlantBodiesAndOneFreeEndTip() {
|
||||
PlatformBlockState vine = mock(PlatformBlockState.class);
|
||||
when(vine.key()).thenReturn("minecraft:weeping_vines");
|
||||
BlockState vine = new BlockState("minecraft:weeping_vines");
|
||||
|
||||
assertEquals("minecraft:weeping_vines_plant", DecoratorCore.stackedVineKey(vine, 3, 0));
|
||||
assertEquals("minecraft:weeping_vines_plant", DecoratorCore.stackedVineKey(vine, 3, 1));
|
||||
assertEquals("minecraft:weeping_vines", DecoratorCore.stackedVineKey(vine, 3, 2));
|
||||
assertEquals("minecraft:weeping_vines_plant", DecoratorCore.stackedVineMaterial(vine, 3, 0).toString());
|
||||
assertEquals("minecraft:weeping_vines_plant", DecoratorCore.stackedVineMaterial(vine, 3, 1).toString());
|
||||
assertEquals("minecraft:weeping_vines", DecoratorCore.stackedVineMaterial(vine, 3, 2).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ascendingTwistingVinesUsePlantBodiesAndOneFreeEndTip() {
|
||||
PlatformBlockState vine = mock(PlatformBlockState.class);
|
||||
when(vine.key()).thenReturn("minecraft:twisting_vines_plant");
|
||||
BlockState vine = new BlockState("minecraft:twisting_vines_plant");
|
||||
|
||||
assertEquals("minecraft:twisting_vines_plant", DecoratorCore.stackedVineKey(vine, 3, 0));
|
||||
assertEquals("minecraft:twisting_vines_plant", DecoratorCore.stackedVineKey(vine, 3, 1));
|
||||
assertEquals("minecraft:twisting_vines", DecoratorCore.stackedVineKey(vine, 3, 2));
|
||||
assertEquals("minecraft:twisting_vines_plant", DecoratorCore.stackedVineMaterial(vine, 3, 0).toString());
|
||||
assertEquals("minecraft:twisting_vines_plant", DecoratorCore.stackedVineMaterial(vine, 3, 1).toString());
|
||||
assertEquals("minecraft:twisting_vines", DecoratorCore.stackedVineMaterial(vine, 3, 2).toString());
|
||||
assertNull(DecoratorCore.stackedVineMaterial(STONE, 3, 2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void boundDecoratorHooksWinWhenBukkitClassesArePresent() {
|
||||
PlatformBlockState vine = mock(PlatformBlockState.class);
|
||||
PlatformBlockState fixed = mock(PlatformBlockState.class);
|
||||
PlatformBlockState decorator = mock(PlatformBlockState.class);
|
||||
PlatformBlockState surface = mock(PlatformBlockState.class);
|
||||
Hunk<PlatformBlockState> output = Hunk.newArrayHunk(1, 1, 1);
|
||||
DecoratorPlatformHooks.FaceFixer faceFixer = mock(DecoratorPlatformHooks.FaceFixer.class);
|
||||
DecoratorPlatformHooks.SurfaceSturdiness sturdiness = mock(DecoratorPlatformHooks.SurfaceSturdiness.class);
|
||||
when(vine.isVineBlock()).thenReturn(true);
|
||||
when(faceFixer.fixFaces(vine, output, 0, 0, 0, 0, 0, null)).thenReturn(fixed);
|
||||
when(decorator.canPlaceOnto(surface)).thenReturn(true);
|
||||
when(sturdiness.canGoOn(surface)).thenReturn(true);
|
||||
DecoratorPlatformHooks.Bindings previous = DecoratorPlatformHooks.bind(faceFixer, sturdiness);
|
||||
try {
|
||||
assertSame(fixed, DecoratorCore.fixFacesForHunk(vine, output, 0, 0, 0, 0, 0, null));
|
||||
assertTrue(DecoratorCore.canGoOn(decorator, surface));
|
||||
} finally {
|
||||
DecoratorPlatformHooks.restore(previous);
|
||||
public void aVineFacesTheNeighboursThatCanHoldIt() {
|
||||
Hunk<BlockState> output = hunk(3, 3, 3);
|
||||
output.set(2, 1, 1, STONE);
|
||||
|
||||
BlockState fixed = DecoratorCore.fixFacesForHunk(scene(output), vine(), 1, 1, 1, 1, 1);
|
||||
|
||||
assertEquals("true", fixed.properties().get("east"));
|
||||
for (String face : new String[]{"north", "south", "west", "up", "down"}) {
|
||||
assertEquals(face, "false", fixed.properties().get(face));
|
||||
}
|
||||
}
|
||||
|
||||
private PlatformBlockState airState() {
|
||||
PlatformBlockState air = mock(PlatformBlockState.class);
|
||||
when(air.isAir()).thenReturn(true);
|
||||
return air;
|
||||
@Test
|
||||
public void aVineHeldByBlocksThePlannedMantleHoldsOutsideTheChunkFacesThem() {
|
||||
Hunk<BlockState> output = hunk(3, 3, 3);
|
||||
Map<String, BlockState> planned = new HashMap<>();
|
||||
planned.put("-1,1,1", STONE);
|
||||
|
||||
BlockState fixed = DecoratorCore.fixFacesForHunk(scene(output, plannedLayer(planned)), vine(), 0, 1, 0, 1, 1);
|
||||
|
||||
assertEquals("true", fixed.properties().get("west"));
|
||||
assertEquals("false", fixed.properties().get("east"));
|
||||
}
|
||||
|
||||
private PlatformBlockState tallPlantState() {
|
||||
return tallPlantState(mock(PlatformBlockState.class), mock(PlatformBlockState.class));
|
||||
@Test
|
||||
public void aVineNothingHoldsFacesDown() {
|
||||
BlockState fixed = DecoratorCore.fixFacesForHunk(scene(hunk(3, 3, 3)), vine(), 1, 1, 1, 1, 1);
|
||||
|
||||
assertEquals("true", fixed.properties().get("down"));
|
||||
assertEquals("false", fixed.properties().get("up"));
|
||||
}
|
||||
|
||||
private PlatformBlockState tallPlantState(PlatformBlockState lower, PlatformBlockState upper) {
|
||||
PlatformBlockState plant = mock(PlatformBlockState.class);
|
||||
when(plant.key()).thenReturn("minecraft:tall_grass[half=lower]");
|
||||
when(plant.withProperty("half", "lower")).thenReturn(lower);
|
||||
when(plant.withProperty("half", "upper")).thenReturn(upper);
|
||||
return plant;
|
||||
@Test
|
||||
public void otherBlocksAreNotFaced() {
|
||||
assertSame(STONE, DecoratorCore.fixFacesForHunk(scene(hunk(1, 1, 1)), STONE, 0, 0, 0, 0, 0));
|
||||
}
|
||||
|
||||
private PlatformBlockState sturdyState() {
|
||||
PlatformBlockState support = mock(PlatformBlockState.class);
|
||||
BlockData blockData = mock(BlockData.class);
|
||||
when(support.nativeHandle()).thenReturn(blockData);
|
||||
when(blockData.isFaceSturdy(any(), eq(BlockSupport.FULL))).thenReturn(true);
|
||||
return support;
|
||||
private static BlockState vine() {
|
||||
return BlockState.parse("minecraft:vine[down=false,east=false,north=false,south=false,up=false,west=false]");
|
||||
}
|
||||
|
||||
private static Hunk<BlockState> hunk(int width, int height, int depth) {
|
||||
return new ArrayHunk<>(BlockState.class, width, height, depth, AIR);
|
||||
}
|
||||
|
||||
private static DecorationScene scene(Hunk<BlockState> blocks) {
|
||||
return scene(blocks, null);
|
||||
}
|
||||
|
||||
private static DecorationScene scene(Hunk<BlockState> blocks, MantleLayer<BlockState> planned) {
|
||||
return new DecorationScene(blocks, ApiChunk.blocks(), null, planned, null, 1L, ModuleLogs.discarding());
|
||||
}
|
||||
|
||||
/** Blocks planned at "x,y,z" in world coordinates; everywhere else reads none. */
|
||||
private static MantleLayer<BlockState> plannedLayer(Map<String, BlockState> planned) {
|
||||
return new MantleLayer<>() {
|
||||
@Override
|
||||
public BlockState get(int x, int y, int z) {
|
||||
return planned.get(x + "," + y + "," + z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int x, int y, int z, BlockState value) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(int x, int y, int z) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(BlockBox area, MantleVisitor<BlockState> visitor) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear(BlockBox area) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -21,9 +21,4 @@ public final class DecoratorTestEngines {
|
||||
when(engine.getGeneration()).thenReturn(generation);
|
||||
return generation;
|
||||
}
|
||||
|
||||
/** Makes {@code engine} keep {@code decorators} as its world's decorators. */
|
||||
static void keepDecorators(Engine engine, BiomeDecorators decorators) {
|
||||
withGeneration(engine).state(BiomeDecorators.class, ignored -> decorators);
|
||||
}
|
||||
}
|
||||
+27
-38
@@ -1,34 +1,29 @@
|
||||
package art.arcane.iris.engine.decorator;
|
||||
|
||||
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.object.world.biome.InferredType;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.builtin.decorant.DecorationPart;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
import art.arcane.iris.engine.modifier.ApiChunk;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.host.ArrayHunk;
|
||||
import com.volmit.host.ModuleLogs;
|
||||
import com.volmit.hunk.Hunk;
|
||||
import com.volmit.world.BiomeKind;
|
||||
import com.volmit.world.TerrainSampler;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyDouble;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
public class IrisDecoratorCaveContextTest {
|
||||
private static final int FLUID_HEIGHT = 63;
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void explicitCaveContextSkipsFluidWithoutMutatingBiome() {
|
||||
Engine engine = mock(Engine.class);
|
||||
SeedManager seedManager = mock(SeedManager.class);
|
||||
doReturn(seedManager).when(engine).getSeedManager();
|
||||
doReturn(mock(IrisData.class)).when(engine).getData();
|
||||
IrisDimension dimension = mock(IrisDimension.class);
|
||||
doReturn(63).when(dimension).getFluidHeight();
|
||||
doReturn(dimension).when(engine).getDimension();
|
||||
public void explicitCaveContextSkipsFluid() {
|
||||
TerrainSampler terrain = mock(TerrainSampler.class);
|
||||
doReturn(FLUID_HEIGHT).when(terrain).fluidHeight();
|
||||
|
||||
ResolvedDecorator decorator = mock(ResolvedDecorator.class);
|
||||
doReturn(true).when(decorator).passesChanceGate(anyDouble(), anyDouble());
|
||||
@@ -36,35 +31,29 @@ public class IrisDecoratorCaveContextTest {
|
||||
doReturn(true).when(decorator).isForcePlace();
|
||||
doReturn(1).when(decorator).stackHeight(anyDouble(), anyDouble());
|
||||
|
||||
IrisBiome biome = mock(IrisBiome.class);
|
||||
doReturn(InferredType.LAND).when(biome).getInferredType();
|
||||
DecoratedBiome cave = new DecoratedBiome("cave", null, BiomeKind.CAVE);
|
||||
BiomeDecorators decorators = mock(BiomeDecorators.class);
|
||||
doReturn(new ResolvedDecorator[]{decorator}).when(decorators).decorators(biome, DecorationPart.NONE);
|
||||
doReturn(new ResolvedDecorator[]{decorator}).when(decorators).decorators(biome, DecorationPart.CEILING);
|
||||
DecoratorTestEngines.keepDecorators(engine, decorators);
|
||||
doReturn(new ResolvedDecorator[]{decorator}).when(decorators).decorators(cave, DecorationPart.NONE);
|
||||
doReturn(new ResolvedDecorator[]{decorator}).when(decorators).decorators(cave, DecorationPart.CEILING);
|
||||
|
||||
PlatformBlockState fluid = mock(PlatformBlockState.class);
|
||||
doReturn(true).when(fluid).isFluid();
|
||||
Hunk<PlatformBlockState> output = mock(Hunk.class);
|
||||
doReturn(128).when(output).getHeight();
|
||||
doReturn(fluid).when(output).get(0, 10, 0);
|
||||
Hunk<BlockState> output = new ArrayHunk<>(BlockState.class, 1, 128, 1, new BlockState("minecraft:water"));
|
||||
DecorationScene scene = new DecorationScene(output, ApiChunk.blocks(), terrain, null, decorators, 1L, ModuleLogs.discarding());
|
||||
|
||||
IrisSurfaceDecorator surfaceDecorator = new IrisSurfaceDecorator(engine);
|
||||
surfaceDecorator.decorate(0, 0, 0, 0, 0, 0, 0, 0, output, biome, InferredType.CAVE, 10, 10);
|
||||
new IrisSurfaceDecorator(scene).decorate(0, 0, 0, 0, 0, 0, 0, 0, cave, 10, 10);
|
||||
DecoratorCore.PlaceOpts surfaceOptions = DecoratorCore.SCRATCH_OPTS.get();
|
||||
assertTrue(surfaceOptions.caveSkipFluid);
|
||||
assertFalse(surfaceOptions.underwater);
|
||||
|
||||
IrisCeilingDecorator ceilingDecorator = new IrisCeilingDecorator(engine);
|
||||
ceilingDecorator.decorate(0, 0, 0, 0, 0, 0, 0, 0, output, biome, InferredType.CAVE, 10, 10);
|
||||
DecoratorCore.PlaceOpts ceilingOptions = DecoratorCore.SCRATCH_OPTS.get();
|
||||
assertTrue(ceilingOptions.caveSkipFluid);
|
||||
assertEquals(InferredType.LAND, biome.getInferredType());
|
||||
new IrisCeilingDecorator(scene).decorate(0, 0, 0, 0, 0, 0, 0, 0, cave, 10, 10);
|
||||
assertTrue(DecoratorCore.SCRATCH_OPTS.get().caveSkipFluid);
|
||||
assertSame(BiomeKind.CAVE, cave.kind());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullInferenceRemainsSafeForNormalSurfaceContext() {
|
||||
assertTrue(IrisSurfaceDecorator.isUnderwater(null, 10, 63));
|
||||
assertFalse(IrisSurfaceDecorator.skipsFluid(null));
|
||||
public void aSurfaceBiomeIsUnderwaterBelowTheFluidAndNeverSkipsFluid() {
|
||||
assertTrue(IrisSurfaceDecorator.isUnderwater(BiomeKind.LAND, 10, FLUID_HEIGHT));
|
||||
assertFalse(IrisSurfaceDecorator.isUnderwater(BiomeKind.CAVE, 10, FLUID_HEIGHT));
|
||||
assertFalse(IrisSurfaceDecorator.skipsFluid(BiomeKind.SEA));
|
||||
assertTrue(IrisSurfaceDecorator.skipsFluid(BiomeKind.CAVE));
|
||||
}
|
||||
}
|
||||
+41
-94
@@ -1,23 +1,18 @@
|
||||
package art.arcane.iris.engine.decorator;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.IrisComplex;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.SeedManager;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.builtin.decorant.DecorationPart;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
import art.arcane.iris.util.project.stream.ProceduralStream;
|
||||
import org.bukkit.block.BlockSupport;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import art.arcane.iris.engine.modifier.ApiChunk;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.host.ArrayHunk;
|
||||
import com.volmit.host.ModuleLogs;
|
||||
import com.volmit.hunk.Hunk;
|
||||
import com.volmit.world.BiomeKind;
|
||||
import com.volmit.world.TerrainSampler;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyDouble;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -25,123 +20,75 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
public class IrisShoreLineDecoratorTest {
|
||||
private static final int FLUID_HEIGHT = 4;
|
||||
private static final BlockState AIR = ApiChunk.AIR;
|
||||
private static final BlockState GRASS_BLOCK = new BlockState("minecraft:grass_block");
|
||||
private static final BlockState WATER = new BlockState("minecraft:water");
|
||||
private static final BlockState POPPY = new BlockState("minecraft:poppy");
|
||||
private static final DecoratedBiome BIOME = new DecoratedBiome("shore", null, BiomeKind.SHORE);
|
||||
|
||||
@Test
|
||||
public void carvedSurfaceRejectsShorelineDecoration() {
|
||||
Fixture fixture = createFixture(false);
|
||||
PlatformBlockState carvedAir = airState();
|
||||
PlatformBlockState targetAir = airState();
|
||||
Hunk<PlatformBlockState> output = output(carvedAir, targetAir);
|
||||
Hunk<BlockState> output = fixture.withSupport(AIR);
|
||||
|
||||
fixture.shoreline.decorate(0, 0, 0, 1, -1, 0, 1, -1,
|
||||
output, fixture.biome, FLUID_HEIGHT, output.getHeight());
|
||||
fixture.shoreline.decorate(0, 0, 0, 1, -1, 0, 1, -1, BIOME, FLUID_HEIGHT, output.getHeight());
|
||||
|
||||
assertSame(targetAir, output.get(0, FLUID_HEIGHT + 1, 0));
|
||||
assertSame(AIR, output.get(0, FLUID_HEIGHT + 1, 0));
|
||||
verify(fixture.decorator).passesChanceGate(anyDouble(), anyDouble());
|
||||
verify(fixture.decorator, never()).blockAt(eq(fixture.biome), anyDouble(), anyDouble(), anyDouble());
|
||||
verify(fixture.decorator, never()).blockAt(anyDouble(), anyDouble(), anyDouble());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preservedFluidRejectsShorelineDecoration() {
|
||||
Fixture fixture = createFixture(false);
|
||||
PlatformBlockState fluid = mock(PlatformBlockState.class);
|
||||
PlatformBlockState targetAir = airState();
|
||||
when(fluid.isFluid()).thenReturn(true);
|
||||
Hunk<PlatformBlockState> output = output(fluid, targetAir);
|
||||
Hunk<BlockState> output = fixture.withSupport(WATER);
|
||||
|
||||
fixture.shoreline.decorate(0, 0, 0, 1, -1, 0, 1, -1,
|
||||
output, fixture.biome, FLUID_HEIGHT, output.getHeight());
|
||||
fixture.shoreline.decorate(0, 0, 0, 1, -1, 0, 1, -1, BIOME, FLUID_HEIGHT, output.getHeight());
|
||||
|
||||
assertSame(targetAir, output.get(0, FLUID_HEIGHT + 1, 0));
|
||||
verify(fixture.decorator, never()).blockAt(eq(fixture.biome), anyDouble(), anyDouble(), anyDouble());
|
||||
assertSame(AIR, output.get(0, FLUID_HEIGHT + 1, 0));
|
||||
verify(fixture.decorator, never()).blockAt(anyDouble(), anyDouble(), anyDouble());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sturdySurfacePlacesShorelineDecoration() {
|
||||
Fixture fixture = createFixture(false);
|
||||
PlatformBlockState support = sturdyState();
|
||||
PlatformBlockState targetAir = airState();
|
||||
when(fixture.decorant.canPlaceOnto(support)).thenReturn(true);
|
||||
Hunk<PlatformBlockState> output = output(support, targetAir);
|
||||
Hunk<BlockState> output = fixture.withSupport(GRASS_BLOCK);
|
||||
|
||||
fixture.shoreline.decorate(0, 0, 0, 1, -1, 0, 1, -1,
|
||||
output, fixture.biome, FLUID_HEIGHT, output.getHeight());
|
||||
fixture.shoreline.decorate(0, 0, 0, 1, -1, 0, 1, -1, BIOME, FLUID_HEIGHT, output.getHeight());
|
||||
|
||||
assertSame(fixture.decorant, output.get(0, FLUID_HEIGHT + 1, 0));
|
||||
assertSame(POPPY, output.get(0, FLUID_HEIGHT + 1, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forcePlaceStillRejectsMissingSurface() {
|
||||
Fixture fixture = createFixture(true);
|
||||
PlatformBlockState targetAir = airState();
|
||||
Hunk<PlatformBlockState> output = output(airState(), targetAir);
|
||||
Hunk<BlockState> output = fixture.withSupport(AIR);
|
||||
|
||||
fixture.shoreline.decorate(0, 0, 0, 1, -1, 0, 1, -1,
|
||||
output, fixture.biome, FLUID_HEIGHT, output.getHeight());
|
||||
fixture.shoreline.decorate(0, 0, 0, 1, -1, 0, 1, -1, BIOME, FLUID_HEIGHT, output.getHeight());
|
||||
|
||||
assertSame(targetAir, output.get(0, FLUID_HEIGHT + 1, 0));
|
||||
assertSame(AIR, output.get(0, FLUID_HEIGHT + 1, 0));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Fixture createFixture(boolean forcePlace) {
|
||||
Engine engine = mock(Engine.class);
|
||||
SeedManager seedManager = mock(SeedManager.class);
|
||||
IrisDimension dimension = mock(IrisDimension.class);
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisBiome biome = mock(IrisBiome.class);
|
||||
TerrainSampler terrain = mock(TerrainSampler.class);
|
||||
when(terrain.fluidHeight()).thenReturn(FLUID_HEIGHT);
|
||||
when(terrain.surfaceY(anyInt(), anyInt())).thenReturn((double) FLUID_HEIGHT - 1);
|
||||
ResolvedDecorator decorator = mock(ResolvedDecorator.class);
|
||||
BiomeDecorators decorators = mock(BiomeDecorators.class);
|
||||
PlatformBlockState decorant = mock(PlatformBlockState.class);
|
||||
ProceduralStream<Double> heightStream = mock(ProceduralStream.class);
|
||||
|
||||
when(engine.getCacheID()).thenReturn(1);
|
||||
when(engine.getSeedManager()).thenReturn(seedManager);
|
||||
when(seedManager.getComponent()).thenReturn(17L);
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
when(dimension.getFluidHeight()).thenReturn(FLUID_HEIGHT);
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
when(complex.getFluidHeight()).thenReturn((double) FLUID_HEIGHT);
|
||||
when(complex.getHeightStream()).thenReturn(heightStream);
|
||||
when(heightStream.get(anyDouble(), anyDouble())).thenReturn((double) FLUID_HEIGHT - 1);
|
||||
when(engine.getData()).thenReturn(data);
|
||||
when(decorators.decorators(biome, DecorationPart.SHORE_LINE)).thenReturn(new ResolvedDecorator[]{decorator});
|
||||
when(decorators.decorators(BIOME, DecorationPart.SHORE_LINE)).thenReturn(new ResolvedDecorator[]{decorator});
|
||||
when(decorator.passesChanceGate(anyDouble(), anyDouble())).thenReturn(true);
|
||||
when(decorator.isForcePlace()).thenReturn(forcePlace);
|
||||
when(decorator.blockAt(eq(biome), anyDouble(), anyDouble(), anyDouble())).thenReturn(decorant);
|
||||
DecoratorTestEngines.keepDecorators(engine, decorators);
|
||||
|
||||
return new Fixture(new IrisShoreLineDecorator(engine), data, biome, decorator, decorant);
|
||||
when(decorator.blockAt(anyDouble(), anyDouble(), anyDouble())).thenReturn(POPPY);
|
||||
Hunk<BlockState> blocks = new ArrayHunk<>(BlockState.class, 1, FLUID_HEIGHT + 3, 1, AIR);
|
||||
return new Fixture(new IrisShoreLineDecorator(new DecorationScene(blocks, ApiChunk.blocks(), terrain, null, decorators, 17L,
|
||||
ModuleLogs.discarding())), decorator, blocks);
|
||||
}
|
||||
|
||||
private Hunk<PlatformBlockState> output(PlatformBlockState support, PlatformBlockState target) {
|
||||
Hunk<PlatformBlockState> output = Hunk.newArrayHunk(1, FLUID_HEIGHT + 3, 1);
|
||||
output.set(0, FLUID_HEIGHT, 0, support);
|
||||
output.set(0, FLUID_HEIGHT + 1, 0, target);
|
||||
return output;
|
||||
}
|
||||
|
||||
private PlatformBlockState airState() {
|
||||
PlatformBlockState air = mock(PlatformBlockState.class);
|
||||
when(air.isAir()).thenReturn(true);
|
||||
return air;
|
||||
}
|
||||
|
||||
private PlatformBlockState sturdyState() {
|
||||
PlatformBlockState support = mock(PlatformBlockState.class);
|
||||
BlockData blockData = mock(BlockData.class);
|
||||
when(support.isSolid()).thenReturn(true);
|
||||
when(support.nativeHandle()).thenReturn(blockData);
|
||||
when(blockData.isFaceSturdy(any(), eq(BlockSupport.FULL))).thenReturn(true);
|
||||
return support;
|
||||
}
|
||||
|
||||
private record Fixture(
|
||||
IrisShoreLineDecorator shoreline,
|
||||
IrisData data,
|
||||
IrisBiome biome,
|
||||
ResolvedDecorator decorator,
|
||||
PlatformBlockState decorant
|
||||
) {
|
||||
private record Fixture(IrisShoreLineDecorator shoreline, ResolvedDecorator decorator, Hunk<BlockState> blocks) {
|
||||
/** The blocks with {@code support} at the fluid height, where the shoreline decorates from. */
|
||||
Hunk<BlockState> withSupport(BlockState support) {
|
||||
blocks.set(0, FLUID_HEIGHT, 0, support);
|
||||
return blocks;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,10 @@ import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.ResourceLoader;
|
||||
import art.arcane.iris.core.modules.IrisPackResources;
|
||||
import art.arcane.iris.engine.UsableBlockPlatform;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.modifier.ApiChunk;
|
||||
import art.arcane.iris.engine.object.material.IrisBlockData;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import com.google.gson.Gson;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.host.ModuleLogs;
|
||||
import com.volmit.noise.NoiseFactory;
|
||||
import com.volmit.noise.NoiseSampler;
|
||||
@@ -50,19 +49,16 @@ public class ResolvedDecoratorTest {
|
||||
public void everyDecoratorPicksAsIrisDecoratorDid() {
|
||||
UsableBlockPlatform.bind();
|
||||
IrisData data = data();
|
||||
Engine engine = engine(data);
|
||||
IrisBiome biome = mock(IrisBiome.class);
|
||||
when(biome.getName()).thenReturn("test");
|
||||
Gson gson = new Gson();
|
||||
StringBuilder transcript = new StringBuilder();
|
||||
for (String json : DECORATORS) {
|
||||
ResolvedDecorator resolved = ResolvedDecorator.of(gson.fromJson(json, Decorator.class), engine, SEED, ModuleLogs.discarding());
|
||||
ResolvedDecorator resolved = ResolvedDecorator.of(gson.fromJson(json, Decorator.class), data.getPackResources(), SEED, ModuleLogs.discarding(), "test");
|
||||
for (int x = -40; x < 40; x += 3) {
|
||||
for (int z = -40; z < 40; z += 5) {
|
||||
transcript.append(resolved.passesChanceGate(x, z)).append(resolved.stackHeight(x, z)).append(key(resolved.pickBlock(x, z)))
|
||||
.append(key(resolved.pickTopBlock(x, z)));
|
||||
for (int y = 60; y < 66; y += 2) {
|
||||
transcript.append(key(resolved.blockAt(biome, x, y, z))).append(key(resolved.topBlockAt(biome, x, y, z)));
|
||||
transcript.append(key(resolved.blockAt(x, y, z))).append(key(resolved.topBlockAt(x, y, z)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -83,7 +79,7 @@ public class ResolvedDecoratorTest {
|
||||
};
|
||||
Decorator decorator = new Gson().fromJson("{\"style\": {\"style\": \"SIMPLEX\"}, \"variance\": {\"style\": \"PERLIN\"}, \"heightVariance\": {\"style\": \"CLOVER\"},"
|
||||
+ "\"stackMin\": 2, \"stackMax\": 7}", Decorator.class);
|
||||
ResolvedDecorator resolved = new ResolvedDecorator(decorator, SEED, recording, state("a", "b", "b"), List.of(), null, List.of(), List.of(), ModuleLogs.discarding());
|
||||
ResolvedDecorator resolved = new ResolvedDecorator(decorator, SEED, recording, state("a", "b", "b"), List.of(), null, List.of(), List.of(), ModuleLogs.discarding(), "test");
|
||||
|
||||
resolved.warm();
|
||||
|
||||
@@ -95,7 +91,7 @@ public class ResolvedDecoratorTest {
|
||||
NoiseFactory refusing = (style, seed) -> {
|
||||
throw new IllegalStateException("no noise");
|
||||
};
|
||||
ResolvedDecorator single = new ResolvedDecorator(new Decorator(), SEED, refusing, state("a"), List.of(), null, List.of(), List.of(), ModuleLogs.discarding());
|
||||
ResolvedDecorator single = new ResolvedDecorator(new Decorator(), SEED, refusing, state("a"), List.of(), null, List.of(), List.of(), ModuleLogs.discarding(), "test");
|
||||
|
||||
assertEquals("a one block palette never needs its variance noise", "minecraft:a", single.pickBlock(1, 2).key());
|
||||
assertEquals("equal limits never need the height noise", 1, single.stackHeight(1, 2));
|
||||
@@ -105,8 +101,8 @@ public class ResolvedDecoratorTest {
|
||||
@Test
|
||||
public void stackHeightFollowsTheHeightNoiseBetweenTheLimits() {
|
||||
Decorator decorator = new Gson().fromJson("{\"stackMin\": 1, \"stackMax\": 2}", Decorator.class);
|
||||
ResolvedDecorator top = new ResolvedDecorator(decorator, SEED, (style, seed) -> constant(1.0), state("a"), List.of(), null, List.of(), List.of(), ModuleLogs.discarding());
|
||||
ResolvedDecorator bottom = new ResolvedDecorator(decorator, SEED, (style, seed) -> constant(0.0), state("a"), List.of(), null, List.of(), List.of(), ModuleLogs.discarding());
|
||||
ResolvedDecorator top = new ResolvedDecorator(decorator, SEED, (style, seed) -> constant(1.0), state("a"), List.of(), null, List.of(), List.of(), ModuleLogs.discarding(), "test");
|
||||
ResolvedDecorator bottom = new ResolvedDecorator(decorator, SEED, (style, seed) -> constant(0.0), state("a"), List.of(), null, List.of(), List.of(), ModuleLogs.discarding(), "test");
|
||||
|
||||
assertEquals(2, top.stackHeight(0, 0));
|
||||
assertEquals(1, bottom.stackHeight(0, 0));
|
||||
@@ -114,12 +110,12 @@ public class ResolvedDecoratorTest {
|
||||
|
||||
@Test
|
||||
public void whiteAndBlackListsKeepTheDecoratorOffSurfaces() {
|
||||
PlatformBlockState sand = state("sand").get(0);
|
||||
PlatformBlockState stone = state("stone").get(0);
|
||||
BlockState sand = state("sand").get(0);
|
||||
BlockState stone = state("stone").get(0);
|
||||
Decorator listed = new Gson().fromJson("{\"whitelist\": [{\"block\": \"sand\"}], \"blacklist\": [{\"block\": \"stone\"}]}", Decorator.class);
|
||||
ResolvedDecorator resolved = new ResolvedDecorator(listed, SEED, (style, seed) -> constant(0), state("a"), List.of(),
|
||||
null, List.of(sand), List.of(stone), ModuleLogs.discarding());
|
||||
ResolvedDecorator unlisted = new ResolvedDecorator(new Decorator(), SEED, (style, seed) -> constant(0), state("a"), List.of(), null, List.of(), List.of(), ModuleLogs.discarding());
|
||||
null, List.of(sand), List.of(stone), ModuleLogs.discarding(), "test");
|
||||
ResolvedDecorator unlisted = new ResolvedDecorator(new Decorator(), SEED, (style, seed) -> constant(0), state("a"), List.of(), null, List.of(), List.of(), ModuleLogs.discarding(), "test");
|
||||
|
||||
assertFalse(resolved.rejectsSurface(sand));
|
||||
assertTrue(resolved.rejectsSurface(stone));
|
||||
@@ -131,9 +127,9 @@ public class ResolvedDecoratorTest {
|
||||
public void onlyASlopeOutsideTheLimitsBlocksAndOnlyWhenTheDecoratorLimitsIt() {
|
||||
Decorator limited = new Gson().fromJson("{\"slopeCondition\": {\"maximumSlope\": 4}}", Decorator.class);
|
||||
Decorator forced = new Gson().fromJson("{\"forcePlace\": true, \"slopeCondition\": {\"maximumSlope\": 4}}", Decorator.class);
|
||||
ResolvedDecorator resolvedLimited = new ResolvedDecorator(limited, SEED, (style, seed) -> constant(0), state("a"), List.of(), null, List.of(), List.of(), ModuleLogs.discarding());
|
||||
ResolvedDecorator resolvedForced = new ResolvedDecorator(forced, SEED, (style, seed) -> constant(0), state("a"), List.of(), null, List.of(), List.of(), ModuleLogs.discarding());
|
||||
ResolvedDecorator resolvedDefault = new ResolvedDecorator(new Decorator(), SEED, (style, seed) -> constant(0), state("a"), List.of(), null, List.of(), List.of(), ModuleLogs.discarding());
|
||||
ResolvedDecorator resolvedLimited = new ResolvedDecorator(limited, SEED, (style, seed) -> constant(0), state("a"), List.of(), null, List.of(), List.of(), ModuleLogs.discarding(), "test");
|
||||
ResolvedDecorator resolvedForced = new ResolvedDecorator(forced, SEED, (style, seed) -> constant(0), state("a"), List.of(), null, List.of(), List.of(), ModuleLogs.discarding(), "test");
|
||||
ResolvedDecorator resolvedDefault = new ResolvedDecorator(new Decorator(), SEED, (style, seed) -> constant(0), state("a"), List.of(), null, List.of(), List.of(), ModuleLogs.discarding(), "test");
|
||||
|
||||
assertTrue(resolvedLimited.slopeBlocks(() -> 5));
|
||||
assertFalse(resolvedLimited.slopeBlocks(() -> 3));
|
||||
@@ -143,11 +139,10 @@ public class ResolvedDecoratorTest {
|
||||
}));
|
||||
}
|
||||
|
||||
private static List<PlatformBlockState> state(String... keys) {
|
||||
UsableBlockPlatform.bind();
|
||||
List<PlatformBlockState> states = new ArrayList<>();
|
||||
private static List<BlockState> state(String... keys) {
|
||||
List<BlockState> states = new ArrayList<>();
|
||||
for (String key : keys) {
|
||||
states.add(UsableBlockPlatform.block(key));
|
||||
states.add(ApiChunk.blocks().resolve(key));
|
||||
}
|
||||
return states;
|
||||
}
|
||||
@@ -166,7 +161,7 @@ public class ResolvedDecoratorTest {
|
||||
};
|
||||
}
|
||||
|
||||
private static String key(PlatformBlockState state) {
|
||||
private static String key(BlockState state) {
|
||||
return state == null ? null : state.key();
|
||||
}
|
||||
|
||||
@@ -180,10 +175,4 @@ public class ResolvedDecoratorTest {
|
||||
when(data.getPackResources()).thenReturn(resources);
|
||||
return data;
|
||||
}
|
||||
|
||||
private static Engine engine(IrisData data) {
|
||||
Engine engine = mock(Engine.class);
|
||||
when(engine.getData()).thenReturn(data);
|
||||
return engine;
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,6 @@ import art.arcane.iris.builtin.carve.CaveProfile;
|
||||
import art.arcane.iris.core.modules.CarveTestTerrain;
|
||||
import art.arcane.iris.core.modules.CarveTestWorld;
|
||||
import art.arcane.iris.core.modules.InMemoryMantle;
|
||||
import art.arcane.iris.engine.modifier.RecordingCaveDressing;
|
||||
import art.arcane.iris.engine.object.TestSettings;
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
@@ -58,7 +57,7 @@ public class CaveCarvingTest {
|
||||
}
|
||||
|
||||
private static CarveTestWorld newWorld() {
|
||||
return new CarveTestWorld().biome("cave/lush", 1).biome("plains", 1).dressing(new RecordingCaveDressing());
|
||||
return new CarveTestWorld().biome("cave/lush", 1).biome("plains", 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -116,7 +115,7 @@ public class CaveCarvingTest {
|
||||
};
|
||||
CarveWorld carveWorld = new CarveWorld(world.resources().noise(), 1337L, HEIGHT, FLUID_HEIGHT, LAVA_HEIGHT, CarveTestWorld.MIN_HEIGHT);
|
||||
|
||||
new CaveCarving(world, carveWorld, false).carve(matter, terrain, 0, 0);
|
||||
new CaveCarving(world, carveWorld, false, (x, z) -> false).carve(matter, terrain, 0, 0);
|
||||
|
||||
int[] count = new int[1];
|
||||
mantle.chunk(0, 0).iterate(MatterCavern.class, (x, y, z, cavern) -> count[0]++);
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package art.arcane.iris.engine.modifier;
|
||||
|
||||
import art.arcane.iris.builtin.CaveDressing;
|
||||
import art.arcane.iris.builtin.MatterMantle;
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
@@ -63,6 +62,7 @@ import com.volmit.mantle.MantleKey;
|
||||
import com.volmit.mantle.MantleLayer;
|
||||
import com.volmit.mantle.MantleVisitor;
|
||||
import com.volmit.noise.NoiseFactory;
|
||||
import com.volmit.noise.NoiseSampler;
|
||||
import com.volmit.object.BlockEntityData;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
@@ -70,15 +70,18 @@ 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;
|
||||
import com.volmit.world.TerrainSample;
|
||||
import com.volmit.world.TerrainSampler;
|
||||
import com.volmit.world.UpperDimension;
|
||||
|
||||
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;
|
||||
@@ -99,10 +102,14 @@ 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;
|
||||
/** What every noise of the fixture's pack samples, everywhere. */
|
||||
private static final double HALF = 0.5;
|
||||
/** 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 double FLAT_NOISE = 0.5D;
|
||||
private static final Set<String> AIRS = Set.of("minecraft:air", "minecraft:cave_air", "minecraft:void_air");
|
||||
private static final Set<String> FLUIDS = Set.of("minecraft:water", "minecraft:lava");
|
||||
private static final Set<String> DECORATIONS = Set.of("minecraft:short_grass", "minecraft:poppy", "minecraft:tall_grass",
|
||||
@@ -119,8 +126,14 @@ 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 boolean stackedOnItself;
|
||||
private BiomeSample biomeSample;
|
||||
private BiomeKind surfaceKind = BiomeKind.LAND;
|
||||
private int minWorldY;
|
||||
private IntBinaryOperator surface = (x, z) -> 0;
|
||||
private IntBinaryOperator upperDimension;
|
||||
private double slope;
|
||||
@@ -158,6 +171,59 @@ 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();
|
||||
}
|
||||
|
||||
/** The dimension above is this dimension itself, stacked on it (with {@link #upperDimension}). */
|
||||
public ApiChunk stackedOnItself() {
|
||||
this.stackedOnItself = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/** 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);
|
||||
@@ -204,9 +270,14 @@ 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 or require: terrain and floating islands. */
|
||||
/** Empty stand-ins for the built-in stages the ported modules order after that the built-ins jar does not hold: floating islands. */
|
||||
public static List<IrisModule> standIns() {
|
||||
return List.of(new TerrainStandIn(), new FloatingStandIn());
|
||||
return List.of(new FloatingStandIn());
|
||||
}
|
||||
|
||||
/** An empty stand-in for {@code iris:terrain}, for modules that order after the shaping of the ground. */
|
||||
public static IrisModule terrainStandIn() {
|
||||
return new TerrainStandIn();
|
||||
}
|
||||
|
||||
/** Runs {@code modules} as a pack's chunk graph, with the {@link #standIns()}. */
|
||||
@@ -249,9 +320,15 @@ 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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <F extends IrisFeature> Optional<F> declaredBy(ResourceId biome, Class<F> featureType) {
|
||||
return biomeSettings.stream().filter(featureType::isInstance).map(featureType::cast).findFirst();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -293,6 +370,34 @@ public final class ApiChunk implements GenerationContext {
|
||||
return new BlockBox(originX, 0, originZ, originX + WIDTH, blocks.getHeight(), originZ + WIDTH);
|
||||
}
|
||||
|
||||
/** The dimension above, which is the one generated. */
|
||||
private final class SelfUpper implements UpperDimension {
|
||||
@Override
|
||||
public boolean isThisDimension() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String key() {
|
||||
return "overworld";
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureSettings settings() {
|
||||
return ApiChunk.this.settings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackResources resources() {
|
||||
return world.resources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<BlockState> surfaceBlock(int worldX, int worldZ) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
private final class Terrain implements TerrainSampler {
|
||||
@Override
|
||||
public BlockBox bounds() {
|
||||
@@ -309,7 +414,31 @@ 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
|
||||
public ResourceId surfaceBiome(int worldX, int worldZ) {
|
||||
return biomeSample == null ? BIOME : biomeSample.surfaceBiome();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<UpperDimension> upperDimension() {
|
||||
return upperDimension != null && stackedOnItself ? Optional.of(new SelfUpper()) : Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -359,6 +488,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");
|
||||
@@ -401,8 +535,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, CaveDressing.Source {
|
||||
private final class World implements PackWorld, IrisSeed.Source {
|
||||
private final Resources resources = new Resources();
|
||||
private final Map<Class<?>, Object> states = new HashMap<>();
|
||||
|
||||
@@ -421,16 +588,15 @@ public final class ApiChunk implements GenerationContext {
|
||||
return new PackSettings() {
|
||||
@Override
|
||||
public <F extends IrisFeature> List<Entry<F>> declared(Class<F> featureType) {
|
||||
return List.of();
|
||||
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
|
||||
public CaveDressing caveDressing() {
|
||||
return new RecordingCaveDressing();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T state(Class<T> type, Function<? super PackWorld, ? extends T> create) {
|
||||
Object known = states.get(type);
|
||||
@@ -485,12 +651,12 @@ public final class ApiChunk implements GenerationContext {
|
||||
return (style, seed) -> new NoiseSampler() {
|
||||
@Override
|
||||
public double sample(double worldX, double worldZ) {
|
||||
return FLAT_NOISE;
|
||||
return HALF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double sample(double worldX, double y, double worldZ) {
|
||||
return FLAT_NOISE;
|
||||
return HALF;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -513,7 +679,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
|
||||
@@ -550,6 +719,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;
|
||||
};
|
||||
}
|
||||
|
||||
+14
-2
@@ -14,6 +14,7 @@ import com.volmit.mantle.BlockBox;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.BiomeSample;
|
||||
import com.volmit.world.TerrainSample;
|
||||
import com.volmit.world.BiomeKind;
|
||||
import com.volmit.world.TerrainSampler;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -34,7 +35,7 @@ public class CaveApplyingBoundarySupportTest {
|
||||
private static final BlockState STONE = new BlockState("minecraft:stone");
|
||||
private static final BlockState SAND = new BlockState("minecraft:sand");
|
||||
|
||||
private final CarveTestWorld world = new CarveTestWorld().biome("custom/floor", 1).dressing(new RecordingCaveDressing());
|
||||
private final CarveTestWorld world = new CarveTestWorld().biome("custom/floor", 1);
|
||||
private final CaveBlockClasses classes = new CaveBlockClasses(new CarveTestWorld.Blocks());
|
||||
|
||||
@Test
|
||||
@@ -58,7 +59,8 @@ public class CaveApplyingBoundarySupportTest {
|
||||
doReturn(new MatterCavern(true, "custom/floor", (byte) 0)).when(floorSlice).get(1, 6, 2);
|
||||
doReturn(null).when(ceilingSlice).get(1, CEILING_Y & 15, 2);
|
||||
TerrainSampler terrain = new CaveBiomeTerrain((x, y, z) -> y == CEILING_Y ? Optional.of(resolvedCeiling) : Optional.empty());
|
||||
CaveApplying.Application application = modifier.new Application(chunkOnly(mantleChunk), mantleChunk, terrain, 2, 2, new ArrayHunk<>(BlockState.class, 16, 64, 16, AIR));
|
||||
CaveApplying.Application application = modifier.new Application(chunkOnly(mantleChunk), mantleChunk, terrain, 2, 2, new ArrayHunk<>(BlockState.class, 16, 64, 16, AIR),
|
||||
new RecordingCaveDressing());
|
||||
Map<String, ResourceId> customBiomeCache = new HashMap<>();
|
||||
|
||||
ResourceId floor = application.resolveCaveBoundaryBiome(1, 6, 2, 40, 44, customBiomeCache);
|
||||
@@ -118,6 +120,16 @@ public class CaveApplyingBoundarySupportTest {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeKind surfaceKind(int worldX, int worldZ) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int minWorldY() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerrainSample column(int worldX, int worldZ) {
|
||||
throw new UnsupportedOperationException();
|
||||
|
||||
@@ -69,7 +69,7 @@ public class CaveApplyingTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
world = new CarveTestWorld().biome("cave/lush", 1).dressing(dressing);
|
||||
world = new CarveTestWorld().biome("cave/lush", 1);
|
||||
dressing.walls.put(LUSH, WALL);
|
||||
dressing.floors.put(LUSH, List.of(FLOOR));
|
||||
dressing.ceilings.put(LUSH, List.of(CEILING));
|
||||
@@ -157,7 +157,7 @@ public class CaveApplyingTest {
|
||||
}
|
||||
};
|
||||
CarveWorld carveWorld = new CarveWorld(world.resources().noise(), 1337L, HEIGHT, FLUID_HEIGHT, LAVA_HEIGHT, CarveTestWorld.MIN_HEIGHT);
|
||||
new CaveApplying(world, carveWorld, upperDimensionCarving).apply(matter, terrain, 0, 0, blocks);
|
||||
new CaveApplying(world, carveWorld, upperDimensionCarving).apply(matter, terrain, 0, 0, blocks, dressing);
|
||||
}
|
||||
|
||||
private int markers() {
|
||||
|
||||
@@ -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(ApiChunk.terrainStandIn(), 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(ApiChunk.terrainStandIn(), new DepositModule());
|
||||
second.generate(ApiChunk.terrainStandIn(), 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(ApiChunk.terrainStandIn(), new DepositModule());
|
||||
carved.generate(ApiChunk.terrainStandIn(), 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(ApiChunk.terrainStandIn(), 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;
|
||||
}
|
||||
}
|
||||
+19
-28
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ public class FloatingIslandsTest {
|
||||
when(output.getHeight()).thenReturn(64);
|
||||
|
||||
islands.fillSolids(CHUNK_ORIGIN, CHUNK_ORIGIN, output, false, context);
|
||||
islands.decorateColumns(CHUNK_ORIGIN, CHUNK_ORIGIN, output, false, context);
|
||||
islands.decorateColumns(CHUNK_ORIGIN, CHUNK_ORIGIN, output, false, context, null);
|
||||
|
||||
verify(sampler, times(2)).parent(CHUNK_ORIGIN + 15, CHUNK_ORIGIN + 15);
|
||||
verify(output, never()).set(anyInt(), anyInt(), anyInt(), any());
|
||||
|
||||
@@ -18,11 +18,9 @@
|
||||
|
||||
package art.arcane.iris.engine.modifier;
|
||||
|
||||
import art.arcane.iris.builtin.CaveDressing;
|
||||
import art.arcane.iris.builtin.decorant.DecorationPart;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.hunk.Hunk;
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -38,28 +36,28 @@ public final class RecordingCaveDressing implements CaveDressing {
|
||||
public final List<String> decorated = new ArrayList<>();
|
||||
public BlockState fluid;
|
||||
|
||||
@Override
|
||||
/** Whether {@link #fluid} is set, for the carving that blends caves towards fluid columns. */
|
||||
public boolean fluidPresentAt(int x, int z) {
|
||||
return fluid != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState fluidAt(Hunk<BlockState> chunk, int x, int z) {
|
||||
public BlockState fluidAt(int x, int z) {
|
||||
return fluid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState wall(Hunk<BlockState> chunk, ResourceId biome, RNG rng, int x, int y, int z) {
|
||||
public BlockState wall(ResourceId biome, RNG rng, int x, int y, int z) {
|
||||
return walls.get(biome);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockState> floorLayers(Hunk<BlockState> chunk, ResourceId biome, int x, int z, RNG rng, int depth, int floorY) {
|
||||
public List<BlockState> floorLayers(ResourceId biome, int x, int z, RNG rng, int depth, int floorY) {
|
||||
return floors.getOrDefault(biome, List.of());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockState> ceilingLayers(Hunk<BlockState> chunk, ResourceId biome, int x, int z, RNG rng, int depth, int ceilingY) {
|
||||
public List<BlockState> ceilingLayers(ResourceId biome, int x, int z, RNG rng, int depth) {
|
||||
return ceilings.getOrDefault(biome, List.of());
|
||||
}
|
||||
|
||||
@@ -69,17 +67,17 @@ public final class RecordingCaveDressing implements CaveDressing {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decorateFloor(Hunk<BlockState> chunk, int localX, int localZ, int x, int z, ResourceId biome, int floorY, int airThickness) {
|
||||
public void decorateFloor(int localX, int localZ, int x, int z, ResourceId biome, int floorY, int airThickness) {
|
||||
decorated.add("floor " + localX + "," + floorY + "," + localZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decorateCeiling(Hunk<BlockState> chunk, int localX, int localZ, int x, int z, ResourceId biome, int ceilingY, int airThickness) {
|
||||
public void decorateCeiling(int localX, int localZ, int x, int z, ResourceId biome, int ceilingY, int airThickness) {
|
||||
decorated.add("ceiling " + localX + "," + ceilingY + "," + localZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState deepSlateOre(Hunk<BlockState> chunk, BlockState existing, BlockState layer) {
|
||||
return new BlockState("minecraft:deepslate_" + layer.material().path());
|
||||
public BlockState oreFor(BlockState rock, BlockState ore) {
|
||||
return new BlockState("minecraft:deepslate_" + ore.material().path());
|
||||
}
|
||||
}
|
||||
@@ -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)));
|
||||
}
|
||||
}
|
||||
+26
-27
@@ -1,10 +1,11 @@
|
||||
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 com.volmit.ModuleLog;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.host.ModuleLogs;
|
||||
import art.arcane.iris.engine.UsableBlockPlatform;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -12,31 +13,26 @@ 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);
|
||||
});
|
||||
/** Other tests bind a platform and leave B's cached registries behind; the tests that run after this class bind their own. */
|
||||
@After
|
||||
public void forgetCachedPlatform() {
|
||||
UsableBlockPlatform.unbind();
|
||||
}
|
||||
|
||||
@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 +42,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")));
|
||||
}
|
||||
}
|
||||
+17
-19
@@ -1,13 +1,13 @@
|
||||
package art.arcane.iris.engine.terrain;
|
||||
|
||||
import art.arcane.iris.builtin.terrain.BiomeLayers;
|
||||
import art.arcane.iris.builtin.terrain.LayeredBiome;
|
||||
import art.arcane.iris.builtin.terrain.PaletteExplosion;
|
||||
import art.arcane.iris.builtin.terrain.CaveCeilingLayersSettings;
|
||||
import art.arcane.iris.builtin.terrain.LayersSettings;
|
||||
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.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import com.volmit.block.BlockState;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.google.gson.Gson;
|
||||
@@ -24,13 +24,11 @@ public class BiomeLayersCeilingGuardTest {
|
||||
private static final String EMPTY_LAYER = "{\"palette\": []}";
|
||||
private static final String EMPTY_CEILING_LAYER = "{\"palette\": [], \"minHeight\": 0, \"maxHeight\": 0}";
|
||||
|
||||
private static IrisBiome biome(int layers, int ceilingLayers) {
|
||||
private static LayeredBiome biome(int layers, int ceilingLayers) {
|
||||
Gson gson = new Gson();
|
||||
IrisBiome biome = new IrisBiome();
|
||||
biome.setModuleSettings(BuiltInPack.settings(
|
||||
gson.fromJson("{\"layers\": " + layerList(EMPTY_LAYER, layers) + "}", LayersSettings.class),
|
||||
gson.fromJson("{\"layers\": " + layerList(EMPTY_CEILING_LAYER, ceilingLayers) + "}", CaveCeilingLayersSettings.class)));
|
||||
return biome;
|
||||
return new LayeredBiome(
|
||||
gson.fromJson("{\"layers\": " + layerList(EMPTY_LAYER, layers) + "}", LayersSettings.class), null,
|
||||
gson.fromJson("{\"layers\": " + layerList(EMPTY_CEILING_LAYER, ceilingLayers) + "}", CaveCeilingLayersSettings.class), null, null, null);
|
||||
}
|
||||
|
||||
private static String layerList(String layer, int count) {
|
||||
@@ -47,33 +45,33 @@ public class BiomeLayersCeilingGuardTest {
|
||||
|
||||
@Test
|
||||
public void moreCeilingLayersThanLayersMustNotThrow() {
|
||||
IrisBiome biome = biome(1, 3);
|
||||
LayeredBiome biome = biome(1, 3);
|
||||
|
||||
KList<PlatformBlockState> result = layersOf(data()).generateCeilingLayers(
|
||||
biome, new IrisDimension(), 0, 0, new RNG(1), 8, 64, data(), null);
|
||||
KList<BlockState> result = layersOf(data()).generateCeilingLayers(
|
||||
biome, PaletteExplosion.NONE, 0, 0, new RNG(1), 8);
|
||||
|
||||
assertTrue("extra ceiling layers are skipped, not crashed on", result.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inRangeCeilingLayersKeepWorking() {
|
||||
IrisBiome biome = biome(3, 2);
|
||||
LayeredBiome biome = biome(3, 2);
|
||||
|
||||
KList<PlatformBlockState> result = layersOf(data()).generateCeilingLayers(
|
||||
biome, new IrisDimension(), 0, 0, new RNG(1), 8, 64, data(), null);
|
||||
KList<BlockState> result = layersOf(data()).generateCeilingLayers(
|
||||
biome, PaletteExplosion.NONE, 0, 0, new RNG(1), 8);
|
||||
|
||||
assertTrue("zeroed palettes with zero heights produce no blocks", result.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void omittedCeilingLayersLeaveCavesUnchanged() {
|
||||
KList<PlatformBlockState> result = layersOf(data()).generateCeilingLayers(
|
||||
new IrisBiome(), new IrisDimension(), 0, 0, new RNG(1), 8, 64, data(), null);
|
||||
KList<BlockState> result = layersOf(data()).generateCeilingLayers(
|
||||
LayeredBiome.UNDECLARED, PaletteExplosion.NONE, 0, 0, new RNG(1), 8);
|
||||
|
||||
assertTrue(result.isEmpty());
|
||||
}
|
||||
|
||||
private static BiomeLayers layersOf(IrisData data) {
|
||||
return new BiomeLayers(TestLayerBlocks.of(data.getPackResources()), ModuleLogs.discarding());
|
||||
return new BiomeLayers(TestLayerBlocks.of(data.getPackResources()), () -> data.getPackResources().noise(), ModuleLogs.discarding());
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package art.arcane.iris.engine.terrain;
|
||||
|
||||
import art.arcane.iris.builtin.terrain.BiomeLayers;
|
||||
import art.arcane.iris.builtin.terrain.LayerBlocks;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.config.PackSettings;
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.engine.terrain;
|
||||
|
||||
import art.arcane.iris.builtin.terrain.LayeredBiome;
|
||||
import art.arcane.iris.builtin.terrain.CaveCeilingLayersSettings;
|
||||
import art.arcane.iris.builtin.terrain.LayersSettings;
|
||||
import art.arcane.iris.builtin.terrain.LockLayersMaxSettings;
|
||||
import art.arcane.iris.builtin.terrain.LockLayersSettings;
|
||||
import art.arcane.iris.builtin.terrain.SeaLayersSettings;
|
||||
import art.arcane.iris.builtin.terrain.WallSettings;
|
||||
import art.arcane.iris.core.modules.ModuleSettings;
|
||||
|
||||
/** What a biome file declares about its layers, for tests that write biomes as pack JSON ({@link TerrainTestSettings}). */
|
||||
public final class TestLayeredBiomes {
|
||||
private TestLayeredBiomes() {
|
||||
}
|
||||
|
||||
public static LayeredBiome of(ModuleSettings settings) {
|
||||
return new LayeredBiome(
|
||||
settings.find(LayersSettings.class).orElse(null),
|
||||
settings.find(SeaLayersSettings.class).orElse(null),
|
||||
settings.find(CaveCeilingLayersSettings.class).orElse(null),
|
||||
settings.find(LockLayersSettings.class).orElse(null),
|
||||
settings.find(LockLayersMaxSettings.class).orElse(null),
|
||||
settings.find(WallSettings.class).orElse(null));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* 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.engine.terrain;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.core.modules.ModuleSettings;
|
||||
import com.volmit.FeatureAttachment.Target;
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.config.FeatureSettings;
|
||||
import com.volmit.config.FeatureSettings.Entry;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.host.ModuleLogs;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.PackWorld;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
/** A world of a pack's resources whose dimension declares the given settings and whose complex and terrain seeds are given, for tests of the terrain's support classes. */
|
||||
public final class TestPackWorld implements PackWorld, IrisSeed.Source {
|
||||
private static final ResourceId DIMENSION = ResourceId.parse("test:dimension/overworld");
|
||||
|
||||
private final PackResources resources;
|
||||
private final PackSettings settings;
|
||||
private final long seed;
|
||||
private final Map<Class<?>, Object> states = new HashMap<>();
|
||||
|
||||
public TestPackWorld(PackResources resources, ModuleSettings dimensionSettings, long seed) {
|
||||
this(resources, new PackSettings() {
|
||||
@Override
|
||||
public <F extends IrisFeature> List<Entry<F>> declared(Class<F> featureType) {
|
||||
Optional<F> found = dimensionSettings.find(featureType);
|
||||
return found.map(value -> List.of(new Entry<>(Target.DIMENSION, DIMENSION, value))).orElse(List.of());
|
||||
}
|
||||
}, seed);
|
||||
}
|
||||
|
||||
/** A world whose pack declares the settings {@code settings} gives, wherever it says. */
|
||||
public TestPackWorld(PackResources resources, PackSettings settings, long seed) {
|
||||
this.resources = resources;
|
||||
this.settings = settings;
|
||||
this.seed = seed;
|
||||
}
|
||||
|
||||
/** The settings the dimension declares, as a dimension in a column of a world holds them. */
|
||||
public static FeatureSettings dimensionLevel(ModuleSettings settings) {
|
||||
return new FeatureSettings() {
|
||||
@Override
|
||||
public <F extends IrisFeature> List<Entry<F>> at(Class<F> featureType, int worldX, int worldZ) {
|
||||
return settings.find(featureType).map(value -> List.of(new Entry<>(Target.DIMENSION, DIMENSION, value))).orElse(List.of());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public long seed() {
|
||||
return seed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long seed(IrisSeed which) {
|
||||
return seed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackResources resources() {
|
||||
return resources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackSettings settings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T state(Class<T> type, Function<? super PackWorld, ? extends T> create) {
|
||||
return type.cast(states.computeIfAbsent(type, ignored -> create.apply(this)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleLog log() {
|
||||
return ModuleLogs.discarding();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackWorld withLog(ModuleLog log) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user