AddRecipe

NOTE: As of the 2.44 DST update released April 26, 2022, this function has been deprecated, and replaced by AddRecipe2.

`AddRecipe(name, ingredients, tab, level, placer_or_more_data=nil, min_spacing=nil, nounlock=nil, numtogive=nil, builder_tag=nil, atlas=nil, image=nil, testfn=nil, product=nil, build_mode=nil, build_distance=nil)`

## Description

AddRecipe adds a crafting recipe to the game. Can be used to add crafting recipes for existing prefabs, override recipes for existing prefabs, and add crafting recipes for new prefabs.

## Parameters

* `name` - The name of the recipe's entry in the game's table of crafting recipes. If the product parameter is omitted (which it typically is), this is also the name of the output of the crafting recipe. If this is the name of a prefab, the ingredients of this recipe determines what it will drop when deconstructed via the Deconstruction Staff.
* `ingredients` - A list of ingredients used to craft the product. Each of these are ingredient objects, for more details see below.
* `recipe_tab` - The crafting tab in which this recipe will be added. Use a constant found in `GLOBAL.RECIPETABS`. This can be found in `constants.lua`. For adding new recipe tabs, see API/AddRecipeTab
* `tech_level` - Determines what kind of crafting structure is needed to access this recipe.
* `placer_or_more_data` (optional) - Accepts a "placer" string. Used to allow the player to place a newly crafted building. Can also accept a table with key/value pairs. Currently used values are "placer" and "no\_deconstruction". See below for more details.
* `min_spacing` (optional) - The minimum spacing between the object being placed and other obstructions. Default is nil, which sets the value to 3.2.
* `nounlock` (optional) - If true, the player cannot permanently unlock the recipe. Most commonly associated with recipes in the Ancient Tab. Default is nil, which sets nounlock to false.
* `numtogive` (optional) - The quantity of the product that results from the crafting recipe. Default is nil, which provides 1 item in the result.
* `builder_tag` (optional) - Defines the tag a character is required to have to access this recipe. Used to restrict crafting recipes to specific characters.
* `atlas` (optional) - An atlas file that positions the image.
* `image` (optional) - An image to override the crafting result's image.
* `testfn` (optional) - A function that returns true if the object can be placed, false otherwise. Used for buildings with special placement restrictions.
* `product` (optional) - A string with the name of the output prefab for the recipe. If left as nil, the first parameter is used instead. Allows one to make multiple crafting recipes with the same output.
* `build_mode` (optional) - TODO
* `build_distance` (optional) - TODO

### `Ingredient(ingredient_name, amount, atlas="")`

Defines an ingredient to be used in a crafting recipe, and how much of it is needed. This object can be stored in a variable, or placed directly in the `AddRecipe()` function call as a parameter.

For example, Rope is crafted with 3 grass in the Refine Tab. This means the ingredient list would be: `{Ingredient("grass", 3)}`.

### `placer_or_more_data`

The placer is a string representing what structure a prefab will place. It is defined in a prefab file using the MakePlacer function.

It is also important to note that it is also possible to pass a table to this parameter with key/value pairs. Currently used keys are "placer" and "no\_deconstruction". This is used with Walter's Slingshot Ammo, where the placer is defined as: `{no_deconstruction = true}`. This prevents the slingshot ammo from being deconstructed by the Deconstruction Staff. This can be found in `recipes.lua`, near the text "SLINGSHOT AMMO". The table also accepts "placer" which is associated with the parameter's original input.

## Vanilla Examples

The AddRecipe function will be available in modmain.lua by default, without needing to use GLOBAL. Note that in `recipes.lua` the original recipes use Recipe(), however these examples will use AddRecipe, which is how modders are intended to call the function.

`AddRecipe("spear", {Ingredient("twigs", 2), Ingredient("rope", 1), Ingredient("flint", 1) }, RECIPETABS.WAR, TECH.SCIENCE_ONE)`
This function call will accomplish the following things:
* It will produce a prefab with id "spear"
* It will require 3 ingredients to craft: 2 twigs, 1 rope and 1 flint
* It will be placed into WAR tab, which is referred to the Fight Tab in-game.
* It will be available to the player when they can access Tech Level TECH.SCIENCE\_ONE, which happens when the player stands next to a science machine.

`AddRecipe("icebox", {Ingredient("goldnugget", 2), Ingredient("gears", 1), Ingredient("cutstone", 1)}, RECIPETABS.FARM, TECH.SCIENCE_TWO, "icebox_placer", 1.5)`
Here we notice two extra parameter calls that were not present in the previous example:
* "icebox\_placer" is the placer object associated with placing the Ice Box. This is defined with the Ice Box in the Ice Box's prefab file, found in `scripts/prefabs/icebox.lua`. It tells the game to prompt the player to place the Ice Box structure. More information on placers can be found in MakePlacer.
* The value 1.5 is defined for the min\_spacing parameter for the Ice Box. By default the spacing is 3.2, so the Ice Box can be placed closer to other structures than placers with the default spacing like the Crock Pot.

`AddRecipe("slingshotammo_thulecite", {Ingredient("thulecite_pieces", 1), Ingredient("nightmarefuel", 1)}, CUSTOM_RECIPETABS.SLINGSHOTAMMO, TECH.ANCIENT_TWO, {no_deconstruction = true}, nil, true, 10, "pebblemaker")`
Here we notice quite a few differences from the previous two crafting recipes.
* CUSTOM\_RECIPETABS is used instead of RECIPETABS for Walter's Ammo Tab. These are separate simply to separate normal crafting tabs from player-exclusive ones.
* For the parameter placer\_or\_more\_data, a table is passed instead of the name of a placer. This table contains the key "no\_deconstruction" with the value "true". This makes it so the Cursed Rounds cannot be deconstructed by a Deconstruction Staff.
* For the nounlock parameter, a true value is passed. Like all recipes from the Ancient Tab, this recipe can only be crafted when a player is standing next to the ancient pseudoscience station, and will not be saved after crafting it.
* A value of 10 is passed to the `numtogive parameter. This will provide a quantity of 10 pebbles upon crafting.`
* Finally, we see the string "pebblemaker" passed into the builder\_tag parameter. This makes it so only characters with the tag "pebblemaker" can use this crafting recipe, which is only Walter.

## Custom Recipe Examples

TODO Examples to be written here:

* Replacing a Vanilla Recipe
* Two Recipes one output
* Recipe for new prefab

### Notes

* Recipe is a deprecated function that functions identically to AddRecipe.
* Since AddRecipe wraps Recipe, its definition can be found in `recipe.lua`, in the Recipe class.
* Examples of this function can be found in `recipes.lua`, but it uses the since-deprecated Recipe function.
* While it is possible to have two recipes that produce the same product, only one recipe can define what the output deconstructs to. Whichever recipe whose name matches the product's prefab name, will be used to determine the deconstruction results.

## See Also

* modutil
* API/AddRecipeTab
* API/MakePlacer