// Priority: 100
/**
  
  █▀▄▀█ █▀█ █▄░█ █░█ █▀▄▀█ █▀▀ █▄░█ ▀█▀ ▄▀█ █░░   █▀▀ ▀▄▀ █▀█ █▀▀ █▀█ █ █▀▀ █▄░█ █▀▀ █▀▀
  █░▀░█ █▄█ █░▀█ █▄█ █░▀░█ ██▄ █░▀█ ░█░ █▀█ █▄▄   ██▄ █░█ █▀▀ ██▄ █▀▄ █ ██▄ █░▀█ █▄▄ ██▄

  ☻/  * @file Nature's Aura recipes script
  /▌  * @copyright KnightDexx's Modded Minecraft World | ModernGamingWorld | GeekTechMedia
  /▌  * Mostly made by @Cyn-SolveroftheAbsoluteGremlins on Discord
  /\  

*/
ServerEvents.recipes(event => {

    let hammer = '#alltheores:ore_hammers'
    //event.remove({mod: 'alltheores', item: hammer})
    const dust = [
        { mat: 'nickel', mod: 'alltheores' },
        { mat: 'tin', mod: 'alltheores' },
        { mat: 'platinum', mod: 'alltheores' },
        { mat: 'lead', mod: 'alltheores' },
        { mat: 'osmium', mod: 'alltheores' },
        { mat: 'iridium', mod: 'alltheores' },
        { mat: 'silver', mod: 'alltheores' },
        { mat: 'aluminum', mod: 'alltheores' },
        { mat: 'zinc', mod: 'alltheores' },
        { mat: 'uranium', mod: 'alltheores' },
        { mat: 'gold', mod: 'minecraft' },
        { mat: 'iron', mod: 'minecraft' },
        { mat: 'copper', mod: 'minecraft' },
        { mat: 'allthemodium', mod: 'allthemodium' },
        { mat: 'vibranium', mod: 'allthemodium' },
        { mat: 'unobtainium', mod: 'allthemodium' },
        // TODO: Ad Astra replaced by Stellaris — confirm Stellaris raw ore item IDs
        // then replace 'stellaris' with the correct modid and verify mat names are correct.
        // If Stellaris uses different names for these metals, update mat: accordingly.
        // { mat: 'desh',     mod: 'moremekanismprocessing', add: 'stellaris' },
        // { mat: 'ostrum',   mod: 'moremekanismprocessing', add: 'stellaris' },
        // { mat: 'calorite', mod: 'moremekanismprocessing', add: 'stellaris' }
    ]
    const rodPlate = [
        'electrum',
        'platinum',
        'gold',
        'lumium',
        'silver',
        'osmium',
        'constantan',
        'uranium',
        'lead',
        'diamond',
        'brass',
        'invar',
        'enderium',
        'iridium',
        'zinc',
        'iron',
        'nickel',
        'signalum',
        'copper',
        'tin',
        'aluminum',
        'steel',
        'bronze',
        'ostrum',
        'desh',
        'calorite'
    ]
    const gem = [
        'peridot',
        'sapphire',
        'ruby'
    ]
    const gemDust = [
        'peridot',
        'ruby',
        'sapphire',
        'diamond',
        'netherite'
    ]
    dust.forEach(d => {
        let raw = 'unused'
        let dust = 'unused'
        if (d.mod != 'moremekanismprocessing' && d.mod != 'allthemodium') {
            raw = `${d.mod}:raw_${d.mat}`
            dust = `alltheores:${d.mat}_dust`
            event.remove({ input: raw, input: hammer, output: dust })
        } else if (d.mod == 'allthemodium') {
            raw = `${d.mod}:raw_${d.mat}`
            dust = `allthemodium:${d.mat}_dust`
            event.remove({ input: raw, input: hammer, output: dust })
        } else if (d.mod == 'moremekanismprocessing') {
            // These use ad_astra raw items — skip if neither ad_astra nor stellaris loaded
            // TODO: once Stellaris item IDs are confirmed, add Platform.isLoaded('stellaris')
            // branch here with the correct raw item IDs
            if (!Platform.isLoaded(d.add)) return
            raw = `${d.add}:raw_${d.mat}`
            dust = `${d.mod}:dust_${d.mat}`
        } else {
            console.error(`Something went wrong! Please fix ${d.mat}, ${d.add}`)
            return
        }
        event.shapeless(
            Item.of(dust, 2),
            [
                hammer,
                raw
            ]
        ).id(`kubejs:${d.mat}_dust_from_hammer_crushing_manual_only`)
    })
    rodPlate.forEach((ing) => {
        if (ing == 'diamond') {
            event.shaped(
                Item.of(`alltheores:${ing}_rod`),
                [
                    "  a",
                    "ha ",
                    "   "
                ],
                {
                    a: `minecraft:${ing}`,
                    h: hammer
                }
            ).id(`kubejs:${ing}_rod_manual_only`)
            event.remove({ input: hammer, output: `alltheores:${ing}_plate` })
            event.shaped(
                Item.of(`alltheores:${ing}_plate`),
                [
                    "ha ",
                    "a  ",
                    "   "
                ],
                {
                    a: `minecraft:${ing}`,
                    h: hammer
                }
            ).id(`kubejs:${ing}_plate_manual_only`)
            event.remove({ input: hammer, output: `alltheores:${ing}_rod` })
        } else if (ing == 'desh' || ing == 'calorite' || ing == 'ostrum') {
            // TODO: Ad Astra replaced by Stellaris.
            // Confirm the plate item IDs in Stellaris, then replace 'ad_astra' below.
            // e.g. if Stellaris uses 'stellaris:desh_plate', change 'ad_astra' → 'stellaris'
            if (Platform.isLoaded('ad_astra')) {
                event.shaped(
                    Item.of(`ad_astra:${ing}_plate`),
                    [
                        "ha ",
                        "a  ",
                        "   "
                    ],
                    {
                        a: `#c:ingots/${ing}`,
                        h: hammer
                    }
                ).id(`kubejs:${ing}_plate_manual_only`)
                event.remove({ input: hammer, output: `ad_astra:${ing}_plate` })
            }
            // TODO: add stellaris block here once plate IDs are confirmed:
            // if (Platform.isLoaded('stellaris')) {
            //     event.shaped(Item.of(`stellaris:${ing}_plate`), ["ha ","a  ","   "], { a: `#c:ingots/${ing}`, h: hammer }).id(`kubejs:${ing}_plate_manual_only`)
            //     event.remove({ input: hammer, output: `stellaris:${ing}_plate` })
            // }
        } else {
            event.shaped(
                Item.of(`alltheores:${ing}_rod`),
                [
                    "  a",
                    "ha ",
                    "   "
                ],
                {
                    a: `#c:ingots/${ing}`,
                    h: hammer
                }
            ).id(`kubejs:${ing}_rod_manual_only`)
            event.remove({ input: hammer, output: `alltheores:${ing}_plate` })
            event.shaped(
                Item.of(`alltheores:${ing}_plate`),
                [
                    "ha ",
                    "a  ",
                    "   "
                ],
                {
                    a: `#c:ingots/${ing}`,
                    h: hammer
                }
            ).id(`kubejs:${ing}_plate_manual_only`)
            event.remove({ input: hammer, output: `alltheores:${ing}_rod` })
        }
    })
    gem.forEach((ge) => {
        event.shapeless(
            Item.of(`alltheores:${ge}`, 3),
            [
                hammer,
                '#c:ores/' + ge
            ]
        ).id(`kubejs:${ge}_from_hammer_crushing_manual_only`)
        event.remove({ input: `#c:ores/${ge}`, input: hammer, output: `alltheores:${ge}` })
    })
    gemDust.forEach((gemDus) => {
        if (gemDus == 'netherite') {
            // thermal:netherite_dust was removed in Thermal 1.21.
            // Use alltheores:netherite_dust if alltheores is loaded, skip otherwise.
            if (Platform.isLoaded('alltheores')) {
                event.shapeless(
                    Item.of('alltheores:netherite_dust'),
                    [hammer, '#c:ingots/netherite']
                ).id('kubejs:netherite_dust_from_hammer_crushing_manual_only')
                event.remove({ input: '#c:ingots/netherite', input: hammer, output: 'alltheores:netherite_dust' })
            }
        } else {
            event.shapeless(
                Item.of(`alltheores:${gemDus}_dust`),
                [
                    hammer,
                    '#c:gems/' + gemDus
                ]
            ).id(`kubejs:${gemDus}_dust_from_hammer_crushing_manual_only`)
            event.remove({ input: `#c:gems/${gemDus}`, input: hammer, output: `alltheores:${gemDus}_dust` })
        }
    })
    event.shapeless(
        Item.of('allthemodium:ancient_chiseled_stone_bricks'),
        [
            hammer,
            'allthemodium:ancient_cracked_stone_bricks'
        ]
    ).id('kubejs:ancient_chiseled_stone_bricks_from_crushing_manual_only')
    event.shapeless(
        Item.of('allthemodium:ancient_cracked_stone_bricks'),
        [
            hammer,
            'allthemodium:ancient_stone_bricks'
        ]
    ).id('kubejs:ancient_cracked_stone_bricks_from_crushing_manual_only')
    event.shaped(
        Item.of('alltheores:enderium_dust', 4),
        [
            "lll",
            "pee",
            "h  "
        ],
        {
            l: '#c:dusts/lead',
            h: hammer,
            e: 'minecraft:ender_pearl',
            p: '#c:dusts/platinum'
        }
    ).id(`kubejs:enderium_dust_from_alloy_blending_manual_only`)
    event.shaped(
        Item.of('alltheores:steel_dust'),
        [
            "dcc",
            "cch",
            "   "
        ],
        {
            d: '#c:dusts/iron',
            h: hammer,
            c: 'minecraft:coal'
        }
    ).id('kubejs:steel_dust_from_alloy_blending_manual_only')
    event.remove({ id: 'alltheores:steel_dust_from_alloy_blending' })
    event.remove({ id: 'alltheores:enderium_dust_from_alloy_blending' })
    event.remove({ id: 'allthemodium:ancient_cracked_stone_bricks_from_crushing' })
    event.remove({ id: 'allthemodium:ancient_chiseled_stone_bricks_from_crushing' })

    // TODO: Ad Astra replaced by Stellaris — check if Stellaris has steel_rod/iron_rod recipes to remove
    if (Platform.isLoaded('ad_astra')) {
        event.remove({ id: 'ad_astra:steel_rod' })
        event.remove({ id: 'ad_astra:iron_rod' })
    }
    // TODO: if (Platform.isLoaded('stellaris')) { event.remove({ id: 'stellaris:steel_rod' }) ... }
    event.remove({ id: 'buildersaddition:iron_rod' })
})