mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-29 09:15:27 +00:00
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:
1 parent
73863e8219
commit
9b86b34187
9 files changed
+199
-26
No files matched your search
@@ -30,7 +30,11 @@ public final class ContentSpawns {
|
||||
|
||||
/** The ground or fluid an entity spawns on. */
|
||||
public enum Surface {
|
||||
LAND, ANIMAL, WATER, OVERWORLD, LAVA
|
||||
LAND, ANIMAL, WATER, OVERWORLD, LAVA;
|
||||
|
||||
public boolean isFluid() {
|
||||
return this == WATER || this == LAVA;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -368,12 +368,38 @@ final class WorldEntitySpawner {
|
||||
}
|
||||
|
||||
private static boolean surfaceAllows(Location l, EntitySpawns.Attempt attempt) {
|
||||
if (!BukkitSurfaces.matches(attempt.surface(), l.clone().subtract(0, 1, 0).getBlock())) {
|
||||
EntitySpawns.Surface surface = attempt.surface();
|
||||
boolean fluid = surface.isFluid();
|
||||
if (!BukkitSurfaces.matches(surface, l.clone().subtract(0, fluid ? 0 : 1, 0).getBlock())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Vector3d boundingBox = BukkitPlatform.entityBoundingBox(BukkitEntitySpawner.bukkitType(attempt.entity()));
|
||||
return boundingBox == null || isAreaClearForSpawn(l, boundingBox);
|
||||
if (boundingBox == null) {
|
||||
return true;
|
||||
}
|
||||
return fluid ? isFluidAreaClearForSpawn(l, boundingBox, surface) : isAreaClearForSpawn(l, boundingBox);
|
||||
}
|
||||
|
||||
private static boolean isFluidAreaClearForSpawn(Location center, Vector3d boundingBox, EntitySpawns.Surface surface) {
|
||||
World world = center.getWorld();
|
||||
int startX = (int) Math.floor(center.getX() + 0.5 - boundingBox.x / 2);
|
||||
int endX = (int) Math.floor(Math.nextDown(center.getX() + 0.5 + boundingBox.x / 2));
|
||||
int startY = center.getBlockY();
|
||||
int endY = (int) Math.floor(Math.nextDown(center.getY() + 0.5 + boundingBox.y));
|
||||
int startZ = (int) Math.floor(center.getZ() + 0.5 - boundingBox.z / 2);
|
||||
int endZ = (int) Math.floor(Math.nextDown(center.getZ() + 0.5 + boundingBox.z / 2));
|
||||
|
||||
for (int x = startX; x <= endX; x++) {
|
||||
for (int y = startY; y <= endY; y++) {
|
||||
for (int z = startZ; z <= endZ; z++) {
|
||||
if (!BukkitSurfaces.matches(surface, world.getBlockAt(x, y, z))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean isAreaClearForSpawn(Location center, Vector3d boundingBox) {
|
||||
|
||||
@@ -25,7 +25,9 @@ import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.EngineGeneration;
|
||||
import art.arcane.iris.engine.framework.SeedManager;
|
||||
import art.arcane.iris.builtin.spawn.EntityDefinition;
|
||||
import art.arcane.iris.builtin.spawn.SpawnGroup;
|
||||
import art.arcane.iris.builtin.spawn.SpawnMarker;
|
||||
import art.arcane.iris.builtin.spawn.SpawnSurface;
|
||||
import art.arcane.iris.builtin.spawn.Spawner;
|
||||
import art.arcane.iris.engine.object.TestSettings;
|
||||
import art.arcane.iris.engine.object.world.IrisWorld;
|
||||
@@ -143,6 +145,53 @@ public class EntitySpawningTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aMarkerSpawnOfAFluidEntityStillChecksItsSurface() {
|
||||
Spawner spawner = TestSettings.of(Spawner.class, "{\"spawns\": [{\"entity\": \"cod\", \"minSpawns\": 1, \"maxSpawns\": 1}]}");
|
||||
fixture.resource(SpawnResources.SPAWNERS, "reef/fish", spawner);
|
||||
fixture.resource(SpawnResources.MARKERS, "reef", TestSettings.of(SpawnMarker.class, "{}"));
|
||||
fixture.resource(SpawnResources.ENTITIES, "cod", TestSettings.of(EntityDefinition.class, "{\"type\": \"minecraft:cod\", \"surface\": \"WATER\"}"));
|
||||
when(engine.getMinHeight()).thenReturn(-64);
|
||||
|
||||
EntitySpawns.Plan plan = new EntitySpawning()
|
||||
.plan(world, new EntitySpawns.Marker(MARKER_BLOCK, world.resources().idOf("reef"), world.resources().idOf("reef/fish"), false))
|
||||
.orElseThrow();
|
||||
|
||||
assertEquals(1, plan.attempts().size());
|
||||
assertTrue(plan.attempts().get(0).checkSurface());
|
||||
assertEquals(EntitySpawns.Surface.WATER, plan.attempts().get(0).surface());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void landEntitiesStandOnTheTopWhileFluidEntitiesSpawnWithinTheFluid() {
|
||||
assertEquals(Integer.valueOf(79), EntitySpawning.surfaceSpawnY(SpawnGroup.NORMAL, SpawnSurface.LAND, 77, 78));
|
||||
assertEquals(Integer.valueOf(78), EntitySpawning.surfaceSpawnY(SpawnGroup.NORMAL, SpawnSurface.WATER, 77, 78));
|
||||
assertEquals(Integer.valueOf(78), EntitySpawning.surfaceSpawnY(SpawnGroup.NORMAL, SpawnSurface.LAVA, 77, 78));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aColumnWithoutFluidHasNoPlaceForAFluidEntity() {
|
||||
assertNull(EntitySpawning.surfaceSpawnY(SpawnGroup.NORMAL, SpawnSurface.WATER, 78, 78));
|
||||
assertNull(EntitySpawning.surfaceSpawnY(SpawnGroup.UNDERWATER, SpawnSurface.WATER, 78, 78));
|
||||
assertNull(EntitySpawning.surfaceSpawnY(SpawnGroup.BEACH, SpawnSurface.LAND, 78, 78));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void underwaterAndBeachEntitiesSpawnBetweenTheFloorAndTheTop() {
|
||||
for (SpawnGroup group : List.of(SpawnGroup.UNDERWATER, SpawnGroup.BEACH)) {
|
||||
for (int i = 0; i < 50; i++) {
|
||||
int y = EntitySpawning.surfaceSpawnY(group, SpawnSurface.WATER, 60, 64);
|
||||
assertTrue(y >= 61 && y <= 64);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void caveEntitiesNeverTakeAColumnHeight() {
|
||||
assertNull(EntitySpawning.surfaceSpawnY(SpawnGroup.CAVE, SpawnSurface.LAND, 60, 64));
|
||||
assertNull(EntitySpawning.surfaceSpawnY(SpawnGroup.CAVE, SpawnSurface.WATER, 60, 64));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aSpawnerThatCannotFireOrHasNoEntitiesPlansNothing() {
|
||||
fixture.resource(SpawnResources.SPAWNERS, "empty", new Spawner());
|
||||
|
||||
Reference in new issue
Block a user