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

    const pools = [
        {
            rolls: [1,2],
            entries: [
                {item: 'eidolon:pewter_block', weight: 20, count: [1,3]},
                {item: 'emendatusenigmatica:aluminum_block', weight: 20, count: [1,3]},
                {item: 'emendatusenigmatica:cast_iron_block', weight: 20, count: [1,3]},
                {item: 'emendatusenigmatica:invar_block', weight: 20, count: [1,3]}
            ]
        },
        {
            rolls: 1,
            entries: [
                {item: 'bloodmagic:strong_tau', count: [1,3]}
            ]
        },
        {
            rolls: [2,4],
            entries: [
                {item: 'bloodmagic:reinforcedslate', weight: 40, count: [3,6]},
                {item: 'bloodmagic:infusedslate', weight: 20, count: [2,4]},
                {item: 'bloodmagic:reagentvoid', weight: 5, count: [1,3]},
                {item: 'bloodmagic:reagentfastminer', weight: 5, count: [1,3]},
                {item: 'bloodmagic:reagentsight', weight: 5, count: [1,3]},
                {item: 'bloodmagic:reagentholding', weight: 5, count: [1,3]},
                {item: 'bloodmagic:melee_anointment_l', weight: 5, count: [1,3]},
                {item: 'bloodmagic:silk_touch_anointment_l', weight: 5, count: [1,3]},
                {item: 'bloodmagic:fortune_anointment_l', weight: 5, count: [1,3]},
                {item: 'bloodmagic:holy_water_anointment_l', weight: 5, count: [1,3]},
                {item: 'bloodmagic:hidden_knowledge_anointment_l', weight: 5, count: [1,3]},
                {item: 'bloodmagic:quick_draw_anointment_l', weight: 5, count: [1,3]},
                {item: 'bloodmagic:looting_anointment_l', weight: 5, count: [1,3]},
                {item: 'bloodmagic:bow_power_anointment_l', weight: 5, count: [1,3]},
                {item: 'bloodmagic:smelting_anointment_l', weight: 5, count: [1,3]},
                {item: 'bloodmagic:bow_velocity_anointment_l', weight: 5, count: [1,3]},
                {item: 'bloodmagic:masterroutingnode', weight: 5}
            ]
        },
        {
            rolls: [0,1],
            entries: [
                {item: 'bloodmagic:basemonstersoul', nbt: '{souls:11.4d}', weight: 10},
                {item: 'bloodmagic:basemonstersoul', nbt: '{souls:18.3d}', weight: 10},
                {item: 'bloodmagic:dungeon_stone', weight: 5, count: [1,3]}
            ]
        },
        {
            rolls: [1,2],
            entries: [
                {item: 'eidolon:lesser_soul_gem', weight: 10, count: [1,3]},
                {item: 'eidolon:shadow_gem', weight: 10, count: [1,3]},
                {item: 'eidolon:wicked_weave', weight: 10, 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: 'create:shadow_steel', weight: 5, count: [1,2]},
                {item: 'integrateddynamics:crystalized_chorus_chunk', weight: 5, count: [3,8]}
            ]
        }
    ];

    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);
});