package agaricus.mods.miscconfiguration;

import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.oredict.OreDictionary;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;

@Mod(modid = "MiscConfiguration", name = "MiscConfiguration", version = "1.0-SNAPSHOT") // TODO: version from resource
@NetworkMod(clientSideRequired = false, serverSideRequired = false)
public class MiscConfiguration {

    private Map<String, ItemStack> itemNames = new HashMap<String, ItemStack>();

    @Mod.PreInit
    public void preInit(FMLPreInitializationEvent event) {
        Configuration cfg = new Configuration(event.getSuggestedConfigurationFile());

        try {
            cfg.load();

        } catch (Exception e) {
            FMLLog.log(Level.SEVERE, e, "MiscConfiguration had a problem loading it's configuration");
        } finally {
            cfg.save();
        }

        FMLLog.log(Level.INFO, "MiscConfiguration enabled");
    }

    @Mod.PostInit
    public void postInit(FMLPostInitializationEvent event) {
    }

    /**
     * Scan item names for lookup
     */
    private void scanItemNames() {
        // TODO: might have to run at first tick, if this is not late enough for all other mods to be loaded

        FMLLog.log(Level.INFO, "Scanning items");
        for (int id = 0; id < Item.itemsList.length; ++id) {
            Item item = Item.itemsList[id];
            if (item == null) continue;

            int damage = 0; // TODO: scan damages?
            ItemStack itemStack = new ItemStack(id, 1, damage);
            try {
                System.out.println("id "+id+" is "+itemStack.getItemName());
            } catch (Throwable t) {
                ;
            }
        }
        // TODO: cache in itemNames
    }

    private ItemStack itemStackByName(String name) {
        // TODO
        //OreDictionary.getOres(name); // gets a list of all matching entries
        //GameRegistry.findItemStack(modId, name, 1); // need mod id

        return null;
    }
}

@@ -389,16 +389,60 @@
 mStack;%0A
+import net.minecraft.item.crafting.IRecipe;%0A
 import n
@@ -534,60 +534,113 @@
 ry;%0A
-%0A
 import 
-java.util.EnumSet;%0Aimport java.util.HashMap;
+net.minecraftforge.oredict.ShapedOreRecipe;%0Aimport net.minecraftforge.oredict.ShapelessOreRecipe;%0A
 %0Aimp
@@ -653,19 +653,17 @@
 va.util.
-Map
+*
 ;%0Aimport
@@ -910,16 +910,78 @@
 tion %7B%0A%0A
+    private List%3CIRecipe%3E recipes = new ArrayList%3CIRecipe%3E();%0A
     priv
@@ -1442,24 +1442,174 @@
 %0A        %7D%0A%0A
+        ItemStack output = new ItemStack(12345, 1, 0);%0A        recipes.add(new ShapelessOreRecipe(output, %22ingotCopper%22)); // TODO: read from config%0A%0A
         FMLL
@@ -1739,24 +1739,119 @@
 nt event) %7B%0A
+        for (IRecipe recipe : recipes) %7B%0A            GameRegistry.addRecipe(recipe);%0A        %7D%0A
     %7D%0A%0A    /

Test adding recipe