From 701fc3115b7b9ec8f0608c3442d8dffe8623d21d Mon Sep 17 00:00:00 2001 From: CraftedMods Date: Tue, 13 Aug 2019 14:56:19 +0200 Subject: [PATCH] Added support for the treasure pile to ingot recipes See #13 --- .../api/utils/LOTRRecipeHandlerUtils.java | 24 ++++++++++++++++- ...OTRVanillaCraftingTableSupportHandler.java | 27 ++++++++++++++++--- src/main/resources/changelog.txt | 1 + 3 files changed, 48 insertions(+), 4 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 a048b7a..31d3bad 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,17 @@ import java.lang.reflect.Field; import java.util.*; +import org.apache.commons.lang3.tuple.Pair; + 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.block.Block; import net.minecraft.entity.EntityList; -import net.minecraft.item.ItemStack; +import net.minecraft.item.*; import net.minecraft.item.crafting.IRecipe; import net.minecraftforge.oredict.OreDictionary; @@ -38,6 +41,8 @@ public class LOTRRecipeHandlerUtils { private static Field catalystField; private static Field theForgeField; + private static Field treasureBlockField; + private static Field ingotItemField; public static ItemStack[] getPoison() { if (LOTRRecipeHandlerUtils.poison == null) { @@ -123,4 +128,21 @@ public static String getUnlocalizedEntityName(Class entityClass) { return EntityList.classToStringMapping.get(entityClass).toString().replace("lotr.", ""); } + public static Pair getTreasurePileRecipeItems(LOTRRecipesTreasurePile recipe) { + try { + if (treasureBlockField == null || ingotItemField == null) { + treasureBlockField = LOTRRecipesTreasurePile.class.getDeclaredField("treasureBlock"); + ingotItemField = LOTRRecipesTreasurePile.class.getDeclaredField("ingotItem"); + + treasureBlockField.setAccessible(true); + ingotItemField.setAccessible(true); + } + return Pair.of((Block) treasureBlockField.get(recipe), (Item) ingotItemField.get(recipe)); + } catch (Exception e) { + System.err.print("Couldn't load the poisoned weapon recipe: "); + e.printStackTrace(); + } + return null; + } + } diff --git a/src/main/java/craftedMods/lotr/recipes/internal/recipeHandlers/LOTRVanillaCraftingTableSupportHandler.java b/src/main/java/craftedMods/lotr/recipes/internal/recipeHandlers/LOTRVanillaCraftingTableSupportHandler.java index 31eebaa..3f9b6ec 100644 --- a/src/main/java/craftedMods/lotr/recipes/internal/recipeHandlers/LOTRVanillaCraftingTableSupportHandler.java +++ b/src/main/java/craftedMods/lotr/recipes/internal/recipeHandlers/LOTRVanillaCraftingTableSupportHandler.java @@ -9,19 +9,30 @@ import craftedMods.recipes.base.*; import lotr.common.item.LOTRPoisonedDrinks; import lotr.common.recipe.*; -import net.minecraft.item.ItemStack; +import net.minecraft.block.Block; +import net.minecraft.item.*; import net.minecraft.item.crafting.IRecipe; @RegisteredHandler public class LOTRVanillaCraftingTableSupportHandler implements VanillaCraftingTableRecipeHandlerSupport { @Override - public Pair undefinedRecipeTypeFound(IRecipe recipe) { + public Pair, Boolean> undefinedRecipeTypeFound(IRecipe recipe) { if (recipe instanceof LOTRRecipesPoisonDrinks) return Pair.of(null, true); - if (recipe instanceof LOTRRecipePoisonWeapon) return Pair.of(LOTRRecipeHandlerUtils.processPoisonWeaponRecipe((LOTRRecipePoisonWeapon) recipe), false); + if (recipe instanceof LOTRRecipePoisonWeapon) + return Pair.of(Arrays.asList(LOTRRecipeHandlerUtils.processPoisonWeaponRecipe((LOTRRecipePoisonWeapon) recipe)), false); + if (recipe instanceof LOTRRecipesTreasurePile) return this.processTreasurePileRecipe((LOTRRecipesTreasurePile) recipe); return null; } + private Pair, Boolean> processTreasurePileRecipe(LOTRRecipesTreasurePile recipe) { + Pair recipeItems = LOTRRecipeHandlerUtils.getTreasurePileRecipeItems(recipe); + // TODO Only a subset of the treasure pile recipes is currently supported (pile to ingot) + return Pair.of( + Arrays.asList(new ShapedRecipe(1, 1, new Object[] { new ItemStack(recipeItems.getLeft(), 1, 7) }, new ItemStack(recipeItems.getRight(), 4))), + false); + } + @Override public int getComplicatedStaticRecipeDepth() { return 1; @@ -42,6 +53,16 @@ public AbstractRecipe loadComplicatedStaticRecipe(ItemStack... stacks) { return recipe; } + @Override + public Collection getDynamicCraftingRecipes(ItemStack result) { + return Arrays.asList(); + } + + @Override + public Collection getDynamicUsageRecipes(ItemStack ingredient) { + return Arrays.asList(); + } + @Override public boolean matches(ItemStack stack1, ItemStack stack2) { return LOTRPoisonedDrinks.isDrinkPoisoned(stack1) == LOTRPoisonedDrinks.isDrinkPoisoned(stack2); diff --git a/src/main/resources/changelog.txt b/src/main/resources/changelog.txt index 6182998..bf8a1a2 100644 --- a/src/main/resources/changelog.txt +++ b/src/main/resources/changelog.txt @@ -7,6 +7,7 @@ Made by 'Crafted_Mods' or 'The_Ranger_Malvegil' + Added a trader recipe handler for the Wicked Dwarf + Added the new technical blocks to the item hiding list + Added a button which shows all recipes of a handler to the handler and device GUIs ("transfer rect") + + Added support for the treasure pile to ingot recipes * Fixed wrong recipes with the cauldron recipe handler and Hobbit Pipes with magic smoke * Slightly improved the performance of the addon