Forge Modding Tutorials 1.8: Crafting Recipes

In this tutorial I will show you how to add a crafting recipe to your mod. All of the code for this will be done in the mod file. This is the file I will start with.

Crafting recipes are added in the FMLInitializationEvent. To add a crafting recipe to Minecraft you will need a piece of code which looks like this.

GameRegistry is a class you will frequently be using when creating a mod. It is the class which you will use to register almost anything in your mod. In this case you will be using the class for the addRecipe method. This method has 2 parameters.

The first is an ItemStack with the Item or Block it will return. In this case the recipe will return a single block of obsidian, but there are ways to return a stacksize of more than one and with metadata. This will be shown in one of the next recipes.

The second parameter is a special Java parameter which can simply take as many Objects as you want. In here you will be constructing the shape of the recipe. As you will know the crafting table is a 3 by 3 grid which you can write by using 3 pairs of quotation marks separated by commas with 3 spaces or letters in each of them. In this case the grid has to be filled with 9 A’s. However, Minecraft doesn’t work with letters, but with items and blocks. After the 3 pairs of quotation marks you have to add another comma and then 2 apostrophes with the used letter in there. Finally you have to add yet another comma and then an Item, Block or ItemStack which you want the letter to represent. In this case 9 cookies will get you an Obsidian block.

When you add this code you may have to import some new files. To do this, press Ctrl, Shift, O and Eclipse should automatically do it for you. If you must choose which files to import, you should usually get the file within the minecraft package.

Another recipe could look like this.

This recipe will give you 4 apples. It also only has 2 pairs of quotation marks with 2 letters in each. When you have it set up like this, the crafting recipe can be put anywhere in the crafting table as long as the required block is in a 2 by 2 shape.

A final example of a Recipe is this one.

This recipe contains multiple new things. First of all it shows you how to use metadata. In this case it returns 2 bonemeal (dye metadata 15). It also shows you how to create slightly more complicated recipe shapes. If you want something to be exactly crafted as shown above be sure to add the spaces in between or it won’t work. Another thing it shows is how to use different items and blocks in a single recipe. Finally it shows you how to use metadata and ItemStacks as a crafting component instead of a result. One thing to note is that you can’t have a stacksize of more than one as a crafting component. It won’t crash, but it will not work properly.

The whole mod file should now look like this.

In the next tutorial I will show you how to create shapeless recipes and smelting recipes.


For a more detailed explanation and much more, check out my book Sams Teach Yourself Mod Development for Minecraft in 24 Hours.

STY Minecraft Mod Development Book


Or donate if you enjoyed this tutorial.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">