package ca.recrown.islandsurvivalcraft.world.generation;

import java.util.Random;

import org.bukkit.util.noise.SimplexOctaveGenerator;

import ca.recrown.islandsurvivalcraft.caching.Cache;
import ca.recrown.islandsurvivalcraft.caching.CacheValue;
import ca.recrown.islandsurvivalcraft.caching.CoordinateIdentifier;

class TemperatureMapGenerator {
    private final Cache<Float> temperatureCache;
    private final double frequency = 0.5D;
    private final double amplitude = 0.5D;

    private SimplexOctaveGenerator noiseGenerator;

    public TemperatureMapGenerator() {
        temperatureCache = new Cache<>(1024);
    }

    public void setSeed(long seed) {
        noiseGenerator = new SimplexOctaveGenerator(new Random(seed), 2);
        noiseGenerator.setScale(0.005D);
    }

    public float getTemperature(int worldX, int worldZ) {
        CacheValue<Float> val = temperatureCache.retrieveCache(new CoordinateIdentifier(worldX/4, worldZ/4));
        if (val.isEmpty()) val.setValue((float) noiseGenerator.noise(worldX/4, worldZ/4, frequency, amplitude, true));
        return val.getValue();
    }
}