onEvent('server.datapack.high_priority', (event) => {
    let loot_table = {
        pools: [
            {
                item: 'placebo_code_pool_15',
                rolls: {
                    min: 6.0,
                    max: 9.0,
                    type: 'minecraft:uniform'
                },
                entries: [
                    {
                        type: 'placebo:stack_entry',
                        weight: 5,
                        quality: 5,
                        min: 1,
                        max: 1,
                        stack: { item: 'apotheosis:null_book', count: 1 }
                    },
                    {
                        type: 'placebo:stack_entry',
                        weight: 5,
                        quality: 5,
                        min: 1,
                        max: 1,
                        stack: { item: 'apotheosis:armor_head_book', count: 1 }
                    },
                    {
                        type: 'placebo:stack_entry',
                        weight: 5,
                        quality: 5,
                        min: 1,
                        max: 1,
                        stack: { item: 'apotheosis:armor_chest_book', count: 1 }
                    },
                    {
                        type: 'placebo:stack_entry',
                        weight: 5,
                        quality: 5,
                        min: 1,
                        max: 1,
                        stack: { item: 'apotheosis:armor_legs_book', count: 1 }
                    },
                    {
                        type: 'placebo:stack_entry',
                        weight: 5,
                        quality: 5,
                        min: 1,
                        max: 1,
                        stack: { item: 'apotheosis:armor_feet_book', count: 1 }
                    },
                    {
                        type: 'placebo:stack_entry',
                        weight: 5,
                        quality: 5,
                        min: 1,
                        max: 1,
                        stack: { item: 'apotheosis:weapon_book', count: 1 }
                    },
                    {
                        type: 'placebo:stack_entry',
                        weight: 5,
                        quality: 5,
                        min: 1,
                        max: 1,
                        stack: { item: 'apotheosis:digger_book', count: 1 }
                    },
                    {
                        type: 'placebo:stack_entry',
                        weight: 5,
                        quality: 5,
                        min: 1,
                        max: 1,
                        stack: { item: 'apotheosis:fishing_rod_book', count: 1 }
                    },
                    {
                        type: 'placebo:stack_entry',
                        weight: 5,
                        quality: 5,
                        min: 1,
                        max: 1,
                        stack: { item: 'apotheosis:bow_book', count: 1 }
                    },
                    {
                        type: 'placebo:stack_entry',
                        weight: 5,
                        quality: 5,
                        min: 1,
                        max: 1,
                        stack: { item: 'minecraft:book', count: 1 }
                    },
                    {
                        type: 'placebo:stack_entry',
                        weight: 16,
                        quality: 10,
                        min: 1,
                        max: 1,
                        stack: { item: 'apotheosis:common_tome', count: 1 }
                    },
                    {
                        type: 'placebo:stack_entry',
                        weight: 13,
                        quality: 10,
                        min: 1,
                        max: 1,
                        stack: { item: 'apotheosis:uncommon_tome', count: 1 }
                    },
                    {
                        type: 'placebo:stack_entry',
                        weight: 10,
                        quality: 10,
                        min: 1,
                        max: 1,
                        stack: { item: 'apotheosis:rare_tome', count: 1 }
                    },
                    {
                        type: 'placebo:stack_entry',
                        weight: 7,
                        quality: 10,
                        min: 1,
                        max: 1,
                        stack: { item: 'apotheosis:epic_tome', count: 1 }
                    },
                    {
                        type: 'placebo:stack_entry',
                        weight: 4,
                        quality: 10,
                        min: 1,
                        max: 1,
                        stack: { item: 'apotheosis:mythic_tome', count: 1 }
                    }
                ]
            }
        ]
    };

    event.addJson(`apotheosis:loot_tables/tome_tower.json`, loot_table);
});

onEvent('generic.loot_tables', (event) => {

    const pools = [
        {
            rolls: { min: 2, max: 4 },
            entries: [
                {
                    item: 'eidolon:enchanted_ash',
                    count: [2,4],
                    weight: 10
                },
                {
                    item: 'eidolon:tattered_cloth',
                    count: [1,2],
                    weight: 5
                },
                {
                    item: 'tconstruct:earth_slime_crystal',
                    weight: 5
                },
                {
                    item: 'tconstruct:sky_slime_crystal',
                    weight: 5
                },
                {
                    item: 'alexsmobs:roadrunner_feather',
                    weight: 2
                },
                {
                    item: 'alexsmobs:kangaroo_hide',
                    weight: 2
                }
            ]
        }
    ];
    
    event.modify('apotheosis:tome_tower', (table) => {
        pools.forEach((pool) => {
            table.addPool((newPool) => {
                newPool.setUniformRolls(pool.rolls.min, pool.rolls.max);
                pool.entries.forEach((entry) => {
                    let count = entry.count ? entry.count : 1,
                        weight = entry.weight ? entry.weight : 1;
    
                    newPool.addItem(entry.item, weight, count);
                });
            });
        });
    });

});

