From 0484805cc05637afc9c45fe156e1ba87f33eaaf1 Mon Sep 17 00:00:00 2001 From: HoleFish <48403212+HoleFish@users.noreply.github.com> Date: Mon, 27 Nov 2023 14:56:02 +0800 Subject: Fix recipe check (#2379) * Update GT_Recipe.java * strange spotless * part of miozune's suggestion * whatever. need more tests --- src/main/java/gregtech/api/util/GT_Recipe.java | 80 +++++++++++--------------- 1 file changed, 32 insertions(+), 48 deletions(-) (limited to 'src/main/java/gregtech/api') diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index 333beeebea..535da25934 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -783,56 +783,40 @@ public class GT_Recipe implements Comparable { } } + double remainingCost; + int providedAmount; if (aInputs != null) { - // Create map for item -> stored amount - Map itemCost = new HashMap<>(); - Map itemMap = new HashMap<>(); - Map itemMapWildcard = new HashMap<>(); // Used only when wildcard input is found - boolean foundWildcard = false; - for (ItemStack itemStack : mInputs) { - if (itemStack == null) continue; - if (itemStack.getItemDamage() == W) { - foundWildcard = true; - } - if (isNBTSensitive) { - itemCost.merge(GT_Utility.ItemId.createNoCopy(itemStack), itemStack.stackSize, Integer::sum); - } else { - itemCost.merge(GT_Utility.ItemId.createWithoutNBT(itemStack), itemStack.stackSize, Integer::sum); - } - } - for (ItemStack itemStack : aInputs) { - if (itemStack == null) continue; - ItemStack unifiedStack = GT_OreDictUnificator.get(false, itemStack, true); - if (unifiedStack == null) continue; - if (isNBTSensitive) { - itemMap.merge(GT_Utility.ItemId.createNoCopy(unifiedStack), unifiedStack.stackSize, Integer::sum); - } else { - itemMap - .merge(GT_Utility.ItemId.createWithoutNBT(unifiedStack), unifiedStack.stackSize, Integer::sum); - } - if (foundWildcard) { - itemMapWildcard - .merge(GT_Utility.ItemId.createAsWildcard(unifiedStack), unifiedStack.stackSize, Integer::sum); - } - } - // Check how many parallels can it perform for each item - for (Map.Entry costEntry : itemCost.entrySet()) { - GT_Utility.ItemId costItem = costEntry.getKey(); - int costValue = costEntry.getValue(); - Map mapToUse = costItem.metaData() == W ? itemMapWildcard : itemMap; - if (costValue > 0) { - currentParallel = Math - .min(currentParallel, (double) mapToUse.getOrDefault(costItem, 0) / costValue); - } else { - // Non-consumed input - // We need to distinguish null and 0 here, since not having item - // and having 0-sized item (ghost circuit) are different. - if (!mapToUse.containsKey(costItem)) { - currentParallel = 0; + nextRecipeItemCost: for (ItemStack recipeItemCost : mInputs) { + + ItemStack unifiedItemCost = GT_OreDictUnificator.get_nocopy(true, recipeItemCost); + if (unifiedItemCost != null) { + remainingCost = recipeItemCost.stackSize * currentParallel; + providedAmount = 0; + + for (ItemStack providedItem : aInputs) { + if (isNBTSensitive && !GT_Utility.areStacksEqual(providedItem, unifiedItemCost, false)) { + continue; + } else if (!isNBTSensitive + && !GT_OreDictUnificator.isInputStackEqual(providedItem, unifiedItemCost)) { + continue; + } + + if (GTppRecipeHelper) { // Please see JavaDoc on GTppRecipeHelper for why this is here. + if (GT_Utility.areStacksEqual(providedItem, Ic2Items.FluidCell.copy(), true) + || GT_Utility.areStacksEqual(providedItem, ItemList.Tool_DataStick.get(1L), true) + || GT_Utility.areStacksEqual(providedItem, ItemList.Tool_DataOrb.get(1L), true)) { + if (!GT_Utility.areStacksEqual(providedItem, recipeItemCost, false)) continue; + } + } + // for non-consumed input + if (recipeItemCost.stackSize == 0) continue nextRecipeItemCost; + + providedAmount += providedItem.stackSize; + + if (providedAmount >= remainingCost) continue nextRecipeItemCost; } - } - if (currentParallel <= 0) { - return 0; + if (providedAmount == 0) return 0; + currentParallel = Math.min(currentParallel, (double) providedAmount / recipeItemCost.stackSize); } } } -- cgit