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

    const pools = [
        {
            rolls: 1,
            entries: [
                {item: 'eidolon:pewter_block', weight: 20},
                {item: 'emendatusenigmatica:aluminum_block', weight: 20},
                {item: 'emendatusenigmatica:cast_iron_block', weight: 10},
                {item: 'emendatusenigmatica:invar_block', weight: 10}
            ]
        },
        {
            rolls: 1,
            entries: [
                {item: 'bloodmagic:strong_tau'}
            ]
        },
        {
            rolls: [0,2],
            entries: [
                {item: 'bloodmagic:reinforcedslate', weight: 40, count: [2,4]},
                {item: 'bloodmagic:infusedslate', weight: 20, count: [1,2]},
                {item: 'bloodmagic:reagentvoid', weight: 5},
                {item: 'bloodmagic:reagentfastminer', weight: 5},
                {item: 'bloodmagic:reagentsight', weight: 5},
                {item: 'bloodmagic:reagentholding', weight: 5},
                {item: 'bloodmagic:melee_anointment_l', weight: 5},
                {item: 'bloodmagic:silk_touch_anointment_l', weight: 5},
                {item: 'bloodmagic:fortune_anointment_l', weight: 5},
                {item: 'bloodmagic:holy_water_anointment_l', weight: 5},
                {item: 'bloodmagic:hidden_knowledge_anointment_l', weight: 5},
                {item: 'bloodmagic:quick_draw_anointment_l', weight: 5},
                {item: 'bloodmagic:looting_anointment_l', weight: 5},
                {item: 'bloodmagic:bow_power_anointment_l', weight: 5},
                {item: 'bloodmagic:smelting_anointment_l', weight: 5},
                {item: 'bloodmagic:bow_velocity_anointment_l', weight: 5},
                {item: 'bloodmagic:masterroutingnode', weight: 1}
            ]
        },
        {
            rolls: [0,1],
            entries: [
                {item: 'bloodmagic:basemonstersoul', nbt: '{souls:11.4d}', weight: 10},
                {item: 'bloodmagic:basemonstersoul', nbt: '{souls:18.3d}', weight: 10},
                {type: 'minecraft:empty', weight: 20}
            ]
        },
        {
            rolls: [0,1],
            entries: [
                {item: 'eidolon:lesser_soul_gem', weight: 20, count: [1,2]},
                {item: 'eidolon:shadow_gem', weight: 20, count: [1,2]},
                {item: 'eidolon:wicked_weave', weight: 20, count: [1,2]},
                {item: 'naturesaura:token_joy', weight: 5},
                {item: 'naturesaura:token_fear', weight: 5},
                {item: 'naturesaura:token_anger', weight: 5},
                {item: 'naturesaura:token_sorrow', weight: 5},
                {type: 'minecraft:empty', weight: 20}
            ]
        }
    ];

    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('kubejs:loot_tables/chests/bloodmagic/dungeon_rare.json', loot_table);
});