aboutsummaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2021-06-30 22:34:51 +0800
committershedaniel <daniel@shedaniel.me>2021-06-30 22:34:51 +0800
commit828247bd6266556bbdd3c1ba41a2d0909c9f68b8 (patch)
tree1aae621724d18791070f3c9e271c9795569e7865 /api
parent4cbdc5d77a1406ef6d8b350ddedce987cbed3647 (diff)
downloadRoughlyEnoughItems-828247bd6266556bbdd3c1ba41a2d0909c9f68b8.tar.gz
RoughlyEnoughItems-828247bd6266556bbdd3c1ba41a2d0909c9f68b8.tar.bz2
RoughlyEnoughItems-828247bd6266556bbdd3c1ba41a2d0909c9f68b8.zip
Improve ComparisonContext matching
Diffstat (limited to 'api')
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/gui/SimpleDisplayRenderer.java1
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/registry/entry/EntryRegistry.java10
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/ComparisonContext.java14
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/EntryComparatorRegistry.java3
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/common/util/EntryStacks.java32
5 files changed, 42 insertions, 18 deletions
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/SimpleDisplayRenderer.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/SimpleDisplayRenderer.java
index 95fc9ef6b..246a32979 100644
--- a/api/src/main/java/me/shedaniel/rei/api/client/gui/SimpleDisplayRenderer.java
+++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/SimpleDisplayRenderer.java
@@ -51,7 +51,6 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
public class SimpleDisplayRenderer extends DisplayRenderer implements WidgetHolder {
- protected static final Comparator<EntryStack<?>> ENTRY_COMPARATOR = Comparator.comparingLong(EntryStacks::hashExact);
protected static final ResourceLocation CHEST_GUI_TEXTURE = new ResourceLocation("roughlyenoughitems", "textures/gui/recipecontainer.png");
protected List<Slot> inputWidgets;
protected List<Slot> outputWidgets;
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/entry/EntryRegistry.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/entry/EntryRegistry.java
index 6c439a43c..b4d206910 100644
--- a/api/src/main/java/me/shedaniel/rei/api/client/registry/entry/EntryRegistry.java
+++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/entry/EntryRegistry.java
@@ -183,4 +183,14 @@ public interface EntryRegistry extends Reloadable<REIClientPlugin> {
* @return whether it was successful to remove any entry
*/
boolean removeEntryExactHashIf(LongPredicate predicate);
+
+ /**
+ * Removes entries from the entry list, if it matches the predicate.
+ * This method is usually faster than {@link #removeEntryIf(Predicate)}
+ * due to its fast comparison.
+ *
+ * @param predicate a predicate which returns {@code true} for the entries to be removed
+ * @return whether it was successful to remove any entry
+ */
+ boolean removeEntryFuzzyHashIf(LongPredicate predicate);
}
diff --git a/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/ComparisonContext.java b/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/ComparisonContext.java
index 8e2917dbc..1094a88e3 100644
--- a/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/ComparisonContext.java
+++ b/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/ComparisonContext.java
@@ -25,11 +25,21 @@ package me.shedaniel.rei.api.common.entry.comparison;
public enum ComparisonContext {
/**
- * Should only compare the type of the object, normalized stacks may still not be the same.
+ * Should only compare the type of the object.
+ * <p>
+ * The fuzzy context type denotes that the equivalent stacks should be <b>primarily</b> the same.
+ * <p>
+ * For example, enchantment books of different enchantments should be different within this context,
+ * while tools with different damage values and different enchantments should be treated as the same within this context.
+ * Skulker boxes with different content should be different within this context.
*/
FUZZY(false),
/**
- * Should compare the nbt and the type of the object, normalized stacks should be exactly the same.
+ * Should compare the nbt and the type of the object.
+ * <p>
+ * The exact context type denotes that the equivalent stacks should be <b>functionally</b> the same.
+ * <p>
+ * For example, tools with different damage values and different enchantments should be treated as different within this context.
*/
EXACT(true);
diff --git a/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/EntryComparatorRegistry.java b/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/EntryComparatorRegistry.java
index 7c051bac1..fecdabacf 100644
--- a/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/EntryComparatorRegistry.java
+++ b/api/src/main/java/me/shedaniel/rei/api/common/entry/comparison/EntryComparatorRegistry.java
@@ -30,9 +30,6 @@ import me.shedaniel.rei.api.common.registry.Reloadable;
* Registry for registering custom methods for identifying variants of {@link T}.
* The default comparator is {@link EntryComparator#noop()} when fuzzy, which does not compare the NBT of the entries;
* and nbt when exact.
- *
- * <p>
- * This comparator is used when the comparison context is {@link ComparisonContext#EXACT}.
*/
public interface EntryComparatorRegistry<T, S> extends Reloadable<REIPlugin<?>> {
void register(EntryComparator<T> comparator, S entry);
diff --git a/api/src/main/java/me/shedaniel/rei/api/common/util/EntryStacks.java b/api/src/main/java/me/shedaniel/rei/api/common/util/EntryStacks.java
index 10c3aaa6d..91805a6ed 100644
--- a/api/src/main/java/me/shedaniel/rei/api/common/util/EntryStacks.java
+++ b/api/src/main/java/me/shedaniel/rei/api/common/util/EntryStacks.java
@@ -114,10 +114,11 @@ public final class EntryStacks {
}
/**
- * Compares equality for the {@link ComparisonContext#EXACT} context, stacks that equal should share the same normalized stack.
+ * Compares equality for the {@link ComparisonContext#EXACT} context.
* <p>
- * For example, enchantment books of different enchantments will not be equal under this context.
- * However, difference between the amount of objects in a stack will not affect the result.
+ * The exact context type denotes that the equivalent stacks should be <b>functionally</b> the same.
+ * <p>
+ * For example, tools with different damage values and different enchantments should be treated as different within this context.
*
* @param left the first stack to compare
* @param right the second stack to compare
@@ -128,10 +129,13 @@ public final class EntryStacks {
}
/**
- * Compares equality for the {@link ComparisonContext#FUZZY} context, stacks that equal may not share the same normalized stack.
- * This result is less specific, mainly used for fuzzy matching between different stacks.
+ * Compares equality for the {@link ComparisonContext#FUZZY} context.
+ * <p>
+ * The fuzzy context type denotes that the equivalent stacks should be <b>primarily</b> the same.
* <p>
- * For example, enchantment books of different enchantments should still be equal under this context.
+ * For example, enchantment books of different enchantments should be different within this context,
+ * while tools with different damage values and different enchantments should be treated as the same within this context.
+ * Skulker boxes with different content should be different within this context.
*
* @param left the first stack to compare
* @param right the second stack to compare
@@ -154,10 +158,11 @@ public final class EntryStacks {
}
/**
- * Hash Code of the {@link ComparisonContext#EXACT} context, stacks with the same hash code should share the same normalized stack.
+ * Hash Code of the {@link ComparisonContext#EXACT} context.
* <p>
- * For example, enchantment books of different enchantments will not receive the same hash code under this context.
- * However, difference between the amount of objects in a stack will not affect the hash code.
+ * The exact context type denotes that the equivalent stacks should be <b>functionally</b> the same.
+ * <p>
+ * For example, tools with different damage values and different enchantments should be treated as different within this context.
*
* @param stack the stack to hash code
* @param <T> the type of the stack
@@ -169,10 +174,13 @@ public final class EntryStacks {
}
/**
- * Hash Code of the {@link ComparisonContext#FUZZY} context, stacks with the same hash code may not share the same normalized stack.
- * This hash is less specific, mainly used for fuzzy matching between different stacks.
+ * Hash Code of the {@link ComparisonContext#FUZZY} context.
+ * <p>
+ * The fuzzy context type denotes that the equivalent stacks should be <b>primarily</b> the same.
* <p>
- * For example, enchantment books of different enchantments should still receive the same hash code under this context.
+ * For example, enchantment books of different enchantments should be different within this context,
+ * while tools with different damage values and different enchantments should be treated as the same within this context.
+ * Skulker boxes with different content should be different within this context.
*
* @param stack the stack to hash code
* @param <T> the type of the stack