// priority: 0

// Visit the wiki for more info - https://kubejs.com/

// onEvent('recipes', event => {

ServerEvents.recipes(event => {
    // Thermal Expansion
    event.remove('thermal:machine_frame')
    event.recipes.create.item_application('thermal:machine_frame', ['#forge:glass', 'thermal:invar_block'])

    event.recipes.create.crushing([Item.of('minecraft:snowball', 2), Item.of('thermal:blizz_rod', 1).withChance(0.65), Item.of('thermal:blizz_rod', 1).withChance(0.15)], 'minecraft:snow_block').id('bttk:crushing/blizz_rod_from_snow_block')
    event.recipes.create.crushing([Item.of('thermal:blizz_powder', 3), Item.of('thermal:blizz_powder', 3).withChance(0.25)], 'thermal:blizz_rod').id('bttk:crushing/blizz_rod')

    event.recipes.create.crushing([Item.of('thermal:basalz_powder', 3), Item.of('thermal:basalz_powder', 3).withChance(0.25)], 'thermal:basalz_rod').id('bttk:crushing/basalz_rod')

    event.recipes.create.crushing([Item.of('thermal:blitz_powder', 3), Item.of('thermal:blitz_powder', 3).withChance(0.25)], 'thermal:blitz_rod').id('bttk:crushing/blitz_rod')

    let coinMaterials = ["enderium", "lumium", "signalum", "netherite", "copper", "iron", "gold", "constantan", "invar", "electrum", "bronze", "nickel", "silver", "lead", "tin"]
    coinMaterials.forEach(i => {
        event.remove(`thermal:machines/press/press_${i}_ingot_to_coin`)
        event.remove(`thermal:machines/press/press_${i}_nugget_to_coin`)
    })

    event.remove('thermal:machines/smelter/smelter_alloy_enderium')

    let magmaticFuel = (fluid, amount, energy) => {
        event.custom({
            type: 'thermal:magmatic_fuel',
            ingredient: {
                fluid: fluid,
                amount: amount
            },
            energy: energy
        })
    }

    magmaticFuel('kubejs:hellish_essence', '1000', 50000)

    event.recipes.create.compacting('4x thermal:rubber', [Fluid.of('thermal:latex', 1000)]).id('bttk:compacting/rubber_from_latex')

    // let incompleteGoldCoin = 'kubejs:incomplete_gold_coin'
    // event.recipes.create.sequenced_assembly([
    //     Item.of('thermal:gold_coin', 1)
    // ], 'thermal:iron_coin', [
    //     event.recipes.create.filling(incompleteGoldCoin, [incompleteGoldCoin, Fluid.of('kubejs:molten_gold', 100)])
    // ]).transitionalItem(incompleteGoldCoin).loops(10).id('bttk:sequenced_assembly/thermal_gold_coin')

    event.recipes.thermal.pulverizer([Item.of('minecraft:bone', 2).withChance(0.85), Item.of('minecraft:soul_sand', 1).withChance(0.04)], 'minecraft:soul_soil')

    event.remove('thermal:dynamo_gourmand')
    event.shaped('thermal:dynamo_gourmand', [
        ' A ',
        'BCB',
        'DED'
    ], {
        A: 'thermal:rf_coil',
        B: 'thermal:iron_gear',
        C: 'garnished:garnished_meal',
        D: '#forge:ingots/tin',
        E: '#forge:dusts/redstone'
    }).id('bttk:thermal_dynamos/gourmand')

    let crucibleRecipe = (result, resultAmount, energy, input) => {
        event.custom({
            type: 'thermal:crucible',
            ingredient: {
                item: input
            },
            result: [
                {
                    fluid: result,
                    amount: resultAmount
                }
            ],
            energy: energy
        })
    }
    let crucibleRecipeWithTag = (result, resultAmount, energy, input) => {
        event.custom({
            type: 'thermal:crucible',
            ingredient: {
                tag: input
            },
            result: [
                {
                    fluid: result,
                    amount: resultAmount
                }
            ],
            energy: energy
        })
    }

    crucibleRecipe('kubejs:molten_slime', 100, 8000, 'minecraft:slime_ball')
    crucibleRecipe('kubejs:molten_slime', 900, 72000, 'minecraft:slime_block')

    crucibleRecipeWithTag('thermal:ender', 250, 20000, 'forge:dusts/ender_pearl')

    event.remove('thermal:storage/electrum_ingot_from_nuggets')
    event.shapeless('thermal:electrum_ingot', '9x thermal:electrum_nugget').id('bttk:thermal/shapeless/electrum_ingot')

    let thermalMinerals = ["tin", "lead", "silver", "nickel", "signalum", "lumium", "enderium", "bronze", "electrum", "invar"]
    thermalMinerals.forEach(i => {
        event.recipes.thermal.chiller(`thermal:${i}_ingot`, [Fluid.of(`kubejs:molten_${i}`, 100), 'thermal:chiller_ingot_cast']).id(`bttk:blast_chiller/ingots/${i}`)
    })
    let vanillaMinerals = ["gold", "iron", "copper", "netherite"]
    vanillaMinerals.forEach(i => {
        event.recipes.thermal.chiller(`minecraft:${i}_ingot`, [Fluid.of(`kubejs:molten_${i}`, 100), 'thermal:chiller_ingot_cast']).id(`bttk:blast_chiller/ingots/${i}`)
    })

    let plateMaterials = ["tin", "lead", "silver", "nickel", "bronze", "electrum", "invar", "constantan", "lumium", "signalum", "enderium"]
    plateMaterials.forEach(i => {
        event.recipes.create.pressing(`thermal:${i}_plate`, `thermal:${i}_ingot`).id(`bttk:pressing/${i}_plate_from_ingot`)
    })
    event.recipes.create.pressing('thermal:netherite_plate', 'minecraft:netherite_ingot').id('bttk:pressing/netherite_plate_from_ingot')

    event.recipes.create.milling([Item.of('thermal:ruby_dust', 1)], 'thermal:ruby').id('bttk:milling/ruby_dust_from_ruby')
    event.recipes.create.milling([Item.of('thermal:lapis_dust', 1)], 'minecraft:lapis_lazuli').id('bttk:milling/lapis_dust_from_lapis_lazuli')
    event.recipes.create.milling([Item.of('thermal:diamond_dust', 1)], 'minecraft:diamond').id('bttk:milling/diamond_dust_from_diamond')
    event.recipes.create.milling([Item.of('thermal:emerald_dust', 1)], 'minecraft:emerald').id('bttk:milling/emerald_dust_from_emerald')
    event.recipes.create.milling([Item.of('thermal:quartz_dust', 1)], 'minecraft:quartz').id('bttk:milling/quartz_dust_from_quartz')

    // Ingots from Mixing + Heating
    event.recipes.create.mixing('2x thermal:invar_ingot', ['2x minecraft:iron_ingot', 'thermal:nickel_ingot']).heated()
    event.recipes.create.mixing('2x thermal:electrum_ingot', ['minecraft:gold_ingot', 'thermal:silver_ingot']).heated()
    event.recipes.create.mixing('2x thermal:bronze_ingot', ['3x minecraft:copper_ingot', 'thermal:tin_ingot']).heated()
    event.recipes.create.mixing('2x thermal:constantan_ingot', ['minecraft:copper_ingot', 'thermal:nickel_ingot']).heated()
    event.recipes.create.mixing('3x thermal:signalum_ingot', ['3x minecraft:copper_ingot', 'thermal:silver_ingot', '4x minecraft:redstone']).superheated()
    event.recipes.create.mixing('3x thermal:lumium_ingot', ['3x thermal:tin_ingot', 'thermal:silver_ingot', '2x minecraft:glowstone_dust']).superheated()
    event.recipes.create.mixing('3x thermal:enderium_ingot', ['2x kubejs:obsidian_ingot', 'minecraft:ender_pearl', 'minecraft:diamond']).superheated()

    let mineralsFromInduction = ['invar', 'electrum', 'bronze', 'constantan', 'signalum', 'lumium', 'enderium']
    mineralsFromInduction.forEach(i => {
    })

    event.remove('thermal:enderium_dust_2')
    // event.shapeless('2x thermal:enderium_dust', ['3x thermal:lead_dust', 'thermal:diamond_dust', '2x #forge:dusts/ender_pearl'])

    event.recipes.thermal.smelter('4x thermal:enderium_ingot', ['minecraft:diamond', '2x kubejs:obsidian_ingot', '2x minecraft:ender_pearl']).energy(4800)

    event.recipes.create.milling('2x minecraft:redstone', 'thermal:cinnabar')
    event.recipes.create.crushing([Item.of('minecraft:redstone', 3), Item.of('minecraft:redstone', 3).withChance(0.25)], 'thermal:cinnabar')

    // Igneous Extruder
    let extruderRecipe = (result, adj) => {
        event.custom({
            type: 'thermal:rock_gen',
            adjacent: adj,
            result: {
                item: result
            }
        })
    }
    let extruderWithBlockBelowRecipe = (result, below, adj) => {
        event.custom({
            type: 'thermal:rock_gen',
            adjacent: adj,
            below: below,
            result: {
                item: result
            }
        })
    }

    // Create Mod Rock Gen
    extruderRecipe('create:limestone', 'create:honey')
    extruderRecipe('create:scoria', 'create:chocolate')

    // Garnished Mod Rock Gen
    extruderRecipe('garnished:carnotite', 'garnished:apple_cider')
    extruderRecipe('minecraft:dripstone_block', 'garnished:peanut_oil')
    extruderRecipe('minecraft:calcite', 'garnished:garnish')
    extruderRecipe('minecraft:end_stone', 'garnished:cashew_mixture')

    extruderRecipe('garnished:zultanite', 'garnished:mastic_resin')
    let colours = ['red', 'orange', 'yellow', 'green', 'lime', 'blue', 'light_blue', 'cyan', 'purple', 'magenta', 'pink', 'black', 'gray', 'light_gray', 'white', 'brown']
    colours.forEach(i => {
        extruderRecipe(`garnished:${i}_zultanite`, `garnished:${i}_mastic_resin`)
    })

    // Phytogenic Insolator
    let phytogenicInsolatorRecipe = (id, results, sapling) => {
        event.recipes.thermal.insolator(results, `${sapling}`).id(`bttk:insolator/${id}`)
    }

    phytogenicInsolatorRecipe('minecraft/warped_fungus', [Item.of('minecraft:warped_fungus', 1).withChance(1.1), Item.of('minecraft:warped_stem', 6), Item.of('minecraft:warped_wart_block', 8).withChance(1.41)], 'minecraft:warped_fungus')
    phytogenicInsolatorRecipe('minecraft/crimson_fungus', [Item.of('minecraft:crimson_fungus', 1).withChance(1.1), Item.of('minecraft:crimson_stem', 6), Item.of('minecraft:nether_wart_block', 8).withChance(1.41)], 'minecraft:crimson_fungus')
    phytogenicInsolatorRecipe('biomesoplenty/umbran', [Item.of('biomesoplenty:umbran_log', 6), Item.of('minecraft:stick', 1).withChance(0.25), Item.of('biomesoplenty:umbran_sapling').withChance(1.25)], 'biomesoplenty:umbran_sapling')
    phytogenicInsolatorRecipe('biomesoplenty/magic', [Item.of('biomesoplenty:magic_log', 6), Item.of('minecraft:stick', 1).withChance(0.25), Item.of('biomesoplenty:magic_sapling').withChance(1.25)], 'biomesoplenty:magic_sapling')
    phytogenicInsolatorRecipe('biomesoplenty/dead', [Item.of('biomesoplenty:dead_log', 6), Item.of('minecraft:stick', 1).withChance(0.25), Item.of('biomesoplenty:dead_sapling').withChance(1.25)], 'biomesoplenty:dead_sapling')
    phytogenicInsolatorRecipe('biomesoplenty/willow', [Item.of('biomesoplenty:willow_log', 6), Item.of('minecraft:stick', 1).withChance(0.25), Item.of('biomesoplenty:willow_sapling').withChance(1.25)], 'biomesoplenty:willow_sapling')
    phytogenicInsolatorRecipe('biomesoplenty/palm', [Item.of('biomesoplenty:palm_log', 6), Item.of('minecraft:stick', 1).withChance(0.25), Item.of('biomesoplenty:palm_sapling').withChance(1.25)], 'biomesoplenty:palm_sapling')
    phytogenicInsolatorRecipe('biomesoplenty/jacaranda', [Item.of('biomesoplenty:jacaranda_log', 6), Item.of('minecraft:stick', 1).withChance(0.25), Item.of('biomesoplenty:jacaranda_sapling').withChance(1.25)], 'biomesoplenty:jacaranda_sapling')
    phytogenicInsolatorRecipe('biomesoplenty/mahogany', [Item.of('biomesoplenty:mahogany_log', 6), Item.of('minecraft:stick', 1).withChance(0.25), Item.of('biomesoplenty:mahogany_sapling').withChance(1.25)], 'biomesoplenty:mahogany_sapling')
    phytogenicInsolatorRecipe('biomesoplenty/redwood', [Item.of('biomesoplenty:redwood_log', 6), Item.of('minecraft:stick', 1).withChance(0.25), Item.of('biomesoplenty:redwood_sapling').withChance(1.25)], 'biomesoplenty:redwood_sapling')
    phytogenicInsolatorRecipe('biomesoplenty/fir', [Item.of('biomesoplenty:fir_log', 6), Item.of('minecraft:stick', 1).withChance(0.25), Item.of('biomesoplenty:fir_sapling').withChance(1.25)], 'biomesoplenty:fir_sapling')
    phytogenicInsolatorRecipe('biomesoplenty/maple', [Item.of('minecraft:oak_log', 6), Item.of('minecraft:stick', 1).withChance(0.25), Item.of('biomesoplenty:maple_sapling').withChance(1.25)], 'biomesoplenty:maple_sapling')
    phytogenicInsolatorRecipe('biomesoplenty/orange_autumn', [Item.of('minecraft:dark_oak_log', 6), Item.of('minecraft:stick', 1).withChance(0.25), Item.of('biomesoplenty:orange_autumn_sapling').withChance(1.25)], 'biomesoplenty:orange_autumn_sapling')
    phytogenicInsolatorRecipe('biomesoplenty/yellow_autumn', [Item.of('minecraft:birch_log', 6), Item.of('minecraft:stick', 1).withChance(0.25), Item.of('biomesoplenty:yellow_autumn_sapling').withChance(1.25)], 'biomesoplenty:yellow_autumn_sapling')
    phytogenicInsolatorRecipe('biomesoplenty/rainbow_birch', [Item.of('minecraft:birch_log', 6), Item.of('minecraft:stick', 1).withChance(0.25), Item.of('biomesoplenty:rainbow_birch_sapling').withChance(1.25)], 'biomesoplenty:rainbow_birch_sapling')
    phytogenicInsolatorRecipe('biomesoplenty/snowblossom', [Item.of('minecraft:cherry_log', 6), Item.of('minecraft:stick', 1).withChance(0.25), Item.of('biomesoplenty:snowblossom_sapling').withChance(1.25)], 'biomesoplenty:snowblossom_sapling')
    phytogenicInsolatorRecipe('biomesoplenty/flowering_oak', [Item.of('minecraft:oak_log', 6), Item.of('minecraft:stick', 1).withChance(0.25), Item.of('biomesoplenty:flowering_oak_sapling').withChance(1.25)], 'biomesoplenty:flowering_oak_sapling')
    phytogenicInsolatorRecipe('biomesoplenty/classic_oak', [Item.of('minecraft:oak_log', 6), Item.of('minecraft:stick', 1).withChance(0.25), Item.of('biomesoplenty:origin_sapling').withChance(1.25)], 'biomesoplenty:origin_sapling')
    phytogenicInsolatorRecipe('biomesoplenty/hellbark', [Item.of('biomesoplenty:hellbark_log', 6), Item.of('minecraft:stick', 1).withChance(0.25), Item.of('biomesoplenty:hellbark_sapling').withChance(1.25)], 'biomesoplenty:hellbark_sapling')
    phytogenicInsolatorRecipe('hibernalherbs/myqueste', [Item.of('hibernalherbs:myqueste_log', 6), Item.of('minecraft:stick', 1).withChance(0.25), Item.of('hibernalherbs:myqueste_sapling').withChance(1.25)], 'hibernalherbs:myqueste_sapling')
    phytogenicInsolatorRecipe('garnished_additions/ethereal', [Item.of('garnished_additions:ethereal_log', 6), Item.of('garnished_additions:ethereal_growth').withChance(1.25), Item.of('garnished_additions:ethereal_fruit').withChance(1.155), Item.of('garnished_additions:ethereal_leaf').withChance(1.10)], 'garnished_additions:ethereal_growth')
    phytogenicInsolatorRecipe('under_the_moon/sweptwood', [Item.of('under_the_moon:sweptwood_log', 6), Item.of('under_the_moon:hollow_sweptwood_log', 2), Item.of('under_the_moon:cursed_acorn', 1), Item.of('under_the_moon:sweptwood_sapling').withChance(1.25)], 'under_the_moon:sweptwood_sapling')

    event.recipes.thermal.chiller('createaddition:iron_rod', [Fluid.of('kubejs:molten_iron', 100), 'thermal:chiller_rod_cast']).id('bttk:blast_chiller/iron_rod')
    event.recipes.thermal.chiller('createaddition:gold_rod', [Fluid.of('kubejs:molten_gold', 100), 'thermal:chiller_rod_cast']).id('bttk:blast_chiller/gold_rod')
    event.recipes.thermal.chiller('createaddition:copper_rod', [Fluid.of('kubejs:molten_copper', 100), 'thermal:chiller_rod_cast']).id('bttk:blast_chiller/copper_rod')
    event.recipes.thermal.chiller('createaddition:brass_rod', [Fluid.of('kubejs:molten_brass', 100), 'thermal:chiller_rod_cast']).id('bttk:blast_chiller/brass_rod')
    event.recipes.thermal.chiller('kubejs:zinc_rod', [Fluid.of('kubejs:molten_zinc', 100), 'thermal:chiller_rod_cast']).id('bttk:blast_chiller/zinc_rod')

    // Thermal Numismatics
    event.recipes.create.mechanical_crafting(Item.of('thermalnumismatics:trade_station'), [
        ' A ',
        'BCB',
        'DED'
    ], {
        A: '#forge:coins',
        B: 'minecraft:gold_block',
        C: 'kubejs:invar_machine',
        D: 'thermal:invar_gear',
        E: 'thermal:rf_coil'
    })

    // No free apples here!
    event.remove('thermalnumismatics:example')

    // KubeJS Additions
    event.shaped('kubejs:chiller_crystal_cast', [
        ' A ',
        'ABA',
        ' A '
    ], {
        A: 'thermal:bronze_plate',
        B: 'minecraft:emerald'
    })
    event.shaped('kubejs:chiller_compound_cast', [
        ' A ',
        'ABA',
        ' A '
    ], {
        A: 'thermal:bronze_plate',
        B: 'create:andesite_alloy'
    })
    event.shaped('kubejs:chiller_coin_cast', [
        ' A ',
        'ABA',
        ' A '
    ], {
        A: 'thermal:bronze_plate',
        B: 'thermal:gold_coin'
    })
})