Step 6: Adding a Recipe For Your Block!

In this part of the tutorial, I’ll show you how to add a recipe. No downloads needed this time! :) So if you've got the other two parts completed successfully, you will have a basic block with your own texture. Now you need a way for people in survival mode to create the block. This one's super quick, just need to invoke one method! See if you can figure this one out yourself, if not I'll explain what each part does below. Btw, this can be done in one line, I just organised it so you would see it as you would in a crafting table, to make it easier to understand. GameRegistry.addRecipe(new ItemStack(yourFirstBlock), new Object[] {     "BBB",     "BAB",     "BBB",     Character.valueOf('A'), Item.diamond,     Character.valueOf('B'), Block.obsidian });






GameRegistry.addRecipe - The method you are invoking, which adds the recipes to minecraft. new ItemStack(yourFirstBlock) - Creation of a new ItemStack method which will create that block or item in the crafting bench result slot. You change "yourFirstBlock" to whatever item/block object you created before. new Object[] - Don't worry about this, whatever you add in the curly brackets after will determine what's included in this object you are passing to the ModLoader method. "BBB", "BAB", "BBB", - This is the formation in the crafting bench. Make sure you use a different letter for each item type you want to add. Because I used two different letters, it will have two different items... Character.valueOf('A') - Now, in the formation above, every "A" signifies what we specify next... Item.diamond, - So now every "A" we used in the formation above will signify that a diamond has to be placed there for the matching recipe to be matched. Repeat the Character.valueOf('letterHere') and Item.whatever for however many items you require in your recipe. }); - Closing the statement. You can also use your own blocks and items, for example I could do Character.valueOf('A'), yourFirstBlock, which link all the "A"s in the formation to require that my custom block be placed there. Here's what the code I used above would look like in the game: Some other example formations: You can use spaces to represent blank slots: "DDD", " I ", " I ",

You can shorten the formation, so that as long as the items are placed like that, it can be placed in any part of the crafting bench (such as the Plank -> Workbench recipe): "BB", "BB",

Or you could have just one, meaning that if that one item/block is placed in the table, it will be crafted into the result item: "Z",

Previous                 Back to Tutorials Index                 Next
Minecraft and Forge are always changing, found something wrong with this tutorial?

external links

social