From d21a84ac2e07fe30685f1d703481425b0f01c93d Mon Sep 17 00:00:00 2001 From: shedaniel Date: Fri, 19 Mar 2021 19:16:12 +0800 Subject: Implement ItemComparatorRegistry as a replacement for previous check tags and check amount flags Signed-off-by: shedaniel --- .../me/shedaniel/rei/RoughlyEnoughItemsCore.java | 75 +++++++++------- .../rei/api/gui/config/entry/FilteringEntry.java | 2 +- .../rei/api/gui/config/entry/FilteringScreen.java | 2 +- .../rei/gui/AbstractRecipeViewingScreen.java | 2 +- .../shedaniel/rei/gui/ContainerScreenOverlay.java | 21 +++-- .../java/me/shedaniel/rei/gui/modules/Menu.java | 5 +- .../entries/EntryStackSubsetsMenuEntry.java | 11 +-- .../gui/modules/entries/SubSubsetsMenuEntry.java | 2 +- .../rei/gui/plugin/DefaultRuntimePlugin.java | 14 +-- .../rei/gui/plugin/entry/FluidEntryDefinition.java | 63 +++++++------ .../rei/gui/plugin/entry/ItemEntryDefinition.java | 83 +++-------------- .../rei/gui/widget/EntryListEntryWidget.java | 3 +- .../shedaniel/rei/gui/widget/EntryListWidget.java | 17 ++-- .../rei/gui/widget/FavoritesListWidget.java | 2 +- .../me/shedaniel/rei/impl/AbstractEntryStack.java | 4 +- .../rei/impl/AmountIgnoredEntryStackWrapper.java | 62 ------------- .../me/shedaniel/rei/impl/ClientHelperImpl.java | 6 +- .../me/shedaniel/rei/impl/ConfigManagerImpl.java | 7 +- .../me/shedaniel/rei/impl/EntryRegistryImpl.java | 36 ++++---- .../me/shedaniel/rei/impl/EntryTypeDeferred.java | 6 +- .../shedaniel/rei/impl/EntryTypeRegistryImpl.java | 8 +- .../rei/impl/HashedEntryStackWrapper.java | 62 +++++++++++++ .../me/shedaniel/rei/impl/PluginManagerImpl.java | 2 + .../me/shedaniel/rei/impl/TypedEntryStack.java | 9 +- .../rei/impl/entry/EmptyEntryDefinition.java | 13 +-- .../rei/impl/entry/ItemComparatorRegistryImpl.java | 70 +++++++++++++++ .../rei/impl/filtering/FilteringContextImpl.java | 14 +-- .../rei/impl/filtering/FilteringResult.java | 22 ++--- .../rei/impl/filtering/FilteringResultImpl.java | 8 +- .../impl/filtering/rules/ManualFilteringRule.java | 5 +- .../rei/impl/nbt/NbtHasherProviderImpl.java | 100 +++++++++++++++++++++ .../me/shedaniel/rei/impl/search/TagArgument.java | 2 +- .../rei/impl/subsets/SubsetsRegistryImpl.java | 6 +- .../java/me/shedaniel/rei/impl/view/ViewsImpl.java | 6 +- .../autocrafting/DefaultCategoryHandler.java | 2 +- 35 files changed, 446 insertions(+), 306 deletions(-) delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/AmountIgnoredEntryStackWrapper.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/HashedEntryStackWrapper.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/entry/ItemComparatorRegistryImpl.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/nbt/NbtHasherProviderImpl.java (limited to 'runtime/src/main/java/me') diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java index 7c2d9df99..29fa87e01 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java @@ -32,8 +32,8 @@ import me.shedaniel.architectury.event.events.client.ClientScreenInputEvent; import me.shedaniel.architectury.networking.NetworkManager; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; -import me.shedaniel.rei.api.config.ConfigObject; import me.shedaniel.rei.api.REIHelper; +import me.shedaniel.rei.api.config.ConfigObject; import me.shedaniel.rei.api.favorites.FavoriteEntry; import me.shedaniel.rei.api.favorites.FavoriteEntryType; import me.shedaniel.rei.api.favorites.FavoriteMenuEntry; @@ -41,9 +41,10 @@ import me.shedaniel.rei.api.gui.DrawableConsumer; import me.shedaniel.rei.api.gui.Renderer; import me.shedaniel.rei.api.gui.widgets.*; import me.shedaniel.rei.api.ingredient.EntryStack; -import me.shedaniel.rei.api.ingredient.entry.BuiltinEntryTypes; -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.BuiltinEntryTypes; +import me.shedaniel.rei.api.ingredient.entry.type.EntryDefinition; +import me.shedaniel.rei.api.ingredient.entry.type.EntryType; import me.shedaniel.rei.api.ingredient.util.EntryStacks; import me.shedaniel.rei.api.plugins.PluginManager; import me.shedaniel.rei.api.registry.screen.ClickArea; @@ -56,6 +57,7 @@ import me.shedaniel.rei.gui.widget.QueuedTooltip; import me.shedaniel.rei.impl.*; import me.shedaniel.rei.impl.entry.EmptyEntryDefinition; import me.shedaniel.rei.impl.entry.EntryIngredientImpl; +import me.shedaniel.rei.impl.nbt.NbtHasherProviderImpl; import me.shedaniel.rei.impl.view.ViewsImpl; import me.shedaniel.rei.impl.widgets.*; import me.shedaniel.rei.tests.plugin.REITestPlugin; @@ -123,6 +125,9 @@ public class RoughlyEnoughItemsCore { }, "entryTypeDeferred"); attachInstance(new PluginManagerImpl(), PluginManager.class); attachInstance(new Internals.EntryStackProvider() { + private EntryType empty; + private EntryType render; + @Override public EntryStack empty() { return TypedEntryStack.EMPTY; @@ -130,39 +135,49 @@ public class RoughlyEnoughItemsCore { @Override public EntryStack of(EntryDefinition definition, T value) { + if (Objects.equals(definition.getType().getId(), BuiltinEntryTypes.EMPTY_ID)) { + return empty().cast(); + } + return new TypedEntryStack<>(definition, value); } @Override public EntryType emptyType(ResourceLocation id) { - return new EntryType() { - @Override - public @NotNull ResourceLocation getId() { - return id; - } - - @SuppressWarnings("rawtypes") - @Override - public @NotNull EntryDefinition getDefinition() { - return (EntryDefinition) EmptyEntryDefinition.EMPTY; - } - }; + if (empty == null) { + empty = new EntryType() { + @Override + public @NotNull ResourceLocation getId() { + return id; + } + + @SuppressWarnings("rawtypes") + @Override + public @NotNull EntryDefinition getDefinition() { + return (EntryDefinition) EmptyEntryDefinition.EMPTY; + } + }; + } + return empty; } @Override public EntryType renderingType(ResourceLocation id) { - return new EntryType() { - @Override - public @NotNull ResourceLocation getId() { - return id; - } - - @SuppressWarnings("rawtypes") - @Override - public @NotNull EntryDefinition getDefinition() { - return (EntryDefinition) EmptyEntryDefinition.RENDERING; - } - }; + if (render == null) { + render = new EntryType() { + @Override + public @NotNull ResourceLocation getId() { + return id; + } + + @SuppressWarnings("rawtypes") + @Override + public @NotNull EntryDefinition getDefinition() { + return (EntryDefinition) EmptyEntryDefinition.RENDERING; + } + }; + } + return render; } }, Internals.EntryStackProvider.class); attachInstance(new Internals.WidgetsProvider() { @@ -217,7 +232,9 @@ public class RoughlyEnoughItemsCore { } }, Internals.WidgetsProvider.class); attachInstance(new ViewsImpl(), Views.class); + attachInstance(new NbtHasherProviderImpl(), Internals.NbtHasherProvider.class); attachInstance(EntryIngredientImpl.provide(), Internals.EntryIngredientProvider.class); + attachInstance((Supplier>) () -> EmptyEntryDefinition.EmptyRenderer.INSTANCE, "emptyEntryRenderer"); attachInstance((BiFunction, Supplier, FavoriteEntry>) (supplier, toJson) -> new FavoriteEntry() { FavoriteEntry value = null; @@ -512,8 +529,6 @@ public class RoughlyEnoughItemsCore { if (shouldReturn(screen)) return; REIHelper.getInstance().getOverlay().get().render(matrices, mouseX, mouseY, delta); - if (!REIHelper.getInstance().isOverlayVisible()) - return; ((ContainerScreenOverlay) REIHelper.getInstance().getOverlay().get()).lateRender(matrices, mouseX, mouseY, delta); }); ClientScreenInputEvent.MOUSE_DRAGGED_PRE.register((minecraftClient, screen, mouseX1, mouseY1, button, mouseX2, mouseY2) -> { diff --git a/runtime/src/main/java/me/shedaniel/rei/api/gui/config/entry/FilteringEntry.java b/runtime/src/main/java/me/shedaniel/rei/api/gui/config/entry/FilteringEntry.java index 79c71af8b..ac1e703a2 100644 --- a/runtime/src/main/java/me/shedaniel/rei/api/gui/config/entry/FilteringEntry.java +++ b/runtime/src/main/java/me/shedaniel/rei/api/gui/config/entry/FilteringEntry.java @@ -62,7 +62,7 @@ public class FilteringEntry extends AbstractConfigListEntry> { public FilteringEntry(int width, List configFiltered, List> rules, List defaultValue, Consumer> saveConsumer, Consumer>> rulesSaveConsumer) { super(NarratorChatListener.NO_TITLE, false); this.width = width; - this.configFiltered = new TreeSet<>(Comparator.comparing(EntryStacks::hashIgnoreCount)); + this.configFiltered = new TreeSet<>(Comparator.comparing(EntryStacks::hashExact)); this.configFiltered.addAll(configFiltered); this.rules = Lists.newArrayList(rules); this.defaultValue = defaultValue; diff --git a/runtime/src/main/java/me/shedaniel/rei/api/gui/config/entry/FilteringScreen.java b/runtime/src/main/java/me/shedaniel/rei/api/gui/config/entry/FilteringScreen.java index d061101a3..ac7a5e0d6 100644 --- a/runtime/src/main/java/me/shedaniel/rei/api/gui/config/entry/FilteringScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/api/gui/config/entry/FilteringScreen.java @@ -315,7 +315,7 @@ public class FilteringScreen extends Screen { Set> list = Sets.newLinkedHashSet(); EntryRegistry.getInstance().getEntryStacks().forEach(stack -> { if (canLastSearchTermsBeAppliedTo(stack)) { - list.add(stack.copy().setting(EntryStack.Settings.CHECK_AMOUNT, EntryStack.Settings.FALSE).setting(EntryStack.Settings.RENDER_COUNTS, EntryStack.Settings.FALSE).setting(EntryStack.Settings.CHECK_TAGS, EntryStack.Settings.TRUE)); + list.add(stack.normalize()); } }); diff --git a/runtime/src/main/java/me/shedaniel/rei/gui/AbstractRecipeViewingScreen.java b/runtime/src/main/java/me/shedaniel/rei/gui/AbstractRecipeViewingScreen.java index 0384a5b49..c7fdcfc54 100644 --- a/runtime/src/main/java/me/shedaniel/rei/gui/AbstractRecipeViewingScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/gui/AbstractRecipeViewingScreen.java @@ -127,7 +127,7 @@ public abstract class AbstractRecipeViewingScreen extends Screen implements Reci if (widget instanceof EntryWidget) { EntryWidget entry = (EntryWidget) widget; if (entry.getNoticeMark() == marker && entry.getEntries().size() > 1) { - EntryStack stack = CollectionUtils.findFirstOrNullEqualsEntryIgnoreAmount(entry.getEntries(), noticeStack); + EntryStack stack = CollectionUtils.findFirstOrNullEqualsExact(entry.getEntries(), noticeStack); if (stack != null) { entry.clearStacks(); entry.entry(stack); diff --git a/runtime/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java b/runtime/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java index 5025bf2f1..67dd29cb3 100644 --- a/runtime/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java +++ b/runtime/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java @@ -597,24 +597,27 @@ public class ContainerScreenOverlay extends REIOverlay { if (widget instanceof LateRenderable && (overlayMenu == null || overlayMenu.wrappedMenu != widget)) widget.render(matrices, mouseX, mouseY, delta); } - } - if (overlayMenu != null) { - if (overlayMenu.wrappedMenu.containsMouse(mouseX, mouseY)) { - TOOLTIPS.clear(); + if (overlayMenu != null) { + if (overlayMenu.wrappedMenu.containsMouse(mouseX, mouseY)) { + TOOLTIPS.clear(); + } + overlayMenu.wrappedMenu.render(matrices, mouseX, mouseY, delta); } - overlayMenu.wrappedMenu.render(matrices, mouseX, mouseY, delta); } Screen currentScreen = Minecraft.getInstance().screen; - if (!(currentScreen instanceof RecipeViewingScreen) || !((RecipeViewingScreen) currentScreen).choosePageActivated) + if (!(currentScreen instanceof RecipeViewingScreen) || !((RecipeViewingScreen) currentScreen).choosePageActivated) { for (Tooltip tooltip : TOOLTIPS) { if (tooltip != null) renderTooltip(matrices, tooltip); } - for (Runnable runnable : AFTER_RENDER) { - runnable.run(); } TOOLTIPS.clear(); - AFTER_RENDER.clear(); + if (REIHelper.getInstance().isOverlayVisible()) { + for (Runnable runnable : AFTER_RENDER) { + runnable.run(); + } + AFTER_RENDER.clear(); + } } public void renderTooltip(PoseStack matrices, Tooltip tooltip) { diff --git a/runtime/src/main/java/me/shedaniel/rei/gui/modules/Menu.java b/runtime/src/main/java/me/shedaniel/rei/gui/modules/Menu.java index d4deaf016..b0b47f44b 100644 --- a/runtime/src/main/java/me/shedaniel/rei/gui/modules/Menu.java +++ b/runtime/src/main/java/me/shedaniel/rei/gui/modules/Menu.java @@ -127,9 +127,10 @@ public class Menu extends WidgetWithBounds implements LateRenderable { lastMap = getOrCreateSubEntryInMap(lastMap, pathSegment); } for (EntryStack entry : SubsetsRegistry.getInstance().getPathEntries(path)) { - EntryStack firstStack = CollectionUtils.findFirstOrNullEqualsEntryIgnoreAmount(stacks, entry); - if (firstStack != null) + EntryStack firstStack = CollectionUtils.findFirstOrNullEqualsExact(stacks, entry); + if (firstStack != null) { putEntryInMap(lastMap, firstStack); + } } } return new Menu(menuStartPoint, buildEntries(entries)); diff --git a/runtime/src/main/java/me/shedaniel/rei/gui/modules/entries/EntryStackSubsetsMenuEntry.java b/runtime/src/main/java/me/shedaniel/rei/gui/modules/entries/EntryStackSubsetsMenuEntry.java index 43fe57510..21063adfa 100644 --- a/runtime/src/main/java/me/shedaniel/rei/gui/modules/entries/EntryStackSubsetsMenuEntry.java +++ b/runtime/src/main/java/me/shedaniel/rei/gui/modules/entries/EntryStackSubsetsMenuEntry.java @@ -27,9 +27,9 @@ import com.mojang.blaze3d.vertex.PoseStack; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.RoughlyEnoughItemsCore; +import me.shedaniel.rei.api.REIHelper; import me.shedaniel.rei.api.config.ConfigManager; import me.shedaniel.rei.api.config.ConfigObject; -import me.shedaniel.rei.api.REIHelper; import me.shedaniel.rei.api.ingredient.EntryStack; import me.shedaniel.rei.api.ingredient.util.EntryStacks; import me.shedaniel.rei.api.registry.entry.EntryRegistry; @@ -98,7 +98,7 @@ public class EntryStackSubsetsMenuEntry extends MenuEntry { minecraft.getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F)); List> filteredStacks = ConfigObject.getInstance().getFilteredStacks(); if (isFiltered()) { - filteredStacks.removeIf(next -> EntryStacks.equalsIgnoreCount(next, stack)); + filteredStacks.removeIf(next -> EntryStacks.equalsExact(next, stack)); } else { filteredStacks.add(stack.normalize()); } @@ -117,10 +117,11 @@ public class EntryStackSubsetsMenuEntry extends MenuEntry { void recalculateFilter(Menu menu) { for (MenuEntry child : menu.children()) { - if (child instanceof SubSubsetsMenuEntry && ((SubSubsetsMenuEntry) child).getSubsetsMenu() != null) + if (child instanceof SubSubsetsMenuEntry && ((SubSubsetsMenuEntry) child).getSubsetsMenu() != null) { recalculateFilter(((SubSubsetsMenuEntry) child).getSubsetsMenu()); - else if (child instanceof EntryStackSubsetsMenuEntry && EntryStacks.equalsIgnoreCount(((EntryStackSubsetsMenuEntry) child).stack, stack)) + } else if (child instanceof EntryStackSubsetsMenuEntry && EntryStacks.equalsExact(((EntryStackSubsetsMenuEntry) child).stack, stack)) { ((EntryStackSubsetsMenuEntry) child).isFiltered = null; + } } } @@ -137,7 +138,7 @@ public class EntryStackSubsetsMenuEntry extends MenuEntry { public boolean isFiltered() { if (isFiltered == null) { List> filteredStacks = ConfigObject.getInstance().getFilteredStacks(); - isFiltered = CollectionUtils.findFirstOrNullEqualsEntryIgnoreAmount(filteredStacks, stack) != null; + isFiltered = CollectionUtils.findFirstOrNullEqualsExact(filteredStacks, stack) != null; } return isFiltered; } diff --git a/runtime/src/main/java/me/shedaniel/rei/gui/modules/entries/SubSubsetsMenuEntry.java b/runtime/src/main/java/me/shedaniel/rei/gui/modules/entries/SubSubsetsMenuEntry.java index 7efe4f886..4b41d0517 100644 --- a/runtime/src/main/java/me/shedaniel/rei/gui/modules/entries/SubSubsetsMenuEntry.java +++ b/runtime/src/main/java/me/shedaniel/rei/gui/modules/entries/SubSubsetsMenuEntry.java @@ -173,7 +173,7 @@ public class SubSubsetsMenuEntry extends MenuEntry { if (entry instanceof EntryStackSubsetsMenuEntry) { if (((EntryStackSubsetsMenuEntry) entry).isFiltered() != filtered) { if (!filtered) { - filteredStacks.removeIf(next -> EntryStacks.equalsIgnoreCount(next, ((EntryStackSubsetsMenuEntry) entry).stack)); + filteredStacks.removeIf(next -> EntryStacks.equalsExact(next, ((EntryStackSubsetsMenuEntry) entry).stack)); } else { filteredStacks.add(((EntryStackSubsetsMenuEntry) entry).stack.normalize()); } diff --git a/runtime/src/main/java/me/shedaniel/rei/gui/plugin/DefaultRuntimePlugin.java b/runtime/src/main/java/me/shedaniel/rei/gui/plugin/DefaultRuntimePlugin.java index f12b169fd..cd2062d7b 100644 --- a/runtime/src/main/java/me/shedaniel/rei/gui/plugin/DefaultRuntimePlugin.java +++ b/runtime/src/main/java/me/shedaniel/rei/gui/plugin/DefaultRuntimePlugin.java @@ -26,7 +26,6 @@ package me.shedaniel.rei.gui.plugin; import com.google.gson.JsonObject; import com.mojang.blaze3d.vertex.PoseStack; import me.shedaniel.architectury.fluid.FluidStack; -import me.shedaniel.architectury.utils.Fraction; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.ClientHelper; @@ -38,9 +37,8 @@ import me.shedaniel.rei.api.gui.Renderer; import me.shedaniel.rei.api.gui.widgets.Panel; import me.shedaniel.rei.api.gui.widgets.Tooltip; import me.shedaniel.rei.api.ingredient.EntryStack; -import me.shedaniel.rei.api.ingredient.entry.ComparisonContext; -import me.shedaniel.rei.api.ingredient.entry.EntryTypeRegistry; -import me.shedaniel.rei.api.ingredient.entry.VanillaEntryTypes; +import me.shedaniel.rei.api.ingredient.entry.type.EntryTypeRegistry; +import me.shedaniel.rei.api.ingredient.entry.type.VanillaEntryTypes; import me.shedaniel.rei.api.ingredient.util.EntryStacks; import me.shedaniel.rei.api.plugins.REIPlugin; import me.shedaniel.rei.api.registry.entry.EntryRegistry; @@ -194,11 +192,7 @@ public class DefaultRuntimePlugin implements REIPlugin { public EntryStackFavoriteEntry(EntryStack stack) { this.stack = stack.normalize(); - if (this.stack.getType() == VanillaEntryTypes.ITEM) - this.stack.setting(EntryStack.Settings.RENDER_COUNTS, EntryStack.Settings.FALSE); - else if (this.stack.getType() == VanillaEntryTypes.FLUID) - this.stack.setting(EntryStack.Settings.Fluid.AMOUNT_TOOLTIP, CANCEL_FLUID_AMOUNT); - this.hashIgnoreAmount = EntryStacks.hashIgnoreCount(this.stack); + this.hashIgnoreAmount = EntryStacks.hashExact(this.stack); } @Override @@ -249,7 +243,7 @@ public class DefaultRuntimePlugin implements REIPlugin { public boolean isSame(FavoriteEntry other) { if (!(other instanceof EntryStackFavoriteEntry)) return false; EntryStackFavoriteEntry that = (EntryStackFavoriteEntry) other; - return EntryStacks.equalsIgnoreCount(stack, that.stack); + return EntryStacks.equalsExact(stack, that.stack); } } } diff --git a/runtime/src/main/java/me/shedaniel/rei/gui/plugin/entry/FluidEntryDefinition.java b/runtime/src/main/java/me/shedaniel/rei/gui/plugin/entry/FluidEntryDefinition.java index 2123001c6..dc3fc0109 100644 --- a/runtime/src/main/java/me/shedaniel/rei/gui/plugin/entry/FluidEntryDefinition.java +++ b/runtime/src/main/java/me/shedaniel/rei/gui/plugin/entry/FluidEntryDefinition.java @@ -30,6 +30,7 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.Tesselator; import com.mojang.math.Matrix4f; import me.shedaniel.architectury.fluid.FluidStack; +import me.shedaniel.architectury.platform.Platform; import me.shedaniel.architectury.utils.Fraction; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; @@ -37,12 +38,20 @@ import me.shedaniel.rei.api.ClientHelper; import me.shedaniel.rei.api.config.ConfigObject; import me.shedaniel.rei.api.gui.widgets.Tooltip; import me.shedaniel.rei.api.ingredient.EntryStack; -import me.shedaniel.rei.api.ingredient.entry.*; +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.AbstractEntryRenderer; +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.ingredient.entry.type.VanillaEntryTypes; +import me.shedaniel.rei.api.ingredient.util.EntryStacks; import me.shedaniel.rei.impl.SimpleFluidRenderer; import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.texture.TextureAtlas; import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.resources.language.I18n; import net.minecraft.core.Registry; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; @@ -58,6 +67,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; public class FluidEntryDefinition implements EntryDefinition, EntrySerializer { + private static final String FLUID_AMOUNT = Platform.isForge() ? "tooltip.rei.fluid_amount.forge" : "tooltip.rei.fluid_amount"; private final EntryRenderer renderer = new FluidEntryRenderer(); @Override @@ -101,8 +111,7 @@ public class FluidEntryDefinition implements EntryDefinition, EntryS public int hash(EntryStack entry, FluidStack value, ComparisonContext context) { int code = 1; code = 31 * code + value.getFluid().hashCode(); - code = 31 * code + (context.isIgnoresCount() ? 0 : value.getAmount().hashCode()); - code = 31 * code + (context.isIgnoresNbt() || !value.hasTag() ? 0 : value.getTag().hashCode()); + code = 31 * code + (context.isFuzzy() || !value.hasTag() ? 0 : value.getTag().hashCode()); return code; } @@ -110,9 +119,7 @@ public class FluidEntryDefinition implements EntryDefinition, EntryS public boolean equals(FluidStack o1, FluidStack o2, ComparisonContext context) { if (o1.getFluid() != o2.getFluid()) return false; - if (!context.isIgnoresCount() && !o1.getAmount().equals(o2.getAmount())) - return false; - return context.isIgnoresNbt() || isTagEqual(o1, o2); + return context.isFuzzy() || isTagEqual(o1, o2); } private boolean isTagEqual(FluidStack o1, FluidStack o2) { @@ -161,28 +168,26 @@ public class FluidEntryDefinition implements EntryDefinition, EntryS public static class FluidEntryRenderer extends AbstractEntryRenderer { @Override public void render(EntryStack entry, PoseStack matrices, Rectangle bounds, int mouseX, int mouseY, float delta) { - if (entry.get(EntryStack.Settings.RENDER).get()) { - FluidStack stack = entry.getValue(); - SimpleFluidRenderer.FluidRenderingData renderingData = SimpleFluidRenderer.fromFluid(stack.getFluid()); - if (renderingData != null) { - TextureAtlasSprite sprite = renderingData.getSprite(); - int color = renderingData.getColor(); - int a = 255; - int r = (color >> 16 & 255); - int g = (color >> 8 & 255); - int b = (color & 255); - Minecraft.getInstance().getTextureManager().bind(TextureAtlas.LOCATION_BLOCKS); - Tesselator tess = Tesselator.getInstance(); - BufferBuilder bb = tess.getBuilder(); - Matrix4f matrix = matrices.last().pose(); - bb.begin(7, DefaultVertexFormat.POSITION_TEX_COLOR); - int z = entry.getZ(); - bb.vertex(matrix, bounds.getMaxX(), bounds.y, z).uv(sprite.getU1(), sprite.getV0()).color(r, g, b, a).endVertex(); - bb.vertex(matrix, bounds.x, bounds.y, z).uv(sprite.getU0(), sprite.getV0()).color(r, g, b, a).endVertex(); - bb.vertex(matrix, bounds.x, bounds.getMaxY(), z).uv(sprite.getU0(), sprite.getV1()).color(r, g, b, a).endVertex(); - bb.vertex(matrix, bounds.getMaxX(), bounds.getMaxY(), z).uv(sprite.getU1(), sprite.getV1()).color(r, g, b, a).endVertex(); - tess.end(); - } + FluidStack stack = entry.getValue(); + SimpleFluidRenderer.FluidRenderingData renderingData = SimpleFluidRenderer.fromFluid(stack.getFluid()); + if (renderingData != null) { + TextureAtlasSprite sprite = renderingData.getSprite(); + int color = renderingData.getColor(); + int a = 255; + int r = (color >> 16 & 255); + int g = (color >> 8 & 255); + int b = (color & 255); + Minecraft.getInstance().getTextureManager().bind(TextureAtlas.LOCATION_BLOCKS); + Tesselator tess = Tesselator.getInstance(); + BufferBuilder bb = tess.getBuilder(); + Matrix4f matrix = matrices.last().pose(); + bb.begin(7, DefaultVertexFormat.POSITION_TEX_COLOR); + int z = entry.getZ(); + bb.vertex(matrix, bounds.getMaxX(), bounds.y, z).uv(sprite.getU1(), sprite.getV0()).color(r, g, b, a).endVertex(); + bb.vertex(matrix, bounds.x, bounds.y, z).uv(sprite.getU0(), sprite.getV0()).color(r, g, b, a).endVertex(); + bb.vertex(matrix, bounds.x, bounds.getMaxY(), z).uv(sprite.getU0(), sprite.getV1()).color(r, g, b, a).endVertex(); + bb.vertex(matrix, bounds.getMaxX(), bounds.getMaxY(), z).uv(sprite.getU1(), sprite.getV1()).color(r, g, b, a).endVertex(); + tess.end(); } } @@ -193,7 +198,7 @@ public class FluidEntryDefinition implements EntryDefinition, EntryS List toolTip = Lists.newArrayList(entry.asFormattedText()); Fraction amount = entry.getValue().getAmount(); if (!amount.isLessThan(Fraction.zero())) { - String amountTooltip = entry.get(EntryStack.Settings.Fluid.AMOUNT_TOOLTIP).apply(entry); + String amountTooltip = I18n.get(FLUID_AMOUNT, EntryStacks.simplifyAmount(entry).getValue().getAmount()); if (amountTooltip != null) toolTip.addAll(Stream.of(amountTooltip.split("\n")).map(TextComponent::new).collect(Collectors.toList())); } diff --git a/runtime/src/main/java/me/shedaniel/rei/gui/plugin/entry/ItemEntryDefinition.java b/runtime/src/main/java/me/shedaniel/rei/gui/plugin/entry/ItemEntryDefinition.java index 4bd13e725..6a639bc31 100644 --- a/runtime/src/main/java/me/shedaniel/rei/gui/plugin/entry/ItemEntryDefinition.java +++ b/runtime/src/main/java/me/shedaniel/rei/gui/plugin/entry/ItemEntryDefinition.java @@ -37,6 +37,14 @@ import me.shedaniel.rei.api.config.ConfigObject; import me.shedaniel.rei.api.gui.widgets.Tooltip; 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.comparison.ItemComparatorRegistry; +import me.shedaniel.rei.api.ingredient.entry.renderer.AbstractEntryRenderer; +import me.shedaniel.rei.api.ingredient.entry.renderer.BatchEntryRenderer; +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.ingredient.entry.type.VanillaEntryTypes; import me.shedaniel.rei.api.util.ImmutableLiteralText; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.MultiBufferSource; @@ -99,7 +107,7 @@ public class ItemEntryDefinition implements EntryDefinition, EntrySer @Override public ItemStack normalize(EntryStack entry, ItemStack value) { ItemStack copy = value.copy(); - copy.setCount(127); + copy.setCount(1); return copy; } @@ -107,8 +115,7 @@ public class ItemEntryDefinition implements EntryDefinition, EntrySer public int hash(EntryStack entry, ItemStack value, ComparisonContext context) { int code = 1; code = 31 * code + System.identityHashCode(value.getItem()); - code = 31 * code + (context.isIgnoresCount() ? 0 : value.getCount()); - code = 31 * code + (context.isIgnoresNbt() || !value.hasTag() ? 0 : value.getTag().hashCode()); + code = 31 * code + (context.isFuzzy() ? 0 : Long.hashCode(ItemComparatorRegistry.getInstance().hashOf(value))); return code; } @@ -116,69 +123,7 @@ public class ItemEntryDefinition implements EntryDefinition, EntrySer public boolean equals(ItemStack o1, ItemStack o2, ComparisonContext context) { if (o1.getItem() != o2.getItem()) return false; - if (!context.isIgnoresCount() && o1.getCount() != o2.getCount()) - return false; - if (!context.isIgnoresNbt()) { - CompoundTag tag1 = o1.getTag(); - CompoundTag tag2 = o2.getTag(); - return tag1 == tag2 || ((tag1 != null && tag2 != null) && equalsTagWithoutCount(tag1, tag2)); - } - return true; - } - - private boolean equalsTagWithoutCount(CompoundTag o1, CompoundTag o2) { - int o1Size = 0; - int o2Size = 0; - for (String key : o1.getAllKeys()) { - if (key.equals("Count")) - continue; - o1Size++; - } - for (String key : o2.getAllKeys()) { - if (key.equals("Count")) - continue; - o2Size++; - if (o2Size > o1Size) - return false; - } - if (o1Size != o2Size) - return false; - - try { - for (String key : o1.getAllKeys()) { - if (key.equals("Count")) - continue; - Tag value = o1.get(key); - Tag otherValue = o2.get(key); - if (!equalsTag(value, otherValue)) - return false; - } - } catch (ClassCastException | NullPointerException unused) { - return false; - } - - return true; - } - - private boolean equalsTag(Tag tag, Tag otherTag) { - if (tag == null || otherTag == null) { - return tag == otherTag; - } - if (tag instanceof ListTag && otherTag instanceof ListTag) - return equalsList((ListTag) tag, (ListTag) otherTag); - return tag.equals(otherTag); - } - - private boolean equalsList(ListTag listTag, ListTag otherListTag) { - if (listTag.size() != otherListTag.size()) - return false; - for (int i = 0; i < listTag.size(); i++) { - Tag value = listTag.get(i); - Tag otherValue = otherListTag.get(i); - if (!equalsTag(value, otherValue)) - return false; - } - return true; + return context.isFuzzy() || ItemComparatorRegistry.getInstance().hashOf(o1) == ItemComparatorRegistry.getInstance().hashOf(o2); } @Override @@ -272,7 +217,7 @@ public class ItemEntryDefinition implements EntryDefinition, EntrySer @Override public void renderBase(EntryStack entry, PoseStack matrices, MultiBufferSource.BufferSource immediate, Rectangle bounds, int mouseX, int mouseY, float delta) { - if (!entry.isEmpty() && entry.get(EntryStack.Settings.RENDER).get()) { + if (!entry.isEmpty()) { ItemStack stack = entry.getValue(); matrices.pushPose(); matrices.translate(bounds.getCenterX(), bounds.getCenterY(), 100.0F + entry.getZ()); @@ -284,9 +229,9 @@ public class ItemEntryDefinition implements EntryDefinition, EntrySer @Override public void renderOverlay(EntryStack entry, PoseStack matrices, Rectangle bounds, int mouseX, int mouseY, float delta) { - if (!entry.isEmpty() && entry.get(EntryStack.Settings.RENDER).get()) { + if (!entry.isEmpty()) { Minecraft.getInstance().getItemRenderer().blitOffset = entry.getZ(); - Minecraft.getInstance().getItemRenderer().renderGuiItemDecorations(Minecraft.getInstance().font, entry.getValue(), bounds.x, bounds.y, entry.get(EntryStack.Settings.RENDER_COUNTS).get() ? entry.get(EntryStack.Settings.COUNTS).apply(entry) : ""); + Minecraft.getInstance().getItemRenderer().renderGuiItemDecorations(Minecraft.getInstance().font, entry.getValue(), bounds.x, bounds.y, entry.get(EntryStack.Settings.COUNTS).apply(entry)); Minecraft.getInstance().getItemRenderer().blitOffset = 0.0F; } } diff --git a/runtime/src/main/java/me/shedaniel/rei/gui/widget/EntryListEntryWidget.java b/runtime/src/main/java/me/shedaniel/rei/gui/widget/EntryListEntryWidget.java index d2e1e822e..f354164e9 100644 --- a/runtime/src/main/java/me/shedaniel/rei/gui/widget/EntryListEntryWidget.java +++ b/runtime/src/main/java/me/shedaniel/rei/gui/widget/EntryListEntryWidget.java @@ -29,7 +29,6 @@ import me.shedaniel.math.Point; import me.shedaniel.rei.api.ClientHelper; import me.shedaniel.rei.api.config.ConfigObject; import me.shedaniel.rei.api.ingredient.EntryStack; -import me.shedaniel.rei.api.ingredient.entry.ComparisonContext; import me.shedaniel.rei.api.ingredient.util.EntryStacks; import net.minecraft.client.gui.screens.Screen; import net.minecraft.world.item.Item; @@ -107,7 +106,7 @@ public abstract class EntryListEntryWidget extends EntryWidget { entry = EntryStacks.of(bucketItem); } } - return EntryStacks.equalsIgnoreCount(entry, stack); + return EntryStacks.equalsExact(entry, stack); } } return super.cancelDeleteItems(stack); diff --git a/runtime/src/main/java/me/shedaniel/rei/gui/widget/EntryListWidget.java b/runtime/src/main/java/me/shedaniel/rei/gui/widget/EntryListWidget.java index e95cfec59..d135b4733 100644 --- a/runtime/src/main/java/me/shedaniel/rei/gui/widget/EntryListWidget.java +++ b/runtime/src/main/java/me/shedaniel/rei/gui/widget/EntryListWidget.java @@ -50,10 +50,9 @@ import me.shedaniel.rei.api.gui.widgets.Tooltip; import me.shedaniel.rei.api.gui.widgets.Widget; import me.shedaniel.rei.api.gui.widgets.WidgetWithBounds; import me.shedaniel.rei.api.ingredient.EntryStack; -import me.shedaniel.rei.api.ingredient.entry.BatchEntryRenderer; -import me.shedaniel.rei.api.ingredient.entry.ComparisonContext; -import me.shedaniel.rei.api.ingredient.entry.EntryRenderer; -import me.shedaniel.rei.api.ingredient.entry.VanillaEntryTypes; +import me.shedaniel.rei.api.ingredient.entry.renderer.BatchEntryRenderer; +import me.shedaniel.rei.api.ingredient.entry.renderer.EntryRenderer; +import me.shedaniel.rei.api.ingredient.entry.type.VanillaEntryTypes; import me.shedaniel.rei.api.ingredient.util.EntryStacks; import me.shedaniel.rei.api.registry.entry.EntryRegistry; import me.shedaniel.rei.api.registry.screen.OverlayDecider; @@ -525,7 +524,7 @@ public class EntryListWidget extends WidgetWithBounds { boolean checkCraftable = ConfigManager.getInstance().isCraftableOnlyEnabled() && !ContainerScreenOverlay.getInstance().inventoryStacks.isEmpty(); IntSet workingItems = checkCraftable ? new IntOpenHashSet() : null; if (checkCraftable) - workingItems.addAll(CollectionUtils.map(Views.getInstance().findCraftableEntriesByItems(ContainerScreenOverlay.getInstance().inventoryStacks), EntryStacks::hashIgnoreCount)); + workingItems.addAll(CollectionUtils.map(Views.getInstance().findCraftableEntriesByItems(ContainerScreenOverlay.getInstance().inventoryStacks), EntryStacks::hashExact)); List> stacks = EntryRegistry.getInstance().getPreFilteredList(); if (!stacks.isEmpty()) { if (ConfigObject.getInstance().shouldAsyncSearch()) { @@ -535,9 +534,9 @@ public class EntryListWidget extends WidgetWithBounds { List> filtered = Lists.newArrayList(); for (EntryStack stack : partitionStacks) { if (canLastSearchTermsBeAppliedTo(stack)) { - if (workingItems != null && !workingItems.contains(EntryStacks.hashIgnoreCount(stack))) + if (workingItems != null && !workingItems.contains(EntryStacks.hashExact(stack))) continue; - filtered.add(stack.rewrap().setting(EntryStack.Settings.RENDER_COUNTS, EntryStack.Settings.FALSE)); + filtered.add(stack.normalize()); } } return filtered; @@ -556,9 +555,9 @@ public class EntryListWidget extends WidgetWithBounds { } else { for (EntryStack stack : stacks) { if (canLastSearchTermsBeAppliedTo(stack)) { - if (workingItems != null && !workingItems.contains(EntryStacks.hashIgnoreCount(stack))) + if (workingItems != null && !workingItems.contains(EntryStacks.hashExact(stack))) continue; - list.add(stack.rewrap().setting(EntryStack.Settings.RENDER_COUNTS, EntryStack.Settings.FALSE)); + list.add(stack.normalize()); } } } diff --git a/runtime/src/main/java/me/shedaniel/rei/gui/widget/FavoritesListWidget.java b/runtime/src/main/java/me/shedaniel/rei/gui/widget/FavoritesListWidget.java index 938988b48..db383eda7 100644 --- a/runtime/src/main/java/me/shedaniel/rei/gui/widget/FavoritesListWidget.java +++ b/runtime/src/main/java/me/shedaniel/rei/gui/widget/FavoritesListWidget.java @@ -52,7 +52,7 @@ import me.shedaniel.rei.api.gui.widgets.Tooltip; import me.shedaniel.rei.api.gui.widgets.Widget; import me.shedaniel.rei.api.gui.widgets.WidgetWithBounds; import me.shedaniel.rei.api.ingredient.EntryStack; -import me.shedaniel.rei.api.ingredient.entry.BatchEntryRenderer; +import me.shedaniel.rei.api.ingredient.entry.renderer.BatchEntryRenderer; import me.shedaniel.rei.api.ingredient.util.EntryStacks; import me.shedaniel.rei.api.util.CollectionUtils; import me.shedaniel.rei.api.util.ImmutableLiteralText; diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/AbstractEntryStack.java b/runtime/src/main/java/me/shedaniel/rei/impl/AbstractEntryStack.java index 6c176dbc1..dc6eb2e43 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/AbstractEntryStack.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/AbstractEntryStack.java @@ -32,7 +32,7 @@ import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.gui.AbstractRenderer; import me.shedaniel.rei.api.gui.widgets.Tooltip; import me.shedaniel.rei.api.ingredient.EntryStack; -import me.shedaniel.rei.api.ingredient.entry.ComparisonContext; +import me.shedaniel.rei.api.ingredient.entry.comparison.ComparisonContext; import me.shedaniel.rei.api.ingredient.util.EntryStacks; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; @@ -98,7 +98,7 @@ public abstract class AbstractEntryStack extends AbstractRenderer implements @Override public void render(PoseStack matrices, Rectangle bounds, int mouseX, int mouseY, float delta) { - this.getDefinition().getRenderer().render(this, matrices, bounds, mouseX, mouseY, delta); + this.getRenderer().render(this, matrices, bounds, mouseX, mouseY, delta); } @Override diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/AmountIgnoredEntryStackWrapper.java b/runtime/src/main/java/me/shedaniel/rei/impl/AmountIgnoredEntryStackWrapper.java deleted file mode 100644 index 344173e15..000000000 --- a/runtime/src/main/java/me/shedaniel/rei/impl/AmountIgnoredEntryStackWrapper.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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.impl; - -import me.shedaniel.rei.api.ingredient.EntryStack; -import me.shedaniel.rei.api.ingredient.util.EntryStacks; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import org.jetbrains.annotations.ApiStatus; - -import java.util.Objects; - -@ApiStatus.Internal -@Environment(EnvType.CLIENT) -public class AmountIgnoredEntryStackWrapper { - private final EntryStack stack; - private int hash; - - public AmountIgnoredEntryStackWrapper(EntryStack stack) { - this.stack = Objects.requireNonNull(stack); - this.hash = EntryStacks.hashIgnoreCount(stack); - } - - @Override - public boolean equals(Object o) { - return o instanceof AmountIgnoredEntryStackWrapper && hashCode() == o.hashCode(); - } - - @Override - public int hashCode() { - return hash; - } - - public boolean isEmpty() { - return stack.isEmpty(); - } - - public EntryStack unwrap() { - return stack; - } -} \ No newline at end of file diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/ClientHelperImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/ClientHelperImpl.java index 450248dbe..e2e2460a6 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/ClientHelperImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/ClientHelperImpl.java @@ -34,7 +34,7 @@ import me.shedaniel.rei.api.config.ConfigObject; import me.shedaniel.rei.api.REIHelper; import me.shedaniel.rei.api.gui.config.RecipeScreenType; import me.shedaniel.rei.api.ingredient.EntryStack; -import me.shedaniel.rei.api.ingredient.entry.VanillaEntryTypes; +import me.shedaniel.rei.api.ingredient.entry.type.VanillaEntryTypes; import me.shedaniel.rei.api.ingredient.util.EntryStacks; import me.shedaniel.rei.api.registry.display.Display; import me.shedaniel.rei.api.registry.display.DisplayCategory; @@ -152,7 +152,7 @@ public class ClientHelperImpl implements ClientHelper { if (ConfigObject.getInstance().isGrabbingItems() && Minecraft.getInstance().screen instanceof CreativeModeInventoryScreen) { Inventory inventory = Minecraft.getInstance().player.inventory; EntryStack stack = entry.copy(); - if (!inventory.getCarried().isEmpty() && EntryStacks.equalsIgnoreCount(EntryStacks.of(inventory.getCarried()), stack)) { + if (!inventory.getCarried().isEmpty() && EntryStacks.equalsExact(EntryStacks.of(inventory.getCarried()), stack)) { stack.getValue().setCount(Mth.clamp(stack.getValue().getCount() + inventory.getCarried().getCount(), 1, stack.getValue().getMaxStackSize())); } else if (!inventory.getCarried().isEmpty()) { return false; @@ -162,7 +162,7 @@ public class ClientHelperImpl implements ClientHelper { } else if (RoughlyEnoughItemsCore.canUsePackets()) { Inventory inventory = Minecraft.getInstance().player.inventory; EntryStack stack = entry.copy(); - if (!inventory.getCarried().isEmpty() && !EntryStacks.equalsIgnoreCount(EntryStacks.of(inventory.getCarried()), stack)) { + if (!inventory.getCarried().isEmpty() && !EntryStacks.equalsExact(EntryStacks.of(inventory.getCarried()), stack)) { return false; } try { diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/ConfigManagerImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/ConfigManagerImpl.java index c99795f5e..b8edc6b5c 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/ConfigManagerImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/ConfigManagerImpl.java @@ -57,6 +57,7 @@ import me.shedaniel.rei.api.gui.config.SyntaxHighlightingMode; import me.shedaniel.rei.api.gui.config.entry.*; import me.shedaniel.rei.api.ingredient.EntryStack; import me.shedaniel.rei.api.registry.entry.EntryRegistry; +import me.shedaniel.rei.api.util.CollectionUtils; import me.shedaniel.rei.gui.ContainerScreenOverlay; import me.shedaniel.rei.gui.TransformingScreen; import me.shedaniel.rei.gui.WarningAndErrorScreen; @@ -195,9 +196,9 @@ public class ConfigManagerImpl implements ConfigManager { getConfig().getFavoriteEntries().removeIf(Objects::isNull); if (getConfig().getFilteredStacks() != null) { getConfig().getFilteredStacks().removeIf(EntryStack::isEmpty); - for (EntryStack stack : getConfig().getFilteredStacks()) { - stack.setting(EntryStack.Settings.CHECK_AMOUNT, EntryStack.Settings.FALSE).setting(EntryStack.Settings.RENDER_COUNTS, EntryStack.Settings.FALSE).setting(EntryStack.Settings.CHECK_TAGS, EntryStack.Settings.TRUE); - } + List> normalizedFilteredStacks = CollectionUtils.map(getConfig().getFilteredStacks(), EntryStack::normalize); + getConfig().getFilteredStacks().clear(); + getConfig().getFilteredStacks().addAll(normalizedFilteredStacks); } if (getConfig().getFilteringRules().stream().noneMatch(filteringRule -> filteringRule instanceof ManualFilteringRule)) { getConfig().getFilteringRules().add(new ManualFilteringRule()); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/EntryRegistryImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/EntryRegistryImpl.java index 7af51086e..1b1be966e 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/EntryRegistryImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/EntryRegistryImpl.java @@ -23,6 +23,7 @@ package me.shedaniel.rei.impl; +import com.google.common.base.MoreObjects; import com.google.common.base.Stopwatch; import com.google.common.collect.Lists; import me.shedaniel.rei.RoughlyEnoughItemsCore; @@ -39,6 +40,7 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.core.NonNullList; import net.minecraft.core.Registry; +import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.ApiStatus; @@ -56,7 +58,7 @@ public class EntryRegistryImpl implements EntryRegistry { private final List> preFilteredList = Lists.newCopyOnWriteArrayList(); private final List> entries = Lists.newCopyOnWriteArrayList(); @Nullable - private List reloadingRegistry; + private List reloadingRegistry; private boolean reloading; @Override @@ -78,9 +80,9 @@ public class EntryRegistryImpl implements EntryRegistry { public void endReload() { reloading = false; preFilteredList.clear(); - reloadingRegistry.removeIf(AmountIgnoredEntryStackWrapper::isEmpty); + reloadingRegistry.removeIf(HashedEntryStackWrapper::isEmpty); entries.clear(); - entries.addAll(CollectionUtils.map(reloadingRegistry, AmountIgnoredEntryStackWrapper::unwrap)); + entries.addAll(CollectionUtils.map(reloadingRegistry, HashedEntryStackWrapper::unwrap)); reloadingRegistry = null; } @@ -92,7 +94,7 @@ public class EntryRegistryImpl implements EntryRegistry { @Override @NotNull public Stream> getEntryStacks() { - return reloading ? reloadingRegistry.stream().map(AmountIgnoredEntryStackWrapper::unwrap) : entries.stream(); + return reloading ? reloadingRegistry.stream().map(HashedEntryStackWrapper::unwrap) : entries.stream(); } @Override @@ -115,16 +117,16 @@ public class EntryRegistryImpl implements EntryRegistry { RoughlyEnoughItemsCore.LOGGER.debug("Refiltered rule [%s] in %s.", FilteringRule.REGISTRY.getKey(rule).toString(), innerStopwatch.stop().toString()); } - Set hiddenStacks = context.stacks.get(FilteringContextType.HIDDEN); + Set hiddenStacks = context.stacks.get(FilteringContextType.HIDDEN); if (hiddenStacks.isEmpty()) { preFilteredList.clear(); preFilteredList.addAll(entries); } else { preFilteredList.clear(); preFilteredList.addAll(entries.parallelStream() - .map(AmountIgnoredEntryStackWrapper::new) + .map(HashedEntryStackWrapper::new) .filter(not(hiddenStacks::contains)) - .map(AmountIgnoredEntryStackWrapper::unwrap) + .map(HashedEntryStackWrapper::unwrap) .collect(Collectors.toList())); } @@ -142,9 +144,11 @@ public class EntryRegistryImpl implements EntryRegistry { @Override public List appendStacksForItem(@NotNull Item item) { NonNullList list = NonNullList.create(); - item.fillItemCategory(item.getItemCategory(), list); - if (list.isEmpty()) + CreativeModeTab category = item.getItemCategory(); + item.fillItemCategory(MoreObjects.firstNonNull(category, CreativeModeTab.TAB_SEARCH), list); + if (list.isEmpty()) { return Collections.singletonList(item.getDefaultInstance()); + } list.sort(STACK_COMPARATOR); return list; } @@ -152,10 +156,10 @@ public class EntryRegistryImpl implements EntryRegistry { @Override public void registerEntryAfter(@Nullable EntryStack afterEntry, @NotNull EntryStack stack) { if (reloading) { - int index = afterEntry != null ? reloadingRegistry.lastIndexOf(new AmountIgnoredEntryStackWrapper(afterEntry)) : -1; + int index = afterEntry != null ? reloadingRegistry.lastIndexOf(new HashedEntryStackWrapper(afterEntry)) : -1; if (index >= 0) { - reloadingRegistry.add(index, new AmountIgnoredEntryStackWrapper(stack)); - } else reloadingRegistry.add(new AmountIgnoredEntryStackWrapper(stack)); + reloadingRegistry.add(index, new HashedEntryStackWrapper(stack)); + } else reloadingRegistry.add(new HashedEntryStackWrapper(stack)); } else { if (afterEntry != null) { int index = entries.lastIndexOf(afterEntry); @@ -167,10 +171,10 @@ public class EntryRegistryImpl implements EntryRegistry { @Override public void registerEntriesAfter(@Nullable EntryStack afterEntry, @NotNull Collection<@NotNull ? extends EntryStack> stacks) { if (reloading) { - int index = afterEntry != null ? reloadingRegistry.lastIndexOf(new AmountIgnoredEntryStackWrapper(afterEntry)) : -1; + int index = afterEntry != null ? reloadingRegistry.lastIndexOf(new HashedEntryStackWrapper(afterEntry)) : -1; if (index >= 0) { - reloadingRegistry.addAll(index, CollectionUtils.map(stacks, AmountIgnoredEntryStackWrapper::new)); - } else reloadingRegistry.addAll(CollectionUtils.map(stacks, AmountIgnoredEntryStackWrapper::new)); + reloadingRegistry.addAll(index, CollectionUtils.map(stacks, HashedEntryStackWrapper::new)); + } else reloadingRegistry.addAll(CollectionUtils.map(stacks, HashedEntryStackWrapper::new)); } else { if (afterEntry != null) { int index = entries.lastIndexOf(afterEntry); @@ -190,7 +194,7 @@ public class EntryRegistryImpl implements EntryRegistry { @Override public boolean removeEntry(EntryStack stack) { if (reloading) { - return reloadingRegistry.remove(new AmountIgnoredEntryStackWrapper(stack)); + return reloadingRegistry.remove(new HashedEntryStackWrapper(stack)); } else { return entries.remove(stack); } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/EntryTypeDeferred.java b/runtime/src/main/java/me/shedaniel/rei/impl/EntryTypeDeferred.java index ac9724734..9ed1277eb 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/EntryTypeDeferred.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/EntryTypeDeferred.java @@ -23,9 +23,9 @@ package me.shedaniel.rei.impl; -import me.shedaniel.rei.api.ingredient.entry.EntryDefinition; -import me.shedaniel.rei.api.ingredient.entry.EntryType; -import me.shedaniel.rei.api.ingredient.entry.EntryTypeRegistry; +import me.shedaniel.rei.api.ingredient.entry.type.EntryDefinition; +import me.shedaniel.rei.api.ingredient.entry.type.EntryType; +import me.shedaniel.rei.api.ingredient.entry.type.EntryTypeRegistry; import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/EntryTypeRegistryImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/EntryTypeRegistryImpl.java index e8fe8cec6..09dfbf6e9 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/EntryTypeRegistryImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/EntryTypeRegistryImpl.java @@ -27,10 +27,10 @@ import com.google.common.collect.BiMap; import com.google.common.collect.HashBasedTable; import com.google.common.collect.HashBiMap; import com.google.common.collect.Table; -import me.shedaniel.rei.api.ingredient.entry.EntryDefinition; -import me.shedaniel.rei.api.ingredient.entry.EntryType; -import me.shedaniel.rei.api.ingredient.entry.EntryTypeBridge; -import me.shedaniel.rei.api.ingredient.entry.EntryTypeRegistry; +import me.shedaniel.rei.api.ingredient.entry.type.EntryDefinition; +import me.shedaniel.rei.api.ingredient.entry.type.EntryType; +import me.shedaniel.rei.api.ingredient.entry.type.EntryTypeBridge; +import me.shedaniel.rei.api.ingredient.entry.type.EntryTypeRegistry; import me.shedaniel.rei.api.plugins.REIPlugin; import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.ApiStatus; diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/HashedEntryStackWrapper.java b/runtime/src/main/java/me/shedaniel/rei/impl/HashedEntryStackWrapper.java new file mode 100644 index 000000000..5ed08e1c2 --- /dev/null +++ b/runtime/src/main/java/me/shedaniel/rei/impl/HashedEntryStackWrapper.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.impl; + +import me.shedaniel.rei.api.ingredient.EntryStack; +import me.shedaniel.rei.api.ingredient.util.EntryStacks; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import org.jetbrains.annotations.ApiStatus; + +import java.util.Objects; + +@ApiStatus.Internal +@Environment(EnvType.CLIENT) +public class HashedEntryStackWrapper { + private final EntryStack stack; + private int hash; + + public HashedEntryStackWrapper(EntryStack stack) { + this.stack = Objects.requireNonNull(stack); + this.hash = EntryStacks.hashExact(stack); + } + + @Override + public boolean equals(Object o) { + return o instanceof HashedEntryStackWrapper && hashCode() == o.hashCode(); + } + + @Override + public int hashCode() { + return hash; + } + + public boolean isEmpty() { + return stack.isEmpty(); + } + + public EntryStack unwrap() { + return stack; + } +} \ No newline at end of file diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/PluginManagerImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/PluginManagerImpl.java index e62c18a30..031f4b22e 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/PluginManagerImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/PluginManagerImpl.java @@ -35,6 +35,7 @@ import me.shedaniel.rei.api.registry.display.DisplayRegistry; import me.shedaniel.rei.api.registry.entry.EntryRegistry; import me.shedaniel.rei.api.registry.screen.ScreenRegistry; import me.shedaniel.rei.api.util.CollectionUtils; +import me.shedaniel.rei.impl.entry.ItemComparatorRegistryImpl; import me.shedaniel.rei.impl.registry.CategoryRegistryImpl; import me.shedaniel.rei.impl.registry.DisplayRegistryImpl; import me.shedaniel.rei.impl.subsets.SubsetsRegistryImpl; @@ -63,6 +64,7 @@ public class PluginManagerImpl implements PluginManager { public PluginManagerImpl() { registerReloadable(new ConfigManagerImpl()); registerReloadable(new EntryTypeRegistryImpl()); + registerReloadable(new ItemComparatorRegistryImpl()); registerReloadable(new FluidSupportProviderImpl()); registerReloadable(new CategoryRegistryImpl()); registerReloadable(new DisplayRegistryImpl()); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/TypedEntryStack.java b/runtime/src/main/java/me/shedaniel/rei/impl/TypedEntryStack.java index f5c53c4a4..367d67453 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/TypedEntryStack.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/TypedEntryStack.java @@ -24,12 +24,11 @@ package me.shedaniel.rei.impl; import it.unimi.dsi.fastutil.shorts.Short2ObjectMap; -import me.shedaniel.architectury.utils.Fraction; import me.shedaniel.rei.api.ingredient.EntryStack; -import me.shedaniel.rei.api.ingredient.entry.BuiltinEntryTypes; -import me.shedaniel.rei.api.ingredient.entry.ComparisonContext; -import me.shedaniel.rei.api.ingredient.entry.EntryDefinition; -import me.shedaniel.rei.api.ingredient.entry.EntryType; +import me.shedaniel.rei.api.ingredient.entry.type.BuiltinEntryTypes; +import me.shedaniel.rei.api.ingredient.entry.comparison.ComparisonContext; +import me.shedaniel.rei.api.ingredient.entry.type.EntryDefinition; +import me.shedaniel.rei.api.ingredient.entry.type.EntryType; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Unit; diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/entry/EmptyEntryDefinition.java b/runtime/src/main/java/me/shedaniel/rei/impl/entry/EmptyEntryDefinition.java index 81614a3fb..8a5008cf1 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/entry/EmptyEntryDefinition.