| 1 | package net.minecraft.data.worldgen;
|
| 2 |
|
| 3 | import it.unimi.dsi.fastutil.floats.Float2FloatFunction;
|
| 4 | import net.minecraft.util.BoundedFloatFunction;
|
| 5 | import net.minecraft.util.CubicSpline;
|
| 6 | import net.minecraft.util.Mth;
|
| 7 |
|
| 8 | public class TerrainProvider {
|
| 9 | private static final float DEEP_OCEAN_CONTINENTALNESS = -0.51F;
|
| 10 | private static final float OCEAN_CONTINENTALNESS = -0.4F;
|
| 11 | private static final float PLAINS_CONTINENTALNESS = 0.1F;
|
| 12 | private static final float BEACH_CONTINENTALNESS = -0.15F;
|
| 13 | private static final Float2FloatFunction NO_TRANSFORM = Float2FloatFunction.identity();
|
| 14 | private static final Float2FloatFunction AMPLIFIED_OFFSET = offset -> offset < 0.0F ? offset : offset * 2.0F;
|
| 15 | private static final Float2FloatFunction AMPLIFIED_FACTOR = factor -> 1.25F - 6.25F / (factor + 5.0F);
|
| 16 | private static final Float2FloatFunction AMPLIFIED_JAGGEDNESS = jaggedness -> jaggedness * 2.0F;
|
| 17 |
|
| 18 | public static <I extends BoundedFloatFunction<?>> CubicSpline<I> overworldOffset(final I continents, final I erosion, final I ridges, final boolean amplified) {
|
| 19 | Float2FloatFunction offsetTransformer = amplified ? AMPLIFIED_OFFSET : NO_TRANSFORM;
|
| 20 | CubicSpline<I> beachSpline = buildErosionOffsetSpline(erosion, ridges, -0.15F, 0.0F, 0.0F, 0.1F, 0.0F, -0.03F, false, false, offsetTransformer);
|
| 21 | CubicSpline<I> lowSpline = buildErosionOffsetSpline(erosion, ridges, -0.1F, 0.03F, 0.1F, 0.1F, 0.01F, -0.03F, false, false, offsetTransformer);
|
| 22 | CubicSpline<I> midSpline = buildErosionOffsetSpline(erosion, ridges, -0.1F, 0.03F, 0.1F, 0.7F, 0.01F, -0.03F, true, true, offsetTransformer);
|
| 23 | CubicSpline<I> highSpline = buildErosionOffsetSpline(erosion, ridges, -0.05F, 0.03F, 0.1F, 1.0F, 0.01F, 0.01F, true, true, offsetTransformer);
|
| 24 | return CubicSpline.<I>builder(continents, offsetTransformer)
|
| 25 | .addPoint(-1.1F, 0.044F)
|
| 26 | .addPoint(-1.02F, -0.2222F)
|
| 27 | .addPoint(-0.51F, -0.2222F)
|
| 28 | .addPoint(-0.44F, -0.12F)
|
| 29 | .addPoint(-0.18F, -0.12F)
|
| 30 | .addPoint(-0.16F, beachSpline)
|
| 31 | .addPoint(-0.15F, beachSpline)
|
| 32 | .addPoint(-0.1F, lowSpline)
|
| 33 | .addPoint(0.25F, midSpline)
|
| 34 | .addPoint(1.0F, highSpline)
|
| 35 | .build();
|
| 36 | }
|
| 37 |
|
| 38 | public static <I extends BoundedFloatFunction<?>> CubicSpline<I> overworldFactor(
|
| 39 | final I continents, final I erosion, final I weirdness, final I ridges, final boolean amplified
|
| 40 | ) {
|
| 41 | Float2FloatFunction factorTransformer = amplified ? AMPLIFIED_FACTOR : NO_TRANSFORM;
|
| 42 | return CubicSpline.<I>builder(continents, NO_TRANSFORM)
|
| 43 | .addPoint(-0.19F, 3.95F)
|
| 44 | .addPoint(-0.15F, getErosionFactor(erosion, weirdness, ridges, 6.25F, true, NO_TRANSFORM))
|
| 45 | .addPoint(-0.1F, getErosionFactor(erosion, weirdness, ridges, 5.47F, true, factorTransformer))
|
| 46 | .addPoint(0.03F, getErosionFactor(erosion, weirdness, ridges, 5.08F, true, factorTransformer))
|
| 47 | .addPoint(0.06F, getErosionFactor(erosion, weirdness, ridges, 4.69F, false, factorTransformer))
|
| 48 | .build();
|
| 49 | }
|
| 50 |
|
| 51 | public static <I extends BoundedFloatFunction<?>> CubicSpline<I> overworldJaggedness(
|
| 52 | final I continents, final I erosion, final I weirdness, final I ridges, final boolean amplified
|
| 53 | ) {
|
| 54 | Float2FloatFunction jaggednessTransformer = amplified ? AMPLIFIED_JAGGEDNESS : NO_TRANSFORM;
|
| 55 | float farInlandMiddle = 0.65F;
|
| 56 | return CubicSpline.<I>builder(continents, jaggednessTransformer)
|
| 57 | .addPoint(-0.11F, 0.0F)
|
| 58 | .addPoint(0.03F, buildErosionJaggednessSpline(erosion, weirdness, ridges, 1.0F, 0.5F, 0.0F, 0.0F, jaggednessTransformer))
|
| 59 | .addPoint(0.65F, buildErosionJaggednessSpline(erosion, weirdness, ridges, 1.0F, 1.0F, 1.0F, 0.0F, jaggednessTransformer))
|
| 60 | .build();
|
| 61 | }
|
| 62 |
|
| 63 | private static <I extends BoundedFloatFunction<?>> CubicSpline<I> buildErosionJaggednessSpline(
|
| 64 | final I erosion,
|
| 65 | final I weirdness,
|
| 66 | final I ridges,
|
| 67 | final float jaggednessFactorAtPeakRidgeAndErosionIndex0,
|
| 68 | final float jaggednessFactorAtPeakRidgeAndErosionIndex1,
|
| 69 | final float jaggednessFactorAtHighRidgeAndErosionIndex0,
|
| 70 | final float jaggednessFactorAtHighRidgeAndErosionIndex1,
|
| 71 | final Float2FloatFunction jaggednessTransformer
|
| 72 | ) {
|
| 73 | float erosionIndex1Middle = -0.5775F;
|
| 74 | CubicSpline<I> ridgeJaggednessSplineAtErosion0 = buildRidgeJaggednessSpline(
|
| 75 | weirdness, ridges, jaggednessFactorAtPeakRidgeAndErosionIndex0, jaggednessFactorAtHighRidgeAndErosionIndex0, jaggednessTransformer
|
| 76 | );
|
| 77 | CubicSpline<I> ridgeJaggednessSplineAtErosion1 = buildRidgeJaggednessSpline(
|
| 78 | weirdness, ridges, jaggednessFactorAtPeakRidgeAndErosionIndex1, jaggednessFactorAtHighRidgeAndErosionIndex1, jaggednessTransformer
|
| 79 | );
|
| 80 | return CubicSpline.<I>builder(erosion, jaggednessTransformer)
|
| 81 | .addPoint(-1.0F, ridgeJaggednessSplineAtErosion0)
|
| 82 | .addPoint(-0.78F, ridgeJaggednessSplineAtErosion1)
|
| 83 | .addPoint(-0.5775F, ridgeJaggednessSplineAtErosion1)
|
| 84 | .addPoint(-0.375F, 0.0F)
|
| 85 | .build();
|
| 86 | }
|
| 87 |
|
| 88 | public static float peaksAndValleys(final float weirdness) {
|
| 89 | return -(Math.abs(Math.abs(weirdness) - 0.6666667F) - 0.33333334F) * 3.0F;
|
| 90 | }
|
| 91 |
|
| 92 | private static <I extends BoundedFloatFunction<?>> CubicSpline<I> buildRidgeJaggednessSpline(
|
| 93 | final I weirdness,
|
| 94 | final I ridges,
|
| 95 | final float jaggednessFactorAtPeakRidge,
|
| 96 | final float jaggednessFactorAtHighRidge,
|
| 97 | final Float2FloatFunction jaggednessTransformer
|
| 98 | ) {
|
| 99 | float highSliceStart = peaksAndValleys(0.4F);
|
| 100 | float highSliceEnd = peaksAndValleys(0.56666666F);
|
| 101 | float highSliceMiddle = (highSliceStart + highSliceEnd) / 2.0F;
|
| 102 | CubicSpline.Builder<I> ridgeSpline = CubicSpline.builder(ridges, jaggednessTransformer);
|
| 103 | ridgeSpline.addPoint(highSliceStart, 0.0F);
|
| 104 | if (jaggednessFactorAtHighRidge > 0.0F) {
|
| 105 | ridgeSpline.addPoint(highSliceMiddle, buildWeirdnessJaggednessSpline(weirdness, jaggednessFactorAtHighRidge, jaggednessTransformer));
|
| 106 | } else {
|
| 107 | ridgeSpline.addPoint(highSliceMiddle, 0.0F);
|
| 108 | }
|
| 109 |
|
| 110 | if (jaggednessFactorAtPeakRidge > 0.0F) {
|
| 111 | ridgeSpline.addPoint(1.0F, buildWeirdnessJaggednessSpline(weirdness, jaggednessFactorAtPeakRidge, jaggednessTransformer));
|
| 112 | } else {
|
| 113 | ridgeSpline.addPoint(1.0F, 0.0F);
|
| 114 | }
|
| 115 |
|
| 116 | return ridgeSpline.build();
|
| 117 | }
|
| 118 |
|
| 119 | private static <I extends BoundedFloatFunction<?>> CubicSpline<I> buildWeirdnessJaggednessSpline(
|
| 120 | final I weirdness, final float jaggednessFactor, final Float2FloatFunction jaggednessTransformer
|
| 121 | ) {
|
| 122 | float maxJaggednessAtNegativeWeirdness = 0.63F * jaggednessFactor;
|
| 123 | float maxJaggednessAtPositiveWeirdness = 0.3F * jaggednessFactor;
|
| 124 | return CubicSpline.<I>builder(weirdness, jaggednessTransformer)
|
| 125 | .addPoint(-0.01F, maxJaggednessAtNegativeWeirdness)
|
| 126 | .addPoint(0.01F, maxJaggednessAtPositiveWeirdness)
|
| 127 | .build();
|
| 128 | }
|
| 129 |
|
| 130 | private static <I extends BoundedFloatFunction<?>> CubicSpline<I> getErosionFactor(
|
| 131 | final I erosion, final I weirdness, final I ridges, final float baseValue, final boolean shatteredTerrain, final Float2FloatFunction factorTransformer
|
| 132 | ) {
|
| 133 | CubicSpline<I> baseSpline = CubicSpline.<I>builder(weirdness, factorTransformer).addPoint(-0.2F, 6.3F).addPoint(0.2F, baseValue).build();
|
| 134 | CubicSpline.Builder<I> erosionPoints = CubicSpline.<I>builder(erosion, factorTransformer)
|
| 135 | .addPoint(-0.6F, baseSpline)
|
| 136 | .addPoint(-0.5F, CubicSpline.<I>builder(weirdness, factorTransformer).addPoint(-0.05F, 6.3F).addPoint(0.05F, 2.67F).build())
|
| 137 | .addPoint(-0.35F, baseSpline)
|
| 138 | .addPoint(-0.25F, baseSpline)
|
| 139 | .addPoint(-0.1F, CubicSpline.<I>builder(weirdness, factorTransformer).addPoint(-0.05F, 2.67F).addPoint(0.05F, 6.3F).build())
|
| 140 | .addPoint(0.03F, baseSpline);
|
| 141 | if (shatteredTerrain) {
|
| 142 | CubicSpline<I> weirdnessShattered = CubicSpline.<I>builder(weirdness, factorTransformer).addPoint(0.0F, baseValue).addPoint(0.1F, 0.625F).build();
|
| 143 | CubicSpline<I> ridgesShattered = CubicSpline.<I>builder(ridges, factorTransformer).addPoint(-0.9F, baseValue).addPoint(-0.69F, weirdnessShattered).build();
|
| 144 | erosionPoints.addPoint(0.35F, baseValue).addPoint(0.45F, ridgesShattered).addPoint(0.55F, ridgesShattered).addPoint(0.62F, baseValue);
|
| 145 | } else {
|
| 146 | CubicSpline<I> extremeHillsTerrainFromMidSliceAndUp = CubicSpline.<I>builder(ridges, factorTransformer)
|
| 147 | .addPoint(-0.7F, baseSpline)
|
| 148 | .addPoint(-0.15F, 1.37F)
|
| 149 | .build();
|
| 150 | CubicSpline<I> extra3dNoiseOnPeaksOnly = CubicSpline.<I>builder(ridges, factorTransformer).addPoint(0.45F, baseSpline).addPoint(0.7F, 1.56F).build();
|
| 151 | erosionPoints.addPoint(0.05F, extra3dNoiseOnPeaksOnly)
|
| 152 | .addPoint(0.4F, extra3dNoiseOnPeaksOnly)
|
| 153 | .addPoint(0.45F, extremeHillsTerrainFromMidSliceAndUp)
|
| 154 | .addPoint(0.55F, extremeHillsTerrainFromMidSliceAndUp)
|
| 155 | .addPoint(0.58F, baseValue);
|
| 156 | }
|
| 157 |
|
| 158 | return erosionPoints.build();
|
| 159 | }
|
| 160 |
|
| 161 | private static float calculateSlope(final float y1, final float y2, final float x1, final float x2) {
|
| 162 | return (y2 - y1) / (x2 - x1);
|
| 163 | }
|
| 164 |
|
| 165 | private static <I extends BoundedFloatFunction<?>> CubicSpline<I> buildMountainRidgeSplineWithPoints(
|
| 166 | final I ridges, final float modulation, final boolean saddle, final Float2FloatFunction offsetTransformer
|
| 167 | ) {
|
| 168 | CubicSpline.Builder<I> build = CubicSpline.builder(ridges, offsetTransformer);
|
| 169 | float allowRiversBelow = -0.7F;
|
| 170 | float minPoint = -1.0F;
|
| 171 | float minPointContinentalness = mountainContinentalness(-1.0F, modulation, -0.7F);
|
| 172 | float maxPoint = 1.0F;
|
| 173 | float maxPointContinentalness = mountainContinentalness(1.0F, modulation, -0.7F);
|
| 174 | float ridgeZeroPoint = calculateMountainRidgeZeroContinentalnessPoint(modulation);
|
| 175 | float afterRiverPoint = -0.65F;
|
| 176 | if (-0.65F < ridgeZeroPoint && ridgeZeroPoint < 1.0F) {
|
| 177 | float afterRiverThresholdContinentalness = mountainContinentalness(-0.65F, modulation, -0.7F);
|
| 178 | float beforeRiverPoint = -0.75F;
|
| 179 | float beforeRiverThresholdContinentalness = mountainContinentalness(-0.75F, modulation, -0.7F);
|
| 180 | float minPointDerivative = calculateSlope(minPointContinentalness, beforeRiverThresholdContinentalness, -1.0F, -0.75F);
|
| 181 | build.addPoint(-1.0F, minPointContinentalness, minPointDerivative);
|
| 182 | build.addPoint(-0.75F, beforeRiverThresholdContinentalness);
|
| 183 | build.addPoint(-0.65F, afterRiverThresholdContinentalness);
|
| 184 | float ridgeZeroPointContinentalness = mountainContinentalness(ridgeZeroPoint, modulation, -0.7F);
|
| 185 | float maxPointDerivative = calculateSlope(ridgeZeroPointContinentalness, maxPointContinentalness, ridgeZeroPoint, 1.0F);
|
| 186 | float smallOffset = 0.01F;
|
| 187 | build.addPoint(ridgeZeroPoint - 0.01F, ridgeZeroPointContinentalness);
|
| 188 | build.addPoint(ridgeZeroPoint, ridgeZeroPointContinentalness, maxPointDerivative);
|
| 189 | build.addPoint(1.0F, maxPointContinentalness, maxPointDerivative);
|
| 190 | } else {
|
| 191 | float simpleDerivative = calculateSlope(minPointContinentalness, maxPointContinentalness, -1.0F, 1.0F);
|
| 192 | if (saddle) {
|
| 193 | build.addPoint(-1.0F, Math.max(0.2F, minPointContinentalness));
|
| 194 | build.addPoint(0.0F, Mth.lerp(0.5F, minPointContinentalness, maxPointContinentalness), simpleDerivative);
|
| 195 | } else {
|
| 196 | build.addPoint(-1.0F, minPointContinentalness, simpleDerivative);
|
| 197 | }
|
| 198 |
|
| 199 | build.addPoint(1.0F, maxPointContinentalness, simpleDerivative);
|
| 200 | }
|
| 201 |
|
| 202 | return build.build();
|
| 203 | }
|
| 204 |
|
| 205 | private static float mountainContinentalness(final float ridge, final float modulation, final float allowRiversBelow) {
|
| 206 | float ridgeOffset = 1.17F;
|
| 207 | float ridgeAmplitude = 0.46082947F;
|
| 208 | float ridgeSlope = 1.0F - (1.0F - modulation) * 0.5F;
|
| 209 | float ridgeIntersect = 0.5F * (1.0F - modulation);
|
| 210 | float adjustedRidgeHeight = (ridge + 1.17F) * 0.46082947F;
|
| 211 | float continentalness = adjustedRidgeHeight * ridgeSlope - ridgeIntersect;
|
| 212 | return ridge < allowRiversBelow ? Math.max(continentalness, -0.2222F) : Math.max(continentalness, 0.0F);
|
| 213 | }
|
| 214 |
|
| 215 | private static float calculateMountainRidgeZeroContinentalnessPoint(final float modulation) {
|
| 216 | float ridgeOffset = 1.17F;
|
| 217 | float ridgeAmplitude = 0.46082947F;
|
| 218 | float ridgeSlope = 1.0F - (1.0F - modulation) * 0.5F;
|
| 219 | float ridgeIntersect = 0.5F * (1.0F - modulation);
|
| 220 | return ridgeIntersect / (0.46082947F * ridgeSlope) - 1.17F;
|
| 221 | }
|
| 222 |
|
| 223 | public static <I extends BoundedFloatFunction<?>> CubicSpline<I> buildErosionOffsetSpline(
|
| 224 | final I erosion,
|
| 225 | final I ridges,
|
| 226 | final float lowValley,
|
| 227 | final float hill,
|
| 228 | final float tallHill,
|
| 229 | final float mountainFactor,
|
| 230 | final float plain,
|
| 231 | final float swamp,
|
| 232 | final boolean includeExtremeHills,
|
| 233 | final boolean saddle,
|
| 234 | final Float2FloatFunction offsetTransformer
|
| 235 | ) {
|
| 236 | float lowPeaks = 0.6F;
|
| 237 | float valleyPlateau = 0.5F;
|
| 238 | float plateau = 0.5F;
|
| 239 | CubicSpline<I> veryLowErosionMountains = buildMountainRidgeSplineWithPoints(ridges, Mth.lerp(mountainFactor, 0.6F, 1.5F), saddle, offsetTransformer);
|
| 240 | CubicSpline<I> lowErosionMountains = buildMountainRidgeSplineWithPoints(ridges, Mth.lerp(mountainFactor, 0.6F, 1.0F), saddle, offsetTransformer);
|
| 241 | CubicSpline<I> mountains = buildMountainRidgeSplineWithPoints(ridges, mountainFactor, saddle, offsetTransformer);
|
| 242 | CubicSpline<I> widePlateau = ridgeSpline(
|
| 243 | ridges,
|
| 244 | lowValley - 0.15F,
|
| 245 | 0.5F * mountainFactor,
|
| 246 | Mth.lerp(0.5F, 0.5F, 0.5F) * mountainFactor,
|
| 247 | 0.5F * mountainFactor,
|
| 248 | 0.6F * mountainFactor,
|
| 249 | 0.5F,
|
| 250 | offsetTransformer
|
| 251 | );
|
| 252 | CubicSpline<I> narrowPlateau = ridgeSpline(
|
| 253 | ridges, lowValley, plain * mountainFactor, hill * mountainFactor, 0.5F * mountainFactor, 0.6F * mountainFactor, 0.5F, offsetTransformer
|
| 254 | );
|
| 255 | CubicSpline<I> plains = ridgeSpline(ridges, lowValley, plain, plain, hill, tallHill, 0.5F, offsetTransformer);
|
| 256 | CubicSpline<I> plainsFarInland = ridgeSpline(ridges, lowValley, plain, plain, hill, tallHill, 0.5F, offsetTransformer);
|
| 257 | CubicSpline<I> extremeHills = CubicSpline.<I>builder(ridges, offsetTransformer)
|
| 258 | .addPoint(-1.0F, lowValley)
|
| 259 | .addPoint(-0.4F, plains)
|
| 260 | .addPoint(0.0F, tallHill + 0.07F)
|
| 261 | .build();
|
| 262 | CubicSpline<I> swamps = ridgeSpline(ridges, -0.02F, swamp, swamp, hill, tallHill, 0.0F, offsetTransformer);
|
| 263 | CubicSpline.Builder<I> builder = CubicSpline.<I>builder(erosion, offsetTransformer)
|
| 264 | .addPoint(-0.85F, veryLowErosionMountains)
|
| 265 | .addPoint(-0.7F, lowErosionMountains)
|
| 266 | .addPoint(-0.4F, mountains)
|
| 267 | .addPoint(-0.35F, widePlateau)
|
| 268 | .addPoint(-0.1F, narrowPlateau)
|
| 269 | .addPoint(0.2F, plains);
|
| 270 | if (includeExtremeHills) {
|
| 271 | builder.addPoint(0.4F, plainsFarInland).addPoint(0.45F, extremeHills).addPoint(0.55F, extremeHills).addPoint(0.58F, plainsFarInland);
|
| 272 | }
|
| 273 |
|
| 274 | builder.addPoint(0.7F, swamps);
|
| 275 | return builder.build();
|
| 276 | }
|
| 277 |
|
| 278 | private static <I extends BoundedFloatFunction<?>> CubicSpline<I> ridgeSpline(
|
| 279 | final I ridges,
|
| 280 | final float valley,
|
| 281 | final float low,
|
| 282 | final float mid,
|
| 283 | final float high,
|
| 284 | final float peaks,
|
| 285 | final float minValleySteepness,
|
| 286 | final Float2FloatFunction offsetTransformer
|
| 287 | ) {
|
| 288 | float d1 = Math.max(0.5F * (low - valley), minValleySteepness);
|
| 289 | float d2 = 5.0F * (mid - low);
|
| 290 | return CubicSpline.<I>builder(ridges, offsetTransformer)
|
| 291 | .addPoint(-1.0F, valley, d1)
|
| 292 | .addPoint(-0.4F, low, Math.min(d1, d2))
|
| 293 | .addPoint(0.0F, mid, d2)
|
| 294 | .addPoint(0.4F, high, 2.0F * (high - mid))
|
| 295 | .addPoint(1.0F, peaks, 0.7F * (peaks - high))
|
| 296 | .build();
|
| 297 | }
|
| 298 | }
|
| 299 |
|