From 2366c876592e93c4a7adefb0f3975417f05564f9 Mon Sep 17 00:00:00 2001 From: piexel Date: Tue, 10 Nov 2026 12:48:48 +0100 Subject: [PATCH] Add a terrain height source to the noise view The noise view could not show the terrain the world generates. It now lists "Terrain height", in blocks above the fluid with the world's seed, so the 2D colours and the 3D water line match the world. The native map Height view is kept as it is. v3: adb9de089 --- .../iris/core/studio/noise/NoiseSources.java | 11 +++ .../studio/noise/TerrainHeightSourceTest.java | 72 +++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 core/src/test/java/art/arcane/iris/core/studio/noise/TerrainHeightSourceTest.java diff --git a/core/src/main/java/art/arcane/iris/core/studio/noise/NoiseSources.java b/core/src/main/java/art/arcane/iris/core/studio/noise/NoiseSources.java index c3a417e90..e42865630 100644 --- a/core/src/main/java/art/arcane/iris/core/studio/noise/NoiseSources.java +++ b/core/src/main/java/art/arcane/iris/core/studio/noise/NoiseSources.java @@ -42,6 +42,7 @@ import java.util.NoSuchElementException; */ public final class NoiseSources { static final String OVERLAY_NOISE_ID = "world:overlay"; + static final String TERRAIN_HEIGHT_ID = "world:height"; // Generators mix their seed the way the Swing explorer did, so a seed shows the same noise in both. private static final long GENERATOR_SEED_SALT = 3245L; @@ -54,6 +55,7 @@ public final class NoiseSources { public static NoiseSources of(Engine engine) { List entries = new ArrayList<>(); addOverlayNoise(engine, entries); + addTerrainHeight(engine, entries); addPackGenerators(engine.getData(), entries); addPackExpressions(engine, entries); addStyles(entries); @@ -93,6 +95,15 @@ public final class NoiseSources { entries.add(new Entry(source, NoiseCategory.PACK_GENERATORS, seed -> engine.getComplex().getOverlayStream()::get)); } + // The terrain the world generates, in blocks above the fluid, so the height colours and the water line match the world. + private static void addTerrainHeight(Engine engine, List entries) { + double fluidHeight = engine.getComplex().getFluidHeight(); + BlockRange blocks = new BlockRange(-fluidHeight, engine.getHeight() - fluidHeight); + Source source = new Source(TERRAIN_HEIGHT_ID, "Terrain height", NoiseCategory.PACK_GENERATORS.label(), false, blocks); + entries.add(new Entry(source, NoiseCategory.PACK_GENERATORS, + seed -> (x, z) -> engine.getComplex().getHeightStream().getDouble(x, z) - fluidHeight)); + } + private static void addPackGenerators(IrisData data, List entries) { for (String key : sortedKeys(data.getGeneratorLoader().getPossibleKeys())) { Source source = new Source("pack:" + key, displayName(key), NoiseCategory.PACK_GENERATORS.label(), true, null); diff --git a/core/src/test/java/art/arcane/iris/core/studio/noise/TerrainHeightSourceTest.java b/core/src/test/java/art/arcane/iris/core/studio/noise/TerrainHeightSourceTest.java new file mode 100644 index 000000000..c3fda78e5 --- /dev/null +++ b/core/src/test/java/art/arcane/iris/core/studio/noise/TerrainHeightSourceTest.java @@ -0,0 +1,72 @@ +package art.arcane.iris.core.studio.noise; + +import art.arcane.iris.core.loader.IrisData; +import art.arcane.iris.core.loader.ResourceLoader; +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 art.arcane.volmlib.util.collection.KList; +import art.arcane.volmlib.util.function.NoiseProvider; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.mockito.ArgumentMatchers.anyDouble; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class TerrainHeightSourceTest { + private static final double FLUID_HEIGHT = 63D; + private static final int WORLD_HEIGHT = 320; + private static final double HILL_X = 100D; + private static final double HILL_HEIGHT = 90D; + private static final long ANY_SEED = 7L; + private static final double EXACT = 0D; + + private Engine engine; + + @Before + @SuppressWarnings({"unchecked", "rawtypes"}) + public void world() { + engine = mock(Engine.class); + IrisComplex complex = mock(IrisComplex.class); + IrisDimension dimension = mock(IrisDimension.class); + IrisData data = mock(IrisData.class); + ProceduralStream heights = mock(ProceduralStream.class); + when(heights.getDouble(anyDouble(), anyDouble())) + .thenAnswer(call -> (double) call.getArgument(0) == HILL_X ? HILL_HEIGHT : FLUID_HEIGHT); + when(engine.getComplex()).thenReturn(complex); + when(engine.getDimension()).thenReturn(dimension); + when(engine.getData()).thenReturn(data); + when(engine.getHeight()).thenReturn(WORLD_HEIGHT); + when(complex.getFluidHeight()).thenReturn(FLUID_HEIGHT); + when(complex.getHeightStream()).thenReturn(heights); + when(dimension.getOverlayNoise()).thenReturn(new KList<>()); + ResourceLoader emptyLoader = mock(ResourceLoader.class); + when(emptyLoader.getPossibleKeys()).thenReturn(new String[0]); + when(data.getGeneratorLoader()).thenReturn(emptyLoader); + when(data.getExpressionLoader()).thenReturn(emptyLoader); + } + + @Test + public void theTerrainIsListedInBlocksAboveTheFluidAndKeepsTheWorldsSeed() { + NoiseSources.Source terrain = NoiseSources.of(engine).list().stream() + .filter(source -> source.id().equals(NoiseSources.TERRAIN_HEIGHT_ID)) + .findFirst().orElseThrow(); + + assertEquals("Terrain height", terrain.name()); + assertFalse(terrain.usesSeed()); + assertEquals(-FLUID_HEIGHT, terrain.blockRange().lowest(), EXACT); + assertEquals(WORLD_HEIGHT - FLUID_HEIGHT, terrain.blockRange().highest(), EXACT); + } + + @Test + public void theTerrainSamplesTheWorldsHeightMinusTheFluid() { + NoiseProvider terrain = NoiseSources.of(engine).sampler(NoiseSources.TERRAIN_HEIGHT_ID, ANY_SEED); + + assertEquals(HILL_HEIGHT - FLUID_HEIGHT, terrain.noise(HILL_X, 5), EXACT); + assertEquals(0D, terrain.noise(0, 5), EXACT); + } +}