Skip to content

Commit

Permalink
Make ore dictionary matching non-strict for comp tier lookups; ascend…
Browse files Browse the repository at this point in the history
…ing lookups also prefer same-mod candidates
  • Loading branch information
jaquadro committed Aug 15, 2015
1 parent e8788c1 commit d7997d3
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 13 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,27 +222,69 @@ private ItemStack findHigherTier (ItemStack stack) {
}

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) {
Expand All @@ -263,7 +305,7 @@ private ItemStack findLowerTier (ItemStack stack) {
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());
Expand All @@ -286,7 +328,7 @@ private ItemStack findLowerTier (ItemStack stack) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ public boolean areItemsEqual (ItemStack item) {
}

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)
Expand All @@ -175,7 +179,7 @@ public static boolean areItemsEqual (ItemStack stack1, ItemStack stack2) {
continue;

String name = OreDictionary.getOreName(id1);
if (StorageDrawers.oreDictRegistry.isEntryValid(name)) {
if (!oreDictStrictMode || StorageDrawers.oreDictRegistry.isEntryValid(name)) {
oreMatch = true;
break;
}
Expand Down

0 comments on commit d7997d3

Please sign in to comment.