Adding recipes

We've covered how to create our own items in this previous section. Of course, you can add whichever components you want for those items and, if you create the models from scratch, make sure to check the modeling guide and the guide on collision regions so that your models are correctly exported and aligned in the world. Here's how to change the scale of an item too, if you need it.

In this other guide we cover how to add your own crafting job to the game.

Steps to add a recipe to an existing crafter from the stonehearth mod

  1. Decide which existing crafter will craft the item.

  2. Create a recipe for the item.

  3. Add a mixinto to integrate the new recipe in the recipes list of that crafter.

  4. Test that the crafter can craft the item.

Let's get started. We're going to add a recipe for the custom table that we created in a previous example in the startermod_basic mod. We'll make the mason craft it.

Anatomy of a recipe

Let's copy the recipe of the "table_for_one" of the carpenter and adjust its values to reference our custom table and our mod's localization file. It is located inside stonehearth\jobs\carpenter\recipes. We'll call our file custom_table_recipe.json. Let's also add some extra fields that we can encounter in recipes:

  {
     "type": "recipe",
     "effort": 30,
     "work_units": 3,
     "recipe_name": "i18n(startermod_basic:jobs.mason.recipes.custom_table_recipe.recipe_name)",
     "description": "i18n(startermod_basic:jobs.mason.recipes.custom_table_recipe.description)",
     "flavor": "i18n(startermod_basic:jobs.mason.recipes.custom_table_recipe.flavor)",
     "portrait": "/startermod_basic/entities/furniture/custom_table/custom_table.png",
     "level_requirement" : 2,
     "workshop": "stonehearth:mason:workbench",
     "ingredients": [
        {
           "material": "stone resource",
           "count": 1
        }
     ],
     "produces": [
        {
           "item": "startermod_basic:furniture:custom_table"
        }
     ]
  }

Explanation of the fields:

iconIf we don't add the "workshop" field to the recipe file, the crafter will craft the item with their hands instead. This is normally used to craft the initial workbenches.

Using generic resources means that the crafter can use any item that counts as that resource (wood from any type of tree, for example). Remember to prefix the alias of the items with the namespace of the mod plus a colon. The "count" field of the ingredients is self-explanatory.

We can also make the recipe produce several different items with that method, simply writing different URIs.

Adding the recipe to the recipes list

We need to create a mixinto for the recipe list. We'll take the keys from the stonehearth/jobs/mason/recipes/recipes.json file:

  {
     "craftable_recipes" : {
        "furniture" : {
           "recipes" : {
              "custom_table_recipe" : {
                 "recipe" : "file(custom_table_recipe.json)"
              }
           }
        }
     }
  }

In this case, we're reusing an existing category from the mason's recipes (furniture). If we wanted to add our recipes in a new category of our own (that will be displayed separately in the recipes list from the workshop's UI), we'd need to add two more fields to our mixinto. Example:

  {
     "craftable_recipes" : {
        "custom_category" : {
           "ordinal": 80,
           "name": "i18n(startermod_basic:jobs.mason.recipes.custom_category_name)",
           "recipes" : {
              "custom_table_recipe" : {
                 "recipe" : "file(custom_table_recipe.json)"
              }
           }
        }
     }
  }

There, "custom_category" is an identifier for the recipes group. "ordinal" is a number used to order the groups in the UI, which ones will be before the other ones (if two categories have the same ordinal, the game will choose one of them to go first, it's not deterministic which one will win). And the "name" is a localized name for the group, which will be displayed in the workshop UI for that category.

Then, don't forget to add our mixinto to the mod's manifest (remember to add commas where needed):

  ...
  "mixintos" : {
     "stonehearth/jobs/mason/recipes/recipes.json" : "file(recipes/recipes.json)"
  }
  ...

icon If you add a custom crafting job, the recipes for it won't need to be added via a mixinto, but rather via a property of a component.

Lastly, let's test that the mason can craft our recipe using debugtools:

Using SHED to add recipes

As explained in the creating items section, we can create an item and a recipe for it in one step. Otherwise, we can uncheck any unwanted files that we don't want to create from the clone popup, leaving only the recipe file checked.

icon At the time this guide was written, cloning the recipes list or single recipes from an existing job from the base mods won't make them appear in the tree view for our mod, and we'll need to edit them outside of SHED. Of course, the mixintos also have to be set up outside of SHED. If we clone the recipe with the item that it produces, the item will be shown in the tree view since an alias will be created, so we'll be able to edit it within SHED.