diff --git a/forge/forge_common/net/minecraft/src/forge/IOreHandler.java b/forge/forge_common/net/minecraft/src/forge/IOreHandler.java new file mode 100644 index 000000000..a4c8651e3 --- /dev/null +++ b/forge/forge_common/net/minecraft/src/forge/IOreHandler.java @@ -0,0 +1,24 @@ +/** + * This software is provided under the terms of the Minecraft Forge Public + * License v1.0. + */ + +package net.minecraft.src.forge; + +import net.minecraft.src.ItemStack; + +/** The current list of known classes. + * oreTin, oreCopper, oreSilver + * ingotTin, ingotCopper, ingotSilver + * dyeBlue + * gemRuby, gemEmerald, gemSapphire + * woodRubber + */ + +public interface IOreHandler { + /** Called when a new ore is registered with the ore dictionary. + * @param oreClass The string class of the ore. + * @param ore The ItemStack for the ore. + */ + public void registerOre(String oreClass, ItemStack ore); +} diff --git a/forge/forge_common/net/minecraft/src/forge/MinecraftForge.java b/forge/forge_common/net/minecraft/src/forge/MinecraftForge.java index cd56b83c0..8a5449338 100755 --- a/forge/forge_common/net/minecraft/src/forge/MinecraftForge.java +++ b/forge/forge_common/net/minecraft/src/forge/MinecraftForge.java @@ -15,7 +15,6 @@ import java.util.*; public class MinecraftForge { private static LinkedList bucketHandlers = new LinkedList(); - /** * Register a new custom bucket handler. */ @@ -66,6 +65,138 @@ public class MinecraftForge { return null; } + // Ore Dictionary + // ------------------------------------------------------------ + private static LinkedList oreHandlers = new LinkedList(); + private static TreeMap> oreDict= + new TreeMap>(); + + /** Register a new ore handler. This will automatically call the handler + * with all current ores during registration, and every time a new ore is + * added later. + */ + public static void registerOreHandler(IOreHandler handler) { + oreHandlers.add(handler); + + for(String key : oreDict.keySet()) { + List val=oreDict.get(key); + for(ItemStack ist : val) { + handler.registerOre(key,ist); + } + } + } + + /** Register a new item with the ore dictionary. + * @param oreClass The string class of the ore. + * @param ore The ItemStack for the ore. + */ + public static void registerOre(String oreClass, ItemStack ore) { + List orelist=oreDict.get(oreClass); + if(orelist==null) { + orelist=new ArrayList(); + oreDict.put(oreClass,orelist); + } + orelist.add(ore); + for(IOreHandler ioh : oreHandlers) { + ioh.registerOre(oreClass,ore); + } + } + + /** Get the list of ores in a given class. + */ + public static List getOreClass(String oreClass) { + return oreDict.get(oreClass); + } + + public static class OreQuery implements Iterable { + Object[] proto; + + public class OreQueryIterator implements Iterator { + LinkedList itering; + LinkedList output; + + private OreQueryIterator() { + itering=new LinkedList(); + output=new LinkedList(); + + for(int i=0; i iterator() { + return new OreQueryIterator(); + } + } + + /** Generate all valid legal recipe combinations. Any Lists in pattern + * will be fully expanded to all valid combinations. + */ + public static OreQuery generateRecipes(Object... pattern) { + return new OreQuery(pattern); + } + + // ------------------------------------------------------------ + /** Register a new plant to be planted when bonemeal is used on grass. * @param bid The block ID to plant. * @param md The metadata to plant.