package gr8pefish.openglider.common.wind;

import gr8pefish.openglider.api.item.IGlider;
import gr8pefish.openglider.common.config.ConfigHandler;
import gr8pefish.openglider.common.wind.generator.OpenSimplexNoise;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;

public class WindHelper {

    public static OpenSimplexNoise noiseGenerator;

    public static void initNoiseGenerator() {
        noiseGenerator = new OpenSimplexNoise();
    }

    public static void applyWind(EntityPlayer player, ItemStack glider){

        if (!ConfigHandler.windEnabled) return; //if no wind, then do nothing

        double windGustSize = ConfigHandler.windGustSize; //18;
        double windFrequency = ConfigHandler.windFrequency; //0.15;
        double windRainingMultiplier = ConfigHandler.windRainingMultiplier; //4;
        double windSpeedMultiplier = ConfigHandler.windSpeedMultiplier; //0.4;
        double windHeightMultiplier = ConfigHandler.windHeightMultiplier; //1.2;
        double windOverallPower = ConfigHandler.windOverallPower; //1;

        //downscale for gust size/occurrence amount
        double noise = WindHelper.noiseGenerator.eval(player.posX / windGustSize, player.posZ / windGustSize); //occurrence amount

        //multiply by intensity factor (alter by multiplier if raining)
        noise *= player.world.isRaining() ? windRainingMultiplier * windFrequency : windFrequency;

        //stabilize somewhat depending on velocity
        double velocity = Math.sqrt(Math.pow(player.motionX, 2) + Math.pow(player.motionZ, 2)); //player's velocity
        double speedStabilized = noise * 1/((velocity * windSpeedMultiplier) + 1); //stabilize somewhat with higher speeds //ToDo: test

        //increase wind depending on world height
        double height = player.posY < 256 ? (player.posY / 256) * windHeightMultiplier : windHeightMultiplier; //world height clamp

        //apply stabilized speed with height
        double wind = speedStabilized * height;

        //apply durability modifier
        double additionalDamagePercentage = glider.isItemDamaged() ? ConfigHandler.windDurabilityMultiplier * ((double)glider.getItemDamage() / (glider.getMaxDamage())) : 0; //1.x where x is the percent of durability used
        wind *= 1 + additionalDamagePercentage;

        //apply overall wind power multiplier
        wind *= windOverallPower;

        //apply tier specific wind power multiplier
        wind *= ((IGlider)glider.getItem()).getWindMultiplier();

        //apply final rotation based on all the above
        player.rotationYaw += wind;
    }

}

@@ -298,188 +298,753 @@
 k;%0A%0A
-public class WindHelper %7B%0A%0A    public static OpenSimplexNoise noiseGenerator;%0A%0A    public static void initNoiseGenerator() %7B%0A        noiseGenerator = new OpenSimplexNoise();%0A    %7D%0A
+%0A/**%0A * Applies %22wind%22 effects to the player, moving them around when they fly.%0A */%0Apublic class WindHelper %7B%0A%0A    /** Simplex noise has a better %22game feel%22 than Perlin (the standard for Minecraft), so ti is used here. */%0A    public static OpenSimplexNoise noiseGenerator;%0A%0A    /** Initialize noise generator once and store in a static variable for performance. */%0A    public static void initNoiseGenerator() %7B%0A        noiseGenerator = new OpenSimplexNoise();%0A    %7D%0A%0A    /**%0A     * Apply wind effect, buffeting them around pseudo-randomly.%0A     * Affected by a variety of things, from player height to glider durability to weather, etc.%0A     *%0A     * @param player - the player to move around%0A     * @param glider - the hang glider item%0A     */
 %0A   
@@ -2287,21 +2287,8 @@
 eeds
- //ToDo: test
 %0A%0A  

Update docs for WindHelper