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

    const pools = [
        {
            rolls: 4,
            entries: [
                {item: 'atum:coin_dirty', weight: 100, count: [1,5]},
                {item: 'atum:relic_dirty_ring', weight: 100, count: [1,3]},
                {item: 'atum:relic_dirty_necklace', weight: 50, count: [1,3]},
                {item: 'atum:relic_dirty_brooch', weight: 40, count: [1,3]},
                {item: 'atum:relic_dirty_bracelet', weight: 30, count: [1,2]},
                {item: 'atum:relic_dirty_idol', weight: 15, count: [1,2]},
                {item: 'atum:date', weight: 45, count: [1,8]},
                {item: 'atum:golden_date', weight: 10, count: [1,2]},
                {item: 'atum:golden_date_enchanted', weight: 1}
            ]
        },
        {
            rolls: [1,3],
            entries: [
                {item: 'atum:nebu_ingot', weight: 10, count: [2,6]},
                {item: 'emendatusenigmatica:bronze_ingot', weight: 20, count: [2,6]},
                {item: 'emendatusenigmatica:brass_ingot', weight: 20, count: [2,6]},
                {item: 'emendatusenigmatica:constantan_ingot', weight: 20, count: [2,6]},
                {item: 'create:rose_quartz', weight: 10, count: [1,4]},
                {item: 'create:chromatic_compound', weight: 5},
                {item: 'kubejs:holy_ingot', weight: 10, count: [1,4]}
            ]
        },
        {
            rolls: [1,3],
            entries: [
                {item: 'bloodmagic:reagentwater', weight: 5},
                {item: 'bloodmagic:reagentlava', weight: 5},
                {item: 'bloodmagic:reagentgrowth', weight: 5},
                {item: 'bloodmagic:reagentair', weight: 5},
                {item: 'bloodmagic:melee_anointment', weight: 4},
                {item: 'bloodmagic:holy_water_anointment', weight: 4},
                {item: 'bloodmagic:quick_draw_anointment', weight: 4},
                {item: 'bloodmagic:bow_power_anointment', weight: 4},
                {item: 'bloodmagic:bow_velocity_anointment', weight: 4},
                {item: 'bloodmagic:basemonstersoul', nbt: '{souls:4.8d}', weight: 4},
                {item: 'bloodmagic:basemonstersoul', nbt: '{souls:9.4d}', weight: 3},
                {item: 'bloodmagic:basemonstersoul', nbt: '{souls:11.4d}', weight: 2},
                {item: 'bloodmagic:basemonstersoul', nbt: '{souls:18.3d}', weight: 1},
                {item: 'create:blaze_cake', weight: 10, count: [1,3]},
                {item: 'naturesaura:effect_powder', nbt:'{effect:\"naturesaura:plant_boost\"}', weight: 5, count: [8,16]},
                {item: 'naturesaura:effect_powder', nbt:'{effect:\"naturesaura:nether_grass\"}', weight: 5, count: [8,16]},
                {item: 'naturesaura:token_joy', weight: 5, count: [1,2]},
                {item: 'naturesaura:token_fear', weight: 5, count: [1,2]},
                {item: 'naturesaura:token_anger', weight: 5, count: [1,2]},
                {item: 'naturesaura:token_sorrow', weight: 5, count: [1,2]},
                {item: 'shrink:mob_bottle', nbt: '{entity:\"alexsmobs:sunbird\"}', weight: 2}
            ]
        },
        {
            rolls: [1,2],
            entries: [
                {item: 'atum:iron_dagger', enchant: [60,80], weight: 10},
                {item: 'atum:dagger_poison', enchant: [60,80], weight: 10},
                {item: 'atum:iron_greatsword', enchant: [60,80], weight: 10},
                {item: 'atum:iron_club', enchant: [60,80], weight: 10},
                {item: 'atum:iron_khopesh', enchant: [60,80], weight: 10},
                {item: 'atum:desert_helmet_iron', enchant: [60,80], weight: 10},
                {item: 'atum:desert_chest_iron', enchant: [60,80], weight: 10},
                {item: 'atum:desert_legs_iron', enchant: [60,80], weight: 10},
                {item: 'atum:desert_boots_iron', enchant: [60,80], weight: 10},
                {item: 'atum:desert_wolf_iron_armor', weight: 5},
                {item: 'atum:camel_iron_armor', weight: 5},
                {item: 'minecraft:diamond_sword', enchant: [30,60], weight: 5},
                {item: 'minecraft:diamond_axe', enchant: [30,60], weight: 5},
                {item: 'naturesaura:sky_sword', enchant: [30,60], weight: 5},
                {item: 'naturesaura:sky_axe', enchant: [30,60], weight: 5},
                {item: 'atum:desert_helmet_diamond', enchant: [30,60], weight: 4},
                {item: 'atum:desert_chest_diamond', enchant: [30,60], weight: 4},
                {item: 'atum:desert_legs_diamond', enchant: [30,60], weight: 4},
                {item: 'atum:desert_boots_diamond', enchant: [30,60], weight: 4},
                {item: 'atum:desert_wolf_diamond_armor', weight: 2},
                {item: 'atum:camel_diamond_armor', weight: 2},
                {type: 'loot_table', item: 'atum:gods/all', weight: 1}
            ]
        },
        {
            rolls: 1,
            entries: [
                {item: 'atum:sand', weight: 1, count: [16,32]}
            ]
        },
        {
            rolls: 1,
            entries: [
                {item: 'atum:efreet_heart', weight: 1}
            ]
        }
    ];

    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});
            }
            entryJson.name = entry.item;
            entriesJson.push(entryJson);
        });
        poolJson.entries = entriesJson;
        loot_table.pools.push(poolJson);
    });

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