Skip to content

Commit

Permalink
Update GT_OreDictUnificator.java
Browse files Browse the repository at this point in the history
  • Loading branch information
aagrishankov committed Jan 22, 2022
1 parent f450711 commit 851e1c7
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/main/java/gregtech/api/util/GT_OreDictUnificator.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,64 @@ public static ItemStack get(boolean aUseBlackList, ItemStack aStack) {
rStack.setTagCompound(aStack.getTagCompound());
return GT_Utility.copyAmount(aStack.stackSize, rStack);
}

/** Doesn't copy the returned stack or set quantity. Be careful and do not mutate it;
* intended only to optimize comparisons */
public static ItemStack get_nocopy(ItemStack aStack) {
return get_nocopy(true, aStack);
}

/** Doesn't copy the returned stack or set quantity. Be careful and do not mutate it;
* intended only to optimize comparisons */
static ItemStack get_nocopy(boolean aUseBlackList, ItemStack aStack) {
if (GT_Utility.isStackInvalid(aStack)) return null;
ItemData tPrefixMaterial = getAssociation(aStack);
ItemStack rStack = null;
if (tPrefixMaterial == null || !tPrefixMaterial.hasValidPrefixMaterialData() || (aUseBlackList && tPrefixMaterial.mBlackListed))
return aStack;
if (aUseBlackList && !GregTech_API.sUnificationEntriesRegistered && isBlacklisted(aStack)) {
tPrefixMaterial.mBlackListed = true;
return aStack;
}
if (tPrefixMaterial.mUnificationTarget == null)
tPrefixMaterial.mUnificationTarget = sName2StackMap.get(tPrefixMaterial.toString());
rStack = tPrefixMaterial.mUnificationTarget;
if (GT_Utility.isStackInvalid(rStack)) return aStack;
assert rStack != null;
rStack.setTagCompound(aStack.getTagCompound());
return rStack;
}

/** Compares the first argument against an already-unificated second argument as if
* aUseBlackList was both true and false. */
public static boolean isInputStackEqual(ItemStack aStack, ItemStack unified_tStack) {
boolean alreadyCompared = false;
if (GT_Utility.isStackInvalid(aStack)) return false;
ItemData tPrefixMaterial = getAssociation(aStack);
ItemStack rStack = null;
if (tPrefixMaterial == null || !tPrefixMaterial.hasValidPrefixMaterialData())
return GT_Utility.areStacksEqual(aStack, unified_tStack, true);
else if(tPrefixMaterial.mBlackListed) {
if (GT_Utility.areStacksEqual(aStack, unified_tStack, true))
return true;
else
alreadyCompared = true;
}
if (!alreadyCompared && !GregTech_API.sUnificationEntriesRegistered && isBlacklisted(aStack)) {
tPrefixMaterial.mBlackListed = true;
if (GT_Utility.areStacksEqual(aStack, unified_tStack, true))
return true;
else
alreadyCompared = true;
}
if (tPrefixMaterial.mUnificationTarget == null)
tPrefixMaterial.mUnificationTarget = sName2StackMap.get(tPrefixMaterial.toString());
rStack = tPrefixMaterial.mUnificationTarget;
if (GT_Utility.isStackInvalid(rStack))
return !alreadyCompared && GT_Utility.areStacksEqual(aStack, unified_tStack, true);
rStack.setTagCompound(aStack.getTagCompound());
return GT_Utility.areStacksEqual(rStack, unified_tStack, true);
}

public static List<ItemStack> getNonUnifiedStacks(Object obj) {
synchronized (sUnificationTable) {
Expand Down

0 comments on commit 851e1c7

Please sign in to comment.