Namespaces

Variants

Share

Share
Views
Actions

Mods/Creating mods/Adding a recipe

From Minecraft Wiki
Jump to: navigation, search
The contents of this page are not supported by Mojang AB, the Minecraft Wiki, the Minecraft IRC channel or the Minecraft Forums.

These tutorials teach how to make new recipes. This includes simple recipes complex recipes, shapeless recipes, and smelting recipes.

Contents

[edit] Creating your First Recipe

This tutorial will show you how to add a simple recipe using items already in the game. This tutorial requires that you have completed the Starting your First Mod tutorial. The tutorial will teach you how to add multiple recipes in an easy and organized matter.

  1. Open your "mod_myMod.java" file. Go to the public void load() {} function. Put the first curly bracket in a new line. Then, put the second curly bracket two lines below the first. See below to see how it should be formatted.
public void load()
        {
                
        }
2. In the blank line, type this.addRecipes();. An error will appear. Ignore it, it will be fixed in the next step.
3. Above public void load(), add two lines. In the top line, add an addRecipes function with the void return type, like so:
public void addRecipes()
        {
                
        }
4. In the blank line, we will add the recipe. The code (only the line directly below this one) below will allow 9 Dirt to be crafted into 2 Diamonds.
ModLoader.addRecipe(new ItemStack(Item.diamond, 2), new Object[] { "DDD", "DDD", "DDD", 'D', Block.dirt });
ModLoader.addRecipe is the method that adds the recipe. (new ItemStack(Item.diamond, 2) is the crafting result. Item.diamond is a Diamond Gem. 2 is the amount crafted per 9 Dirt. new Object[] { "DDD", "DDD", "DDD" is the format of where the blocks should be placed in the Crafting Table. Since there are 9 Ds, every slot in the grid is used. The first three symbols represent the first row, the second three the second row, and so on. Since it is the same symbol throughout the entire grid, this means that the same block/item is being used in each slot. 'D', Block.dirt says that the letter D represents a Dirt block. In this example, I used D since Dirt begins with D.

The above line would tell the game to craft 2 Diamonds with 9 Dirt like below:

Dirt Dirt Dirt Grid layout Arrow (small).png Diamond2
Dirt Dirt Dirt
Dirt Dirt Dirt
5. You can customize the ingredients of the recipe by changing Block.dirt to another block or item. For a list of blocks, see "Block.java". Keep in mind that block names can be very different in the code than on the in-game labels (for example, End Stone is called whiteStone in the code). For a list of items, see "Item.java". Blocks must have Block. in front, while items must have Item. in front. If you are creating a new recipe for a new block/item in your mod or using a new modded block/item then use mod_Your_Mod_Name in front . This is the same for the outcome item. The amount of the outcome can be changed by simply changing the number 2 to whatever amount you would like.
6. Your first recipe is complete. To test it out, click the botton with the white arrow in the green circle in the top toolbar. This should launch Minecraft with your mod. If the game crashes or your recipe does not work, you have done something wrong. More tutorials below show how to add more complex recipes, shapeless recipes, and smelting recipes.

[edit] Completed code

The code of "mod_myMod.java" after completing the above tutorial should look like the following. You may also copy and paste this into your file.

package net.minecraft.src;

public class mod_myMod extends BaseMod
{       
        public void addRecipes()
        {
                ModLoader.addRecipe(new ItemStack(Item.diamond, 2), new Object[] { "DDD", "DDD", "DDD", 'D', Block.dirt});
        }
        
        public void load()
        {
                this.addRecipes();
        }
        
        public String getVersion()
        {
                return "Version 1.0";
        }
}

A Pastebin of the above code can be found here.

[edit] Adding a Complex Recipe

This tutorial will show you how to add another recipe, this one more complex and using items and blocks. This tutorial requires that you have already completed the Creating your First Recipe tutorial.

1. Return to your public void addRecipes() function. Add a new line under your first recipe.
2. Type in the following code.
ModLoader.addRecipe(new ItemStack(Block.whiteStone, 64), new Object[] { "W $", " S ", "s E", 'W', new ItemStack(Block.wood, 1, 2), '$', Item.stick, 'S', Block.sand, 's', Block.sapling, 'E', Item.enderPearl });
3. The above recipe will yield 64 End Stone (called whiteStone in the code) when several different items are put in an X format in the Crafting grid. Above, one of the symbols used was $. The symbols used in the recipe code can be any type of symbol, they do not need to be letters. For the Wood block, the following was used: 'W', new ItemStack(Block.wood, 1, 2) This forces the Wood in this particular recipe to have metadata 2. This means that the Wood can only be Birch Wood for this recipe. Placing any other type of Wood in the Crafting Table will not have an effect. Yet, Saplings also have metadata. For Saplings, the code does not specify a certain metadata. This means any type of Sapling can be used in the recipe and provide the same result.
The recipe in the grid is below:
Birch Wood
Stick Grid layout Arrow (small).png End Stone64

Sand
Oak SaplingSpruce SaplingBirch SaplingJungle Sapling
Ender Pearl
4. You have completed your second recipe.

[edit] Completed code

The following code includes the recipe from the Creating your First Recipe tutorial too.

package net.minecraft.src;

public class mod_myMod extends BaseMod
{       
        public void addRecipes()
        {
                ModLoader.addRecipe(new ItemStack(Item.diamond, 2), new Object[] { "DDD", "DDD", "DDD", 'D', Block.dirt});
                ModLoader.addRecipe(new ItemStack(Block.whiteStone, 64), new Object[] { "W $", " S ", "s E", 'W', new ItemStack(Block.wood, 1, 2), '$', Item.stick, 'S', Block.sand, 's', Block.sapling, 'E', Item.enderPearl });
        }
        
        public void load()
        {
                this.addRecipes();
        }
        
        public String getVersion()
        {
                return "Version 1.0";
        }
}

A Pastebin of the above code can be found here.

[edit] Adding a Shapeless Recipe

This tutorial requires that you have completed the Creating your First Recipe tutorial. Unlike normal recipes, the items do not need to be placed in a certain formation, and can be simply placed in the Crafting Table in any formation.

1. Navigate to your public void addRecipes() function. Add a new line.
2. Type in the following code.
ModLoader.addShapelessRecipe(new ItemStack(Block.grass, 1), new Object[] { Item.seeds, Block.wood });
3. The above shapeless recipe returns one block of Grass when Seeds and Wood are put in the Crafting Table. ModLoader.addShapelessRecipe is the method used to declare a shapeless recipe. new ItemStack(Block.grass, 1), is the item that is crafted along with the amount that is given. new Object[] { Item.seeds, Block.wood }); says that Wheat Seeds and a Wood Block are required in to craft the result. Unlike the normal ModLoader.addRecipe method, if a certain metadata for a block or item is not specified, it will only recognize the default metadata. For example, this recipe only allows for regular Oak Wood to be used, not Jungle Wood or any other type. To specify a certain metadata, we must use the method that we used in the above tutorial (new ItemStack(Block.wood, 1, 2),), and replace it with Block.wood. Replace the last number (2) with the metadata you would like. For Wood, 0 is Oak, 1 is Spruce, 2 is Birch, and 3 is Jungle.
A few examples of how the recipe can be formatted in the grid is below (Using the above code, not with metadata specification).
Seeds

Grid layout Arrow (small).png Grass Block

Oak Wood



Grid layout Shapeless.png


Oak Wood Grid layout Arrow (small).png Grass Block



Seeds

Grid layout Shapeless.png
4. Your first shapeless recipe is complete.

[edit] Completed code

The following code includes the code from the Creating your First Recipe tutorial too.

package net.minecraft.src;

public class mod_myMod extends BaseMod
{               
        public void addRecipes()
        {
                ModLoader.addRecipe(new ItemStack(Item.diamond, 2), new Object[] { "DDD", "DDD", "DDD", 'D', Block.dirt});
                ModLoader.addShapelessRecipe(new ItemStack(Block.grass, 1), new Object[] { Item.seeds, new ItemStack(Block.wood, 1, 3) });
        }
        
        public void load()
        {
                this.addRecipes();
        }
        
        public String getVersion()
        {
                return "Version 1.0";
        }
}

A Pastebin of the above code can be found here.

[edit] Adding a Smelting Recipe

This tutorial requires that you have completed the Creating your First Recipe tutorial. Smelting recipes, also known as Furnace recipes, are coded a bit differently than regular crafting recipes. This tutorial only teaches how to add a new recipe, not a new fuel source.

1. Navigate to your public void addRecipes() function. Add a new line.
2. Type in the following code.
ModLoader.addSmelting(Block.dirt.blockID, new ItemStack(Item.dyePowder, 32, 4));
3. This code says that when Dirt is smelted, return 32 Lapis Lazuli Dye. ModLoader.addSmelting is the method name, which tells ModLoader that this is a smelting recipe. Block.dirt.blockID says that the ingredient is a Dirt block. new ItemStack(Item.dyePowder, 32, 4) says the the output is 32 Lapis Lazuli Dye for every Dirt block. Item.dyePowder is the item that includes all dyes. This includes not only Lapis Lazuli Dye, yet also Cactus Green, Rose Red, and Ink Sacs. See Wool Dyes for more information. 32 is the number of items returned. The number must be above 0. The number can be above 64, yet the Furnace will not smelt again until the stack is removed. When a number higher than 64 is used, the stack is automatically sorted into stacks of 64. For example, if programmed to return 72, it will put one full stack in the slot you choose and the other 8 into another slot. The stack may become glitchy if a number above 120 is used. 4 is the metadata of the item returned. 4 is the metadata of Lapis Lazuli Dye in Item.dyePowder. This last parameter is not necessary if the item returned has no metadata. For example, Dirt and Paper are examples of items with no metadata. If Paper was being returned instead of Lapis Lazuli Dye, new ItemStack(Item.dyePowder, 32, 4) could simply be new ItemStack(Item.paper, 32). Using the code mentioned in Step 2, the following would occur in a Furnace:
Dirt Grid layout Furnace Progress.png Lapis Lazuli32
Grid layout Fire.png
Coal
4. Keep in mind that in the above example, any type of Furnace fuel can be used, not just Coal. You have created your first smelting recipe.

[edit] Completed code

The following code includes the code from the Creating your First Recipe tutorial too.

package net.minecraft.src;

public class mod_myMod extends BaseMod
{
        public void addRecipes()
        {
                ModLoader.addRecipe(new ItemStack(Item.diamond, 2), new Object[] { "DDD", "DDD", "DDD", 'D', Block.cobblestone});
                ModLoader.addSmelting(Block.dirt.blockID, new ItemStack(Item.dyePowder, 32, 4));
        }
        
        public void load()
        {
                this.addRecipes();
        }
        
        public String getVersion()
        {
                return "Version 1.0";
        }
}

A Pastebin of the above code can be found here.

[edit] Final code

If every tutorial above was completed, the result should be this:

package net.minecraft.src;

public class mod_myMod extends BaseMod
{
        public void addRecipes()
        {
                ModLoader.addRecipe(new ItemStack(Item.diamond, 2), new Object[] { "DDD", "DDD", "DDD", 'D', Block.cobblestone});
                ModLoader.addRecipe(new ItemStack(Block.whiteStone, 64), new Object[] { "W $", " S ", "s E", 'W', new ItemStack(Block.wood, 1, 2), '$', Item.stick, 'S', Block.sand, 's', Block.sapling, 'E', Item.enderPearl });
                ModLoader.addShapelessRecipe(new ItemStack(Block.grass, 1), new Object[] { Item.seeds, new ItemStack(Block.wood, 1, 3) });
                ModLoader.addSmelting(Block.dirt.blockID, new ItemStack(Item.dyePowder, 32, 4));
        }
        
        public void load()
        {
                this.addRecipes();
        }
        
        public String getVersion()
        {
                return "Version 1.0";
        }
}

A Pastebin of the above code can be found here.

[edit] Changing ingredients and results of recipes

The above tutorials use certain blocks and items. In the code, many items in Minecraft are called by different names, or are compacted to use less data. To find an item in particular you are looking for, the files Block.java and Item.java contain all of the blocks and items in the game. Most blocks will be formatted like this:
dirt = (new BlockDirt(3, 2)).setHardness(0.5F).setStepSound(soundGravelFootstep).setBlockName("dirt");
This format will not be explained in this tutorial. Items are formatted similarly, yet do not contain as many methods. To find the block/item you want to use, you will need to do the following:

  1. Determine the correct file to find what you are looking for. Blocks are in Block.java, and items are in Item.java. Open the file.
  2. For blocks scroll towards the bottom of the page, until you see lines similar to the example provided above. For items, stay at the top of the page.
  3. Search for your item/block. Ctrl + F (⌘ Cmd + F on Mac) should open a "Find/Replace" window. This can be used to find your item. Keep in mind that many blocks/items are under a different name in the code. For example, an inactive Furnace is referenced as stoneOvenIdle. Once you have found your block/item, proceed to the next step.
  4. Return to mod_myMod.java. Find the block/item you want to replace in your recipe. Make sure you remove the Block. or Item. that precedes the method too. Then, type Block. or Item. again, Block. for Block.java, and Item. for Item.java.
  5. Type the name of the item or block that you want to use. For a Furnace, this would be stoneOvenIdle.
  6. The final result should look similar to Block.dirt or Item.silk.