// Priority: 1000
/**
  ---╔═══╗------------╔═╗--╔═══╗--╔╗-------
  ---║╔═╗║------------║╔╝--║╔══╝-╔╝╚╗------
  ---║║ ║╠══╦══╗--╔══╦╝╚╗--║╚══╦═╩╗╔╬══╗---
  ---║╚═╝║╔╗║║═╣--║╔╗╠╗╔╝--║╔══╣╔╗║║║║═╣---
  ---║╔═╗║╚╝║║═╣--║╚╝║║║---║║--║╔╗║╚╣║═╣---
  ---╚╝ ╚╩═╗╠══╝--╚══╝╚╝---╚╝--╚╝╚╩═╩══╝---
  -------╔═╝║------------------------------
  -------╚══╝------------------------------
*/
/**
  ☻/  * @file Immersive Aircraft recipe script
  /▌  * @copyright KnightDexx's Modded Minecraft World
  /\
*/
ServerEvents.recipes(function (event) {

    // ── Helpers ────────────────────────────────────────────────────────────

    function addBaseBlueprint() {
        event.shaped('kubejs:blueprint', [' A ', 'ABA', ' A '], {
            A: '#c:paper',
            B: '#c:dyes/blue'
        }).id('kubejs:immersive_aircraft/blueprint')
    }

    function addDerivedBlueprint(result, idSuffix, ingredients) {
        event.shapeless(result, ingredients)
            .id('kubejs:immersive_aircraft/' + idSuffix)
    }

    function addMechanicalCrafting(idSuffix, pattern, key, resultItem) {
        event.recipes.create.mechanical_crafting(resultItem, pattern, key)
            .id('kubejs:immersive_aircraft/' + idSuffix)
    }
    
    function addSequencedAssembly(idSuffix, blueprintItem, resultItem, deployIngredients) {
        event.recipes.create.sequenced_assembly(
            [resultItem],
            blueprintItem,
            deployIngredients.map(ing =>
                event.recipes.create.deploying(blueprintItem, [blueprintItem, ing])
            )
        )
        .transitionalItem(blueprintItem)
        .loops(1)
        .id('kubejs:immersive_aircraft/' + idSuffix)
    }

    // ── Blueprints — vanilla only, always register ─────────────────────────

    addBaseBlueprint()

    addDerivedBlueprint('kubejs:airship_blueprint', 'airship_blueprint', [
        'kubejs:blueprint', '2x #minecraft:planks'
    ])
    addDerivedBlueprint('kubejs:cargo_blueprint', 'cargo_blueprint', [
        'kubejs:blueprint', '2x #c:chests/wooden'
    ])
    addDerivedBlueprint('kubejs:biplane_blueprint', 'biplane_blueprint', [
        'kubejs:blueprint', '2x #c:ingots/iron'
    ])
    addDerivedBlueprint('kubejs:gyrodyne_blueprint', 'gyrodyne_blueprint', [
        'kubejs:blueprint', '#c:ingots/iron', '#c:ingots/copper'
    ])
    addDerivedBlueprint('kubejs:quadrocopter_blueprint', 'quadrocopter_blueprint', [
        'kubejs:blueprint', '2x minecraft:bamboo_block'
    ])

    // ── Mechanical crafting ────────────────────────────────────────────────

    // Hull — requires immersiveengineering
    if (Platform.isLoaded('immersiveengineering')) {
        addMechanicalCrafting(
            'hull',
            ['CCCCC', 'BEBEB', 'AFAFA', 'BEBEB', 'CCCCC'],
            {
                A: 'immersiveengineering:alu_scaffolding_standard',
                B: 'immersiveengineering:slab_sheetmetal_aluminum',
                C: '#c:treated_wood',
                E: '#c:plates/aluminum',
                F: '#c:gears/iron'
            },
            'immersive_aircraft:hull'
        )
    }

    // Boiler — requires create + ironfurnaces + cyclic + thermal
    if (Platform.isLoaded('create') && Platform.isLoaded('ironfurnaces')
            && Platform.isLoaded('cyclic') && Platform.isLoaded('thermal')) {
        addMechanicalCrafting(
            'boiler',
            ['AAAAA', 'ACECA', 'ACBCA', 'ACECA', 'ADDDA'],
            {
                A: '#c:ingots/copper',
                B: 'create:steam_engine',
                C: 'ironfurnaces:copper_furnace',
                D: 'cyclic:copper_bars',
                E: 'thermal:fluid_duct'
            },
            'immersive_aircraft:boiler'
        )
    }

    // Engine — requires immersiveengineering + createaddition + create
    if (Platform.isLoaded('immersiveengineering') && Platform.isLoaded('createaddition')
            && Platform.isLoaded('create')) {
        addMechanicalCrafting(
            'engine',
            ['GGGGG', 'ADEDA', 'AEBEA', 'ADEDA', 'ACFCA'],
            {
                A: 'immersiveengineering:sheetmetal_steel',
                B: 'createaddition:electric_motor',
                C: 'create:smart_fluid_pipe',
                D: 'create:belt_connector',
                E: '#c:gears/steel',
                F: 'immersive_aircraft:boiler',
                G: 'immersiveengineering:slab_sheetmetal_aluminum'
            },
            'immersive_aircraft:engine'
        )
    }

    // Sail — requires supplementaries + immersiveengineering
    if (Platform.isLoaded('supplementaries') && Platform.isLoaded('immersiveengineering')) {
        addMechanicalCrafting(
            'sail',
            [' C BA', 'CCCBA', 'CCCBA', ' CCBA', 'C CBA'],
            {
                A: 'supplementaries:rope',
                B: 'immersiveengineering:hemp_fabric',
                C: 'minecraft:white_banner'
            },
            'immersive_aircraft:sail'
        )
    }

    // Propeller — all tags, no hard mod deps
    addMechanicalCrafting(
        'propeller',
        ['AA   ', ' AA  ', ' CBC ', '  AA ', '   AA'],
        {
            A: '#c:ingots/steel',
            B: '#c:gears/steel',
            C: '#c:plates/aluminum'
        },
        'immersive_aircraft:propeller'
    )

    // ── Shaped parts ───────────────────────────────────────────────────────

    // Enhanced Propeller — requires supplementaries
    if (Platform.isLoaded('supplementaries')) {
        event.shaped('immersive_aircraft:enhanced_propeller', ['AB ', ' C ', ' BA'], {
            A: '#c:ingots/copper',
            B: 'immersive_aircraft:propeller',
            C: 'supplementaries:cog_block'
        }).id('kubejs:immersive_aircraft/enhanced_propeller')
    }

    // Eco Engine — requires mekanism
    if (Platform.isLoaded('mekanism')) {
        event.shaped('immersive_aircraft:eco_engine', ['ABA', 'BCB', 'DDD'], {
            A: 'mekanism:bio_fuel',
            B: '#c:ingots/gold',
            C: 'immersive_aircraft:engine',
            D: '#c:plates/aluminum'
        }).id('kubejs:immersive_aircraft/eco_engine')
    }

    // Nether Engine — requires reliquary
    if (Platform.isLoaded('reliquary')) {
        event.shaped('immersive_aircraft:nether_engine', ['ABA', 'BCB', 'DDD'], {
            A: 'reliquary:molten_core',
            B: '#c:ingots/netherite',
            C: 'immersive_aircraft:engine',
            D: '#c:plates/steel'
        }).id('kubejs:immersive_aircraft/nether_engine')
    }

    // Steel Boiler — requires mekanism
    if (Platform.isLoaded('mekanism')) {
        event.shaped('immersive_aircraft:steel_boiler', ['AAA', 'ACA', 'ABA'], {
            A: '#c:ingots/steel',
            B: 'mekanism:boiler_valve',
            C: 'immersive_aircraft:boiler'
        }).id('kubejs:immersive_aircraft/steel_boiler')
    }

    // Industrial Gears — requires create
    if (Platform.isLoaded('create')) {
        event.shaped('immersive_aircraft:industrial_gears', [' AB', 'CDA', 'EC '], {
            A: '#c:ingots/iron',
            B: '#c:gears/iron',
            D: 'create:gearbox',
            C: '#c:ingots/copper',
            E: '#c:gears/copper'
        }).id('kubejs:immersive_aircraft/industrial_gears')
    }

    // Sturdy Pipes — requires create + immersiveengineering
    if (Platform.isLoaded('create') && Platform.isLoaded('immersiveengineering')) {
        event.shaped('immersive_aircraft:sturdy_pipes', ['  A', 'BCB', 'A  '], {
            A: 'create:fluid_pipe',
            B: 'immersiveengineering:fluid_pipe',
            C: 'create:smart_fluid_pipe'
        }).id('kubejs:immersive_aircraft/sturdy_pipes')
    }

    // Gyroscope — requires cyclic + buildersaddition
    if (Platform.isLoaded('cyclic') && Platform.isLoaded('buildersaddition')) {
        event.shaped('immersive_aircraft:gyroscope', [' A ', 'BCB', ' D '], {
            A: 'cyclic:detector_weather',
            B: 'cyclic:location_data',
            C: 'minecraft:compass',
            D: 'buildersaddition:entity_detector'
        }).id('kubejs:immersive_aircraft/gyroscope')
    }

    // Hull Reinforcement — all tags (hull itself registered separately above)
    event.shaped('immersive_aircraft:hull_reinforcement', ['AAA', 'BCB', 'AAA'], {
        A: '#c:ingots/steel',
        B: 'immersive_aircraft:hull',
        C: '#c:storage_blocks/steel'
    }).id('kubejs:immersive_aircraft/hull_reinforcement')

    // Improved Landing Gear — all tags
    event.shaped('immersive_aircraft:improved_landing_gear', [' AB', 'CCA', 'CC '], {
        A: '#c:plates/iron',
        B: '#c:ingots/steel',
        C: '#c:rubber'
    }).id('kubejs:immersive_aircraft/improved_landing_gear')

    // ── Sequenced Assembly — all require create ────────────────────────────

    if (Platform.isLoaded('create')) {

        addSequencedAssembly(
            'airship', 'kubejs:airship_blueprint', 'immersive_aircraft:airship',
            [
                'create:precision_mechanism',
                'immersive_aircraft:sail',
                'immersive_aircraft:sail',
                'immersive_aircraft:hull',
                'immersive_aircraft:engine'
            ]
        )

        if (Platform.isLoaded('sophisticatedstorage')) {
            addSequencedAssembly(
                'cargo_airship', 'kubejs:cargo_blueprint', 'immersive_aircraft:cargo_airship',
                [
                    'create:precision_mechanism',
                    'immersive_aircraft:airship',
                    'sophisticatedstorage:storage_tool',
                    'immersive_aircraft:hull'
                ]
            )
        }

        addSequencedAssembly(
            'biplane', 'kubejs:biplane_blueprint', 'immersive_aircraft:biplane',
            [
                'create:precision_mechanism',
                'immersive_aircraft:hull',
                'immersive_aircraft:hull',
                'immersive_aircraft:engine',
                'immersive_aircraft:propeller'
            ]
        )

        addSequencedAssembly(
            'gyrodyne', 'kubejs:gyrodyne_blueprint', 'immersive_aircraft:gyrodyne',
            [
                'create:precision_mechanism',
                'immersive_aircraft:sail',
                'immersive_aircraft:sail',
                'immersive_aircraft:hull',
                'immersive_aircraft:propeller'
            ]
        )

        if (Platform.isLoaded('farmersdelight')) {
            addSequencedAssembly(
                'quadrocopter', 'kubejs:quadrocopter_blueprint', 'immersive_aircraft:quadrocopter',
                [
                    'immersive_aircraft:propeller',
                    'immersive_aircraft:propeller',
                    'immersive_aircraft:engine',
                    'farmersdelight:basket',
                    'immersive_aircraft:propeller',
                    'immersive_aircraft:propeller'
                ]
            )
        }

    }

    // ── Removals ───────────────────────────────────────────────────────────

    removeRecipeByID(event, [
        'immersive_aircraft:hull',           'immersive_aircraft:boiler',
        'immersive_aircraft:engine',         'immersive_aircraft:sail',
        'immersive_aircraft:propeller',      'immersive_aircraft:enhanced_propeller',
        'immersive_aircraft:eco_engine',     'immersive_aircraft:nether_engine',
        'immersive_aircraft:steel_boiler',   'immersive_aircraft:industrial_gears',
        'immersive_aircraft:sturdy_pipes',   'immersive_aircraft:gyroscope',
        'immersive_aircraft:hull_reinforcement', 'immersive_aircraft:improved_landing_gear',
        'immersive_aircraft:airship',        'immersive_aircraft:cargo_airship',
        'immersive_aircraft:biplane',        'immersive_aircraft:gyrodyne',
        'immersive_aircraft:quadrocopter'
    ])

})
// Made by KnightDexx, for use in both Monumental Experience & Age of Fate modpacks
// https://legacy.curseforge.com/minecraft/modpacks/age-of-fate
// https://legacy.curseforge.com/minecraft/modpacks/monumental-experience-in-space
