Spawn water and lava entities only inside matching fluid

Fluid entities were placed above the sea and checked against the block below and for air, so they could not spawn where they live. They now take a Y inside the fluid, are always surface-checked (marker spawns too), and both hosts test the block itself and require the fluid across the entity's volume.

Upstream: e33e6a632
This commit is contained in:
piexel committed 2026-11-10 01:10:16 +01:00
1 parent 73863e8219
commit 9b86b34187
9 files changed
+199 -26

No files matched your search

@@ -22,6 +22,7 @@ import art.arcane.iris.core.IrisSettings;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.core.content.ContentEntity;
import art.arcane.iris.core.content.ContentItem;
import art.arcane.iris.core.content.ContentSpawns;
import art.arcane.iris.modded.api.ModdedCustomContentRegistry;
import art.arcane.iris.spi.IrisLogging;
import art.arcane.volmlib.util.math.RNG;
@@ -248,7 +249,8 @@ public final class ModdedEntitySpawner {
}
}
static boolean isAreaClearForSpawn(ServerLevel level, ContentEntity entity, int blockX, int blockY, int blockZ) {
static boolean isAreaClearForSpawn(ServerLevel level, ContentEntity entity, ContentSpawns.Surface surface,
int blockX, int blockY, int blockZ) {
if (entity.isSpecial()) {
return true;
}
@@ -256,10 +258,33 @@ public final class ModdedEntitySpawner {
if (type == null) {
return true;
}
if (surface.isFluid()) {
return isFluidAreaClearForSpawn(blockX, blockY, blockZ, type.getWidth(), type.getHeight(),
position -> ModdedWorldManager.matchesSurface(surface, level.getBlockState(position)));
}
return isAreaClearForSpawn(blockX, blockY, blockZ, type.getWidth(), type.getHeight(),
position -> level.getBlockState(position).is(Blocks.AIR));
}
static boolean isFluidAreaClearForSpawn(int blockX, int blockY, int blockZ,
float width, float height, Predicate<BlockPos> isFluid) {
int startX = (int) Math.floor(blockX + 0.5 - width / 2D);
int endX = (int) Math.floor(Math.nextDown(blockX + 0.5 + width / 2D));
int endY = (int) Math.floor(Math.nextDown(blockY + 0.5 + height));
int startZ = (int) Math.floor(blockZ + 0.5 - width / 2D);
int endZ = (int) Math.floor(Math.nextDown(blockZ + 0.5 + width / 2D));
for (int x = startX; x <= endX; x++) {
for (int y = blockY; y <= endY; y++) {
for (int z = startZ; z <= endZ; z++) {
if (!isFluid.test(new BlockPos(x, y, z))) {
return false;
}
}
}
}
return true;
}
static boolean isAreaClearForSpawn(int blockX, int blockY, int blockZ, float width, float height, Predicate<BlockPos> isAir) {
int radius = (int) (width / 2F);
int endY = blockY + (int) height;
@@ -465,12 +465,14 @@ public final class ModdedWorldManager implements EngineWorldManager {
}
private static boolean surfaceAllows(ContentSpawns.Attempt attempt, ServerLevel level) {
BlockState below = level.getBlockState(new BlockPos(attempt.x(), attempt.worldY() - 1, attempt.z()));
return matchesSurface(attempt.surface(), below)
&& ModdedEntitySpawner.isAreaClearForSpawn(level, attempt.entity(), attempt.x(), attempt.worldY(), attempt.z());
int surfaceY = attempt.surface().isFluid() ? attempt.worldY() : attempt.worldY() - 1;
BlockState surfaceBlock = level.getBlockState(new BlockPos(attempt.x(), surfaceY, attempt.z()));
return matchesSurface(attempt.surface(), surfaceBlock)
&& ModdedEntitySpawner.isAreaClearForSpawn(level, attempt.entity(), attempt.surface(),
attempt.x(), attempt.worldY(), attempt.z());
}
private static boolean matchesSurface(ContentSpawns.Surface surface, BlockState below) {
static boolean matchesSurface(ContentSpawns.Surface surface, BlockState below) {
if (ModdedBlockResolution.isSolid(below)) {
return surface == ContentSpawns.Surface.LAND || surface == ContentSpawns.Surface.OVERWORLD
|| (surface == ContentSpawns.Surface.ANIMAL && isAnimalGround(below));
@@ -51,6 +51,34 @@ public class ModdedEntitySpawnerParityTest {
assertFalse(clear);
}
@Test
public void fractionalFluidVolumeIncludesHorizontalEdgesAndCenteredHeight() {
Set<BlockPos> checked = new HashSet<>();
assertTrue(ModdedEntitySpawner.isFluidAreaClearForSpawn(-1, 78, -1, 1.3F, 0.8F, position -> {
checked.add(position);
return true;
}));
assertEquals(18, checked.size());
assertTrue(checked.contains(new BlockPos(-2, 79, -2)));
assertTrue(checked.contains(new BlockPos(0, 78, 0)));
assertFalse(ModdedEntitySpawner.isFluidAreaClearForSpawn(-1, 78, -1, 1.3F, 0.8F,
position -> !position.equals(new BlockPos(-2, 79, -2))));
}
@Test
public void exactUpperBoundaryDoesNotRequireFluidOutsideTheBody() {
Set<BlockPos> checked = new HashSet<>();
assertTrue(ModdedEntitySpawner.isFluidAreaClearForSpawn(0, 78, 0, 1F, 0.5F, position -> {
checked.add(position);
return true;
}));
assertEquals(Set.of(new BlockPos(0, 78, 0)), checked);
}
@Test
public void spawnSafetyRequiresTheTargetChunkAndAllEightNeighbors() {
Set<Long> loaded = new HashSet<>();