diff --git a/src/main/java/glowredman/wherearetheores/WATO.java b/src/main/java/glowredman/wherearetheores/WATO.java index 5314a71..71fb7ba 100644 --- a/src/main/java/glowredman/wherearetheores/WATO.java +++ b/src/main/java/glowredman/wherearetheores/WATO.java @@ -9,6 +9,7 @@ import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.registry.GameRegistry; +import glowredman.wherearetheores.config.ConfigHandler; import glowredman.wherearetheores.proxy.CommonProxy; import net.minecraft.init.Items; import net.minecraft.item.Item; @@ -49,36 +50,78 @@ public static void postInit(FMLPostInitializationEvent event) { * "IC2:dust", "IC2:dust:4". */ public static ItemStack findItem(String item) { + ItemStack ret; String[] parts = item.split(":"); switch (parts.length) { // The item is from minecraft and has no meta value. case 1: - return GameRegistry.findItemStack("minecraft", item, 1); + ret = GameRegistry.findItemStack("minecraft", item, 1); + break; case 2: // The item is from Minecraft and has a meta value. try { ItemStack stack = GameRegistry.findItemStack("minecraft", parts[0], 1); - Items.apple.setDamage(stack, Integer.parseInt(parts[1])); - return stack; + if (stack == null) { + ret = null; + } else { + Items.apple.setDamage(stack, Integer.parseInt(parts[1])); + ret = stack; + } // The item is not from Minecraft and has no meta value. } catch (Exception e) { - return GameRegistry.findItemStack(parts[0], parts[1], 1); + ret = GameRegistry.findItemStack(parts[0], parts[1], 1); } + break; // The item is not from Minecraft and has a meta value. case 3: ItemStack stack = GameRegistry.findItemStack(parts[0], parts[1], 1); - Items.apple.setDamage(stack, Integer.parseInt(parts[2])); - return stack; + if (stack == null) { + ret = null; + } else { + Items.apple.setDamage(stack, Integer.parseInt(parts[2])); + ret = stack; + } + break; default: - WATO.logger.error("Unable to translate \"" + item + "\" to an ItemStack!"); - return null; + ret = null; + } + if (ret == null) + error("Unable to translate \"" + item + "\" to an ItemStack!"); + return ret; + } + + public static void fatal(String message) { + logger.fatal(message); + } + + public static void error(String message) { + logger.error(message); + } + + public static void warn(String message) { + logger.warn(message); + } + + public static void info(String message) { + logger.info(message); + } + + public static void debug(String message) { + if (ConfigHandler.enableDebug) { + logger.info(message); + } else { + logger.debug(message); } } + public static void trace(String message) { + logger.trace(message); + } + public static long getUSIID(ItemStack stack) { return getUSIID(Item.getIdFromItem(stack.getItem()), stack.getItemDamage()); } diff --git a/src/main/java/glowredman/wherearetheores/config/ConfigHandler.java b/src/main/java/glowredman/wherearetheores/config/ConfigHandler.java index ac9caa3..6ed0634 100644 --- a/src/main/java/glowredman/wherearetheores/config/ConfigHandler.java +++ b/src/main/java/glowredman/wherearetheores/config/ConfigHandler.java @@ -23,6 +23,7 @@ public class ConfigHandler { public static File configFile; + public static boolean enableDebug; public static Map>> config = new HashMap>>(); public static Map possibleItems = new HashMap(); @@ -43,15 +44,18 @@ public static void init(FMLPreInitializationEvent event) { "Attempts per Chunk: 3 to 9", "Y-Level: 4 - 31", "This Ore generates only in Hills!"))); list.put("oreQuartz", dimension("Nether", 14, 16, 10, 117)); - ConfigObject holder = new ConfigObject(); - holder.ores = list; + ConfigObject obj = new ConfigObject(); + obj.showDebug = false; + obj.ores = list; BufferedWriter writer = new BufferedWriter(new FileWriter(configFile)); - writer.write(new GsonBuilder().setPrettyPrinting().create().toJson(holder)); + writer.write(new GsonBuilder().setPrettyPrinting().create().toJson(obj)); writer.close(); } - config = new Gson().fromJson(readFile(configFile.getPath()), ConfigObject.class).ores; + ConfigObject configObj = new Gson().fromJson(readFile(configFile.getPath()), ConfigObject.class); + config = configObj.ores; + enableDebug = configObj.showDebug; } catch (Exception e) { e.printStackTrace(); @@ -59,18 +63,36 @@ public static void init(FMLPreInitializationEvent event) { } public static void collectPossibleItems() { + WATO.info("Adding Information for Ores..."); for (String ore : config.keySet()) { if (ore.startsWith("[")) { + WATO.debug(" USIIDs for Item-Key \"" + ore + "\":"); for (String item : ore.substring(1).split(";")) { - possibleItems.put(WATO.getUSIID(WATO.findItem(item)), ore); + ItemStack itemStack = WATO.findItem(item); + if (itemStack == null) + continue; + long usiid = WATO.getUSIID(itemStack); + WATO.debug(" " + item + " -> " + usiid); + String before = possibleItems.put(usiid, ore); + if (before != null) { + WATO.error("The USIID " + usiid + " (previously assosiated with Entry \"" + before + + "\") has been overridden and is now associated with entry \"" + ore + "\"!"); + } } } else { + WATO.debug(" USIIDs for OreDict-Key \"" + ore + "\":"); for (ItemStack stack : OreDictionary.getOres(ore)) { - possibleItems.put(WATO.getUSIID(stack), ore); + long usiid = WATO.getUSIID(stack); + WATO.debug(" " + stack.toString().substring(2) + " -> " + usiid); + String before = possibleItems.put(usiid, ore); + if (before != null) { + WATO.error("The USIID " + usiid + " (previously assosiated with Entry \"" + before + + "\") has been overridden and is now associated with entry \"" + ore + "\"!"); + } } } } - WATO.logger.info("Added Information for " + possibleItems.size() + " Ores!"); + WATO.info("Added Information for " + possibleItems.size() + " Ores!"); } private static Map> dimension(String dim, List info) { diff --git a/src/main/java/glowredman/wherearetheores/config/ConfigObject.java b/src/main/java/glowredman/wherearetheores/config/ConfigObject.java index d3f6965..919a495 100644 --- a/src/main/java/glowredman/wherearetheores/config/ConfigObject.java +++ b/src/main/java/glowredman/wherearetheores/config/ConfigObject.java @@ -6,6 +6,7 @@ public class ConfigObject { + public boolean showDebug; public Map>> ores = new HashMap>>(); } diff --git a/src/main/java/glowredman/wherearetheores/nei/WATORecipeHandler.java b/src/main/java/glowredman/wherearetheores/nei/WATORecipeHandler.java index f9144e9..41b5e69 100644 --- a/src/main/java/glowredman/wherearetheores/nei/WATORecipeHandler.java +++ b/src/main/java/glowredman/wherearetheores/nei/WATORecipeHandler.java @@ -127,7 +127,7 @@ public void loadTransferRects() { /** * Draws a tooltip with details about the dimension the mouse is hovering over. */ - public void drawTooltip(CachedOreRecipe recipe) { + private void drawTooltip(CachedOreRecipe recipe) { Point mouse = GuiDraw.getMousePosition(); Point mouseRel = new Point(mouse.x - getXOffset(), mouse.y - getYOffset());