Skip to content

Commit

Permalink
Added support for the treasure pile to ingot recipes
Browse files Browse the repository at this point in the history
See #13
  • Loading branch information
CraftedMods committed Aug 13, 2019
1 parent 1ed9854 commit 701fc31
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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) {
Expand Down Expand Up @@ -123,4 +128,21 @@ public static String getUnlocalizedEntityName(Class<?> entityClass) {
return EntityList.classToStringMapping.get(entityClass).toString().replace("lotr.", "");
}

public static Pair<Block, Item> 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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<AbstractRecipe, Boolean> undefinedRecipeTypeFound(IRecipe recipe) {
public Pair<Collection<AbstractRecipe>, 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<Collection<AbstractRecipe>, Boolean> processTreasurePileRecipe(LOTRRecipesTreasurePile recipe) {
Pair<Block, Item> 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;
Expand All @@ -42,6 +53,16 @@ public AbstractRecipe loadComplicatedStaticRecipe(ItemStack... stacks) {
return recipe;
}

@Override
public Collection<AbstractRecipe> getDynamicCraftingRecipes(ItemStack result) {
return Arrays.asList();
}

@Override
public Collection<AbstractRecipe> getDynamicUsageRecipes(ItemStack ingredient) {
return Arrays.asList();
}

@Override
public boolean matches(ItemStack stack1, ItemStack stack2) {
return LOTRPoisonedDrinks.isDrinkPoisoned(stack1) == LOTRPoisonedDrinks.isDrinkPoisoned(stack2);
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 @@ -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
Expand Down

0 comments on commit 701fc31

Please sign in to comment.