ServerEvents.recipes(event => {
    function addContainerIngredient(ingredients, container) {
        const item = container.item ?? container.id ?? container.containerId
        if (!item) return ingredients

        return ingredients.concat([{ item: item }])
    }

    function addBottledPotAndMixingRecipe(recipeId, result, ingredients) {
        const container = { item: 'minecraft:glass_bottle' }

        event.custom({
            type: 'farmersdelight:cooking',
            container: container,
            cookingtime: 200,
            experience: 0.35,
            ingredients: ingredients,
            recipe_book_tab: 'meals',
            result: result
        }).id(`kubejs:fd_pot/${recipeId}`)

        event.custom({
            type: 'create:mixing',
            heatRequirement: 'heated',
            ingredients: addContainerIngredient(ingredients, container),
            results: [
                result
            ],
            processingTime: 200
        }).id(`kubejs:mixing/farmersdelight_pot/${recipeId}`)
    }

    event.remove({ id: 'croptopia:olive_oil' })
    event.remove({ id: 'croptopia:shaped_peanut_butter' })
    event.remove({ id: 'croptopia:campfire_molasses' })
    event.remove({ id: 'croptopia:molasses_from_smoking_sugar_cane' })
    event.remove({ id: 'croptopia:molasses_from_sugar_cane' })

    addBottledPotAndMixingRecipe(
        'croptopia_olive_oil',
        { item: 'croptopia:olive_oil' },
        [
            { tag: 'forge:olives' },
            { tag: 'forge:olives' },
            { tag: 'forge:olives' }
        ]
    )

    addBottledPotAndMixingRecipe(
        'croptopia_peanut_butter',
        { item: 'croptopia:peanut_butter', count: 4 },
        [
            { tag: 'forge:peanuts' },
            { tag: 'forge:peanuts' },
            { tag: 'forge:peanuts' },
            { tag: 'forge:peanuts' }
        ]
    )

    addBottledPotAndMixingRecipe(
        'croptopia_molasses',
        { item: 'croptopia:molasses' },
        [
            { item: 'minecraft:sugar_cane' },
            { item: 'minecraft:sugar_cane' }
        ]
    )
})
