Views
Actions
Difference between revisions of "Recipes"
(Inital Import doku wiki) |
(Categorize with Category:Resources and Data by SizableShrimp#0755) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | With the update to Minecraft 1.12, Mojang introduced a new data-driven recipe system based on JSON files. Since then it has been adopted by Forge as well and was expanded in Minecraft 1.13 into [ | + | With the update to Minecraft 1.12, Mojang introduced a new data-driven recipe system based on JSON files. Since then, it has been adopted by Forge as well and was expanded in Minecraft 1.13 into [[datapacks]]. |
== Loading Recipes == | == Loading Recipes == | ||
− | Forge will load all recipes | + | Forge will load all recipes found within the <code><nowiki>./resources/data/<modid>/recipes/</nowiki></code> folder of your mod. You can call these files whatever you want, though the vanilla convention is to name them after the output item. For multiple recipes from different sources (smelting, crafting, etc) one vanilla convention is to use <code><nowiki>item_name_from_smelting.json</nowiki></code>. This name is also used as the registration key but does not affect the operation of the recipe. |
− | == The Recipe | + | == The Recipe File == |
A basic recipe file might look like the following example: | A basic recipe file might look like the following example: | ||
<syntaxhighlight lang="json"> | <syntaxhighlight lang="json"> | ||
Line 11: | Line 11: | ||
"pattern": | "pattern": | ||
[ | [ | ||
− | " | + | "XXX", |
− | " | + | "XAX", |
− | " | + | "XXX" |
], | ], | ||
"key": | "key": | ||
{ | { | ||
− | " | + | "X": |
{ | { | ||
"tag": "forge:gems/diamond" | "tag": "forge:gems/diamond" | ||
}, | }, | ||
− | " | + | "A": |
{ | { | ||
− | "item": "mymod:myfirstitem" | + | "item": "mymod:myfirstitem" |
} | } | ||
}, | }, | ||
"result": | "result": | ||
{ | { | ||
− | "item": "mymod: | + | "item": "mymod:myseconditem", |
− | "count": 9 | + | "count": 9 |
} | } | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | {{Colored box|title=Tip|content=When you first obtain an ingredient to a vanilla recipe it will automatically unlock the recipe in the recipe book. To achieve the same effect, you have to use the <code><nowiki>Advancement</nowiki></code> system and create a new <code><nowiki>Advancement</nowiki></code> for each of your ingredients. | + | {{Colored box|title=Tip|content=When you first obtain an ingredient to a vanilla recipe, it will automatically unlock the recipe in the recipe book. To achieve the same effect, you have to use the <code><nowiki>Advancement</nowiki></code> system and create a new <code><nowiki>Advancement</nowiki></code> for each of your ingredients. |
<br><br> | <br><br> | ||
The advancement has to exist. This doesn’t mean it has to be visible in the advancement tree.}} | The advancement has to exist. This doesn’t mean it has to be visible in the advancement tree.}} | ||
+ | === Groups === | ||
+ | Optionally, you can add a group to your recipes to be displayed within the recipe helper interface. All recipes with the same group String will be shown in the same group. For example, this can be used to have all door recipes shown in the recipe helper interface as a single entry, even though there are different types of doors. | ||
=== Type === | === Type === | ||
− | The type of | + | The type of the recipe. You can think of this as the definition of which crafting layout is to be used. <code><nowiki>minecraft:crafting_shaped</nowiki></code> and <code><nowiki>minecraft:crafting_shapeless</nowiki></code> are the two options. |
− | == | + | == Types of Crafting Recipes == |
− | + | In this section, we will take a closer look at the differences between defining a shaped and a shapeless crafting recipe. | |
− | == | + | === Shaped Crafting === |
− | + | Shaped recipes require the <code><nowiki>pattern</nowiki></code> and <code><nowiki>key</nowiki></code> keywords. | |
+ | The '''Pattern''' keyword defines the slot an item must appear in using placeholder characters. You can choose whatever character you want to be a placeholder for an item. | ||
+ | '''Keys''' define what items the placeholders stand for. A key is defined by a placeholder character and the item or tag it stands for (in the correct format). | ||
− | === | + | === Shapeless Crafting === |
− | + | A shapeless recipe doesn’t use the <code><nowiki>pattern</nowiki></code> or <code><nowiki>key</nowiki></code> keywords. | |
− | + | To define a shapeless recipe, you have to use the <code><nowiki>ingredients</nowiki></code> list. It defines which items have to be used for the crafting process. There are many more of these types that can be used here, and you can even register your own. It is even possible to define multiple instances of the same item which means multiple of these items have to be in place for the crafting recipe to take place. | |
− | |||
− | + | {{Colored box|title=Tip|content=While there is no limit on how many ingredients your recipe requires, the vanilla crafting table only allows 9 items for each crafting recipe.}} | |
− | + | Below is an example of an ingredient list: | |
− | |||
− | {{Colored box|title=Tip|content=While there is no limit on how many ingredients your recipe requires the vanilla crafting table | ||
− | |||
<syntaxhighlight lang="json"> | <syntaxhighlight lang="json"> | ||
"ingredients": [ | "ingredients": [ | ||
Line 72: | Line 72: | ||
=== Patterns === | === Patterns === | ||
− | A pattern will be defined with the <code><nowiki>pattern</nowiki></code> list. Each string represents one row in the crafting grid and each placeholder character within the | + | A pattern will be defined with the <code><nowiki>pattern</nowiki></code> list. Each string represents one row in the crafting grid and each placeholder character within the string represents a column. As shown in the example above, a space means that no item needs to be inserted at that position. |
=== Keys === | === Keys === | ||
− | A key set is used in combination with | + | A key set is used in combination with a pattern set. It contains keys whose name is the same as the placeholder character in the pattern list which it represents. One key may be defined to represent multiple items, as is the case for the wooden button. This means that the player can use one of the defined items for the crafting recipe, for example, different types of wood. |
<syntaxhighlight lang="json"> | <syntaxhighlight lang="json"> | ||
"key": { | "key": { | ||
Line 91: | Line 91: | ||
=== Results === | === Results === | ||
− | Every <code><nowiki>recipe</nowiki></code> | + | Every <code><nowiki>recipe</nowiki></code> must have a result tag to define the output item. |
+ | |||
+ | When crafting something, you can get more than one item. This is achieved by defining the <code><nowiki>count</nowiki></code> value. If this is left out, meaning it doesn’t exist within the result block, it defaults to 1. Negative values are not allowed here as an itemstack cannot be smaller than 0. There is no option to use the <code><nowiki>count</nowiki></code> number anywhere else than the result. | ||
+ | |||
− | + | [[Category:Resources and Data]] |
Latest revision as of 00:59, 19 May 2021
With the update to Minecraft 1.12, Mojang introduced a new data-driven recipe system based on JSON files. Since then, it has been adopted by Forge as well and was expanded in Minecraft 1.13 into datapacks.
Loading Recipes
Forge will load all recipes found within the ./resources/data/<modid>/recipes/
folder of your mod. You can call these files whatever you want, though the vanilla convention is to name them after the output item. For multiple recipes from different sources (smelting, crafting, etc) one vanilla convention is to use item_name_from_smelting.json
. This name is also used as the registration key but does not affect the operation of the recipe.
The Recipe File
A basic recipe file might look like the following example:
{ "type": "minecraft:crafting_shaped", "pattern": [ "XXX", "XAX", "XXX" ], "key": { "X": { "tag": "forge:gems/diamond" }, "A": { "item": "mymod:myfirstitem" } }, "result": { "item": "mymod:myseconditem", "count": 9 } }
Tip
When you first obtain an ingredient to a vanilla recipe, it will automatically unlock the recipe in the recipe book. To achieve the same effect, you have to use the Advancement
system and create a new Advancement
for each of your ingredients.
Groups
Optionally, you can add a group to your recipes to be displayed within the recipe helper interface. All recipes with the same group String will be shown in the same group. For example, this can be used to have all door recipes shown in the recipe helper interface as a single entry, even though there are different types of doors.
Type
The type of the recipe. You can think of this as the definition of which crafting layout is to be used. minecraft:crafting_shaped
and minecraft:crafting_shapeless
are the two options.
Types of Crafting Recipes
In this section, we will take a closer look at the differences between defining a shaped and a shapeless crafting recipe.
Shaped Crafting
Shaped recipes require the pattern
and key
keywords.
The Pattern keyword defines the slot an item must appear in using placeholder characters. You can choose whatever character you want to be a placeholder for an item.
Keys define what items the placeholders stand for. A key is defined by a placeholder character and the item or tag it stands for (in the correct format).
Shapeless Crafting
A shapeless recipe doesn’t use the pattern
or key
keywords.
To define a shapeless recipe, you have to use the ingredients
list. It defines which items have to be used for the crafting process. There are many more of these types that can be used here, and you can even register your own. It is even possible to define multiple instances of the same item which means multiple of these items have to be in place for the crafting recipe to take place.
Tip
Below is an example of an ingredient list:
"ingredients": [ { "tag": "forge:gems/diamond" }, { "item": "minecraft:nether_star" } ],
Recipe Elements
Patterns
A pattern will be defined with the pattern
list. Each string represents one row in the crafting grid and each placeholder character within the string represents a column. As shown in the example above, a space means that no item needs to be inserted at that position.
Keys
A key set is used in combination with a pattern set. It contains keys whose name is the same as the placeholder character in the pattern list which it represents. One key may be defined to represent multiple items, as is the case for the wooden button. This means that the player can use one of the defined items for the crafting recipe, for example, different types of wood.
"key": { "#": [ { "item": "minecraft:oak_planks" }, { "item": "minecraft:spruce_planks" } ] }
Results
Every recipe
must have a result tag to define the output item.
When crafting something, you can get more than one item. This is achieved by defining the count
value. If this is left out, meaning it doesn’t exist within the result block, it defaults to 1. Negative values are not allowed here as an itemstack cannot be smaller than 0. There is no option to use the count
number anywhere else than the result.