Skip to content

Commit

Permalink
Add some debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
glowredman committed Apr 12, 2021
1 parent cf5c892 commit b2231b5
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 16 deletions.
59 changes: 51 additions & 8 deletions src/main/java/glowredman/wherearetheores/WATO.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down
36 changes: 29 additions & 7 deletions src/main/java/glowredman/wherearetheores/config/ConfigHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
public class ConfigHandler {

public static File configFile;
public static boolean enableDebug;
public static Map<String, Map<String, List<String>>> config = new HashMap<String, Map<String, List<String>>>();
public static Map<Long, String> possibleItems = new HashMap<Long, String>();

Expand All @@ -43,34 +44,55 @@ 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();
}
}

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<String, List<String>> dimension(String dim, List<String> info) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

public class ConfigObject {

public boolean showDebug;
public Map<String, Map<String, List<String>>> ores = new HashMap<String, Map<String,List<String>>>();

}
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down

0 comments on commit b2231b5

Please sign in to comment.