ModderDojo Java Modding 10: A Recipe for Our New Item

To have something useful we can do with our item, let’s add a recipe to turn two of our coins into a diamond. (You could probably do something better, like shapeless recipes to turn 10 coins into a diamond or a diamond into 10 coins.)

Here is the full class including the parts we added earlier:

package modderdojo.firstitem;

import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.registry.GameRegistry;

@Mod(modid = "firstitem", name = "First Item Mod from ModderDojo by Michael", version = "1.0")
public class MyFirstMod
   public void preInit(FMLPreInitializationEvent event)
      MyFirstItem first = new MyFirstItem();
      GameRegistry.registerItem(first, "MichaelFirstItem"); // This name doesn't have to be same as unlocalised name, but no harm in them being the same

      // Recipe to turn 2 of our items into diamond
      ItemStack myStack = new ItemStack(first);
      ItemStack diamond = new ItemStack(Items.diamond);
         "x ",
         " x",
         'x', first);

Note that for built-in items like a diamond, you can write Items.diamond to get a diamond object to use in your  recipe code. Since our item is not built-in, we have to create an item object. We already have one called first in the preInit code, so we use that in our addRecipe code.

One thought on “ModderDojo Java Modding 10: A Recipe for Our New Item

  1. Pingback: ModderDojo Java Modding 11: Packaging our First Mod | CoderDojo Athenry

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s