| 1 | package net.minecraft.world.level.levelgen.synth;
|
| 2 |
|
| 3 | import it.unimi.dsi.fastutil.doubles.DoubleList;
|
| 4 | import java.util.Arrays;
|
| 5 | import java.util.Objects;
|
| 6 | import net.minecraft.util.RandomSource;
|
| 7 |
|
| 8 | @Deprecated
|
| 9 | public class LegacyFbmInitializer {
|
| 10 | public static NoiseStack createForLegacyNetherBiome(final RandomSource random, final int firstOctave, final DoubleList amplitudes) {
|
| 11 | int octaves = amplitudes.size();
|
| 12 | int zeroOctaveIndex = -firstOctave;
|
| 13 | PerlinNoise[] noiseLevels = new PerlinNoise[octaves];
|
| 14 | PerlinNoise zeroOctave = new PerlinNoise(random);
|
| 15 | if (zeroOctaveIndex >= 0 && zeroOctaveIndex < octaves) {
|
| 16 | double zeroOctaveAmplitude = amplitudes.getDouble(zeroOctaveIndex);
|
| 17 | if (zeroOctaveAmplitude != 0.0) {
|
| 18 | noiseLevels[zeroOctaveIndex] = zeroOctave;
|
| 19 | }
|
| 20 | }
|
| 21 |
|
| 22 | for (int i = zeroOctaveIndex - 1; i >= 0; i--) {
|
| 23 | if (i < octaves) {
|
| 24 | double amplitude = amplitudes.getDouble(i);
|
| 25 | if (amplitude != 0.0) {
|
| 26 | noiseLevels[i] = new PerlinNoise(random);
|
| 27 | } else {
|
| 28 | skipOctave(random);
|
| 29 | }
|
| 30 | } else {
|
| 31 | skipOctave(random);
|
| 32 | }
|
| 33 | }
|
| 34 |
|
| 35 | if (Arrays.stream(noiseLevels).filter(Objects::nonNull).count() != amplitudes.stream().filter(a -> a != 0.0).count()) {
|
| 36 | throw new IllegalStateException("Failed to create correct number of noise levels for given non-zero amplitudes");
|
| 37 | }
|
| 38 |
|
| 39 | if (zeroOctaveIndex < octaves - 1) {
|
| 40 | throw new IllegalArgumentException("Positive octaves are temporarily disabled");
|
| 41 | }
|
| 42 |
|
| 43 | double factor = Math.pow(2.0, -zeroOctaveIndex);
|
| 44 | double valueFactor = Math.pow(2.0, octaves - 1) / (Math.pow(2.0, octaves) - 1.0);
|
| 45 | NoiseStack.Builder stack = NoiseStack.builder();
|
| 46 |
|
| 47 | for (int i = 0; i < noiseLevels.length; i++) {
|
| 48 | PerlinNoise noise = noiseLevels[i];
|
| 49 | if (noise != null) {
|
| 50 | stack.add(noise, factor, (float)(valueFactor * amplitudes.getDouble(i)));
|
| 51 | }
|
| 52 |
|
| 53 | factor *= 2.0;
|
| 54 | valueFactor /= 2.0;
|
| 55 | }
|
| 56 |
|
| 57 | return stack.build();
|
| 58 | }
|
| 59 |
|
| 60 | private static void skipOctave(final RandomSource random) {
|
| 61 | random.consumeCount(262);
|
| 62 | }
|
| 63 | }
|
| 64 |
|