From 8a2df51193fd3db145f3b1ace974e9e0a0bc09a5 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Wed, 5 Aug 2020 17:14:07 +0800 Subject: REI 5.1.0: - Improve auto crafting, now able to detect things on the grid - Introduce getResultingEntries as a replacement for getOutputEntries, it can now handle lists of lists of stacks - Caching for fluid hashing - Full fractions support for simple recipe display - Made searchFavorites defaulted false Signed-off-by: shedaniel --- .../me/shedaniel/rei/impl/FluidEntryStack.java | 26 ++++++++++++++-------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/FluidEntryStack.java') diff --git a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/FluidEntryStack.java b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/FluidEntryStack.java index 8a7c395dd..d75deeda5 100644 --- a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/FluidEntryStack.java +++ b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/FluidEntryStack.java @@ -65,6 +65,8 @@ public class FluidEntryStack extends AbstractEntryStack { private static final Fraction IGNORE_AMOUNT = Fraction.of(ThreadLocalRandom.current().nextLong(), ThreadLocalRandom.current().nextLong(Long.MAX_VALUE)).simplify(); private Fluid fluid; private Fraction amount; + private int hashIgnoreAmount; + private int hash; public FluidEntryStack(Fluid fluid) { this(fluid, IGNORE_AMOUNT); @@ -73,6 +75,15 @@ public class FluidEntryStack extends AbstractEntryStack { public FluidEntryStack(Fluid fluid, Fraction amount) { this.fluid = fluid; this.amount = amount; + + rehash(); + } + + private void rehash() { + hashIgnoreAmount = 31 + getType().ordinal(); + hashIgnoreAmount = 31 * hashIgnoreAmount + fluid.hashCode(); + + hash = 31 * hashIgnoreAmount + amount.hashCode(); } @Override @@ -96,6 +107,8 @@ public class FluidEntryStack extends AbstractEntryStack { if (isEmpty()) { fluid = Fluids.EMPTY; } + + rehash(); } private > T max(T o1, T o2) { @@ -157,27 +170,22 @@ public class FluidEntryStack extends AbstractEntryStack { @Override public int hashOfAll() { - int result = hashIgnoreAmountAndTags(); - result = 31 * result + amount.hashCode(); - return result; + return hash; } @Override public int hashIgnoreAmountAndTags() { - int result = 1; - result = 31 * result + getType().ordinal(); - result = 31 * result + fluid.hashCode(); - return result; + return hashIgnoreAmount; } @Override public int hashIgnoreTags() { - return hashOfAll(); + return hash; } @Override public int hashIgnoreAmount() { - return hashIgnoreAmountAndTags(); + return hashIgnoreAmount; } @Nullable -- cgit