From 286bdd2fd5f5beb8f6754c266c5fdb050ad19f1d Mon Sep 17 00:00:00 2001 From: darkevilmac Date: Wed, 9 Aug 2017 01:56:32 -0700 Subject: [PATCH] Add exception for missing ores instead of just existing the game. --- .../elytradev/teckle/common/TeckleObjects.java | 18 +++++++++++------- .../common/exception/MissingOreException.java | 7 +++++++ 2 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/elytradev/teckle/common/exception/MissingOreException.java diff --git a/src/main/java/com/elytradev/teckle/common/TeckleObjects.java b/src/main/java/com/elytradev/teckle/common/TeckleObjects.java index 8e10f0b6..1b1f3bd9 100644 --- a/src/main/java/com/elytradev/teckle/common/TeckleObjects.java +++ b/src/main/java/com/elytradev/teckle/common/TeckleObjects.java @@ -19,6 +19,7 @@ import com.elytradev.teckle.common.block.*; import com.elytradev.teckle.common.crafting.AlloyRecipes; import com.elytradev.teckle.common.crafting.RecipeSlice; +import com.elytradev.teckle.common.exception.MissingOreException; import com.elytradev.teckle.common.handlers.PaintbrushRecipe; import com.elytradev.teckle.common.item.ItemBlade; import com.elytradev.teckle.common.item.ItemIngot; @@ -38,7 +39,6 @@ import net.minecraft.item.crafting.IRecipe; import net.minecraft.util.ResourceLocation; import net.minecraftforge.event.RegistryEvent; -import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; @@ -99,12 +99,16 @@ public void init(FMLInitializationEvent e) { public void postInit(FMLPostInitializationEvent e) { // Crash if there's missing ores. - boolean foundMatchingOre = !OreDictionary.getOres("ingotSilver").isEmpty(); - foundMatchingOre = foundMatchingOre && !OreDictionary.getOres("ingotTin").isEmpty(); - foundMatchingOre = foundMatchingOre && !OreDictionary.getOres("ingotCopper").isEmpty(); - if (!foundMatchingOre && !TeckleMod.INDEV) { - TeckleMod.LOG.error("Teckle is missing ores, Tin, Silver, and Copper must be present to run. The game will now exit."); - FMLCommonHandler.instance().exitJava(1, false); + boolean foundSilver = !OreDictionary.getOres("ingotSilver").isEmpty(); + boolean foundTin = !OreDictionary.getOres("ingotTin").isEmpty(); + boolean foundCopper = !OreDictionary.getOres("ingotCopper").isEmpty(); + + boolean foundMatchingOres = foundSilver && foundTin && foundCopper; + if (!foundMatchingOres && !TeckleMod.INDEV) { + String additionalData = (foundSilver ? "Found " : "Couldn't find ") + "silver ingots. "; + additionalData += (foundTin ? "Found " : "Couldn't find ") + "tin ingots. "; + additionalData += (foundCopper ? "Found " : "Couldn't find ") + "copper ingots."; + throw new MissingOreException("Teckle is missing ores, Tin, Silver, and Copper must be present to run. " + additionalData); } } diff --git a/src/main/java/com/elytradev/teckle/common/exception/MissingOreException.java b/src/main/java/com/elytradev/teckle/common/exception/MissingOreException.java new file mode 100644 index 00000000..b4aa8cf2 --- /dev/null +++ b/src/main/java/com/elytradev/teckle/common/exception/MissingOreException.java @@ -0,0 +1,7 @@ +package com.elytradev.teckle.common.exception; + +public class MissingOreException extends RuntimeException { + public MissingOreException(String data) { + super(data); + } +}