Host side of the floating port: IrisFloatingHost

IrisPackWorld and IrisPackSettings serve a FloatingHost; iris:floating loads
from the built-ins jar and is no longer compiled in. ChunkContext loses the
shared island boundary sampler. The floating tests move to the API types, the
jar tests load the jar without stand-ins, ApiChunk's world serves empty
floating and object hosts, and UndersideTurnTest pins the underside turn
against IrisObjectRotation.xFlip180WithY.
This commit is contained in:
piexel committed 2026-10-15 12:36:10 +02:00
1 parent 901d46a3b9
commit 40f042dc8e
22 files changed
+706 -591

No files matched your search

@@ -0,0 +1,210 @@
/*
* 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.floating.FloatingHost;
import art.arcane.iris.builtin.floating.IslandAnchor;
import art.arcane.iris.builtin.floating.IslandFootprint;
import art.arcane.iris.builtin.objects.ObjectPlacement;
import art.arcane.iris.builtin.objects.PlaceableObject;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.mantle.MantleWriter;
import art.arcane.iris.engine.mantle.components.FloatingObjectPlacementTransaction;
import art.arcane.iris.engine.mantle.components.IslandAnchorPlacer;
import art.arcane.iris.engine.object.placement.FloatingObjectFootprint;
import art.arcane.iris.engine.object.placement.IObjectPlacer;
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
import art.arcane.iris.engine.object.placement.ObjectPlacements;
import art.arcane.iris.engine.object.prefab.IrisObject;
import art.arcane.iris.engine.object.prefab.IrisObjectRotation;
import art.arcane.iris.engine.object.prefab.IrisObjectScale;
import art.arcane.iris.engine.object.prefab.IrisObjectShaping;
import art.arcane.iris.engine.object.prefab.IrisObjectTranslate;
import art.arcane.iris.engine.object.world.biome.IrisBiome;
import art.arcane.iris.engine.object.world.biome.custom.IrisBiomeCustom;
import art.arcane.iris.spi.IrisPlatforms;
import art.arcane.iris.spi.PlatformBlockState;
import art.arcane.iris.util.common.data.B;
import art.arcane.volmlib.util.math.RNG;
import art.arcane.volmlib.util.matter.MatterBiomeInject;
import art.arcane.volmlib.util.matter.slices.BiomeInjectMatter;
import com.volmit.ModuleLog;
import com.volmit.resource.ResourceId;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
/**
* Iris's answers to {@code iris:floating}: biomes by the engine's streams and loader, sky biomes into the engine's mantle,
* and floating objects placed by Iris's own object placement into the mantle chunk being generated.
*/
final class IrisFloatingHost implements FloatingHost {
private static final IrisObjectRotation NO_ROTATION = IrisObjectRotation.of(0, 0, 0);
private static final int FLOATING_OBJECT_Y = -1;
private final Engine engine;
private final ModuleLog log;
private final PackResourceIds ids;
private final Map<Double, IrisObjectScale> shrinkScales = new ConcurrentHashMap<>();
IrisFloatingHost(Engine engine, ModuleLog log) {
this.engine = engine;
this.log = log;
this.ids = new PackResourceIds(engine.getData().getDataFolder());
}
@Override
public ResourceId surfaceBiome(int worldX, int worldZ) {
IrisBiome biome = engine.getSurfaceBiome(worldX, worldZ);
return biome == null ? null : ids.of(biome.getLoadKey());
}
@Override
public Optional<ResourceId> biome(String key) {
IrisBiome biome = engine.getData().getBiomeLoader().load(key);
return biome == null ? Optional.empty() : Optional.of(ids.of(biome.getLoadKey()));
}
@Override
public double biomeHeight(ResourceId biome, int worldX, int worldZ, long seed) {
return irisBiome(biome).getHeight(engine, worldX, worldZ, seed);
}
@Override
public void paintSkyBiome(ResourceId biome, int worldX, int worldZ, int[] ys, RNG random) {
MatterBiomeInject matter = skyBiomeMatter(irisBiome(biome), worldX, worldZ, random);
for (int y : ys) {
engine.getMantle().getMantle().set(worldX, y, worldZ, matter);
}
}
private MatterBiomeInject skyBiomeMatter(IrisBiome target, int worldX, int worldZ, RNG random) {
if (target.isCustom()) {
IrisBiomeCustom custom = target.getCustomBiome(random, engine, worldX, 0, worldZ);
return BiomeInjectMatter.get(IrisPlatforms.get().biomeWriter().biomeIdFor(engine.getDimension().getLoadKey() + ":" + custom.getId()));
}
return BiomeInjectMatter.get(IrisPlatforms.get().biomeWriter().biomeIdFor(target.getSkyBiomeKey(random, engine, worldX, 0, worldZ)));
}
private IrisBiome irisBiome(ResourceId biome) {
return ((IrisPackResources) engine.getData().getPackResources()).irisBiome(biome)
.orElseThrow(() -> new IllegalArgumentException("The pack has no biome " + biome));
}
@Override
public IslandFootprint footprint(PlaceableObject object) {
FloatingObjectFootprint footprint = FloatingObjectFootprint.compute((IrisObject) object);
return new IslandFootprint(footprint.getTallestKx(), footprint.getTallestKz(), footprint.getLowestSolidKeyY(), footprint.footprintXZ());
}
@Override
public Optional<PlaceableObject> shrink(PlaceableObject object, double factor, RNG random) {
IrisObjectScale scale = shrinkScales.computeIfAbsent(factor, IrisFloatingHost::scaleOf);
return Optional.ofNullable(scale.get(random, (IrisObject) object, engine));
}
private static IrisObjectScale scaleOf(double factor) {
IrisObjectScale scale = new IrisObjectScale();
scale.setSize(factor);
return scale;
}
@Override
public void placeFloating(PlaceableObject object, int worldX, int worldZ, ObjectPlacement placement, RNG random) {
IrisObject placed = (IrisObject) object;
IrisData data = engine.getData();
IrisObjectPlacement floating = ObjectPlacements.host(placement, data).toPlacement(placed.getLoadKey());
MantleWriter writer = IrisMantleChunk.current().writer();
int id = random.i(0, Integer.MAX_VALUE);
try {
placed.place(worldX, FLOATING_OBJECT_Y, worldZ, writer, floating, random, (block, state) -> writeMarker(writer, placed, id, block.getX(),
block.getY(), block.getZ(), state), null, data);
} catch (Throwable e) {
log.error("Failed to place a floating object", e);
}
}
@Override
public void placeOnTop(PlaceableObject object, int worldX, int y, int worldZ, ObjectPlacement placement, IslandAnchor anchor, RNG random) {
placeAgainstIsland((IrisObject) object, worldX, y, worldZ, placement, NO_ROTATION, anchor, random, "anchored");
}
@Override
public void placeUnder(PlaceableObject object, int worldX, int y, int worldZ, int yRotation, ObjectPlacement placement,
IslandAnchor anchor, RNG random) {
placeAgainstIsland((IrisObject) object, worldX, y, worldZ, placement, IrisObjectRotation.xFlip180WithY(yRotation), anchor, random,
"inverted");
}
/** Places the object through a transaction that writes nothing unless every block lands where the anchor allows. */
private void placeAgainstIsland(IrisObject object, int worldX, int y, int worldZ, ObjectPlacement placement, IrisObjectRotation rotation,
IslandAnchor anchor, RNG random, String kind) {
IrisData data = engine.getData();
IrisObjectPlacement anchored = ObjectPlacements.host(placement, data).toPlacement(object.getLoadKey());
anchored.setMode(anchored.getMode().onFloatingIsland());
anchored.setTranslate(new IrisObjectTranslate());
anchored.setRotation(rotation);
anchored.setForcePlace(true);
anchored.setBottom(false);
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(
new IslandAnchorPlacer(IrisMantleChunk.current().writer(), anchor));
int id = random.i(0, Integer.MAX_VALUE);
try {
int resultY = object.place(worldX, y, worldZ, transaction, anchored, random, (block, state) -> writeMarker(transaction, object, id,
block.getX(), block.getY(), block.getZ(), state), null, data);
if (resultY < 0) {
transaction.discard();
} else {
transaction.commit();
}
} catch (Throwable e) {
transaction.discard();
log.error("Failed to place an " + kind + " floating object", e);
}
}
private static void writeMarker(IObjectPlacer placer, IrisObject object, int id, int x, int y, int z, PlatformBlockState state) {
String marker = placementMarker(object, id);
if (marker != null && shouldWritePlacementMarker(placer, state, x, y, z)) {
placer.setData(x, y, z, marker);
}
}
private static boolean shouldWritePlacementMarker(IObjectPlacer placer, PlatformBlockState state, int x, int y, int z) {
if (state == null) {
return false;
}
PlatformBlockState existingState = placer.get(x, y, z);
boolean wouldReplace = B.isSolid(existingState) && B.isVineBlock(state);
String material = IrisObjectShaping.materialKey(state);
boolean placesBlock = !material.equals("minecraft:air") && !material.equals("minecraft:cave_air") && !wouldReplace;
return state.isCustom() || placesBlock;
}
private static String placementMarker(IrisObject object, int id) {
String key = object.getLoadKey();
if (key == null || key.isEmpty() || key.equals("null")) {
return null;
}
return key + "@" + id;
}
}
@@ -20,7 +20,6 @@ package art.arcane.iris.core.modules;
import art.arcane.iris.core.loader.IrisData; import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.engine.mantle.components.StructureModule; import art.arcane.iris.engine.mantle.components.StructureModule;
import art.arcane.iris.engine.modifier.FloatingModule;
import art.arcane.iris.spi.IrisPlatforms; import art.arcane.iris.spi.IrisPlatforms;
import com.volmit.IrisModule; import com.volmit.IrisModule;
import com.volmit.ModuleLog; import com.volmit.ModuleLog;
@@ -57,7 +56,8 @@ public final class IrisModuleHost {
*/ */
public static final List<String> JAR_MODULE_IDS = List.of("iris:post", "iris:perfection", "iris:matter", "iris:loot", 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:spawn", "iris:prepare", "iris:anchor", "iris:validate", "iris:bore", "iris:blocks", "iris:stilt", "iris:vacuum",
"iris:snow", "iris:vanilla-features", "iris:carve", "iris:deposit", "iris:decorant", "iris:terrain", "iris:objects"); "iris:snow", "iris:vanilla-features", "iris:carve", "iris:deposit", "iris:decorant", "iris:terrain", "iris:objects",
"iris:floating");
/** Iris's pack object model: built-in settings may hold these classes, which Iris reads and describes itself. */ /** 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"; public static final String HOST_TYPE_PACKAGE = "art.arcane.iris.engine.object";
private static final String[] JAR_COPY_FOLDER = {"cache", "module-jars"}; private static final String[] JAR_COPY_FOLDER = {"cache", "module-jars"};
@@ -81,7 +81,7 @@ public final class IrisModuleHost {
} }
private static List<IrisModule> generationModules() { private static List<IrisModule> generationModules() {
return List.of(new StructureModule(), new FloatingModule()); return List.of(new StructureModule());
} }
/** Iris's own log, labelled {@code [iris]}, for host code that calls module classes outside any module's stage, service or hook. */ /** Iris's own log, labelled {@code [iris]}, for host code that calls module classes outside any module's stage, service or hook. */
@@ -19,6 +19,7 @@
package art.arcane.iris.core.modules; package art.arcane.iris.core.modules;
import art.arcane.iris.core.loader.IrisRegistrant; import art.arcane.iris.core.loader.IrisRegistrant;
import art.arcane.iris.builtin.floating.FloatingHost;
import art.arcane.iris.builtin.objects.ObjectHost; import art.arcane.iris.builtin.objects.ObjectHost;
import art.arcane.iris.engine.framework.Engine; import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.object.world.biome.IrisBiome; import art.arcane.iris.engine.object.world.biome.IrisBiome;
@@ -39,7 +40,7 @@ import java.util.List;
* structure hooks: the engine's dimension, then every region it can reach, then every biome. Iris's built-in modules * structure hooks: the engine's dimension, then every region it can reach, then every biome. Iris's built-in modules
* decide from Iris's own pack data instead of module settings; they reach the engine through {@link #of(PackSettings)}. * decide from Iris's own pack data instead of module settings; they reach the engine through {@link #of(PackSettings)}.
*/ */
public final class IrisPackSettings implements PackSettings, ObjectHost.Source { public final class IrisPackSettings implements PackSettings, ObjectHost.Source, FloatingHost.Source {
static final String DIMENSION = "dimension"; static final String DIMENSION = "dimension";
static final String REGION = "region"; static final String REGION = "region";
static final String BIOME = "biome"; static final String BIOME = "biome";
@@ -70,6 +71,11 @@ public final class IrisPackSettings implements PackSettings, ObjectHost.Source {
return new IrisObjectHost(engine, IrisApiLogger.hostLog()); return new IrisObjectHost(engine, IrisApiLogger.hostLog());
} }
@Override
public FloatingHost floating() {
return new IrisFloatingHost(engine, IrisApiLogger.hostLog());
}
@Override @Override
public <F extends IrisFeature> List<Entry<F>> declared(Class<F> featureType) { public <F extends IrisFeature> List<Entry<F>> declared(Class<F> featureType) {
return declaredBy(engine.getDimension(), engine, ids, featureType); return declaredBy(engine.getDimension(), engine, ids, featureType);
@@ -20,6 +20,7 @@ package art.arcane.iris.core.modules;
import art.arcane.iris.builtin.IrisSeed; import art.arcane.iris.builtin.IrisSeed;
import art.arcane.iris.builtin.LiveWorld; import art.arcane.iris.builtin.LiveWorld;
import art.arcane.iris.builtin.floating.FloatingHost;
import art.arcane.iris.builtin.objects.ObjectHost; import art.arcane.iris.builtin.objects.ObjectHost;
import art.arcane.iris.engine.framework.Engine; import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.framework.SeedManager; import art.arcane.iris.engine.framework.SeedManager;
@@ -37,7 +38,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 * 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}. * reaches do through {@link IrisPackSettings#of}.
*/ */
public final class IrisPackWorld implements PackWorld, IrisSeed.Source, LiveWorld.Source, ObjectHost.Source { public final class IrisPackWorld implements PackWorld, IrisSeed.Source, LiveWorld.Source, ObjectHost.Source, FloatingHost.Source {
private final Engine engine; private final Engine engine;
private final IrisPackResources resources; private final IrisPackResources resources;
private final WorldStates states; private final WorldStates states;
@@ -45,6 +46,7 @@ public final class IrisPackWorld implements PackWorld, IrisSeed.Source, LiveWorl
private final Map<ModuleLog, IrisPackWorld> viewsByLog; private final Map<ModuleLog, IrisPackWorld> viewsByLog;
private final LiveWorld liveWorld; private final LiveWorld liveWorld;
private volatile IrisObjectHost objectHost; private volatile IrisObjectHost objectHost;
private volatile IrisFloatingHost floatingHost;
IrisPackWorld(Engine engine) { IrisPackWorld(Engine engine) {
this(engine, engine.getData().getPackResources(), new WorldStates(), IrisApiLogger.hostLog(), new ConcurrentHashMap<>()); this(engine, engine.getData().getPackResources(), new WorldStates(), IrisApiLogger.hostLog(), new ConcurrentHashMap<>());
@@ -142,6 +144,16 @@ public final class IrisPackWorld implements PackWorld, IrisSeed.Source, LiveWorl
return host; return host;
} }
@Override
public FloatingHost floating() {
IrisFloatingHost host = floatingHost;
if (host == null) {
host = new IrisFloatingHost(engine, log);
floatingHost = host;
}
return host;
}
/** Whether the pack's resources were reloaded since this world was made, so it generates with an old snapshot. */ /** Whether the pack's resources were reloaded since this world was made, so it generates with an old snapshot. */
boolean isStale() { boolean isStale() {
return engine.getData().getPackResources() != resources; return engine.getData().getPackResources() != resources;
@@ -3,7 +3,6 @@ package art.arcane.iris.util.project.context;
import art.arcane.iris.spi.IrisPlatforms; import art.arcane.iris.spi.IrisPlatforms;
import art.arcane.iris.engine.IrisComplex; import art.arcane.iris.engine.IrisComplex;
import art.arcane.iris.engine.framework.EngineMetrics; import art.arcane.iris.engine.framework.EngineMetrics;
import art.arcane.iris.engine.object.terrain.floating.FloatingIslandBoundarySampler;
import art.arcane.iris.engine.object.world.biome.IrisBiome; import art.arcane.iris.engine.object.world.biome.IrisBiome;
import art.arcane.iris.engine.object.world.region.IrisRegion; import art.arcane.iris.engine.object.world.region.IrisRegion;
import art.arcane.iris.util.common.parallel.MultiBurst; import art.arcane.iris.util.common.parallel.MultiBurst;
@@ -22,7 +21,6 @@ public class ChunkContext {
private final ChunkedDataCache<IrisBiome> biome; private final ChunkedDataCache<IrisBiome> biome;
private final ChunkedDataCache<IrisBiome> cave; private final ChunkedDataCache<IrisBiome> cave;
private final ChunkedDataCache<IrisRegion> region; private final ChunkedDataCache<IrisRegion> region;
private final FloatingIslandBoundarySampler floatingIslandBoundarySampler;
public ChunkContext(int x, int z, IrisComplex complex) { public ChunkContext(int x, int z, IrisComplex complex) {
this(x, z, complex, 0L, true, PrefillPlan.NO_CAVE, null); this(x, z, complex, 0L, true, PrefillPlan.NO_CAVE, null);
@@ -50,7 +48,6 @@ public class ChunkContext {
this.biome = new ChunkedDataCache<>(complex.getTrueBiomeStream(), x, z, cache); this.biome = new ChunkedDataCache<>(complex.getTrueBiomeStream(), x, z, cache);
this.cave = new ChunkedDataCache<>(complex.getCaveBiomeStream(), x, z, cache); this.cave = new ChunkedDataCache<>(complex.getCaveBiomeStream(), x, z, cache);
this.region = new ChunkedDataCache<>(complex.getRegionStream(), x, z, cache); this.region = new ChunkedDataCache<>(complex.getRegionStream(), x, z, cache);
this.floatingIslandBoundarySampler = new FloatingIslandBoundarySampler((wx, wz) -> complex.getTrueBiomeStream().get(wx, wz));
if (cache) { if (cache) {
PrefillPlan resolvedPlan = prefillPlan == null ? PrefillPlan.NO_CAVE : prefillPlan; PrefillPlan resolvedPlan = prefillPlan == null ? PrefillPlan.NO_CAVE : prefillPlan;
@@ -109,10 +106,6 @@ public class ChunkContext {
return complex; return complex;
} }
public FloatingIslandBoundarySampler getFloatingIslandBoundarySampler() {
return floatingIslandBoundarySampler;
}
public long getGenerationSessionId() { public long getGenerationSessionId() {
return generationSessionId; return generationSessionId;
} }
@@ -29,7 +29,6 @@ import art.arcane.iris.engine.framework.EngineGeneration;
import art.arcane.iris.engine.framework.SeedManager; import art.arcane.iris.engine.framework.SeedManager;
import art.arcane.iris.engine.loot.BlockDropping; import art.arcane.iris.engine.loot.BlockDropping;
import art.arcane.iris.engine.loot.LootResources; import art.arcane.iris.engine.loot.LootResources;
import art.arcane.iris.engine.modifier.ApiChunk;
import art.arcane.iris.engine.object.TestSettings; import art.arcane.iris.engine.object.TestSettings;
import art.arcane.iris.engine.object.world.biome.IrisBiome; 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.dimension.IrisDimension;
@@ -143,7 +142,7 @@ public class BuiltInModulesJarServicesTest {
private LoadedPack load() throws IOException { private LoadedPack load() throws IOException {
Path pack = BuiltInPack.newPackFolder(folder); Path pack = BuiltInPack.newPackFolder(folder);
BuiltInModulesJar.writeInto(pack); BuiltInModulesJar.writeInto(pack);
return LoadedPack.load(pack, ModuleHost.of(ApiChunk.standIns()) return LoadedPack.load(pack, ModuleHost.of(List.of())
.exposing(IrisModuleHost.EXPOSED_PACKAGES.toArray(String[]::new)) .exposing(IrisModuleHost.EXPOSED_PACKAGES.toArray(String[]::new))
.copyingJarsTo(folder.newFolder().toPath())); .copyingJarsTo(folder.newFolder().toPath()));
} }
@@ -59,7 +59,7 @@ public class BuiltInModulesJarTest {
Path pack = BuiltInPack.newPackFolder(folder); Path pack = BuiltInPack.newPackFolder(folder);
List<String> listed = BuiltInModulesJar.writeInto(pack); List<String> listed = BuiltInModulesJar.writeInto(pack);
try (LoadedPack loaded = loadWithStandIns(pack)) { try (LoadedPack loaded = loadJar(pack)) {
List<DiscoveredModule> fromJar = loaded.packModules(); List<DiscoveredModule> fromJar = loaded.packModules();
assertEquals(listed, fromJar.stream().map(module -> module.module().getClass().getName()).toList()); assertEquals(listed, fromJar.stream().map(module -> module.module().getClass().getName()).toList());
fromJar.forEach(module -> assertNotSame(MatterModule.class.getClassLoader(), module.module().getClass().getClassLoader())); fromJar.forEach(module -> assertNotSame(MatterModule.class.getClassLoader(), module.module().getClass().getClassLoader()));
@@ -71,7 +71,7 @@ public class BuiltInModulesJarTest {
Path pack = BuiltInPack.newPackFolder(folder); Path pack = BuiltInPack.newPackFolder(folder);
BuiltInModulesJar.writeInto(pack); BuiltInModulesJar.writeInto(pack);
try (LoadedPack loaded = loadWithStandIns(pack)) { try (LoadedPack loaded = loadJar(pack)) {
List<String> provided = loaded.packModules().stream().map(module -> module.info().id().toString()).toList(); List<String> provided = loaded.packModules().stream().map(module -> module.info().id().toString()).toList();
assertEquals(provided, IrisModuleHost.JAR_MODULE_IDS); assertEquals(provided, IrisModuleHost.JAR_MODULE_IDS);
} }
@@ -85,7 +85,7 @@ public class BuiltInModulesJarTest {
ApiChunk fromJar = scene(); ApiChunk fromJar = scene();
compiledIn.generate(BuiltInPack.jarModules().toArray(IrisModule[]::new)); compiledIn.generate(BuiltInPack.jarModules().toArray(IrisModule[]::new));
try (LoadedPack loaded = loadWithStandIns(pack)) { try (LoadedPack loaded = loadJar(pack)) {
fromJar.generate(loaded.chunk()); fromJar.generate(loaded.chunk());
} }
@@ -96,9 +96,9 @@ public class BuiltInModulesJarTest {
compiledIn.get(position[0], position[1], position[2]), fromJar.get(position[0], position[1], position[2]))); compiledIn.get(position[0], position[1], position[2]), fromJar.get(position[0], position[1], position[2])));
} }
/** The jar next to stand-ins for the compiled-in stages it orders after, exposing what Iris exposes. */ /** The jar on its own, exposing what Iris exposes. */
private LoadedPack loadWithStandIns(Path pack) throws IOException { private LoadedPack loadJar(Path pack) throws IOException {
return LoadedPack.load(pack, ModuleHost.of(ApiChunk.standIns()) return LoadedPack.load(pack, ModuleHost.of(List.of())
.exposing(IrisModuleHost.EXPOSED_PACKAGES.toArray(String[]::new)) .exposing(IrisModuleHost.EXPOSED_PACKAGES.toArray(String[]::new))
.copyingJarsTo(folder.newFolder().toPath())); .copyingJarsTo(folder.newFolder().toPath()));
} }
@@ -27,6 +27,7 @@ import art.arcane.iris.engine.framework.vanillafeatures.VanillaFeaturesModule;
import art.arcane.iris.engine.loot.LootModule; import art.arcane.iris.engine.loot.LootModule;
import art.arcane.iris.engine.modifier.CarveModule; import art.arcane.iris.engine.modifier.CarveModule;
import art.arcane.iris.engine.modifier.DepositModule; import art.arcane.iris.engine.modifier.DepositModule;
import art.arcane.iris.engine.modifier.FloatingModule;
import art.arcane.iris.engine.modifier.MatterModule; import art.arcane.iris.engine.modifier.MatterModule;
import art.arcane.iris.engine.modifier.PerfectionModule; import art.arcane.iris.engine.modifier.PerfectionModule;
import art.arcane.iris.engine.mantle.components.ObjectModule; import art.arcane.iris.engine.mantle.components.ObjectModule;
@@ -70,7 +71,7 @@ public final class BuiltInPack {
return List.of(new PostModule(), new PerfectionModule(), new MatterModule(), new LootModule(), new SpawnModule(), return List.of(new PostModule(), new PerfectionModule(), new MatterModule(), new LootModule(), new SpawnModule(),
new PrepareModule(), new AnchorModule(), new ValidateModule(), new BoreModule(), new BlocksModule(), 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(), new ObjectModule()); new DepositModule(), new DecorantModule(), new TerrainModule(), new ObjectModule(), new FloatingModule());
} }
/** Every built-in module: Iris's own and the compiled-in copies of the jar's ({@link #jarModules()}). */ /** Every built-in module: Iris's own and the compiled-in copies of the jar's ({@link #jarModules()}). */
@@ -19,7 +19,7 @@
package art.arcane.iris.core.modules; package art.arcane.iris.core.modules;
import art.arcane.iris.core.loader.IrisData; import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.engine.modifier.FloatingModule; import art.arcane.iris.engine.mantle.components.StructureModule;
import com.volmit.host.LoadedPack; import com.volmit.host.LoadedPack;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@@ -79,7 +79,7 @@ public class PackModuleJarNextToBuiltInsTest {
@Test @Test
public void aJarModuleWithTheIdOfACompiledInBuiltInFailsAsADuplicate() throws IOException { public void aJarModuleWithTheIdOfACompiledInBuiltInFailsAsADuplicate() throws IOException {
String builtInId = new FloatingModule().info().id().toString(); String builtInId = new StructureModule().info().id().toString();
Path packFolder = BuiltInPack.newPackFolder(folder); Path packFolder = BuiltInPack.newPackFolder(folder);
PackModuleJar.write(packFolder, "carve.jar", "pack.ported.Ported", PackModuleJar.write(packFolder, "carve.jar", "pack.ported.Ported",
Map.of("pack.ported.Ported", module("ported", "Ported", builtInId))); Map.of("pack.ported.Ported", module("ported", "Ported", builtInId)));
@@ -88,7 +88,7 @@ public class PackModuleJarNextToBuiltInsTest {
() -> BuiltInPack.serve(mock(IrisData.class), folder, packFolder, List.of())); () -> BuiltInPack.serve(mock(IrisData.class), folder, packFolder, List.of()));
assertEquals("Duplicate module " + builtInId + " from " + Path.of("modules", "carve.jar") + " (pack.ported.Ported); already loaded from host classpath (" assertEquals("Duplicate module " + builtInId + " from " + Path.of("modules", "carve.jar") + " (pack.ported.Ported); already loaded from host classpath ("
+ FloatingModule.class.getName() + ")", failure.getMessage()); + StructureModule.class.getName() + ")", failure.getMessage());
} }
private static String module(String packageName, String className, String moduleId) { private static String module(String packageName, String className, String moduleId) {
@@ -36,7 +36,7 @@ import static org.mockito.Mockito.when;
public class FloatingObjectPlacementTransactionTest { public class FloatingObjectPlacementTransactionTest {
@Test @Test
public void unsupportedFinalTerrainRejectsBlocksTilesAndMarkersTogether() { public void unsupportedFinalTerrainRejectsBlocksTilesAndMarkersTogether() {
IslandObjectPlacer delegate = createPlacer(false); IslandAnchorPlacer delegate = createPlacer(false);
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(delegate); FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(delegate);
PlatformBlockState first = mock(PlatformBlockState.class); PlatformBlockState first = mock(PlatformBlockState.class);
PlatformBlockState second = mock(PlatformBlockState.class); PlatformBlockState second = mock(PlatformBlockState.class);
@@ -62,7 +62,7 @@ public class FloatingObjectPlacementTransactionTest {
@Test @Test
public void supportedNeighborChunkCommitsBlocksTilesAndMarkers() { public void supportedNeighborChunkCommitsBlocksTilesAndMarkers() {
IslandObjectPlacer delegate = createPlacer(true); IslandAnchorPlacer delegate = createPlacer(true);
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(delegate); FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(delegate);
PlatformBlockState first = mock(PlatformBlockState.class); PlatformBlockState first = mock(PlatformBlockState.class);
PlatformBlockState second = mock(PlatformBlockState.class); PlatformBlockState second = mock(PlatformBlockState.class);
@@ -86,8 +86,8 @@ public class FloatingObjectPlacementTransactionTest {
verify(delegate).set(16, 101, 8, second); verify(delegate).set(16, 101, 8, second);
} }
private IslandObjectPlacer createPlacer(boolean supportNeighborChunk) { private IslandAnchorPlacer createPlacer(boolean supportNeighborChunk) {
IslandObjectPlacer placer = mock(IslandObjectPlacer.class); IslandAnchorPlacer placer = mock(IslandAnchorPlacer.class);
Engine engine = mock(Engine.class); Engine engine = mock(Engine.class);
when(engine.getHeight()).thenReturn(384); when(engine.getHeight()).thenReturn(384);
when(placer.getEngine()).thenReturn(engine); when(placer.getEngine()).thenReturn(engine);
@@ -18,103 +18,62 @@
package art.arcane.iris.engine.mantle.components; package art.arcane.iris.engine.mantle.components;
import art.arcane.iris.core.modules.BuiltInPack;
import art.arcane.iris.builtin.floating.FloatingChildSettings;
import art.arcane.iris.engine.framework.EngineGeneration;
import art.arcane.iris.engine.object.TestSettings;
import art.arcane.iris.builtin.floating.FloatingChildBiome; import art.arcane.iris.builtin.floating.FloatingChildBiome;
import art.arcane.iris.engine.object.placement.IrisObjectPlacement; import art.arcane.iris.builtin.floating.FloatingChildSettings;
import art.arcane.iris.core.loader.IrisData; import art.arcane.iris.builtin.floating.FloatingHost;
import art.arcane.iris.core.loader.ResourceLoader; import art.arcane.iris.builtin.objects.ObjectHost;
import art.arcane.iris.engine.framework.Engine; import art.arcane.iris.builtin.objects.ObjectPlacement;
import art.arcane.iris.engine.object.world.biome.IrisBiome; import art.arcane.iris.builtin.objects.ObjectSize;
import art.arcane.iris.engine.object.world.dimension.IrisDimension; import art.arcane.iris.engine.object.TestSettings;
import art.arcane.iris.engine.object.prefab.IrisObject; import com.volmit.FeatureAttachment.Target;
import art.arcane.iris.engine.object.prefab.IrisObjectTranslate; import com.volmit.IrisFeature;
import art.arcane.iris.spi.IrisPlatform; import com.volmit.config.FeatureSettings.Entry;
import art.arcane.iris.spi.IrisPlatforms; import com.volmit.config.PackSettings;
import art.arcane.iris.spi.PlatformBlockState;
import art.arcane.iris.spi.PlatformRegistries;
import art.arcane.volmlib.util.collection.KList;
import com.volmit.host.ModuleLogs; import com.volmit.host.ModuleLogs;
import org.junit.After; import com.volmit.resource.ResourceId;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Optional;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
public class FloatingObjectPlacingBoundaryRadiusTest { public class FloatingObjectPlacingBoundaryRadiusTest {
@Rule private static final ResourceId BIOME = ResourceId.parse("test:biome/floating");
public TemporaryFolder temporaryFolder = new TemporaryFolder();
@Before
public void bindPlatform() {
IrisPlatforms.unbind();
PlatformRegistries registries = mock(PlatformRegistries.class);
// IrisObject retains these built-in states after this fixture unbinds its platform.
Map<String, PlatformBlockState> registryStates = new HashMap<>();
when(registries.block(anyString())).thenAnswer(invocation -> {
String key = invocation.<String>getArgument(0).toLowerCase(java.util.Locale.ROOT);
return registryStates.computeIfAbsent(key, value -> {
PlatformBlockState block = mock(PlatformBlockState.class);
when(block.key()).thenReturn(value);
when(block.materialKey()).thenReturn(value.split("\\[", 2)[0]);
when(block.isSolid()).thenReturn(!value.contains("air"));
when(block.isOccluding()).thenReturn(!value.contains("air"));
return block;
});
});
IrisPlatform platform = mock(IrisPlatform.class);
when(platform.registries()).thenReturn(registries);
IrisPlatforms.bind(platform);
}
@After
public void unbindPlatform() {
IrisPlatforms.unbind();
}
@Test @Test
@SuppressWarnings("unchecked") public void transformedFloatingPlacementExpandsOwnerRadius() {
public void transformedFloatingPlacementExpandsOwnerRadius() throws Exception { ObjectPlacement placement = TestSettings.of(ObjectPlacement.class, "{\"place\":[\"test/floating\"],\"translate\":{\"x\":32}}");
File objectFile = temporaryFolder.newFile("floating.iob"); FloatingChildBiome floatingChild = TestSettings.with(new FloatingChildBiome(), "floatingObjects", List.of(placement));
try (DataOutputStream output = new DataOutputStream(new FileOutputStream(objectFile))) { ObjectHost objects = mock(ObjectHost.class);
output.writeInt(1); when(objects.sizeOf("test/floating")).thenReturn(Optional.of(new ObjectSize(1, 1, 1)));
output.writeInt(1);
output.writeInt(1);
}
IrisObjectPlacement placement = new IrisObjectPlacement() assertEquals(33, FloatingObjectPlacing.reach(pack(new FloatingChildSettings(List.of(floatingChild)), objects), ModuleLogs.discarding()));
.setPlace(new KList<>("test/floating")) }
.setTranslate(new IrisObjectTranslate().setX(32));
FloatingChildBiome floatingChild = TestSettings.with(new FloatingChildBiome(), "floatingObjects", new KList<>(placement));
IrisBiome biome = new IrisBiome();
biome.setModuleSettings(BuiltInPack.settings(new FloatingChildSettings(List.of(floatingChild))));
IrisDimension dimension = mock(IrisDimension.class);
when(dimension.getReachableBiomes(org.mockito.ArgumentMatchers.any())).thenReturn(new KList<>(biome));
ResourceLoader<IrisObject> objectLoader = mock(ResourceLoader.class); private static PackSettings pack(FloatingChildSettings declared, ObjectHost objects) {
when(objectLoader.findFile("test/floating")).thenReturn(objectFile); FloatingHost floating = mock(FloatingHost.class);
IrisData data = mock(IrisData.class); return new FloatingPack() {
when(data.getObjectLoader()).thenReturn(objectLoader); @Override
@SuppressWarnings("unchecked")
public <T extends IrisFeature> List<Entry<T>> declared(Class<T> featureType) {
return featureType == FloatingChildSettings.class ? List.of(new Entry<>(Target.BIOME, BIOME, (T) declared)) : List.of();
}
Engine engine = mock(Engine.class); @Override
when(engine.getDimension()).thenReturn(dimension); public FloatingHost floating() {
when(engine.getData()).thenReturn(data); return floating;
when(engine.getGeneration()).thenReturn(new EngineGeneration(engine)); }
assertEquals(33, new FloatingObjectPlacing(engine, ModuleLogs.discarding()).reach()); @Override
public ObjectHost objects() {
return objects;
}
};
}
private interface FloatingPack extends PackSettings, FloatingHost.Source, ObjectHost.Source {
} }
} }
@@ -1,120 +1,86 @@
package art.arcane.iris.engine.mantle.components; package art.arcane.iris.engine.mantle.components;
import art.arcane.iris.builtin.floating.FloatingChildBiome; import art.arcane.iris.builtin.floating.IslandFootprint;
import art.arcane.iris.engine.object.terrain.floating.ResolvedFloatingChild;
import art.arcane.iris.engine.object.terrain.floating.FloatingIslandSample; import art.arcane.iris.engine.object.terrain.floating.FloatingIslandSample;
import art.arcane.iris.engine.object.placement.FloatingObjectFootprint; import art.arcane.iris.engine.object.terrain.floating.FloatingIslandSamples;
import art.arcane.iris.engine.object.prefab.IrisObjectRotation; import art.arcane.iris.engine.object.terrain.floating.ResolvedFloatingChild;
import org.junit.Test; import org.junit.Test;
import java.lang.reflect.Constructor;
import java.util.Arrays; import java.util.Arrays;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
public class FloatingObjectPlacingInvertedPlacementTest { public class FloatingObjectPlacingInvertedPlacementTest {
private static final UndersideTurn UNTURNED = new UndersideTurn(0);
private FloatingObjectFootprint footprint(int lowestSolidKeyY, int highestSolidKeyY, int tallestKx, int tallestKz) throws Exception { private IslandFootprint footprint(int lowestSolidY, int tallestX, int tallestZ) {
return footprint(lowestSolidKeyY, highestSolidKeyY, tallestKx, tallestKz, new long[0]); return footprint(lowestSolidY, tallestX, tallestZ, new long[0]);
} }
private FloatingObjectFootprint footprint(int lowestSolidKeyY, int highestSolidKeyY, private IslandFootprint footprint(int lowestSolidY, int tallestX, int tallestZ, long[] columns) {
int tallestKx, int tallestKz, long[] cells) throws Exception { return new IslandFootprint(tallestX, tallestZ, lowestSolidY, columns);
Constructor<FloatingObjectFootprint> constructor = FloatingObjectFootprint.class.getDeclaredConstructor(
int.class,
int.class,
int.class,
int.class,
int.class,
int.class,
int.class,
int.class,
int.class,
long[].class
);
constructor.setAccessible(true);
return constructor.newInstance(
lowestSolidKeyY,
highestSolidKeyY,
0,
0,
0,
tallestKx,
tallestKz,
99,
99,
cells
);
} }
private FloatingIslandSample sample(ResolvedFloatingChild entry) throws Exception { private FloatingIslandSample sample(ResolvedFloatingChild entry) {
Constructor<FloatingIslandSample> constructor = FloatingIslandSample.class.getDeclaredConstructor(
ResolvedFloatingChild.class,
int.class,
int.class,
int.class,
int.class,
boolean[].class
);
constructor.setAccessible(true);
boolean[] solidMask = new boolean[10]; boolean[] solidMask = new boolean[10];
Arrays.fill(solidMask, true); Arrays.fill(solidMask, true);
return constructor.newInstance(entry, 100, 10, 9, 10, solidMask); return FloatingIslandSamples.of(entry, 100, 10, 9, 10, solidMask, null);
} }
@Test @Test
public void invertedBaseY_anchorsOriginalLowestSolidBelowBottomFace() throws Exception { public void invertedBaseY_anchorsOriginalLowestSolidBelowBottomFace() {
FloatingObjectFootprint footprint = footprint(5, 30, 2, 3); IslandFootprint footprint = footprint(5, 2, 3);
assertEquals(104, FloatingObjectPlacing.invertedBaseY(100, footprint)); assertEquals(104, FloatingObjectPlacing.invertedBaseY(100, footprint, UNTURNED));
} }
@Test @Test
public void invertedBaseX_usesTopFootprintAnchor() throws Exception { public void invertedBaseX_usesTopFootprintAnchor() {
FloatingObjectFootprint footprint = footprint(5, 30, 2, 3); IslandFootprint footprint = footprint(5, 2, 3);
assertEquals(106, FloatingObjectPlacing.invertedBaseX(100, 8, footprint)); assertEquals(106, FloatingObjectPlacing.invertedBaseX(100, 8, footprint, UNTURNED));
} }
@Test @Test
public void invertedBaseZ_mirrorsTopFootprintAnchor() throws Exception { public void invertedBaseZ_mirrorsTopFootprintAnchor() {
FloatingObjectFootprint footprint = footprint(5, 30, 2, 3); IslandFootprint footprint = footprint(5, 2, 3);
assertEquals(111, FloatingObjectPlacing.invertedBaseZ(100, 8, footprint)); assertEquals(111, FloatingObjectPlacing.invertedBaseZ(100, 8, footprint, UNTURNED));
} }
@Test @Test
public void invertedBaseX_usesFixedYRotationAnchor() throws Exception { public void invertedBaseX_usesFixedYRotationAnchor() {
FloatingObjectFootprint footprint = footprint(5, 30, 2, 3); IslandFootprint footprint = footprint(5, 2, 3);
IrisObjectRotation rotation = IrisObjectRotation.xFlip180WithY(90); UndersideTurn turn = new UndersideTurn(90);
assertEquals(111, FloatingObjectPlacing.invertedBaseX(100, 8, footprint, rotation)); assertEquals(111, FloatingObjectPlacing.invertedBaseX(100, 8, footprint, turn));
} }
@Test @Test
public void invertedBaseZ_usesFixedYRotationAnchor() throws Exception { public void invertedBaseZ_usesFixedYRotationAnchor() {
FloatingObjectFootprint footprint = footprint(5, 30, 2, 3); IslandFootprint footprint = footprint(5, 2, 3);
IrisObjectRotation rotation = IrisObjectRotation.xFlip180WithY(90); UndersideTurn turn = new UndersideTurn(90);
assertEquals(110, FloatingObjectPlacing.invertedBaseZ(100, 8, footprint, rotation)); assertEquals(110, FloatingObjectPlacing.invertedBaseZ(100, 8, footprint, turn));
} }
@Test @Test
public void invertedBaseY_isStableAcrossFixedYRotation() throws Exception { public void invertedBaseY_isStableAcrossFixedYRotation() {
FloatingObjectFootprint footprint = footprint(5, 30, 2, 3); IslandFootprint footprint = footprint(5, 2, 3);
IrisObjectRotation rotation = IrisObjectRotation.xFlip180WithY(270); UndersideTurn turn = new UndersideTurn(270);
assertEquals(104, FloatingObjectPlacing.invertedBaseY(100, footprint, rotation)); assertEquals(104, FloatingObjectPlacing.invertedBaseY(100, footprint, turn));
} }
@Test @Test
public void topFootprintChecksNeighborChunkTerrain() throws Exception { public void topFootprintChecksNeighborChunkTerrain() {
ResolvedFloatingChild entry = new ResolvedFloatingChild(new FloatingChildBiome()); ResolvedFloatingChild entry = mock(ResolvedFloatingChild.class);
FloatingIslandSample sample = sample(entry); FloatingIslandSample sample = sample(entry);
long[] cells = {0L, 1L << 32}; long[] cells = {0L, 1L << 32};
FloatingObjectFootprint footprint = footprint(0, 0, 0, 0, cells); IslandFootprint footprint = footprint(0, 0, 0, cells);
assertTrue(FloatingObjectPlacing.isFootprintFlat( assertTrue(FloatingObjectPlacing.isFootprintFlat(
footprint, 15, 0, 109, footprint, 15, 0, 109,
@@ -1,18 +1,19 @@
package art.arcane.iris.engine.object.terrain.floating; package art.arcane.iris.engine.mantle.components;
import art.arcane.iris.engine.object.terrain.floating.FloatingIslandSample; import art.arcane.iris.engine.object.terrain.floating.FloatingIslandSample;
import art.arcane.iris.engine.mantle.components.IslandObjectPlacer; import art.arcane.iris.engine.object.terrain.floating.FloatingIslandSamples;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
public class IslandObjectPlacerAnchorFaceTest { public class IslandFaceTest {
private static final int WORLD_HEIGHT = 320;
private FloatingIslandSample sampleWithBottomAt(int baseY, int bottomOffset) { private FloatingIslandSample sampleWithBottomAt(int baseY, int bottomOffset) {
boolean[] mask = new boolean[10]; boolean[] mask = new boolean[10];
mask[bottomOffset] = true; mask[bottomOffset] = true;
mask[9] = true; mask[9] = true;
return FloatingIslandSample.constructForTest(baseY, 10, 9, 2, mask); return FloatingIslandSamples.of(baseY, 10, 9, 2, mask);
} }
@Test @Test
@@ -20,9 +21,9 @@ public class IslandObjectPlacerAnchorFaceTest {
FloatingIslandSample[] samples = new FloatingIslandSample[256]; FloatingIslandSample[] samples = new FloatingIslandSample[256];
samples[0] = sampleWithBottomAt(100, 0); samples[0] = sampleWithBottomAt(100, 0);
IslandObjectPlacer placer = IslandObjectPlacer.bottom(null, sampleProvider(samples), null, 100); IslandFace face = IslandFace.bottom(sampleProvider(samples), null, 100, WORLD_HEIGHT);
int result = placer.getHighest(0, 0, null); int result = face.faceY(0, 0);
assertEquals(100, result); assertEquals(100, result);
} }
@@ -31,9 +32,9 @@ public class IslandObjectPlacerAnchorFaceTest {
FloatingIslandSample[] samples = new FloatingIslandSample[256]; FloatingIslandSample[] samples = new FloatingIslandSample[256];
samples[0] = sampleWithBottomAt(100, 0); samples[0] = sampleWithBottomAt(100, 0);
IslandObjectPlacer placer = IslandObjectPlacer.bottom(null, sampleProvider(samples), null, 100); IslandFace face = IslandFace.bottom(sampleProvider(samples), null, 100, WORLD_HEIGHT);
int result = placer.getHighest(15, 15, null); int result = face.faceY(15, 15);
assertEquals(100, result); assertEquals(100, result);
} }
@@ -42,10 +43,9 @@ public class IslandObjectPlacerAnchorFaceTest {
FloatingIslandSample[] samples = new FloatingIslandSample[256]; FloatingIslandSample[] samples = new FloatingIslandSample[256];
samples[0] = sampleWithBottomAt(100, 0); samples[0] = sampleWithBottomAt(100, 0);
IslandObjectPlacer placer = IslandObjectPlacer.bottom(null, sampleProvider(samples), null, 100); IslandFace face = IslandFace.bottom(sampleProvider(samples), null, 100, WORLD_HEIGHT);
assertEquals(false, placer.canWriteObjectBlock(0, 101, 0)); assertEquals(false, face.writes(0, 101, 0));
placer.set(0, 101, 0, null);
} }
@Test @Test
@@ -53,9 +53,9 @@ public class IslandObjectPlacerAnchorFaceTest {
FloatingIslandSample[] samples = new FloatingIslandSample[256]; FloatingIslandSample[] samples = new FloatingIslandSample[256];
samples[0] = sampleWithBottomAt(100, 0); samples[0] = sampleWithBottomAt(100, 0);
IslandObjectPlacer placer = IslandObjectPlacer.bottom(null, sampleProvider(samples), null, 100); IslandFace face = IslandFace.bottom(sampleProvider(samples), null, 100, WORLD_HEIGHT);
assertEquals(true, placer.canWriteObjectBlock(0, 99, 0)); assertEquals(true, face.writes(0, 99, 0));
} }
@Test @Test
@@ -63,10 +63,10 @@ public class IslandObjectPlacerAnchorFaceTest {
FloatingIslandSample[] samples = new FloatingIslandSample[256]; FloatingIslandSample[] samples = new FloatingIslandSample[256];
samples[0] = sampleWithBottomAt(100, 0); samples[0] = sampleWithBottomAt(100, 0);
IslandObjectPlacer placer = IslandObjectPlacer.bottom(null, sampleProvider(samples), null, 100); IslandFace face = IslandFace.bottom(sampleProvider(samples), null, 100, WORLD_HEIGHT);
assertEquals(false, placer.canWriteObjectBlock(0, 100, 0)); assertEquals(false, face.writes(0, 100, 0));
assertEquals(false, placer.canWriteObjectBlock(0, 101, 0)); assertEquals(false, face.writes(0, 101, 0));
} }
@Test @Test
@@ -74,31 +74,28 @@ public class IslandObjectPlacerAnchorFaceTest {
FloatingIslandSample[] samples = new FloatingIslandSample[256]; FloatingIslandSample[] samples = new FloatingIslandSample[256];
samples[0] = sampleWithBottomAt(100, 0); samples[0] = sampleWithBottomAt(100, 0);
IslandObjectPlacer placer = IslandObjectPlacer.top(null, sampleProvider(samples), null, 105); IslandFace face = IslandFace.top(sampleProvider(samples), null, 105, WORLD_HEIGHT);
assertEquals(false, placer.canWriteObjectBlock(1, 104, 0)); assertEquals(false, face.writes(1, 104, 0));
placer.set(1, 104, 0, null);
} }
@Test @Test
public void topFace_allowsSupportedNeighborChunkWrite() { public void topFace_allowsSupportedNeighborChunkWrite() {
FloatingIslandSample sample = sampleWithBottomAt(100, 0); FloatingIslandSample sample = sampleWithBottomAt(100, 0);
IslandObjectPlacer placer = IslandObjectPlacer.top(null, IslandFace face = IslandFace.top((x, z) -> z == 0 && (x == 15 || x == 16) ? sample : null, null, 109, WORLD_HEIGHT);
(x, z) -> z == 0 && (x == 15 || x == 16) ? sample : null, null, 109);
assertEquals(true, placer.canWriteObjectBlock(16, 110, 0)); assertEquals(true, face.writes(16, 110, 0));
} }
@Test @Test
public void topFace_rejectsUnsupportedWorldColumnBeyondOverhang() { public void topFace_rejectsUnsupportedWorldColumnBeyondOverhang() {
FloatingIslandSample sample = sampleWithBottomAt(100, 0); FloatingIslandSample sample = sampleWithBottomAt(100, 0);
IslandObjectPlacer placer = IslandObjectPlacer.top(null, IslandFace face = IslandFace.top((x, z) -> x == 15 && z == 0 ? sample : null, null, 109, WORLD_HEIGHT);
(x, z) -> x == 15 && z == 0 ? sample : null, null, 109);
assertEquals(false, placer.canWriteObjectBlock(18, 110, 0)); assertEquals(false, face.writes(18, 110, 0));
} }
private IslandObjectPlacer.SampleProvider sampleProvider(FloatingIslandSample[] samples) { private IslandFace.SampleProvider sampleProvider(FloatingIslandSample[] samples) {
return (x, z) -> { return (x, z) -> {
if (x < 0 || x >= 16 || z < 0 || z >= 16) { if (x < 0 || x >= 16 || z < 0 || z >= 16) {
return null; return null;
@@ -0,0 +1,34 @@
package art.arcane.iris.engine.mantle.components;
import art.arcane.iris.engine.object.prefab.IrisObjectRotation;
import art.arcane.volmlib.util.math.IrisBlockVector;
import com.volmit.world.BlockPosition;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/** {@link UndersideTurn} turns positions the way the Iris rotation it stands in for, {@link IrisObjectRotation#xFlip180WithY}, does. */
public class UndersideTurnTest {
private static final int[] Y_ROTATIONS = {0, 90, 180, 270};
private static final int SPAN = 3;
@Test
public void turnsEveryPositionLikeTheFlippedIrisRotation() {
for (int yRotation : Y_ROTATIONS) {
UndersideTurn turn = new UndersideTurn(yRotation);
IrisObjectRotation rotation = IrisObjectRotation.xFlip180WithY(yRotation);
for (int x = -SPAN; x <= SPAN; x++) {
for (int y = -SPAN; y <= SPAN; y++) {
for (int z = -SPAN; z <= SPAN; z++) {
IrisBlockVector expected = rotation.rotate(new IrisBlockVector(x, y, z), 0, 0, 0);
BlockPosition actual = turn.turn(x, y, z);
String at = yRotation + "° at " + x + "," + y + "," + z;
assertEquals(at, expected.getBlockX(), actual.x());
assertEquals(at, expected.getBlockY(), actual.y());
assertEquals(at, expected.getBlockZ(), actual.z());
}
}
}
}
}
}
@@ -24,6 +24,8 @@ import art.arcane.volmlib.util.matter.Matter;
import com.volmit.noise.NoiseSampler; import com.volmit.noise.NoiseSampler;
import art.arcane.iris.builtin.IrisStages; import art.arcane.iris.builtin.IrisStages;
import art.arcane.iris.builtin.IrisSeed; import art.arcane.iris.builtin.IrisSeed;
import art.arcane.iris.builtin.floating.FloatingHost;
import art.arcane.iris.builtin.objects.ObjectHost;
import art.arcane.iris.builtin.post.PostProcessingSlabsSettings; import art.arcane.iris.builtin.post.PostProcessingSlabsSettings;
import art.arcane.iris.builtin.post.PostProcessingWallsSettings; import art.arcane.iris.builtin.post.PostProcessingWallsSettings;
import art.arcane.iris.builtin.prepare.SlopeClip; import art.arcane.iris.builtin.prepare.SlopeClip;
@@ -79,6 +81,7 @@ import com.volmit.world.TerrainSampler;
import com.volmit.world.UpperDimension; import com.volmit.world.UpperDimension;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@@ -102,6 +105,7 @@ public final class ApiChunk implements GenerationContext {
public static final int WIDTH = 16; public static final int WIDTH = 16;
public static final BlockState AIR = new BlockState("minecraft:air"); public static final BlockState AIR = new BlockState("minecraft:air");
private static final long SEED = 1337L; private static final long SEED = 1337L;
private static final String FLOATING_ID = "iris:floating";
/** What every noise of the fixture's pack samples, everywhere. */ /** What every noise of the fixture's pack samples, everywhere. */
private static final double HALF = 0.5; private static final double HALF = 0.5;
/** A key that the fixture's pack has no block for. */ /** A key that the fixture's pack has no block for. */
@@ -270,21 +274,17 @@ public final class ApiChunk implements GenerationContext {
return TestSettings.with(new PaletteLayer(), "palette", List.of(BlockSpec.of(block.key())), "slopeCondition", slope); 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 that the built-ins jar does not hold: floating islands. */
public static List<IrisModule> standIns() {
return List.of(new FloatingStandIn());
}
/** An empty stand-in for {@code iris:terrain}, for modules that order after the shaping of the ground. */ /** An empty stand-in for {@code iris:terrain}, for modules that order after the shaping of the ground. */
public static IrisModule terrainStandIn() { public static IrisModule terrainStandIn() {
return new TerrainStandIn(); return new TerrainStandIn();
} }
/** Runs {@code modules} as a pack's chunk graph, with the {@link #standIns()}. */ /** Runs {@code modules} as a pack's chunk graph, with an empty stand-in for the floating islands unless they bring their own. */
public ApiChunk generate(IrisModule... modules) { public ApiChunk generate(IrisModule... modules) {
StageGraphBuilder builder = new StageGraphBuilder(); StageGraphBuilder builder = new StageGraphBuilder();
for (IrisModule module : standIns()) { if (Arrays.stream(modules).noneMatch(module -> module.info().id().toString().equals(FLOATING_ID))) {
builder.install(DiscoveredModule.builtIn(module)); builder.install(DiscoveredModule.builtIn(new FloatingStandIn()));
} }
for (IrisModule module : modules) { for (IrisModule module : modules) {
builder.install(DiscoveredModule.builtIn(module)); builder.install(DiscoveredModule.builtIn(module));
@@ -569,9 +569,22 @@ public final class ApiChunk implements GenerationContext {
} }
/** A world of the chunk: its pack's blocks, a state store and Iris's seeds, each the world seed plus its place. */ /** A world of the chunk: its pack's blocks, a state store and Iris's seeds, each the world seed plus its place. */
private final class World implements PackWorld, IrisSeed.Source { /** A world without floating islands: its floating host answers no surface biome, so no column has an island. */
private final class World implements PackWorld, IrisSeed.Source, FloatingHost.Source, ObjectHost.Source {
private final Resources resources = new Resources(); private final Resources resources = new Resources();
private final Map<Class<?>, Object> states = new HashMap<>(); private final Map<Class<?>, Object> states = new HashMap<>();
private final FloatingHost floating = mock(FloatingHost.class);
private final ObjectHost objects = mock(ObjectHost.class);
@Override
public FloatingHost floating() {
return floating;
}
@Override
public ObjectHost objects() {
return objects;
}
@Override @Override
public long seed() { public long seed() {
@@ -761,7 +774,7 @@ public final class ApiChunk implements GenerationContext {
private static final class FloatingStandIn implements IrisModule { private static final class FloatingStandIn implements IrisModule {
@Override @Override
public ModuleInfo info() { public ModuleInfo info() {
return ModuleInfo.of("iris:floating", "Floating stand-in", "test"); return ModuleInfo.of(FLOATING_ID, "Floating stand-in", "test");
} }
@Override @Override
@@ -1,57 +1,74 @@
package art.arcane.iris.engine.modifier; package art.arcane.iris.engine.modifier;
import art.arcane.iris.core.modules.ModuleSettings; import art.arcane.iris.builtin.IrisSeed;
import art.arcane.iris.engine.decorator.DecoratorTestEngines; import art.arcane.iris.builtin.floating.FloatingHost;
import art.arcane.iris.engine.framework.Engine; import art.arcane.iris.builtin.objects.ObjectHost;
import art.arcane.iris.engine.framework.EngineMetrics; import art.arcane.iris.engine.decorator.BiomeDecorators;
import art.arcane.iris.engine.framework.SeedManager; import com.volmit.block.BlockState;
import art.arcane.iris.engine.object.terrain.floating.FloatingIslandBoundarySampler; import com.volmit.config.FeatureSettings;
import art.arcane.iris.engine.object.world.biome.IrisBiome; import com.volmit.config.PackSettings;
import art.arcane.iris.spi.PlatformBlockState;
import art.arcane.iris.util.project.context.ChunkContext;
import art.arcane.iris.util.project.hunk.Hunk;
import com.volmit.host.ModuleLogs; import com.volmit.host.ModuleLogs;
import com.volmit.hunk.Hunk;
import com.volmit.resource.PackResources;
import com.volmit.resource.ResourceId;
import com.volmit.stage.ChunkStageContext;
import com.volmit.world.PackWorld;
import org.junit.Test; import org.junit.Test;
import java.util.function.Function;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import static org.mockito.Mockito.withSettings;
/** A column whose biome declares no floating child biomes gets no island: nothing is written or decorated. */ /** A column whose biome declares no floating child biomes gets no island: nothing is written or decorated. */
public class FloatingIslandsTest { public class FloatingIslandsTest {
private static final int CHUNK_ORIGIN = 32; private static final int CHUNK_ORIGIN = 32;
private static final ResourceId PLAIN_BIOME = ResourceId.parse("test:plain");
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void columnsWithoutFloatingChildBiomesAreLeftAlone() { public void columnsWithoutFloatingChildBiomesAreLeftAlone() {
FloatingIslands islands = new FloatingIslands(engine(), ModuleLogs.discarding()); FloatingHost host = mock(FloatingHost.class);
IrisBiome biome = mock(IrisBiome.class); when(host.surfaceBiome(anyInt(), anyInt())).thenReturn(PLAIN_BIOME);
when(biome.getModuleSettings()).thenReturn(ModuleSettings.NONE); PackWorld world = world(host);
FloatingIslandBoundarySampler sampler = mock(FloatingIslandBoundarySampler.class); Hunk<BlockState> output = mock(Hunk.class);
when(sampler.parent(anyInt(), anyInt())).thenReturn(biome);
ChunkContext context = mock(ChunkContext.class);
when(context.getFloatingIslandBoundarySampler()).thenReturn(sampler);
Hunk<PlatformBlockState> output = mock(Hunk.class);
when(output.getHeight()).thenReturn(64); when(output.getHeight()).thenReturn(64);
ChunkStageContext context = mock(ChunkStageContext.class, RETURNS_DEEP_STUBS);
when(context.originX()).thenReturn(CHUNK_ORIGIN);
when(context.originZ()).thenReturn(CHUNK_ORIGIN);
when(context.world()).thenReturn(world);
when(context.hunk(BlockState.class)).thenReturn(output);
when(context.settings()).thenReturn(mock(FeatureSettings.class));
when(context.mantle()).thenReturn(null);
FloatingIslands islands = FloatingIslands.of(world, ModuleLogs.discarding());
islands.fillSolids(CHUNK_ORIGIN, CHUNK_ORIGIN, output, false, context); islands.fillSolids(context);
islands.decorateColumns(CHUNK_ORIGIN, CHUNK_ORIGIN, output, false, context, null); islands.decorateColumns(context);
verify(sampler, times(2)).parent(CHUNK_ORIGIN + 15, CHUNK_ORIGIN + 15); verify(host, org.mockito.Mockito.atLeastOnce()).surfaceBiome(CHUNK_ORIGIN + 15, CHUNK_ORIGIN + 15);
verify(output, never()).set(anyInt(), anyInt(), anyInt(), any()); verify(output, never()).set(anyInt(), anyInt(), anyInt(), any());
verify(output, never()).setRaw(anyInt(), anyInt(), anyInt(), any());
} }
private Engine engine() { @SuppressWarnings("unchecked")
SeedManager seeds = mock(SeedManager.class); private static PackWorld world(FloatingHost host) {
Engine engine = mock(Engine.class); PackWorld world = mock(PackWorld.class, withSettings().extraInterfaces(FloatingHost.Source.class, ObjectHost.Source.class, IrisSeed.Source.class));
when(engine.getSeedManager()).thenReturn(seeds); when(((FloatingHost.Source) world).floating()).thenReturn(host);
when(engine.getMetrics()).thenReturn(new EngineMetrics(16)); when(((ObjectHost.Source) world).objects()).thenReturn(mock(ObjectHost.class));
DecoratorTestEngines.withGeneration(engine); when(world.resources()).thenReturn(mock(PackResources.class));
return engine; when(world.settings()).thenReturn(mock(PackSettings.class));
when(world.state(any(), any())).thenAnswer(invocation -> {
Class<?> type = invocation.getArgument(0);
if (type == BiomeDecorators.class) {
return mock(BiomeDecorators.class);
}
return invocation.getArgument(1, Function.class).apply(world);
});
return world;
} }
} }
@@ -24,6 +24,7 @@ import art.arcane.iris.builtin.floating.OverrideMode;
import art.arcane.iris.builtin.floating.TopShapeMode; import art.arcane.iris.builtin.floating.TopShapeMode;
import art.arcane.iris.core.loader.IrisData; import art.arcane.iris.core.loader.IrisData;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.volmit.noise.NoiseFactory;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
@@ -37,6 +38,7 @@ import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.CALLS_REAL_METHODS; import static org.mockito.Mockito.CALLS_REAL_METHODS;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/** The floating child of the overworld pack's magnetics/dunes biome, read into {@link FloatingChildBiome} with the values Iris's own class read from the same JSON. */ /** The floating child of the overworld pack's magnetics/dunes biome, read into {@link FloatingChildBiome} with the values Iris's own class read from the same JSON. */
public class FloatingChildBiomeDecodingTest { public class FloatingChildBiomeDecodingTest {
@@ -99,9 +101,9 @@ public class FloatingChildBiomeDecodingTest {
assertEquals(0.55, child.objectShrinkFactor(), 0); assertEquals(0.55, child.objectShrinkFactor(), 0);
assertEquals(OverrideMode.MERGE, child.topObjectMode()); assertEquals(OverrideMode.MERGE, child.topObjectMode());
assertEquals(2, child.topObjectOverrides().size()); assertEquals(2, child.topObjectOverrides().size());
assertEquals(5, child.topObjectOverrides().get(0).getDensity()); assertEquals(5, child.topObjectOverrides().get(0).density());
assertEquals(OverrideMode.REPLACE, child.bottomObjectMode()); assertEquals(OverrideMode.REPLACE, child.bottomObjectMode());
assertEquals("clutter/bone4", child.bottomObjectOverrides().get(0).getPlace().get(0)); assertEquals("clutter/bone4", child.bottomObjectOverrides().get(0).place().get(0));
} }
@Test @Test
@@ -134,13 +136,15 @@ public class FloatingChildBiomeDecodingTest {
@Test @Test
public void theEdgeTaperProfileKeepsTheSettingsWidthExponentAndVariation() { public void theEdgeTaperProfileKeepsTheSettingsWidthExponentAndVariation() {
FloatingChildBiome child = gson.fromJson(DUNES_CHILD, FloatingChildBiome.class); FloatingChildBiome child = gson.fromJson(DUNES_CHILD, FloatingChildBiome.class);
ResolvedFloatingChild resolved = new ResolvedFloatingChild(child); FloatingWorld world = mock(FloatingWorld.class);
when(world.noise()).thenReturn(mock(NoiseFactory.class));
ResolvedFloatingChild resolved = new ResolvedFloatingChild(child, world);
FloatingIslandEdgeProfile profile = resolved.getEdgeTaperProfile(77L, mock(IrisData.class)); FloatingIslandEdgeProfile profile = resolved.edgeTaperProfile();
assertEquals(14, profile.width()); assertEquals(14, profile.width());
assertEquals(1.45, profile.exponent(), 0); assertEquals(1.45, profile.exponent(), 0);
assertEquals(4, profile.variationAmplitude(), 0); assertEquals(4, profile.variationAmplitude(), 0);
assertEquals(2, resolved.getRarity() + 1); assertEquals(2, resolved.rarity() + 1);
} }
} }
@@ -18,22 +18,13 @@
package art.arcane.iris.engine.object.terrain.floating; package art.arcane.iris.engine.object.terrain.floating;
import art.arcane.iris.core.modules.ModuleSettings;
import art.arcane.iris.core.modules.BuiltInPack;
import art.arcane.iris.builtin.floating.MergeFloatingChildrenSettings;
import art.arcane.iris.builtin.floating.FloatingChildBiome; import art.arcane.iris.builtin.floating.FloatingChildBiome;
import art.arcane.iris.engine.object.TestSettings; import art.arcane.iris.engine.object.TestSettings;
import art.arcane.iris.builtin.floating.TopShapeMode; import art.arcane.iris.builtin.floating.TopShapeMode;
import art.arcane.iris.engine.object.terrain.floating.FloatingIslandBoundarySampler;
import art.arcane.iris.engine.object.terrain.floating.FloatingIslandSample;
import art.arcane.iris.engine.object.world.IrisWorld;
import art.arcane.iris.engine.object.world.biome.IrisBiome;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.util.project.noise.CNG;
import art.arcane.volmlib.util.collection.KList; import art.arcane.volmlib.util.collection.KList;
import art.arcane.volmlib.util.math.RNG;
import com.volmit.host.ModuleLogs; import com.volmit.host.ModuleLogs;
import com.volmit.noise.NoiseSampler;
import com.volmit.resource.ResourceId;
import org.junit.Test; import org.junit.Test;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
@@ -49,15 +40,13 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame; import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
public class FloatingIslandBoundarySamplerTest { public class FloatingIslandBoundarySamplerTest {
@Test @Test
public void edgeFade_remainsFullInsideOneParentBiome() { public void edgeFade_remainsFullInsideOneParentBiome() {
IrisBiome parent = new IrisBiome(); ResourceId parent = ResourceId.parse("ns:parent");
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> parent); FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> parent);
assertEquals(1.0D, sampler.edgeFade(parent, 0, 0), 0.0D); assertEquals(1.0D, sampler.edgeFade(parent, 0, 0), 0.0D);
@@ -65,10 +54,8 @@ public class FloatingIslandBoundarySamplerTest {
@Test @Test
public void edgeFade_roundsTowardParentBiomeBoundary() { public void edgeFade_roundsTowardParentBiomeBoundary() {
IrisBiome left = new IrisBiome(); ResourceId left = ResourceId.parse("ns:left");
left.setLoadKey("left"); ResourceId right = ResourceId.parse("ns:right");
IrisBiome right = new IrisBiome();
right.setLoadKey("right");
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> x < 0 ? left : right); FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> x < 0 ? left : right);
assertEquals(FloatingIslandBoundarySampler.edgeFadeForDistance(1), sampler.edgeFade(right, 0, 0), 0.0D); assertEquals(FloatingIslandBoundarySampler.edgeFadeForDistance(1), sampler.edgeFade(right, 0, 0), 0.0D);
@@ -78,10 +65,8 @@ public class FloatingIslandBoundarySamplerTest {
@Test @Test
public void edgeFade_acceptsReloadedBiomeInstanceWithSameKey() { public void edgeFade_acceptsReloadedBiomeInstanceWithSameKey() {
IrisBiome expected = new IrisBiome(); ResourceId expected = ResourceId.parse("ns:magnetics/mycelium");
expected.setLoadKey("magnetics/mycelium"); ResourceId reloaded = ResourceId.parse("ns:magnetics/mycelium");
IrisBiome reloaded = new IrisBiome();
reloaded.setLoadKey("magnetics/mycelium");
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> reloaded); FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> reloaded);
assertEquals(1.0D, sampler.edgeFade(expected, 0, 0), 0.0D); assertEquals(1.0D, sampler.edgeFade(expected, 0, 0), 0.0D);
@@ -89,10 +74,8 @@ public class FloatingIslandBoundarySamplerTest {
@Test @Test
public void edgeFade_detectsOffAxisBoundaryWithinRadius() { public void edgeFade_detectsOffAxisBoundaryWithinRadius() {
IrisBiome parent = new IrisBiome(); ResourceId parent = ResourceId.parse("ns:parent");
parent.setLoadKey("parent"); ResourceId neighbor = ResourceId.parse("ns:neighbor");
IrisBiome neighbor = new IrisBiome();
neighbor.setLoadKey("neighbor");
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> x == 2 && z == 1 ? neighbor : parent); FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> x == 2 && z == 1 ? neighbor : parent);
assertEquals(FloatingIslandBoundarySampler.edgeFadeForDistance(2), sampler.edgeFade(parent, 0, 0), 0.0D); assertEquals(FloatingIslandBoundarySampler.edgeFadeForDistance(2), sampler.edgeFade(parent, 0, 0), 0.0D);
@@ -100,10 +83,8 @@ public class FloatingIslandBoundarySamplerTest {
@Test @Test
public void edgeFade_isSymmetricAcrossChunkBoundary() { public void edgeFade_isSymmetricAcrossChunkBoundary() {
IrisBiome left = new IrisBiome(); ResourceId left = ResourceId.parse("ns:left");
left.setLoadKey("left"); ResourceId right = ResourceId.parse("ns:right");
IrisBiome right = new IrisBiome();
right.setLoadKey("right");
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> x < 16 ? left : right); FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> x < 16 ? left : right);
assertEquals(sampler.edgeFade(left, 15, 0), sampler.edgeFade(right, 16, 0), 0.0D); assertEquals(sampler.edgeFade(left, 15, 0), sampler.edgeFade(right, 16, 0), 0.0D);
@@ -113,7 +94,7 @@ public class FloatingIslandBoundarySamplerTest {
@Test @Test
public void parent_cachesResolvedBiomeColumns() { public void parent_cachesResolvedBiomeColumns() {
IrisBiome parent = new IrisBiome(); ResourceId parent = ResourceId.parse("ns:parent");
AtomicInteger calls = new AtomicInteger(); AtomicInteger calls = new AtomicInteger();
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> { FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> {
calls.incrementAndGet(); calls.incrementAndGet();
@@ -130,7 +111,7 @@ public class FloatingIslandBoundarySamplerTest {
@Test @Test
public void edgeFade_boundsBiomeStreamReadsToChunkHalo() { public void edgeFade_boundsBiomeStreamReadsToChunkHalo() {
IrisBiome parent = new IrisBiome(); ResourceId parent = ResourceId.parse("ns:parent");
AtomicInteger calls = new AtomicInteger(); AtomicInteger calls = new AtomicInteger();
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> { FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> {
calls.incrementAndGet(); calls.incrementAndGet();
@@ -150,15 +131,15 @@ public class FloatingIslandBoundarySamplerTest {
@Test @Test
public void footprintFade_usesDistanceForSaturatedHalfPlane() { public void footprintFade_usesDistanceForSaturatedHalfPlane() {
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> null); FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> null);
CNG footprint = new CNG(new RNG(12)) { NoiseSampler footprint = new NoiseSampler() {
@Override @Override
public double noise(double x, double z) { public double sample(double x, double z) {
return x >= 0 ? 1.0D : 0.0D; return x >= 0 ? 1.0D : 0.0D;
} }
@Override @Override
public double noise(double x, double y, double z) { public double sample(double x, double y, double z) {
return noise(x, z); return sample(x, z);
} }
}; };
int[] depths = new int[FloatingIslandBoundarySampler.EDGE_TAPER_WIDTH]; int[] depths = new int[FloatingIslandBoundarySampler.EDGE_TAPER_WIDTH];
@@ -184,15 +165,15 @@ public class FloatingIslandBoundarySamplerTest {
@Test @Test
public void footprint_deepSingleCellPinholeRemainsSolid() { public void footprint_deepSingleCellPinholeRemainsSolid() {
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> null); FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> null);
CNG footprint = new CNG(new RNG(13)) { NoiseSampler footprint = new NoiseSampler() {
@Override @Override
public double noise(double x, double z) { public double sample(double x, double z) {
return x == 0.0D && z == 0.0D ? 0.0D : 1.0D; return x == 0.0D && z == 0.0D ? 0.0D : 1.0D;
} }
@Override @Override
public double noise(double x, double y, double z) { public double sample(double x, double y, double z) {
return noise(x, z); return sample(x, z);
} }
}; };
@@ -205,27 +186,27 @@ public class FloatingIslandBoundarySamplerTest {
@Test @Test
public void footprint_repairsOneByTwoAndDiagonalStaticGaps() { public void footprint_repairsOneByTwoAndDiagonalStaticGaps() {
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> null); FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> null);
CNG adjacent = new CNG(new RNG(27)) { NoiseSampler adjacent = new NoiseSampler() {
@Override @Override
public double noise(double x, double z) { public double sample(double x, double z) {
return z == 0.0D && (x == 0.0D || x == 1.0D) ? 0.0D : 1.0D; return z == 0.0D && (x == 0.0D || x == 1.0D) ? 0.0D : 1.0D;
} }
@Override @Override
public double noise(double x, double y, double z) { public double sample(double x, double y, double z) {
return noise(x, z); return sample(x, z);
} }
}; };
CNG diagonal = new CNG(new RNG(28)) { NoiseSampler diagonal = new NoiseSampler() {
@Override @Override
public double noise(double x, double z) { public double sample(double x, double z) {
boolean gap = x == 0.0D && z == 0.0D || x == 1.0D && z == 1.0D; boolean gap = x == 0.0D && z == 0.0D || x == 1.0D && z == 1.0D;
return gap ? 0.0D : 1.0D; return gap ? 0.0D : 1.0D;
} }
@Override @Override
public double noise(double x, double y, double z) { public double sample(double x, double y, double z) {
return noise(x, z); return sample(x, z);
} }
}; };
@@ -238,15 +219,15 @@ public class FloatingIslandBoundarySamplerTest {
@Test @Test
public void footprint_broadOpeningRemainsOpen() { public void footprint_broadOpeningRemainsOpen() {
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> null); FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> null);
CNG footprint = new CNG(new RNG(14)) { NoiseSampler footprint = new NoiseSampler() {
@Override @Override
public double noise(double x, double z) { public double sample(double x, double z) {
return Math.abs(x) <= 1.0D && Math.abs(z) <= 1.0D ? 0.0D : 1.0D; return Math.abs(x) <= 1.0D && Math.abs(z) <= 1.0D ? 0.0D : 1.0D;
} }
@Override @Override
public double noise(double x, double y, double z) { public double sample(double x, double y, double z) {
return noise(x, z); return sample(x, z);
} }
}; };
@@ -257,16 +238,16 @@ public class FloatingIslandBoundarySamplerTest {
public void footprint_buildsOneBoundedChunkHalo() { public void footprint_buildsOneBoundedChunkHalo() {
AtomicInteger calls = new AtomicInteger(); AtomicInteger calls = new AtomicInteger();
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> null); FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> null);
CNG footprint = new CNG(new RNG(15)) { NoiseSampler footprint = new NoiseSampler() {
@Override @Override
public double noise(double x, double z) { public double sample(double x, double z) {
calls.incrementAndGet(); calls.incrementAndGet();
return 1.0D; return 1.0D;
} }
@Override @Override
public double noise(double x, double y, double z) { public double sample(double x, double y, double z) {
return noise(x, z); return sample(x, z);
} }
}; };
@@ -282,15 +263,15 @@ public class FloatingIslandBoundarySamplerTest {
@Test @Test
public void footprintFade_isStableAcrossChunkAlignedFields() { public void footprintFade_isStableAcrossChunkAlignedFields() {
CNG footprint = new CNG(new RNG(16)) { NoiseSampler footprint = new NoiseSampler() {
@Override @Override
public double noise(double x, double z) { public double sample(double x, double z) {
return z >= 0.0D ? 1.0D : 0.0D; return z >= 0.0D ? 1.0D : 0.0D;
} }
@Override @Override
public double noise(double x, double y, double z) { public double sample(double x, double y, double z) {
return noise(x, z); return sample(x, z);
} }
}; };
FloatingIslandBoundarySampler forwardSampler = new FloatingIslandBoundarySampler((x, z) -> null); FloatingIslandBoundarySampler forwardSampler = new FloatingIslandBoundarySampler((x, z) -> null);
@@ -316,15 +297,15 @@ public class FloatingIslandBoundarySamplerTest {
@Test @Test
public void footprint_rejectsTwoColumnStaticFragment() { public void footprint_rejectsTwoColumnStaticFragment() {
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> null); FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> null);
CNG footprint = new CNG(new RNG(17)) { NoiseSampler footprint = new NoiseSampler() {
@Override @Override
public double noise(double x, double z) { public double sample(double x, double z) {
return z == 0.0D && (x == 0.0D || x == 1.0D) ? 1.0D : 0.0D; return z == 0.0D && (x == 0.0D || x == 1.0D) ? 1.0D : 0.0D;
} }
@Override @Override
public double noise(double x, double y, double z) { public double sample(double x, double y, double z) {
return noise(x, z); return sample(x, z);
} }
}; };
@@ -335,26 +316,26 @@ public class FloatingIslandBoundarySamplerTest {
@Test @Test
public void footprint_rejectsComponentWithoutThreeCellDeepCore() { public void footprint_rejectsComponentWithoutThreeCellDeepCore() {
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> null); FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> null);
CNG threeByThree = new CNG(new RNG(21)) { NoiseSampler threeByThree = new NoiseSampler() {
@Override @Override
public double noise(double x, double z) { public double sample(double x, double z) {
return Math.abs(x) <= 1.0D && Math.abs(z) <= 1.0D ? 1.0D : 0.0D; return Math.abs(x) <= 1.0D && Math.abs(z) <= 1.0D ? 1.0D : 0.0D;
} }
@Override @Override
public double noise(double x, double y, double z) { public double sample(double x, double y, double z) {
return noise(x, z); return sample(x, z);
} }
}; };
CNG fourWideTendril = new CNG(new RNG(22)) { NoiseSampler fourWideTendril = new NoiseSampler() {
@Override @Override
public double noise(double x, double z) { public double sample(double x, double z) {
return x >= 0.0D && x <= 3.0D ? 1.0D : 0.0D; return x >= 0.0D && x <= 3.0D ? 1.0D : 0.0D;
} }
@Override @Override
public double noise(double x, double y, double z) { public double sample(double x, double y, double z) {
return noise(x, z); return sample(x, z);
} }
}; };
@@ -366,15 +347,15 @@ public class FloatingIslandBoundarySamplerTest {
@Test @Test
public void footprint_acceptsComponentWithThreeCellDeepCore() { public void footprint_acceptsComponentWithThreeCellDeepCore() {
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> null); FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> null);
CNG footprint = new CNG(new RNG(23)) { NoiseSampler footprint = new NoiseSampler() {
@Override @Override
public double noise(double x, double z) { public double sample(double x, double z) {
return Math.abs(x) <= 2.0D && Math.abs(z) <= 2.0D ? 1.0D : 0.0D; return Math.abs(x) <= 2.0D && Math.abs(z) <= 2.0D ? 1.0D : 0.0D;
} }
@Override @Override
public double noise(double x, double y, double z) { public double sample(double x, double y, double z) {
return noise(x, z); return sample(x, z);
} }
}; };
@@ -387,17 +368,17 @@ public class FloatingIslandBoundarySamplerTest {
@Test @Test
public void footprint_trimsAttachedThinArmWithoutChunkSeam() { public void footprint_trimsAttachedThinArmWithoutChunkSeam() {
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> null); FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> null);
CNG footprint = new CNG(new RNG(25)) { NoiseSampler footprint = new NoiseSampler() {
@Override @Override
public double noise(double x, double z) { public double sample(double x, double z) {
boolean arm = Math.abs(z) <= 1.0D; boolean arm = Math.abs(z) <= 1.0D;
boolean core = x >= -10.0D && x <= -6.0D && Math.abs(z) <= 2.0D; boolean core = x >= -10.0D && x <= -6.0D && Math.abs(z) <= 2.0D;
return arm || core ? 1.0D : 0.0D; return arm || core ? 1.0D : 0.0D;
} }
@Override @Override
public double noise(double x, double y, double z) { public double sample(double x, double y, double z) {
return noise(x, z); return sample(x, z);
} }
}; };
@@ -408,20 +389,20 @@ public class FloatingIslandBoundarySamplerTest {
@Test @Test
public void ownershipFade_tapersAcrossPickerBoundary() { public void ownershipFade_tapersAcrossPickerBoundary() {
ResolvedFloatingChild left = new ResolvedFloatingChild(new FloatingChildBiome()); ResolvedFloatingChild left = new ResolvedFloatingChild(new FloatingChildBiome(), null);
ResolvedFloatingChild right = new ResolvedFloatingChild(new FloatingChildBiome()); ResolvedFloatingChild right = new ResolvedFloatingChild(new FloatingChildBiome(), null);
KList<ResolvedFloatingChild> entries = new KList<>(); KList<ResolvedFloatingChild> entries = new KList<>();
entries.add(left); entries.add(left);
entries.add(right); entries.add(right);
CNG picker = new CNG(new RNG(18)) { NoiseSampler picker = new NoiseSampler() {
@Override @Override
public double noise(double x, double z) { public double sample(double x, double z) {
return x < 0.0D ? 0.0D : 1.0D; return x < 0.0D ? 0.0D : 1.0D;
} }
@Override @Override
public double noise(double x, double y, double z) { public double sample(double x, double y, double z) {
return noise(x, z); return sample(x, z);
} }
}; };
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> null); FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> null);
@@ -437,20 +418,20 @@ public class FloatingIslandBoundarySamplerTest {
@Test @Test
public void ownershipFade_rejectsThinPickerRegion() { public void ownershipFade_rejectsThinPickerRegion() {
ResolvedFloatingChild left = new ResolvedFloatingChild(new FloatingChildBiome()); ResolvedFloatingChild left = new ResolvedFloatingChild(new FloatingChildBiome(), null);
ResolvedFloatingChild right = new ResolvedFloatingChild(new FloatingChildBiome()); ResolvedFloatingChild right = new ResolvedFloatingChild(new FloatingChildBiome(), null);
KList<ResolvedFloatingChild> entries = new KList<>(); KList<ResolvedFloatingChild> entries = new KList<>();
entries.add(left); entries.add(left);
entries.add(right); entries.add(right);
CNG picker = new CNG(new RNG(24)) { NoiseSampler picker = new NoiseSampler() {
@Override @Override
public double noise(double x, double z) { public double sample(double x, double z) {
return Math.abs(x) <= 1.0D ? 1.0D : 0.0D; return Math.abs(x) <= 1.0D ? 1.0D : 0.0D;
} }
@Override @Override
public double noise(double x, double y, double z) { public double sample(double x, double y, double z) {
return noise(x, z); return sample(x, z);
} }
}; };
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> null); FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> null);
@@ -463,24 +444,22 @@ public class FloatingIslandBoundarySamplerTest {
@Test @Test
public void labelFieldsTrimAttachedThinArmWithoutChunkSeam() { public void labelFieldsTrimAttachedThinArmWithoutChunkSeam() {
IrisBiome leftParent = new IrisBiome(); ResourceId leftParent = ResourceId.parse("ns:left");
leftParent.setLoadKey("left"); ResourceId rightParent = ResourceId.parse("ns:right");
IrisBiome rightParent = new IrisBiome(); ResolvedFloatingChild leftChild = new ResolvedFloatingChild(new FloatingChildBiome(), null);
rightParent.setLoadKey("right"); ResolvedFloatingChild rightChild = new ResolvedFloatingChild(new FloatingChildBiome(), null);
ResolvedFloatingChild leftChild = new ResolvedFloatingChild(new FloatingChildBiome());
ResolvedFloatingChild rightChild = new ResolvedFloatingChild(new FloatingChildBiome());
KList<ResolvedFloatingChild> entries = new KList<>(); KList<ResolvedFloatingChild> entries = new KList<>();
entries.add(leftChild); entries.add(leftChild);
entries.add(rightChild); entries.add(rightChild);
CNG picker = new CNG(new RNG(29)) { NoiseSampler picker = new NoiseSampler() {
@Override @Override
public double noise(double x, double z) { public double sample(double x, double z) {
return isAttachedArm(x, z) ? 1.0D : 0.0D; return isAttachedArm(x, z) ? 1.0D : 0.0D;
} }
@Override @Override
public double noise(double x, double y, double z) { public double sample(double x, double y, double z) {
return noise(x, z); return sample(x, z);
} }
}; };
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler( FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler(
@@ -497,21 +476,20 @@ public class FloatingIslandBoundarySamplerTest {
@Test @Test
public void sampler_fieldsPublishSafelyAcrossConcurrentReaders() throws Exception { public void sampler_fieldsPublishSafelyAcrossConcurrentReaders() throws Exception {
IrisBiome parent = new IrisBiome(); ResourceId parent = ResourceId.parse("ns:parent");
parent.setLoadKey("parent"); ResolvedFloatingChild left = new ResolvedFloatingChild(new FloatingChildBiome(), null);
ResolvedFloatingChild left = new ResolvedFloatingChild(new FloatingChildBiome()); ResolvedFloatingChild right = new ResolvedFloatingChild(new FloatingChildBiome(), null);
ResolvedFloatingChild right = new ResolvedFloatingChild(new FloatingChildBiome());
KList<ResolvedFloatingChild> entries = new KList<>(); KList<ResolvedFloatingChild> entries = new KList<>();
entries.add(left); entries.add(left);
entries.add(right); entries.add(right);
CNG constant = new CNG(new RNG(26)) { NoiseSampler constant = new NoiseSampler() {
@Override @Override
public double noise(double x, double z) { public double sample(double x, double z) {
return 1.0D; return 1.0D;
} }
@Override @Override
public double noise(double x, double y, double z) { public double sample(double x, double y, double z) {
return 1.0D; return 1.0D;
} }
}; };
@@ -538,55 +516,50 @@ public class FloatingIslandBoundarySamplerTest {
@Test @Test
public void sample_appliesSpatialProfileToFinalWorldCoordinates() { public void sample_appliesSpatialProfileToFinalWorldCoordinates() {
CNG footprint = new CNG(new RNG(19)) { NoiseSampler footprint = new NoiseSampler() {
@Override @Override
public double noise(double x, double z) { public double sample(double x, double z) {
return x >= 0.0D ? 1.0D : 0.0D; return x >= 0.0D ? 1.0D : 0.0D;
} }
@Override @Override
public double noise(double x, double y, double z) { public double sample(double x, double y, double z) {
return noise(x, z); return sample(x, z);
} }
}; };
CNG constant = new CNG(new RNG(20)) { NoiseSampler constant = new NoiseSampler() {
@Override @Override
public double noise(double x, double z) { public double sample(double x, double z) {
return 1.0D; return 1.0D;
} }
@Override @Override
public double noise(double x, double y, double z) { public double sample(double x, double y, double z) {
return 1.0D; return 1.0D;
} }
}; };
ResolvedFloatingChild entry = mock(ResolvedFloatingChild.class); ResolvedFloatingChild entry = mock(ResolvedFloatingChild.class);
IrisBiome parent = mock(IrisBiome.class); ResourceId parent = ResourceId.parse("ns:parent");
IrisData data = mock(IrisData.class);
Engine engine = mock(Engine.class);
IrisWorld world = IrisWorld.builder().minHeight(0).maxHeight(320).build();
KList<ResolvedFloatingChild> entries = new KList<>(); KList<ResolvedFloatingChild> entries = new KList<>();
entries.add(entry); entries.add(entry);
ModuleSettings separate = BuiltInPack.settings(new MergeFloatingChildrenSettings(false)); FloatingWorld world = floatingWorld(parent, false, 31L);
when(parent.getModuleSettings()).thenReturn(separate); when(entry.footprintNoise()).thenReturn(footprint);
when(entry.getFootprintCng(anyLong(), same(data))).thenReturn(footprint); when(entry.altitudeNoise()).thenReturn(constant);
when(entry.getAltitudeCng(anyLong(), same(data))).thenReturn(constant); when(entry.realBiome(parent)).thenReturn(parent);
when(entry.getRealBiome(parent, data)).thenReturn(parent); when(entry.topShapeNoise()).thenReturn(constant);
when(entry.getTopShapeCng(anyLong(), same(data))).thenReturn(constant); when(entry.bottomNoise()).thenReturn(constant);
when(entry.getBottomCng(anyLong(), same(data))).thenReturn(constant); when(entry.wallWarpNoise()).thenReturn(null);
when(entry.getWallWarpCng(anyLong(), same(data))).thenReturn(null); when(entry.carvingProfileSampler()).thenReturn(null);
when(entry.getCarvingProfileSampler(engine, data)).thenReturn(null);
when(entry.hasCarvingReference()).thenReturn(false); when(entry.hasCarvingReference()).thenReturn(false);
when(entry.getCarveCng(anyLong(), same(data))).thenReturn(constant); when(entry.carveNoise()).thenReturn(constant);
when(entry.settings()).thenReturn(TestSettings.with(new FloatingChildBiome(), "footprintThreshold", 0.5D, "minHeightAboveSurface", 160, "maxHeightAboveSurface", 160, "topShapeMode", TopShapeMode.NOISE, "topShapeAmp", 1.0D, "maxTopHeight", 18, "bottomExponent", 1.0D, "bottomDepthMin", 20, "bottomDepthMax", 20, "maxThickness", 64, "wallWarpAmplitude", 0.0D, "carveThreshold", 0.5D)); when(entry.settings()).thenReturn(TestSettings.with(new FloatingChildBiome(), "footprintThreshold", 0.5D, "minHeightAboveSurface", 160, "maxHeightAboveSurface", 160, "topShapeMode", TopShapeMode.NOISE, "topShapeAmp", 1.0D, "maxTopHeight", 18, "bottomExponent", 1.0D, "bottomDepthMin", 20, "bottomDepthMax", 20, "maxThickness", 64, "wallWarpAmplitude", 0.0D, "carveThreshold", 0.5D));
when(engine.getWorld()).thenReturn(world);
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> parent); FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> parent);
int[] expectedBottom = {159, 158, 156, 153, 150, 147, 144, 142, 141, 140}; int[] expectedBottom = {159, 158, 156, 153, 150, 147, 144, 142, 141, 140};
int[] expectedTop = {161, 162, 164, 166, 169, 172, 174, 176, 177, 178}; int[] expectedTop = {161, 162, 164, 166, 169, 172, 174, 176, 177, 178};
assertNull(FloatingIslandSample.sample(parent, entries, 0, 0, 320, 31L, data, engine, sampler, ModuleLogs.discarding())); assertNull(FloatingIslandSample.sample(parent, entries, 0, 0, 320, world, sampler, ModuleLogs.discarding()));
for (int i = 0; i < expectedBottom.length; i++) { for (int i = 0; i < expectedBottom.length; i++) {
FloatingIslandSample sample = FloatingIslandSample.sample(parent, entries, i + 1, 0, 320, 31L, data, engine, sampler, ModuleLogs.discarding()); FloatingIslandSample sample = FloatingIslandSample.sample(parent, entries, i + 1, 0, 320, world, sampler, ModuleLogs.discarding());
assertNotNull("distance " + (i + 2) + " rejected with code " + FloatingIslandSample.getLastReject(), sample); assertNotNull("distance " + (i + 2) + " rejected with code " + FloatingIslandSample.getLastReject(), sample);
assertEquals(expectedBottom[i], sample.bottomY()); assertEquals(expectedBottom[i], sample.bottomY());
assertEquals(expectedTop[i], sample.topY()); assertEquals(expectedTop[i], sample.topY());
@@ -604,57 +577,52 @@ public class FloatingIslandBoundarySamplerTest {
@Test @Test
public void sample_mergesNoiseTopEntriesAcrossSpatialRim() { public void sample_mergesNoiseTopEntriesAcrossSpatialRim() {
CNG footprint = new CNG(new RNG(33)) { NoiseSampler footprint = new NoiseSampler() {
@Override @Override
public double noise(double x, double z) { public double sample(double x, double z) {
return x >= 0.0D ? 1.0D : 0.0D; return x >= 0.0D ? 1.0D : 0.0D;
} }
@Override @Override
public double noise(double x, double y, double z) { public double sample(double x, double y, double z) {
return noise(x, z); return sample(x, z);
} }
}; };
CNG constant = new CNG(new RNG(34)) { NoiseSampler constant = new NoiseSampler() {
@Override @Override
public double noise(double x, double z) { public double sample(double x, double z) {
return 1.0D; return 1.0D;
} }
@Override @Override
public double noise(double x, double y, double z) { public double sample(double x, double y, double z) {
return 1.0D; return 1.0D;
} }
}; };
ResolvedFloatingChild lower = mock(ResolvedFloatingChild.class); ResolvedFloatingChild lower = mock(ResolvedFloatingChild.class);
ResolvedFloatingChild upper = mock(ResolvedFloatingChild.class); ResolvedFloatingChild upper = mock(ResolvedFloatingChild.class);
IrisBiome parent = mock(IrisBiome.class); ResourceId parent = ResourceId.parse("ns:parent");
IrisData data = mock(IrisData.class);
Engine engine = mock(Engine.class);
IrisWorld world = IrisWorld.builder().minHeight(0).maxHeight(320).build();
KList<ResolvedFloatingChild> entries = new KList<>(); KList<ResolvedFloatingChild> entries = new KList<>();
entries.add(lower); entries.add(lower);
entries.add(upper); entries.add(upper);
ModuleSettings merged = BuiltInPack.settings(new MergeFloatingChildrenSettings(true)); FloatingWorld world = floatingWorld(parent, true, 35L);
when(parent.getModuleSettings()).thenReturn(merged);
for (ResolvedFloatingChild entry : entries) { for (ResolvedFloatingChild entry : entries) {
when(entry.getFootprintCng(anyLong(), same(data))).thenReturn(footprint); when(entry.footprintNoise()).thenReturn(footprint);
when(entry.getAltitudeCng(anyLong(), same(data))).thenReturn(constant); when(entry.altitudeNoise()).thenReturn(constant);
when(entry.getRealBiome(parent, data)).thenReturn(parent); when(entry.realBiome(parent)).thenReturn(parent);
when(entry.getTopShapeCng(anyLong(), same(data))).thenReturn(constant); when(entry.topShapeNoise()).thenReturn(constant);
when(entry.getBottomCng(anyLong(), same(data))).thenReturn(constant); when(entry.bottomNoise()).thenReturn(constant);
when(entry.getWallWarpCng(anyLong(), same(data))).thenReturn(null); when(entry.wallWarpNoise()).thenReturn(null);
when(entry.getCarvingProfileSampler(engine, data)).thenReturn(null); when(entry.carvingProfileSampler()).thenReturn(null);
when(entry.hasCarvingReference()).thenReturn(false); when(entry.hasCarvingReference()).thenReturn(false);
when(entry.getCarveCng(anyLong(), same(data))).thenReturn(null); when(entry.carveNoise()).thenReturn(null);
when(entry.settings()).thenReturn(TestSettings.with(new FloatingChildBiome(), "footprintThreshold", 0.5D, "topShapeMode", TopShapeMode.NOISE, "topShapeAmp", 1.0D, "maxTopHeight", 18, "bottomExponent", 1.0D, "bottomDepthMin", 20, "bottomDepthMax", 20, "maxThickness", 64, "wallWarpAmplitude", 0.0D, "carveThreshold", 1.0D, when(entry.settings()).thenReturn(TestSettings.with(new FloatingChildBiome(), "footprintThreshold", 0.5D, "topShapeMode", TopShapeMode.NOISE, "topShapeAmp", 1.0D, "maxTopHeight", 18, "bottomExponent", 1.0D, "bottomDepthMin", 20, "bottomDepthMax", 20, "maxThickness", 64, "wallWarpAmplitude", 0.0D, "carveThreshold", 1.0D,
"minHeightAboveSurface", entry == lower ? 160 : 180, "maxHeightAboveSurface", entry == lower ? 160 : 180)); "minHeightAboveSurface", entry == lower ? 160 : 180, "maxHeightAboveSurface", entry == lower ? 160 : 180));
} }
when(engine.getWorld()).thenReturn(world);
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> parent); FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> parent);
assertNull(FloatingIslandSample.sample(parent, entries, 0, 0, 320, 35L, data, engine, sampler, ModuleLogs.discarding())); assertNull(FloatingIslandSample.sample(parent, entries, 0, 0, 320, world, sampler, ModuleLogs.discarding()));
FloatingIslandSample sample = FloatingIslandSample.sample(parent, entries, 1, 0, 320, 35L, data, engine, sampler, ModuleLogs.discarding()); FloatingIslandSample sample = FloatingIslandSample.sample(parent, entries, 1, 0, 320, world, sampler, ModuleLogs.discarding());
assertNotNull(sample); assertNotNull(sample);
assertTrue(sample.hasMergedEntries()); assertTrue(sample.hasMergedEntries());
@@ -665,6 +633,14 @@ public class FloatingIslandBoundarySamplerTest {
assertSame(upper, sample.entryAt(sample.topIdx)); assertSame(upper, sample.entryAt(sample.topIdx));
} }
private static FloatingWorld floatingWorld(ResourceId parent, boolean merges, long baseSeed) {
FloatingWorld world = mock(FloatingWorld.class);
when(world.merges(parent)).thenReturn(merges);
when(world.baseSeed()).thenReturn(baseSeed);
when(world.minHeight()).thenReturn(0);
return world;
}
private static boolean isAttachedArm(double x, double z) { private static boolean isAttachedArm(double x, double z) {
return Math.abs(z) <= 1.0D || x >= -10.0D && x <= -6.0D && Math.abs(z) <= 2.0D; return Math.abs(z) <= 1.0D || x >= -10.0D && x <= -6.0D && Math.abs(z) <= 2.0D;
} }
@@ -2,10 +2,7 @@ package art.arcane.iris.engine.object.terrain.floating;
import art.arcane.iris.engine.object.TestSettings; import art.arcane.iris.engine.object.TestSettings;
import art.arcane.iris.builtin.floating.FloatingChildBiome; import art.arcane.iris.builtin.floating.FloatingChildBiome;
import art.arcane.iris.engine.object.terrain.floating.FloatingIslandSample; import com.volmit.noise.NoiseSampler;
import art.arcane.iris.util.project.noise.CNG;
import art.arcane.iris.util.project.noise.NoiseGenerator;
import art.arcane.volmlib.util.math.RNG;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@@ -63,8 +60,8 @@ public class FloatingIslandSampleBottomYTest {
@Test @Test
public void mergedEntryMask_preservesTopAndBottomOwners() { public void mergedEntryMask_preservesTopAndBottomOwners() {
ResolvedFloatingChild bottom = new ResolvedFloatingChild(new FloatingChildBiome()); ResolvedFloatingChild bottom = new ResolvedFloatingChild(new FloatingChildBiome(), null);
ResolvedFloatingChild top = new ResolvedFloatingChild(new FloatingChildBiome()); ResolvedFloatingChild top = new ResolvedFloatingChild(new FloatingChildBiome(), null);
boolean[] mask = {true, true, false, true}; boolean[] mask = {true, true, false, true};
ResolvedFloatingChild[] entryMask = {bottom, bottom, null, top}; ResolvedFloatingChild[] entryMask = {bottom, bottom, null, top};
FloatingIslandSample sample = FloatingIslandSample.constructForTest(top, 80, mask.length, 3, 3, mask, entryMask); FloatingIslandSample sample = FloatingIslandSample.constructForTest(top, 80, mask.length, 3, 3, mask, entryMask);
@@ -132,7 +129,7 @@ public class FloatingIslandSampleBottomYTest {
public void carveSolidInterior_preservesOuterShell() { public void carveSolidInterior_preservesOuterShell() {
boolean[] mask = {false, true, true, true, true, false}; boolean[] mask = {false, true, true, true, true, false};
boolean[] lateralCarveMask = {true, true, true, true, true, true}; boolean[] lateralCarveMask = {true, true, true, true, true, true};
CNG carve = constantCng(1.0); NoiseSampler carve = constantNoise(1.0);
int count = FloatingIslandSample.carveSolidInterior(mask, lateralCarveMask, 100, 0, 0, carve, 0.5); int count = FloatingIslandSample.carveSolidInterior(mask, lateralCarveMask, 100, 0, 0, carve, 0.5);
@@ -150,7 +147,7 @@ public class FloatingIslandSampleBottomYTest {
boolean[] mask = {true, true, true, true, true, true}; boolean[] mask = {true, true, true, true, true, true};
boolean[] lateralCarveMask = {false, false, false, false, false, false}; boolean[] lateralCarveMask = {false, false, false, false, false, false};
int count = FloatingIslandSample.carveSolidInterior(mask, lateralCarveMask, 100, 0, 0, constantCng(1.0), 0.5); int count = FloatingIslandSample.carveSolidInterior(mask, lateralCarveMask, 100, 0, 0, constantNoise(1.0), 0.5);
assertEquals(6, count); assertEquals(6, count);
for (boolean solid : mask) { for (boolean solid : mask) {
@@ -160,17 +157,17 @@ public class FloatingIslandSampleBottomYTest {
@Test @Test
public void lateralCarving_requiresRoundedInteriorAndFullNeighborRing() { public void lateralCarving_requiresRoundedInteriorAndFullNeighborRing() {
CNG fullRing = constantCng(1.0); NoiseSampler fullRing = constantNoise(1.0);
FloatingIslandSample.NeighborSupport fullSupport = FloatingIslandSample.footprintNeighborSupport(fullRing, 0, 0, 0.0); FloatingIslandSample.NeighborSupport fullSupport = FloatingIslandSample.footprintNeighborSupport(fullRing, 0, 0, 0.0);
CNG missingDiagonal = new CNG(new RNG(11)) { NoiseSampler missingDiagonal = new NoiseSampler() {
@Override @Override
public double noise(double x, double z) { public double sample(double x, double z) {
return x == 1 && z == 1 ? 0.0 : 1.0; return x == 1 && z == 1 ? 0.0 : 1.0;
} }
@Override @Override
public double noise(double x, double y, double z) { public double sample(double x, double y, double z) {
return noise(x, z); return sample(x, z);
} }
}; };
FloatingIslandSample.NeighborSupport partialSupport = FloatingIslandSample.footprintNeighborSupport(missingDiagonal, 0, 0, 0.0); FloatingIslandSample.NeighborSupport partialSupport = FloatingIslandSample.footprintNeighborSupport(missingDiagonal, 0, 0, 0.0);
@@ -182,15 +179,15 @@ public class FloatingIslandSampleBottomYTest {
@Test @Test
public void footprintPinholeFill_acceptsSingleColumnHoleWithSolidRing() { public void footprintPinholeFill_acceptsSingleColumnHoleWithSolidRing() {
CNG footprint = new CNG(new RNG(4)) { NoiseSampler footprint = new NoiseSampler() {
@Override @Override
public double noise(double x, double z) { public double sample(double x, double z) {
return x == 0 && z == 0 ? 0.46 : 1.0; return x == 0 && z == 0 ? 0.46 : 1.0;
} }
@Override @Override
public double noise(double x, double y, double z) { public double sample(double x, double y, double z) {
return noise(x, z); return sample(x, z);
} }
}; };
@@ -200,15 +197,15 @@ public class FloatingIslandSampleBottomYTest {
@Test @Test
public void footprintPinholeFill_keepsBroadHoleOpen() { public void footprintPinholeFill_keepsBroadHoleOpen() {
CNG footprint = new CNG(new RNG(5)) { NoiseSampler footprint = new NoiseSampler() {
@Override @Override
public double noise(double x, double z) { public double sample(double x, double z) {
return Math.abs(x) <= 1 && Math.abs(z) <= 1 ? 0.0 : 1.0; return Math.abs(x) <= 1 && Math.abs(z) <= 1 ? 0.0 : 1.0;
} }
@Override @Override
public double noise(double x, double y, double z) { public double sample(double x, double y, double z) {
return noise(x, z); return sample(x, z);
} }
}; };
@@ -218,15 +215,15 @@ public class FloatingIslandSampleBottomYTest {
@Test @Test
public void layerSupport_rejectsIsolatedSolidProtrusion() { public void layerSupport_rejectsIsolatedSolidProtrusion() {
CNG footprint = new CNG(new RNG(6)) { NoiseSampler footprint = new NoiseSampler() {
@Override @Override
public double noise(double x, double z) { public double sample(double x, double z) {
return x == 0 && z == 0 ? 1.0 : 0.0; return x == 0 && z == 0 ? 1.0 : 0.0;
} }
@Override @Override
public double noise(double x, double y, double z) { public double sample(double x, double y, double z) {
return noise(x, z); return sample(x, z);
} }
}; };
@@ -236,15 +233,15 @@ public class FloatingIslandSampleBottomYTest {
@Test @Test
public void layerSupport_fillsSingleColumnAirGap() { public void layerSupport_fillsSingleColumnAirGap() {
CNG footprint = new CNG(new RNG(7)) { NoiseSampler footprint = new NoiseSampler() {
@Override @Override
public double noise(double x, double z) { public double sample(double x, double z) {
return x == 0 && z == 0 ? 0.0 : 1.0; return x == 0 && z == 0 ? 0.0 : 1.0;
} }
@Override @Override
public double noise(double x, double y, double z) { public double sample(double x, double y, double z) {
return noise(x, z); return sample(x, z);
} }
}; };
@@ -255,22 +252,17 @@ public class FloatingIslandSampleBottomYTest {
@Test @Test
public void carveSolidInterior_rejectsIsolatedCarveAir() { public void carveSolidInterior_rejectsIsolatedCarveAir() {
boolean[] mask = {true, true, true, true, true}; boolean[] mask = {true, true, true, true, true};
CNG carve = new CNG(new RNG(8), new NoiseGenerator() { NoiseSampler carve = new NoiseSampler() {
@Override @Override
public double noise(double x) { public double sample(double x, double z) {
return 0.0;
}
@Override
public double noise(double x, double z) {
return x == 0 && z == 0 ? 1.0 : 0.0; return x == 0 && z == 0 ? 1.0 : 0.0;
} }
@Override @Override
public double noise(double x, double y, double z) { public double sample(double x, double y, double z) {
return noise(x, z); return sample(x, z);
} }
}, 1.0, 1); };
boolean[] lateralCarveMask = {true, true, true, true, true}; boolean[] lateralCarveMask = {true, true, true, true, true};
int count = FloatingIslandSample.carveSolidInterior(mask, lateralCarveMask, 100, 0, 0, carve, 0.5); int count = FloatingIslandSample.carveSolidInterior(mask, lateralCarveMask, 100, 0, 0, carve, 0.5);
@@ -289,7 +281,7 @@ public class FloatingIslandSampleBottomYTest {
mask[i] = true; mask[i] = true;
lateralCarveMask[i] = true; lateralCarveMask[i] = true;
} }
CNG carve = constantCng(1.0); NoiseSampler carve = constantNoise(1.0);
int count = FloatingIslandSample.carveSolidInterior(mask, lateralCarveMask, 100, 0, 0, carve, 0.5); int count = FloatingIslandSample.carveSolidInterior(mask, lateralCarveMask, 100, 0, 0, carve, 0.5);
@@ -328,23 +320,23 @@ public class FloatingIslandSampleBottomYTest {
@Test @Test
public void directCarveEnabled_respectsCarvingReferenceOverride() { public void directCarveEnabled_respectsCarvingReferenceOverride() {
ResolvedFloatingChild entry = new ResolvedFloatingChild(TestSettings.with(new FloatingChildBiome(), "carving", "carving/mushroom")); ResolvedFloatingChild entry = new ResolvedFloatingChild(TestSettings.with(new FloatingChildBiome(), "carving", "carving/mushroom"), null);
CNG carve = new CNG(new RNG(9)); NoiseSampler carve = constantNoise(0.0);
assertFalse(FloatingIslandSample.directCarveEnabled(entry, null, carve, 0.5)); assertFalse(FloatingIslandSample.directCarveEnabled(entry, null, carve, 0.5));
} }
@Test @Test
public void hasFootprintNeighborSupport_rejectsSingleIsolatedColumn() { public void hasFootprintNeighborSupport_rejectsSingleIsolatedColumn() {
CNG footprint = new CNG(new RNG(2)) { NoiseSampler footprint = new NoiseSampler() {
@Override @Override
public double noise(double x, double z) { public double sample(double x, double z) {
return x == 0 && z == 0 ? 1.0 : 0.0; return x == 0 && z == 0 ? 1.0 : 0.0;
} }
@Override @Override
public double noise(double x, double y, double z) { public double sample(double x, double y, double z) {
return noise(x, z); return sample(x, z);
} }
}; };
@@ -353,37 +345,32 @@ public class FloatingIslandSampleBottomYTest {
@Test @Test
public void hasFootprintNeighborSupport_acceptsCardinalNeighbor() { public void hasFootprintNeighborSupport_acceptsCardinalNeighbor() {
CNG footprint = new CNG(new RNG(3)) { NoiseSampler footprint = new NoiseSampler() {
@Override @Override
public double noise(double x, double z) { public double sample(double x, double z) {
return (x == 0 && z == 0) || (x == 1 && z == 0) ? 1.0 : 0.0; return (x == 0 && z == 0) || (x == 1 && z == 0) ? 1.0 : 0.0;
} }
@Override @Override
public double noise(double x, double y, double z) { public double sample(double x, double y, double z) {
return noise(x, z); return sample(x, z);
} }
}; };
assertEquals(true, FloatingIslandSample.hasFootprintNeighborSupport(footprint, 0, 0, 0.0)); assertEquals(true, FloatingIslandSample.hasFootprintNeighborSupport(footprint, 0, 0, 0.0));
} }
private CNG constantCng(double value) { private NoiseSampler constantNoise(double value) {
return new CNG(new RNG(12), new NoiseGenerator() { return new NoiseSampler() {
@Override @Override
public double noise(double x) { public double sample(double x, double z) {
return value; return value;
} }
@Override @Override
public double noise(double x, double z) { public double sample(double x, double y, double z) {
return value; return value;
} }
};
@Override
public double noise(double x, double y, double z) {
return value;
}
}, 1.0, 1);
} }
} }
@@ -0,0 +1,16 @@
package art.arcane.iris.engine.object.terrain.floating;
/** Builds {@link FloatingIslandSample}s for tests outside the floating package. */
public final class FloatingIslandSamples {
private FloatingIslandSamples() {
}
public static FloatingIslandSample of(int islandBaseY, int thickness, int topIdx, int solidCount, boolean[] solidMask) {
return FloatingIslandSample.constructForTest(islandBaseY, thickness, topIdx, solidCount, solidMask);
}
public static FloatingIslandSample of(ResolvedFloatingChild entry, int islandBaseY, int thickness, int topIdx, int solidCount,
boolean[] solidMask, ResolvedFloatingChild[] entryMask) {
return FloatingIslandSample.constructForTest(entry, islandBaseY, thickness, topIdx, solidCount, solidMask, entryMask);
}
}
@@ -1,123 +1,48 @@
package art.arcane.iris.engine.object.terrain.floating; package art.arcane.iris.engine.object.terrain.floating;
import art.arcane.iris.engine.object.world.biome.IrisBiome;
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
import art.arcane.iris.builtin.carve.CarvingEntry; import art.arcane.iris.builtin.carve.CarvingEntry;
import art.arcane.iris.builtin.carve.CarvingSettings; import art.arcane.iris.builtin.floating.FloatingChildBiome;
import art.arcane.iris.core.modules.BuiltInPack; import art.arcane.iris.builtin.floating.FloatingHost;
import art.arcane.iris.core.modules.ModuleSettings; import art.arcane.iris.engine.object.TestSettings;
import art.arcane.iris.engine.decorator.DecoratorTestEngines;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.core.loader.ResourceLoader;
import art.arcane.iris.engine.framework.Engine;
import com.google.gson.Gson; import com.google.gson.Gson;
import org.bukkit.Bukkit; import com.volmit.resource.ResourceId;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.block.data.BlockData;
import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import java.util.ArrayList; import java.util.List;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.logging.Logger; import java.util.Optional;
import static org.junit.Assert.assertSame; import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class ResolvedFloatingChildCarvingResolutionTest { public class ResolvedFloatingChildCarvingResolutionTest {
@BeforeClass @Test
public static void setupBukkit() { public void carvingBiome_loadsBiomeKeyWhenEntryIdMissing() {
if (Bukkit.getServer() != null) { ResourceId biome = ResourceId.parse("ns:carving/mushroom");
return; FloatingWorld world = world(List.of(), Map.of("carving/mushroom", biome));
}
Server server = mock(Server.class); assertEquals(Optional.of(biome), child("carving/mushroom", world).carvingBiome());
doReturn(Logger.getLogger("IrisTest")).when(server).getLogger();
doReturn("IrisTestServer").when(server).getName();
doReturn("1.0").when(server).getVersion();
doReturn("1.0").when(server).getBukkitVersion();
doAnswer((InvocationOnMock invocation) -> namedBlockData(invocation.getArgument(0, Material.class).name().toLowerCase(Locale.ROOT))).when(server).createBlockData(any(Material.class));
doAnswer((InvocationOnMock invocation) -> namedBlockData(invocation.getArgument(0, String.class))).when(server).createBlockData(anyString());
try {
Bukkit.setServer(server);
} catch (Throwable ignored) {
}
}
private static BlockData namedBlockData(String key) {
String canonical = key.indexOf(':') >= 0 ? key : "minecraft:" + key;
BlockData data = mock(BlockData.class);
doReturn(canonical).when(data).getAsString();
return data;
} }
@Test @Test
public void resolveCarvingBiome_loadsBiomeKeyWhenEntryIdMissing() { public void carvingBiome_prefersDimensionCarvingEntryId() {
IrisBiome biome = mock(IrisBiome.class); ResourceId entryBiome = ResourceId.parse("ns:carving/standard-deepdark");
Fixture fixture = createFixture(Map.of(), Map.of("carving/mushroom", biome)); ResourceId sameKeyBiome = ResourceId.parse("ns:global-deepdark-band");
IrisBiome resolved = ResolvedFloatingChild.resolveCarvingBiome("carving/mushroom", fixture.engine, fixture.data);
assertSame(biome, resolved);
}
@Test
public void resolveCarvingBiome_prefersDimensionCarvingEntryId() {
IrisBiome entryBiome = mock(IrisBiome.class);
IrisBiome sameKeyBiome = mock(IrisBiome.class);
CarvingEntry entry = new Gson().fromJson("{\"id\": \"global-deepdark-band\", \"biome\": \"carving/standard-deepdark\"}", CarvingEntry.class); CarvingEntry entry = new Gson().fromJson("{\"id\": \"global-deepdark-band\", \"biome\": \"carving/standard-deepdark\"}", CarvingEntry.class);
FloatingWorld world = world(List.of(entry), Map.of("carving/standard-deepdark", entryBiome, "global-deepdark-band", sameKeyBiome));
Map<String, CarvingEntry> entries = new HashMap<>(); assertEquals(Optional.of(entryBiome), child("global-deepdark-band", world).carvingBiome());
entries.put("global-deepdark-band", entry);
Map<String, IrisBiome> biomes = new HashMap<>();
biomes.put("carving/standard-deepdark", entryBiome);
biomes.put("global-deepdark-band", sameKeyBiome);
Fixture fixture = createFixture(entries, biomes);
IrisBiome resolved = ResolvedFloatingChild.resolveCarvingBiome("global-deepdark-band", fixture.engine, fixture.data);
assertSame(entryBiome, resolved);
} }
private Fixture createFixture(Map<String, CarvingEntry> entries, Map<String, IrisBiome> biomes) { private static ResolvedFloatingChild child(String carving, FloatingWorld world) {
@SuppressWarnings("unchecked") return new ResolvedFloatingChild(TestSettings.with(new FloatingChildBiome(), "carving", carving), world);
ResourceLoader<IrisBiome> biomeLoader = mock(ResourceLoader.class);
for (Map.Entry<String, IrisBiome> biome : biomes.entrySet()) {
doReturn(biome.getValue()).when(biomeLoader).load(biome.getKey());
}
IrisData data = mock(IrisData.class);
doReturn(biomeLoader).when(data).getBiomeLoader();
IrisDimension dimension = mock(IrisDimension.class);
ModuleSettings declared = BuiltInPack.settings(new CarvingSettings(new ArrayList<>(entries.values())));
doReturn(declared).when(dimension).getModuleSettings();
Engine engine = mock(Engine.class);
doReturn(data).when(engine).getData();
doReturn(dimension).when(engine).getDimension();
DecoratorTestEngines.withGeneration(engine);
return new Fixture(engine, data);
} }
private static final class Fixture { private static FloatingWorld world(List<CarvingEntry> dimensionCarving, Map<String, ResourceId> biomes) {
private final Engine engine; FloatingHost host = mock(FloatingHost.class);
private final IrisData data; when(host.biome(anyString())).thenAnswer(invocation -> Optional.ofNullable(biomes.get(invocation.getArgument(0, String.class))));
return new FloatingWorld(host, null, null, 0L, 0L, 0, dimensionCarving);
private Fixture(Engine engine, IrisData data) {
this.engine = engine;
this.data = data;
}
} }
} }
@@ -3,7 +3,7 @@ package art.arcane.iris.engine.object.terrain.floating;
import art.arcane.iris.builtin.floating.FloatingChildBiome; import art.arcane.iris.builtin.floating.FloatingChildBiome;
import art.arcane.iris.engine.object.TestSettings; import art.arcane.iris.engine.object.TestSettings;
import art.arcane.iris.builtin.floating.OverrideMode; import art.arcane.iris.builtin.floating.OverrideMode;
import art.arcane.iris.engine.object.placement.IrisObjectPlacement; import art.arcane.iris.builtin.objects.ObjectPlacement;
import art.arcane.volmlib.util.collection.KList; import art.arcane.volmlib.util.collection.KList;
import org.junit.Test; import org.junit.Test;
@@ -13,29 +13,29 @@ import static org.junit.Assert.assertTrue;
public class ResolvedFloatingChildTest { public class ResolvedFloatingChildTest {
@Test @Test
public void resolveTopObjects_inheritOnly_withInheritTrue_returnsSurfaceObjects() { public void resolveTopObjects_inheritOnly_withInheritTrue_returnsSurfaceObjects() {
IrisObjectPlacement placement = new IrisObjectPlacement(); ObjectPlacement placement = new ObjectPlacement();
KList<IrisObjectPlacement> surface = new KList<>(); KList<ObjectPlacement> surface = new KList<>();
surface.add(placement); surface.add(placement);
ResolvedFloatingChild entry = new ResolvedFloatingChild(TestSettings.with(new FloatingChildBiome(), "inheritObjects", true, "topObjectMode", OverrideMode.INHERIT_ONLY)); FloatingChildBiome settings = TestSettings.with(new FloatingChildBiome(), "inheritObjects", true, "topObjectMode", OverrideMode.INHERIT_ONLY);
KList<IrisObjectPlacement> result = entry.resolveTopObjectsFromSurface(surface); KList<ObjectPlacement> result = ResolvedFloatingChild.topObjects(settings, surface);
assertEquals(surface, result); assertEquals(surface, result);
} }
@Test @Test
public void resolveTopObjects_replace_returnsTopOverridesIgnoringSurface() { public void resolveTopObjects_replace_returnsTopOverridesIgnoringSurface() {
IrisObjectPlacement surfacePlacement = new IrisObjectPlacement(); ObjectPlacement surfacePlacement = new ObjectPlacement();
IrisObjectPlacement overridePlacement = new IrisObjectPlacement(); ObjectPlacement overridePlacement = new ObjectPlacement();
KList<IrisObjectPlacement> surface = new KList<>(); KList<ObjectPlacement> surface = new KList<>();
surface.add(surfacePlacement); surface.add(surfacePlacement);
KList<IrisObjectPlacement> overrides = new KList<>(); KList<ObjectPlacement> overrides = new KList<>();
overrides.add(overridePlacement); overrides.add(overridePlacement);
ResolvedFloatingChild entry = new ResolvedFloatingChild(TestSettings.with(new FloatingChildBiome(), "inheritObjects", true, "topObjectMode", OverrideMode.REPLACE, "topObjectOverrides", overrides)); FloatingChildBiome settings = TestSettings.with(new FloatingChildBiome(), "inheritObjects", true, "topObjectMode", OverrideMode.REPLACE, "topObjectOverrides", overrides);
KList<IrisObjectPlacement> result = entry.resolveTopObjectsFromSurface(surface); KList<ObjectPlacement> result = ResolvedFloatingChild.topObjects(settings, surface);
assertEquals(1, result.size()); assertEquals(1, result.size());
assertEquals(overridePlacement, result.get(0)); assertEquals(overridePlacement, result.get(0));
@@ -43,16 +43,16 @@ public class ResolvedFloatingChildTest {
@Test @Test
public void resolveTopObjects_merge_returnsCombinedSurfacePlusOverrides() { public void resolveTopObjects_merge_returnsCombinedSurfacePlusOverrides() {
IrisObjectPlacement surfacePlacement = new IrisObjectPlacement(); ObjectPlacement surfacePlacement = new ObjectPlacement();
IrisObjectPlacement overridePlacement = new IrisObjectPlacement(); ObjectPlacement overridePlacement = new ObjectPlacement();
KList<IrisObjectPlacement> surface = new KList<>(); KList<ObjectPlacement> surface = new KList<>();
surface.add(surfacePlacement); surface.add(surfacePlacement);
KList<IrisObjectPlacement> overrides = new KList<>(); KList<ObjectPlacement> overrides = new KList<>();
overrides.add(overridePlacement); overrides.add(overridePlacement);
ResolvedFloatingChild entry = new ResolvedFloatingChild(TestSettings.with(new FloatingChildBiome(), "inheritObjects", true, "topObjectMode", OverrideMode.MERGE, "topObjectOverrides", overrides)); FloatingChildBiome settings = TestSettings.with(new FloatingChildBiome(), "inheritObjects", true, "topObjectMode", OverrideMode.MERGE, "topObjectOverrides", overrides);
KList<IrisObjectPlacement> result = entry.resolveTopObjectsFromSurface(surface); KList<ObjectPlacement> result = ResolvedFloatingChild.topObjects(settings, surface);
assertEquals(2, result.size()); assertEquals(2, result.size());
assertTrue(result.contains(surfacePlacement)); assertTrue(result.contains(surfacePlacement));
@@ -61,31 +61,31 @@ public class ResolvedFloatingChildTest {
@Test @Test
public void resolveTopObjects_inheritOnly_emptySurface_returnsEmpty() { public void resolveTopObjects_inheritOnly_emptySurface_returnsEmpty() {
ResolvedFloatingChild entry = new ResolvedFloatingChild(TestSettings.with(new FloatingChildBiome(), "topObjectMode", OverrideMode.INHERIT_ONLY)); FloatingChildBiome settings = TestSettings.with(new FloatingChildBiome(), "topObjectMode", OverrideMode.INHERIT_ONLY);
KList<IrisObjectPlacement> result = entry.resolveTopObjectsFromSurface(new KList<>()); KList<ObjectPlacement> result = ResolvedFloatingChild.topObjects(settings, new KList<>());
assertTrue(result.isEmpty()); assertTrue(result.isEmpty());
} }
@Test @Test
public void resolveBottomObjects_inheritOnly_returnsEmptyList() { public void resolveBottomObjects_inheritOnly_returnsEmptyList() {
ResolvedFloatingChild entry = new ResolvedFloatingChild(TestSettings.with(new FloatingChildBiome(), "bottomObjectMode", OverrideMode.INHERIT_ONLY)); FloatingChildBiome settings = TestSettings.with(new FloatingChildBiome(), "bottomObjectMode", OverrideMode.INHERIT_ONLY);
KList<IrisObjectPlacement> result = entry.resolveBottomObjects(null); KList<ObjectPlacement> result = ResolvedFloatingChild.bottomObjects(settings);
assertTrue(result.isEmpty()); assertTrue(result.isEmpty());
} }
@Test @Test
public void resolveBottomObjects_replace_returnsBottomOverrides() { public void resolveBottomObjects_replace_returnsBottomOverrides() {
IrisObjectPlacement overridePlacement = new IrisObjectPlacement(); ObjectPlacement overridePlacement = new ObjectPlacement();
KList<IrisObjectPlacement> overrides = new KList<>(); KList<ObjectPlacement> overrides = new KList<>();
overrides.add(overridePlacement); overrides.add(overridePlacement);
ResolvedFloatingChild entry = new ResolvedFloatingChild(TestSettings.with(new FloatingChildBiome(), "bottomObjectMode", OverrideMode.REPLACE, "bottomObjectOverrides", overrides)); FloatingChildBiome settings = TestSettings.with(new FloatingChildBiome(), "bottomObjectMode", OverrideMode.REPLACE, "bottomObjectOverrides", overrides);
KList<IrisObjectPlacement> result = entry.resolveBottomObjects(null); KList<ObjectPlacement> result = ResolvedFloatingChild.bottomObjects(settings);
assertEquals(1, result.size()); assertEquals(1, result.size());
assertEquals(overridePlacement, result.get(0)); assertEquals(overridePlacement, result.get(0));
@@ -93,9 +93,9 @@ public class ResolvedFloatingChildTest {
@Test @Test
public void resolveTopObjects_inheritTrue_nullTargetProduces_emptySurface() { public void resolveTopObjects_inheritTrue_nullTargetProduces_emptySurface() {
ResolvedFloatingChild entry = new ResolvedFloatingChild(TestSettings.with(new FloatingChildBiome(), "inheritObjects", true, "topObjectMode", OverrideMode.INHERIT_ONLY)); ResolvedFloatingChild entry = new ResolvedFloatingChild(TestSettings.with(new FloatingChildBiome(), "inheritObjects", true, "topObjectMode", OverrideMode.INHERIT_ONLY), null);
KList<IrisObjectPlacement> result = entry.resolveTopObjects(null); KList<ObjectPlacement> result = entry.resolveTopObjects(null);
assertTrue(result.isEmpty()); assertTrue(result.isEmpty());
} }