package net.minecraft.world.level.levelgen.synth;

import java.util.List;
import java.util.stream.Collector;
import com.google.common.collect.ImmutableList;
import java.util.stream.IntStream;
import net.minecraft.world.level.levelgen.WorldgenRandom;

public class NormalNoise {
    private final double valueFactor;
    private final PerlinNoise first;
    private final PerlinNoise second;
    
    public NormalNoise(final WorldgenRandom ciy, final IntStream intStream) {
        this(ciy, intStream.boxed().collect(ImmutableList.<Integer>toImmutableList()));
    }
    
    public NormalNoise(final WorldgenRandom ciy, final List<Integer> list) {
        this.first = new PerlinNoise(ciy, list);
        this.second = new PerlinNoise(ciy, list);
        final int integer4 = list.stream().min(Integer::compareTo).orElse(0);
        final int integer5 = list.stream().max(Integer::compareTo).orElse(0);
        this.valueFactor = 0.16666666666666666 / expectedDeviation(integer5 - integer4);
    }
    
    private static double expectedDeviation(final int integer) {
        return 0.1 * (1.0 + 1.0 / (integer + 1));
    }
    
    public double getValue(final double double1, final double double2, final double double3) {
        final double double4 = double1 * 1.0181268882175227;
        final double double5 = double2 * 1.0181268882175227;
        final double double6 = double3 * 1.0181268882175227;
        return (this.first.getValue(double1, double2, double3) + this.second.getValue(double4, double5, double6)) * this.valueFactor;
    }
}
