From d4e1cbfd1f986fad6df33eab119eabc2aa84b05e Mon Sep 17 00:00:00 2001 From: CraftedMods Date: Sun, 11 Aug 2019 17:32:11 +0200 Subject: [PATCH] Closed #51 --- .../api/utils/LOTRRecipeHandlerUtils.java | 29 ++++++++++++++----- src/main/resources/changelog.txt | 1 + 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/main/java/craftedMods/lotr/recipes/api/utils/LOTRRecipeHandlerUtils.java b/src/main/java/craftedMods/lotr/recipes/api/utils/LOTRRecipeHandlerUtils.java index 5f4c182..a048b7a 100644 --- a/src/main/java/craftedMods/lotr/recipes/api/utils/LOTRRecipeHandlerUtils.java +++ b/src/main/java/craftedMods/lotr/recipes/api/utils/LOTRRecipeHandlerUtils.java @@ -19,14 +19,13 @@ import java.lang.reflect.Field; import java.util.*; -import cpw.mods.fml.relauncher.ReflectionHelper; import craftedMods.recipes.api.utils.RecipeHandlerUtils; import craftedMods.recipes.base.*; import lotr.client.gui.LOTRGuiAlloyForge; import lotr.common.item.LOTRItemMug; import lotr.common.recipe.*; import lotr.common.tileentity.LOTRTileEntityAlloyForgeBase; -import net.minecraft.entity.*; +import net.minecraft.entity.EntityList; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; import net.minecraftforge.oredict.OreDictionary; @@ -37,6 +36,9 @@ public class LOTRRecipeHandlerUtils { private static List brewingRecipes; private static float[] drinkStrenghts; + private static Field catalystField; + private static Field theForgeField; + public static ItemStack[] getPoison() { if (LOTRRecipeHandlerUtils.poison == null) { List poisonList = OreDictionary.getOres("poison"); @@ -86,11 +88,14 @@ public static int getDrinkStrengthIndex(float strength) { } public static AbstractRecipe processPoisonWeaponRecipe(LOTRRecipePoisonWeapon poisonRecipe) { - List ingredients = new ArrayList<>(); - ingredients.add(poisonRecipe.getInputItem()); try { - Field catalystField = LOTRRecipePoisonWeapon.class.getDeclaredField("catalystObj"); - catalystField.setAccessible(true); + if (catalystField == null) { + catalystField = LOTRRecipePoisonWeapon.class.getDeclaredField("catalystObj"); + catalystField.setAccessible(true); + } + List ingredients = new ArrayList<>(); + ingredients.add(poisonRecipe.getInputItem()); + ingredients.add(RecipeHandlerUtils.getInstance().extractRecipeItems(catalystField.get(poisonRecipe))); return new ShapelessRecipe(ingredients, poisonRecipe.getRecipeOutput()); } catch (Exception e) { @@ -101,7 +106,17 @@ public static AbstractRecipe processPoisonWeaponRecipe(LOTRRecipePoisonWeapon po } public static LOTRTileEntityAlloyForgeBase getAlloyForge(LOTRGuiAlloyForge gui) { - return ReflectionHelper.getPrivateValue(LOTRGuiAlloyForge.class, gui, "theForge"); + try { + if (theForgeField == null) { + theForgeField = LOTRGuiAlloyForge.class.getDeclaredField("theForge"); + theForgeField.setAccessible(true); + } + return (LOTRTileEntityAlloyForgeBase) theForgeField.get(gui); + } catch (Exception e) { + System.err.print("Couldn't load the poisoned weapon recipe: "); + e.printStackTrace(); + } + return null; } public static String getUnlocalizedEntityName(Class entityClass) { diff --git a/src/main/resources/changelog.txt b/src/main/resources/changelog.txt index 264c638..6182998 100644 --- a/src/main/resources/changelog.txt +++ b/src/main/resources/changelog.txt @@ -9,6 +9,7 @@ Made by 'Crafted_Mods' or 'The_Ranger_Malvegil' + Added a button which shows all recipes of a handler to the handler and device GUIs ("transfer rect") * Fixed wrong recipes with the cauldron recipe handler and Hobbit Pipes with magic smoke + * Slightly improved the performance of the addon #1.0.0-ALPHA: + Defined a public API