From 0dd97db996b084fc8e0533e093e8116786308747 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sat, 20 Nov 2021 20:51:17 +0800 Subject: Fix merge conflicts --- .../client/FilteredStacksVisibilityHandler.java | 116 --------------------- .../runtime/FilteredStacksVisibilityHandler.java | 116 +++++++++++++++++++++ 2 files changed, 116 insertions(+), 116 deletions(-) delete mode 100644 runtime/src/main/java/me/shedaniel/rei/plugin/client/FilteredStacksVisibilityHandler.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/FilteredStacksVisibilityHandler.java (limited to 'runtime/src/main/java') diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/FilteredStacksVisibilityHandler.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/FilteredStacksVisibilityHandler.java deleted file mode 100644 index 50bc8f277..000000000 --- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/FilteredStacksVisibilityHandler.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020, 2021 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.plugin.client; - -import com.google.common.base.Stopwatch; -import it.unimi.dsi.fastutil.objects.Reference2BooleanMap; -import it.unimi.dsi.fastutil.objects.Reference2BooleanMaps; -import it.unimi.dsi.fastutil.objects.Reference2BooleanOpenHashMap; -import me.shedaniel.architectury.event.EventResult; -import me.shedaniel.rei.RoughlyEnoughItemsCore; -import me.shedaniel.rei.api.client.config.ConfigObject; -import me.shedaniel.rei.api.client.registry.display.DisplayCategory; -import me.shedaniel.rei.api.client.registry.display.DisplayRegistry; -import me.shedaniel.rei.api.client.registry.display.visibility.DisplayVisibilityPredicate; -import me.shedaniel.rei.api.common.display.Display; -import me.shedaniel.rei.api.common.entry.EntryIngredient; -import me.shedaniel.rei.impl.client.config.ConfigObjectImpl; -import me.shedaniel.rei.impl.client.entry.filtering.*; - -import java.util.List; -import java.util.function.Predicate; - -public class FilteredStacksVisibilityHandler implements DisplayVisibilityPredicate { - private boolean checkHiddenStacks; - private Reference2BooleanMap visible = Reference2BooleanMaps.synchronize(new Reference2BooleanOpenHashMap<>()); - private List> filteringRules; - private FilteringCacheImpl cache; - private final Predicate displayPredicate = this::checkHiddenStacks; - - @Override - public EventResult handleDisplay(DisplayCategory category, Display display) { - if (checkHiddenStacks) { - return visible.computeBooleanIfAbsent(display, displayPredicate) ? EventResult.pass() : EventResult.interruptFalse(); - } - - return EventResult.pass(); - } - - public void reset() { - checkHiddenStacks = ConfigObject.getInstance().shouldFilterDisplays(); - visible = Reference2BooleanMaps.synchronize(new Reference2BooleanOpenHashMap<>()); - - if (checkHiddenStacks) { - filteringRules = ((ConfigObjectImpl) ConfigObject.getInstance()).getFilteringRules(); - cache = new FilteringCacheImpl(); - for (int i = filteringRules.size() - 1; i >= 0; i--) { - FilteringRule rule = filteringRules.get(i); - cache.setCache(rule, rule.prepareCache(false)); - } - - cacheExisting(); - } else { - filteringRules = null; - cache = null; - } - } - - public void cacheExisting() { - Stopwatch stopwatch = Stopwatch.createStarted(); - DisplayRegistry.getInstance().getAll().values().parallelStream().map(displays -> { - Reference2BooleanMap current = new Reference2BooleanOpenHashMap<>(); - for (Display display : displays) { - current.put(display, checkHiddenStacks(display)); - } - return current; - }).forEach(map -> { - visible.putAll(map); - }); - RoughlyEnoughItemsCore.LOGGER.debug("Computed existing filtered displays with %d rules in %s", filteringRules.size(), stopwatch.stop()); - } - - private boolean checkHiddenStacks(Display display) { - for (EntryIngredient ingredient : display.getInputEntries()) { - if (isEntryIngredientAllHidden(ingredient, cache, filteringRules)) { - return false; - } - } - for (EntryIngredient ingredient : display.getOutputEntries()) { - if (isEntryIngredientAllHidden(ingredient, cache, filteringRules)) { - return false; - } - } - - return true; - } - - private static boolean isEntryIngredientAllHidden(EntryIngredient ingredient, FilteringCache cache, List> rules) { - FilteringContextImpl context = new FilteringContextImpl(false, ingredient); - for (int i = rules.size() - 1; i >= 0; i--) { - FilteringRule rule = rules.get(i); - context.handleResult(rule.processFilteredStacks(context, cache, false)); - } - return context.stacks.get(FilteringContextType.SHOWN).isEmpty() && context.stacks.get(FilteringContextType.DEFAULT).isEmpty(); - } -} diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/FilteredStacksVisibilityHandler.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/FilteredStacksVisibilityHandler.java new file mode 100644 index 000000000..d39672c68 --- /dev/null +++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/FilteredStacksVisibilityHandler.java @@ -0,0 +1,116 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021 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.plugin.client.runtime; + +import com.google.common.base.Stopwatch; +import dev.architectury.event.EventResult; +import it.unimi.dsi.fastutil.objects.Reference2BooleanMap; +import it.unimi.dsi.fastutil.objects.Reference2BooleanMaps; +import it.unimi.dsi.fastutil.objects.Reference2BooleanOpenHashMap; +import me.shedaniel.rei.RoughlyEnoughItemsCore; +import me.shedaniel.rei.api.client.config.ConfigObject; +import me.shedaniel.rei.api.client.registry.display.DisplayCategory; +import me.shedaniel.rei.api.client.registry.display.DisplayRegistry; +import me.shedaniel.rei.api.client.registry.display.visibility.DisplayVisibilityPredicate; +import me.shedaniel.rei.api.common.display.Display; +import me.shedaniel.rei.api.common.entry.EntryIngredient; +import me.shedaniel.rei.impl.client.config.ConfigObjectImpl; +import me.shedaniel.rei.impl.client.entry.filtering.*; + +import java.util.List; +import java.util.function.Predicate; + +public class FilteredStacksVisibilityHandler implements DisplayVisibilityPredicate { + private boolean checkHiddenStacks; + private Reference2BooleanMap visible = Reference2BooleanMaps.synchronize(new Reference2BooleanOpenHashMap<>()); + private List> filteringRules; + private FilteringCacheImpl cache; + private final Predicate displayPredicate = this::checkHiddenStacks; + + @Override + public EventResult handleDisplay(DisplayCategory category, Display display) { + if (checkHiddenStacks) { + return visible.computeBooleanIfAbsent(display, displayPredicate) ? EventResult.pass() : EventResult.interruptFalse(); + } + + return EventResult.pass(); + } + + public void reset() { + checkHiddenStacks = ConfigObject.getInstance().shouldFilterDisplays(); + visible = Reference2BooleanMaps.synchronize(new Reference2BooleanOpenHashMap<>()); + + if (checkHiddenStacks) { + filteringRules = ((ConfigObjectImpl) ConfigObject.getInstance()).getFilteringRules(); + cache = new FilteringCacheImpl(); + for (int i = filteringRules.size() - 1; i >= 0; i--) { + FilteringRule rule = filteringRules.get(i); + cache.setCache(rule, rule.prepareCache(false)); + } + + cacheExisting(); + } else { + filteringRules = null; + cache = null; + } + } + + public void cacheExisting() { + Stopwatch stopwatch = Stopwatch.createStarted(); + DisplayRegistry.getInstance().getAll().values().parallelStream().map(displays -> { + Reference2BooleanMap current = new Reference2BooleanOpenHashMap<>(); + for (Display display : displays) { + current.put(display, checkHiddenStacks(display)); + } + return current; + }).forEach(map -> { + visible.putAll(map); + }); + RoughlyEnoughItemsCore.LOGGER.debug("Computed existing filtered displays with %d rules in %s", filteringRules.size(), stopwatch.stop()); + } + + private boolean checkHiddenStacks(Display display) { + for (EntryIngredient ingredient : display.getInputEntries()) { + if (isEntryIngredientAllHidden(ingredient, cache, filteringRules)) { + return false; + } + } + for (EntryIngredient ingredient : display.getOutputEntries()) { + if (isEntryIngredientAllHidden(ingredient, cache, filteringRules)) { + return false; + } + } + + return true; + } + + private static boolean isEntryIngredientAllHidden(EntryIngredient ingredient, FilteringCache cache, List> rules) { + FilteringContextImpl context = new FilteringContextImpl(false, ingredient); + for (int i = rules.size() - 1; i >= 0; i--) { + FilteringRule rule = rules.get(i); + context.handleResult(rule.processFilteredStacks(context, cache, false)); + } + return context.stacks.get(FilteringContextType.SHOWN).isEmpty() && context.stacks.get(FilteringContextType.DEFAULT).isEmpty(); + } +} -- cgit