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

    const pools = [
        {
            rolls: [2,4],
            entries: [
                {item: 'atum:nebu_drop', weight: 20, count: [2,4]},
                {item: 'jaopca:nuggets.holy', weight: 20, count: [2,4]},
                {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: 5},
                {item: 'atum:golden_date_enchanted', weight: 1}
            ]
        },
        {
            rolls: [2,4],
            entries: [
                {item: 'eidolon:arcane_gold_ingot', weight: 10, count: [2,4]},
                {item: 'naturesaura:tainted_gold', weight: 10, count: [2,4]},
                {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:wolf_pelt', weight: 20, count: [1,3]},
                {item: 'atum:mandibles', weight: 20, count: [1,2]},
                {item: 'atum:quail_egg', weight: 20, count: [1,2]},
                {item: 'atum:crunchy_scarab', weight: 20, count: [1,3]},
                {item: 'atum:crunchy_golden_scarab', weight: 5},
                {item: 'shrink:mob_bottle', nbt: '{entity:\"alexsmobs:komodo_dragon\"}', weight: 5}
            ]
        },
        {
            rolls: [1,2],
            entries: [
                {item: 'atum:iron_dagger', enchant: [35,45], weight: 10},
                {item: 'atum:dagger_poison', enchant: [35,45], weight: 10},
                {item: 'atum:iron_greatsword', enchant: [35,45], weight: 10},
                {item: 'atum:iron_club', enchant: [35,45], weight: 10},
                {item: 'atum:iron_khopesh', enchant: [35,45], weight: 10},
                {item: 'atum:desert_helmet_iron', enchant: [35,45], weight: 10},
                {item: 'atum:desert_chest_iron', enchant: [35,45], weight: 10},
                {item: 'atum:desert_legs_iron', enchant: [35,45], weight: 10},
                {item: 'atum:desert_boots_iron', enchant: [35,45], weight: 10},
                {item: 'atum:desert_wolf_iron_armor', weight: 5},
                {item: 'atum:camel_iron_armor', weight: 5},
                {item: 'minecraft:diamond_sword', enchant: [20,25], weight: 2},
                {item: 'minecraft:diamond_axe', enchant: [20,25], weight: 2},
                {item: 'naturesaura:sky_sword', enchant: [20,25], weight: 2},
                {item: 'naturesaura:sky_axe', enchant: [20,25], weight: 2},
                {item: 'atum:desert_helmet_diamond', enchant: [20,25], weight: 2},
                {item: 'atum:desert_chest_diamond', enchant: [20,25], weight: 2},
                {item: 'atum:desert_legs_diamond', enchant: [20,25], weight: 2},
                {item: 'atum:desert_boots_diamond', enchant: [20,25], weight: 2},
                {item: 'atum:desert_wolf_diamond_armor', weight: 1},
                {item: 'atum:camel_diamond_armor', weight: 1}
            ]
        },
        {
            rolls: 1,
            entries: [
                {item: 'atum:sand', weight: 1, count: [8,16]}
            ]
        }
    ];

    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/tomb.json', loot_table);
});