Make ore dictionary matching non-strict for comp tier lookups; ascending lookups also prefer same-mod candidates

This commit is contained in:
Justin Aquadro committed 2015-08-15 01:28:30 -04:00
1 parent e8788c179f
commit d7997d3129
3 files changed
+59 -13

No files matched your search

+1 -1
View File
@@ -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"
@@ -222,27 +222,69 @@ public class TileEntityDrawersComp extends TileEntityDrawers
}
CraftingManager cm = CraftingManager.getInstance();
List<ItemStack> candidates = new ArrayList<ItemStack>();
setupLookup(lookup3, stack);
ItemStack match = cm.findMatchingRecipe(lookup3, worldObj);
List<ItemStack> 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<ItemStack> 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<ItemStack> findAllMatchingRecipes (InventoryCrafting crafting) {
List<ItemStack> candidates = new ArrayList<ItemStack>();
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);
@@ -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;
}