Adding Shaped Crafting Recipes

In this tutorial I will show how you can add a shaped recipe into your mod.

Let’s start. First, again to be organized, create a new class in the init package, let’s call it ModRecipes.

package com.emx.tutorial.init;

public class ModRecipes
{
    public static void init()
    {

    }
}

Now, I will add a recipe to make a red diamond block. It will need nine diamonds placed in all nine slots of the crafting table. To do that, add this line:

GameRegistry.addRecipe(new ItemStack(ModBlocks.red_diamond_block), "XXX", "XXX", "XXX", 'X', ModItems.red_diamond);

The first parameter is a new ItemStack of the item you want outputted. ItemStacks are simply said a group of items in Minecraft. It can have data values and amounts. The three “XXX” represent the crafting slots, from top to bottom. The following parameters tell what X is, in this case a red diamond. For example, an iron pickaxe recipe will be as follows:

GameRegistry.addRecipe(new ItemStack(Items.iron_pickaxe), "XXX", " Y ", " Y ", 'X', Items.iron_ingot, 'Y', Items.stick);

Your ModRecipes code should look like this:

package com.emx.tutorial.init;

public class ModRecipes
{
    public static void init()
    {
        GameRegistry.addRecipe(new ItemStack(ModBlocks.red_diamond_block), "XXX", "XXX", "XXX", 'X', ModItems.red_diamond);
    }
}

For the last step, you will again need to call the init() method from your main class. Add this to your preInit method:

ModRecipes.init();

Your main mod class should look like this:

package com.emx.tutorial;

@Mod(modid = TutorialMod.MODID, name = TutorialMod.NAME, version = TutorialMod.VERSION)

public class TutorialMod
{
    public static final String NAME = "Tutorial Mod";
    public static final String MODID = "tutorial";
    public static final String VERSION = "1.7.10-R1";

    @Mod.Instance("tutorial")
    public static TutorialMod instance;

    @Mod.EventHandler
    public void preInit(FMLPreInitializationEvent event)
    {
        ModItems.init();
        ModBlocks.init();
        ModRecipes.init();
    }

    @Mod.EventHandler
    public void init(FMLInitializationEvent event) {}

    @Mod.EventHandler
    public void postInit(FMLPostInitializationEvent event) {}
}

Notice how I initialized the recipes after the blocks and items? That’s critical. If you put it before the items and blocks, Minecraft wouldn’t know what blocks you are mentioning, and you will crash.

Thanks for reading, have fun modding!

Advertisements

2 thoughts on “Adding Shaped Crafting Recipes

  1. Armetron October 13, 2015 / 5:43 AM

    Um where is the adding blocks tutorial?

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s