diff options
| author | shedaniel <daniel@shedaniel.me> | 2020-07-13 22:08:26 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2020-07-13 22:08:26 +0800 |
| commit | f2d6d8525aa74329c6491f57afad6570aec25791 (patch) | |
| tree | 9828feba6b3d7fedc27ecf2573a5a4afbcda5e08 /src/main/java | |
| parent | 627b2524ee1111a020a38928818858cd8f1bd804 (diff) | |
| download | RoughlyEnoughItems-f2d6d8525aa74329c6491f57afad6570aec25791.tar.gz RoughlyEnoughItems-f2d6d8525aa74329c6491f57afad6570aec25791.tar.bz2 RoughlyEnoughItems-f2d6d8525aa74329c6491f57afad6570aec25791.zip | |
Performance Improvements
Signed-off-by: shedaniel <daniel@shedaniel.me>
Diffstat (limited to 'src/main/java')
22 files changed, 272 insertions, 211 deletions
diff --git a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java index 1ac85319f..950b6f331 100644 --- a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java +++ b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java @@ -242,12 +242,14 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { field.setAccessible(true); Logger logger = (Logger) field.get(instance); if (logger.getName().toLowerCase(Locale.ROOT).contains("subsystem")) { - if (!new File(instance.getConfigDirectory(), "roughlyenoughitems/.ignoresubsystem").exists()) { + File reiConfigFolder = new File(instance.getConfigDirectory(), "roughlyenoughitems"); + File ignoreFile = new File(reiConfigFolder, ".ignoresubsystem"); + if (!ignoreFile.exists()) { RoughlyEnoughItemsState.warn("Subsystem is detected (probably though Aristois), please contact support from them if anything happens."); RoughlyEnoughItemsState.onContinue(() -> { try { - new File(instance.getConfigDirectory(), "roughlyenoughitems").mkdirs(); - new File(instance.getConfigDirectory(), "roughlyenoughitems/.ignoresubsystem").createNewFile(); + reiConfigFolder.mkdirs(); + ignoreFile.createNewFile(); } catch (IOException e) { e.printStackTrace(); } diff --git a/src/main/java/me/shedaniel/rei/api/ConfigManager.java b/src/main/java/me/shedaniel/rei/api/ConfigManager.java index f85d528e5..358ef22af 100644 --- a/src/main/java/me/shedaniel/rei/api/ConfigManager.java +++ b/src/main/java/me/shedaniel/rei/api/ConfigManager.java @@ -28,6 +28,7 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.Screen; +import org.jetbrains.annotations.NotNull; @Environment(EnvType.CLIENT) public interface ConfigManager { @@ -35,6 +36,7 @@ public interface ConfigManager { /** * @return the api instance of {@link me.shedaniel.rei.impl.ConfigManagerImpl} */ + @NotNull static ConfigManager getInstance() { return RoughlyEnoughItemsCore.getConfigManager(); } diff --git a/src/main/java/me/shedaniel/rei/api/DisplayHelper.java b/src/main/java/me/shedaniel/rei/api/DisplayHelper.java index fbf753a98..fe5c77950 100644 --- a/src/main/java/me/shedaniel/rei/api/DisplayHelper.java +++ b/src/main/java/me/shedaniel/rei/api/DisplayHelper.java @@ -31,6 +31,7 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.util.ActionResult; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.function.Supplier; @@ -43,6 +44,7 @@ public interface DisplayHelper { /** * @return the api instance of {@link me.shedaniel.rei.impl.DisplayHelperImpl} */ + @NotNull static DisplayHelper getInstance() { return RoughlyEnoughItemsCore.getDisplayHelper(); } diff --git a/src/main/java/me/shedaniel/rei/api/EntryRegistry.java b/src/main/java/me/shedaniel/rei/api/EntryRegistry.java index 56c9aac19..723f468bf 100644 --- a/src/main/java/me/shedaniel/rei/api/EntryRegistry.java +++ b/src/main/java/me/shedaniel/rei/api/EntryRegistry.java @@ -30,10 +30,15 @@ import net.fabricmc.api.Environment; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; @Environment(EnvType.CLIENT) public interface EntryRegistry { @@ -41,6 +46,7 @@ public interface EntryRegistry { /** * @return the api instance of {@link me.shedaniel.rei.impl.EntryRegistryImpl} */ + @NotNull static EntryRegistry getInstance() { return RoughlyEnoughItemsCore.getEntryRegistry(); } @@ -50,11 +56,21 @@ public interface EntryRegistry { * * @return a stacks list */ - List<EntryStack> getStacksList(); + @Deprecated + @ApiStatus.ScheduledForRemoval + @NotNull + default List<EntryStack> getStacksList() { + return getEntryStacks().collect(Collectors.toList()); + } + @NotNull + Stream<EntryStack> getEntryStacks(); + + @NotNull List<EntryStack> getPreFilteredList(); - List<ItemStack> appendStacksForItem(Item item); + @NotNull + List<ItemStack> appendStacksForItem(@NotNull Item item); /** * Gets all possible stacks from an item @@ -62,9 +78,10 @@ public interface EntryRegistry { * @param item the item to find * @return the array of possible stacks */ - ItemStack[] getAllStacksFromItem(Item item); + @NotNull + ItemStack[] getAllStacksFromItem(@NotNull Item item); - default void registerEntry(EntryStack stack) { + default void registerEntry(@NotNull EntryStack stack) { registerEntryAfter(null, stack); } @@ -74,8 +91,8 @@ public interface EntryRegistry { * @param afterEntry the stack to put after * @param stack the stack to register */ - default void registerEntryAfter(EntryStack afterEntry, EntryStack stack) { - registerEntryAfter(afterEntry, stack, true); + default void registerEntryAfter(@Nullable EntryStack afterEntry, @NotNull EntryStack stack) { + registerEntriesAfter(afterEntry, Collections.singletonList(stack)); } /** @@ -87,11 +104,16 @@ public interface EntryRegistry { * @see #queueRegisterEntryAfter(EntryStack, Collection) for a faster method */ @Deprecated - @ApiStatus.Internal - void registerEntryAfter(EntryStack afterEntry, EntryStack stack, boolean checkAlreadyContains); - + @ApiStatus.ScheduledForRemoval + default void registerEntryAfter(@Nullable EntryStack afterEntry, @NotNull EntryStack stack, boolean checkAlreadyContains) { + registerEntryAfter(afterEntry, stack); + } - void queueRegisterEntryAfter(EntryStack afterEntry, Collection<? extends EntryStack> stacks); + @Deprecated + @ApiStatus.ScheduledForRemoval + default void queueRegisterEntryAfter(@Nullable EntryStack afterEntry, @NotNull Collection<@NotNull ? extends EntryStack> stacks) { + registerEntriesAfter(afterEntry, stacks); + } /** * Registers multiple stacks to the item list @@ -99,7 +121,7 @@ public interface EntryRegistry { * @param afterStack the stack to put after * @param stacks the stacks to register */ - default void registerEntriesAfter(EntryStack afterStack, EntryStack... stacks) { + default void registerEntriesAfter(@Nullable EntryStack afterStack, @NotNull EntryStack... stacks) { registerEntriesAfter(afterStack, Arrays.asList(stacks)); } @@ -109,14 +131,14 @@ public interface EntryRegistry { * @param afterStack the stack to put after * @param stacks the stacks to register */ - void registerEntriesAfter(EntryStack afterStack, Collection<? extends EntryStack> stacks); + void registerEntriesAfter(@Nullable EntryStack afterStack, @NotNull Collection<@NotNull ? extends EntryStack> stacks); /** * Registers multiple stacks to the item list * * @param stacks the stacks to register */ - default void registerEntries(EntryStack... stacks) { + default void registerEntries(@NotNull EntryStack... stacks) { registerEntriesAfter(null, stacks); } diff --git a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java index fc6724634..26f17e81f 100644 --- a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java +++ b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java @@ -32,6 +32,7 @@ import net.minecraft.recipe.Recipe; import net.minecraft.recipe.RecipeManager; import net.minecraft.util.Identifier; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.Map; @@ -45,6 +46,7 @@ public interface RecipeHelper { /** * @return the api instance of {@link me.shedaniel.rei.impl.RecipeHelperImpl} */ + @NotNull static RecipeHelper getInstance() { return RoughlyEnoughItemsCore.getRecipeHelper(); } diff --git a/src/main/java/me/shedaniel/rei/gui/ConfigReloadingScreen.java b/src/main/java/me/shedaniel/rei/gui/ConfigReloadingScreen.java index b9e557d21..12d1fa039 100644 --- a/src/main/java/me/shedaniel/rei/gui/ConfigReloadingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/ConfigReloadingScreen.java @@ -68,9 +68,4 @@ public class ConfigReloadingScreen extends Screen { this.drawCenteredString(matrices, this.textRenderer, string_3, this.width / 2, this.height / 2 - 41, 8421504); super.render(matrices, int_1, int_2, float_1); } - - @Override - public boolean isPauseScreen() { - return false; - } } diff --git a/src/main/java/me/shedaniel/rei/gui/config/entry/FilteringEntry.java b/src/main/java/me/shedaniel/rei/gui/config/entry/FilteringEntry.java index 1109e6b19..f55269f0b 100644 --- a/src/main/java/me/shedaniel/rei/gui/config/entry/FilteringEntry.java +++ b/src/main/java/me/shedaniel/rei/gui/config/entry/FilteringEntry.java @@ -38,8 +38,7 @@ import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.TranslatableText; import org.jetbrains.annotations.ApiStatus; -import java.util.List; -import java.util.Optional; +import java.util.*; import java.util.function.Consumer; @ApiStatus.Internal @@ -48,7 +47,7 @@ public class FilteringEntry extends AbstractConfigListEntry<List<EntryStack>> { Consumer<List<EntryStack>> saveConsumer; Consumer<List<FilteringRule<?>>> rulesSaveConsumer; List<EntryStack> defaultValue; - List<EntryStack> configFiltered; + Set<EntryStack> configFiltered; List<FilteringRule<?>> rules; boolean edited = false; final FilteringScreen filteringScreen = new FilteringScreen(this); @@ -62,7 +61,8 @@ public class FilteringEntry extends AbstractConfigListEntry<List<EntryStack>> { public FilteringEntry(int width, List<EntryStack> configFiltered, List<FilteringRule<?>> rules, List<EntryStack> defaultValue, Consumer<List<EntryStack>> saveConsumer, Consumer<List<FilteringRule<?>>> rulesSaveConsumer) { super(NarratorManager.EMPTY, false); this.width = width; - this.configFiltered = configFiltered; + this.configFiltered = new TreeSet<>(Comparator.comparing(EntryStack::hashIgnoreAmount)); + this.configFiltered.addAll(configFiltered); this.rules = Lists.newArrayList(rules); this.defaultValue = defaultValue; this.saveConsumer = saveConsumer; @@ -71,7 +71,7 @@ public class FilteringEntry extends AbstractConfigListEntry<List<EntryStack>> { @Override public List<EntryStack> getValue() { - return configFiltered; + return Lists.newArrayList(configFiltered); } @Override diff --git a/src/main/java/me/shedaniel/rei/gui/config/entry/FilteringScreen.java b/src/main/java/me/shedaniel/rei/gui/config/entry/FilteringScreen.java index 2b9c84985..cbc70982b 100644 --- a/src/main/java/me/shedaniel/rei/gui/config/entry/FilteringScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/config/entry/FilteringScreen.java @@ -42,7 +42,6 @@ import me.shedaniel.rei.gui.OverlaySearchField; import me.shedaniel.rei.gui.widget.EntryWidget; import me.shedaniel.rei.impl.ScreenHelper; import me.shedaniel.rei.impl.SearchArgument; -import me.shedaniel.rei.utils.CollectionUtils; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.Element; import net.minecraft.client.gui.screen.Screen; @@ -495,7 +494,7 @@ public class FilteringScreen extends Screen { public boolean isFiltered() { if (dirty) { - filtered = CollectionUtils.findFirstOrNullEqualsEntryIgnoreAmount(filteringEntry.configFiltered, getCurrentEntry()) != null; + filtered = filteringEntry.configFiltered.contains(getCurrentEntry()); dirty = false; } return filtered; diff --git a/src/main/java/me/shedaniel/rei/gui/modules/Menu.java b/src/main/java/me/shedaniel/rei/gui/modules/Menu.java index 16bc8e218..b33c2c3ea 100644 --- a/src/main/java/me/shedaniel/rei/gui/modules/Menu.java +++ b/src/main/java/me/shedaniel/rei/gui/modules/Menu.java @@ -40,19 +40,18 @@ import me.shedaniel.rei.gui.modules.entries.EntryStackSubsetsMenuEntry; import me.shedaniel.rei.gui.modules.entries.SubSubsetsMenuEntry; import me.shedaniel.rei.gui.widget.LateRenderable; import me.shedaniel.rei.gui.widget.WidgetWithBounds; -import me.shedaniel.rei.impl.EntryRegistryImpl; import me.shedaniel.rei.utils.CollectionUtils; import net.minecraft.client.resource.language.I18n; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; -import net.minecraft.util.collection.DefaultedList; import net.minecraft.util.registry.Registry; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import java.util.*; +import java.util.stream.Collectors; @ApiStatus.Experimental @ApiStatus.Internal @@ -86,7 +85,8 @@ public class Menu extends WidgetWithBounds implements LateRenderable { } public static Menu createSubsetsMenuFromRegistry(Point menuStartPoint) { - List<EntryStack> stacks = EntryRegistry.getInstance().getStacksList(); + EntryRegistry instance = EntryRegistry.getInstance(); + List<EntryStack> stacks = instance.getEntryStacks().collect(Collectors.toList()); Map<String, Object> entries = Maps.newHashMap(); { // All Entries group @@ -102,12 +102,9 @@ public class Menu extends WidgetWithBounds implements LateRenderable { ItemGroup group = item.getGroup(); if (group == null) continue; - DefaultedList<ItemStack> list; + List<ItemStack> list; try { - list = new EntryRegistryImpl.DefaultedLinkedList<>(Lists.newLinkedList(), null); - item.appendStacks(group, list); - if (list.isEmpty()) - list.add(item.getStackForRender()); + list = instance.appendStacksForItem(item); Map<String, Object> groupMenu = getOrCreateSubEntryInMap(itemGroups, "_item_group_" + group.getId()); for (ItemStack stack : list) { putEntryInMap(groupMenu, EntryStack.create(stack)); diff --git a/src/main/java/me/shedaniel/rei/gui/modules/entries/EntryStackSubsetsMenuEntry.java b/src/main/java/me/shedaniel/rei/gui/modules/entries/EntryStackSubsetsMenuEntry.java index 4586ebc91..9b20b376d 100644 --- a/src/main/java/me/shedaniel/rei/gui/modules/entries/EntryStackSubsetsMenuEntry.java +++ b/src/main/java/me/shedaniel/rei/gui/modules/entries/EntryStackSubsetsMenuEntry.java @@ -39,8 +39,7 @@ import net.minecraft.client.util.math.MatrixStack; import net.minecraft.sound.SoundEvents; import org.jetbrains.annotations.ApiStatus; -import java.util.Collections; -import java.util.List; +import java.util.*; @ApiStatus.Experimental @ApiStatus.Internal @@ -131,8 +130,8 @@ public class EntryStackSubsetsMenuEntry extends MenuEntry { } public boolean isFiltered() { - List<EntryStack> filteredStacks = ConfigObject.getInstance().getFilteredStacks(); if (isFiltered == null) { + List<EntryStack> filteredStacks = ConfigObject.getInstance().getFilteredStacks(); isFiltered = CollectionUtils.findFirstOrNullEqualsEntryIgnoreAmount(filteredStacks, stack) != null; } return isFiltered; diff --git a/src/main/java/me/shedaniel/rei/gui/widget/EntryListWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/EntryListWidget.java index b079c0eb1..481c24adb 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/EntryListWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/EntryListWidget.java @@ -56,10 +56,7 @@ import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.concurrent.*; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -494,7 +491,9 @@ public class EntryListWidget extends WidgetWithBounds { this.lastSearchArguments = SearchArgument.processSearchTerm(searchTerm); List<EntryStack> list = Lists.newArrayList(); boolean checkCraftable = ConfigManager.getInstance().isCraftableOnlyEnabled() && !ScreenHelper.inventoryStacks.isEmpty(); - List<EntryStack> workingItems = checkCraftable ? RecipeHelper.getInstance().findCraftableEntriesByItems(CollectionUtils.map(ScreenHelper.inventoryStacks, EntryStack::create)) : null; + Set<EntryStack> workingItems = checkCraftable ? new TreeSet<>(Comparator.comparing(EntryStack::hashIgnoreAmount)) : null; + if (checkCraftable) + workingItems.addAll(RecipeHelper.getInstance().findCraftableEntriesByItems(CollectionUtils.map(ScreenHelper.inventoryStacks, EntryStack::create))); List<EntryStack> stacks = EntryRegistry.getInstance().getPreFilteredList(); if (stacks instanceof CopyOnWriteArrayList && !stacks.isEmpty()) { if (ConfigObject.getInstance().shouldAsyncSearch()) { @@ -508,7 +507,7 @@ public class EntryListWidget extends WidgetWithBounds { for (; start[0] < end; start[0]++) { EntryStack stack = stacks.get(start[0]); if (canLastSearchTermsBeAppliedTo(stack)) { - if (workingItems != null && CollectionUtils.findFirstOrNullEqualsEntryIgnoreAmount(workingItems, stack) == null) + if (workingItems != null && workingItems.contains(stack)) continue; filtered.add(stack.copy().setting(EntryStack.Settings.RENDER_COUNTS, EntryStack.Settings.FALSE).setting(EntryStack.Settings.Item.RENDER_ENCHANTMENT_GLINT, RENDER_ENCHANTMENT_GLINT)); } @@ -529,7 +528,7 @@ public class EntryListWidget extends WidgetWithBounds { } else { for (EntryStack stack : stacks) { if (canLastSearchTermsBeAppliedTo(stack)) { - if (workingItems != null && CollectionUtils.findFirstOrNullEqualsEntryIgnoreAmount(workingItems, stack) == null) + if (workingItems != null && workingItems.contains(stack)) continue; list.add(stack.copy().setting(EntryStack.Settings.RENDER_COUNTS, EntryStack.Settings.FALSE).setting(EntryStack.Settings.Item.RENDER_ENCHANTMENT_GLINT, RENDER_ENCHANTMENT_GLINT)); } diff --git a/src/main/java/me/shedaniel/rei/gui/widget/FavoritesListWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/FavoritesListWidget.java index d3b66c117..16b5bb917 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/FavoritesListWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/FavoritesListWidget.java @@ -47,8 +47,7 @@ import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Collections; -import java.util.List; +import java.util.*; import static me.shedaniel.rei.gui.widget.EntryListWidget.*; @@ -188,10 +187,12 @@ public class FavoritesListWidget extends WidgetWithBounds { if (ConfigObject.getInstance().doSearchFavorites()) { List<EntryStack> list = Lists.newArrayList(); boolean checkCraftable = ConfigManager.getInstance().isCraftableOnlyEnabled() && !ScreenHelper.inventoryStacks.isEmpty(); - List<EntryStack> workingItems = checkCraftable ? RecipeHelper.getInstance().findCraftableEntriesByItems(CollectionUtils.map(ScreenHelper.inventoryStacks, EntryStack::create)) : null; + Set<EntryStack> workingItems = checkCraftable ? new TreeSet<>(Comparator.comparing(EntryStack::hashIgnoreAmount)) : null; + if (checkCraftable) + workingItems.addAll(RecipeHelper.getInstance().findCraftableEntriesByItems(CollectionUtils.map(ScreenHelper.inventoryStacks, EntryStack::create))); for (EntryStack stack : ConfigObject.getInstance().getFavorites()) { if (listWidget.canLastSearchTermsBeAppliedTo(stack)) { - if (checkCraftable && CollectionUtils.findFirstOrNullEqualsEntryIgnoreAmount(workingItems, stack) == null) + if (checkCraftable && workingItems.contains(stack)) continue; list.add(stack.copy().setting(EntryStack.Settings.RENDER_COUNTS, EntryStack.Settings.FALSE).setting(EntryStack.Settings.Item.RENDER_ENCHANTMENT_GLINT, RENDER_ENCHANTMENT_GLINT)); } @@ -207,9 +208,11 @@ public class FavoritesListWidget extends WidgetWithBounds { } else { List<EntryStack> list = Lists.newArrayList(); boolean checkCraftable = ConfigManager.getInstance().isCraftableOnlyEnabled() && !ScreenHelper.inventoryStacks.isEmpty(); - List<EntryStack> workingItems = checkCraftable ? RecipeHelper.getInstance().findCraftableEntriesByItems(CollectionUtils.map(ScreenHelper.inventoryStacks, EntryStack::create)) : null; + Set<EntryStack> workingItems = checkCraftable ? new TreeSet<>(Comparator.comparing(EntryStack::hashIgnoreAmount)) : null; + if (checkCraftable) + workingItems.addAll(RecipeHelper.getInstance().findCraftableEntriesByItems(CollectionUtils.map(ScreenHelper.inventoryStacks, EntryStack::create))); for (EntryStack stack : ConfigObject.getInstance().getFavorites()) { - if (checkCraftable && CollectionUtils.findFirstOrNullEqualsEntryIgnoreAmount(workingItems, stack) == null) + if (checkCraftable && workingItems.contains(stack)) continue; list.add(stack.copy().setting(EntryStack.Settings.RENDER_COUNTS, EntryStack.Settings.FALSE).setting(EntryStack.Settings.Item.RENDER_ENCHANTMENT_GLINT, RENDER_ENCHANTMENT_GLINT)); } diff --git a/src/main/java/me/shedaniel/rei/impl/AmountIgnoredEntryStackWrapper.java b/src/main/java/me/shedaniel/rei/impl/AmountIgnoredEntryStackWrapper.java new file mode 100644 index 000000000..42526da97 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/impl/AmountIgnoredEntryStackWrapper.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.impl; + +import me.shedaniel.rei.api.EntryStack; +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 = -1390123012; + + public AmountIgnoredEntryStackWrapper(EntryStack stack) { + this.stack = Objects.requireNonNull(stack); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + AmountIgnoredEntryStackWrapper that = (AmountIgnoredEntryStackWrapper) o; + return hashCode() == that.hashCode(); + } + + @Override + public int hashCode() { + if (hash == -1390123012) { + hash = stack.hashIgnoreAmount(); + } + return hash; + } + + public boolean isEmpty() { + return stack.isEmpty(); + } + + public EntryStack unwrap() { + return stack; + } +}
\ No newline at end of file diff --git a/src/main/java/me/shedaniel/rei/impl/EntryRegistryImpl.java b/src/main/java/me/shedaniel/rei/impl/EntryRegistryImpl.java index b3274ae94..a4fccb16a 100644 --- a/src/main/java/me/shedaniel/rei/impl/EntryRegistryImpl.java +++ b/src/main/java/me/shedaniel/rei/impl/EntryRegistryImpl.java @@ -24,26 +24,25 @@ package me.shedaniel.rei.impl; import com.google.common.collect.Lists; -import com.google.common.collect.Queues; import com.google.common.collect.Sets; import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.api.ConfigObject; import me.shedaniel.rei.api.EntryRegistry; import me.shedaniel.rei.api.EntryStack; -import me.shedaniel.rei.api.RecipeHelper; import me.shedaniel.rei.impl.filtering.FilteringContextImpl; import me.shedaniel.rei.impl.filtering.FilteringRule; +import me.shedaniel.rei.utils.CollectionUtils; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.util.Pair; import net.minecraft.util.collection.DefaultedList; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.*; -import java.util.stream.Collectors; +import java.util.stream.Stream; @ApiStatus.Internal @Environment(EnvType.CLIENT) @@ -51,9 +50,8 @@ public class EntryRegistryImpl implements EntryRegistry { private final List<EntryStack> preFilteredList = Lists.newCopyOnWriteArrayList(); private final List<EntryStack> entries = Lists.newCopyOnWriteArrayList(); - private final Queue<Pair<EntryStack, Collection<? extends EntryStack>>> queueRegisterEntryStackAfter = Queues.newConcurrentLinkedQueue(); - private List<EntryStack> reloadList; - private boolean doingDistinct = false; |
