/*
 *  This file is part of Cubic Chunks Mod, licensed under the MIT License (MIT).
 *
 *  Copyright (c) 2015 contributors
 *
 *  Permission is hereby granted, free of charge, to any person obtaining a copy
 *  of this software and associated documentation files (the "Software"), to deal
 *  in the Software without restriction, including without limitation the rights
 *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 *  copies of the Software, and to permit persons to whom the Software is
 *  furnished to do so, subject to the following conditions:
 *
 *  The above copyright notice and this permission notice shall be included in
 *  all copies or substantial portions of the Software.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 *  THE SOFTWARE.
 */
package cubicchunks.worldgen.generator.custom;

/**
 * Util class to convert from vanilla configs to cubic chunks config
 */
public class ConversionUtils {

    // uh... don't try to check it. It will take forever. It's correct. At least in MC 1.11.
    // --> /8 because we are using world coords instead of unscaled coords
    private static final float YSCALE = 8;
    private static final float XZSCALE = 4;

    public static final float VANILLA_DEPTH_NOISE_FACTOR = 1024f / 125.0f / YSCALE;
    public static final float VANILLA_SELECTOR_NOISE_FACTOR = 12.75f;
    public static final float VANILLA_SELECTOR_NOISE_OFFSET = 0.5f;

    public static final float VANILLA_DEPTH_NOISE_FREQUENCY = 200f / (2 << 15) / XZSCALE;
    public static final float VANILLA_SELECTOR_NOISE_FREQUENCY_XZ = (684.412f / 80.0f) / (2 << 7) / XZSCALE;
    public static final float VANILLA_SELECTOR_NOISE_FREQUENCY_Y = (684.412f / 160.0f) / (2 << 7) / YSCALE;

    public static final float VANILLA_LOWHIGH_NOISE_FREQUENCY_XZ = (684.412f) / (2 << 15) / XZSCALE;
    public static final float VANILLA_LOWHIGH_NOISE_FREQUENCY_Y = (684.412f) / (2 << 15) / YSCALE;

    public static float biomeHeightVariationVanilla(float heightVariation) {
        return 2.4f * heightVariation + 4.0f / 15.0f;
    }

    public static float biomeHeightVanilla(float height) {
        return height * 17.0f / 64.0f - 1.0f / 256.0f;
    }

    // vanilla adds noise of frequencies: f, f*2, f*4, f*8 etc...
    // for 1 octave: 1*f = f*2^0 = f*2^(octaves-1)
    // for 2 octaves: 2*f = f*2^1 = f*2^(octaves-1)
    // same for 3 and higher
    public static float frequencyFromVanilla(float freq, int octaves) {
        return (float) (freq / Math.pow(2, octaves - 1));
    }
}

@@ -1912,23 +1912,37 @@
 Y = 
-200f / (2 %3C%3C 15
+frequencyFromVanilla(200f, 16
 ) / 
@@ -2010,32 +2010,52 @@
 _FREQUENCY_XZ = 
+frequencyFromVanilla
 (684.412f / 80.0
@@ -2051,35 +2051,27 @@
 412f / 80.0f
-) / (2 %3C%3C 7
+, 8
 ) / XZSCALE;
@@ -2130,32 +2130,52 @@
 E_FREQUENCY_Y = 
+frequencyFromVanilla
 (684.412f / 160.
@@ -2174,25 +2174,16 @@
 f / 
-16
+8
 0.0f
-) / (2 %3C%3C 7
+, 8
 ) / 
@@ -2258,37 +2258,49 @@
 CY_XZ = 
-(684.412f) / (2 %3C%3C 15
+frequencyFromVanilla(684.412f, 16
 ) / XZSC
@@ -2374,29 +2374,41 @@
 Y = 
-(684.412f) / (2 %3C%3C 15
+frequencyFromVanilla(684.412f, 16
 ) / 
@@ -2873,16 +2873,95 @@
  higher%0A
+    // for some reason the multiplier of 2 is needed (verified experimentally)%0A
     publ
@@ -3043,15 +3043,13 @@
 urn 
-(float)
+2.f *
  (fr
@@ -3057,27 +3057,123 @@
 q / 
-Math.pow(2,
+(1 %3C%3C (octaves - 1)));%0A    %7D%0A%0A    public static float maxValueMultipler(int octaves) %7B%0A        return (1 %3C%3C
  octaves
  - 1
@@ -3168,22 +3168,21 @@
  octaves
+)
  - 1
-))
 ;%0A    %7D%0A

Fix converting noise frequency from vanilla to flow noise