Amazon Ad

Thursday, February 2, 2017

Crafting and Smelting Recipes

Hello, my name is Alex and I am going to show you how to create a mod for minecraft forge 1.11.2. There's not a lot of tutorials on 1.11 so I am creating one for those that want to get started.

WARNING: IF YOU DO NOT KNOW ANYTHING ABOUT JAVA, PLEASE LEARN THE BASICS BEFORE ATTEMPTING TO FOLLOW ANY MODDING TUTORIALS!!!!!

In this tutorial we are going to be looking at how crafting and smelting works in forge. Let's start by creating a class called CraftingHandler in our "handlers" package. In here we will have a method called init (returns a void, static).  In this we will refer to GameRegistry.addRecipe. This method takes in two parameters: the crafted item, and the ingredients. Below is how we will be writing the line of code:


1
GameRegistry.addRecipe(new ItemStack(<youritem>, <amount>), "", "", "", '', <ingredient_1>, '', <ingredient_2>, '', <ingredient_3>);

Replace <youritem> with the item you want to output, let's make the pickaxe we made. So replace <youritem> with our pickaxe.

Next, replace <amount> with the amount that you want to output. Most output only 1, so in this case we are going to put 1, because, I mean, like, who needs to get multiple swords out of one recipe? Uh...nobody!

Now is the tricky part, the actual recipe. The 3 strings are going to go through a pattern recognition. Each of them represent a row on the crafting table, the first string being the top row, the second string being the middle row, and, you guessed it, the third string for the bottom row. Each of them MUST have 3 characters. If you want a blank space, you just put a space.

The third part of the method is telling the game what each character represents. You can have as many as you want, as long as it has at least one. It takes in a char, which is a character surrounded by single-quotes, followed by the ingredient you want, and so on and so forth.

Let's plug in the missing links, shall we?


1
GameRegistry.addRecipe(new ItemStack(ItemHandler.tutPickaxe, 1), "XXX", " C ", " C ", 'X', ItemHandler.tutItem, 'C', Items.STICK);

As you can see, I am only using the middle slots of the middle and bottom row, leaving the edges blank using a space. The end result is this:


Next we gotta put it in the postInit of our CommonProxy. Call the init within our postInit of CommonProxy and you should be good to test it. Make the other recipes for the rest of the tool set, too.

============================================Smelting==========================================

Smelting is very similar. Let's create a handler for it called SmeltingHandler. In here we will also create an init method. This init method will have our smelting recipes in it, obviously.

To add a smelting recipe, we need to call on addSmelting from the GameRegistry class. This takes in three arguments: input, output, and xp. The input takes in an Item or a Block. Let's add our item and make it smelt into another item, which we will then use for crafting.

Let's create the item in our ItemHandler and call it carbite. This will then initialize to a new ItemCarbite class, with the same parameters as our tutItem. Create the class, extend it to ModItem and create the constructor. Now to create the the JSON files. Just copy and paste our tutItem JSON files and change all the naming to carbite. Create the texture and model files and we should be good to go, and make sure you register and render it, too.

The following line of code is how we will create the smelting recipe:


1
GameRegistry.addSmelting(ItemHandler.tutItem, new ItemStack(ItemHandler.carbite), 1.0F);

We are passing through our tutItem as the input, and the newly created carbite item, as the output. The last parameter is how much experience you will get from it. 0.7F is iron, 1.0F is gold and diamond. We are giving this a lot of XP.

Next is to call it in our CommonProxy.postInit, and run the game. We should now have a smelting recipe.

Next we gotta change our crafting recipes to take in the carbite we made.

The end result should be this:


Don't forget to name your items!!

2 comments:

  1. Is this tutorial out of the order? You say "Replace with the item you want to output, let's make the pickaxe we made. So replace with our pickaxe.", but we have not yet made a pickaxe. I am following the order you posted on your forum topic: http://www.minecraftforum.net/forums/mapping-and-modding/mapping-and-modding-tutorials/2790483-1-11-2-forge-minecraft-forge-modding-tutorials-up
    Great tutorials btw :D!

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete