onEvent('server.datapack.high_priority', (event) => {

    const pools = [
        {
            rolls: [1,2],
            entries: [
                {item: 'atum:coin_dirty', weight: 45, count: [1,3]},
                {item: 'atum:relic_dirty_ring', weight: 20},
                {item: 'atum:relic_dirty_necklace', weight: 15},
                {item: 'atum:relic_dirty_brooch', weight: 10},
                {item: 'atum:relic_dirty_bracelet', weight: 5},
                {item: 'atum:relic_dirty_idol', weight: 1},
                {item: 'atum:date', weight: 45, count: [1,2]},
                {item: 'atum:golden_date', weight: 1},
                {item: 'minecraft:map', map: 'atum:pyramid', weight: 15}
            ]
        },
        {
            rolls: [1,2],
            entries: [
                {item: 'emendatusenigmatica:bronze_ingot', weight: 20, count: [2,4]},
                {item: 'emendatusenigmatica:brass_ingot', weight: 20, count: [2,4]},
                {item: 'emendatusenigmatica:constantan_ingot', weight: 20, count: [2,4]}
            ]
        },
        {
            rolls: [1,2],
            entries: [
                {item: 'minecraft:rabbit_hide', weight: 20, count: [1,3]},
                {item: 'atum:dusty_bone', weight: 20, count: [1,3]},
                {item: 'atum:cloth_scrap', weight: 20, count: [1,2]},
                {item: 'atum:crunchy_scarab', weight: 20, count: [1,3]},
                {item: 'shrink:mob_bottle', nbt: '{entity:\"alexsmobs:emu\"}', weight: 5}
            ]
        },
        {
            rolls: [0,1],
            entries: [
                {item: 'atum:flax_seeds', weight: 20, count: [1,3]},
                {item: 'atum:emmer_seeds', weight: 20, count: [1,3]},
                {item: 'occultism:datura_seeds', weight: 20, count: [1,3]},
                {item: 'atum:fertile_soil_pile', weight: 20, count: [1,4]},
                {item: 'immersiveengineering:seed', weight: 20, count: [1,3]}
            ]
        },
        {
            rolls: [0,1],
            entries: [
                {item: 'atum:iron_dagger', enchant: [10,30], weight: 10},
                {item: 'atum:dagger_poison', enchant: [10,30], weight: 10},
                {item: 'atum:iron_greatsword', enchant: [10,30], weight: 10},
                {item: 'atum:iron_club', enchant: [10,30], weight: 10},
                {item: 'atum:iron_khopesh', enchant: [10,30], weight: 10},
                {item: 'atum:desert_helmet_iron', enchant: [10,30], weight: 10},
                {item: 'atum:desert_chest_iron', enchant: [10,30], weight: 10},
                {item: 'atum:desert_legs_iron', enchant: [10,30], weight: 10},
                {item: 'atum:desert_boots_iron', enchant: [10,30], weight: 10},
                {item: 'minecraft:diamond_sword', weight: 2},
                {item: 'minecraft:diamond_axe', weight: 2},
                {item: 'naturesaura:sky_sword', weight: 2},
                {item: 'naturesaura:sky_axe', weight: 2},
                {item: 'atum:desert_helmet_diamond', weight: 2},
                {item: 'atum:desert_chest_diamond', weight: 2},
                {item: 'atum:desert_legs_diamond', weight: 2},
                {item: 'atum:desert_boots_diamond', weight: 2}
            ]
        },
        {
            rolls: 1,
            entries: [
                {item: 'atum:sand', weight: 1, count: [2,9]}
            ]
        }
    ];

    let loot_table = {
        type: 'minecraft:chest',
        pools: []
    };

    pools.forEach(pool => {
        let poolJson = {};
        poolJson.rolls = typeof pool.rolls === 'number'? pool.rolls : {min:pool.rolls[0],max:pool.rolls[1],type:'minecraft:uniform'};
        let entriesJson = [];
        pool.entries.forEach(entry => {
            let entryJson = {};
            entryJson.type = entry.type? entry.type : 'minecraft:item';
            entryJson.weight = entry.weight;
            entryJson.functions = [];
            if(entry.count){
                entryJson.functions.push({function:'minecraft:set_count',count:{min:entry.count[0],max:entry.count[1],type:'minecraft:uniform'}});
            }
            if(entry.enchant){
                entryJson.functions.push({function:'minecraft:enchant_with_levels',levels:{min:entry.enchant[0],max:entry.enchant[1]}});
            }
            if(entry.nbt){
                entryJson.functions.push({function:'minecraft:set_nbt',tag:entry.nbt});
            }
            if(entry.map){
                entryJson.functions.push({function:'minecraft:exploration_map',destination:entry.map,decoration:'red_x',zoom:1,skip_existing_chunks:false});
            }
            entryJson.name = entry.item;
            entriesJson.push(entryJson);
        });
        poolJson.entries = entriesJson;
        loot_table.pools.push(poolJson);
    });

    event.addJson('atum:loot_tables/chests/crate.json', loot_table);
});