Recipes
This is the full list of what the API gives you, one section for each part. Text in brackets at the end of a note is extra detail for experienced modders, and you can skip it on a first read.
Recipes looks up the game’s recipes, checks whether the player could make one, and unlocks one. Each recipe is a RecipeInfo, a snapshot of the recipe at the moment you asked. The snapshot does not update by itself, so ask again for fresh values.
Recipes look up, check and unlock recipes
Use it to look up recipes, check whether the player can make one, and give the player a recipe with Unlock.
public static class Recipes
{
public static event Action<RecipeUnlockedArgs> Unlocked;
public static List<RecipeInfo> All();
public static RecipeInfo Get(int recipeId);
public static List<RecipeInfo> Find(int itemId);
public static bool CanCraft(int recipeId);
public static bool CanCraftAt(int recipeId, CraftingStationInfo station);
public static bool MeetsSkill(int recipeId);
public static bool Unlock(int recipeId, bool notify = true);
public static bool IsAvailable { get; }
}
| Method | Returns | What it does |
|---|---|---|
All() | List<RecipeInfo> | Every recipe in the game. |
Get(recipeId) | RecipeInfo | One recipe. It is null when there is none. |
Find(itemId) | List<RecipeInfo> | Every recipe that makes this item. |
CanCraft(recipeId) | bool | true when the player has every ingredient. |
CanCraftAt(recipeId, station) | bool | true when this station can make the recipe. |
MeetsSkill(recipeId) | bool | true when the player’s skill is enough for the recipe. |
Unlock(recipeId, notify) | bool | Gives the player the recipe. Returns true when it was new. |
| Property | Type | What it means |
|---|---|---|
IsAvailable | bool | false when the Unlocked event could not be set up. |
| Event | Gives you | When it fires |
|---|---|---|
Unlocked | RecipeUnlockedArgs | The player just got a recipe. |
RecipeUnlockedArgs what Unlocked gives you
Recipes.Unlocked hands you one of these when the player gets a recipe. Learned tells you whether they learned it by crafting it.
public sealed class RecipeUnlockedArgs
{
public int RecipeId { get; }
public bool Learned { get; }
}
| Property | Type | What it means |
|---|---|---|
RecipeId | int | The recipe that was unlocked. |
Learned | bool | false when the recipe was collected. true when the player learned it by crafting it for the first time. |
RecipeInfo a snapshot of one recipe
Recipes.All(), Recipes.Get and Recipes.Find give you these. Use Ingredients and RequiredConditions to see what a recipe needs.
public sealed class RecipeInfo
{
public int Id { get; }
public string Name { get; }
public string Station { get; }
public int ProcessSeconds { get; }
public string Skill { get; }
public int MinimumSkill { get; }
public bool RequiresUnlock { get; }
public bool Known { get; }
public List<RecipeIngredient> Ingredients { get; }
public List<ItemCount> Results { get; }
public List<ItemCount> FailResults { get; }
public List<string> RequiredConditions { get; }
public List<string> ExcludingConditions { get; }
public float BaseFailChance { get; }
public bool HardMinimumSkill { get; }
}
| Property | Type | What it means |
|---|---|---|
Id | int | The recipe’s number in the game’s recipe list. |
Name | string | The name the game shows. |
Station | string | The kind of station that makes it, such as "Stove", "Oven" or "Basic". |
ProcessSeconds | int | How many seconds it takes at the start, before the game’s speed and skill changes. |
Skill | string | The skill it uses, such as "Cooking". |
MinimumSkill | int | The skill level the recipe asks for. |
RequiresUnlock | bool | true when the player must collect or learn the recipe first. |
Known | bool | true when the player has collected or learned it, when you asked. |
Ingredients | List<RecipeIngredient> | The items the recipe needs. |
Results | List<ItemCount> | What comes out when the craft works. |
FailResults | List<ItemCount> | What comes out when the craft fails. |
RequiredConditions | List<string> | Conditions the station must have, such as Clean or Industrial. |
ExcludingConditions | List<string> | Conditions the station must not have, such as Dirty or Infested. |
BaseFailChance | float | The chance of failing before skill and equipment change it. |
HardMinimumSkill | bool | true when the player can’t try below the minimum skill at all. |
RecipeIngredient one thing a recipe uses up
Each entry in RecipeInfo.Ingredients is one of these. Count is how many the recipe needs, and Consumed is always true.
public sealed class RecipeIngredient
{
public int ItemId { get; }
public float Count { get; }
public bool Consumed { get; }
}
| Property | Type | What it means |
|---|---|---|
ItemId | int | The item’s number in the game. |
Count | float | How many it needs. |
Consumed | bool | Always true. The ingredient is used up. |
ItemCount an amount of one item
RecipeInfo.Results, RecipeInfo.FailResults, CraftedArgs.Results and PlantHarvestArgs.Items hold these. Count can be fractional, as it is for a liquid.
public sealed class ItemCount
{
public int ItemId { get; }
public float Count { get; }
}
| Property | Type | What it means |
|---|---|---|
ItemId | int | The item’s number in the game. |
Count | float | How many. It can be fractional, for example 0.4 for a liquid. |
Things to know
All()lists every recipe, in the game’s own order.Get(recipeId)returns the first recipe with that number. Two numbers in the game’sRecipes.jsonare used twice, and the first one wins. (Allreturns every recipe inRecipeDatabase.Recipes.Getreturns the same one the game’sFetchRecipesByIdreturns.)Find(itemId)lists the recipes whose successful results include that item.CanCraft(recipeId)says whether the player has every ingredient, and nothing else. It looks at the player’s backpack and the items they carry. It does not check whether the player knows the recipe, and it does not look inside the storage of a workbench. (It uses the game’sCraftingBaseHelperFunctions.StorageHasRequiredItemson the player’s inventory (backpack and character slots included).)CanCraftAt(recipeId, station)says whether one particular station can make the recipe. It istruewhen the station makes that kind of recipe and has the conditions the recipe needs and none it forbids.- Use a station from
Crafting.All()or a craft event, so two stations of the same kind are told apart. It returnsfalsewhen the station has been destroyed. It does not check the ingredients (useCanCraft), the skill (useMeetsSkill) or whether the recipe is known. (The station’sRecipesWithUpgradesmust contain the recipe’s type, and itsModifiersWithUpgradesmust satisfy the recipe’s required and excluding conditions (RecipeInfoUI.CheckModifiers).) MeetsSkill(recipeId)says whether the player’s skill is enough, using the game’s gentle check. It istruewhen the player’s skill reachesMinimumSkill. It is alsotruewhen the skill is short but the game’s chance of failing is still below 100 percent andHardMinimumSkillisfalse. It returnsfalsewhen no player is loaded. (It is the game’s soft skill check (RecipeInfoUI.CheckSkillSoft, equipment quality 1). A framework tweak that patchesCheckSkillSoft(src/TweaksCrafting.cs) changes the result.)Unlock(recipeId, notify)gives the player the recipe, the same way the game’s own scripts do. It returnsfalsewhen the player already knows the recipe, when no save is loaded, when the number is unknown, and while a save is loading or being written. Withnotifyset totrue(the default) the game shows its “New recipe” notice. Passfalseto unlock silently. (It callsRecipeController.AddRecipe, the same call the game’sGiveRecipeLua function makes.)Knownis a snapshot. Ask for the recipe again afterUnlockto see the new value.Unlockedfires when the player gets a recipe.Learnedisfalsewhen the recipe was collected: from a pickup, a book, mail, a readable item, a task item, a game script, or your ownUnlock.Learnedistruewhen the player crafted the recipe for the first time at a manufacturing station. (It fires inside the game’sRecipeController.AddRecipe. The game keeps the collected and learned lists separately andIsKnowncounts either, so a recipe that was collected and is then crafted for the first time fires a second event for the same id withLearnedtrue. The first-craft event fires once for each recipe, because later crafts find the recipe already learned.)Unlockeddoes not fire while a save is loading or being written. It only fires on your own computer, and it is not sent to other players in a multiplayer game.- Your handler runs inside the game’s own call, so keep it short. Do not wait or block in it. A handler that calls
Unlockfor the same recipe getsfalseand does not start a loop. IsAvailabletells you whetherUnlockedworks. It isfalsewhen the framework could not set up the event, or when its feature group was turned off. The reads andUnlockkeep working.
Limits
MeetsSkillis not a roll. The real chance of failing depends on skill, alcohol and equipment, and the framework can’t read it.