NoiseSampler.scaled: the noise with an extra coordinate scale, folded into the host's generator

This commit is contained in:
piexel committed 2026-10-10 18:19:54 +02:00
1 parent 904a6599b3
commit 44c98dcd8b
3 files changed
+49

No files matched your search

+4
View File
@@ -800,6 +800,10 @@ Why these lines:
the module's: noise lines up across chunks only when it comes from `worldSeed()`, not a stage's stream.
- **`NoiseSampler` moved to `com.volmit.noise`** and gained a two-dimensional `sample(x, z)`: Iris's noise
gives different fields in two and three dimensions, and most features sample columns.
- **`NoiseSampler.scaled(factor)`** is a style with an extra coordinate scale that the host folds into its generator: a cave
biome band splits into child bands with noise shrunk by a factor, and a module that multiplied the coordinates itself would
round differently from the generator Iris has always built, moving a cell border here and there. A default method
(multiply the coordinates) keeps every other sampler valid.
- **`PackWorld.minHeight()`**: all heights are above the dimension's bottom, but packs write some settings as absolute
world Y (cave biome bands, floating island altitudes, structure bands). Those are converted by the module with the
platform's Y of the bottom, a default method (0) so a fixture without negative Y needs nothing.
@@ -23,4 +23,34 @@ public interface NoiseSampler {
default double signed(double worldX, double y, double worldZ) {
return sample(worldX, y, worldZ) * 2D - 1D;
}
/** This noise with its coordinates multiplied by {@code factor}: a factor above 1 squeezes the pattern, below 1
* stretches it. A host folds the factor into the generator's own scale, so the result is the very noise the style
* would give with that extra scale (same values and float rounding), and builds it without touching this sampler.
* The default multiplies the coordinates before sampling, which may round differently.
*/
default NoiseSampler scaled(double factor) {
NoiseSampler source = this;
return new NoiseSampler() {
@Override
public double sample(double worldX, double worldZ) {
return source.sample(worldX * factor, worldZ * factor);
}
@Override
public double sample(double worldX, double y, double worldZ) {
return source.sample(worldX * factor, y * factor, worldZ * factor);
}
@Override
public double signed(double worldX, double worldZ) {
return source.signed(worldX * factor, worldZ * factor);
}
@Override
public double signed(double worldX, double y, double worldZ) {
return source.signed(worldX * factor, y * factor, worldZ * factor);
}
};
}
}
@@ -32,4 +32,19 @@ class NoiseSamplerTest {
assertEquals(7D, noise.signed(1D, 1D), EXACT);
assertEquals(0.25D * 2D - 1D, noise.signed(1D, 1D, 1D), EXACT);
}
@Test
void scaledSamplesAtTheScaledCoordinates() {
NoiseSampler noise = new NoiseSampler() {
public double sample(double worldX, double worldZ) { return worldX + worldZ * 100D; }
public double sample(double worldX, double y, double worldZ) { return worldX + y * 100D + worldZ * 10000D; }
};
NoiseSampler scaled = noise.scaled(2D);
assertEquals(noise.sample(6D, 4D), scaled.sample(3D, 2D), EXACT);
assertEquals(noise.sample(6D, 4D, 2D), scaled.sample(3D, 2D, 1D), EXACT);
assertEquals(noise.signed(6D, 4D), scaled.signed(3D, 2D), EXACT);
assertEquals(noise.signed(6D, 4D, 2D), scaled.signed(3D, 2D, 1D), EXACT);
}
}