Drop the LegacyStreams offer and IrisPlacementForm

The module now draws the chunk random, density and heightmap from the API, so
IrisLegacyStreams, the ToolWorld extension and the placement form that cached
Iris's noise for them have no reader left.
This commit is contained in:
piexel committed 2026-11-06 11:39:57 +01:00
1 parent 97410afad9
commit a6f1ccd1e7
14 files changed
+258 -305

No files matched your search

@@ -1,62 +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.LegacyStreams;
import art.arcane.iris.builtin.objects.ObjectPlacement;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.engine.framework.SeedManager;
import art.arcane.iris.engine.object.noise.IrisNoiseGenerator;
import art.arcane.iris.engine.object.placement.IrisPlacementForm;
import art.arcane.iris.util.project.noise.CNG;
import art.arcane.iris.util.project.noise.NoiseType;
import art.arcane.volmlib.util.cache.CacheKey;
import art.arcane.volmlib.util.math.RNG;
/** Iris's own random streams and placement noise, from the world's legacy seeds and the pack's data. */
final class IrisLegacyStreams implements LegacyStreams {
private final IrisData data;
private final SeedManager seeds;
IrisLegacyStreams(IrisData data, SeedManager seeds) {
this.data = data;
this.seeds = seeds;
}
@Override
public RNG objectChunkRandom(int chunkX, int chunkZ) {
long seed = CacheKey.key(chunkX, chunkZ) + seeds.getMantle();
CNG noise = CNG.signatureFast(new RNG(seed), NoiseType.WHITE, NoiseType.GLOB);
return new RNG((long) (seed * noise.noise(chunkX, chunkZ)));
}
@Override
public int density(ObjectPlacement placement, RNG rng, double x, double z) {
return IrisPlacementForm.of(placement, data).density(placement, rng, x, z, data);
}
@Override
public int heightmapSurface(ObjectPlacement placement, long seed, int x, int z) {
IrisNoiseGenerator heightmap = IrisPlacementForm.of(placement, data).heightmap();
if (heightmap == null) {
throw new IllegalArgumentException("The placement has no virtual heightmap");
}
return (int) Math.round(heightmap.getNoise(seed, x, z, data));
}
}
@@ -22,7 +22,6 @@ import art.arcane.iris.builtin.objects.ObjectPlacement;
import art.arcane.iris.builtin.objects.ObjectRun;
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.placement.IObjectPlacer;
import art.arcane.iris.engine.object.prefab.IrisObject;
import art.arcane.iris.engine.object.terrain.carving.CarveResult;
@@ -78,7 +77,7 @@ public final class ModuleObjectPlacement {
}
long worldSeed = rng.nextLong();
try (ToolWorld toolWorld = new ToolWorld(worldSeed, data.getPackResources(), new PackDeclaredSettings(data),
world -> new IrisPlacements(data, null, () -> world), new IrisLegacyStreams(data, new SeedManager(worldSeed)))) {
world -> new IrisPlacements(data, null, () -> world))) {
return run.placeIn(toolWorld, terrain);
}
}
@@ -18,7 +18,6 @@
package art.arcane.iris.core.modules;
import art.arcane.iris.builtin.LegacyStreams;
import art.arcane.iris.engine.framework.SeedManager;
import com.volmit.ModuleLog;
import com.volmit.config.PackSettings;
@@ -43,12 +42,9 @@ final class ToolWorld implements PackWorld, AutoCloseable {
private final WorldStates states;
private final ModuleLog log;
private final Placements placements;
private final LegacyStreams legacyStreams;
/** {@code placements} makes the placements of the new world; {@code legacyStreams} are offered as its extension. */
ToolWorld(long seed, PackResources resources, PackSettings settings, Function<PackWorld, Placements> placements,
LegacyStreams legacyStreams) {
this.legacyStreams = legacyStreams;
/** {@code placements} makes the placements of the new world. */
ToolWorld(long seed, PackResources resources, PackSettings settings, Function<PackWorld, Placements> placements) {
this.seeds = new SeedManager(seed);
this.resources = resources;
this.settings = settings;
@@ -90,11 +86,6 @@ final class ToolWorld implements PackWorld, AutoCloseable {
return placements;
}
@Override
public <T> Optional<T> extension(Class<T> type) {
return type == LegacyStreams.class ? HostExtensions.as(type, legacyStreams) : Optional.empty();
}
@Override
public <T> T state(Class<T> type, Function<? super PackWorld, ? extends T> create) {
return states.state(type, () -> create.apply(this));
@@ -1,125 +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.engine.object.placement;
import art.arcane.iris.builtin.objects.ObjectPlacement;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.core.modules.IrisPackResources;
import art.arcane.iris.core.modules.IrisValues;
import art.arcane.iris.core.modules.ModuleSettings;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.object.noise.IrisGeneratorStyle;
import art.arcane.iris.engine.object.noise.IrisNoiseGenerator;
import art.arcane.iris.engine.object.noise.IrisStyledRange;
import art.arcane.iris.util.project.noise.CNG;
import art.arcane.volmlib.util.cache.LazyBoundedCache;
import art.arcane.volmlib.util.math.RNG;
import org.jetbrains.annotations.Nullable;
/**
* What Iris makes of one object placement: the module settings its JSON declares, and its noise as Iris's own
* generators, which keep the noise they build. Made once per placement and kept on it, so copies made with
* {@link ObjectPlacement#toBuilder()} share it until their noise changes.
*/
public final class IrisPlacementForm {
private static final int SURFACE_WARP_CACHE_SIZE = 8;
private static final long SURFACE_WARP_SEED_OFFSET = 1024L;
private final ModuleSettings moduleSettings;
private final IrisGeneratorStyle warp;
private final IrisStyledRange densityStyle;
private final IrisNoiseGenerator heightmap;
private final LazyBoundedCache<SurfaceWarpKey, CNG> surfaceWarps = new LazyBoundedCache<>(SURFACE_WARP_CACHE_SIZE);
private IrisPlacementForm(ModuleSettings moduleSettings, IrisGeneratorStyle warp, IrisStyledRange densityStyle,
IrisNoiseGenerator heightmap) {
this.moduleSettings = moduleSettings;
this.warp = warp;
this.densityStyle = densityStyle;
this.heightmap = heightmap;
}
/** Iris's form of {@code placement}, made the first time it is asked for. */
public static IrisPlacementForm of(ObjectPlacement placement, IrisData data) {
if (placement.hostForm() instanceof IrisPlacementForm kept) {
return kept;
}
IrisPlacementForm made = make(placement, data);
placement.hostForm(made);
return made;
}
private static IrisPlacementForm make(ObjectPlacement placement, IrisData data) {
IrisPackResources resources = (IrisPackResources) data.getPackResources();
return new IrisPlacementForm(moduleSettingsOf(placement, data),
IrisValues.generatorStyle(placement.warp(), resources),
placement.densityStyle().map(range -> IrisValues.styledRange(range, resources)).orElse(null),
placement.heightmap().map(noise -> IrisValues.noiseGenerator(noise, resources)).orElse(null));
}
private static ModuleSettings moduleSettingsOf(ObjectPlacement placement, IrisData data) {
if (placement.json() == null) {
return ModuleSettings.NONE;
}
return data.getModules().settings().decodePlacement(placement.json());
}
/** The settings the pack's modules declare on the placement. */
public ModuleSettings moduleSettings() {
return moduleSettings;
}
public IrisGeneratorStyle warp() {
return warp;
}
/** The virtual heightmap the objects place on, or null to place on the terrain. */
public @Nullable IrisNoiseGenerator heightmap() {
return heightmap;
}
/** How many objects to place at the given column: the fixed density, or the one the density style picks there. */
public int density(ObjectPlacement placement, RNG rng, double x, double z, IrisData data) {
if (densityStyle == null) {
return placement.density();
}
return (int) Math.round(densityStyle.get(rng, x, z, data));
}
/** The noise that warps the surface the objects sit on, built once per world seed. */
public CNG surfaceWarp(RNG rng, IrisData data, @Nullable Engine engine) {
long seed = engine == null ? rng.getSeed() : engine.getSeedManager().getComponent() + SURFACE_WARP_SEED_OFFSET;
return surfaceWarps.computeIfAbsent(new SurfaceWarpKey(data, engine, seed),
ignored -> warp.create(new RNG(seed), data, engine));
}
private record SurfaceWarpKey(IrisData data, Engine engine, long seed) {
@Override
public boolean equals(Object other) {
return other instanceof SurfaceWarpKey key && data == key.data && engine == key.engine && seed == key.seed;
}
@Override
public int hashCode() {
int result = System.identityHashCode(data);
result = 31 * result + System.identityHashCode(engine);
return 31 * result + Long.hashCode(seed);
}
}
}
@@ -23,7 +23,6 @@ import art.arcane.iris.modules.placement.PlacementStages;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.engine.object.placement.IObjectPlacer;
import art.arcane.iris.builtin.objects.ObjectPlacement;
import art.arcane.iris.engine.object.placement.IrisPlacementForm;
import art.arcane.iris.engine.object.prefab.IrisObject;
import art.arcane.iris.spi.IrisPlatform;
import art.arcane.iris.spi.IrisPlatforms;
@@ -132,13 +131,6 @@ public class ObjectPlacementModuleSettingsTest {
assertSame(ModuleSettings.NONE, moduleSettings(silent));
}
@Test
public void copiesOfAPlacementKeepItsSettings() {
ObjectPlacement placement = decode("{\"place\": [\"tree\"], \"glow\": {}}");
assertSame(moduleSettings(placement), moduleSettings(placement.toBuilder().place(List.of("rock")).build()));
}
@Test
public void aPlacementsSettingsActivateItsStages() {
IObjectPlacer declaring = placer();
@@ -156,7 +148,7 @@ public class ObjectPlacementModuleSettingsTest {
}
private ModuleSettings moduleSettings(ObjectPlacement placement) {
return IrisPlacementForm.of(placement, data).moduleSettings();
return data.getModules().settings().decodePlacement(placement.json());
}
private void place(ObjectPlacement declared, IObjectPlacer placer) {
@@ -23,6 +23,5 @@ public class PlacementTypeFieldsTest {
@Test
public void whatIrisKeepsBesideThePlacementIsNoField() {
assertTrue(!ObjectPlacement.jsonFields().contains("json"));
assertTrue(!ObjectPlacement.jsonFields().contains("hostForm"));
}
}
@@ -18,7 +18,6 @@
package art.arcane.iris.core.modules;
import art.arcane.iris.builtin.LegacyStreams;
import com.volmit.ModuleLog;
import com.volmit.config.PackSettings;
import com.volmit.placement.Placements;
@@ -49,8 +48,7 @@ public class ToolWorldTest {
public void theWorldKeepsItsStateUntilItIsClosed() {
PackResources resources = mock(PackResources.class);
Tracked tracked;
try (ToolWorld world = new ToolWorld(SEED, resources, mock(PackSettings.class), ignored -> mock(Placements.class),
mock(LegacyStreams.class))) {
try (ToolWorld world = new ToolWorld(SEED, resources, mock(PackSettings.class), ignored -> mock(Placements.class))) {
tracked = world.state(Tracked.class, ignored -> new Tracked());
assertSame(tracked, world.state(Tracked.class, ignored -> new Tracked()));
@@ -0,0 +1,140 @@
package art.arcane.iris.core.modules;
import art.arcane.iris.builtin.objects.HeightmapNoise;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.engine.object.TestSettings;
import art.arcane.iris.engine.object.noise.IrisNoiseGenerator;
import art.arcane.iris.modules.placement.VirtualHeightmap;
import com.google.gson.Gson;
import com.volmit.noise.NoiseFactory;
import com.volmit.noise.NoiseSampler;
import org.junit.Test;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.function.DoubleBinaryOperator;
import java.util.function.LongFunction;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/** The heights of a placement's virtual heightmap: the settings shape the API noise, and the heights are those Iris's own noise generator gave. */
public class VirtualHeightmapTest {
private static final long SUPER_SEED = 1_000L;
private static final long GENERATOR_SEED_SALT = 33_955_677L;
private static final long FIRST_FRACTURE_OFFSET = 33L;
private static final long FRACTURE_STEP = 819L;
private final List<Long> sampledSeeds = new ArrayList<>();
@Test
public void aDisabledHeightmapIsFlatAtItsOffset() {
VirtualHeightmap heightmap = heightmap("{\"enabled\": false, \"offsetY\": 70}", seed -> (x, z) -> 999);
assertEquals(70, heightmap.surface(12, -40));
assertTrue("no noise is built for it", sampledSeeds.isEmpty());
}
@Test
public void theNoiseIsSeededFromTheSuperSeedAndTheSettingsOwnSeed() {
heightmap("{\"seed\": 7}", seed -> (x, z) -> 0);
assertEquals(List.of(SUPER_SEED + GENERATOR_SEED_SALT - 7), sampledSeeds);
}
@Test
public void zoomAndOffsetsMoveTheColumnAndOpacityAndOffsetYShapeTheHeight() {
VirtualHeightmap heightmap = heightmap("{\"zoom\": 2, \"offsetX\": 10, \"opacity\": 0.5, \"offsetY\": 60}", seed -> (x, z) -> x + 2 * z);
double sampleX = 40 / 2D + 10;
double sampleZ = 6 / 2D;
assertEquals(Math.round((sampleX + 2 * sampleZ) * 0.5 + 60), heightmap.surface(40, 6));
}
@Test
public void aNegativeHeightmapIsTurnedOverItsOpacity() {
VirtualHeightmap heightmap = heightmap("{\"negative\": true, \"opacity\": 0.5, \"offsetY\": 60}", seed -> (x, z) -> 0.25);
assertEquals(Math.round(-(0.25 * 0.5) + 0.5 + 60), heightmap.surface(0, 0));
}
@Test
public void anExponentRaisesTheHeightBeforeItsOffset() {
VirtualHeightmap heightmap = heightmap("{\"exponent\": 2, \"offsetY\": 3}", seed -> (x, z) -> 4);
assertEquals(19, heightmap.surface(0, 0));
}
@Test
public void aFractureMovesTheColumnByItsHeightAroundHalfItsOpacity() {
long fractureSeed = SUPER_SEED + FIRST_FRACTURE_OFFSET + GENERATOR_SEED_SALT - 3;
VirtualHeightmap heightmap = heightmap("{\"fracture\": [{\"seed\": 3}]}",
seed -> seed == fractureSeed ? (x, z) -> 1.0 : (x, z) -> x);
assertEquals("10 + (1.0 - 0.5)", 11, heightmap.surface(10, 0));
assertTrue(sampledSeeds.contains(fractureSeed));
}
@Test
public void aDisabledFractureIsSkippedButStillCountsForTheSeedsOfTheOnesAfterIt() {
long secondFractureSeed = SUPER_SEED + FIRST_FRACTURE_OFFSET + FRACTURE_STEP + GENERATOR_SEED_SALT - 5;
heightmap("{\"fracture\": [{\"enabled\": false}, {\"seed\": 5}]}", seed -> (x, z) -> 0);
assertEquals(2, sampledSeeds.size());
assertTrue(sampledSeeds.contains(secondFractureSeed));
}
@Test
public void theHeightsAreThoseOfIrisGeneratorsForTheSameSettingsAndSeed() {
IrisData data = mock(IrisData.class);
when(data.getDataFolder()).thenReturn(new File("test-pack"));
IrisNoiseFactory noise = new IrisNoiseFactory(data, new IrisPackResources(data, List::of));
String[] settings = {
"{\"style\": {\"style\": \"SIMPLEX\", \"zoom\": 0.5}, \"zoom\": 40, \"offsetY\": 60, \"opacity\": 0.5, \"seed\": 9}",
"{\"style\": {\"style\": \"CELLULAR\"}, \"zoom\": 17, \"negative\": true, \"exponent\": 1.5, \"offsetX\": 33, \"offsetZ\": -8}",
"{\"style\": {\"style\": \"SIMPLEX\"}, \"zoom\": 25, \"bezier\": true, \"fracture\": [{\"style\": {\"style\": \"PERLIN\"}, \"zoom\": 6, \"seed\": 2},"
+ "{\"enabled\": false}, {\"style\": {\"style\": \"SIMPLEX\"}, \"zoom\": 11, \"opacity\": 0.7, \"seed\": 4}]}",
"{\"style\": {\"style\": \"SIMPLEX\"}, \"zoom\": 20, \"sinCentered\": true, \"octaves\": 4}",
};
long mismatches = 0;
for (long superSeed : new long[]{1L, 7235L, -3_999_281L}) {
for (String json : settings) {
VirtualHeightmap heightmap = VirtualHeightmap.of(TestSettings.of(HeightmapNoise.class, json), noise, superSeed);
IrisNoiseGenerator legacy = new Gson().fromJson(json, IrisNoiseGenerator.class);
for (int x = -300; x < 300; x += 23) {
for (int z = -300; z < 300; z += 29) {
mismatches += heightmap.surface(x, z) == (int) Math.round(legacy.getNoise(superSeed, x, z, data)) ? 0 : 1;
}
}
}
}
assertEquals(0, mismatches);
}
private VirtualHeightmap heightmap(String json, LongFunction<DoubleBinaryOperator> noiseOfSeed) {
NoiseFactory noise = (style, seed) -> {
sampledSeeds.add(seed);
return planar(noiseOfSeed.apply(seed));
};
return VirtualHeightmap.of(TestSettings.of(HeightmapNoise.class, json), noise, SUPER_SEED);
}
private static NoiseSampler planar(DoubleBinaryOperator height) {
return new NoiseSampler() {
@Override
public double sample(double worldX, double worldZ) {
return height.applyAsDouble(worldX, worldZ);
}
@Override
public double sample(double worldX, double y, double worldZ) {
throw new UnsupportedOperationException("A heightmap is planar");
}
};
}
}
@@ -1,19 +1,18 @@
package art.arcane.iris.engine.mantle.components;
import art.arcane.iris.builtin.IrisSeedPurposes;
import art.arcane.iris.builtin.LegacyStreams;
import art.arcane.iris.builtin.objects.ObjectPlacement;
import art.arcane.iris.builtin.objects.ObjectSettings;
import art.arcane.iris.engine.object.TestSettings;
import art.arcane.iris.engine.procedural.ProceduralObjectCatalog;
import art.arcane.iris.engine.procedural.part.ProceduralObject;
import art.arcane.volmlib.util.math.RNG;
import com.volmit.IrisFeature;
import com.volmit.block.BlockState;
import com.volmit.config.FeatureSettings.Entry;
import com.volmit.config.Level;
import com.volmit.config.PackSettings;
import com.volmit.config.SettingsStack;
import com.volmit.noise.NoiseStyle;
import com.volmit.object.PackObjects;
import com.volmit.resource.PackResources;
import com.volmit.resource.ResourceId;
@@ -27,7 +26,6 @@ import java.util.Optional;
import java.util.function.Function;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyDouble;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.contains;
@@ -43,10 +41,10 @@ import static org.mockito.Mockito.when;
public class ObjectWarmUpTest {
private static final ResourceId REGION = new ResourceId("test", "region/region");
private static final ResourceId BIOME = new ResourceId("test", "biome/biome");
private static final long DENSITY_SEED = 1337L;
@Test
public void everyPlacementOfBiomesAndRegionsIsBuiltWithTheProceduralObjectsItPlaces() {
LegacyStreams streams = mock(LegacyStreams.class);
PackResources resources = mock(PackResources.class, RETURNS_DEEP_STUBS);
PackObjects objects = mock(PackObjects.class, RETURNS_MOCKS);
when(resources.objects()).thenReturn(objects);
@@ -54,15 +52,15 @@ public class ObjectWarmUpTest {
when(resources.idOf(anyString())).thenAnswer(invocation -> new ResourceId("test", invocation.getArgument(0)));
when(resources.find(eq(ProceduralObjectCatalog.DEFINITIONS), any())).thenReturn(Optional.of(oneLog()));
PackSettings settings = mock(PackSettings.class);
PackWorld world = worldWithStates(settings, resources, streams);
ObjectPlacement biomePlacement = placement("procedural/trees/biome-oak");
ObjectPlacement regionPlacement = placement("procedural/trees/region-oak");
PackWorld world = worldWithStates(settings, resources);
ObjectPlacement biomePlacement = placement("procedural/trees/biome-oak", 2);
ObjectPlacement regionPlacement = placement("procedural/trees/region-oak", 5);
declare(settings, ObjectSettings.class, objects(regionPlacement), objects(biomePlacement));
new ObjectWarmUp(world).warm();
verify(streams).density(eq(biomePlacement), any(RNG.class), anyDouble(), anyDouble());
verify(streams).density(eq(regionPlacement), any(RNG.class), anyDouble(), anyDouble());
verify(resources.noise(), atLeastOnce()).sampler(eq(densityStyleOf(biomePlacement)), eq(DENSITY_SEED));
verify(resources.noise(), atLeastOnce()).sampler(eq(densityStyleOf(regionPlacement)), eq(DENSITY_SEED));
verify(objects, atLeastOnce()).build(contains("region-oak"), anyInt(), anyInt(), anyInt(), any());
verify(objects, atLeastOnce()).build(contains("biome-oak"), anyInt(), anyInt(), anyInt(), any());
}
@@ -73,13 +71,12 @@ public class ObjectWarmUpTest {
}
@SuppressWarnings("unchecked")
private static PackWorld worldWithStates(PackSettings settings, PackResources resources, LegacyStreams streams) {
private static PackWorld worldWithStates(PackSettings settings, PackResources resources) {
PackWorld world = mock(PackWorld.class);
Map<Class<?>, Object> states = new HashMap<>();
when(world.settings()).thenReturn(settings);
when(world.resources()).thenReturn(resources);
when(world.extension(LegacyStreams.class)).thenReturn(Optional.of(streams));
when(world.seed(IrisSeedPurposes.COMPONENT)).thenReturn(1337L);
when(world.seed(IrisSeedPurposes.OBJECT_DENSITY)).thenReturn(DENSITY_SEED);
when(world.state(any(), any())).thenAnswer(invocation -> states.computeIfAbsent(invocation.getArgument(0),
ignored -> invocation.<Function<PackWorld, Object>>getArgument(1).apply(world)));
return world;
@@ -90,8 +87,13 @@ public class ObjectWarmUpTest {
+ "\"parts\":[{\"stem\":{\"length\":3}}]}");
}
private static ObjectPlacement placement(String objectKey) {
return TestSettings.of(ObjectPlacement.class, "{\"place\":[\"" + objectKey + "\"]}");
private static ObjectPlacement placement(String objectKey, int densityZoom) {
return TestSettings.of(ObjectPlacement.class, "{\"place\":[\"" + objectKey + "\"],"
+ "\"densityStyle\":{\"min\":1,\"max\":3,\"style\":{\"style\":\"SIMPLEX\",\"zoom\":" + densityZoom + "}}}");
}
private static NoiseStyle densityStyleOf(ObjectPlacement placement) {
return placement.densityStyle().orElseThrow().style();
}
private static ObjectSettings objects(ObjectPlacement placement) {
@@ -24,7 +24,6 @@ import art.arcane.volmlib.util.matter.Matter;
import com.volmit.noise.NoiseSampler;
import art.arcane.iris.builtin.IrisStages;
import art.arcane.iris.builtin.IrisSeedPurposes;
import art.arcane.iris.builtin.LegacyStreams;
import com.volmit.block.BlockTurn;
import com.volmit.object.PackObjects;
import com.volmit.placement.Placements;
@@ -607,7 +606,6 @@ public final class ApiChunk implements GenerationContext {
private final class World implements PackWorld {
private final Resources resources = new Resources();
private final Map<Class<?>, Object> states = new HashMap<>();
private final LegacyStreams streams = mock(LegacyStreams.class);
private final Placements placements = mock(Placements.class);
private final RunningWorld running = mock(RunningWorld.class);
@@ -618,12 +616,6 @@ public final class ApiChunk implements GenerationContext {
when(running.settings()).thenReturn(nothingDeclared);
}
@Override
public <T> Optional<T> extension(Class<T> type) {
Object offered = type == LegacyStreams.class ? streams : null;
return Optional.ofNullable(offered).map(type::cast);
}
@Override
public Placements placements() {
return placements;
@@ -1,6 +1,5 @@
package art.arcane.iris.engine.modifier;
import art.arcane.iris.builtin.LegacyStreams;
import art.arcane.iris.engine.decorator.BiomeDecorators;
import com.volmit.block.BlockState;
import com.volmit.config.FeatureSettings;
@@ -68,7 +67,6 @@ public class FloatingIslandsTest {
when(running.settings()).thenReturn(nothingDeclaredByBiomes);
PackWorld world = mock(PackWorld.class);
when(world.running()).thenReturn(Optional.of(running));
when(world.extension(LegacyStreams.class)).thenReturn(Optional.of(mock(LegacyStreams.class)));
when(world.resources()).thenReturn(mock(PackResources.class));
PackSettings nothingDeclared = mock(PackSettings.class);
when(nothingDeclared.declared(any())).thenAnswer(invocation -> SettingsStack.empty());
@@ -1,67 +0,0 @@
package art.arcane.iris.engine.object.placement;
import art.arcane.iris.builtin.objects.ObjectPlacement;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.core.modules.IrisPackResources;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.framework.SeedManager;
import art.arcane.iris.util.project.noise.CNG;
import art.arcane.volmlib.util.math.RNG;
import com.volmit.noise.NoiseStyle;
import org.junit.Test;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class IrisPlacementFormSurfaceWarpTest {
@Test
public void surfaceWarpSeparatesEngineSeeds() {
IrisData data = data();
IrisPlacementForm form = IrisPlacementForm.of(placement(), data);
Engine firstEngine = engine(100L);
CNG firstWarp = form.surfaceWarp(new RNG(1L), data, firstEngine);
assertSame(firstWarp, form.surfaceWarp(new RNG(999L), data, firstEngine));
assertNotSame(firstWarp, form.surfaceWarp(new RNG(1L), data, engine(200L)));
}
@Test
public void standaloneSurfaceWarpUsesSuppliedSeed() {
IrisData data = data();
IrisPlacementForm form = IrisPlacementForm.of(placement(), data);
CNG first = form.surfaceWarp(new RNG(1L), data, null);
assertSame(first, form.surfaceWarp(new RNG(1L), data, null));
assertNotSame(first, form.surfaceWarp(new RNG(2L), data, null));
}
@Test
public void theFormIsMadeOncePerPlacement() {
IrisData data = data();
ObjectPlacement placement = placement();
assertSame(IrisPlacementForm.of(placement, data), IrisPlacementForm.of(placement, data));
}
private static ObjectPlacement placement() {
return ObjectPlacement.builder().warp(NoiseStyle.of("SIMPLEX")).build();
}
private static IrisData data() {
IrisData data = mock(IrisData.class);
when(data.getPackResources()).thenReturn(mock(IrisPackResources.class));
return data;
}
private static Engine engine(long componentSeed) {
SeedManager seedManager = mock(SeedManager.class);
when(seedManager.getComponent()).thenReturn(componentSeed);
Engine engine = mock(Engine.class);
when(engine.getSeedManager()).thenReturn(seedManager);
return engine;
}
}
@@ -20,7 +20,6 @@ public class ObjectPlacementMirrorTest {
assertEquals(GSON.fromJson(json, JsonObject.class), GSON.fromJson(placement.json(), JsonObject.class));
assertEquals(0.5, placement.chance(), 0);
assertNull(placement.hostForm());
}
@Test
@@ -0,0 +1,97 @@
package art.arcane.iris.modules.objects;
import art.arcane.iris.builtin.IrisSeedPurposes;
import art.arcane.iris.builtin.objects.ObjectPlacement;
import art.arcane.iris.engine.object.TestSettings;
import art.arcane.volmlib.util.math.RNG;
import com.volmit.noise.NoiseSampler;
import com.volmit.resource.PackResources;
import com.volmit.world.PackWorld;
import org.junit.Before;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyDouble;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/** Object placing draws its chunk random and its density from the world's seeds alone, not from any host stream. */
public class ObjectPoolStreamsTest {
private static final long CHUNK_SEED = 4_242L;
private static final long DENSITY_SEED = 9_999L;
private PackResources resources;
private NoiseSampler halfway;
@Before
public void buildResources() {
resources = mock(PackResources.class, RETURNS_DEEP_STUBS);
halfway = mock(NoiseSampler.class);
when(halfway.sample(anyDouble(), anyDouble())).thenReturn(0.5);
when(resources.noise().sampler(any(), eq(DENSITY_SEED))).thenReturn(halfway);
}
@Test
public void aChunkGetsTheSameRandomEveryTimeFromTheSameWorld() {
ObjectPool pool = ObjectPool.of(world(CHUNK_SEED));
assertEquals(pool.chunkRandom(5, -9).nextLong(), ObjectPool.of(world(CHUNK_SEED)).chunkRandom(5, -9).nextLong());
assertEquals(pool.chunkRandom(5, -9).nextLong(), pool.chunkRandom(5, -9).nextLong());
}
@Test
public void neighbouringChunksAndOtherWorldsGetOtherRandoms() {
ObjectPool pool = ObjectPool.of(world(CHUNK_SEED));
RNG here = pool.chunkRandom(5, -9);
assertNotEquals(here.nextLong(), pool.chunkRandom(6, -9).nextLong());
assertNotEquals(pool.chunkRandom(5, -9).nextLong(), pool.chunkRandom(5, -8).nextLong());
assertNotEquals(pool.chunkRandom(5, -9).nextLong(), ObjectPool.of(world(CHUNK_SEED + 1)).chunkRandom(5, -9).nextLong());
}
@Test
public void aPlacementWithoutADensityStyleHasItsFixedDensity() {
ObjectPlacement fixed = TestSettings.of(ObjectPlacement.class, "{\"place\": [\"rock\"], \"density\": 3}");
assertEquals(3, ObjectPool.of(world(CHUNK_SEED)).density(fixed, 10, 20));
}
@Test
public void aDensityStylePicksTheCountFromTheWorldsDensityNoise() {
ObjectPlacement styled = TestSettings.of(ObjectPlacement.class,
"{\"place\": [\"rock\"], \"density\": 1, \"densityStyle\": {\"min\": 2, \"max\": 6, \"style\": {\"style\": \"SIMPLEX\"}}}");
assertEquals("halfway between 2 and 6", 4, ObjectPool.of(world(CHUNK_SEED)).density(styled, 10, 20));
verify(halfway).sample(10, 20);
}
@Test
public void aDensityStyleWithEqualBoundsNeedsNoNoise() {
ObjectPlacement even = TestSettings.of(ObjectPlacement.class,
"{\"place\": [\"rock\"], \"densityStyle\": {\"min\": 3, \"max\": 3, \"style\": {\"style\": \"SIMPLEX\"}}}");
assertEquals(3, ObjectPool.of(world(CHUNK_SEED)).density(even, 10, 20));
verify(halfway, never()).sample(anyDouble(), anyDouble());
}
private PackWorld world(long chunkSeed) {
PackWorld world = mock(PackWorld.class);
Map<Class<?>, Object> states = new HashMap<>();
when(world.resources()).thenReturn(resources);
when(world.seed(IrisSeedPurposes.OBJECT_CHUNK)).thenReturn(chunkSeed);
when(world.seed(IrisSeedPurposes.OBJECT_DENSITY)).thenReturn(DENSITY_SEED);
when(world.state(any(), any())).thenAnswer(invocation -> states.computeIfAbsent(invocation.getArgument(0),
ignored -> invocation.<Function<PackWorld, Object>>getArgument(1).apply(world)));
return world;
}
}