From c91b432e09726878ea2d1b4d59a06bedbea2865e Mon Sep 17 00:00:00 2001 From: Gunther De Wachter Date: Thu, 13 Jul 2017 22:18:59 +0200 Subject: [PATCH] Added exceptions to the Recipe handlers. Don't crash, but log to the console what went wrong. --- .../java/appeng/recipes/RecipeHandler.java | 4 ++- .../recipes/helpers/PartRecipeFactory.java | 25 +++++++++++++++++- .../helpers/PartShapedCraftingFactory.java | 25 +++++++++++++++++- .../helpers/PartShapelessCraftingFactory.java | 26 ++++++++++++++++++- 4 files changed, 76 insertions(+), 4 deletions(-) diff --git a/src/main/java/appeng/recipes/RecipeHandler.java b/src/main/java/appeng/recipes/RecipeHandler.java index a1367ea55..5665c3a57 100644 --- a/src/main/java/appeng/recipes/RecipeHandler.java +++ b/src/main/java/appeng/recipes/RecipeHandler.java @@ -800,7 +800,9 @@ public class RecipeHandler implements IRecipeHandler return net.minecraft.item.crafting.Ingredient.fromStacks( itemStack ); } - return null; + + AELog.warn( "Looking for ingredient with name '" + partName + "' ended up with a null item!" ); + return net.minecraft.item.crafting.Ingredient.EMPTY; } } diff --git a/src/main/java/appeng/recipes/helpers/PartRecipeFactory.java b/src/main/java/appeng/recipes/helpers/PartRecipeFactory.java index d4308dd0e..d57d187c8 100644 --- a/src/main/java/appeng/recipes/helpers/PartRecipeFactory.java +++ b/src/main/java/appeng/recipes/helpers/PartRecipeFactory.java @@ -1,7 +1,26 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + package appeng.recipes.helpers; import appeng.core.AppEng; import com.google.gson.JsonObject; +import com.google.gson.JsonSyntaxException; import net.minecraft.item.crafting.IRecipe; import net.minecraft.util.JsonUtils; import net.minecraft.util.ResourceLocation; @@ -35,6 +54,10 @@ public class PartRecipeFactory implements IRecipeFactory return new PartShapelessCraftingFactory( new ResourceLocation( AppEng.MOD_ID, "part_shapeless_crafting" ), recipe.getIngredients(), recipe.getRecipeOutput() ); } - return null; + else + { + throw new JsonSyntaxException( "Applied Energistics 2 was given a custom recipe that it does not know how to handle!\n" + + "Type should either be '" + AppEng.MOD_ID + ":shapeless' or '" + AppEng.MOD_ID + ":shaped', got '"+type+"'!" ); + } } } diff --git a/src/main/java/appeng/recipes/helpers/PartShapedCraftingFactory.java b/src/main/java/appeng/recipes/helpers/PartShapedCraftingFactory.java index a7671bfdc..75e76eca0 100644 --- a/src/main/java/appeng/recipes/helpers/PartShapedCraftingFactory.java +++ b/src/main/java/appeng/recipes/helpers/PartShapedCraftingFactory.java @@ -1,3 +1,21 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + package appeng.recipes.helpers; import appeng.api.recipes.ResolverResult; @@ -104,11 +122,16 @@ public class PartShapedCraftingFactory extends ShapedOreRecipe Item item = Item.getByNameOrId( AppEng.MOD_ID + ":" + resolverResult.itemName ); if(item == null) + { AELog.warn( "item was null for " + resolverResult.itemName + " ( " + ingredient + " )!" ); + throw new JsonSyntaxException ( "Got a null item for " + resolverResult.itemName + " ( " + ingredient + " ). This should never happen!" ); + } ItemStack itemStack = new ItemStack( item, count, resolverResult.damageValue, resolverResult.compound ); return new PartShapedCraftingFactory( group.isEmpty() ? null : new ResourceLocation( group ), itemStack, primer ); } - return null; + + // Should never reach this part unless mangled JSON or bug in AE. + throw new JsonSyntaxException ( "Couldn't find the resulting item in AE. This means AE was provided a recipe that it shouldn't be handling.\nWas looking for : '" + ingredient + "'." ); } } \ No newline at end of file diff --git a/src/main/java/appeng/recipes/helpers/PartShapelessCraftingFactory.java b/src/main/java/appeng/recipes/helpers/PartShapelessCraftingFactory.java index 7bd986b29..da962ecdf 100644 --- a/src/main/java/appeng/recipes/helpers/PartShapelessCraftingFactory.java +++ b/src/main/java/appeng/recipes/helpers/PartShapelessCraftingFactory.java @@ -1,3 +1,21 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + package appeng.recipes.helpers; import appeng.api.recipes.ResolverResult; @@ -8,6 +26,7 @@ import appeng.core.AppEng; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; +import com.google.gson.JsonSyntaxException; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.Ingredient; @@ -55,12 +74,17 @@ public class PartShapelessCraftingFactory extends ShapelessOreRecipe Item item = Item.getByNameOrId( AppEng.MOD_ID + ":" + resolverResult.itemName ); if( item == null ) + { AELog.warn( "item was null for " + resolverResult.itemName + " ( " + ingredient + " )!" ); + throw new JsonSyntaxException ( "Got a null item for " + resolverResult.itemName + " ( " + ingredient + " ). This should never happen!" ); + } ItemStack itemStack = new ItemStack( item, count, resolverResult.damageValue, resolverResult.compound ); return new PartShapelessCraftingFactory(group.isEmpty() ? null : new ResourceLocation(group), ings, itemStack); } - return null; + + throw new JsonSyntaxException( "Couldn't find the resulting item in AE. This means AE was provided a recipe that it shouldn't be handling.\n" + + "Was looking for : '" + ingredient + "'." ); } }