Skip to content

Commit

Permalink
Compacting drawers prefer same-mod materials in descending search.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaquadro committed Jun 21, 2015
1 parent 863425f commit e0e879e
Showing 1 changed file with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import com.jaquadro.minecraft.storagedrawers.storage.*;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.registry.GameData;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -243,6 +245,8 @@ private ItemStack findLowerTier (ItemStack stack) {
CraftingManager cm = CraftingManager.getInstance();
List recipeList = cm.getRecipeList();

List<ItemStack> candidates = new ArrayList<ItemStack>();

for (int i = 0, n = recipeList.size(); i < n; i++) {
IRecipe recipe = (IRecipe) recipeList.get(i);
ItemStack match = null;
Expand Down Expand Up @@ -273,7 +277,31 @@ private ItemStack findLowerTier (ItemStack stack) {
ItemStack comp = cm.findMatchingRecipe(lookup1, worldObj);
if (DrawerData.areItemsEqual(match, comp) && comp.stackSize == recipe.getRecipeSize()) {
lookupSizeResult = recipe.getRecipeSize();
return match;
candidates.add(match);
}
}
}

ItemStack modMatch = findMatchingModCandidate(stack, candidates);
if (modMatch != null)
return modMatch;

if (candidates.size() > 0)
return candidates.get(0);

return null;
}

private ItemStack findMatchingModCandidate (ItemStack reference, List<ItemStack> candidates) {
String referenceName = GameData.getItemRegistry().getNameForObject(reference.getItem());
if (referenceName != null) {
GameRegistry.UniqueIdentifier referneceID = new GameRegistry.UniqueIdentifier(referenceName);
for (ItemStack candidate : candidates) {
String matchName = GameData.getItemRegistry().getNameForObject(candidate.getItem());
if (matchName != null) {
GameRegistry.UniqueIdentifier matchID = new GameRegistry.UniqueIdentifier(matchName);
if (referneceID.modId.equals(matchID.modId))
return candidate;
}
}
}
Expand Down Expand Up @@ -341,7 +369,10 @@ else if (item instanceof ArrayList) {

ArrayList itemList = (ArrayList)item;
if (itemList.size() > 0) {
Object item1 = itemList.get(0);
Object item1 = findMatchingModCandidate(stack, itemList);
if (item1 == null)
item1 = itemList.get(0);

if (item1 instanceof ItemStack)
return (ItemStack)item1;
}
Expand Down

0 comments on commit e0e879e

Please sign in to comment.