Recipes
This page uses Sprite from Unity. The glossary says what each one is.
A recipe definition says which existing recipe to copy and what is different. Leave a field out to keep the template’s.
RecipeRegistry adds recipes
Use Define to add a recipe based on an existing one. IdFor gives the number a key will have before you define it.
public static class RecipeRegistry
{
public static bool IsAvailable { get; }
public static int IdFor(string modGuid, string key);
public static int Define(string modGuid, string key, RecipeDefinition definition);
}
| Method | Returns | What it does |
|---|---|---|
IdFor(modGuid, key) | int | The number a key will have. |
Define(modGuid, key, definition) | int | Adds a recipe. Returns its number, or -1 when refused. |
| Property | Type | What it means |
|---|---|---|
IsAvailable | bool | false when the registry could not be set up. |
RecipeDefinition what your new recipe is based on and what is different
Pass one of these to RecipeRegistry.Define. TemplateRecipeId, Name, Station, Inputs and Outputs are required.
public sealed class RecipeDefinition
{
public int TemplateRecipeId;
public string Name;
public string Station;
public Dictionary<int, float> Inputs = new Dictionary<int, float>();
public Dictionary<int, float> Outputs = new Dictionary<int, float>();
public Dictionary<int, float> OutputsOnFail = new Dictionary<int, float>();
public int ProcessTime;
public int MinimumSkill;
public bool HardMinimumSkill;
public Skill RelevantSkill;
public float FailChance = 0.2f;
public bool RecipeRequired;
public List<string> RecipeTags;
}
| Property | Type | What it means |
|---|---|---|
TemplateRecipeId | int | The number of the existing recipe to copy. Required. |
Name | string | The recipe’s name. Required. |
Station | string | The station that makes it, such as Stove or Oven. Required. |
Inputs | Dictionary<int, float> | The items it uses: item number and amount. At least one. |
Outputs | Dictionary<int, float> | The items it makes: item number and amount. At least one. |
OutputsOnFail | Dictionary<int, float> | The items you get when it fails. May be empty. |
ProcessTime | int | How long it takes, in seconds. |
MinimumSkill | int | The skill level the recipe wants. Below it the chance of failing is higher. |
HardMinimumSkill | bool | true if the player cannot craft it at all below that skill level. |
RelevantSkill | Skill | The skill the recipe uses. |
FailChance | float | The chance it fails, from 0 to 1. |
RecipeRequired | bool | true if the recipe stays hidden until the player learns it. |
RecipeTags | List<string> | Labels for the recipe. null keeps the template’s. |
Things to know
TemplateRecipeIdis required, and is the number of an existing recipe. A mod recipe used as a template must be defined earlier.Nameis required, 1 to 200 characters.Stationis the name of the station that makes the recipe, such asStove,OvenorMashing. Capital letters do not matter.Noneand names that do not exist throw an error. Stations list their recipes by this value. (The name is asRecipes.Get(id).Stationreports it.)InputsandOutputsare required, with at least one entry each. Each key is an item number of 0 or more. Each amount is above 0 and at most 1000000.OutputsOnFailis optional.ProcessTimeis in seconds, 0 to 10000000.MinimumSkillis 0 to the highest skill level.RelevantSkillis aSkillvalue, andSkill.Noneis allowed.FailChanceis 0 to 1. (The highest skill level isSkills.MaxLevel.)RecipeTagscan have up to 16 entries of 1 to 64 characters each. Usenullto keep the template’s tags.- These things are copied from the template: the conditions that must or must not hold, the variant settings, whether only stolen items are used, which items are allowed when they are not stolen, and whether the item owner is kept on failure. (It copies the required and excluding conditions, the variant fields,
useOnlyStolenItems,allowedNonStolenItemsIds,keepItemOwnerOnFail,disableJunkSpawn,SkillFactor,SkillGainFactor,Metaand the sprite.) - Also copied from the template: whether junk is spawned, the skill factors, the extra data and the picture. The settings for extra data of the result are new defaults, not the template’s. (
metaSettingsis a new default, not the template’s.) - Added recipes live in the game’s memory only. The game’s recipe file is not changed. (They live in
RecipeDatabase.Recipes.Recipes.jsonis not written.)
Limits
- A recipe is added only when its template exists and every item in it exists. That covers
Inputs,OutputsandOutputsOnFail. - A recipe with a missing item is not added, and an error goes to the log, because a partial recipe could give free items.