Merge branch 'wave3b/p' into feat/irisapi-host

# Conflicts:
#	core/src/main/java/art/arcane/iris/core/modules/ModuleServices.java
This commit is contained in:
piexel committed 2026-10-10 15:07:41 +02:00
commit 80d50b5cff
8 files changed
+230 -18

No files matched your search

@@ -0,0 +1,87 @@
/*
* 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.core.loader.IrisData;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.object.world.biome.IrisBiome;
import com.volmit.service.CaveBiomes;
import com.volmit.world.PackWorld;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
/**
* What the world's {@link CaveBiomes} provider says, kept for the world. The host asks it for every cave block it gives a
* biome, so the provider is found once per world, each biome's minimum depth asked once and each overriding biome
* loaded once.
*/
public final class CaveBiomeAnswers {
private static final CaveBiomes NO_PROVIDER = new CaveBiomes() {
@Override
public Optional<String> overriddenBiome(PackWorld world, int x, int y, int z) {
return Optional.empty();
}
@Override
public int minDepthBelowSurface(PackWorld world, String biomeKey) {
return 0;
}
};
private final PackWorld world;
private final IrisData data;
private final CaveBiomes provider;
private final Map<String, IrisBiome> overridingBiomes = new ConcurrentHashMap<>();
private final Map<String, Integer> minDepths = new ConcurrentHashMap<>();
CaveBiomeAnswers(Engine engine, CaveBiomes provider, PackWorld world) {
this.world = world;
this.data = engine.getData();
this.provider = provider == null ? NO_PROVIDER : provider;
}
/** The pack biome the module puts at the position whatever the regions say; null where it overrides nothing or names a biome the pack lacks. {@code y} is the height above the dimension's bottom. */
public IrisBiome overriddenBiome(int x, int y, int z) {
Optional<String> key = provider.overriddenBiome(world, x, y, z);
return key.isEmpty() ? null : overridingBiome(key.get());
}
/** How many blocks below the surface the caves of the pack biome {@code biomeKey} begin; 0 where nothing limits them. */
public int minDepthBelowSurface(String biomeKey) {
Integer depth = minDepths.get(biomeKey);
if (depth != null) {
return depth;
}
return minDepths.computeIfAbsent(biomeKey, key -> provider.minDepthBelowSurface(world, key));
}
private IrisBiome overridingBiome(String key) {
IrisBiome biome = overridingBiomes.get(key);
if (biome != null) {
return biome;
}
biome = data.getBiomeLoader().load(key);
if (biome != null) {
overridingBiomes.putIfAbsent(key, biome);
}
return biome;
}
}
@@ -70,6 +70,12 @@ final class IrisTerrainSampler implements TerrainSampler {
return new TerrainSample(surfaceY, fluidY, slope);
}
@Override
public double surfaceY(int worldX, int worldZ) {
requireInside(worldX, bounds.minY(), worldZ);
return engine.getComplex().getHeightStream().get(worldX, worldZ);
}
@Override
public BiomeSample biome(int worldX, int y, int worldZ) {
requireInside(worldX, y, worldZ);
@@ -77,17 +77,11 @@ public final class ModuleServices {
return Optional.of(new Provider<>(service.cast(first.provider()), first.scope(engine.getGeneration().world())));
}
/** The pack biome key the module that decides cave biomes puts at the position, whatever the regions say; empty where it overrides nothing. {@code y} is the height above the dimension's bottom. */
public static Optional<String> overriddenCaveBiome(Engine engine, int x, int y, int z) {
return firstProvider(engine, CaveBiomes.class)
.flatMap(provider -> provider.service().overriddenBiome(provider.world(), x, y, z));
}
/** How many blocks below the surface the caves of the pack biome {@code biomeKey} begin; 0 where nothing limits them. */
public static int caveMinDepthBelowSurface(Engine engine, String biomeKey) {
return firstProvider(engine, CaveBiomes.class)
.map(provider -> provider.service().minDepthBelowSurface(provider.world(), biomeKey))
.orElse(0);
/** What the module that decides cave biomes says for the engine's world, kept for the world, its log the module's own. */
public static CaveBiomeAnswers caveBiomes(Engine engine) {
return engine.getGeneration().state(CaveBiomeAnswers.class, owner -> firstProvider(owner, CaveBiomes.class)
.map(provider -> new CaveBiomeAnswers(owner, provider.service(), provider.world()))
.orElseGet(() -> new CaveBiomeAnswers(owner, null, owner.getGeneration().world())));
}
/** The objects every module would place in the chunk at {@code chunkX}, {@code chunkZ}, guessed without generating it. */
@@ -44,7 +44,8 @@ public final class PackModuleSet implements AutoCloseable {
private final File packFolder;
private final Supplier<Gson> irisGson;
private State state = State.NOT_LOADED;
private LoadedPack pack;
/** Set only while loaded; volatile so {@link #pack()}, asked on the generation hot path, needs no lock then. */
private volatile LoadedPack pack;
private ModuleSettingsDecoder settings;
private PackModulesException failure;
private List<String> loadedJars = List.of();
@@ -56,7 +57,15 @@ public final class PackModuleSet implements AutoCloseable {
}
/** The loaded pack, its built-in modules included. */
public synchronized LoadedPack pack() {
public LoadedPack pack() {
LoadedPack loaded = pack;
if (loaded != null) {
return loaded;
}
return loadedPack();
}
private synchronized LoadedPack loadedPack() {
requireLoaded();
return pack;
}
@@ -111,8 +120,8 @@ public final class PackModuleSet implements AutoCloseable {
loadedJars = jarFingerprint();
try {
LoadedPack loaded = LoadedPack.load(packFolder.toPath(), IrisModuleHost.get());
pack = loaded;
settings = new ModuleSettingsDecoder(loaded.catalog(), packFolder.toPath(), irisGson);
pack = loaded;
state = State.LOADED;
warnWhenBuiltInModulesAreMissing(loaded);
} catch (RuntimeException loadFailure) {
@@ -46,6 +46,9 @@ public final class PlatformBlockStates {
private final Map<PlatformBlockState, BlockState> read = new HashMap<>();
private final Map<BlockState, PlatformBlockState> written = new HashMap<>();
private final Map<BlockState, PlatformBlockState> origins = new IdentityHashMap<>();
/** The state read last: scans over a chunk read long runs of one state, such as stone or air, so most reads hit it. */
private PlatformBlockState lastRead;
private BlockState lastReadAsApi;
/** {@code platformStates} turns a block state key into the platform's state, such as {@code B::getState}. */
public PlatformBlockStates(Function<String, PlatformBlockState> platformStates) {
@@ -60,6 +63,14 @@ public final class PlatformBlockStates {
if (state == null) {
return AIR;
}
if (state != lastRead) {
lastReadAsApi = convertRead(state);
lastRead = state;
}
return lastReadAsApi;
}
private BlockState convertRead(PlatformBlockState state) {
BlockState known = read.get(state);
if (known != null) {
return known;
@@ -28,6 +28,7 @@ import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.core.loader.IrisRegistrant;
import art.arcane.iris.core.nms.container.BlockPos;
import art.arcane.iris.core.nms.container.Pair;
import art.arcane.iris.core.modules.CaveBiomeAnswers;
import art.arcane.iris.core.modules.ModuleServices;
import art.arcane.iris.engine.IrisComplex;
import art.arcane.iris.engine.UpperDimensionContext;
@@ -71,7 +72,6 @@ import org.jetbrains.annotations.Nullable;
import java.awt.Color;
import java.util.Locale;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@@ -275,8 +275,8 @@ public interface Engine extends DataProvider, Fallible, BlockUpdater, Renderer,
@BlockCoordinates
default IrisBiome getCaveBiome(int x, int y, int z) {
IrisBiome surfaceBiome = getSurfaceBiome(x, z);
Optional<String> overriddenKey = ModuleServices.overriddenCaveBiome(this, x, y, z);
IrisBiome overriddenBiome = overriddenKey.map(key -> getData().getBiomeLoader().load(key)).orElse(null);
CaveBiomeAnswers caves = ModuleServices.caveBiomes(this);
IrisBiome overriddenBiome = caves.overriddenBiome(x, y, z);
if (overriddenBiome != null) {
return overriddenBiome;
}
@@ -292,7 +292,7 @@ public interface Engine extends DataProvider, Fallible, BlockUpdater, Renderer,
return surfaceBiome;
}
int minDepth = Math.max(0, ModuleServices.caveMinDepthBelowSurface(this, caveBiome.getLoadKey()));
int minDepth = Math.max(0, caves.minDepthBelowSurface(caveBiome.getLoadKey()));
if (depthBelowSurface < minDepth) {
return surfaceBiome;
}
@@ -0,0 +1,74 @@
/*
* 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.engine.IrisComplex;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
import art.arcane.iris.util.project.stream.ProceduralStream;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class IrisTerrainSamplerTest {
private static final int HEIGHT = 384;
private static final int CHUNK_REACH = 16;
private Engine engine;
private IrisComplex complex;
@Before
public void mockEngine() {
engine = mock(Engine.class);
complex = mock(IrisComplex.class);
when(complex.getHeightStream()).thenReturn(ProceduralStream.ofDouble((x, z) -> 60D + x + z));
when(engine.getComplex()).thenReturn(complex);
when(engine.getHeight()).thenReturn(HEIGHT);
when(engine.getDimension()).thenReturn(new IrisDimension());
}
@Test
public void aColumnsSurfaceAloneIsTheSurfaceOfTheWholeColumn() {
when(complex.getSlopeStream()).thenReturn(ProceduralStream.ofDouble((x, z) -> 0.5D));
IrisTerrainSampler terrain = new IrisTerrainSampler(engine, null, 0, 0, CHUNK_REACH);
assertEquals(terrain.column(3, -7).surfaceY(), terrain.surfaceY(3, -7), 0D);
assertEquals(terrain.column(-16, 31).surfaceY(), terrain.surfaceY(-16, 31), 0D);
}
@Test
public void aColumnsSurfaceAloneLeavesTheSlopeUnworked() {
when(complex.getSlopeStream()).thenThrow(new AssertionError("the slope was worked out"));
IrisTerrainSampler terrain = new IrisTerrainSampler(engine, null, 0, 0, CHUNK_REACH);
assertEquals(64D, terrain.surfaceY(1, 3), 0D);
}
@Test
public void aColumnsSurfaceOutsideTheSampledAreaIsRefusedLikeTheColumn() {
IrisTerrainSampler terrain = new IrisTerrainSampler(engine, null, 0, 0, CHUNK_REACH);
assertThrows(IndexOutOfBoundsException.class, () -> terrain.surfaceY(32, 0));
assertThrows(IndexOutOfBoundsException.class, () -> terrain.column(32, 0));
}
}
@@ -39,13 +39,17 @@ import org.junit.Before;
import org.junit.Test;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.mockito.ArgumentMatchers.anyDouble;
import static org.mockito.ArgumentMatchers.anyInt;
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.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/**
@@ -166,6 +170,33 @@ public class EngineCaveBiomeTest {
assertSame(cave, engine.getCaveBiome(10, SURFACE_Y - 1, 20));
}
@Test
public void theWorldAsksTheProviderForABiomesDepthOnceAndLoadsAnOverridingBiomeOnce() {
AtomicInteger depthQuestions = new AtomicInteger();
CaveBiomes counting = caves(null, 10);
serve(new CaveBiomes() {
@Override
public Optional<String> overriddenBiome(PackWorld world, int x, int y, int z) {
return y > SURFACE_Y ? Optional.of("band/deep") : Optional.empty();
}
@Override
public int minDepthBelowSurface(PackWorld world, String biomeKey) {
depthQuestions.incrementAndGet();
return counting.minDepthBelowSurface(world, biomeKey);
}
});
for (int y = 0; y < SURFACE_Y; y++) {
engine.getCaveBiome(10, y, 20);
}
assertSame(band, engine.getCaveBiome(10, SURFACE_Y + 5, 20));
assertSame(band, engine.getCaveBiome(10, SURFACE_Y + 6, 20));
assertEquals(1, depthQuestions.get());
verify(data.getBiomeLoader(), times(1)).load("band/deep");
}
@Test
public void theCarveModulesProviderReadsTheDepthFromTheBiomesSettings() {
IrisBiome deep = mock(IrisBiome.class);