AddCookerRecipe

`AddCookerRecipe(cooker, recipe, is_mod_food)`

## Description

This function adds a crockpot recipe to the game. If the result is not already a prefab, a prefab for it must be created.

## Parameters

* `cooker` - A string containing the type of cooker this recipe applies to. See below for possible values.
* `recipe` - A table containing several key/value pairs detailing the recipe itself. See below for more details on the recipe table.
* `is_mod_food` - A boolean set to true if used in a mod. If this value is set to false, or not set at all, it will likely crash the game due to an error with the game's cookbook functionality. It's notable that vanilla recipes commonly omit this value.

### `cooker`

The cooker parameter takes the name of a cooker as a string. There are four cookers currently available in the game:

* `cookpot` - Regular Crock Pot
* `portablecookpot` - Warly's Portable Crock Pot
* `portablespicer` - Warly's Portable Seasoning Station
* `archive_cookpot` - The Ancient Kiln found in the Ancient Archives. Functions identically to the Crock Pot

### `recipe`

Not to be confused with the Recipe function mentioned in API/AddRecipe. The `recipe` used as a parameter in this function is a table containing the following keys:

* `name` - Name of the output food item.
* `test` - A function that checks if the recipe is valid. Function should take cooker, names, and tags as parameters.
* `priority` - The recipe's priority. Higher priority recipes can override overlapping lower ones.
* `weight` - Not sure what weight does at the moment. Only defined in Butter Muffin recipe.
* `foodtype` - The type of food the result will be. Relevant for Meat/Veggie mechanics.
* `health` - The amount of health the food item restores. See `tuning.lua` for usable constants.
* `hunger` - The amount of hunger the food item restores. See `tuning.lua` for usable constants.
* `sanity` - The amount of sanity the food item restores. See `tuning.lua` for usable constants.
* `perishtime` - The time it takes for the food to spoil. Measured in seconds, however typically calculated in multiples of days. There are several constants in the TUNING class that define several perish durations, from 1 day to 40 days.
* `cooktime` - The amount of time it takes to finish cooking. Most likely measured in 20sec intervals. For example entering 1 would make the recipe cook for 20sec, 4 → 80 sec.
* `potlevel` - Determines the height at which the output recipe is displayed in the crockpot.
* `tags` - Food tags applied to resulting recipe. Such as "Meat" or "Veggie".
* `floater` - ?

## Examples

It's notable that any of the parameters can be defined within the parameters of the function call, or stored in a separate variable to be used in the parameter. In this example, the recipe will be defined in its own variable to make the code more readable.

The following is a valid way to define a recipe for Froggle Bunwich:

```
bunwich_recipe = {
    name = "frogglebunwich"
    test = function(cooker, names, tags) return (names.froglegs or names.froglegs_cooked) and tags.veggie end,
    priority = 1,
    weight = 1,
    foodtype = FOODTYPE.MEAT,
    health = TUNING.HEALING_MED,
    hunger = TUNING.CALORIES_LARGE,
    perishtime = TUNING.PERISH_SLOW,
    sanity = TUNING.SANITY_TINY,
    cooktime = 2,
    potlevel = "high",
    floater = {"med", nil, 0.55},
}
```

Note that the requirements for Froggle Bunwich is one Froglegs and one vegetable. Because of this, the test function first checks if froglegs or cooked froglegs are in the names table. It then checks if veggie is in the tags table, which it is if any vegetables are present. Also note that this is identical to the recipe found in `preparedfoods.lua`, except the name and weight keys were added here.

Once we have defined the recipe, we can use it in the **AddCookerRecipe** function.

```
AddCookerRecipe("cookpot", bunwich_recipe, true)
```

To keep Ancient Kiln consistent with the Crock Pot, we may want to add the recipe to that too:

```
AddCookerRecipe("archive_cookpot", bunwich_recipe, true)
```

*Note: Recipe changes for vanilla food items don't necessarily need is\_mod\_food to be true. It is strongly suggested you set it to true anyway.*

## Notes

* The definition of **AddCookerRecipe** can be found in `cooking.lua`.
* Vanilla recipes can be found in `preparedfoods.lua`.
* Warly's recipes can be found in `preparedfoods_warly.lua`.
* Constants for Food, Health, Sanity, and Time values can be found in `tuning.lua`
* When added recipes to be used in the crockpot, remember to also add them to the Ancient Kiln, as it's supposed to mirror the functionality of the crockpot.
* Adding modded recipes using just this function will result in the crockpot yielding the item, but it will not be visible in the crockpot. The fix for this will be added to another page later, but this forum post might help.
* Added recipes for new food items will require the creation of a new prefab, which will be addressed in another page.

## See Also

* modutil
* API/AddIngredientValues