Hello everyone, in this part we will be adding some custom recipes, I will show how to add a smelting recipe, a shapeless recipe and a shaped recipe.
For the people who haven’t followed this tutorial, I have 2 custom items and 2 custom blocks. If you don’t know how to add blocks click here, for items click here. For the people who followed the tutorial, I renamed the tutorialItem to tutorialIngot to be more consistent with the texture. Well lets get started!
In the init package create a new class and call it ModRecipes. Add a public static method, this method will register all of your recipes. I called it init to be consistent with the other classes.
I am going to add a smelting recipe to smelt the tutorialDust into the tutorialIngot. In this method call the method addSmelting on the GameRegistry object. This method needs an input, an output, and an amount of xp it will give. The input can be a Block, an Item or an ItemStack. The output has to be an ItemStack and the amount of xp has to be an float.
As input I will pass it ModItems.tutorialDust. The output has to be an ItemStack, an ItemStack is like an stack of items in game. You have to instantiate it with the item you want the stack to be and the amount of items in the stack. I will make it an ItemStack of 1 ModItems.tutorialIngot item. Diamond has 1.0 for the xp amount, I will use 1.5. I will make another smelting recipe, this one takes the ModBlocks.oreBlock and turns into 2 ModItems.tutorialIngots, it wil only give 0.2 xp.
If you want to know all of the xp values for vanilla, you can see the vanilla smelting recipes in net.minecraft.item.crafting.FurnaceRecipes.
Now in the main class’ init method call the ModRecipes.init();
For crafting recipes you don’t have to add any code. In your assets package create a new package called recipes in this folder you can put .json files which will be loaded by the game. Here is a shaped recipe example:
This recipe needs 9 tutorialIngots in a 3×3 grid, this recipe is just like the iron block recipe.
And here a shapeless one:
This recipe needs a vanilla stone block and the custom tutorialIngot (My modid is “stm”). Putting this in a crafting table, or your 2×2 crafting grid will result in 2 purpur block.
A shaped recipe has a pattern, to fill the 3×3 of the crafting table you can do:
"AAA" "AAA" "AAA"
You can enter any symbol you want instead of “A” but you have to define the key and the value. That is done in the json under keys. You can also have different keys:
"AAA" " B " " B "
This would be a pickaxe shaped recipe. If you have a place where you don’t have a recipe you should put space (” “) there. For recipes that don’t fill the 3×3 you should leave out the spaces at the end, for example:
"AA" "B " "B "
This would be a hoe shaped recipe, this recipe is only 2 wide so we can remove the space at the end (Make sure every line is the same length, as you can see they are all 2 long).
If your recipe is your recipe is only 2 high you can remove the bottom line.
This recipe would also be possible in your 2×2 crafting grid.
For shapeless recipes you don’t need a pattern, but you need ingredients. To complete the recipe you need all of the ingredients to be in the crafting grid, but the order doesn’t matter., like dyeing wool.
There is a recipe generator, it only works with vanilla blocks but you can renamen the items in the json file you get so it can be useful.
For more information about the format you can check this post.
That was all for this part! I hope you learned something, as always if you have any question don’t hesitate to ask in the comments. Saw any errors? Please tell me!
Till next time!