Skip to content

Commit

Permalink
Closed #51
Browse files Browse the repository at this point in the history
  • Loading branch information
CraftedMods committed Aug 11, 2019
1 parent 67933c0 commit d4e1cbf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,6 +36,9 @@ public class LOTRRecipeHandlerUtils {
private static List<IRecipe> brewingRecipes;
private static float[] drinkStrenghts;

private static Field catalystField;
private static Field theForgeField;

public static ItemStack[] getPoison() {
if (LOTRRecipeHandlerUtils.poison == null) {
List<ItemStack> poisonList = OreDictionary.getOres("poison");
Expand Down Expand Up @@ -86,11 +88,14 @@ public static int getDrinkStrengthIndex(float strength) {
}

public static AbstractRecipe processPoisonWeaponRecipe(LOTRRecipePoisonWeapon poisonRecipe) {
List<Object> 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<Object> ingredients = new ArrayList<>();
ingredients.add(poisonRecipe.getInputItem());

ingredients.add(RecipeHandlerUtils.getInstance().extractRecipeItems(catalystField.get(poisonRecipe)));
return new ShapelessRecipe(ingredients, poisonRecipe.getRecipeOutput());
} catch (Exception e) {
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d4e1cbf

Please sign in to comment.