// priority: 0

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

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

ServerEvents.recipes(event => {
    let mechanicalExtractionRecipe = (input, result, count, count1, count2, chance, chance1, chance2, timeToProcess) => {
        event.custom({
            type: `garnishedstoneautomation:extracting`,
            ingredients: [
                {
                    item: input
                }
            ],
            processingTime: timeToProcess,
            results: [
                {
                    chance: chance,
                    item: result,
                    count: count
                },
                {
                    chance: chance1,
                    item: result,
                    count: count1
                },
                {
                    chance: chance2,
                    item: result,
                    count: count2
                }
            ]
        })
    }

    let extractionAlternativeSiftingRecipe = (mesh, input, timeToProcess, chance, result, count) => {
        event.custom({
            type: "createsifter:sifting",
            ingredients: [
                {
                    item: mesh
                },
                {
                    item: input
                }
            ],
            processingTime: timeToProcess,
            results: [
                {
                    chance: chance,
                    item: result,
                    count: count
                }
            ]
        })
    }

    event.recipes.garnished.freezing('hibernalherbs:myqueste_sapling', '#minecraft:saplings', 200).id('bttk:freezing/myqueste_sapling_from_sapling')
    event.recipes.garnished.freezing(['hibernalherbs:dried_calendula', Item.of('hibernalherbs:dried_calendula', 1).withChance(0.45)], 'hibernalherbs:pounded_calendula', 200).id('bttk:freezing/dried_calendula_from_pounded_calendula')

    event.remove('hibernalherbs:compat/create/milling/herbs_to_dyes/red')
    //event.remove('hibernalherbs:compat/create/milling/pounded_herbs_to_dyes/red')
    event.remove('hibernalherbs:compat/create/milling/herbs_to_dyes/orange')
    //event.remove('hibernalherbs:compat/create/milling/pounded_herbs_to_dyes/orange')
    event.remove('hibernalherbs:compat/create/milling/herbs_to_dyes/yellow')
    //event.remove('hibernalherbs:compat/create/milling/pounded_herbs_to_dyes/yellow')
    event.remove('hibernalherbs:compat/create/milling/herbs_to_dyes/lime')
    //event.remove('hibernalherbs:compat/create/milling/pounded_herbs_to_dyes/lime')
    event.remove('hibernalherbs:compat/create/milling/herbs_to_dyes/green')
    //event.remove('hibernalherbs:compat/create/milling/pounded_herbs_to_dyes/green')
    event.remove('hibernalherbs:compat/create/milling/herbs_to_dyes/cyan')
    //event.remove('hibernalherbs:compat/create/milling/pounded_herbs_to_dyes/cyan')
    event.remove('hibernalherbs:compat/create/milling/herbs_to_dyes/blue')
    //event.remove('hibernalherbs:compat/create/milling/pounded_herbs_to_dyes/blue')
    event.remove('hibernalherbs:compat/create/milling/herbs_to_dyes/purple')
    //event.remove('hibernalherbs:compat/create/milling/pounded_herbs_to_dyes/purple')
    event.remove('hibernalherbs:compat/create/milling/herbs_to_dyes/white')
    //event.remove('hibernalherbs:compat/create/milling/pounded_herbs_to_dyes/white')
    
    let herbs = ["calendula", "rosemary", "thyme", "tarragon", "chamomile", "chives", "verbena", "sorrel", "marjoram", "chervil", "fennsel", "ceillis", "punuel", "essitte", "fennkystral", "thyocielle", "sage"]
    herbs.forEach(i => {
        // event.recipes.thermal.insolator([Item.of(`garnished:ungarnished_${i}`, 4), Item.of(`garnished:ungarnished_${i}`, 1), Item.of('garnished:nut_log', 6), Item.of('minecraft:apple', 1).withChance(0.05)], `garnished:cracked_${i}`).id(`kubejs:${i}_from_insolator`)
        // event.recipes.create.milling([Item.of(`hibernalherbs:pounded_${i}`, 2), Item.of(`hibernalherbs:pounded_${i}`, 1).withChance(0.35)], `hibernalherbs:${i}`).id(`bttk:milling/pounded_${i}`)
        event.recipes.create.mixing(Item.of(`hibernalherbs:dried_${i}`, 2), ['hibernalherbs:dried_calendula', `hibernalherbs:pounded_${i}`, 'thermal:blizz_powder']).superheated().id(`bttk:mixing/superheated/dried_${i}`)

        event.recipes.thermal.insolator([Item.of(`hibernalherbs:${i}`, 2)], `hibernalherbs:pounded_${i}`).id(`kubejs:${i}_from_insolator`)
        event.recipes.thermal.pulverizer([Item.of(`hibernalherbs:pounded_${i}`, 2), Item.of(`hibernalherbs:pounded_${i}`, 1).withChance(0.50)], `hibernalherbs:${i}`)
    });

    mechanicalExtractionRecipe('hibernalherbs:myqueste_log', 'kubejs:myqueste_catalyst', 2, 2, 1, 0.85, 0.05, 0.1, 200)
    extractionAlternativeSiftingRecipe('createsifter:andesite_mesh', 'hibernalherbs:myqueste_log', 200, 0.45, 'kubejs:myqueste_catalyst', 1)
    event.remove('hibernalherbs:fertilizer/herb_fertilizer_myqueste')
    event.shapeless('2x hibernalherbs:herb_fertilizer_myqueste', ['2x minecraft:bone_meal', 'hibernalherbs:herb_humus_myqueste'])
    event.recipes.create.deploying('hibernalherbs:herb_humus_myqueste', ['hibernalherbs:herb_humus', 'kubejs:myqueste_catalyst']).id('bttk:deploying/herb_humus_myqueste')
    let tree_types = ["oak", "spruce", "dark_oak", "acacia", "birch", "jungle", "mangrove", "cherry"]
    tree_types.forEach(i => {
        mechanicalExtractionRecipe(`minecraft:${i}_log`, `kubejs:${i}_catalyst`, 2, 2, 1, 0.85, 0.05, 0.1, 200)
        extractionAlternativeSiftingRecipe('createsifter:andesite_mesh', `minecraft:${i}_log`, 200, 0.45, `kubejs:${i}_catalyst`, 1)
        event.recipes.create.deploying(`hibernalherbs:herb_humus_${i}`, ['hibernalherbs:herb_humus', `kubejs:${i}_catalyst`]).id(`bttk:deploying/herb_humus_${i}`)

        event.remove(`hibernalherbs:fertilizer/herb_fertilizer_${i}`)
        event.shapeless(`2x hibernalherbs:herb_fertilizer_${i}`, ['2x minecraft:bone_meal', `hibernalherbs:herb_humus_${i}`])
    })
    let stem_types = ["crimson", "warped"]
    stem_types.forEach(i => {
        mechanicalExtractionRecipe(`minecraft:${i}_stem`, `kubejs:${i}_catalyst`, 2, 2, 1, 0.85, 0.05, 0.1, 200)
        extractionAlternativeSiftingRecipe('createsifter:andesite_mesh', `minecraft:${i}_stem`, 200, 0.45, `kubejs:${i}_catalyst`, 1)
        event.recipes.create.deploying(`hibernalherbs:herb_humus_${i}`, ['hibernalherbs:herb_humus', `kubejs:${i}_catalyst`]).id(`bttk:deploying/herb_humus_${i}`)

        event.remove(`hibernalherbs:fertilizer/herb_fertilizer_${i}`)
        event.shapeless(`2x hibernalherbs:herb_fertilizer_${i}`, ['2x minecraft:bone_meal', `hibernalherbs:herb_humus_${i}`])
    })

    let sins = ["pride", "envy", "greed", "gluttony", "sloth", "wrath", "lust"]
    sins.forEach(i => {
        event.remove(`hibernalherbs:conjuration/trinket/padlocks/${i}_padlock`)
        event.recipes.create.mechanical_crafting(Item.of(`hibernalherbs:padlock_${i}`), [
            'BAB',
            'CDC',
            'AEA'
        ], {
            A: 'minecraft:iron_ingot',
            B: 'hibernalherbs:sin_petals',
            C: 'kubejs:hellish_essence_bucket',
            D: `hibernalherbs:${i}_herb`,
            E: `hibernalherbs:sigil_${i}`
        })
        let incompleteBoundPadlock = `kubejs:incomplete_${i}_bound_padlock`
        event.remove(`hibernalherbs:conjuration/trinket/padlocks/bound/${i}_padlock`)
        event.recipes.create.sequenced_assembly([
            Item.of(`hibernalherbs:bound_padlock_${i}`, 1)
        ], `hibernalherbs:padlock_${i}`, [
            event.recipes.create.deploying(incompleteBoundPadlock, [incompleteBoundPadlock, 'hibernalherbs:julisium_petals']),
            event.recipes.create.filling(incompleteBoundPadlock, [incompleteBoundPadlock, Fluid.of('kubejs:hellish_essence', 500)])
        ]).transitionalItem(incompleteBoundPadlock).loops(3).id(`bttk:sequenced_assembly/bound_padlock/${i}`)
    })
})