package eu.mhsl.minenet.minigames.world.generator.featureEnriched;

import de.articdive.jnoise.JNoise;
import eu.mhsl.minenet.minigames.util.NumberUtil;
import eu.mhsl.minenet.minigames.world.generator.terrain.HeightTerrainGenerator;
import net.minestom.server.coordinate.Point;

import java.util.function.Function;

public class ValeGenerator extends HeightTerrainGenerator {
    private final JNoise curves = JNoise.newBuilder()
            .fastSimplex()
            .setSeed(rnd.nextLong())
            .setFrequency(0.01)
            .build();

    private final JNoise largeCurves = JNoise.newBuilder()
            .fastSimplex()
            .setSeed(rnd.nextLong())
            .setFrequency(0.001)
            .build();

    private Function<Integer, Double> xShiftMultiplier = multiplier -> 1d;

    public ValeGenerator() {
        setCalculateHeight(this::calculateY);
        setHeightNoiseMultiplier(point -> (int) NumberUtil.map(calculateY(point), -64, 100, 0, 16));
    }

    private int calculateY(Point point) {
        return (int) (Math.abs(point.blockX() - getXShiftAtZ(point.blockZ())) / 1.5);
    }

    public int getXShiftAtZ(int z) {
        return (int) ((curves.getNoise(z) * 32 + largeCurves.getNoise(z) * 64) * xShiftMultiplier.apply(z));
    }

    public void setXShiftMultiplier(Function<Integer, Double> xShiftMultiplier) {
        this.xShiftMultiplier = xShiftMultiplier;
    }
}
