//short names for collections of biome_tags that should be valid for the biome
const BIOMETAGGROUPS = {
    grass: {
        any_of: [
            "plains",
            "meadow"
        ]
    },
    sand: {
        any_of: [
            "desert"
        ],
        none_of: [
            "hills"
        ]
    },
    snow: {
        any_of: [
            "ice_plains",
            "snowy_slopes"
        ],
        none_of: [
            "hills",
            "mutated"
        ]
    }
};
const STRUCTURES = [];
/**
 * List of ores and their spawn rules
 * @param {string} block The block ID to place
 * @param {number} tries Number of attempts to seed this ore
 * @param {number} 0.0-1.0 chance for the try to succeed
 * @param {number} min_size The smallest amount of blocks to place in the vein
 * @param {number} max_size The largest amount of blocks to place in the vein
 * @param {number} max_height The highest point in the chunk to seed the vein
 * @param {number} min_height The lowest point in the chunk to seed the vein
 * @param {number} height_offset -0.5-0.5 the point in the height range from the center to spawn with highest frequency
 * @param {number} distribution_fallof How sharp the dropoff of spawn range from the center. 1 is even distribution
 */ export const ORES_OVERWORLD = [
    {
        block: "wonder_ores:cobalt_ore",
        tries: 10,
        weight: 0.8,
        min_size: 3,
        max_size: 9,
        min_height: 0,
        max_height: 128,
        height_offset: -0.3,
        distribution_falloff: 3,
        deepslate_variant: true
    },
    {
        block: "wonder_ores:zinc_ore",
        tries: 8,
        weight: 0.8,
        min_size: 7,
        max_size: 15,
        min_height: 0,
        max_height: 128,
        height_offset: -0.2,
        distribution_falloff: 2,
        deepslate_variant: true
    },
    {
        block: "wonder_ores:lead_ore",
        tries: 10,
        weight: 0.9,
        min_size: 3,
        max_size: 9,
        min_height: 0,
        max_height: 128,
        height_offset: -0.3,
        distribution_falloff: 3,
        deepslate_variant: true
    },
    {
        block: "wonder_ores:silver_ore",
        tries: 10,
        weight: 0.8,
        min_size: 3,
        max_size: 10,
        min_height: -50,
        max_height: 64,
        height_offset: -0.3,
        distribution_falloff: 2,
        deepslate_variant: true
    },
    {
        block: "wonder_ores:lithium_ore",
        tries: 5,
        weight: 0.9,
        min_size: 5,
        max_size: 15,
        min_height: -50,
        max_height: 64,
        height_offset: -0.2,
        distribution_falloff: 3,
        deepslate_variant: true
    },
    {
        block: "wonder_ores:sulfur_ore",
        tries: 4,
        weight: 0.7,
        min_size: 8,
        max_size: 20,
        min_height: -50,
        max_height: 64,
        height_offset: 0.2,
        distribution_falloff: 3,
        deepslate_variant: true
    },
    {
        block: "wonder_ores:platinum_ore",
        tries: 5,
        weight: 0.8,
        min_size: 3,
        max_size: 10,
        min_height: -55,
        max_height: 10,
        height_offset: 0.4,
        distribution_falloff: 2,
        deepslate_variant: true
    },
    {
        block: "wonder_ores:titanium_ore",
        tries: 5,
        weight: 0.8,
        min_size: 4,
        max_size: 9,
        min_height: -55,
        max_height: 10,
        height_offset: 0.4,
        distribution_falloff: 2,
        deepslate_variant: true
    },
    {
        block: "wonder_ores:uranium_ore",
        tries: 6,
        weight: 0.5,
        min_size: 1,
        max_size: 5,
        min_height: -55,
        max_height: 0,
        height_offset: -0.4,
        distribution_falloff: 3,
        deepslate_variant: true
    },
    {
        block: "wonder_ores:bedrock_ore",
        tries: 6,
        weight: 0.5,
        min_size: 1,
        max_size: 2,
        min_height: -64,
        max_height: -60,
        height_offset: 0,
        distribution_falloff: 1,
        deepslate_variant: true
    },
    {
        block: "wonder_ores:flame_ore",
        tries: 25,
        weight: 1,
        min_size: 10,
        max_size: 30,
        min_height: -60,
        max_height: 70,
        height_offset: 0,
        distribution_falloff: 1,
        deepslate_variant: true
    },
    {
        block: "wonder_ores:rainbow_ore",
        tries: 5,
        weight: 0.6,
        min_size: 1,
        max_size: 4,
        min_height: -60,
        max_height: -32,
        height_offset: 0.2,
        distribution_falloff: 2,
        deepslate_variant: true
    },
    {
        block: "wonder_ores:ruby_ore",
        tries: 5,
        weight: 0.6,
        min_size: 2,
        max_size: 5,
        min_height: -60,
        max_height: 32,
        height_offset: 0.1,
        distribution_falloff: 2,
        deepslate_variant: true
    },
    {
        block: "wonder_ores:sapphire_ore",
        tries: 5,
        weight: 0.6,
        min_size: 2,
        max_size: 5,
        min_height: -60,
        max_height: 32,
        height_offset: 0.1,
        distribution_falloff: 2,
        deepslate_variant: true
    },
    {
        block: "wonder_ores:volcanic_rock",
        tries: 20,
        weight: 1,
        min_size: 15,
        max_size: 30,
        min_height: -60,
        max_height: 70,
        height_offset: 0,
        distribution_falloff: 1,
        deepslate_variant: false
    },
    {
        block: "wonder_ores:marble",
        tries: 5,
        weight: 0.6,
        min_size: 15,
        max_size: 30,
        min_height: 0,
        max_height: 120,
        height_offset: 0,
        distribution_falloff: 1,
        deepslate_variant: false
    },
    {
        block: "wonder_ores:flint",
        tries: 5,
        weight: 0.6,
        min_size: 15,
        max_size: 30,
        min_height: -60,
        max_height: 120,
        height_offset: 0,
        distribution_falloff: 1,
        deepslate_variant: false
    },
    {
        block: "wonder_ores:graphite",
        tries: 5,
        weight: 0.6,
        min_size: 15,
        max_size: 30,
        min_height: 0,
        max_height: 120,
        height_offset: 0,
        distribution_falloff: 1,
        deepslate_variant: false
    },
    {
        block: "wonder_ores:limestone",
        tries: 5,
        weight: 0.6,
        min_size: 15,
        max_size: 30,
        min_height: 0,
        max_height: 120,
        height_offset: 0,
        distribution_falloff: 1,
        deepslate_variant: false
    },
    {
        block: "wonder_ores:rock_salt",
        tries: 5,
        weight: 0.5,
        min_size: 15,
        max_size: 30,
        min_height: 0,
        max_height: 120,
        height_offset: 0,
        distribution_falloff: 1,
        deepslate_variant: false
    },
    {
        block: "wonder_ores:graphite",
        tries: 5,
        weight: 0.6,
        min_size: 15,
        max_size: 30,
        min_height: -60,
        max_height: 120,
        height_offset: 0,
        distribution_falloff: 1,
        deepslate_variant: false
    },
    {
        block: "wonder_ores:slate",
        tries: 5,
        weight: 0.5,
        min_size: 15,
        max_size: 30,
        min_height: -60,
        max_height: 120,
        height_offset: 0,
        distribution_falloff: 1,
        deepslate_variant: false
    }
];
export const ORES_NETHER = [
    {
        block: "wonder_ores:cobalt_ore_nether",
        tries: 7,
        weight: 0.8,
        min_size: 3,
        max_size: 9,
        min_height: 64,
        max_height: 120,
        height_offset: -0.3,
        distribution_falloff: 3
    },
    {
        block: "wonder_ores:zinc_ore_nether",
        tries: 5,
        weight: 0.8,
        min_size: 7,
        max_size: 15,
        min_height: 64,
        max_height: 120,
        height_offset: -0.2,
        distribution_falloff: 2
    },
    {
        block: "wonder_ores:lead_ore_nether",
        tries: 7,
        weight: 0.9,
        min_size: 3,
        max_size: 9,
        min_height: 64,
        max_height: 120,
        height_offset: -0.3,
        distribution_falloff: 3
    },
    {
        block: "wonder_ores:silver_ore_nether",
        tries: 7,
        weight: 0.8,
        min_size: 3,
        max_size: 10,
        min_height: 32,
        max_height: 64,
        height_offset: -0.3,
        distribution_falloff: 2
    },
    {
        block: "wonder_ores:lithium_ore_nether",
        tries: 7,
        weight: 0.9,
        min_size: 5,
        max_size: 15,
        min_height: 32,
        max_height: 64,
        height_offset: -0.2,
        distribution_falloff: 3
    },
    {
        block: "wonder_ores:sulfur_ore_nether",
        tries: 4,
        weight: 0.7,
        min_size: 8,
        max_size: 20,
        min_height: 32,
        max_height: 64,
        height_offset: 0.2,
        distribution_falloff: 3
    },
    {
        block: "wonder_ores:platinum_ore_nether",
        tries: 5,
        weight: 0.8,
        min_size: 3,
        max_size: 10,
        min_height: 0,
        max_height: 32,
        height_offset: 0.4,
        distribution_falloff: 2
    },
    {
        block: "wonder_ores:titanium_ore_nether",
        tries: 5,
        weight: 0.8,
        min_size: 4,
        max_size: 9,
        min_height: 0,
        max_height: 32,
        height_offset: 0.4,
        distribution_falloff: 2
    },
    {
        block: "wonder_ores:uranium_ore_nether",
        tries: 3,
        weight: 0.5,
        min_size: 1,
        max_size: 5,
        min_height: 0,
        max_height: 15,
        height_offset: 0.4,
        distribution_falloff: 3
    },
    {
        block: "wonder_ores:bedrock_ore_nether",
        tries: 6,
        weight: 0.8,
        min_size: 1,
        max_size: 3,
        min_height: 0,
        max_height: 5,
        height_offset: 0,
        distribution_falloff: 1
    },
    {
        block: "wonder_ores:bedrock_ore_nether",
        tries: 5,
        weight: 0.5,
        min_size: 1,
        max_size: 2,
        min_height: 115,
        max_height: 120,
        height_offset: 0,
        distribution_falloff: 1
    },
    {
        block: "wonder_ores:flame_ore_nether",
        tries: 10,
        weight: 1,
        min_size: 5,
        max_size: 20,
        min_height: 0,
        max_height: 100,
        height_offset: 0,
        distribution_falloff: 1
    },
    {
        block: "wonder_ores:rainbow_ore_nether",
        tries: 5,
        weight: 0.6,
        min_size: 1,
        max_size: 4,
        min_height: 0,
        max_height: 120,
        height_offset: 0.1,
        distribution_falloff: 3
    },
    {
        block: "wonder_ores:ruby_ore_nether",
        tries: 5,
        weight: 0.6,
        min_size: 2,
        max_size: 5,
        min_height: 0,
        max_height: 120,
        height_offset: 0.1,
        distribution_falloff: 3
    },
    {
        block: "wonder_ores:sapphire_ore_nether",
        tries: 5,
        weight: 0.6,
        min_size: 2,
        max_size: 5,
        min_height: 0,
        max_height: 120,
        height_offset: 0.1,
        distribution_falloff: 3
    },
    {
        block: "wonder_ores:volcanic_rock",
        tries: 15,
        weight: 1,
        min_size: 15,
        max_size: 30,
        min_height: 0,
        max_height: 100,
        height_offset: 0,
        distribution_falloff: 1
    }
];
export const ORES_END = [
    {
        block: "wonder_ores:cobalt_ore_end",
        tries: 5,
        weight: 0.7,
        min_size: 3,
        max_size: 9,
        min_height: 10,
        max_height: 70,
        height_offset: 0.3,
        distribution_falloff: 3
    },
    {
        block: "wonder_ores:zinc_ore_end",
        tries: 5,
        weight: 0.8,
        min_size: 7,
        max_size: 15,
        min_height: 10,
        max_height: 70,
        height_offset: 0.2,
        distribution_falloff: 2
    },
    {
        block: "wonder_ores:lead_ore_end",
        tries: 2,
        weight: 0.9,
        min_size: 3,
        max_size: 9,
        min_height: 10,
        max_height: 70,
        height_offset: 0.3,
        distribution_falloff: 3
    },
    {
        block: "wonder_ores:silver_ore_end",
        tries: 4,
        weight: 0.8,
        min_size: 3,
        max_size: 10,
        min_height: 10,
        max_height: 32,
        height_offset: 0.2,
        distribution_falloff: 2
    },
    {
        block: "wonder_ores:lithium_ore_end",
        tries: 3,
        weight: 0.9,
        min_size: 5,
        max_size: 15,
        min_height: 10,
        max_height: 32,
        height_offset: -0.2,
        distribution_falloff: 3
    },
    {
        block: "wonder_ores:sulfur_ore_end",
        tries: 4,
        weight: 0.7,
        min_size: 8,
        max_size: 20,
        min_height: 10,
        max_height: 32,
        height_offset: 0.2,
        distribution_falloff: 3
    },
    {
        block: "wonder_ores:platinum_ore_end",
        tries: 3,
        weight: 0.8,
        min_size: 3,
        max_size: 10,
        min_height: 10,
        max_height: 32,
        height_offset: -0.3,
        distribution_falloff: 2
    },
    {
        block: "wonder_ores:titanium_ore_end",
        tries: 3,
        weight: 0.8,
        min_size: 4,
        max_size: 9,
        min_height: 10,
        max_height: 32,
        height_offset: -0.4,
        distribution_falloff: 2
    },
    {
        block: "wonder_ores:uranium_ore_end",
        tries: 3,
        weight: 0.5,
        min_size: 1,
        max_size: 3,
        min_height: 10,
        max_height: 16,
        height_offset: 0.4,
        distribution_falloff: 3
    },
    {
        block: "wonder_ores:rainbow_ore_end",
        tries: 5,
        weight: 0.6,
        min_size: 1,
        max_size: 4,
        min_height: 10,
        max_height: 50,
        height_offset: 0.1,
        distribution_falloff: 3
    },
    {
        block: "wonder_ores:ruby_ore_end",
        tries: 5,
        weight: 0.6,
        min_size: 2,
        max_size: 5,
        min_height: 10,
        max_height: 50,
        height_offset: 0.1,
        distribution_falloff: 3
    },
    {
        block: "wonder_ores:sapphire_ore_end",
        tries: 5,
        weight: 0.6,
        min_size: 2,
        max_size: 5,
        min_height: 10,
        max_height: 50,
        height_offset: 0.1,
        distribution_falloff: 3
    }
];
/**
 * Return a random number weighted towards 0.5
 * @param {number} offset A number between -0.5 and 0.5 to shift the peak of the curve towards
 */ export function guassianRand(offset, falloff) {
    if (offset == undefined) offset = 0;
    if (falloff == undefined) falloff = 2;
    var res = 0;
    var i = falloff;
    while(i--)res += Math.max(0, Math.min(1, Math.random() + offset));
    return res / falloff;
}
/**
* A JSON object with a list of structures and rules about their spawning
* @param {Array[string]} biomeTags a list of biome tags the entity has
* @return {path, chunkSize} path The path to the structure file
*/ export function rollStructure(biomeTags) {
    //build the list of biometaggroups and whether they are valid
    var validBiomeTagGroups = {};
    var chosenBiomeGroup = "none";
    for(var key in BIOMETAGGROUPS){
        validBiomeTagGroups[key] = {};
        validBiomeTagGroups[key].valid = undefined;
    }
    //work out which biometagroup we are in
    for(var key in validBiomeTagGroups){
        for (var biomeTag of biomeTags){
            var tag = biomeTag.replace("biometag_", "");
            if (BIOMETAGGROUPS[key].any_of != undefined && BIOMETAGGROUPS[key].any_of.includes(tag) && validBiomeTagGroups[key].valid != false) {
                validBiomeTagGroups[key].valid = true;
            }
            if (BIOMETAGGROUPS[key].none_of != undefined && BIOMETAGGROUPS[key].none_of.includes(tag)) {
                validBiomeTagGroups[key].valid = false;
                break;
            }
        }
        //if the group is valid, use it
        if (validBiomeTagGroups[key].valid) {
            chosenBiomeGroup = key;
            //once a valid group is found, don't check the rest
            var structurePool = [];
            var totalWeights = 0;
            for (var structure of STRUCTURES){
                if (structure["biomeGroup"] == chosenBiomeGroup) {
                    structurePool.push({
                        path: structure["path"],
                        min: totalWeights + 1,
                        max: totalWeights + structure["weight"],
                        yOffset: -structure["yOffset"],
                        footprint: structure["footprint"]
                    });
                    totalWeights += structure["weight"];
                }
            }
            var roll = Math.round(Math.random() * totalWeights) + 1;
            for (var structure of structurePool){
                if (roll >= structure["min"] && roll <= structure["max"]) {
                    var obj = {
                        path: structure["path"],
                        footprint: structure["footprint"],
                        yOffset: -structure["yOffset"]
                    };
                    return obj;
                }
            }
            break;
        }
    }
    var obj = {
        path: "",
        footprint: [
            0,
            0
        ],
        yOffset: -0
    };
    return obj;
}
