diff options
Diffstat (limited to 'api/src/main/java')
19 files changed, 231 insertions, 97 deletions
diff --git a/api/src/main/java/me/shedaniel/rei/api/gui/SimpleDisplayRenderer.java b/api/src/main/java/me/shedaniel/rei/api/gui/SimpleDisplayRenderer.java index 50d44339e..404fab43a 100644 --- a/api/src/main/java/me/shedaniel/rei/api/gui/SimpleDisplayRenderer.java +++ b/api/src/main/java/me/shedaniel/rei/api/gui/SimpleDisplayRenderer.java @@ -81,12 +81,12 @@ public class SimpleDisplayRenderer extends DisplayRenderer { public static boolean equalsList(EntryIngredient left, EntryIngredient right) { IntSet leftBytes = new IntOpenHashSet(left.size()); for (EntryStack<?> entryStack : left) { - leftBytes.add(EntryStacks.hashIgnoreCount(entryStack)); + leftBytes.add(EntryStacks.hashExact(entryStack)); } if (leftBytes.size() > right.size()) return false; IntSet rightBytes = new IntOpenHashSet(right.size()); for (EntryStack<?> entryStack : right) { - rightBytes.add(EntryStacks.hashIgnoreCount(entryStack)); + rightBytes.add(EntryStacks.hashExact(entryStack)); if (rightBytes.size() > leftBytes.size()) return false; } @@ -149,5 +149,4 @@ public class SimpleDisplayRenderer extends DisplayRenderer { public int getItemsPerLine() { return Mth.floor((getWidth() - 4f) / 18f); } - } diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/EntryStack.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/EntryStack.java index d39bd4dde..d083b425b 100644 --- a/api/src/main/java/me/shedaniel/rei/api/ingredient/EntryStack.java +++ b/api/src/main/java/me/shedaniel/rei/api/ingredient/EntryStack.java @@ -27,15 +27,16 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.mojang.serialization.Dynamic; import com.mojang.serialization.JsonOps; -import me.shedaniel.architectury.platform.Platform; import me.shedaniel.rei.api.gui.Renderer; -import me.shedaniel.rei.api.ingredient.entry.*; -import me.shedaniel.rei.api.ingredient.util.EntryStacks; +import me.shedaniel.rei.api.ingredient.entry.EntrySerializer; +import me.shedaniel.rei.api.ingredient.entry.comparison.ComparisonContext; +import me.shedaniel.rei.api.ingredient.entry.renderer.EntryRenderer; +import me.shedaniel.rei.api.ingredient.entry.type.EntryDefinition; +import me.shedaniel.rei.api.ingredient.entry.type.EntryType; import me.shedaniel.rei.api.util.TextRepresentable; import me.shedaniel.rei.impl.Internals; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.resources.language.I18n; import net.minecraft.nbt.NbtOps; import net.minecraft.nbt.TagParser; import net.minecraft.network.chat.Component; @@ -109,7 +110,8 @@ public interface EntryStack<T> extends TextRepresentable, Renderer { } default EntryRenderer<T> getRenderer() { - return getDefinition().getRenderer(); + EntryRenderer<?> renderer = get(Settings.RENDER).apply(this); + return renderer == null ? EntryRenderer.empty() : renderer.cast(); } Optional<ResourceLocation> getIdentifier(); @@ -151,16 +153,12 @@ public interface EntryStack<T> extends TextRepresentable, Renderer { public static final Supplier<Boolean> TRUE = () -> true; public static final Supplier<Boolean> FALSE = () -> false; - public static final Settings<Supplier<Boolean>> RENDER = new Settings<>(TRUE); - @Deprecated - public static final Settings<Supplier<Boolean>> CHECK_TAGS = new Settings<>(FALSE); - @Deprecated - public static final Settings<Supplier<Boolean>> CHECK_AMOUNT = new Settings<>(FALSE); + public static final Function<EntryStack<?>, EntryRenderer<?>> DEFAULT_RENDERER = stack -> stack.getDefinition().getRenderer(); + public static final Settings<Function<EntryStack<?>, EntryRenderer<?>>> RENDER = new Settings<>(DEFAULT_RENDERER); @Deprecated public static final Settings<Supplier<Boolean>> TOOLTIP_ENABLED = new Settings<>(TRUE); @Deprecated public static final Settings<Supplier<Boolean>> TOOLTIP_APPEND_MOD = new Settings<>(TRUE); - public static final Settings<Supplier<Boolean>> RENDER_COUNTS = new Settings<>(TRUE); @Deprecated public static final Settings<Function<EntryStack<?>, List<Component>>> TOOLTIP_APPEND_EXTRA = new Settings<>(stack -> Collections.emptyList()); @Deprecated @@ -190,16 +188,6 @@ public interface EntryStack<T> extends TextRepresentable, Renderer { public short getId() { return id; } - - public static class Fluid { - private static final String FLUID_AMOUNT = Platform.isForge() ? "tooltip.rei.fluid_amount.forge" : "tooltip.rei.fluid_amount"; - // Return null to disable - public static final Settings<Function<EntryStack<?>, String>> AMOUNT_TOOLTIP = new Settings<>(stack -> I18n.get(FLUID_AMOUNT, EntryStacks.simplifyAmount(stack.cast()).getValue().getAmount())); - - private Fluid() { - } - } - } @ApiStatus.NonExtendable diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/ComparisonContext.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/comparison/ComparisonContext.java index 4b30e44c1..3a958adb5 100644 --- a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/ComparisonContext.java +++ b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/comparison/ComparisonContext.java @@ -21,39 +21,29 @@ * SOFTWARE. */ -package me.shedaniel.rei.api.ingredient.entry; +package me.shedaniel.rei.api.ingredient.entry.comparison; public enum ComparisonContext { /** - * Should only compare the type of the object + * Should only compare the type of the object, normalized stacks may still not be the same. */ - FUZZY(true, true), + FUZZY(false), /** - * Should compare the nbt and the type of the object + * Should compare the nbt and the type of the object, normalized stacks should be exactly the same. */ - IGNORE_COUNT(true, false), - /** - * Should compare the amount and the type of the object - */ - IGNORE_NBT(true, false), - /** - * Should compare the amount, the nbt and the type of the object - */ - EXACT(false, false); + EXACT(true); - boolean ignoresCount; - boolean ignoresNbt; + boolean exact; - ComparisonContext(boolean ignoresCount, boolean ignoresNbt) { - this.ignoresCount = ignoresCount; - this.ignoresNbt = ignoresNbt; + ComparisonContext(boolean exact) { + this.exact = exact; } - public boolean isIgnoresCount() { - return ignoresCount; + public boolean isExact() { + return exact; } - public boolean isIgnoresNbt() { - return ignoresNbt; + public boolean isFuzzy() { + return !exact; } }
\ No newline at end of file diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/comparison/ItemComparator.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/comparison/ItemComparator.java new file mode 100644 index 000000000..03f9511c4 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/comparison/ItemComparator.java @@ -0,0 +1,67 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.api.ingredient.entry.comparison; + +import me.shedaniel.rei.impl.Internals; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.Tag; +import net.minecraft.world.item.ItemStack; + +import java.util.Objects; +import java.util.function.ToLongFunction; + +/** + * Hasher implementation for {@link ItemStack}. + */ +@FunctionalInterface +public interface ItemComparator { + static ItemComparator noop() { + return stack -> 1; + } + + static ItemComparator itemNbt() { + ToLongFunction<Tag> nbtHasher = nbtHasher("Count"); + return stack -> { + CompoundTag tag = stack.getTag(); + return tag == null ? 0L : nbtHasher.applyAsLong(tag); + }; + } + + static ToLongFunction<Tag> nbtHasher(String... ignoredKeys) { + return Internals.getNbtHasher(ignoredKeys); + } + + long hash(ItemStack stack); + + default ItemComparator then(ItemComparator other) { + Objects.requireNonNull(other); + + return stack -> { + long hash = 1L; + hash = hash * 31 + hash(stack); + hash = hash * 31 + other.hash(stack); + return hash; + }; + } +} diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/comparison/ItemComparatorRegistry.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/comparison/ItemComparatorRegistry.java new file mode 100644 index 000000000..ea97a57ac --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/comparison/ItemComparatorRegistry.java @@ -0,0 +1,62 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.api.ingredient.entry.comparison; + +import me.shedaniel.rei.api.plugins.PluginManager; +import me.shedaniel.rei.api.registry.Reloadable; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; + +/** + * Registry for registering custom methods for identifying variants of {@link net.minecraft.world.item.ItemStack}. + * The default comparator is {@link ItemComparator#noop()}, which does not compare the NBT of the items. + * <p> + * This comparator is used when the comparison context is {@link ComparisonContext#EXACT}. + */ +public interface ItemComparatorRegistry extends Reloadable { + /** + * @return the instance of {@link ItemComparatorRegistry} + */ + static ItemComparatorRegistry getInstance() { + return PluginManager.getInstance().get(ItemComparatorRegistry.class); + } + + void register(ItemComparator comparator, Item item); + + default void register(ItemComparator comparator, Item... items) { + for (Item item : items) { + register(comparator, item); + } + } + + default void registerNbt(Item item) { + register(ItemComparator.itemNbt(), item); + } + + default void registerNbt(Item... items) { + register(ItemComparator.itemNbt(), items); + } + + long hashOf(ItemStack stack); +} diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/AbstractEntryRenderer.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/renderer/AbstractEntryRenderer.java index bbc52436b..c868b44dc 100644 --- a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/AbstractEntryRenderer.java +++ b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/renderer/AbstractEntryRenderer.java @@ -21,7 +21,7 @@ * SOFTWARE. */ -package me.shedaniel.rei.api.ingredient.entry; +package me.shedaniel.rei.api.ingredient.entry.renderer; import net.minecraft.client.gui.GuiComponent; diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/BatchEntryRenderer.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/renderer/BatchEntryRenderer.java index 16660f336..343a2d4ac 100644 --- a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/BatchEntryRenderer.java +++ b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/renderer/BatchEntryRenderer.java @@ -21,7 +21,7 @@ * SOFTWARE. */ -package me.shedaniel.rei.api.ingredient.entry; +package me.shedaniel.rei.api.ingredient.entry.renderer; import com.mojang.blaze3d.vertex.PoseStack; import me.shedaniel.math.Rectangle; diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryRenderer.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/renderer/EntryRenderer.java index 3ff850bb3..0ab20098d 100644 --- a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryRenderer.java +++ b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/renderer/EntryRenderer.java @@ -21,18 +21,29 @@ * SOFTWARE. */ -package me.shedaniel.rei.api.ingredient.entry; +package me.shedaniel.rei.api.ingredient.entry.renderer; import com.mojang.blaze3d.vertex.PoseStack; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.gui.widgets.Tooltip; import me.shedaniel.rei.api.ingredient.EntryStack; +import me.shedaniel.rei.impl.Internals; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; public interface EntryRenderer<T> { + static <T> EntryRenderer<T> empty() { + return Internals.getEmptyEntryRenderer(); + } + void render(EntryStack<T> entry, PoseStack matrices, Rectangle bounds, int mouseX, int mouseY, float delta); @Nullable Tooltip getTooltip(EntryStack<T> entry, Point mouse); + + @ApiStatus.NonExtendable + default <O> EntryRenderer<O> cast() { + return (EntryRenderer<O>) this; + } }
\ No newline at end of file diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/BuiltinEntryTypes.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/type/BuiltinEntryTypes.java index 935418904..72d535846 100644 --- a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/BuiltinEntryTypes.java +++ b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/type/BuiltinEntryTypes.java @@ -21,7 +21,7 @@ * SOFTWARE. */ -package me.shedaniel.rei.api.ingredient.entry; +package me.shedaniel.rei.api.ingredient.entry.type; import me.shedaniel.rei.api.gui.Renderer; import me.shedaniel.rei.impl.Internals; @@ -33,6 +33,7 @@ import org.jetbrains.annotations.ApiStatus; public interface BuiltinEntryTypes { ResourceLocation EMPTY_ID = new ResourceLocation("empty"); ResourceLocation RENDERING_ID = new ResourceLocation("rendering"); + EntryType<Unit> EMPTY = Internals.getEntryStackProvider().emptyType(EMPTY_ID); EntryType<Renderer> RENDERING = Internals.getEntryStackProvider().renderingType(RENDERING_ID); } diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryDefinition.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/type/EntryDefinition.java index faa35334a..a4ba8f2bd 100644 --- a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryDefinition.java +++ b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/type/EntryDefinition.java @@ -21,9 +21,12 @@ * SOFTWARE. */ -package me.shedaniel.rei.api.ingredient.entry; +package me.shedaniel.rei.api.ingredient.entry.type; import me.shedaniel.rei.api.ingredient.EntryStack; +import me.shedaniel.rei.api.ingredient.entry.renderer.EntryRenderer; +import me.shedaniel.rei.api.ingredient.entry.EntrySerializer; +import me.shedaniel.rei.api.ingredient.entry.comparison.ComparisonContext; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.ApiStatus; diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryType.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/type/EntryType.java index cc47fa116..89479588f 100644 --- a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryType.java +++ b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/type/EntryType.java @@ -21,7 +21,7 @@ * SOFTWARE. */ -package me.shedaniel.rei.api.ingredient.entry; +package me.shedaniel.rei.api.ingredient.entry.type; import me.shedaniel.rei.impl.Internals; import net.minecraft.resources.ResourceLocation; diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryTypeBridge.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/type/EntryTypeBridge.java index bd87a90ec..de13eacda 100644 --- a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryTypeBridge.java +++ b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/type/EntryTypeBridge.java @@ -21,7 +21,7 @@ * SOFTWARE. */ -package me.shedaniel.rei.api.ingredient.entry; +package me.shedaniel.rei.api.ingredient.entry.type; import me.shedaniel.rei.api.ingredient.EntryStack; import net.minecraft.world.InteractionResultHolder; diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryTypeRegistry.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/type/EntryTypeRegistry.java index eb11722dc..3d836047a 100644 --- a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/EntryTypeRegistry.java +++ b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/type/EntryTypeRegistry.java @@ -21,7 +21,7 @@ * SOFTWARE. */ -package me.shedaniel.rei.api.ingredient.entry; +package me.shedaniel.rei.api.ingredient.entry.type; import me.shedaniel.rei.api.plugins.PluginManager; import me.shedaniel.rei.api.registry.Reloadable; diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/VanillaEntryTypes.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/type/VanillaEntryTypes.java index 3737a2d7d..2bc2bdb99 100644 --- a/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/VanillaEntryTypes.java +++ b/api/src/main/java/me/shedaniel/rei/api/ingredient/entry/type/VanillaEntryTypes.java @@ -21,7 +21,7 @@ * SOFTWARE. */ -package me.shedaniel.rei.api.ingredient.entry; +package me.shedaniel.rei.api.ingredient.entry.type; import me.shedaniel.architectury.fluid.FluidStack; import net.minecraft.resources.ResourceLocation; diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/util/EntryIngredients.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/util/EntryIngredients.java index bbd401247..a56270571 100644 --- a/api/src/main/java/me/shedaniel/rei/api/ingredient/util/EntryIngredients.java +++ b/api/src/main/java/me/shedaniel/rei/api/ingredient/util/EntryIngredients.java @@ -29,8 +29,8 @@ import me.shedaniel.architectury.utils.Fraction; import me.shedaniel.rei.api.gui.Renderer; import me.shedaniel.rei.api.ingredient.EntryIngredient; import me.shedaniel.rei.api.ingredient.EntryStack; -import me.shedaniel.rei.api.ingredient.entry.EntryDefinition; -import me.shedaniel.rei.api.ingredient.entry.EntryType; +import me.shedaniel.rei.api.ingredient.entry.type.EntryDefinition; +import me.shedaniel.rei.api.ingredient.entry.type.EntryType; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.level.ItemLike; diff --git a/api/src/main/java/me/shedaniel/rei/api/ingredient/util/EntryStacks.java b/api/src/main/java/me/shedaniel/rei/api/ingredient/util/EntryStacks.java index cf6eb454d..b8a281ed2 100644 --- a/api/src/main/java/me/shedaniel/rei/api/ingredient/util/EntryStacks.java +++ b/api/src/main/java/me/shedaniel/rei/api/ingredient/util/EntryStacks.java @@ -28,7 +28,8 @@ import me.shedaniel.architectury.fluid.FluidStack; import me.shedaniel.architectury.utils.Fraction; import me.shedaniel.rei.api.gui.Renderer; import me.shedaniel.rei.api.ingredient.EntryStack; -import me.shedaniel.rei.api.ingredient.entry.*; +import me.shedaniel.rei.api.ingredient.entry.comparison.ComparisonContext; +import me.shedaniel.rei.api.ingredient.entry.type.*; import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.item.ItemStack; @@ -176,30 +177,34 @@ public final class EntryStacks { return equals(left, right, ComparisonContext.FUZZY); } - public static <A, B> boolean equalsIgnoreCount(EntryStack<A> left, EntryStack<B> right) { - return equals(left, right, ComparisonContext.IGNORE_COUNT); - } - - public static <A, B> boolean equalsIgnoreNbt(EntryStack<A> left, EntryStack<B> right) { - return equals(left, right, ComparisonContext.IGNORE_NBT); - } - + /** + * Hash Code of the {@link ComparisonContext#EXACT} context, stacks with the same hash code should share the same normalized stack. + * <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. + * + * @param stack the stack to hash code + * @param <T> the type of the stack + * @return the hash code of the {@link ComparisonContext#EXACT} context + */ public static <T> int hashExact(EntryStack<T> stack) { return stack.hash(ComparisonContext.EXACT); } + /** + * 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. + * <p> + * For example, enchantment books of different enchantments should still receive the same hash code under this context. + * + * @param stack the stack to hash code + * @param <T> the type of the stack + * @return the hash code of the {@link ComparisonContext#FUZZY} context + */ public static <T> int hashFuzzy(EntryStack<T> stack) { return stack.hash(ComparisonContext.FUZZY); } - public static <T> int hashIgnoreCount(EntryStack<T> stack) { - return stack.hash(ComparisonContext.IGNORE_COUNT); - } - - public static <T> int hashIgnoreNbt(EntryStack<T> stack) { - return stack.hash(ComparisonContext.IGNORE_NBT); - } - public static EntryStack<FluidStack> simplifyAmount(EntryStack<FluidStack> stack) { stack.getValue().setAmount(stack.getValue().getAmount().simplify()); return stack; diff --git a/api/src/main/java/me/shedaniel/rei/api/plugins/REIPlugin.java b/api/src/main/java/me/shedaniel/rei/api/plugins/REIPlugin.java index de9c47d95..a7a25b7c9 100644 --- a/api/src/main/java/me/shedaniel/rei/api/plugins/REIPlugin.java +++ b/api/src/main/java/me/shedaniel/rei/api/plugins/REIPlugin.java @@ -25,7 +25,8 @@ package me.shedaniel.rei.api.plugins; import me.shedaniel.rei.api.favorites.FavoriteEntryType; import me.shedaniel.rei.api.fluid.FluidSupportProvider; -import me.shedaniel.rei.api.ingredient.entry.EntryTypeRegistry; +import me.shedaniel.rei.api.ingredient.entry.comparison.ItemComparatorRegistry; +import me.shedaniel.rei.api.ingredient.entry.type.EntryTypeRegistry; import me.shedaniel.rei.api.registry.category.CategoryRegistry; import me.shedaniel.rei.api.registry.display.DisplayRegistry; import me.shedaniel.rei.api.registry.entry.EntryRegistry; @@ -64,6 +65,15 @@ public interface REIPlugin extends Comparable<REIPlugin> { } /** + * Registers item comparators for identifying variants of {@link net.minecraft.world.item.ItemStack}. + * + * @see ItemComparatorRegistry + */ + @ApiStatus.OverrideOnly + default void registerItemComparators(ItemComparatorRegistry registry) { + } + + /** * Registers new item to fluid support providers. * * @param support the support registry diff --git a/api/src/main/java/me/shedaniel/rei/api/util/CollectionUtils.java b/api/src/main/java/me/shedaniel/rei/api/util/CollectionUtils.java index a72891363..ea31ef72c 100644 --- a/api/src/main/java/me/shedaniel/rei/api/util/CollectionUtils.java +++ b/api/src/main/java/me/shedaniel/rei/api/util/CollectionUtils.java @@ -87,17 +87,7 @@ public class CollectionUtils { } @Environment(EnvType.CLIENT) - public static boolean anyMatchEqualsAll(Iterable<? extends EntryStack<?>> list, EntryStack<?> stack) { - return firstOrNullEqualsAll(list, stack) != null; - } - - @Environment(EnvType.CLIENT) - public static boolean anyMatchEqualsEntryIgnoreAmount(Iterable<? extends EntryStack<?>> list, EntryStack<?> stack) { - return findFirstOrNullEqualsEntryIgnoreAmount(list, stack) != null; - } - - @Environment(EnvType.CLIENT) - public static EntryStack<?> firstOrNullEqualsAll(Iterable<? extends EntryStack<?>> list, EntryStack<?> stack) { + public static EntryStack<?> findFirstOrNullEqualsExact(Iterable<? extends EntryStack<?>> list, EntryStack<?> stack) { for (EntryStack<?> t : list) { if (EntryStacks.equalsExact(t, stack)) return t; @@ -105,15 +95,6 @@ public class CollectionUtils { return null; } - @Environment(EnvType.CLIENT) - public static EntryStack<?> findFirstOrNullEqualsEntryIgnoreAmount(Iterable<? extends EntryStack<?>> list, EntryStack<?> stack) { - for (EntryStack<?> t : list) { - if (EntryStacks.equalsIgnoreCount(t, stack)) - return t; - } - return null; - } - public static <T> List<T> filterToList(Iterable<T> list, Predicate<T> predicate) { List<T> l = Lists.newArrayList(); for (T t : list) { diff --git a/api/src/main/java/me/shedaniel/rei/impl/Internals.java b/api/src/main/java/me/shedaniel/rei/impl/Internals.java index 9762f4b28..2f2b6325d 100644 --- a/api/src/main/java/me/shedaniel/rei/impl/Internals.java +++ b/api/src/main/java/me/shedaniel/rei/impl/Internals.java @@ -33,8 +33,9 @@ import me.shedaniel.rei.api.gui.Renderer; import me.shedaniel.rei.api.gui.widgets.*; import me.shedaniel.rei.api.ingredient.EntryIngredient; import me.shedaniel.rei.api.ingredient.EntryStack; -import me.shedaniel.rei.api.ingredient.entry.EntryDefinition; -import me.shedaniel.rei.api.ingredient.entry.EntryType; +import me.shedaniel.rei.api.ingredient.entry.renderer.EntryRenderer; +import me.shedaniel.rei.api.ingredient.entry.type.EntryDefinition; +import me.shedaniel.rei.api.ingredient.entry.type.EntryType; import me.shedaniel.rei.api.plugins.BuiltinPlugin; import me.shedaniel.rei.api.plugins.PluginManager; import me.shedaniel.rei.api.registry.screen.ClickArea; @@ -42,6 +43,7 @@ import me.shedaniel.rei.api.view.ViewSearchBuilder; import me.shedaniel.rei.api.view.Views; import net.fabricmc.api.EnvType; import net.fabricmc.api.Envi |
