package ca.recrown.islandsurvivalcraft.world;

import java.util.Random;

import org.bukkit.util.noise.SimplexOctaveGenerator;

import ca.recrown.islandsurvivalcraft.utilities.caching.Cache;
import ca.recrown.islandsurvivalcraft.utilities.datatypes.Point2;

public class TemperatureMap {
    private final Cache<Point2, Float> temperatureCache;
    private final double frequency = 0.5D;
    private final double amplitude = 0.5D;

    private volatile SimplexOctaveGenerator noiseGenerator;

    public TemperatureMap(Random random) {
        temperatureCache = new Cache<>(1024);
        noiseGenerator = new SimplexOctaveGenerator(random, 2);
        noiseGenerator.setScale(0.002D);
    }

    public float getTemperature(int worldX, int worldZ) {
        Point2 loc = new Point2(worldX, worldZ);
        Float val = temperatureCache.get(loc);
        if (val == null) {
            val = (float) noiseGenerator.noise(worldX, worldZ, frequency, amplitude, true);
            temperatureCache.set(loc, val);
        }
        return val;
    }
}