//Priority: 1
/**
 * @file        fishing_balance.js
 * @description FISHING LOOT BALANCE SYSTEM
 * @modpack     Monumental Experience
 * @author      KnightDexx
 * @version     2.0 - EntityEvents.death Edition 
 * @copyright   KnightDexx's Modded Minecraft World
 * @license     All Rights Reserved
 */

// ═══════════════════════════════════════════════════════════
// FISHING LOOT BALANCE - REMOVE OP ITEMS
// ═══════════════════════════════════════════════════════════

LootJS.modifiers((event) => {

    // Check if feature is enabled
    if (!global.AOF_LOOT || !global.AOF_LOOT.FEATURES.FISHING_LOOT) {
        console.info('[AOF] Fishing Balance: DISABLED (skipping)')
        return
    }

    console.info('═══════════════════════════════════════════════════════')
    console.info('[AOF] Fishing Loot Balance System v2.0')
    console.info('[AOF] Removing OP items from ALL fishing loot...')
    console.info('[AOF] Neptune gear now drops from water creatures!')
    console.info('═══════════════════════════════════════════════════════')

    const config = global.AOF_LOOT

    // ───────────────────────────────────────────────────────────
    // VANILLA & MODDED FISHING LOOT TABLES
    // ───────────────────────────────────────────────────────────

    const fishingTables = [
        /minecraft:gameplay\/fishing\/.*/, // Vanilla fishing
        /aquaculture:gameplay\/fishing\/.*/ // Aquaculture 2 fishing
    ]

    // ───────────────────────────────────────────────────────────
    // REMOVE BLACKLISTED MODS FROM FISHING
    // ───────────────────────────────────────────────────────────

    if (config.FISHING.USE_CHEST_BLACKLIST) {
        config.BLACKLIST.MODS.forEach(mod => {
            fishingTables.forEach(table => {
                event.addLootTableModifier(table)
                    .removeLoot(new RegExp(`${mod}:.*`))
            })
            console.info(`[AOF] ✓ Removed all items from: ${mod}`)
        })
    }

    // ───────────────────────────────────────────────────────────
    // REMOVE SPECIFIC BLACKLISTED ITEMS
    // ───────────────────────────────────────────────────────────

    if (config.FISHING.USE_CHEST_BLACKLIST) {
        config.BLACKLIST.ITEMS.forEach(item => {
            fishingTables.forEach(table => {
                event.addLootTableModifier(table)
                    .removeLoot(item)
            })
            console.info(`[AOF] ✓ Removed item: ${item}`)
        })
    }

    // ───────────────────────────────────────────────────────────
    // REMOVE PATTERN-MATCHED ITEMS (Tools/Weapons/Armor)
    // ───────────────────────────────────────────────────────────

    if (config.FISHING.USE_CHEST_BLACKLIST) {
        config.BLACKLIST.PATTERNS.forEach(pattern => {
            fishingTables.forEach(table => {
                event.addLootTableModifier(table)
                    .removeLoot(pattern)
            })
        })
        console.info('[AOF] ✓ Removed all tools/weapons/armor patterns')
    }

    // ───────────────────────────────────────────────────────────
    // AQUACULTURE 2 - EXTRA BLACKLIST (Neptunium Gear)
    // ───────────────────────────────────────────────────────────

    if (config.FISHING.EXTRA_BLACKLIST) {
        config.FISHING.EXTRA_BLACKLIST.forEach(item => {
            fishingTables.forEach(table => {
                event.addLootTableModifier(table)
                    .removeLoot(item)
            })
        })
        console.info('[AOF] ✓ Removed Aquaculture 2 neptunium gear from fishing')
    }

    // ───────────────────────────────────────────────────────────
    // REMOVE NEPTUNE'S BOUNTY FROM FISHING
    // ───────────────────────────────────────────────────────────

    fishingTables.forEach(table => {
        event.addLootTableModifier(table)
            .removeLoot('aquaculture:neptunes_bounty')
    })
    console.info('[AOF] ✓ Removed Neptune\'s Bounty from fishing')
    console.info('[AOF]   (Now drops from water creatures instead!)')

    // ───────────────────────────────────────────────────────────
    // REMOVE VANILLA TREASURE FROM NEPTUNIUM FISHING
    // ───────────────────────────────────────────────────────────

    event.addLootTableModifier('aquaculture:gameplay/fishing/neptunium')
        .removeLoot('minecraft:bow')
        .removeLoot('minecraft:fishing_rod')
        .removeLoot('minecraft:enchanted_book')
        .removeLoot('minecraft:name_tag')
        .removeLoot('minecraft:nautilus_shell')
        .removeLoot('minecraft:saddle')

    console.info('[AOF] ✓ Removed vanilla treasure from neptunium fishing')

    // ───────────────────────────────────────────────────────────
    // SUMMARY
    // ───────────────────────────────────────────────────────────

    console.info('═══════════════════════════════════════════════════════')
    console.info('[AOF] Fishing Balance Complete!')
    console.info('[AOF]')
    console.info('[AOF] ✓ OP items removed from fishing')
    console.info('[AOF] ✓ Neptune\'s Bounty removed from fishing')
    console.info('[AOF] ✓ Neptunium gear removed from fishing')
    console.info('[AOF] ✓ Vanilla treasure disabled')
    console.info('[AOF]')
    console.info('[AOF] 🎣 Fishing = Basic materials only')
    console.info('[AOF] 🐟 Water Creatures = Neptune progression')
    console.info('[AOF] ⚒️  Crafting = Make your own tools')
    console.info('═══════════════════════════════════════════════════════')

    // ═══════════════════════════════════════════════════════════
    // ADD CUSTOM AQ FISH POOL (No data-pack needed)
    // ═══════════════════════════════════════════════════════════

    if (global.AOF_LOOT.FEATURES.FISHING_LOOT) {

        event.addLootTableModifier('aquaculture:gameplay/fishing/fish')
            .addWeightedLoot(
                1, // rolls = 1
                [
                    Item.of('aquaculture:atlantic_cod').withChance(0.15),
                    Item.of('aquaculture:blackfish').withChance(0.40),
                    Item.of('aquaculture:pacific_halibut').withChance(0.10),
                    Item.of('aquaculture:atlantic_halibut').withChance(0.08),
                    Item.of('aquaculture:atlantic_herring').withChance(0.60),
                    Item.of('aquaculture:pink_salmon').withChance(0.20),
                    Item.of('aquaculture:pollock').withChance(0.25),
                    Item.of('aquaculture:rainbow_trout').withChance(0.20),
                    Item.of('aquaculture:bayad').withChance(0.20),
                    Item.of('aquaculture:boulti').withChance(0.30),
                    Item.of('aquaculture:capitaine').withChance(0.07),
                    Item.of('aquaculture:synodontis').withChance(0.60),
                    Item.of('aquaculture:smallmouth_bass').withChance(0.30),
                    Item.of('aquaculture:bluegill').withChance(0.60),
                    Item.of('aquaculture:brown_trout').withChance(0.30),
                    Item.of('aquaculture:carp').withChance(0.30),
                    Item.of('aquaculture:catfish').withChance(0.10),
                    Item.of('aquaculture:gar').withChance(0.20),
                    Item.of('aquaculture:minnow').withChance(0.55),
                    Item.of('aquaculture:muskellunge').withChance(0.10),
                    Item.of('aquaculture:perch').withChance(0.60),
                    Item.of('aquaculture:arapaima').withChance(0.08),
                    Item.of('aquaculture:piranha').withChance(0.40),
                    Item.of('aquaculture:tambaqui').withChance(0.20),
                    Item.of('aquaculture:brown_shrooma').withChance(0.50),
                    Item.of('aquaculture:red_shrooma').withChance(0.50),
                    Item.of('aquaculture:jellyfish').withChance(0.30),
                    Item.of('aquaculture:red_grouper').withChance(0.20),
                    Item.of('aquaculture:tuna').withChance(0.10),
                    Item.of('aquaculture:leech').withChance(0.30),
                    Item.of('aquaculture:arrau_turtle').withChance(0.05),
                    Item.of('aquaculture:box_turtle').withChance(0.05),
                    Item.of('aquaculture:starshell_turtle').withChance(0.05)
                ]
            )

        console.info('[AOF] ✓ Custom AQ fish pool added (no data-pack needed)')
    }

})