Skip to content

How to create a recipe through JSON

Khanx edited this page Feb 1, 2021 · 2 revisions

The easiest way to create a recipe is by means of JSON files

There are two types of recipes: player recipe & NPC recipe The player's recipe is a recipe that the player can make (in the stockpile menu), while the NPC's recipe is the one that a colonist can make (in a job).

Before creating a type you need a modInfo.json file that indicates the information of your mod and the location of the JSON file in which you are creating the types. Without the modInfo.json file the mod will not work.

In the modInfo.json file it is necessary to indicate in the "jsonFiles" key the location of this JSON file, which will be of type addNewTypes.

Example of modInfo.json file from the Sign mod:

[
	{
		"name": "Sign",
		"version": "0.1.1.3",
		"enableddefault": true,
		"description": "The player will able to place signs with text.",
		"dllpath": "Sign.dll",
		"compatibleversions":
			[
				"0.8.0"
			],
		"jsonFiles" : [
			{
				"fileType" : "addOrReplacePlayerRecipes",
				"relativePath" : "./autoload/player_recipes.json",
				"index" : -1000000,
			},
			{
				"fileType" : "addOrReplaceNPCRecipes",
				"relativePath" : "./autoload/npc_recipes.json",
				"index" : -1000000,
				"limitsUIMapping" : [
					"workbench"
				],
				"npcType" : "pipliz.crafter"
	}
		]
	}
]

This modInfo.json file indicates that the JSON file used to create the player's recipe is located in "./autoload/recipes.json"

The file also indicates that the JSON file used to create the npc's recipe (in this case for the pipliz.crafter npc and that is showed when the player interacts with the workbench type) is located in "./autoload/npc_recipes.json"

An extract JSON file used by the Sign mod to add the Sign recipe to the player is shown below (npc's recipe file is the same):

[
	{
		"defaultLimit" : 0,
		"defaultPriority" : -100,
		"name" : "Khanx.player.Sign",
		"requires" : [
			{"amount":2,"type":"planks"},
			{"type":"coppertools"},
			{"amount":3,"type":"coppernails"}
		],
		"results" : [
			{"type":"Khanx.Sign"}
		]
	}
]

If you want to make that the recipe is unlocked by a research, you have to add in the JSON recipe: "isOptional" : true

More examples of JSON files that adds types: