How to use the ore dictionary

From Minecraft Forge
Jump to: navigation, search

Contents

Prerequisites

Minecraft Version

1.6.4

Forge Build

This tutorial was written for Minecraft Forge recommended build 953 1.6.4

Registering an Ore

In this tutorial I am going to teach you how to use the ore dictionary feature of Minecraft Forge. In this tutorial I assume you know how to make a basic block and item and install Forge. We are going to start out with some basic code with nothing but a mod template. I have broken up Recipes, Name registration, and Ore Registration using the OreDictionary into separate methods for Organization(You should already know how to make a CommonProxy and ClientProxy before viewing this tutorial)

If you don't know what ore dictionary name you should assign to your ores then you might visit: Common Oredict names

package net.minecraft.CopperMod.src;

import net.minecraft.CopperMod.src.CommonProxy;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;



@NetworkMod(clientSideRequired = true, serverSideRequired = false)
@Mod(modid = "YourModID", name = "Copper Mod", version = "0.0.1")

public class CopperMod
{
        @SidedProxy(clientSide = "net.minecraft.CopperMod.src.ClientProxy", serverSide = "net.minecraft.CopperMod.src.CommonProxy")
        public static CommonProxy proxy;
       
        @Instance(value="YourModID")
        public static CopperMod instance;
       
        @EventHandler
        //1.3.2 @Init
        public void load(FMLInitializationEvent event)
        {
                addNames();
                oreRegistration();
                addOreRecipes();
        }
       
        public static void addNames()
        {
               
        }
       
        public static void oreRegistration()
        {
               
        }
       
        public static void addOreRecipes()
        {
               
        }
}

Now, I'm going to add a simple copper ingot that we will add into the ore dictionary.

package net.minecraft.CopperMod.src;

import net.minecraft.CopperMod.src.CommonProxy;
import net.minecraft.src.Block;
import net.minecraft.src.CraftingManager;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.LanguageRegistry;


@NetworkMod(clientSideRequired = true, serverSideRequired = false)
@Mod(modid = "YourModID", name = "Copper Mod", version = "0.0.1")

public class CopperMod
{
        @SidedProxy(clientSide = "net.minecraft.CopperMod.src.ClientProxy", serverSide = "net.minecraft.CopperMod.src.CommonProxy")
        public static CommonProxy proxy;
       
        @Instance(value="YourModID")
        public static CopperMod instance;
       
        public static Item ingotCopper = new ItemCopperIngot(5000).setIconIndex(20).setItemName("Copper Ingot");
        @EventHandler
        //1.3.2 @Init
        public void load(FMLInitializationEvent event)
        {
                addNames();
                oreRegistration();
                addOreRecipes();
        }
       
        public static void addNames()
        {
                LanguageRegistry.addName(ingotCopper, "Copper Ingot");
        }
       
        public static void oreRegistration()
        {
         
        }
       
        public static void addOreRecipes()
        {
         
        }
}

Not a very functional copper ingot, but it's sufficient for this tutorial. You should already know how to implement a new item by now. Now we're going to add the ore dictionary code into our @Init method, which in copper's case is:

OreDictionary.registerOre("ingotCopper", new ItemStack(ingotCopper));

Replace the ingotCopper on the left with whatever you want to register your ore as. There is technically no incorrect name to register an item under, but don't expect any other mods to use your ore if you don't follow standards. The typical format is "itemType" such as "ingotCopper", "oreSilver" or "woodRubber". The documentation for IOreHandler lists some examples of ore registrations, but those are by no means a complete list, so don't feel limited by just those entries. All registering does is let Forge know "Hey, I have an item here of type 'ingotCopper' that other mods may also want to use." You can just as easily register flannel colored wool as "woolFlannel" if you think it'll be something other mods will be using.

In case you're confused about the new ItemStack() thing, that's a constructor of ItemStack, which basically means that it is a block or item, and can have a quantity and damage value. Don't use the quantities other than 1 while implementing the ore dictionary, though.

And that's it! Pretty simple, huh? Now, if your mod is installed alongside another mod that uses copper from the ore dictionary such as IndustrialCraft2 or Forestry, those mods will be able to use copper ingots from your mod in their recipes.

If you have a problem, message me on the MinecraftForge Forums. Username: Ghostrec35.
Final code:

package net.minecraft.CopperMod.src;

import net.minecraft.CopperMod.src.CommonProxy;
import net.minecraft.src.Block;
import net.minecraft.src.CraftingManager;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import net.minecraftforge.oredict.ShapedOreRecipe;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.LanguageRegistry;


@NetworkMod(clientSideRequired = true, serverSideRequired = false)
@Mod(modid = "test", name = "Copper Mod", version = "0.0.1")

public class CopperMod
{
        @SidedProxy(clientSide = "net.minecraft.CopperMod.src.ClientProxy", serverSide = "net.minecraft.CopperMod.src.CommonProxy")
        public static CommonProxy proxy;
       
        @Instance(value="test")
        public static CopperMod instance;
       
        public static Item ingotCopper = new ItemCopperIngot(5000).setIconIndex(20).setItemName("Copper Ingot");
        @EventHandler
        //1.3.2 @Init
        public void load(FMLInitializationEvent event)
        {
                addNames();
                oreRegistration();
                addOreRecipes();
                proxy.init();
        }
       
        public static void addNames()
        {
                LanguageRegistry.addName(ingotCopper, "Copper Ingot");
        }
       
        public static void oreRegistration()
        {
                //1.3.2 OreDictionary.registerOre("ingotCopper", new ItemStack(ingotCopper));
                //1.6.4
                OreDictionary.registerOre("ingotCopper", ingotCopper);
        }
       
        public static void addOreRecipes()
        {

        }
}

Creating Recipes that use the Ore Dictionary

So, you now have copper ingots that other mods can use, but what if you want to use other mods' copper ingots? That's where the CraftingManager comes into play. Let's go back to the copper mod shown above. First off, if we want to use another mod's copper ingots, we should probably give copper ingots a use. Lets go with a simple recipe to make buckets out of copper ingots.

package net.minecraft.CopperMod.src;

import net.minecraft.CopperMod.src.CommonProxy;
import net.minecraft.src.Block;
import net.minecraft.src.CraftingManager;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import net.minecraftforge.oredict.ShapedOreRecipe;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.LanguageRegistry;


@NetworkMod(clientSideRequired = true, serverSideRequired = false)
@Mod(modid = "test", name = "Copper Mod", version = "0.0.1")

public class CopperMod
{
        @SidedProxy(clientSide = "net.minecraft.CopperMod.src.ClientProxy", serverSide = "net.minecraft.CopperMod.src.CommonProxy")
        public static CommonProxy proxy;
       
        @Instance(value="test")
        public static CopperMod instance;
       
        public static Item ingotCopper = new ItemCopperIngot(5000).setIconIndex(20).setItemName("Copper Ingot");
        @EventHandler
        //1.3.2 @Init
        public void load(FMLInitializationEvent event)
        {
                addNames();
                oreRegistration();
                addOreRecipes();
                proxy.init();
        }
       
        public static void addNames()
        {
                LanguageRegistry.addName(ingotCopper, "Copper Ingot");
        }
       
        public static void oreRegistration()
        {
                //1.3.2 OreDictionary.registerOre("ingotCopper", new ItemStack(ingotCopper));
                //1.6.4
                OreDictionary.registerOre("ingotCopper", ingotCopper);
        }
       
        public static void addOreRecipes()
        {
                GameRegistry.addRecipe(new ShapedOreRecipe(Item.bucketEmpty, true, new Object[]{
                                "FF", Character.valueOf('F'), ingotCopper}));
        }
}

Now, copper ingots from this mod can be crafted into buckets, but other copper ingots can't. In order to add recipes for those copper ingots, we'll need to use the String you used to signify your ingot in the OreDictionary. In this case me merely have to change the Item ingotCopper to the String "ingotCopper".

package net.minecraft.CopperMod.src;

import net.minecraft.CopperMod.src.CommonProxy;
import net.minecraft.src.Block;
import net.minecraft.src.CraftingManager;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import net.minecraftforge.oredict.ShapedOreRecipe;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.LanguageRegistry;


@NetworkMod(clientSideRequired = true, serverSideRequired = false)
@Mod(modid = "test", name = "Copper Mod", version = "0.0.1")

public class CopperMod
{
        @SidedProxy(clientSide = "net.minecraft.CopperMod.src.ClientProxy", serverSide = "net.minecraft.CopperMod.src.CommonProxy")
        public static CommonProxy proxy;
       
        @Instance(value="test")
        public static CopperMod instance;
       
        public static Item ingotCopper = new ItemCopperIngot(5000).setIconIndex(20).setItemName("Copper Ingot");
        @EventHandler
        //1.3.2 @Init
        public void load(FMLInitializationEvent event)
        {
                addNames();
                oreRegistration();
                addOreRecipes();
                proxy.init();
        }
       
        public static void addNames()
        {
                LanguageRegistry.addName(ingotCopper, "Copper Ingot");
        }
       
        public static void oreRegistration()
        {
                //1.3.2 OreDictionary.registerOre("ingotCopper", new ItemStack(ingotCopper));
                //1.6.4
                OreDictionary.registerOre("ingotCopper", ingotCopper);
        }
       
        public static void addOreRecipes()
        {
                GameRegistry.addRecipe(new ShapedOreRecipe(Item.bucketEmpty, true, new Object[]{
                                "FF", Character.valueOf('F'), "ingotCopper"}));
        }
}


Now your mod should be all set. Other mods will be able to use your copper ingots for their own recipes, and you can use other mods' copper ingots for your bucket recipe.

Credits

Originally made by: volcomrj (from LethalComboFilms)
Huge thanks to Methusaleh96 who taught volcromj almost everything he knows about modding.
Thanks to LexManos for the correction to his stupid mistake(s).

--Volcomrj 16:29, 9 June 2012 (PDT)


With some help from: SpitefulFox
volcomrj EDIT: A LOT of help.

Re-created for Minecraft 1.3.2 (Minecraft Forge 4.x) by Ghostrec35

--Ghostrec35 14:40, 1 September 2012 (EST)

Added a link to the Common Oredict names page created by me

--ExE Boss 03:20, 20 November 2012 (PST)

Personal tools
Namespaces
Variants
Actions
Navigation
tutorials
Toolbox