From 79bf272f283f1bf3f40dcac2e6fdd913fb6171df Mon Sep 17 00:00:00 2001 From: Pahimar Date: Thu, 26 May 2016 16:04:04 -0400 Subject: [PATCH] Fix a rather insidious bug in the wrapped stack comparator that was causing incorrect energy values to be computed --- .../pahimar/ee3/exchange/WrappedStack.java | 75 +++++++++++-------- 1 file changed, 44 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/pahimar/ee3/exchange/WrappedStack.java b/src/main/java/com/pahimar/ee3/exchange/WrappedStack.java index 165f3cd2..6418b3c9 100644 --- a/src/main/java/com/pahimar/ee3/exchange/WrappedStack.java +++ b/src/main/java/com/pahimar/ee3/exchange/WrappedStack.java @@ -336,55 +336,68 @@ public class WrappedStack implements Comparable { public int compare(WrappedStack wrappedStack1, WrappedStack wrappedStack2) { - if (wrappedStack1.wrappedStack instanceof ItemStack) - { - if (wrappedStack2.wrappedStack instanceof ItemStack) - { - return ItemHelper.compare((ItemStack) wrappedStack1.wrappedStack, (ItemStack) wrappedStack2.wrappedStack); + if (wrappedStack1.wrappedStack instanceof ItemStack) { + + if (wrappedStack2.wrappedStack instanceof ItemStack) { + + int compareResult = ItemHelper.compare((ItemStack) wrappedStack1.wrappedStack, (ItemStack) wrappedStack2.wrappedStack); + + if (compareResult == 0) { + return wrappedStack1.stackSize - wrappedStack2.stackSize; + } + else { + return compareResult; + } } - else - { + else { return 1; } } - else if (wrappedStack1.wrappedStack instanceof OreStack) - { - if (wrappedStack2.wrappedStack instanceof ItemStack) - { + else if (wrappedStack1.wrappedStack instanceof OreStack) { + + if (wrappedStack2.wrappedStack instanceof ItemStack) { return -1; } - else if (wrappedStack2.wrappedStack instanceof OreStack) - { - return OreStack.compare((OreStack) wrappedStack1.wrappedStack, (OreStack) wrappedStack2.wrappedStack); + else if (wrappedStack2.wrappedStack instanceof OreStack) { + + int compareResult = OreStack.compare((OreStack) wrappedStack1.wrappedStack, (OreStack) wrappedStack2.wrappedStack); + + if (compareResult == 0) { + return wrappedStack1.stackSize - wrappedStack2.stackSize; + } + else { + return compareResult; + } } - else - { + else { return 1; } } - else if (wrappedStack1.wrappedStack instanceof FluidStack) - { - if (wrappedStack2.wrappedStack instanceof ItemStack || wrappedStack2.wrappedStack instanceof OreStack) - { + else if (wrappedStack1.wrappedStack instanceof FluidStack) { + + if (wrappedStack2.wrappedStack instanceof ItemStack || wrappedStack2.wrappedStack instanceof OreStack) { return -1; } - else if (wrappedStack2.wrappedStack instanceof FluidStack) - { - return FluidHelper.compare((FluidStack) wrappedStack1.wrappedStack, (FluidStack) wrappedStack2.wrappedStack); + else if (wrappedStack2.wrappedStack instanceof FluidStack) { + + int compareResult = FluidHelper.compare((FluidStack) wrappedStack1.wrappedStack, (FluidStack) wrappedStack2.wrappedStack); + + if (compareResult == 0) { + return wrappedStack1.stackSize - wrappedStack2.stackSize; + } + else { + return compareResult; + } } - else - { + else { return 1; } } - else if (wrappedStack1.wrappedStack == null) - { - if (wrappedStack2.wrappedStack != null) - { + else if (wrappedStack1.wrappedStack == null) { + if (wrappedStack2.wrappedStack != null) { return -1; } - else - { + else { return 0; } }