diff --git a/core/src/test/java/art/arcane/iris/core/modules/ModuleMantleComponentTest.java b/core/src/test/java/art/arcane/iris/core/modules/ModuleMantleComponentTest.java index 3e1db12f3..a16336dc2 100644 --- a/core/src/test/java/art/arcane/iris/core/modules/ModuleMantleComponentTest.java +++ b/core/src/test/java/art/arcane/iris/core/modules/ModuleMantleComponentTest.java @@ -78,7 +78,7 @@ public class ModuleMantleComponentTest { assertEquals(List.of(MantleFlag.of(first), MantleFlag.of(first + 1), MantleFlag.of(first + 2), MantleFlag.of(first + 3), MantleFlag.of(first + 4)), components.stream().map(ModuleMantleComponent::getFlag).toList()); assertEquals(List.of(0, 1, 2, 3, 4), components.stream().map(ModuleMantleComponent::getPriority).toList()); - assertEquals("a pack without objects or structures: caves 1, floating objects at least 16", List.of(1, 0, 16, 0, MARK_REACH), + assertEquals("a pack without objects or structures: caves 1, no floating objects", List.of(1, 0, 0, 0, MARK_REACH), components.stream().map(ModuleMantleComponent::getRadius).toList()); assertEquals("disabledComponents: [iris:carve/caves] turns the cave pass off", List.of(false, true, true, true, true), components.stream().map(ModuleMantleComponent::isEnabled).toList()); diff --git a/core/src/test/java/art/arcane/iris/engine/mantle/components/FloatingObjectPlacingBoundaryRadiusTest.java b/core/src/test/java/art/arcane/iris/engine/mantle/components/FloatingObjectPlacingBoundaryRadiusTest.java index 92b7097b6..a9e52c5d2 100644 --- a/core/src/test/java/art/arcane/iris/engine/mantle/components/FloatingObjectPlacingBoundaryRadiusTest.java +++ b/core/src/test/java/art/arcane/iris/engine/mantle/components/FloatingObjectPlacingBoundaryRadiusTest.java @@ -38,6 +38,7 @@ import java.util.List; import java.util.Optional; import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -58,6 +59,39 @@ public class FloatingObjectPlacingBoundaryRadiusTest { assertEquals(33, FloatingObjectPlacing.reach(pack(new FloatingChildSettings(List.of(floatingChild)), resources), ModuleLogs.discarding())); } + @Test + public void packWithoutFloatingChildrenHasNoReach() { + assertEquals(0, FloatingObjectPlacing.reach(pack(new FloatingChildSettings(List.of()), mock(PackResources.class)), ModuleLogs.discarding())); + } + + @Test + public void floatingChildWithoutObjectsHasNoReach() { + FloatingChildBiome floatingChild = TestSettings.with(new FloatingChildBiome(), "inheritObjects", false); + + assertEquals(0, FloatingObjectPlacing.reach(pack(new FloatingChildSettings(List.of(floatingChild)), mock(PackResources.class)), ModuleLogs.discarding())); + } + + @Test + public void placementOfMissingObjectKeepsTheMinimumReach() { + ObjectPlacement placement = TestSettings.of(ObjectPlacement.class, "{\"place\":[\"test/missing\"]}"); + FloatingChildBiome floatingChild = TestSettings.with(new FloatingChildBiome(), "extraObjects", List.of(placement)); + PackResources resources = mock(PackResources.class); + PackObjects objects = mock(PackObjects.class); + when(resources.objects()).thenReturn(objects); + when(objects.sizeOf(any())).thenReturn(Optional.empty()); + + assertEquals(16, FloatingObjectPlacing.reach(pack(new FloatingChildSettings(List.of(floatingChild)), resources), ModuleLogs.discarding())); + } + + @Test + public void failedReachScanKeepsTheMinimumReach() { + PackSettings failing = mock(PackSettings.class); + when(failing.resources()).thenReturn(mock(PackResources.class)); + when(failing.declared(any())).thenThrow(new IllegalStateException("Unavailable settings")); + + assertEquals(16, FloatingObjectPlacing.reach(failing, ModuleLogs.discarding())); + } + private static PackSettings pack(FloatingChildSettings declared, PackResources resources) { return new PackSettings() { @Override diff --git a/module/src/main/java/art/arcane/iris/engine/mantle/components/FloatingObjectPlacing.java b/module/src/main/java/art/arcane/iris/engine/mantle/components/FloatingObjectPlacing.java index e6662de4f..fd5d63b3c 100644 --- a/module/src/main/java/art/arcane/iris/engine/mantle/components/FloatingObjectPlacing.java +++ b/module/src/main/java/art/arcane/iris/engine/mantle/components/FloatingObjectPlacing.java @@ -58,7 +58,8 @@ import java.util.Set; /** * Places the objects of floating child biomes on and under their islands into the mantle for * {@link art.arcane.iris.engine.modifier.FloatingModule}. One per world. Its reach is the largest placement reach of any - * floating object the dimension's biomes can place, at least 16 blocks. + * floating object the dimension's biomes can place, at least 16 blocks once any of them places objects, and none when + * no floating biome places objects. */ public final class FloatingObjectPlacing { private static final int INVERTED_PICK_ATTEMPTS = 8; @@ -77,13 +78,15 @@ public final class FloatingObjectPlacing { private final ObjectPool objects; private final FloatingPlacer placer; private final long mantleSeed; + private final int reachBlocks; private final ModuleLog log; - FloatingObjectPlacing(FloatingWorld world, ObjectPool objects, FloatingPlacer placer, long mantleSeed, ModuleLog log) { + FloatingObjectPlacing(FloatingWorld world, ObjectPool objects, FloatingPlacer placer, long mantleSeed, int reachBlocks, ModuleLog log) { this.world = world; this.objects = objects; this.placer = placer; this.mantleSeed = mantleSeed; + this.reachBlocks = reachBlocks; this.log = log; } @@ -91,11 +94,15 @@ public final class FloatingObjectPlacing { public static FloatingObjectPlacing of(PackWorld world, ModuleLog log) { return world.state(FloatingObjectPlacing.class, generating -> new FloatingObjectPlacing(FloatingWorld.of(generating), ObjectPool.of(generating), - new FloatingPlacer(generating, log), generating.seed(IrisSeedPurposes.MANTLE), log)); + new FloatingPlacer(generating, log), generating.seed(IrisSeedPurposes.MANTLE), + reach(generating.settings(), log), log)); } /** Places what originates in the chunk of {@code context} into the mantle. */ public void place(MantleStageContext context) { + if (reachBlocks == 0) { + return; + } int minX = context.originX(); int minZ = context.originZ(); BlockBox bounds = context.terrain().bounds(); @@ -390,9 +397,9 @@ public final class FloatingObjectPlacing { /** How far, in blocks along X and Z, the floating objects of the pack {@code settings} describe may write beyond their chunk. */ public static int reach(PackSettings settings, ModuleLog log) { - Reach reach = new Reach(settings.resources(), biomeObjectsOf(settings), log); - int maxObjectExtent = MIN_REACH_BLOCKS; + int maxObjectExtent = 0; try { + Reach reach = new Reach(settings.resources(), biomeObjectsOf(settings), log); for (Entry declared : settings.declared(FloatingChildSettings.class)) { if (declared.level() != Level.BIOME) { continue; @@ -405,6 +412,7 @@ public final class FloatingObjectPlacing { } catch (Throwable e) { GenerationFailures.rethrowEngineFailure(e); log.error("Failed to work out the reach of the floating biomes' objects", e); + maxObjectExtent = Math.max(maxObjectExtent, MIN_REACH_BLOCKS); } return maxObjectExtent; } @@ -454,8 +462,7 @@ public final class FloatingObjectPlacing { } int of(FloatingChildBiome child, ResourceId parent) { - int reach = 0; - reach = Math.max(reach, placementRadius(child.floatingObjects())); + int reach = placementRadius(child.floatingObjects()); reach = Math.max(reach, placementRadius(child.extraObjects())); reach = Math.max(reach, placementRadius(child.topObjectOverrides())); reach = Math.max(reach, placementRadius(child.bottomObjectOverrides())); @@ -466,12 +473,16 @@ public final class FloatingObjectPlacing { } catch (Throwable e) { GenerationFailures.rethrowEngineFailure(e); log.error("Failed to work out the reach of a floating biome's objects", e); + reach = Math.max(reach, MIN_REACH_BLOCKS); } return reach; } private int placementRadius(List placements) { - int radius = 0; + if (placements.isEmpty()) { + return 0; + } + int radius = MIN_REACH_BLOCKS; for (ObjectPlacement placement : placements) { if (placement == null) { continue;