mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 08:14:45 +00:00
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:
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.engine.mantle.components.StructureModule;
|
||||
import art.arcane.iris.engine.modifier.FloatingModule;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import com.volmit.IrisModule;
|
||||
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",
|
||||
"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. */
|
||||
public static final String HOST_TYPE_PACKAGE = "art.arcane.iris.engine.object";
|
||||
private static final String[] JAR_COPY_FOLDER = {"cache", "module-jars"};
|
||||
@@ -81,7 +81,7 @@ public final class IrisModuleHost {
|
||||
}
|
||||
|
||||
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. */
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
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.engine.framework.Engine;
|
||||
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
|
||||
* 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 REGION = "region";
|
||||
static final String BIOME = "biome";
|
||||
@@ -70,6 +71,11 @@ public final class IrisPackSettings implements PackSettings, ObjectHost.Source {
|
||||
return new IrisObjectHost(engine, IrisApiLogger.hostLog());
|
||||
}
|
||||
|
||||
@Override
|
||||
public FloatingHost floating() {
|
||||
return new IrisFloatingHost(engine, IrisApiLogger.hostLog());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <F extends IrisFeature> List<Entry<F>> declared(Class<F> 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.LiveWorld;
|
||||
import art.arcane.iris.builtin.floating.FloatingHost;
|
||||
import art.arcane.iris.builtin.objects.ObjectHost;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
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
|
||||
* 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 IrisPackResources resources;
|
||||
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 LiveWorld liveWorld;
|
||||
private volatile IrisObjectHost objectHost;
|
||||
private volatile IrisFloatingHost floatingHost;
|
||||
|
||||
IrisPackWorld(Engine engine) {
|
||||
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;
|
||||
}
|
||||
|
||||
@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. */
|
||||
boolean isStale() {
|
||||
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.engine.IrisComplex;
|
||||
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.region.IrisRegion;
|
||||
import art.arcane.iris.util.common.parallel.MultiBurst;
|
||||
@@ -22,7 +21,6 @@ public class ChunkContext {
|
||||
private final ChunkedDataCache<IrisBiome> biome;
|
||||
private final ChunkedDataCache<IrisBiome> cave;
|
||||
private final ChunkedDataCache<IrisRegion> region;
|
||||
private final FloatingIslandBoundarySampler floatingIslandBoundarySampler;
|
||||
|
||||
public ChunkContext(int x, int z, IrisComplex complex) {
|
||||
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.cave = new ChunkedDataCache<>(complex.getCaveBiomeStream(), 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) {
|
||||
PrefillPlan resolvedPlan = prefillPlan == null ? PrefillPlan.NO_CAVE : prefillPlan;
|
||||
@@ -109,10 +106,6 @@ public class ChunkContext {
|
||||
return complex;
|
||||
}
|
||||
|
||||
public FloatingIslandBoundarySampler getFloatingIslandBoundarySampler() {
|
||||
return floatingIslandBoundarySampler;
|
||||
}
|
||||
|
||||
public long getGenerationSessionId() {
|
||||
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.loot.BlockDropping;
|
||||
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.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
@@ -143,7 +142,7 @@ public class BuiltInModulesJarServicesTest {
|
||||
private LoadedPack load() throws IOException {
|
||||
Path pack = BuiltInPack.newPackFolder(folder);
|
||||
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))
|
||||
.copyingJarsTo(folder.newFolder().toPath()));
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ public class BuiltInModulesJarTest {
|
||||
Path pack = BuiltInPack.newPackFolder(folder);
|
||||
List<String> listed = BuiltInModulesJar.writeInto(pack);
|
||||
|
||||
try (LoadedPack loaded = loadWithStandIns(pack)) {
|
||||
try (LoadedPack loaded = loadJar(pack)) {
|
||||
List<DiscoveredModule> fromJar = loaded.packModules();
|
||||
assertEquals(listed, fromJar.stream().map(module -> module.module().getClass().getName()).toList());
|
||||
fromJar.forEach(module -> assertNotSame(MatterModule.class.getClassLoader(), module.module().getClass().getClassLoader()));
|
||||
@@ -71,7 +71,7 @@ public class BuiltInModulesJarTest {
|
||||
Path pack = BuiltInPack.newPackFolder(folder);
|
||||
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();
|
||||
assertEquals(provided, IrisModuleHost.JAR_MODULE_IDS);
|
||||
}
|
||||
@@ -85,7 +85,7 @@ public class BuiltInModulesJarTest {
|
||||
ApiChunk fromJar = scene();
|
||||
|
||||
compiledIn.generate(BuiltInPack.jarModules().toArray(IrisModule[]::new));
|
||||
try (LoadedPack loaded = loadWithStandIns(pack)) {
|
||||
try (LoadedPack loaded = loadJar(pack)) {
|
||||
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])));
|
||||
}
|
||||
|
||||
/** The jar next to stand-ins for the compiled-in stages it orders after, exposing what Iris exposes. */
|
||||
private LoadedPack loadWithStandIns(Path pack) throws IOException {
|
||||
return LoadedPack.load(pack, ModuleHost.of(ApiChunk.standIns())
|
||||
/** The jar on its own, exposing what Iris exposes. */
|
||||
private LoadedPack loadJar(Path pack) throws IOException {
|
||||
return LoadedPack.load(pack, ModuleHost.of(List.of())
|
||||
.exposing(IrisModuleHost.EXPOSED_PACKAGES.toArray(String[]::new))
|
||||
.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.modifier.CarveModule;
|
||||
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.PerfectionModule;
|
||||
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(),
|
||||
new PrepareModule(), new AnchorModule(), new ValidateModule(), new BoreModule(), new BlocksModule(),
|
||||
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()}). */
|
||||
|
||||
+3
-3
@@ -19,7 +19,7 @@
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
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 org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@@ -79,7 +79,7 @@ public class PackModuleJarNextToBuiltInsTest {
|
||||
|
||||
@Test
|
||||
public void aJarModuleWithTheIdOfACompiledInBuiltInFailsAsADuplicate() throws IOException {
|
||||
String builtInId = new FloatingModule().info().id().toString();
|
||||
String builtInId = new StructureModule().info().id().toString();
|
||||
Path packFolder = BuiltInPack.newPackFolder(folder);
|
||||
PackModuleJar.write(packFolder, "carve.jar", "pack.ported.Ported",
|
||||
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()));
|
||||
|
||||
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) {
|
||||
|
||||
+4
-4
@@ -36,7 +36,7 @@ import static org.mockito.Mockito.when;
|
||||
public class FloatingObjectPlacementTransactionTest {
|
||||
@Test
|
||||
public void unsupportedFinalTerrainRejectsBlocksTilesAndMarkersTogether() {
|
||||
IslandObjectPlacer delegate = createPlacer(false);
|
||||
IslandAnchorPlacer delegate = createPlacer(false);
|
||||
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(delegate);
|
||||
PlatformBlockState first = mock(PlatformBlockState.class);
|
||||
PlatformBlockState second = mock(PlatformBlockState.class);
|
||||
@@ -62,7 +62,7 @@ public class FloatingObjectPlacementTransactionTest {
|
||||
|
||||
@Test
|
||||
public void supportedNeighborChunkCommitsBlocksTilesAndMarkers() {
|
||||
IslandObjectPlacer delegate = createPlacer(true);
|
||||
IslandAnchorPlacer delegate = createPlacer(true);
|
||||
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(delegate);
|
||||
PlatformBlockState first = mock(PlatformBlockState.class);
|
||||
PlatformBlockState second = mock(PlatformBlockState.class);
|
||||
@@ -86,8 +86,8 @@ public class FloatingObjectPlacementTransactionTest {
|
||||
verify(delegate).set(16, 101, 8, second);
|
||||
}
|
||||
|
||||
private IslandObjectPlacer createPlacer(boolean supportNeighborChunk) {
|
||||
IslandObjectPlacer placer = mock(IslandObjectPlacer.class);
|
||||
private IslandAnchorPlacer createPlacer(boolean supportNeighborChunk) {
|
||||
IslandAnchorPlacer placer = mock(IslandAnchorPlacer.class);
|
||||
Engine engine = mock(Engine.class);
|
||||
when(engine.getHeight()).thenReturn(384);
|
||||
when(placer.getEngine()).thenReturn(engine);
|
||||
|
||||
+40
-81
@@ -18,103 +18,62 @@
|
||||
|
||||
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.engine.object.placement.IrisObjectPlacement;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.ResourceLoader;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectTranslate;
|
||||
import art.arcane.iris.spi.IrisPlatform;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.spi.PlatformRegistries;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.iris.builtin.floating.FloatingChildSettings;
|
||||
import art.arcane.iris.builtin.floating.FloatingHost;
|
||||
import art.arcane.iris.builtin.objects.ObjectHost;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.ObjectSize;
|
||||
import art.arcane.iris.engine.object.TestSettings;
|
||||
import com.volmit.FeatureAttachment.Target;
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.config.FeatureSettings.Entry;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.host.ModuleLogs;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import com.volmit.resource.ResourceId;
|
||||
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.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class FloatingObjectPlacingBoundaryRadiusTest {
|
||||
@Rule
|
||||
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();
|
||||
}
|
||||
private static final ResourceId BIOME = ResourceId.parse("test:biome/floating");
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void transformedFloatingPlacementExpandsOwnerRadius() throws Exception {
|
||||
File objectFile = temporaryFolder.newFile("floating.iob");
|
||||
try (DataOutputStream output = new DataOutputStream(new FileOutputStream(objectFile))) {
|
||||
output.writeInt(1);
|
||||
output.writeInt(1);
|
||||
output.writeInt(1);
|
||||
}
|
||||
public void transformedFloatingPlacementExpandsOwnerRadius() {
|
||||
ObjectPlacement placement = TestSettings.of(ObjectPlacement.class, "{\"place\":[\"test/floating\"],\"translate\":{\"x\":32}}");
|
||||
FloatingChildBiome floatingChild = TestSettings.with(new FloatingChildBiome(), "floatingObjects", List.of(placement));
|
||||
ObjectHost objects = mock(ObjectHost.class);
|
||||
when(objects.sizeOf("test/floating")).thenReturn(Optional.of(new ObjectSize(1, 1, 1)));
|
||||
|
||||
IrisObjectPlacement placement = new IrisObjectPlacement()
|
||||
.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));
|
||||
assertEquals(33, FloatingObjectPlacing.reach(pack(new FloatingChildSettings(List.of(floatingChild)), objects), ModuleLogs.discarding()));
|
||||
}
|
||||
|
||||
ResourceLoader<IrisObject> objectLoader = mock(ResourceLoader.class);
|
||||
when(objectLoader.findFile("test/floating")).thenReturn(objectFile);
|
||||
IrisData data = mock(IrisData.class);
|
||||
when(data.getObjectLoader()).thenReturn(objectLoader);
|
||||
private static PackSettings pack(FloatingChildSettings declared, ObjectHost objects) {
|
||||
FloatingHost floating = mock(FloatingHost.class);
|
||||
return new FloatingPack() {
|
||||
@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);
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
when(engine.getData()).thenReturn(data);
|
||||
when(engine.getGeneration()).thenReturn(new EngineGeneration(engine));
|
||||
@Override
|
||||
public FloatingHost floating() {
|
||||
return floating;
|
||||
}
|
||||
|
||||
assertEquals(33, new FloatingObjectPlacing(engine, ModuleLogs.discarding()).reach());
|
||||
@Override
|
||||
public ObjectHost objects() {
|
||||
return objects;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private interface FloatingPack extends PackSettings, FloatingHost.Source, ObjectHost.Source {
|
||||
}
|
||||
}
|
||||
+35
-69
@@ -1,120 +1,86 @@
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.builtin.floating.FloatingChildBiome;
|
||||
import art.arcane.iris.engine.object.terrain.floating.ResolvedFloatingChild;
|
||||
import art.arcane.iris.builtin.floating.IslandFootprint;
|
||||
import art.arcane.iris.engine.object.terrain.floating.FloatingIslandSample;
|
||||
import art.arcane.iris.engine.object.placement.FloatingObjectFootprint;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectRotation;
|
||||
import art.arcane.iris.engine.object.terrain.floating.FloatingIslandSamples;
|
||||
import art.arcane.iris.engine.object.terrain.floating.ResolvedFloatingChild;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
public class FloatingObjectPlacingInvertedPlacementTest {
|
||||
private static final UndersideTurn UNTURNED = new UndersideTurn(0);
|
||||
|
||||
private FloatingObjectFootprint footprint(int lowestSolidKeyY, int highestSolidKeyY, int tallestKx, int tallestKz) throws Exception {
|
||||
return footprint(lowestSolidKeyY, highestSolidKeyY, tallestKx, tallestKz, new long[0]);
|
||||
private IslandFootprint footprint(int lowestSolidY, int tallestX, int tallestZ) {
|
||||
return footprint(lowestSolidY, tallestX, tallestZ, new long[0]);
|
||||
}
|
||||
|
||||
private FloatingObjectFootprint footprint(int lowestSolidKeyY, int highestSolidKeyY,
|
||||
int tallestKx, int tallestKz, long[] cells) throws Exception {
|
||||
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 IslandFootprint footprint(int lowestSolidY, int tallestX, int tallestZ, long[] columns) {
|
||||
return new IslandFootprint(tallestX, tallestZ, lowestSolidY, columns);
|
||||
}
|
||||
|
||||
private FloatingIslandSample sample(ResolvedFloatingChild entry) throws Exception {
|
||||
Constructor<FloatingIslandSample> constructor = FloatingIslandSample.class.getDeclaredConstructor(
|
||||
ResolvedFloatingChild.class,
|
||||
int.class,
|
||||
int.class,
|
||||
int.class,
|
||||
int.class,
|
||||
boolean[].class
|
||||
);
|
||||
constructor.setAccessible(true);
|
||||
private FloatingIslandSample sample(ResolvedFloatingChild entry) {
|
||||
boolean[] solidMask = new boolean[10];
|
||||
Arrays.fill(solidMask, true);
|
||||
return constructor.newInstance(entry, 100, 10, 9, 10, solidMask);
|
||||
return FloatingIslandSamples.of(entry, 100, 10, 9, 10, solidMask, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invertedBaseY_anchorsOriginalLowestSolidBelowBottomFace() throws Exception {
|
||||
FloatingObjectFootprint footprint = footprint(5, 30, 2, 3);
|
||||
public void invertedBaseY_anchorsOriginalLowestSolidBelowBottomFace() {
|
||||
IslandFootprint footprint = footprint(5, 2, 3);
|
||||
|
||||
assertEquals(104, FloatingObjectPlacing.invertedBaseY(100, footprint));
|
||||
assertEquals(104, FloatingObjectPlacing.invertedBaseY(100, footprint, UNTURNED));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invertedBaseX_usesTopFootprintAnchor() throws Exception {
|
||||
FloatingObjectFootprint footprint = footprint(5, 30, 2, 3);
|
||||
public void invertedBaseX_usesTopFootprintAnchor() {
|
||||
IslandFootprint footprint = footprint(5, 2, 3);
|
||||
|
||||
assertEquals(106, FloatingObjectPlacing.invertedBaseX(100, 8, footprint));
|
||||
assertEquals(106, FloatingObjectPlacing.invertedBaseX(100, 8, footprint, UNTURNED));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invertedBaseZ_mirrorsTopFootprintAnchor() throws Exception {
|
||||
FloatingObjectFootprint footprint = footprint(5, 30, 2, 3);
|
||||
public void invertedBaseZ_mirrorsTopFootprintAnchor() {
|
||||
IslandFootprint footprint = footprint(5, 2, 3);
|
||||
|
||||
assertEquals(111, FloatingObjectPlacing.invertedBaseZ(100, 8, footprint));
|
||||
assertEquals(111, FloatingObjectPlacing.invertedBaseZ(100, 8, footprint, UNTURNED));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invertedBaseX_usesFixedYRotationAnchor() throws Exception {
|
||||
FloatingObjectFootprint footprint = footprint(5, 30, 2, 3);
|
||||
IrisObjectRotation rotation = IrisObjectRotation.xFlip180WithY(90);
|
||||
public void invertedBaseX_usesFixedYRotationAnchor() {
|
||||
IslandFootprint footprint = footprint(5, 2, 3);
|
||||
UndersideTurn turn = new UndersideTurn(90);
|
||||
|
||||
assertEquals(111, FloatingObjectPlacing.invertedBaseX(100, 8, footprint, rotation));
|
||||
assertEquals(111, FloatingObjectPlacing.invertedBaseX(100, 8, footprint, turn));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invertedBaseZ_usesFixedYRotationAnchor() throws Exception {
|
||||
FloatingObjectFootprint footprint = footprint(5, 30, 2, 3);
|
||||
IrisObjectRotation rotation = IrisObjectRotation.xFlip180WithY(90);
|
||||
public void invertedBaseZ_usesFixedYRotationAnchor() {
|
||||
IslandFootprint footprint = footprint(5, 2, 3);
|
||||
UndersideTurn turn = new UndersideTurn(90);
|
||||
|
||||
assertEquals(110, FloatingObjectPlacing.invertedBaseZ(100, 8, footprint, rotation));
|
||||
assertEquals(110, FloatingObjectPlacing.invertedBaseZ(100, 8, footprint, turn));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invertedBaseY_isStableAcrossFixedYRotation() throws Exception {
|
||||
FloatingObjectFootprint footprint = footprint(5, 30, 2, 3);
|
||||
IrisObjectRotation rotation = IrisObjectRotation.xFlip180WithY(270);
|
||||
public void invertedBaseY_isStableAcrossFixedYRotation() {
|
||||
IslandFootprint footprint = footprint(5, 2, 3);
|
||||
UndersideTurn turn = new UndersideTurn(270);
|
||||
|
||||
assertEquals(104, FloatingObjectPlacing.invertedBaseY(100, footprint, rotation));
|
||||
assertEquals(104, FloatingObjectPlacing.invertedBaseY(100, footprint, turn));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void topFootprintChecksNeighborChunkTerrain() throws Exception {
|
||||
ResolvedFloatingChild entry = new ResolvedFloatingChild(new FloatingChildBiome());
|
||||
public void topFootprintChecksNeighborChunkTerrain() {
|
||||
ResolvedFloatingChild entry = mock(ResolvedFloatingChild.class);
|
||||
FloatingIslandSample sample = sample(entry);
|
||||
long[] cells = {0L, 1L << 32};
|
||||
FloatingObjectFootprint footprint = footprint(0, 0, 0, 0, cells);
|
||||
IslandFootprint footprint = footprint(0, 0, 0, cells);
|
||||
|
||||
assertTrue(FloatingObjectPlacing.isFootprintFlat(
|
||||
footprint, 15, 0, 109,
|
||||
|
||||
+23
-26
@@ -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.mantle.components.IslandObjectPlacer;
|
||||
import art.arcane.iris.engine.object.terrain.floating.FloatingIslandSamples;
|
||||
import org.junit.Test;
|
||||
|
||||
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) {
|
||||
boolean[] mask = new boolean[10];
|
||||
mask[bottomOffset] = true;
|
||||
mask[9] = true;
|
||||
return FloatingIslandSample.constructForTest(baseY, 10, 9, 2, mask);
|
||||
return FloatingIslandSamples.of(baseY, 10, 9, 2, mask);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -20,9 +21,9 @@ public class IslandObjectPlacerAnchorFaceTest {
|
||||
FloatingIslandSample[] samples = new FloatingIslandSample[256];
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -31,9 +32,9 @@ public class IslandObjectPlacerAnchorFaceTest {
|
||||
FloatingIslandSample[] samples = new FloatingIslandSample[256];
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -42,10 +43,9 @@ public class IslandObjectPlacerAnchorFaceTest {
|
||||
FloatingIslandSample[] samples = new FloatingIslandSample[256];
|
||||
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));
|
||||
placer.set(0, 101, 0, null);
|
||||
assertEquals(false, face.writes(0, 101, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -53,9 +53,9 @@ public class IslandObjectPlacerAnchorFaceTest {
|
||||
FloatingIslandSample[] samples = new FloatingIslandSample[256];
|
||||
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
|
||||
@@ -63,10 +63,10 @@ public class IslandObjectPlacerAnchorFaceTest {
|
||||
FloatingIslandSample[] samples = new FloatingIslandSample[256];
|
||||
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, placer.canWriteObjectBlock(0, 101, 0));
|
||||
assertEquals(false, face.writes(0, 100, 0));
|
||||
assertEquals(false, face.writes(0, 101, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -74,31 +74,28 @@ public class IslandObjectPlacerAnchorFaceTest {
|
||||
FloatingIslandSample[] samples = new FloatingIslandSample[256];
|
||||
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));
|
||||
placer.set(1, 104, 0, null);
|
||||
assertEquals(false, face.writes(1, 104, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void topFace_allowsSupportedNeighborChunkWrite() {
|
||||
FloatingIslandSample sample = sampleWithBottomAt(100, 0);
|
||||
IslandObjectPlacer placer = IslandObjectPlacer.top(null,
|
||||
(x, z) -> z == 0 && (x == 15 || x == 16) ? sample : null, null, 109);
|
||||
IslandFace face = IslandFace.top((x, z) -> z == 0 && (x == 15 || x == 16) ? sample : null, null, 109, WORLD_HEIGHT);
|
||||
|
||||
assertEquals(true, placer.canWriteObjectBlock(16, 110, 0));
|
||||
assertEquals(true, face.writes(16, 110, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void topFace_rejectsUnsupportedWorldColumnBeyondOverhang() {
|
||||
FloatingIslandSample sample = sampleWithBottomAt(100, 0);
|
||||
IslandObjectPlacer placer = IslandObjectPlacer.top(null,
|
||||
(x, z) -> x == 15 && z == 0 ? sample : null, null, 109);
|
||||
IslandFace face = IslandFace.top((x, z) -> x == 15 && z == 0 ? sample : null, null, 109, WORLD_HEIGHT);
|
||||
|
||||
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) -> {
|
||||
if (x < 0 || x >= 16 || z < 0 || z >= 16) {
|
||||
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 art.arcane.iris.builtin.IrisStages;
|
||||
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.PostProcessingWallsSettings;
|
||||
import art.arcane.iris.builtin.prepare.SlopeClip;
|
||||
@@ -79,6 +81,7 @@ import com.volmit.world.TerrainSampler;
|
||||
import com.volmit.world.UpperDimension;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@@ -102,6 +105,7 @@ public final class ApiChunk implements GenerationContext {
|
||||
public static final int WIDTH = 16;
|
||||
public static final BlockState AIR = new BlockState("minecraft:air");
|
||||
private static final long SEED = 1337L;
|
||||
private static final String FLOATING_ID = "iris:floating";
|
||||
/** What every noise of the fixture's pack samples, everywhere. */
|
||||
private static final double HALF = 0.5;
|
||||
/** A key that the fixture's pack has no block for. */
|
||||
@@ -270,21 +274,17 @@ public final class ApiChunk implements GenerationContext {
|
||||
return TestSettings.with(new PaletteLayer(), "palette", List.of(BlockSpec.of(block.key())), "slopeCondition", slope);
|
||||
}
|
||||
|
||||
/** Empty stand-ins for the built-in stages the ported modules order after 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. */
|
||||
public static IrisModule 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) {
|
||||
StageGraphBuilder builder = new StageGraphBuilder();
|
||||
for (IrisModule module : standIns()) {
|
||||
builder.install(DiscoveredModule.builtIn(module));
|
||||
if (Arrays.stream(modules).noneMatch(module -> module.info().id().toString().equals(FLOATING_ID))) {
|
||||
builder.install(DiscoveredModule.builtIn(new FloatingStandIn()));
|
||||
}
|
||||
for (IrisModule module : modules) {
|
||||
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. */
|
||||
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 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
|
||||
public long seed() {
|
||||
@@ -761,7 +774,7 @@ public final class ApiChunk implements GenerationContext {
|
||||
private static final class FloatingStandIn implements IrisModule {
|
||||
@Override
|
||||
public ModuleInfo info() {
|
||||
return ModuleInfo.of("iris:floating", "Floating stand-in", "test");
|
||||
return ModuleInfo.of(FLOATING_ID, "Floating stand-in", "test");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,57 +1,74 @@
|
||||
package art.arcane.iris.engine.modifier;
|
||||
|
||||
import art.arcane.iris.core.modules.ModuleSettings;
|
||||
import art.arcane.iris.engine.decorator.DecoratorTestEngines;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.EngineMetrics;
|
||||
import art.arcane.iris.engine.framework.SeedManager;
|
||||
import art.arcane.iris.engine.object.terrain.floating.FloatingIslandBoundarySampler;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.project.context.ChunkContext;
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.floating.FloatingHost;
|
||||
import art.arcane.iris.builtin.objects.ObjectHost;
|
||||
import art.arcane.iris.engine.decorator.BiomeDecorators;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.config.FeatureSettings;
|
||||
import com.volmit.config.PackSettings;
|
||||
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 java.util.function.Function;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
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.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
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. */
|
||||
public class FloatingIslandsTest {
|
||||
private static final int CHUNK_ORIGIN = 32;
|
||||
private static final ResourceId PLAIN_BIOME = ResourceId.parse("test:plain");
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void columnsWithoutFloatingChildBiomesAreLeftAlone() {
|
||||
FloatingIslands islands = new FloatingIslands(engine(), ModuleLogs.discarding());
|
||||
IrisBiome biome = mock(IrisBiome.class);
|
||||
when(biome.getModuleSettings()).thenReturn(ModuleSettings.NONE);
|
||||
FloatingIslandBoundarySampler sampler = mock(FloatingIslandBoundarySampler.class);
|
||||
when(sampler.parent(anyInt(), anyInt())).thenReturn(biome);
|
||||
ChunkContext context = mock(ChunkContext.class);
|
||||
when(context.getFloatingIslandBoundarySampler()).thenReturn(sampler);
|
||||
Hunk<PlatformBlockState> output = mock(Hunk.class);
|
||||
FloatingHost host = mock(FloatingHost.class);
|
||||
when(host.surfaceBiome(anyInt(), anyInt())).thenReturn(PLAIN_BIOME);
|
||||
PackWorld world = world(host);
|
||||
Hunk<BlockState> output = mock(Hunk.class);
|
||||
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.decorateColumns(CHUNK_ORIGIN, CHUNK_ORIGIN, output, false, context, null);
|
||||
islands.fillSolids(context);
|
||||
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()).setRaw(anyInt(), anyInt(), anyInt(), any());
|
||||
}
|
||||
|
||||
private Engine engine() {
|
||||
SeedManager seeds = mock(SeedManager.class);
|
||||
Engine engine = mock(Engine.class);
|
||||
when(engine.getSeedManager()).thenReturn(seeds);
|
||||
when(engine.getMetrics()).thenReturn(new EngineMetrics(16));
|
||||
DecoratorTestEngines.withGeneration(engine);
|
||||
return engine;
|
||||
@SuppressWarnings("unchecked")
|
||||
private static PackWorld world(FloatingHost host) {
|
||||
PackWorld world = mock(PackWorld.class, withSettings().extraInterfaces(FloatingHost.Source.class, ObjectHost.Source.class, IrisSeed.Source.class));
|
||||
when(((FloatingHost.Source) world).floating()).thenReturn(host);
|
||||
when(((ObjectHost.Source) world).objects()).thenReturn(mock(ObjectHost.class));
|
||||
when(world.resources()).thenReturn(mock(PackResources.class));
|
||||
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;
|
||||
}
|
||||
}
|
||||
+9
-5
@@ -24,6 +24,7 @@ import art.arcane.iris.builtin.floating.OverrideMode;
|
||||
import art.arcane.iris.builtin.floating.TopShapeMode;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import com.google.gson.Gson;
|
||||
import com.volmit.noise.NoiseFactory;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import org.junit.Before;
|
||||
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.doReturn;
|
||||
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. */
|
||||
public class FloatingChildBiomeDecodingTest {
|
||||
@@ -99,9 +101,9 @@ public class FloatingChildBiomeDecodingTest {
|
||||
assertEquals(0.55, child.objectShrinkFactor(), 0);
|
||||
assertEquals(OverrideMode.MERGE, child.topObjectMode());
|
||||
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("clutter/bone4", child.bottomObjectOverrides().get(0).getPlace().get(0));
|
||||
assertEquals("clutter/bone4", child.bottomObjectOverrides().get(0).place().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -134,13 +136,15 @@ public class FloatingChildBiomeDecodingTest {
|
||||
@Test
|
||||
public void theEdgeTaperProfileKeepsTheSettingsWidthExponentAndVariation() {
|
||||
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(1.45, profile.exponent(), 0);
|
||||
assertEquals(4, profile.variationAmplitude(), 0);
|
||||
assertEquals(2, resolved.getRarity() + 1);
|
||||
assertEquals(2, resolved.rarity() + 1);
|
||||
}
|
||||
}
|
||||
+133
-157
@@ -18,22 +18,13 @@
|
||||
|
||||
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.engine.object.TestSettings;
|
||||
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.math.RNG;
|
||||
import com.volmit.host.ModuleLogs;
|
||||
import com.volmit.noise.NoiseSampler;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import org.junit.Test;
|
||||
|
||||
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.assertSame;
|
||||
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.when;
|
||||
|
||||
public class FloatingIslandBoundarySamplerTest {
|
||||
@Test
|
||||
public void edgeFade_remainsFullInsideOneParentBiome() {
|
||||
IrisBiome parent = new IrisBiome();
|
||||
ResourceId parent = ResourceId.parse("ns:parent");
|
||||
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> parent);
|
||||
|
||||
assertEquals(1.0D, sampler.edgeFade(parent, 0, 0), 0.0D);
|
||||
@@ -65,10 +54,8 @@ public class FloatingIslandBoundarySamplerTest {
|
||||
|
||||
@Test
|
||||
public void edgeFade_roundsTowardParentBiomeBoundary() {
|
||||
IrisBiome left = new IrisBiome();
|
||||
left.setLoadKey("left");
|
||||
IrisBiome right = new IrisBiome();
|
||||
right.setLoadKey("right");
|
||||
ResourceId left = ResourceId.parse("ns:left");
|
||||
ResourceId right = ResourceId.parse("ns:right");
|
||||
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> x < 0 ? left : right);
|
||||
|
||||
assertEquals(FloatingIslandBoundarySampler.edgeFadeForDistance(1), sampler.edgeFade(right, 0, 0), 0.0D);
|
||||
@@ -78,10 +65,8 @@ public class FloatingIslandBoundarySamplerTest {
|
||||
|
||||
@Test
|
||||
public void edgeFade_acceptsReloadedBiomeInstanceWithSameKey() {
|
||||
IrisBiome expected = new IrisBiome();
|
||||
expected.setLoadKey("magnetics/mycelium");
|
||||
IrisBiome reloaded = new IrisBiome();
|
||||
reloaded.setLoadKey("magnetics/mycelium");
|
||||
ResourceId expected = ResourceId.parse("ns:magnetics/mycelium");
|
||||
ResourceId reloaded = ResourceId.parse("ns:magnetics/mycelium");
|
||||
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> reloaded);
|
||||
|
||||
assertEquals(1.0D, sampler.edgeFade(expected, 0, 0), 0.0D);
|
||||
@@ -89,10 +74,8 @@ public class FloatingIslandBoundarySamplerTest {
|
||||
|
||||
@Test
|
||||
public void edgeFade_detectsOffAxisBoundaryWithinRadius() {
|
||||
IrisBiome parent = new IrisBiome();
|
||||
parent.setLoadKey("parent");
|
||||
IrisBiome neighbor = new IrisBiome();
|
||||
neighbor.setLoadKey("neighbor");
|
||||
ResourceId parent = ResourceId.parse("ns:parent");
|
||||
ResourceId neighbor = ResourceId.parse("ns:neighbor");
|
||||
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> x == 2 && z == 1 ? neighbor : parent);
|
||||
|
||||
assertEquals(FloatingIslandBoundarySampler.edgeFadeForDistance(2), sampler.edgeFade(parent, 0, 0), 0.0D);
|
||||
@@ -100,10 +83,8 @@ public class FloatingIslandBoundarySamplerTest {
|
||||
|
||||
@Test
|
||||
public void edgeFade_isSymmetricAcrossChunkBoundary() {
|
||||
IrisBiome left = new IrisBiome();
|
||||
left.setLoadKey("left");
|
||||
IrisBiome right = new IrisBiome();
|
||||
right.setLoadKey("right");
|
||||
ResourceId left = ResourceId.parse("ns:left");
|
||||
ResourceId right = ResourceId.parse("ns:right");
|
||||
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> x < 16 ? left : right);
|
||||
|
||||
assertEquals(sampler.edgeFade(left, 15, 0), sampler.edgeFade(right, 16, 0), 0.0D);
|
||||
@@ -113,7 +94,7 @@ public class FloatingIslandBoundarySamplerTest {
|
||||
|
||||
@Test
|
||||
public void parent_cachesResolvedBiomeColumns() {
|
||||
IrisBiome parent = new IrisBiome();
|
||||
ResourceId parent = ResourceId.parse("ns:parent");
|
||||
AtomicInteger calls = new AtomicInteger();
|
||||
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> {
|
||||
calls.incrementAndGet();
|
||||
@@ -130,7 +111,7 @@ public class FloatingIslandBoundarySamplerTest {
|
||||
|
||||
@Test
|
||||
public void edgeFade_boundsBiomeStreamReadsToChunkHalo() {
|
||||
IrisBiome parent = new IrisBiome();
|
||||
ResourceId parent = ResourceId.parse("ns:parent");
|
||||
AtomicInteger calls = new AtomicInteger();
|
||||
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> {
|
||||
calls.incrementAndGet();
|
||||
@@ -150,15 +131,15 @@ public class FloatingIslandBoundarySamplerTest {
|
||||
@Test
|
||||
public void footprintFade_usesDistanceForSaturatedHalfPlane() {
|
||||
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> null);
|
||||
CNG footprint = new CNG(new RNG(12)) {
|
||||
NoiseSampler footprint = new NoiseSampler() {
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
public double sample(double x, double z) {
|
||||
return x >= 0 ? 1.0D : 0.0D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return noise(x, z);
|
||||
public double sample(double x, double y, double z) {
|
||||
return sample(x, z);
|
||||
}
|
||||
};
|
||||
int[] depths = new int[FloatingIslandBoundarySampler.EDGE_TAPER_WIDTH];
|
||||
@@ -184,15 +165,15 @@ public class FloatingIslandBoundarySamplerTest {
|
||||
@Test
|
||||
public void footprint_deepSingleCellPinholeRemainsSolid() {
|
||||
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> null);
|
||||
CNG footprint = new CNG(new RNG(13)) {
|
||||
NoiseSampler footprint = new NoiseSampler() {
|
||||
@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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return noise(x, z);
|
||||
public double sample(double x, double y, double z) {
|
||||
return sample(x, z);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -205,27 +186,27 @@ public class FloatingIslandBoundarySamplerTest {
|
||||
@Test
|
||||
public void footprint_repairsOneByTwoAndDiagonalStaticGaps() {
|
||||
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> null);
|
||||
CNG adjacent = new CNG(new RNG(27)) {
|
||||
NoiseSampler adjacent = new NoiseSampler() {
|
||||
@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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return noise(x, z);
|
||||
public double sample(double x, double y, double z) {
|
||||
return sample(x, z);
|
||||
}
|
||||
};
|
||||
CNG diagonal = new CNG(new RNG(28)) {
|
||||
NoiseSampler diagonal = new NoiseSampler() {
|
||||
@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;
|
||||
return gap ? 0.0D : 1.0D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return noise(x, z);
|
||||
public double sample(double x, double y, double z) {
|
||||
return sample(x, z);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -238,15 +219,15 @@ public class FloatingIslandBoundarySamplerTest {
|
||||
@Test
|
||||
public void footprint_broadOpeningRemainsOpen() {
|
||||
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> null);
|
||||
CNG footprint = new CNG(new RNG(14)) {
|
||||
NoiseSampler footprint = new NoiseSampler() {
|
||||
@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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return noise(x, z);
|
||||
public double sample(double x, double y, double z) {
|
||||
return sample(x, z);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -257,16 +238,16 @@ public class FloatingIslandBoundarySamplerTest {
|
||||
public void footprint_buildsOneBoundedChunkHalo() {
|
||||
AtomicInteger calls = new AtomicInteger();
|
||||
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> null);
|
||||
CNG footprint = new CNG(new RNG(15)) {
|
||||
NoiseSampler footprint = new NoiseSampler() {
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
public double sample(double x, double z) {
|
||||
calls.incrementAndGet();
|
||||
return 1.0D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return noise(x, z);
|
||||
public double sample(double x, double y, double z) {
|
||||
return sample(x, z);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -282,15 +263,15 @@ public class FloatingIslandBoundarySamplerTest {
|
||||
|
||||
@Test
|
||||
public void footprintFade_isStableAcrossChunkAlignedFields() {
|
||||
CNG footprint = new CNG(new RNG(16)) {
|
||||
NoiseSampler footprint = new NoiseSampler() {
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
public double sample(double x, double z) {
|
||||
return z >= 0.0D ? 1.0D : 0.0D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return noise(x, z);
|
||||
public double sample(double x, double y, double z) {
|
||||
return sample(x, z);
|
||||
}
|
||||
};
|
||||
FloatingIslandBoundarySampler forwardSampler = new FloatingIslandBoundarySampler((x, z) -> null);
|
||||
@@ -316,15 +297,15 @@ public class FloatingIslandBoundarySamplerTest {
|
||||
@Test
|
||||
public void footprint_rejectsTwoColumnStaticFragment() {
|
||||
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> null);
|
||||
CNG footprint = new CNG(new RNG(17)) {
|
||||
NoiseSampler footprint = new NoiseSampler() {
|
||||
@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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return noise(x, z);
|
||||
public double sample(double x, double y, double z) {
|
||||
return sample(x, z);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -335,26 +316,26 @@ public class FloatingIslandBoundarySamplerTest {
|
||||
@Test
|
||||
public void footprint_rejectsComponentWithoutThreeCellDeepCore() {
|
||||
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> null);
|
||||
CNG threeByThree = new CNG(new RNG(21)) {
|
||||
NoiseSampler threeByThree = new NoiseSampler() {
|
||||
@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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return noise(x, z);
|
||||
public double sample(double x, double y, double z) {
|
||||
return sample(x, z);
|
||||
}
|
||||
};
|
||||
CNG fourWideTendril = new CNG(new RNG(22)) {
|
||||
NoiseSampler fourWideTendril = new NoiseSampler() {
|
||||
@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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return noise(x, z);
|
||||
public double sample(double x, double y, double z) {
|
||||
return sample(x, z);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -366,15 +347,15 @@ public class FloatingIslandBoundarySamplerTest {
|
||||
@Test
|
||||
public void footprint_acceptsComponentWithThreeCellDeepCore() {
|
||||
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> null);
|
||||
CNG footprint = new CNG(new RNG(23)) {
|
||||
NoiseSampler footprint = new NoiseSampler() {
|
||||
@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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return noise(x, z);
|
||||
public double sample(double x, double y, double z) {
|
||||
return sample(x, z);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -387,17 +368,17 @@ public class FloatingIslandBoundarySamplerTest {
|
||||
@Test
|
||||
public void footprint_trimsAttachedThinArmWithoutChunkSeam() {
|
||||
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> null);
|
||||
CNG footprint = new CNG(new RNG(25)) {
|
||||
NoiseSampler footprint = new NoiseSampler() {
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
public double sample(double x, double z) {
|
||||
boolean arm = Math.abs(z) <= 1.0D;
|
||||
boolean core = x >= -10.0D && x <= -6.0D && Math.abs(z) <= 2.0D;
|
||||
return arm || core ? 1.0D : 0.0D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return noise(x, z);
|
||||
public double sample(double x, double y, double z) {
|
||||
return sample(x, z);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -408,20 +389,20 @@ public class FloatingIslandBoundarySamplerTest {
|
||||
|
||||
@Test
|
||||
public void ownershipFade_tapersAcrossPickerBoundary() {
|
||||
ResolvedFloatingChild left = new ResolvedFloatingChild(new FloatingChildBiome());
|
||||
ResolvedFloatingChild right = new ResolvedFloatingChild(new FloatingChildBiome());
|
||||
ResolvedFloatingChild left = new ResolvedFloatingChild(new FloatingChildBiome(), null);
|
||||
ResolvedFloatingChild right = new ResolvedFloatingChild(new FloatingChildBiome(), null);
|
||||
KList<ResolvedFloatingChild> entries = new KList<>();
|
||||
entries.add(left);
|
||||
entries.add(right);
|
||||
CNG picker = new CNG(new RNG(18)) {
|
||||
NoiseSampler picker = new NoiseSampler() {
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
public double sample(double x, double z) {
|
||||
return x < 0.0D ? 0.0D : 1.0D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return noise(x, z);
|
||||
public double sample(double x, double y, double z) {
|
||||
return sample(x, z);
|
||||
}
|
||||
};
|
||||
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> null);
|
||||
@@ -437,20 +418,20 @@ public class FloatingIslandBoundarySamplerTest {
|
||||
|
||||
@Test
|
||||
public void ownershipFade_rejectsThinPickerRegion() {
|
||||
ResolvedFloatingChild left = new ResolvedFloatingChild(new FloatingChildBiome());
|
||||
ResolvedFloatingChild right = new ResolvedFloatingChild(new FloatingChildBiome());
|
||||
ResolvedFloatingChild left = new ResolvedFloatingChild(new FloatingChildBiome(), null);
|
||||
ResolvedFloatingChild right = new ResolvedFloatingChild(new FloatingChildBiome(), null);
|
||||
KList<ResolvedFloatingChild> entries = new KList<>();
|
||||
entries.add(left);
|
||||
entries.add(right);
|
||||
CNG picker = new CNG(new RNG(24)) {
|
||||
NoiseSampler picker = new NoiseSampler() {
|
||||
@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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return noise(x, z);
|
||||
public double sample(double x, double y, double z) {
|
||||
return sample(x, z);
|
||||
}
|
||||
};
|
||||
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> null);
|
||||
@@ -463,24 +444,22 @@ public class FloatingIslandBoundarySamplerTest {
|
||||
|
||||
@Test
|
||||
public void labelFieldsTrimAttachedThinArmWithoutChunkSeam() {
|
||||
IrisBiome leftParent = new IrisBiome();
|
||||
leftParent.setLoadKey("left");
|
||||
IrisBiome rightParent = new IrisBiome();
|
||||
rightParent.setLoadKey("right");
|
||||
ResolvedFloatingChild leftChild = new ResolvedFloatingChild(new FloatingChildBiome());
|
||||
ResolvedFloatingChild rightChild = new ResolvedFloatingChild(new FloatingChildBiome());
|
||||
ResourceId leftParent = ResourceId.parse("ns:left");
|
||||
ResourceId rightParent = ResourceId.parse("ns:right");
|
||||
ResolvedFloatingChild leftChild = new ResolvedFloatingChild(new FloatingChildBiome(), null);
|
||||
ResolvedFloatingChild rightChild = new ResolvedFloatingChild(new FloatingChildBiome(), null);
|
||||
KList<ResolvedFloatingChild> entries = new KList<>();
|
||||
entries.add(leftChild);
|
||||
entries.add(rightChild);
|
||||
CNG picker = new CNG(new RNG(29)) {
|
||||
NoiseSampler picker = new NoiseSampler() {
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
public double sample(double x, double z) {
|
||||
return isAttachedArm(x, z) ? 1.0D : 0.0D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return noise(x, z);
|
||||
public double sample(double x, double y, double z) {
|
||||
return sample(x, z);
|
||||
}
|
||||
};
|
||||
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler(
|
||||
@@ -497,21 +476,20 @@ public class FloatingIslandBoundarySamplerTest {
|
||||
|
||||
@Test
|
||||
public void sampler_fieldsPublishSafelyAcrossConcurrentReaders() throws Exception {
|
||||
IrisBiome parent = new IrisBiome();
|
||||
parent.setLoadKey("parent");
|
||||
ResolvedFloatingChild left = new ResolvedFloatingChild(new FloatingChildBiome());
|
||||
ResolvedFloatingChild right = new ResolvedFloatingChild(new FloatingChildBiome());
|
||||
ResourceId parent = ResourceId.parse("ns:parent");
|
||||
ResolvedFloatingChild left = new ResolvedFloatingChild(new FloatingChildBiome(), null);
|
||||
ResolvedFloatingChild right = new ResolvedFloatingChild(new FloatingChildBiome(), null);
|
||||
KList<ResolvedFloatingChild> entries = new KList<>();
|
||||
entries.add(left);
|
||||
entries.add(right);
|
||||
CNG constant = new CNG(new RNG(26)) {
|
||||
NoiseSampler constant = new NoiseSampler() {
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
public double sample(double x, double z) {
|
||||
return 1.0D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
public double sample(double x, double y, double z) {
|
||||
return 1.0D;
|
||||
}
|
||||
};
|
||||
@@ -538,55 +516,50 @@ public class FloatingIslandBoundarySamplerTest {
|
||||
|
||||
@Test
|
||||
public void sample_appliesSpatialProfileToFinalWorldCoordinates() {
|
||||
CNG footprint = new CNG(new RNG(19)) {
|
||||
NoiseSampler footprint = new NoiseSampler() {
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
public double sample(double x, double z) {
|
||||
return x >= 0.0D ? 1.0D : 0.0D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return noise(x, z);
|
||||
public double sample(double x, double y, double z) {
|
||||
return sample(x, z);
|
||||
}
|
||||
};
|
||||
CNG constant = new CNG(new RNG(20)) {
|
||||
NoiseSampler constant = new NoiseSampler() {
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
public double sample(double x, double z) {
|
||||
return 1.0D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
public double sample(double x, double y, double z) {
|
||||
return 1.0D;
|
||||
}
|
||||
};
|
||||
ResolvedFloatingChild entry = mock(ResolvedFloatingChild.class);
|
||||
IrisBiome parent = mock(IrisBiome.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
Engine engine = mock(Engine.class);
|
||||
IrisWorld world = IrisWorld.builder().minHeight(0).maxHeight(320).build();
|
||||
ResourceId parent = ResourceId.parse("ns:parent");
|
||||
KList<ResolvedFloatingChild> entries = new KList<>();
|
||||
entries.add(entry);
|
||||
ModuleSettings separate = BuiltInPack.settings(new MergeFloatingChildrenSettings(false));
|
||||
when(parent.getModuleSettings()).thenReturn(separate);
|
||||
when(entry.getFootprintCng(anyLong(), same(data))).thenReturn(footprint);
|
||||
when(entry.getAltitudeCng(anyLong(), same(data))).thenReturn(constant);
|
||||
when(entry.getRealBiome(parent, data)).thenReturn(parent);
|
||||
when(entry.getTopShapeCng(anyLong(), same(data))).thenReturn(constant);
|
||||
when(entry.getBottomCng(anyLong(), same(data))).thenReturn(constant);
|
||||
when(entry.getWallWarpCng(anyLong(), same(data))).thenReturn(null);
|
||||
when(entry.getCarvingProfileSampler(engine, data)).thenReturn(null);
|
||||
FloatingWorld world = floatingWorld(parent, false, 31L);
|
||||
when(entry.footprintNoise()).thenReturn(footprint);
|
||||
when(entry.altitudeNoise()).thenReturn(constant);
|
||||
when(entry.realBiome(parent)).thenReturn(parent);
|
||||
when(entry.topShapeNoise()).thenReturn(constant);
|
||||
when(entry.bottomNoise()).thenReturn(constant);
|
||||
when(entry.wallWarpNoise()).thenReturn(null);
|
||||
when(entry.carvingProfileSampler()).thenReturn(null);
|
||||
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(engine.getWorld()).thenReturn(world);
|
||||
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> parent);
|
||||
int[] expectedBottom = {159, 158, 156, 153, 150, 147, 144, 142, 141, 140};
|
||||
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++) {
|
||||
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);
|
||||
assertEquals(expectedBottom[i], sample.bottomY());
|
||||
assertEquals(expectedTop[i], sample.topY());
|
||||
@@ -604,57 +577,52 @@ public class FloatingIslandBoundarySamplerTest {
|
||||
|
||||
@Test
|
||||
public void sample_mergesNoiseTopEntriesAcrossSpatialRim() {
|
||||
CNG footprint = new CNG(new RNG(33)) {
|
||||
NoiseSampler footprint = new NoiseSampler() {
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
public double sample(double x, double z) {
|
||||
return x >= 0.0D ? 1.0D : 0.0D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return noise(x, z);
|
||||
public double sample(double x, double y, double z) {
|
||||
return sample(x, z);
|
||||
}
|
||||
};
|
||||
CNG constant = new CNG(new RNG(34)) {
|
||||
NoiseSampler constant = new NoiseSampler() {
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
public double sample(double x, double z) {
|
||||
return 1.0D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
public double sample(double x, double y, double z) {
|
||||
return 1.0D;
|
||||
}
|
||||
};
|
||||
ResolvedFloatingChild lower = mock(ResolvedFloatingChild.class);
|
||||
ResolvedFloatingChild upper = mock(ResolvedFloatingChild.class);
|
||||
IrisBiome parent = mock(IrisBiome.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
Engine engine = mock(Engine.class);
|
||||
IrisWorld world = IrisWorld.builder().minHeight(0).maxHeight(320).build();
|
||||
ResourceId parent = ResourceId.parse("ns:parent");
|
||||
KList<ResolvedFloatingChild> entries = new KList<>();
|
||||
entries.add(lower);
|
||||
entries.add(upper);
|
||||
ModuleSettings merged = BuiltInPack.settings(new MergeFloatingChildrenSettings(true));
|
||||
when(parent.getModuleSettings()).thenReturn(merged);
|
||||
FloatingWorld world = floatingWorld(parent, true, 35L);
|
||||
for (ResolvedFloatingChild entry : entries) {
|
||||
when(entry.getFootprintCng(anyLong(), same(data))).thenReturn(footprint);
|
||||
when(entry.getAltitudeCng(anyLong(), same(data))).thenReturn(constant);
|
||||
when(entry.getRealBiome(parent, data)).thenReturn(parent);
|
||||
when(entry.getTopShapeCng(anyLong(), same(data))).thenReturn(constant);
|
||||
when(entry.getBottomCng(anyLong(), same(data))).thenReturn(constant);
|
||||
when(entry.getWallWarpCng(anyLong(), same(data))).thenReturn(null);
|
||||
when(entry.getCarvingProfileSampler(engine, data)).thenReturn(null);
|
||||
when(entry.footprintNoise()).thenReturn(footprint);
|
||||
when(entry.altitudeNoise()).thenReturn(constant);
|
||||
when(entry.realBiome(parent)).thenReturn(parent);
|
||||
when(entry.topShapeNoise()).thenReturn(constant);
|
||||
when(entry.bottomNoise()).thenReturn(constant);
|
||||
when(entry.wallWarpNoise()).thenReturn(null);
|
||||
when(entry.carvingProfileSampler()).thenReturn(null);
|
||||
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,
|
||||
"minHeightAboveSurface", entry == lower ? 160 : 180, "maxHeightAboveSurface", entry == lower ? 160 : 180));
|
||||
}
|
||||
when(engine.getWorld()).thenReturn(world);
|
||||
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> parent);
|
||||
|
||||
assertNull(FloatingIslandSample.sample(parent, entries, 0, 0, 320, 35L, data, engine, sampler, ModuleLogs.discarding()));
|
||||
FloatingIslandSample sample = FloatingIslandSample.sample(parent, entries, 1, 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, world, sampler, ModuleLogs.discarding());
|
||||
|
||||
assertNotNull(sample);
|
||||
assertTrue(sample.hasMergedEntries());
|
||||
@@ -665,6 +633,14 @@ public class FloatingIslandBoundarySamplerTest {
|
||||
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) {
|
||||
return Math.abs(z) <= 1.0D || x >= -10.0D && x <= -6.0D && Math.abs(z) <= 2.0D;
|
||||
}
|
||||
|
||||
+47
-60
@@ -2,10 +2,7 @@ package art.arcane.iris.engine.object.terrain.floating;
|
||||
|
||||
import art.arcane.iris.engine.object.TestSettings;
|
||||
import art.arcane.iris.builtin.floating.FloatingChildBiome;
|
||||
import art.arcane.iris.engine.object.terrain.floating.FloatingIslandSample;
|
||||
import art.arcane.iris.util.project.noise.CNG;
|
||||
import art.arcane.iris.util.project.noise.NoiseGenerator;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.noise.NoiseSampler;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -63,8 +60,8 @@ public class FloatingIslandSampleBottomYTest {
|
||||
|
||||
@Test
|
||||
public void mergedEntryMask_preservesTopAndBottomOwners() {
|
||||
ResolvedFloatingChild bottom = new ResolvedFloatingChild(new FloatingChildBiome());
|
||||
ResolvedFloatingChild top = new ResolvedFloatingChild(new FloatingChildBiome());
|
||||
ResolvedFloatingChild bottom = new ResolvedFloatingChild(new FloatingChildBiome(), null);
|
||||
ResolvedFloatingChild top = new ResolvedFloatingChild(new FloatingChildBiome(), null);
|
||||
boolean[] mask = {true, true, false, true};
|
||||
ResolvedFloatingChild[] entryMask = {bottom, bottom, null, top};
|
||||
FloatingIslandSample sample = FloatingIslandSample.constructForTest(top, 80, mask.length, 3, 3, mask, entryMask);
|
||||
@@ -132,7 +129,7 @@ public class FloatingIslandSampleBottomYTest {
|
||||
public void carveSolidInterior_preservesOuterShell() {
|
||||
boolean[] mask = {false, true, true, true, true, false};
|
||||
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);
|
||||
|
||||
@@ -150,7 +147,7 @@ public class FloatingIslandSampleBottomYTest {
|
||||
boolean[] mask = {true, true, true, true, true, true};
|
||||
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);
|
||||
for (boolean solid : mask) {
|
||||
@@ -160,17 +157,17 @@ public class FloatingIslandSampleBottomYTest {
|
||||
|
||||
@Test
|
||||
public void lateralCarving_requiresRoundedInteriorAndFullNeighborRing() {
|
||||
CNG fullRing = constantCng(1.0);
|
||||
NoiseSampler fullRing = constantNoise(1.0);
|
||||
FloatingIslandSample.NeighborSupport fullSupport = FloatingIslandSample.footprintNeighborSupport(fullRing, 0, 0, 0.0);
|
||||
CNG missingDiagonal = new CNG(new RNG(11)) {
|
||||
NoiseSampler missingDiagonal = new NoiseSampler() {
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
public double sample(double x, double z) {
|
||||
return x == 1 && z == 1 ? 0.0 : 1.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return noise(x, z);
|
||||
public double sample(double x, double y, double z) {
|
||||
return sample(x, z);
|
||||
}
|
||||
};
|
||||
FloatingIslandSample.NeighborSupport partialSupport = FloatingIslandSample.footprintNeighborSupport(missingDiagonal, 0, 0, 0.0);
|
||||
@@ -182,15 +179,15 @@ public class FloatingIslandSampleBottomYTest {
|
||||
|
||||
@Test
|
||||
public void footprintPinholeFill_acceptsSingleColumnHoleWithSolidRing() {
|
||||
CNG footprint = new CNG(new RNG(4)) {
|
||||
NoiseSampler footprint = new NoiseSampler() {
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
public double sample(double x, double z) {
|
||||
return x == 0 && z == 0 ? 0.46 : 1.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return noise(x, z);
|
||||
public double sample(double x, double y, double z) {
|
||||
return sample(x, z);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -200,15 +197,15 @@ public class FloatingIslandSampleBottomYTest {
|
||||
|
||||
@Test
|
||||
public void footprintPinholeFill_keepsBroadHoleOpen() {
|
||||
CNG footprint = new CNG(new RNG(5)) {
|
||||
NoiseSampler footprint = new NoiseSampler() {
|
||||
@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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return noise(x, z);
|
||||
public double sample(double x, double y, double z) {
|
||||
return sample(x, z);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -218,15 +215,15 @@ public class FloatingIslandSampleBottomYTest {
|
||||
|
||||
@Test
|
||||
public void layerSupport_rejectsIsolatedSolidProtrusion() {
|
||||
CNG footprint = new CNG(new RNG(6)) {
|
||||
NoiseSampler footprint = new NoiseSampler() {
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
public double sample(double x, double z) {
|
||||
return x == 0 && z == 0 ? 1.0 : 0.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return noise(x, z);
|
||||
public double sample(double x, double y, double z) {
|
||||
return sample(x, z);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -236,15 +233,15 @@ public class FloatingIslandSampleBottomYTest {
|
||||
|
||||
@Test
|
||||
public void layerSupport_fillsSingleColumnAirGap() {
|
||||
CNG footprint = new CNG(new RNG(7)) {
|
||||
NoiseSampler footprint = new NoiseSampler() {
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
public double sample(double x, double z) {
|
||||
return x == 0 && z == 0 ? 0.0 : 1.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return noise(x, z);
|
||||
public double sample(double x, double y, double z) {
|
||||
return sample(x, z);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -255,22 +252,17 @@ public class FloatingIslandSampleBottomYTest {
|
||||
@Test
|
||||
public void carveSolidInterior_rejectsIsolatedCarveAir() {
|
||||
boolean[] mask = {true, true, true, true, true};
|
||||
CNG carve = new CNG(new RNG(8), new NoiseGenerator() {
|
||||
NoiseSampler carve = new NoiseSampler() {
|
||||
@Override
|
||||
public double noise(double x) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
public double sample(double x, double z) {
|
||||
return x == 0 && z == 0 ? 1.0 : 0.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return noise(x, z);
|
||||
public double sample(double x, double y, double z) {
|
||||
return sample(x, z);
|
||||
}
|
||||
}, 1.0, 1);
|
||||
};
|
||||
|
||||
boolean[] lateralCarveMask = {true, true, true, true, true};
|
||||
int count = FloatingIslandSample.carveSolidInterior(mask, lateralCarveMask, 100, 0, 0, carve, 0.5);
|
||||
@@ -289,7 +281,7 @@ public class FloatingIslandSampleBottomYTest {
|
||||
mask[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);
|
||||
|
||||
@@ -328,23 +320,23 @@ public class FloatingIslandSampleBottomYTest {
|
||||
|
||||
@Test
|
||||
public void directCarveEnabled_respectsCarvingReferenceOverride() {
|
||||
ResolvedFloatingChild entry = new ResolvedFloatingChild(TestSettings.with(new FloatingChildBiome(), "carving", "carving/mushroom"));
|
||||
CNG carve = new CNG(new RNG(9));
|
||||
ResolvedFloatingChild entry = new ResolvedFloatingChild(TestSettings.with(new FloatingChildBiome(), "carving", "carving/mushroom"), null);
|
||||
NoiseSampler carve = constantNoise(0.0);
|
||||
|
||||
assertFalse(FloatingIslandSample.directCarveEnabled(entry, null, carve, 0.5));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasFootprintNeighborSupport_rejectsSingleIsolatedColumn() {
|
||||
CNG footprint = new CNG(new RNG(2)) {
|
||||
NoiseSampler footprint = new NoiseSampler() {
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
public double sample(double x, double z) {
|
||||
return x == 0 && z == 0 ? 1.0 : 0.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return noise(x, z);
|
||||
public double sample(double x, double y, double z) {
|
||||
return sample(x, z);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -353,37 +345,32 @@ public class FloatingIslandSampleBottomYTest {
|
||||
|
||||
@Test
|
||||
public void hasFootprintNeighborSupport_acceptsCardinalNeighbor() {
|
||||
CNG footprint = new CNG(new RNG(3)) {
|
||||
NoiseSampler footprint = new NoiseSampler() {
|
||||
@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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return noise(x, z);
|
||||
public double sample(double x, double y, double z) {
|
||||
return sample(x, z);
|
||||
}
|
||||
};
|
||||
|
||||
assertEquals(true, FloatingIslandSample.hasFootprintNeighborSupport(footprint, 0, 0, 0.0));
|
||||
}
|
||||
|
||||
private CNG constantCng(double value) {
|
||||
return new CNG(new RNG(12), new NoiseGenerator() {
|
||||
private NoiseSampler constantNoise(double value) {
|
||||
return new NoiseSampler() {
|
||||
@Override
|
||||
public double noise(double x) {
|
||||
public double sample(double x, double z) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
public double sample(double x, double y, double z) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return value;
|
||||
}
|
||||
}, 1.0, 1);
|
||||
};
|
||||
}
|
||||
}
|
||||
+16
@@ -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);
|
||||
}
|
||||
}
|
||||
+24
-99
@@ -1,123 +1,48 @@
|
||||
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.CarvingSettings;
|
||||
import art.arcane.iris.core.modules.BuiltInPack;
|
||||
import art.arcane.iris.core.modules.ModuleSettings;
|
||||
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 art.arcane.iris.builtin.floating.FloatingChildBiome;
|
||||
import art.arcane.iris.builtin.floating.FloatingHost;
|
||||
import art.arcane.iris.engine.object.TestSettings;
|
||||
import com.google.gson.Gson;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.junit.BeforeClass;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import org.junit.Test;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
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.when;
|
||||
|
||||
public class ResolvedFloatingChildCarvingResolutionTest {
|
||||
@BeforeClass
|
||||
public static void setupBukkit() {
|
||||
if (Bukkit.getServer() != null) {
|
||||
return;
|
||||
}
|
||||
@Test
|
||||
public void carvingBiome_loadsBiomeKeyWhenEntryIdMissing() {
|
||||
ResourceId biome = ResourceId.parse("ns:carving/mushroom");
|
||||
FloatingWorld world = world(List.of(), Map.of("carving/mushroom", biome));
|
||||
|
||||
Server server = mock(Server.class);
|
||||
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;
|
||||
assertEquals(Optional.of(biome), child("carving/mushroom", world).carvingBiome());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveCarvingBiome_loadsBiomeKeyWhenEntryIdMissing() {
|
||||
IrisBiome biome = mock(IrisBiome.class);
|
||||
Fixture fixture = createFixture(Map.of(), Map.of("carving/mushroom", biome));
|
||||
|
||||
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);
|
||||
public void carvingBiome_prefersDimensionCarvingEntryId() {
|
||||
ResourceId entryBiome = ResourceId.parse("ns:carving/standard-deepdark");
|
||||
ResourceId sameKeyBiome = ResourceId.parse("ns:global-deepdark-band");
|
||||
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<>();
|
||||
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);
|
||||
assertEquals(Optional.of(entryBiome), child("global-deepdark-band", world).carvingBiome());
|
||||
}
|
||||
|
||||
private Fixture createFixture(Map<String, CarvingEntry> entries, Map<String, IrisBiome> biomes) {
|
||||
@SuppressWarnings("unchecked")
|
||||
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 ResolvedFloatingChild child(String carving, FloatingWorld world) {
|
||||
return new ResolvedFloatingChild(TestSettings.with(new FloatingChildBiome(), "carving", carving), world);
|
||||
}
|
||||
|
||||
private static final class Fixture {
|
||||
private final Engine engine;
|
||||
private final IrisData data;
|
||||
|
||||
private Fixture(Engine engine, IrisData data) {
|
||||
this.engine = engine;
|
||||
this.data = data;
|
||||
}
|
||||
private static FloatingWorld world(List<CarvingEntry> dimensionCarving, Map<String, ResourceId> biomes) {
|
||||
FloatingHost host = mock(FloatingHost.class);
|
||||
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);
|
||||
}
|
||||
}
|
||||
+27
-27
@@ -3,7 +3,7 @@ package art.arcane.iris.engine.object.terrain.floating;
|
||||
import art.arcane.iris.builtin.floating.FloatingChildBiome;
|
||||
import art.arcane.iris.engine.object.TestSettings;
|
||||
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 org.junit.Test;
|
||||
|
||||
@@ -13,29 +13,29 @@ import static org.junit.Assert.assertTrue;
|
||||
public class ResolvedFloatingChildTest {
|
||||
@Test
|
||||
public void resolveTopObjects_inheritOnly_withInheritTrue_returnsSurfaceObjects() {
|
||||
IrisObjectPlacement placement = new IrisObjectPlacement();
|
||||
KList<IrisObjectPlacement> surface = new KList<>();
|
||||
ObjectPlacement placement = new ObjectPlacement();
|
||||
KList<ObjectPlacement> surface = new KList<>();
|
||||
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);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveTopObjects_replace_returnsTopOverridesIgnoringSurface() {
|
||||
IrisObjectPlacement surfacePlacement = new IrisObjectPlacement();
|
||||
IrisObjectPlacement overridePlacement = new IrisObjectPlacement();
|
||||
KList<IrisObjectPlacement> surface = new KList<>();
|
||||
ObjectPlacement surfacePlacement = new ObjectPlacement();
|
||||
ObjectPlacement overridePlacement = new ObjectPlacement();
|
||||
KList<ObjectPlacement> surface = new KList<>();
|
||||
surface.add(surfacePlacement);
|
||||
KList<IrisObjectPlacement> overrides = new KList<>();
|
||||
KList<ObjectPlacement> overrides = new KList<>();
|
||||
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(overridePlacement, result.get(0));
|
||||
@@ -43,16 +43,16 @@ public class ResolvedFloatingChildTest {
|
||||
|
||||
@Test
|
||||
public void resolveTopObjects_merge_returnsCombinedSurfacePlusOverrides() {
|
||||
IrisObjectPlacement surfacePlacement = new IrisObjectPlacement();
|
||||
IrisObjectPlacement overridePlacement = new IrisObjectPlacement();
|
||||
KList<IrisObjectPlacement> surface = new KList<>();
|
||||
ObjectPlacement surfacePlacement = new ObjectPlacement();
|
||||
ObjectPlacement overridePlacement = new ObjectPlacement();
|
||||
KList<ObjectPlacement> surface = new KList<>();
|
||||
surface.add(surfacePlacement);
|
||||
KList<IrisObjectPlacement> overrides = new KList<>();
|
||||
KList<ObjectPlacement> overrides = new KList<>();
|
||||
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());
|
||||
assertTrue(result.contains(surfacePlacement));
|
||||
@@ -61,31 +61,31 @@ public class ResolvedFloatingChildTest {
|
||||
|
||||
@Test
|
||||
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());
|
||||
}
|
||||
|
||||
@Test
|
||||
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());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveBottomObjects_replace_returnsBottomOverrides() {
|
||||
IrisObjectPlacement overridePlacement = new IrisObjectPlacement();
|
||||
KList<IrisObjectPlacement> overrides = new KList<>();
|
||||
ObjectPlacement overridePlacement = new ObjectPlacement();
|
||||
KList<ObjectPlacement> overrides = new KList<>();
|
||||
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(overridePlacement, result.get(0));
|
||||
@@ -93,9 +93,9 @@ public class ResolvedFloatingChildTest {
|
||||
|
||||
@Test
|
||||
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());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user