From d7997d312992877c1e270e2c4892548f71fe6bfd Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Sat, 15 Aug 2015 01:28:30 -0400 Subject: [PATCH] Make ore dictionary matching non-strict for comp tier lookups; ascending lookups also prefer same-mod candidates --- build.gradle | 2 +- .../block/tile/TileEntityDrawersComp.java | 64 +++++++++++++++---- .../storage/BaseDrawerData.java | 6 +- 3 files changed, 59 insertions(+), 13 deletions(-) diff --git a/build.gradle b/build.gradle index 38ec380..dae56c9 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ buildscript { apply plugin: 'forge' -version = "1.7.10-1.5.12" +version = "1.7.10-1.5.13" group= "com.jaquadro.minecraft.storagedrawers" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "StorageDrawers" diff --git a/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityDrawersComp.java b/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityDrawersComp.java index 6b37560..9f1e3fd 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityDrawersComp.java +++ b/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityDrawersComp.java @@ -222,27 +222,69 @@ public class TileEntityDrawersComp extends TileEntityDrawers } CraftingManager cm = CraftingManager.getInstance(); + List candidates = new ArrayList(); setupLookup(lookup3, stack); - ItemStack match = cm.findMatchingRecipe(lookup3, worldObj); + List fwdCandidates = findAllMatchingRecipes(lookup3); - if (match == null || match.getItem() == null) { + if (fwdCandidates.size() == 0) { setupLookup(lookup2, stack); - match = cm.findMatchingRecipe(lookup2, worldObj); + fwdCandidates = findAllMatchingRecipes(lookup2); } - if (match != null && match.getItem() != null) { + if (fwdCandidates.size() > 0) { int size = lookupSizeResult; - setupLookup(lookup1, match); - ItemStack comp = cm.findMatchingRecipe(lookup1, worldObj); - if (!DrawerData.areItemsEqual(comp, stack) || comp.stackSize != size) - return null; + for (int i = 0, n1 = fwdCandidates.size(); i < n1; i++) { + ItemStack match = fwdCandidates.get(i); + setupLookup(lookup1, match); + List backCandidates = findAllMatchingRecipes(lookup1); + + for (int j = 0, n2 = backCandidates.size(); j < n2; j++) { + ItemStack comp = backCandidates.get(j); + if (comp.stackSize != size) + continue; + + if (!DrawerData.areItemsEqual(comp, stack, false)) + continue; + + candidates.add(match); + if (!worldObj.isRemote && StorageDrawers.config.cache.debugTrace) + FMLLog.log(StorageDrawers.MOD_ID, Level.INFO, "Found ascending candidate for " + stack.toString() + ": " + match.toString() + " size=" + lookupSizeResult + ", inverse=" + comp.toString()); + + break; + } + } lookupSizeResult = size; } - return match; + ItemStack modMatch = findMatchingModCandidate(stack, candidates); + if (modMatch != null) + return modMatch; + + if (candidates.size() > 0) + return candidates.get(0); + + return null; + } + + private List findAllMatchingRecipes (InventoryCrafting crafting) { + List candidates = new ArrayList(); + + CraftingManager cm = CraftingManager.getInstance(); + List recipeList = cm.getRecipeList(); + + for (int i = 0, n = recipeList.size(); i < n; i++) { + IRecipe recipe = (IRecipe) recipeList.get(i); + if (recipe.matches(crafting, worldObj)) { + ItemStack result = recipe.getCraftingResult(crafting); + if (result != null && result.getItem() != null) + candidates.add(result); + } + } + + return candidates; } private ItemStack findLowerTier (ItemStack stack) { @@ -263,7 +305,7 @@ public class TileEntityDrawersComp extends TileEntityDrawers ItemStack match = null; ItemStack output = recipe.getRecipeOutput(); - if (!DrawerData.areItemsEqual(stack, output)) + if (!DrawerData.areItemsEqual(stack, output, false)) continue; IRecipeHandler handler = StorageDrawers.recipeHandlerRegistry.getRecipeHandler(recipe.getClass()); @@ -286,7 +328,7 @@ public class TileEntityDrawersComp extends TileEntityDrawers if (match != null) { setupLookup(lookup1, stack); ItemStack comp = cm.findMatchingRecipe(lookup1, worldObj); - if (DrawerData.areItemsEqual(match, comp) && comp.stackSize == recipe.getRecipeSize()) { + if (DrawerData.areItemsEqual(match, comp, false) && comp.stackSize == recipe.getRecipeSize()) { lookupSizeResult = recipe.getRecipeSize(); candidates.add(match); candidatesRate.put(match, lookupSizeResult); diff --git a/src/com/jaquadro/minecraft/storagedrawers/storage/BaseDrawerData.java b/src/com/jaquadro/minecraft/storagedrawers/storage/BaseDrawerData.java index fb8a860..ab1ee76 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/storage/BaseDrawerData.java +++ b/src/com/jaquadro/minecraft/storagedrawers/storage/BaseDrawerData.java @@ -150,6 +150,10 @@ public abstract class BaseDrawerData implements IDrawer, IInventoryAdapter } public static boolean areItemsEqual (ItemStack stack1, ItemStack stack2) { + return areItemsEqual(stack1, stack2, true); + } + + public static boolean areItemsEqual (ItemStack stack1, ItemStack stack2, boolean oreDictStrictMode) { if (stack1 == null || stack2 == null) return false; if (stack1.getItem() == null || stack2.getItem() == null) @@ -175,7 +179,7 @@ public abstract class BaseDrawerData implements IDrawer, IInventoryAdapter continue; String name = OreDictionary.getOreName(id1); - if (StorageDrawers.oreDictRegistry.isEntryValid(name)) { + if (!oreDictStrictMode || StorageDrawers.oreDictRegistry.isEntryValid(name)) { oreMatch = true; break; }