Modding: All kinds of recipes

Now we will start changing the game by adding things to the load() method.
This was how the file looked the last time:


package Tutorial.common;

import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;

@Mod(modid = “YourName_ModName”, name = “ModName”, version = “Version number”)
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class Tutorial
{
@Init
public void load(FMLInitializationEvent event)
{

}
}


This is one of the most basic recipes:


GameRegistry.addRecipe(new ItemStack(Item.pickaxeDiamond), new Object[]
{
“XXX”, “XXX”, “XXX”, ‘X’, Block.dirt
});


GameRegistry is the class where the method addRecipe is located.

The new ItemStack() is the new itemstack you will get.
What the ItemStack is gets decided within the brackets. In this case: Item.pickaxeDiamond
New Object[] is the part where you will add the recipe.
{ something }); Between these brackets you will have to write the shape of items and blocks you need for the result (Diamond Pickaxe in this case).
“XXX” is the shape of the recipe. In this case a 3 by 3 shape. When you leave a space somewhere it will become empty.
‘X’ is used to tell Java what the X stands for.
Block.dirt is the value of the X in this recipe.
When you add this to your file it will look like this.

package Tutorial.common;

import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraft.src.Block

@Mod(modid = “YourName_ModName”, name = “ModName”, version = “Version number”)
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class Tutorial
{
@Init
public void load(FMLInitializationEvent event)
{
GameRegistry.addRecipe(new ItemStack(Item.pickaxeDiamond), new Object[]
{
“XXX”, “XXX”, “XXX”, ‘X’, Block.dirt
});
}
}


With this recipe you will get 1 diamond pickaxe for 9 dirt.

If you want the middle to be empty just change it into this:

GameRegistry.addRecipe(new ItemStack(Item.pickaxeDiamond), new Object[]
{
“XXX”, “X X”, “XXX” ‘X’, Block.dirt
});


If you want to change the result into 10 cobblestone you will make it like this.


GameRegistry.addRecipe(new ItemStack(Block.cobblestone, 10), new Object[]
{
“XXX”, “X X”, “XXX”, ‘X’, Block.dirt
});


As you can see the number after the Block or item is the ammount you get.

If you want to change the result into 5 bonemeal you should make it like this.

GameRegistry.addRecipe(new ItemStack(Item.dyePowder, 5, 15), new Object[]
{
“XXX”, “X X”, “XXX”, ‘X’, Block.dirt
});


The second number in here is the metadata of the item or block.

If you want to create a crafting recipe that uses an item or block with metadata you should use this.

GameRegistry.addRecipe(new ItemStack(Item.pickaxeDiamond), new Object[]
{
“XXX”, “X X”, “XXX”, ‘X’, new ItemStack(Item.dyePowder, 1, 15)
});


You can change the metadata of the required item like this. You can’t change the ammount that you need of it.

If you want to use a waterbucket in a recipe and you would like to get an empty bucket back you just change it into this.

GameRegistry.addRecipe(new ItemStack(Item.pickaxeDiamond), new Object[]
{
“XX”, ‘X’, Item.bucketWater
});


If you create the recipe like this you have to fill up the top left 2 spots with a water bucket to get the pickaxe. If you want to get a recipe that doesn’t require a set place for the items you need to do this.


GameRegistry.addShapelessRecipe(new ItemStack(Item.pickaxeDiamond), new Object[]
{
new ItemStack(Item.bucketWater), new ItemStack(Item.dyePowder, 1, 15)
});


With this recipe you can combine a bucket of water and 1 bonemeal in any spot of the crafting table to get the diamond pickaxe.

In the next tutorial I will show you how to add smelting recipes.

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