Modding 1.4.7: Basic Crafting Recipe

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


package tutorial;

import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.SidedProxy;
importcpw.mods.fml.common.event.FMLInitializationEvent;
importcpw.mods.fml.common.network.NetworkMod;
@Mod(modid = “Tutorial_Tutorialmod”, name = “Tutorial”, version = “1.0”)
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
publicclass Tutorial
{
       @SidedProxy(clientSide = “tutorial.ClientProxyTutorial”, serverSide = “tutorial.CommonProxyTutorial”)
       publicstatic CommonProxyTutorial proxy;
      
       @Init
       publicvoid load(FMLInitializationEvent event)
       {
             proxy.registerRenderThings();
       }
}

To add a recipe to your mod you will have to add some lines of code to the load method. This is an example of the code you need for a crafting recipe.


GameRegistry.addRecipe(new ItemStack(Item.arrow, 4), new Object[]{

                    “XXX”,
                    “XXX”,
                    “XXX”,
                    ‘X’, Item.coal
             });

The first thing you will see is GameRegistry. If there is an error under that you will have to import it so that you get this line of code below the other imports.


importcpw.mods.fml.common.registry.GameRegistry;


If you are also getting errors under ItemStack and Item you will also have to import them.
GameRegistry is the file  you are going to use to add a recipe.
addRecipe is a method inside of GameRegistry which will add the recipe to the game for you.
After that you see a pair of brackets and inside: new ItemStack(Item.arrow, 4). 4 is the amount of items you will get back from this recipe. Item.arrow is the type of item you will get.
new Object[] is some java, but you don’t have to know how or why that works. Just copy that part.
Below you see “XXX” three times. This is the shape of the recipe.
At the bottom you see ‘X’, Item.coal. This code will set the value of ‘X’ to coal. This way all the X’s in the shape of 3×3 are coal items. If you replace one of the X’s by a space you have an empty spot in that recipe.

If you want to use something with metadata, for example a dye, you will have to make it look like this.


GameRegistry.addRecipe(new ItemStack(Item.dyePowder, 4, 2), new Object[]{

                    “XXX”,
                    “XXX”,
                    “XXX”,
                    ‘X’, Item.coal
             });

Now you will get 4 items of the dyepowder with metadata 2 which means you get green dye.

If you instead want to use metadata items in a recipe you can use something like this.


GameRegistry.addRecipe(new ItemStack(Item.dyePowder, 4, 2), new Object[]{

                    “XXX”,
                    “XZX”,
                    “XXX”,
                    ‘X’, Item.coal, ‘Z’, newItemStack(Item.dyePowder, 1, 15)
             });

This recipe not only shows you how to use a metadata item, but also how to use 2 different items in one recipe.
To use a second item in a recipe you just add another character in the 3×3 shape. Then below after the Item.coal in this case you simply add that character like you did before with ‘X’. After that comes the part where you set the item. This part is also different. There is an ItemStack() here. That is because you will need one of those when you want to use metadata in a recipe.
In this case it will need 1 bonemeal surrounded by 8 coal.
If you want to use Blocks instead of items you simply change it into something like this.


GameRegistry.addRecipe(new ItemStack(Block.blockGold, 2), new Object[]

             {
                    “XXX”,
                    “XZX”,
                    “XXX”,
                    ‘X’, Item.coal, ‘Z’, new ItemStack(Item.dyePowder, 1, 15)
             });

Below you can see where the recipe code goes.


package tutorial;

import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.SidedProxy;
importcpw.mods.fml.common.event.FMLInitializationEvent;
importcpw.mods.fml.common.network.NetworkMod;
importcpw.mods.fml.common.registry.GameRegistry;
@Mod(modid = “Tutorial_Tutorialmod”, name = “Tutorial”, version = “1.0”)
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
publicclass Tutorial
{
       @SidedProxy(clientSide = “tutorial.ClientProxyTutorial”, serverSide = “tutorial.CommonProxyTutorial”)
       publicstatic CommonProxyTutorial proxy;
      
       @Init
       publicvoid load(FMLInitializationEvent event)
       {
             proxy.registerRenderThings();
            
             GameRegistry.addRecipe(new ItemStack(Block.blockGold, 2), new Object[]
             {
                    “XXX”,
                    “XZX”,
                    “XXX”,
                    ‘X’, Item.coal, ‘Z’, new ItemStack(Item.dyePowder, 1, 15)
             });
       }
}

 

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="">