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

    const pools = [
        {
            rolls: 1,
            entries: [
                { type: 'bloodmagic:loot_table', item: 'atum:chests/crate', weight: 10 },
                { type: 'bloodmagic:loot_table', item: 'kubejs:chests/bloodmagic/dungeon_common', weight: 10 },
                { type: 'bloodmagic:loot_table', item: 'atum:chests/pyramid_chest', weight: 10 },
                { type: 'bloodmagic:loot_table', item: 'kubejs:chests/bloodmagic/dungeon_rare', weight: 10 }
            ]
        },
        {
            rolls: [0,1],
            entries: [
                {item: 'astralsorcery:constellation_paper', weight: 10},
                {item: 'astralsorcery:perk_seal', weight: 10},
                {item: 'occultism:familiar_ring', weight: 10},
                {item: 'immersiveengineering:skyhook', weight: 10},
                {item: 'immersiveengineering:maintenance_kit', weight: 10},
                {item: 'immersiveengineering:rockcutter', weight: 10},
                {item: 'immersiveengineering:drillhead_steel', weight: 10},
                {item: 'pedestals:upgradespeed', weight: 5},
                {item: 'pedestals:upgradecapacity', weight: 5},
                {item: 'pedestals:upgraderange', weight: 5},
            ]
        },
        {
            rolls: [1,2],
            entries: [
                {item: 'jaept:holy_ingot', weight: 10, count: [2,4]},
                {item: 'integrateddynamics:crystalized_chorus_chunk', weight: 10, count: [2,4]},
                {item: 'emendatusenigmatica:signalum_ingot', weight: 20, count: [2,4]},
                {item: 'emendatusenigmatica:lumium_ingot', weight: 20, count: [2,4]},
                {item: 'emendatusenigmatica:enderium_ingot', weight: 20, count: [2,4]}
            ]
        },
        {
            rolls: [0,1],
            entries: [
                {item: 'minecraft:ender_pearl', weight: 20, count: [2,4]},
                {item: 'tconstruct:ender_slime_ball', weight: 20, count: [2,4]},
                {item: 'alexsmobs:mimicream', weight: 20, count: [1,2]},
                {item: 'minecraft:shulker_shell', weight: 20, count: [1,2]},
                {item: 'occultism:soul_gem', nbt: '{entityData:{id:\"alexsmobs:spectre\"}}', weight: 5},
                {item: 'occultism:soul_gem', nbt: '{entityData:{id:\"alexsmobs:endergrade\"}}', weight: 5}
            ]
        },
        {
            rolls: [1,2],
            entries: [
                {item: 'immersiveengineering:pickaxe_steel', enchant: [50,70], weight: 10},
                {item: 'immersiveengineering:shovel_steel', enchant: [50,70], weight: 10},
                {item: 'immersiveengineering:axe_steel', enchant: [50,70], weight: 10},
                {item: 'immersiveengineering:hoe_steel', enchant: [50,70], weight: 10},
                {item: 'immersiveengineering:sword_steel', enchant: [50,70], weight: 10},
                {item: 'immersiveengineering:shield', enchant: [50,70], weight: 10},
                {item: 'immersiveengineering:armor_steel_head', enchant: [50,70], weight: 10},
                {item: 'immersiveengineering:armor_steel_chest', enchant: [50,70], weight: 10},
                {item: 'immersiveengineering:armor_steel_legs', enchant: [50,70], weight: 10},
                {item: 'immersiveengineering:armor_steel_feet', enchant: [50,70], weight: 10},
                {item: 'minecraft:netherite_sword', enchant: [30,50], weight: 2},
                {item: 'minecraft:netherite_shovel', enchant: [30,50], weight: 2},
                {item: 'minecraft:netherite_axe', enchant: [30,50], weight: 2},
                {item: 'minecraft:netherite_hoe', enchant: [30,50], weight: 2},
                {item: 'minecraft:netherite_pickaxe', enchant: [30,50], weight: 2},
                {item: 'farmersdelight:netherite_knife', enchant: [30,50], weight: 2},
                {item: 'minecraft:netherite_helmet', enchant: [30,50], weight: 2},
                {item: 'minecraft:netherite_chestplate', enchant: [30,50], weight: 2},
                {item: 'minecraft:netherite_leggings', enchant: [30,50], weight: 2},
                {item: 'minecraft:netherite_boots', enchant: [30,50], weight: 2},
            ]
        },
        {
            rolls: [0,1],
            entries: [
                {item: 'astralsorcery:rock_crystal', weight: 9},
                {item: 'astralsorcery:celestial_crystal', 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('minecraft:loot_tables/chests/end_city_treasure.json', loot_table);
});