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

    const pools = [
        {
            rolls: 4,
            entries: [
                {item: 'atum:nebu_ingot', weight: 40, count: [2,4]},
                {item: 'kubejs:holy_ingot', weight: 40, count: [2,4]},
                {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: 'eidolon:arcane_gold_block', weight: 10, count: [2,4]},
                {item: 'naturesaura:tainted_gold_block', weight: 10, count: [2,4]},
                {item: 'emendatusenigmatica:bronze_block', weight: 20, count: [2,4]},
                {item: 'emendatusenigmatica:brass_block', weight: 20, count: [2,4]},
                {item: 'emendatusenigmatica:constantan_block', weight: 20, count: [2,4]},
            ]
        },
        {
            rolls: [1,3],
            entries: [
                {item: 'eidolon:gold_inlay', weight: 10, count: [1,3]},
                {item: 'eidolon:lesser_soul_gem', weight: 10, count: [1,3]},
                {item: 'eidolon:shadow_gem', weight: 5, count: [1,3]},
                {item: 'create:blaze_cake', weight: 10, count: [1,3]},
                {item: 'create:rose_quartz', weight: 10, count: [2,4]},
                {item: 'create:chromatic_compound', weight: 5, count: [1,3]},
                {item: 'naturesaura:token_joy', weight: 5, count: [1,3]},
                {item: 'naturesaura:token_fear', weight: 5, count: [1,3]},
                {item: 'naturesaura:token_anger', weight: 5, count: [1,3]},
                {item: 'naturesaura:token_sorrow', weight: 5, count: [1,3]},
                {item: 'shrink:mob_bottle', nbt: '{entity:\"alexsmobs:sunbird\"}', weight: 2}
            ]
        },
        {
            rolls: [2,4],
            entries: [
                {item: 'atum:iron_dagger', enchant: [40,50], weight: 10},
                {item: 'atum:dagger_poison', enchant: [40,50], weight: 10},
                {item: 'atum:iron_greatsword', enchant: [40,50], weight: 10},
                {item: 'atum:iron_club', enchant: [40,50], weight: 10},
                {item: 'atum:iron_khopesh', enchant: [40,50], weight: 10},
                {item: 'atum:desert_helmet_iron', enchant: [40,50], weight: 10},
                {item: 'atum:desert_chest_iron', enchant: [40,50], weight: 10},
                {item: 'atum:desert_legs_iron', enchant: [40,50], weight: 10},
                {item: 'atum:desert_boots_iron', enchant: [40,50], weight: 10},
                {item: 'atum:desert_wolf_iron_armor', weight: 5},
                {item: 'atum:camel_iron_armor', weight: 5},
                {item: 'minecraft:diamond_sword', enchant: [25,30], weight: 5},
                {item: 'minecraft:diamond_axe', enchant: [25,30], weight: 5},
                {item: 'naturesaura:sky_sword', enchant: [25,30], weight: 5},
                {item: 'naturesaura:sky_axe', enchant: [25,30], weight: 5},
                {item: 'atum:desert_helmet_diamond', enchant: [25,30], weight: 4},
                {item: 'atum:desert_chest_diamond', enchant: [25,30], weight: 4},
                {item: 'atum:desert_legs_diamond', enchant: [25,30], weight: 4},
                {item: 'atum:desert_boots_diamond', enchant: [25,30], 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);
});