diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/DefaultCraftingCategory.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/DefaultCraftingCategory.java index 963717e45..3f91ad76b 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/DefaultCraftingCategory.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/DefaultCraftingCategory.java @@ -95,7 +95,7 @@ public DisplayMerger> getDisplayMerger() { @Override public boolean canMerge(DefaultCraftingDisplay first, DefaultCraftingDisplay second) { if (!first.getCategoryIdentifier().equals(second.getCategoryIdentifier())) return false; - if (!equals(first.getOrganisedInputEntries(3, 3), second.getInputEntries())) return false; + if (!equals(first.getOrganisedInputEntries(3, 3), second.getOrganisedInputEntries(3, 3))) return false; if (!equals(first.getOutputEntries(), second.getOutputEntries())) return false; if (first.isShapeless() != second.isShapeless()) return false; if (first.getWidth() != second.getWidth()) return false; diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java index 6ea420004..de49c9a29 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java @@ -479,6 +479,7 @@ public static void reloadPlugins(MutableLong lastReload, @Nullable ReloadStage s } lastReload.setValue(System.currentTimeMillis()); } + InternalLogger.getInstance().debug("Starting Reload Plugins of stage " + start, new Throwable()); if (ConfigObject.getInstance().doesRegisterRecipesInAnotherThread()) { Future[] futures = new Future[1]; CompletableFuture future = CompletableFuture.runAsync(() -> RoughlyEnoughItemsCore._reloadPlugins(start), RELOAD_PLUGINS) diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringScreen.java index 477fb0d00..6d528c50d 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringScreen.java @@ -248,7 +248,7 @@ public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { scrolling.renderScrollBar(0, 1.0F, REIRuntime.getInstance().isDarkThemeEnabled() ? 0.8F : 1F); matrices.pushPose(); matrices.translate(0, 0, 300); - this.searchField.laterRender(matrices, mouseX, mouseY, delta); + this.searchField.render(matrices, mouseX, mouseY, delta); this.selectAllButton.render(matrices, mouseX, mouseY, delta); this.selectNoneButton.render(matrices, mouseX, mouseY, delta); this.hideButton.render(matrices, mouseX, mouseY, delta); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/ReloadPluginsEntry.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/ReloadPluginsEntry.java index 9cc189f55..0ac3e13b4 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/ReloadPluginsEntry.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/ReloadPluginsEntry.java @@ -57,7 +57,7 @@ public class ReloadPluginsEntry extends AbstractConfigListEntry { public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { if (PluginManager.areAnyReloading()) { Screen screen = Minecraft.getInstance().screen; - Minecraft.getInstance().setScreen(new ConfigReloadingScreen(Component.translatable("text.rei.config.is.reloading"), PluginManager::areAnyReloading, () -> Minecraft.getInstance().setScreen(screen))); + Minecraft.getInstance().setScreen(new ConfigReloadingScreen(Component.translatable("text.rei.config.is.reloading"), PluginManager::areAnyReloading, () -> Minecraft.getInstance().setScreen(screen), null)); } else { super.render(matrices, mouseX, mouseY, delta); } @@ -87,7 +87,7 @@ public Optional getDefaultValue() { @Override public void save() { - + } @Override diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/ConfigReloadingScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/ConfigReloadingScreen.java index 232239977..8b0abbebf 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/ConfigReloadingScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/ConfigReloadingScreen.java @@ -25,7 +25,9 @@ import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.Util; +import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.Component; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; @@ -39,12 +41,14 @@ public class ConfigReloadingScreen extends Screen { private final BooleanSupplier predicate; private Supplier<@Nullable Component> subtitle = () -> null; private final Runnable parent; + private final Runnable cancel; - public ConfigReloadingScreen(Component title, BooleanSupplier predicate, Runnable parent) { + public ConfigReloadingScreen(Component title, BooleanSupplier predicate, Runnable parent, Runnable cancel) { super(Component.empty()); this.title = title; this.predicate = predicate; this.parent = parent; + this.cancel = cancel; } public void setSubtitle(Supplier<@Nullable Component> subtitle) { @@ -56,6 +60,15 @@ public boolean shouldCloseOnEsc() { return false; } + @Override + public void init() { + super.init(); + if (cancel == null) return; + this.addRenderableWidget(Button.builder(CommonComponents.GUI_CANCEL, button -> { + cancel.run(); + }).bounds(this.width / 2 - 100, this.height / 4 + 120 + 12, 200, 20).build()); + } + @Override public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { this.renderDirtBackground(matrices); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/CraftableFilterButtonWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/CraftableFilterButtonWidget.java index 27624c69c..0796a374b 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/CraftableFilterButtonWidget.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/CraftableFilterButtonWidget.java @@ -23,6 +23,7 @@ package me.shedaniel.rei.impl.client.gui.widget; +import dev.architectury.platform.Platform; import dev.architectury.utils.value.BooleanValue; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; @@ -148,15 +149,22 @@ public static List createInputMethodEntries(MenuAccess access ConfigReloadingScreen reloadingScreen = new ConfigReloadingScreen(Component.translatable("text.rei.input.methods.initializing"), () -> !future.isDone(), () -> { Minecraft.getInstance().setScreen(screen); + }, () -> { + Minecraft.getInstance().setScreen(screen); + InternalLogger.getInstance().error("Failed to prepare input method: cancelled"); + ConfigManagerImpl.getInstance().getConfig().setInputMethodId(new ResourceLocation("rei:default")); + future.cancel(Platform.isFabric()); + service.shutdown(); }); reloadingScreen.setSubtitle(() -> Component.translatable("text.rei.input.methods.reload.progress", String.format("%.2f", progress[0] * 100))); Minecraft.getInstance().setScreen(reloadingScreen); access.close(); future.whenComplete((unused, throwable) -> { service.shutdown(); + if (throwable != null) return; + ScreenOverlayImpl.getInstance().getHintsContainer().addHint(12, () -> new Point(getCraftableFilterBounds().getCenterX(), getCraftableFilterBounds().getCenterY()), + "text.rei.hint.input.methods", List.of(Component.translatable("text.rei.hint.input.methods"))); }); - ScreenOverlayImpl.getInstance().getHintsContainer().addHint(12, () -> new Point(getCraftableFilterBounds().getCenterX(), getCraftableFilterBounds().getCenterY()), - "text.rei.hint.input.methods", List.of(Component.translatable("text.rei.hint.input.methods"))); }) .withActive(() -> !Objects.equals(config.getInputMethodId(), pair.getKey())) .withTooltip(() -> Tooltip.create(Widget.mouse(), pair.getValue().getDescription())) diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/screen/DefaultScreenOverlayRenderer.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/screen/DefaultScreenOverlayRenderer.java index 520b89bb7..8a76a0da3 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/screen/DefaultScreenOverlayRenderer.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/screen/DefaultScreenOverlayRenderer.java @@ -31,9 +31,7 @@ import me.shedaniel.rei.api.client.registry.screen.OverlayRendererProvider; import me.shedaniel.rei.impl.common.InternalLogger; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; - -import java.util.ArrayList; -import java.util.List; +import org.jetbrains.annotations.Nullable; import static me.shedaniel.rei.RoughlyEnoughItemsCoreClient.resetFocused; import static me.shedaniel.rei.RoughlyEnoughItemsCoreClient.shouldReturn; @@ -41,22 +39,50 @@ public enum DefaultScreenOverlayRenderer implements OverlayRendererProvider { INSTANCE; - private final List onRemoved = new ArrayList<>(); + @Nullable + private ClientGuiEvent.ScreenRenderPre renderPre; + @Nullable + private ClientGuiEvent.ContainerScreenRenderBackground renderContainerBg; + @Nullable + private ClientGuiEvent.ContainerScreenRenderForeground renderContainerFg; + @Nullable + private ClientGuiEvent.ScreenRenderPost renderPost; + + { + ClientGuiEvent.RENDER_PRE.register((screen, graphics, mouseX, mouseY, delta) -> { + if (renderPre != null) { + return renderPre.render(screen, graphics, mouseX, mouseY, delta); + } else { + return EventResult.pass(); + } + }); + ClientGuiEvent.RENDER_CONTAINER_BACKGROUND.register((screen, graphics, mouseX, mouseY, delta) -> { + if (renderContainerBg != null) { + renderContainerBg.render(screen, graphics, mouseX, mouseY, delta); + } + }); + ClientGuiEvent.RENDER_CONTAINER_FOREGROUND.register((screen, graphics, mouseX, mouseY, delta) -> { + if (renderContainerFg != null) { + renderContainerFg.render(screen, graphics, mouseX, mouseY, delta); + } + }); + ClientGuiEvent.RENDER_POST.register((screen, graphics, mouseX, mouseY, delta) -> { + if (renderPost != null) { + renderPost.render(screen, graphics, mouseX, mouseY, delta); + } + }); + } @Override public void onApplied(Sink sink) { int[] rendered = {0}; - ClientGuiEvent.ScreenRenderPre renderPre; - ClientGuiEvent.ContainerScreenRenderBackground renderContainerBg; - ClientGuiEvent.ContainerScreenRenderForeground renderContainerFg; - ClientGuiEvent.ScreenRenderPost renderPost; - ClientGuiEvent.RENDER_PRE.register(renderPre = (screen, matrices, mouseX, mouseY, delta) -> { + this.renderPre = (screen, matrices, mouseX, mouseY, delta) -> { if (shouldReturn(screen)) return EventResult.pass(); rendered[0] = 0; return EventResult.pass(); - }); - ClientGuiEvent.RENDER_CONTAINER_BACKGROUND.register(renderContainerBg = (screen, matrices, mouseX, mouseY, delta) -> { + }; + this.renderContainerBg = (screen, matrices, mouseX, mouseY, delta) -> { if (shouldReturn(screen)) return; rendered[0] = 1; @@ -65,8 +91,8 @@ public void onApplied(Sink sink) { sink.render(matrices, mouseX, mouseY, delta); } resetFocused(screen); - }); - ClientGuiEvent.RENDER_CONTAINER_FOREGROUND.register(renderContainerFg = (screen, matrices, mouseX, mouseY, delta) -> { + }; + this.renderContainerFg = (screen, matrices, mouseX, mouseY, delta) -> { if (shouldReturn(screen)) return; rendered[0] = 2; @@ -79,8 +105,8 @@ public void onApplied(Sink sink) { poseStack.popPose(); RenderSystem.applyModelViewMatrix(); resetFocused(screen); - }); - ClientGuiEvent.RENDER_POST.register(renderPost = (screen, matrices, mouseX, mouseY, delta) -> { + }; + this.renderPost = (screen, matrices, mouseX, mouseY, delta) -> { if (shouldReturn(screen) || rendered[0] == 2) return; if (screen instanceof AbstractContainerScreen) { @@ -95,18 +121,14 @@ public void onApplied(Sink sink) { sink.lateRender(matrices, mouseX, mouseY, delta); } resetFocused(screen); - }); - this.onRemoved.add(() -> { - ClientGuiEvent.RENDER_PRE.unregister(renderPre); - ClientGuiEvent.RENDER_CONTAINER_BACKGROUND.unregister(renderContainerBg); - ClientGuiEvent.RENDER_CONTAINER_FOREGROUND.unregister(renderContainerFg); - ClientGuiEvent.RENDER_POST.unregister(renderPost); - }); + }; } @Override public void onRemoved() { - this.onRemoved.forEach(Runnable::run); - this.onRemoved.clear(); + this.renderPre = null; + this.renderContainerBg = null; + this.renderContainerFg = null; + this.renderPost = null; } } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/search/AsyncSearchManager.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/search/AsyncSearchManager.java index c1ab15fba..8d1f6f056 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/search/AsyncSearchManager.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/search/AsyncSearchManager.java @@ -48,14 +48,14 @@ public class AsyncSearchManager { private static final ExecutorService EXECUTOR_SERVICE = new ThreadCreator("REI-AsyncSearchManager").asService(Math.min(3, Runtime.getRuntime().availableProcessors())); - private final Supplier> stacksProvider; + private final Supplier> stacksProvider; private final Supplier> additionalPredicateSupplier; private final UnaryOperator transformer; private volatile Map.Entry, SearchFilter> last; public volatile ExecutorTuple executor; public volatile SearchFilter filter; - public AsyncSearchManager(Supplier> stacksProvider, Supplier> additionalPredicateSupplier, UnaryOperator transformer) { + public AsyncSearchManager(Supplier> stacksProvider, Supplier> additionalPredicateSupplier, UnaryOperator transformer) { this.stacksProvider = stacksProvider; this.additionalPredicateSupplier = additionalPredicateSupplier; this.transformer = transformer; @@ -134,7 +134,7 @@ public CompletableFuture, SearchFilter>> } public static CompletableFuture, SearchFilter>> get(SearchFilter filter, Predicate additionalPredicate, - UnaryOperator transformer, List stacks, Map.Entry, SearchFilter> last, + UnaryOperator transformer, List stacks, Map.Entry, SearchFilter> last, AsyncSearchManager manager, Executor executor, Steps steps) { int searchPartitionSize = ConfigObject.getInstance().getAsyncSearchPartitionSize(); boolean shouldAsync = ConfigObject.getInstance().shouldAsyncSearch() && stacks.size() > searchPartitionSize * 4; @@ -144,7 +144,7 @@ public static CompletableFuture, SearchF if (shouldAsync) { List>> futures = Lists.newArrayList(); int partitions = 0; - for (Iterable partitionStacks : CollectionUtils.partition(stacks, searchPartitionSize * 4)) { + for (Iterable partitionStacks : CollectionUtils.partition(stacks, searchPartitionSize * 4)) { final int finalPartitions = partitions; futures.add(CompletableFuture.supplyAsync(() -> { List filtered = Lists.newArrayList(); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/search/argument/Argument.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/search/argument/Argument.java index bd5034aa3..e0b7fd737 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/search/argument/Argument.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/search/argument/Argument.java @@ -24,7 +24,6 @@ package me.shedaniel.rei.impl.client.search.argument; import com.google.common.base.MoreObjects; -import com.google.common.collect.Iterators; import com.google.common.collect.Lists; import it.unimi.dsi.fastutil.ints.IntList; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; @@ -33,12 +32,14 @@ import me.shedaniel.rei.api.client.search.method.CharacterUnpackingInputMethod; import me.shedaniel.rei.api.client.search.method.InputMethod; import me.shedaniel.rei.api.common.entry.EntryStack; +import me.shedaniel.rei.api.common.util.CollectionUtils; import me.shedaniel.rei.impl.client.search.IntRange; import me.shedaniel.rei.impl.client.search.argument.type.ArgumentType; import me.shedaniel.rei.impl.client.search.argument.type.ArgumentTypesRegistry; import me.shedaniel.rei.impl.client.search.collapsed.CollapsedEntriesCache; import me.shedaniel.rei.impl.client.search.result.ArgumentApplicableResult; import me.shedaniel.rei.impl.common.entry.type.EntryRegistryImpl; +import me.shedaniel.rei.impl.common.util.HNEntryStackWrapper; import me.shedaniel.rei.impl.common.util.HashedEntryStackWrapper; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -78,18 +79,8 @@ public Argument(ArgumentType argumentType, String text, boolean regular, T public static void resetCache(boolean cache) { Argument.cache = new ArgumentCache(); CollapsedEntriesCache.reset(); - Collection stacks = new AbstractCollection<>() { - @Override - public Iterator iterator() { - return Iterators.transform(((EntryRegistryImpl) EntryRegistry.getInstance()).getComplexList().iterator(), - HashedEntryStackWrapper::normalize); - } - - @Override - public int size() { - return ((EntryRegistryImpl) EntryRegistry.getInstance()).getComplexList().size(); - } - }; + List stacks = CollectionUtils.map(((EntryRegistryImpl) EntryRegistry.getInstance()).getComplexList(), + HNEntryStackWrapper::normalize); if (cache) { Argument.cache.prepareFilter(stacks, ArgumentTypesRegistry.ARGUMENT_TYPE_LIST, ArgumentCache.EXECUTOR_SERVICE); } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/search/collapsed/CollapsedEntriesCache.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/search/collapsed/CollapsedEntriesCache.java index fc7ada4e8..2f87b2295 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/search/collapsed/CollapsedEntriesCache.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/search/collapsed/CollapsedEntriesCache.java @@ -51,7 +51,7 @@ public static CollapsedEntriesCache getInstance() { return instance; } - public void prepare(Collection stacks) { + public void prepare(Collection stacks) { Collection entries = ((CollapsibleEntryRegistryImpl) CollapsibleEntryRegistry.getInstance()).getEntries(); InternalLogger.getInstance().debug("Preparing collapsed entry groups cache with %d entries and %d stacks", entries.size(), stacks.size()); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryImpl.java index 942e61ad8..c756205e3 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryImpl.java @@ -35,7 +35,7 @@ import me.shedaniel.rei.api.common.util.CollectionUtils; import me.shedaniel.rei.api.common.util.EntryStacks; import me.shedaniel.rei.impl.common.InternalLogger; -import me.shedaniel.rei.impl.common.util.HashedEntryStackWrapper; +import me.shedaniel.rei.impl.common.util.HNEntryStackWrapper; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.world.item.Item; @@ -76,7 +76,7 @@ public ReloadStage getStage() { @Override public void startReload() { this.listeners.clear(); - this.registryList.collectHashed().clear(); + this.registryList.collectHN().clear(); this.entriesHash = new LongOpenHashSet(); this.filteredList = new PreFilteredEntryList(this, this.registryList); this.listeners.add(filteredList); @@ -116,17 +116,17 @@ public List> getPreFilteredList() { return Collections.unmodifiableList(filteredList.getList()); } - public List getPreFilteredComplexList() { + public List getPreFilteredComplexList() { return Collections.unmodifiableList(filteredList.getComplexList()); } - public List getComplexList() { - return Collections.unmodifiableList(registryList.collectHashed()); + public List getComplexList() { + return Collections.unmodifiableList(registryList.collectHN()); } @Override public void refilter() { - List stacks = registryList.collectHashed(); + List stacks = registryList.collectHN(); for (EntryRegistryListener listener : listeners) { listener.onReFilter(stacks); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryList.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryList.java index 5b39024d8..101743097 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryList.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryList.java @@ -25,7 +25,7 @@ import it.unimi.dsi.fastutil.longs.LongList; import me.shedaniel.rei.api.common.entry.EntryStack; -import me.shedaniel.rei.impl.common.util.HashedEntryStackWrapper; +import me.shedaniel.rei.impl.common.util.HNEntryStackWrapper; import java.util.List; import java.util.stream.Stream; @@ -37,7 +37,7 @@ public interface EntryRegistryList { List> collect(); - List collectHashed(); + List collectHN(); int indexOf(EntryStack stack); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryListImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryListImpl.java index d82343d49..6c260455a 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryListImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryListImpl.java @@ -25,6 +25,7 @@ import it.unimi.dsi.fastutil.longs.LongList; import me.shedaniel.rei.api.common.entry.EntryStack; +import me.shedaniel.rei.impl.common.util.HNEntryStackWrapper; import me.shedaniel.rei.impl.common.util.HashedEntryStackWrapper; import net.minecraft.core.registries.BuiltInRegistries; @@ -35,7 +36,7 @@ import java.util.stream.Stream; public class EntryRegistryListImpl implements EntryRegistryList { - private final List hashedList = new ArrayList<>(BuiltInRegistries.ITEM.keySet().size() + 100); + private final List hashedList = new ArrayList<>(BuiltInRegistries.ITEM.keySet().size() + 100); private final List> list = createMappedList(hashedList); public EntryRegistryListImpl() { @@ -61,7 +62,7 @@ public List> collect() { } @Override - public List collectHashed() { + public List collectHN() { return hashedList; } @@ -77,20 +78,20 @@ public int lastIndexOf(EntryStack stack) { @Override public void add(EntryStack stack, long hashExact) { - hashedList.add(new HashedEntryStackWrapper(stack, hashExact)); + hashedList.add(new HNEntryStackWrapper(stack, hashExact)); } @Override public void add(int index, EntryStack stack, long hashExact) { - hashedList.add(index, new HashedEntryStackWrapper(stack, hashExact)); + hashedList.add(index, new HNEntryStackWrapper(stack, hashExact)); } @Override public void addAll(List> stacks, LongList hashes) { hashedList.addAll(new AbstractList<>() { @Override - public HashedEntryStackWrapper get(int index) { - return new HashedEntryStackWrapper(stacks.get(index), hashes.getLong(index)); + public HNEntryStackWrapper get(int index) { + return new HNEntryStackWrapper(stacks.get(index), hashes.getLong(index)); } @Override @@ -104,8 +105,8 @@ public int size() { public void addAll(int index, List> stacks, LongList hashes) { hashedList.addAll(index, new AbstractList<>() { @Override - public HashedEntryStackWrapper get(int index) { - return new HashedEntryStackWrapper(stacks.get(index), hashes.getLong(index)); + public HNEntryStackWrapper get(int index) { + return new HNEntryStackWrapper(stacks.get(index), hashes.getLong(index)); } @Override @@ -134,7 +135,7 @@ public List> getList() { return list; } - private static List> createMappedList(List hashedList) { + private static List> createMappedList(List hashedList) { return new AbstractList<>() { @Override public EntryStack get(int index) { @@ -148,12 +149,12 @@ public int size() { @Override public void add(int index, EntryStack element) { - hashedList.add(index, new HashedEntryStackWrapper(element)); + hashedList.add(index, new HNEntryStackWrapper(element)); } @Override public EntryStack set(int index, EntryStack element) { - return hashedList.set(index, new HashedEntryStackWrapper(element)).unwrap(); + return hashedList.set(index, new HNEntryStackWrapper(element)).unwrap(); } @Override diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryListener.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryListener.java index df91ea28f..2d0f3d238 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryListener.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/EntryRegistryListener.java @@ -25,7 +25,7 @@ import it.unimi.dsi.fastutil.longs.LongList; import me.shedaniel.rei.api.common.entry.EntryStack; -import me.shedaniel.rei.impl.common.util.HashedEntryStackWrapper; +import me.shedaniel.rei.impl.common.util.HNEntryStackWrapper; import org.jetbrains.annotations.Nullable; import java.util.List; @@ -39,5 +39,5 @@ default void removeEntry(EntryStack stack, long hashExact) {} default void removeEntries(List> stacks, @Nullable LongList hashes) {} - default void onReFilter(List stacks) {} + default void onReFilter(List stacks) {} } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/FilteredEntryList.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/FilteredEntryList.java index 76393a51d..efe289659 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/FilteredEntryList.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/FilteredEntryList.java @@ -26,7 +26,7 @@ import it.unimi.dsi.fastutil.longs.LongCollection; import me.shedaniel.rei.api.client.entry.filtering.FilteringRule; import me.shedaniel.rei.api.common.entry.EntryStack; -import me.shedaniel.rei.impl.common.util.HashedEntryStackWrapper; +import me.shedaniel.rei.impl.common.util.HNEntryStackWrapper; import org.jetbrains.annotations.Nullable; import java.util.Collection; @@ -40,7 +40,7 @@ public interface FilteredEntryList extends EntryRegistryListener { List> getList(); - List getComplexList(); + List getComplexList(); boolean isFiltered(EntryStack stack, long hashExact); } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/PreFilteredEntryList.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/PreFilteredEntryList.java index 03a4b47c3..3133afb20 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/PreFilteredEntryList.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/PreFilteredEntryList.java @@ -39,6 +39,7 @@ import me.shedaniel.rei.api.common.util.EntryStacks; import me.shedaniel.rei.impl.client.entry.filtering.FilteringContextType; import me.shedaniel.rei.impl.common.InternalLogger; +import me.shedaniel.rei.impl.common.util.HNEntryStackWrapper; import me.shedaniel.rei.impl.common.util.HashedEntryStackWrapper; import org.jetbrains.annotations.Nullable; @@ -49,7 +50,7 @@ public class PreFilteredEntryList implements FilteredEntryList { private final EntryRegistryList list; private final Map, DataPair> filteringData = new HashMap<>(); private final Long2BooleanMap cached = new Long2BooleanOpenHashMap(); - private final List listView = new InternalListView(); + private final List listView = new InternalListView(); private final List> simpleListView = new InternalSimpleListView(listView); private long mod = 0; @@ -87,7 +88,7 @@ public void removeEntries(List> stacks, @Nullable LongList hashes) } @Override - public void onReFilter(List stacks) { + public void onReFilter(List stacks) { ConfigObject config = ConfigObject.getInstance(); if (config.getFilteredStackProviders() != null) { List> normalizedFilteredStacks = CollectionUtils.map(config.getFilteredStackProviders(), EntryStackProvider::provide); @@ -97,7 +98,7 @@ public void onReFilter(List stacks) { } Stopwatch stopwatch = Stopwatch.createStarted(); - refreshFilteringFor(true, null, Lists.transform(stacks, HashedEntryStackWrapper::unwrap), new AbstractLongList() { + refreshFilteringFor(true, null, Lists.transform(stacks, HNEntryStackWrapper::unwrap), new AbstractLongList() { @Override public long getLong(int index) { return stacks.get(index).hashExact(); @@ -216,16 +217,16 @@ public List> getList() { } @Override - public List getComplexList() { + public List getComplexList() { return listView; } - private class InternalListView extends AbstractList { + private class InternalListView extends AbstractList { private long prevMod = -1; - private List stacks; + private List stacks; @Override - public HashedEntryStackWrapper get(int index) { + public HNEntryStackWrapper get(int index) { if (prevMod == mod) { return stacks.get(index); } @@ -250,18 +251,18 @@ public int size() { } @Override - public Iterator iterator() { + public Iterator iterator() { if (prevMod == mod) { return stacks.iterator(); } - Iterator iterator = list.collectHashed().iterator(); + Iterator iterator = list.collectHN().iterator(); return new AbstractIterator<>() { @Nullable @Override - protected HashedEntryStackWrapper computeNext() { + protected HNEntryStackWrapper computeNext() { while (iterator.hasNext()) { - HashedEntryStackWrapper wrapper = iterator.next(); + HNEntryStackWrapper wrapper = iterator.next(); if (isFiltered(wrapper.unwrap(), wrapper.hashExact())) return wrapper; } @@ -272,9 +273,9 @@ protected HashedEntryStackWrapper computeNext() { } private static class InternalSimpleListView extends AbstractList> { - private final List list; + private final List list; - public InternalSimpleListView(List list) { + public InternalSimpleListView(List list) { this.list = list; } @@ -290,7 +291,7 @@ public int size() { @Override public Iterator> iterator() { - return Iterators.transform(list.iterator(), HashedEntryStackWrapper::unwrap); + return Iterators.transform(list.iterator(), HNEntryStackWrapper::unwrap); } } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/collapsed/CollapsibleEntryRegistryImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/collapsed/CollapsibleEntryRegistryImpl.java index 482d7100b..50f57d3bc 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/collapsed/CollapsibleEntryRegistryImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/collapsed/CollapsibleEntryRegistryImpl.java @@ -47,6 +47,10 @@ public void group(ResourceLocation id, Component name, List normalized; + private final long normalizedHash; + + public HNEntryStackWrapper(EntryStack stack) { + super(stack); + this.normalized = stack.normalize(); + this.normalizedHash = EntryStacks.hashExact(this.normalized); + } + + public HNEntryStackWrapper(EntryStack stack, long hash) { + super(stack, hash); + this.normalized = stack.normalize(); + this.normalizedHash = EntryStacks.hashExact(this.normalized); + } + + public EntryStack normalized() { + return normalized; + } + + @Override + public HashedEntryStackWrapper normalize() { + return new HashedEntryStackWrapper(normalized, normalizedHash); + } +} \ No newline at end of file diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java index 3094c3166..e4898a6be 100644 --- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java +++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java @@ -64,7 +64,7 @@ import me.shedaniel.rei.impl.client.search.method.unihan.*; import me.shedaniel.rei.impl.common.entry.type.EntryRegistryImpl; import me.shedaniel.rei.impl.common.entry.type.EntryRegistryListener; -import me.shedaniel.rei.impl.common.util.HashedEntryStackWrapper; +import me.shedaniel.rei.impl.common.util.HNEntryStackWrapper; import me.shedaniel.rei.plugin.autocrafting.DefaultCategoryHandler; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -119,7 +119,7 @@ public Tooltip getTooltip(TooltipContext context) { ((EntryRegistryImpl) registry).listeners.add(new EntryRegistryListener() { @Override - public void onReFilter(List stacks) { + public void onReFilter(List stacks) { filteredStacksVisibilityHandler.reset(); } });