mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 16:25:36 +00:00
Make cave biomes reachable and read them from carved cells
A listed cave's biome joins the reachable walk, cave anchors and cave fluid prefer the biome a cell was painted with
This commit is contained in:
1 parent
1693e3f397
commit
9d0f7a6887
6 files changed
+90
-7
No files matched your search
@@ -118,12 +118,22 @@ final class MantleCarvedTerrain implements CarvedTerrain {
|
||||
return null;
|
||||
}
|
||||
long revision = ProvisionalSampling.revision();
|
||||
IrisBiome biome = engine.getCaveBiomeBelowSurface(x, y, z);
|
||||
IrisBiome carvedBiome = carvedBiome(x, y, z);
|
||||
IrisBiome biome = carvedBiome != null ? carvedBiome : engine.getCaveBiomeBelowSurface(x, y, z);
|
||||
IrisRegion region = complex.getRegionStream().get(x, z);
|
||||
requireFinal(revision, x, z);
|
||||
return IrisHydrologyPolicy.inherited(biome == null ? List.of() : List.of(biome), region, dimension, IrisHydrologyPolicy::getFluid);
|
||||
}
|
||||
|
||||
/** The biome the cave that carved the cell paints it with, where that cave names one. */
|
||||
private IrisBiome carvedBiome(int x, int y, int z) {
|
||||
if (existing(x, z)) {
|
||||
return null;
|
||||
}
|
||||
MatterCavern cavern = TerrainMatterView.get(chunk(x, z), x, y, z, MatterCavern.class);
|
||||
return cavern == null ? null : engine.carvedCaveBiome(cavern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean structureNear(int x, int y, int z) {
|
||||
if (dimension.getTerrainTransform() != null) {
|
||||
|
||||
@@ -845,7 +845,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
? null
|
||||
: writer.getDataIfPresent(candidateX, candidateY, candidateZ, MatterCavern.class);
|
||||
if (candidateY < 0
|
||||
|| caveAnchorBiomeConflicts(candidateX, candidateY, candidateZ, expectedCaveBiomeKey)
|
||||
|| caveAnchorBiomeConflicts(candidateX, candidateY, candidateZ, cavern, expectedCaveBiomeKey)
|
||||
|| !acceptsCaveAnchorAt(candidateX, candidateY, candidateZ, underwater, cavern, hydrology)) {
|
||||
continue;
|
||||
}
|
||||
@@ -1044,12 +1044,13 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
}
|
||||
|
||||
@ChunkCoordinates
|
||||
private boolean caveAnchorBiomeConflicts(int x, int y, int z, String expectedCaveBiomeKey) {
|
||||
private boolean caveAnchorBiomeConflicts(int x, int y, int z, MatterCavern carvedCell, String expectedCaveBiomeKey) {
|
||||
if (expectedCaveBiomeKey == null) {
|
||||
return false;
|
||||
}
|
||||
Engine engine = getEngineMantle().getEngine();
|
||||
IrisBiome at = engine.getCaveBiome(x, y, z);
|
||||
IrisBiome carvedBiome = engine.carvedCaveBiome(carvedCell);
|
||||
IrisBiome at = carvedBiome != null ? carvedBiome : engine.getCaveBiome(x, y, z);
|
||||
IrisBiome surface = engine.getComplex().getTrueBiomeStream().get(x, z);
|
||||
return caveAnchorBiomeConflicts(at, surface, expectedCaveBiomeKey);
|
||||
}
|
||||
|
||||
@@ -365,11 +365,12 @@ public interface Engine extends DataProvider, Fallible, BlockUpdater, Renderer,
|
||||
if (featureBiome != null) {
|
||||
return featureBiome;
|
||||
}
|
||||
IrisBiome mantleBiome = customCaveBiome(getMantle().getMantle().get(x, y, z, MatterCavern.class));
|
||||
IrisBiome mantleBiome = carvedCaveBiome(getMantle().getMantle().get(x, y, z, MatterCavern.class));
|
||||
return mantleBiome != null ? mantleBiome : getCaveBiome(x, y, z);
|
||||
}
|
||||
|
||||
private IrisBiome customCaveBiome(MatterCavern cavern) {
|
||||
/** The cave biome a carved cell was painted with by the cave that carved it; null for a cell that names none. */
|
||||
default IrisBiome carvedCaveBiome(MatterCavern cavern) {
|
||||
if (cavern != null && cavern.getCustomBiome() != null && !cavern.getCustomBiome().isEmpty()) {
|
||||
return getData().getBiomeLoader().load(cavern.getCustomBiome());
|
||||
}
|
||||
@@ -428,7 +429,7 @@ public interface Engine extends DataProvider, Fallible, BlockUpdater, Renderer,
|
||||
cavernChunkResolved = true;
|
||||
}
|
||||
IrisBiome biome = cavernChunk == null || y < 0 || y >= getMantle().getMantle().getWorldHeight()
|
||||
? null : customCaveBiome(cavernChunk.get(x & 15, y, z & 15, MatterCavern.class));
|
||||
? null : carvedCaveBiome(cavernChunk.get(x & 15, y, z & 15, MatterCavern.class));
|
||||
if (biome == null) {
|
||||
biome = resolveConfiguredCaveBiome(x, y, z, null);
|
||||
}
|
||||
|
||||
@@ -695,12 +695,14 @@ public class IrisDimension extends IrisRegistrant {
|
||||
|
||||
Deque<String> pending = new ArrayDeque<>();
|
||||
addReachableBiomeKey(pending, getFocus());
|
||||
addListedCaveBiomeKeys(pending, data, getCaves());
|
||||
KList<IrisRegion> regions = getAllRegions(g);
|
||||
for (IrisRegion region : regions) {
|
||||
if (region == null) {
|
||||
continue;
|
||||
}
|
||||
addReachableBiomeKeys(pending, region.getNaturalBiomeIds());
|
||||
addListedCaveBiomeKeys(pending, data, region.getCaves());
|
||||
}
|
||||
addReachableBiomeKeys(pending, ShoreBiomeLineages.placed(this, regions, g));
|
||||
addReachableBiomeKeys(pending, getImageMapBiomeKeys(g));
|
||||
@@ -746,6 +748,7 @@ public class IrisDimension extends IrisRegistrant {
|
||||
biomes.put(loadKey, biome);
|
||||
addReachableBiomeKeys(pending, biome.getChildren());
|
||||
addReachableBiomeKey(pending, biome.getCarvingBiome());
|
||||
addListedCaveBiomeKeys(pending, data, biome.getCaves());
|
||||
|
||||
KList<IrisFloatingChildBiomes> floatingChildren = biome.getFloatingChildBiomes();
|
||||
if (floatingChildren == null) {
|
||||
@@ -833,6 +836,19 @@ public class IrisDimension extends IrisRegistrant {
|
||||
}
|
||||
}
|
||||
|
||||
/** The biomes that caves listed by key paint their walls with: a cave's biome is as reachable as the cave is listed. */
|
||||
private void addListedCaveBiomeKeys(Deque<String> pending, IrisData data, Iterable<String> caveKeys) {
|
||||
if (caveKeys == null || data.getCaveLoader() == null) {
|
||||
return;
|
||||
}
|
||||
for (String caveKey : caveKeys) {
|
||||
IrisCave cave = caveKey == null || caveKey.isBlank() ? null : data.getCaveLoader().load(caveKey, false);
|
||||
if (cave != null) {
|
||||
addReachableBiomeKey(pending, cave.biome());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addReachableBiomeKey(Deque<String> pending, String biomeKey) {
|
||||
if (biomeKey != null && !biomeKey.isBlank()) {
|
||||
pending.addLast(biomeKey);
|
||||
|
||||
@@ -57,6 +57,7 @@ import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.argThat;
|
||||
import static org.mockito.ArgumentMatchers.anyDouble;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
@@ -115,6 +116,26 @@ public class MantleCarvedTerrainTest {
|
||||
assertThrows(IllegalStateException.class, () -> carved.voxel(0, 20, -17));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aCellPaintedWithACaveBiomeTakesItsFluidFromThatBiomeInsteadOfTheBiomeOfThePlace() {
|
||||
Scene scene = new Scene();
|
||||
Matter[] sections = scene.chunk(0, 0);
|
||||
sections[1].<MatterCavern>slice(MatterCavern.class).set(1, 4, 1, new MatterCavern(true, "magma-grotto", (byte) 0));
|
||||
cavern(sections, 5, 20, 5, (byte) 0);
|
||||
IrisBiome magmaGrotto = new IrisBiome();
|
||||
magmaGrotto.setHydrologyPolicy(new IrisHydrologyPolicy().setFluid("lava"));
|
||||
IrisBiome ofThePlace = new IrisBiome();
|
||||
ofThePlace.setHydrologyPolicy(new IrisHydrologyPolicy().setFluid("water"));
|
||||
when(scene.engine.carvedCaveBiome(argThat(cell -> cell != null && "magma-grotto".equals(cell.getCustomBiome())))).thenReturn(magmaGrotto);
|
||||
when(scene.engine.getCaveBiomeBelowSurface(1, 20, 1)).thenReturn(ofThePlace);
|
||||
when(scene.engine.getCaveBiomeBelowSurface(5, 20, 5)).thenReturn(ofThePlace);
|
||||
|
||||
MantleCarvedTerrain carved = scene.carved();
|
||||
|
||||
assertEquals("lava", carved.caveFluid(1, 20, 1));
|
||||
assertEquals("water", carved.caveFluid(5, 20, 5));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void historicalAndAlreadyGeneratedChunksReadAsForeignNeverAsRock() {
|
||||
Scene scene = new Scene();
|
||||
|
||||
+34
@@ -2,6 +2,8 @@ package art.arcane.iris.generation.terrain;
|
||||
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.biome.IrisFloatingChildBiomes;
|
||||
import art.arcane.iris.generation.cave.IrisCave;
|
||||
import art.arcane.iris.generation.cave.TestSettings;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrologyPolicy;
|
||||
import art.arcane.iris.testsupport.PackCompatFixtures;
|
||||
@@ -11,6 +13,7 @@ import art.arcane.iris.pack.loading.ResourceLoader;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -22,6 +25,37 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class IrisDimensionReachableBiomesTest {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void includesTheBiomesOfCavesTheDimensionTheRegionsAndTheReachableBiomesList() {
|
||||
IrisDimension dimension = new IrisDimension().setRegions(new KList<>("reachable")).setCaves(new KList<>("dimension-cave"));
|
||||
IrisRegion reachable = new IrisRegion().setLandBiomes(new KList<>("land")).setCaves(new KList<>("region-cave"));
|
||||
IrisBiome land = biome("land").setCaves(new KList<>("biome-cave", "plain-cave", "ghost"));
|
||||
IrisBiome unlisted = biome("unlisted-cave-biome");
|
||||
|
||||
IrisData data = mock(IrisData.class);
|
||||
ResourceLoader<IrisRegion> regionLoader = mock(ResourceLoader.class);
|
||||
ResourceLoader<IrisBiome> biomeLoader = mock(ResourceLoader.class);
|
||||
ResourceLoader<IrisCave> caveLoader = mock(ResourceLoader.class);
|
||||
when(data.getRegionLoader()).thenReturn(regionLoader);
|
||||
when(data.getBiomeLoader()).thenReturn(biomeLoader);
|
||||
when(data.getCaveLoader()).thenReturn(caveLoader);
|
||||
when(regionLoader.load("reachable")).thenReturn(reachable);
|
||||
when(biomeLoader.load("land")).thenReturn(land);
|
||||
for (String key : List.of("dimension-biome", "region-biome", "biome-biome")) {
|
||||
when(biomeLoader.load(key)).thenReturn(biome(key));
|
||||
}
|
||||
when(biomeLoader.load("unlisted-cave-biome")).thenReturn(unlisted);
|
||||
when(caveLoader.load("dimension-cave", false)).thenReturn(TestSettings.of(IrisCave.class, "{\"biome\": \"dimension-biome\"}"));
|
||||
when(caveLoader.load("region-cave", false)).thenReturn(TestSettings.of(IrisCave.class, "{\"biome\": \"region-biome\"}"));
|
||||
when(caveLoader.load("biome-cave", false)).thenReturn(TestSettings.of(IrisCave.class, "{\"biome\": \"biome-biome\"}"));
|
||||
when(caveLoader.load("plain-cave", false)).thenReturn(TestSettings.of(IrisCave.class, "{}"));
|
||||
|
||||
Set<String> keys = dimension.getReachableBiomes(() -> data).stream().map(IrisBiome::getLoadKey).collect(Collectors.toSet());
|
||||
|
||||
assertEquals(Set.of("land", "dimension-biome", "region-biome", "biome-biome"), keys);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void includesOutOfPoolFocusBiomeAndRegion() {
|
||||
|
||||
Reference in new issue
Block a user