From b38db9ae7a12871e619e773edc0df705be1bffa2 Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 26 Oct 2015 16:35:53 -0700 Subject: [PATCH] Swallow the NPE caused when other mods add recipes with null inputs Also swallows the NPE caused by players adding a dead and outdated mod to their instance. Read as: Screw you BiblioWoods Forestry. --- .../compress/StorageBlockCraftingManager.java | 3 ++- ...StorageBlockCraftingRecipeAssimilator.java | 27 ++++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/compress/StorageBlockCraftingManager.java b/src/main/java/WayofTime/alchemicalWizardry/common/compress/StorageBlockCraftingManager.java index 6f52fefa..9b90faa9 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/compress/StorageBlockCraftingManager.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/compress/StorageBlockCraftingManager.java @@ -3,6 +3,7 @@ package WayofTime.alchemicalWizardry.common.compress; import java.util.LinkedList; import java.util.List; +import WayofTime.alchemicalWizardry.AlchemicalWizardry; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.InventoryCrafting; @@ -26,7 +27,7 @@ public class StorageBlockCraftingManager { this.recipes = new StorageBlockCraftingRecipeAssimilator().getPackingRecipes(); - System.out.println("Total number of compression recipes: " + this.recipes.size()); + AlchemicalWizardry.logger.info("Total number of compression recipes: " + this.recipes.size()); // List tempRecipeList = new LinkedList(); // // World world = DimensionManager.getWorld(0); diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/compress/StorageBlockCraftingRecipeAssimilator.java b/src/main/java/WayofTime/alchemicalWizardry/common/compress/StorageBlockCraftingRecipeAssimilator.java index 7025d0f5..efe9fb43 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/compress/StorageBlockCraftingRecipeAssimilator.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/compress/StorageBlockCraftingRecipeAssimilator.java @@ -21,6 +21,11 @@ import net.minecraftforge.oredict.ShapedOreRecipe; import net.minecraftforge.oredict.ShapelessOreRecipe; public class StorageBlockCraftingRecipeAssimilator { + + public static String[] problemMods = { + "BiblioWoodsForestry" + }; + public List getPackingRecipes() { // grab all recipes potentially suitable for packing or unpacking @@ -220,12 +225,26 @@ public class StorageBlockCraftingRecipeAssimilator { } private boolean areInputsIdentical(ItemStack a, ItemStack b) { - if (a.getItem() != b.getItem()) return false; - int dmgA = a.getItemDamage(); - int dmgB = b.getItemDamage(); + try { + if (a.getItem() != b.getItem()) + return false; - return dmgA == dmgB || dmgA == OreDictionary.WILDCARD_VALUE || dmgB == OreDictionary.WILDCARD_VALUE; + int dmgA = a.getItemDamage(); + int dmgB = b.getItemDamage(); + + return dmgA == dmgB || dmgA == OreDictionary.WILDCARD_VALUE || dmgB == OreDictionary.WILDCARD_VALUE; + } catch (NullPointerException e) { + + AlchemicalWizardry.logger.error("A mod in this instance has registered an item with a null input. Known problem mods are:"); + + String err = ""; + for (String problem : problemMods) + err += (err.length() > 0 ? ", " : "") + problem; + AlchemicalWizardry.logger.error(err); + + return false; + } } private static class PackingRecipe {