Basic Modding - Crafting Recipes

Goal

I want to show you how to create crafting and smelting recipes.

Difficulty

1/10 - Pretty simple

Prerequisites

  • You need a workspace with proxies.
  • You should have some blocks or items to craft and smelt.

Forge Version

This Tutorial was created with Forge 10.13.0.1180 for Minecraft 1.7.10. If anything doesn't work with other versions, please contact me!


Creating crafting recipes

There are two different types of crafting recipes: Shapeless and Shaped recipes. A shapeless recipe is defined by the sum of the items in the crafting grid while a shaped recipe requires the items to be in a special shape.

 

To create a shaped recipe, we need the following method:

Shaped Recipe:
GameRegistry.addRecipe(new ItemStack(ModBlocks.tutorialBlock), new Object[] {"##", "##", '#', ModItems.tutorialItem});

Here we have something new: An ItemStack. This is basically one Item (or Block) along with its stack size and some other values like the damage value for tools.

Here, the ItemStack defines the output of the recipe. If we want to get more than one Item as the result of a recipe, we have to give the ItemStack's constructor two arguments: first the item or block, then the amount of items.

 

The array of objects describes how to craft the output stack.

The first elements of the array are one to three String objects which show the actual recipe encoded in chars. Each String represents one row of the crafting grid so we can use up to three Strings. The length of the Strings define the width of the crafted pattern, so they can't be longer than three characters. The Strings must be equal in length, otherwise the recipe won't work.

After the Strings we have to add pairs of a Char object and an Item, Block or ItemStack object. These pairs are the encoding for the chars we used in the Strings.

Note that the recipes can be crafted in the way they were written in the code but also mirrored on the vertical axis. In a later tutorial I'll cover non-mirrored recipes.


Some examples:

The output is coloured blue.

The Strings are coloured red.

The encoding is coloured green.

Iron Pickaxe:
GameRegistry.addRecipe(new ItemStack(Items.iron_pickaxe), new Object[] {"###", " I ", " I ", '#', Items.iron_ingot, 'I', Items.stick});
Diamond Chestplate:
GameRegistry.addRecipe(new ItemStack(Items.diamond_chestplate), new Object[] {"# #", "###", "###", '#', Items.diamond});

 The crafting recipe I'll use for my example mod is a recipe to craft the tutorialBlock out of four tutorialItems arranged in a 2*2 square.

Crafting


Tutorial Block:
GameRegistry.addRecipe(new ItemStack(ModBlocks.tutorialBlock), new Object[] {"##", "##", '#', ModItems.tutorialItem});

NOTE:
Actually we don't need to make the last argument an array of objects, we can just write the Strings, Chars, Items, Blocks and ItemStacks one after another without putting them into an array because this is automatically done.

These two methods do exactly the same:

With Array:
GameRegistry.addRecipe(new ItemStack(ModBlocks.tutorialBlock), new Object[] {"##", "##", '#', ModItems.tutorialItem});
Without Array:
GameRegistry.addRecipe(new ItemStack(ModBlocks.tutorialBlock), "##", "##", '#', ModItems.tutorialItem);

I would recommend using the method without the array, because it saves a lot of code.

Shapeless recipes

A shapeless recipe is not defined by a special structure of the items but by the count of all items in the crafting grid. The method to create shapeless recipes is very similar to the one to create shaped recipes; the only difference is the array which needs different values.

Shapeless Recipe:
GameRegistry.addShapelessRecipe(new ItemStack(ModItems.tutorialItem), new Object[] {Items.redstone, new ItemStack(Items.dye, 1, 4)});

The first argument of the method defines the output of the recipe. The second argument - the Object-array - contains all the items/blocks/itemstacks needed in the recipe.

 

The shapeless recipe above is crafted with one redstone and one lapis lazuli. It results in a tutorialItem.

 

In my example I used a special ItemStack which refers to the item of lapis lazuli:

new ItemStack(Items.dye, 1, 4);

This must be an ItemStack in this case because Items.dye is a metadata sensitive item. This means that the same item object ("dye") can be used for several different items (All dyes in minecraft; bone meal, ink sac, cocoa bean, lapis lazuli etc.).

In a later tutorial I'll explain how metadata Items work and how you can create them.

The itemstack here defines a stack of 1 item of the type dye with metadata 4 which is lapis lazuli.

 

In this recipe it doesn't matter where we place the items, the only important thing is that the crafting grid contains all these items.

 

NOTE:
Here we can also replace the Array with a list of single objects.

Furnace Recipes

The furnace recipes are much easier than the shaped and shapeless recipes because we only need an in- and an output stack. Additionally we need to add the amount of experience a player gets when smelting the item.

Furnace Recipe:
GameRegistry.addSmelting(Items.diamond, new ItemStack(ModItems.tutorialItem), 1.0F);

The first argument for this method is the input. It can be either an Item, Block or ItemStack object. The next argument is the output. This argument must be an ItemStack. The last argument defines the experience a player gets when taking an item out of the furnace. Examples for this value:

Iron Ore: 0.7F

Gold/Diamond/Emerald Ore: 1.0F

Beef/Porkchop: 0.35F

 

The furnace recipe above allows the player to smelt a diamond into a tutorialItem.

Where to place the recipes

It's useful if we create a new class to store the recipes. For this example I placed the recipes in the class com.bedrockminer.tutorial.crafting.ModCrafting.class. The methods mentioned above need to be called during the init() phase of the CommonProxy.

 


You can download the code used in this tutorial as a .zip file from here.


Recommended tutorials to continue with

Take a look at the tutorial overview and find out what you want to do next!


Comments and Questions:

If you want to report modding problems, please make sure to include the code in a pastebin link or something else! Don't just write "It doesn't work", otherwise your post will be deleted. For more complicated problems, please use the troubleshooter form.