Skip to content

Commit

Permalink
Add exception for missing ores instead of just existing the game.
Browse files Browse the repository at this point in the history
  • Loading branch information
darkevilmac committed Aug 9, 2017
1 parent ae713f6 commit 286bdd2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/main/java/com/elytradev/teckle/common/TeckleObjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.elytradev.teckle.common.exception;

public class MissingOreException extends RuntimeException {
public MissingOreException(String data) {
super(data);
}
}

0 comments on commit 286bdd2

Please sign in to comment.