From 7fafa7d9bbb2483313d86f946653f3ad64b2db18 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sat, 9 Apr 2022 02:41:21 +0800 Subject: Support for JEI 9.5, Close #821, Fix #807 --- .../me/shedaniel/rei/RoughlyEnoughItemsCore.java | 8 +- .../rei/impl/client/ClientHelperImpl.java | 86 +++++++++++++++- .../shedaniel/rei/impl/client/view/ViewsImpl.java | 32 ++++-- .../rei/impl/common/logging/FileLogger.java | 3 +- .../rei/impl/common/logging/Log4JLogger.java | 3 +- .../shedaniel/rei/impl/common/logging/Logger.java | 110 --------------------- .../rei/impl/common/logging/MultiLogger.java | 13 +-- .../impl/common/logging/TransformingLogger.java | 54 ++++++++++ .../shedaniel/rei/plugin/test/REITestPlugin.java | 4 +- 9 files changed, 177 insertions(+), 136 deletions(-) delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/common/logging/Logger.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/common/logging/TransformingLogger.java (limited to 'runtime/src/main/java') diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java index 5681e6598..d1be18c87 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java @@ -41,6 +41,7 @@ import me.shedaniel.rei.api.common.plugins.REIServerPlugin; import me.shedaniel.rei.api.common.registry.ReloadStage; import me.shedaniel.rei.api.common.transfer.info.MenuInfoRegistry; import me.shedaniel.rei.impl.Internals; +import me.shedaniel.rei.impl.common.InternalLogger; import me.shedaniel.rei.impl.common.category.CategoryIdentifierImpl; import me.shedaniel.rei.impl.common.display.DisplaySerializerRegistryImpl; import me.shedaniel.rei.impl.common.entry.DeferringEntryTypeProviderImpl; @@ -54,8 +55,8 @@ import me.shedaniel.rei.impl.common.entry.type.EntryTypeRegistryImpl; import me.shedaniel.rei.impl.common.fluid.FluidSupportProviderImpl; import me.shedaniel.rei.impl.common.logging.FileLogger; import me.shedaniel.rei.impl.common.logging.Log4JLogger; -import me.shedaniel.rei.impl.common.logging.Logger; import me.shedaniel.rei.impl.common.logging.MultiLogger; +import me.shedaniel.rei.impl.common.logging.TransformingLogger; import me.shedaniel.rei.impl.common.logging.performance.PerformanceLogger; import me.shedaniel.rei.impl.common.logging.performance.PerformanceLoggerImpl; import me.shedaniel.rei.impl.common.plugins.PluginManagerImpl; @@ -74,10 +75,10 @@ import java.util.function.UnaryOperator; @ApiStatus.Internal public class RoughlyEnoughItemsCore { @ApiStatus.Internal - public static final Logger LOGGER = new MultiLogger(ImmutableList.of( + public static final InternalLogger LOGGER = new TransformingLogger(new MultiLogger(ImmutableList.of( new FileLogger(Platform.getGameFolder().resolve("logs/rei.log")), new Log4JLogger(LogManager.getFormatterLogger("REI")) - )); + )), message -> "[REI] " + message); public static final PerformanceLogger PERFORMANCE_LOGGER = new PerformanceLoggerImpl(); static { @@ -124,6 +125,7 @@ public class RoughlyEnoughItemsCore { ); }, new MenuInfoRegistryImpl()), "serverPluginManager"); + Internals.attachInstanceSupplier(LOGGER, "logger"); } public static void _reloadPlugins(@Nullable ReloadStage stage) { diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java index 89568931a..f3b18ba39 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java @@ -31,7 +31,6 @@ import it.unimi.dsi.fastutil.longs.LongOpenHashSet; import it.unimi.dsi.fastutil.longs.LongSet; import me.shedaniel.rei.RoughlyEnoughItemsNetwork; import me.shedaniel.rei.api.client.ClientHelper; -import me.shedaniel.rei.api.client.REIRuntime; import me.shedaniel.rei.api.client.config.ConfigManager; import me.shedaniel.rei.api.client.config.ConfigObject; import me.shedaniel.rei.api.client.gui.config.DisplayScreenType; @@ -40,7 +39,6 @@ import me.shedaniel.rei.api.client.gui.widgets.Tooltip; import me.shedaniel.rei.api.client.registry.display.DisplayCategory; import me.shedaniel.rei.api.client.view.ViewSearchBuilder; import me.shedaniel.rei.api.common.category.CategoryIdentifier; -import me.shedaniel.rei.api.common.display.Display; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes; import me.shedaniel.rei.api.common.util.EntryStacks; @@ -48,7 +46,6 @@ import me.shedaniel.rei.api.common.util.FormattingUtils; import me.shedaniel.rei.impl.ClientInternals; import me.shedaniel.rei.impl.client.gui.screen.CompositeDisplayViewingScreen; import me.shedaniel.rei.impl.client.gui.screen.DefaultDisplayViewingScreen; -import me.shedaniel.rei.impl.client.gui.screen.UncertainDisplayViewingScreen; import me.shedaniel.rei.impl.client.view.ViewsImpl; import me.shedaniel.rei.impl.display.DisplaySpec; import net.fabricmc.api.EnvType; @@ -70,6 +67,7 @@ import org.jetbrains.annotations.Nullable; import java.time.LocalDateTime; import java.util.*; import java.util.function.Supplier; +import java.util.stream.Stream; @ApiStatus.Internal @Environment(EnvType.CLIENT) @@ -302,14 +300,22 @@ public class ClientHelperImpl implements ClientHelper { } return this; } + + @Override + public Stream streamDisplays() { + return buildMapInternal().values().stream().flatMap(Collection::stream); + } } public static final class ViewSearchBuilderImpl extends AbstractViewSearchBuilder { + private final Set> filteringCategories = new HashSet<>(); private final Set> categories = new HashSet<>(); private final List> recipesFor = new ArrayList<>(); private final List> usagesFor = new ArrayList<>(); @Nullable private CategoryIdentifier preferredOpenedCategory = null; + private boolean mergeDisplays = true; + private boolean processVisibilityHandlers = true; private final Supplier, List>> map = Suppliers.memoize(() -> ViewsImpl.buildMapFor(this)); @Override @@ -363,11 +369,50 @@ public class ClientHelperImpl implements ClientHelper { return this.preferredOpenedCategory; } + @Override + public ViewSearchBuilder filterCategory(CategoryIdentifier category) { + this.filteringCategories.add(category); + return this; + } + + @Override + public ViewSearchBuilder filterCategories(Collection> categories) { + this.filteringCategories.addAll(categories); + return this; + } + + @Override + public Set> getFilteringCategories() { + return filteringCategories; + } + @Override public Map, List> buildMapInternal() { fillPreferredOpenedCategory(); return this.map.get(); } + + @Override + public boolean isMergingDisplays() { + return mergeDisplays; + } + + @Override + public ViewSearchBuilder mergingDisplays(boolean mergingDisplays) { + this.mergeDisplays = mergingDisplays; + return this; + } + + @Override + public boolean isProcessingVisibilityHandlers() { + return processVisibilityHandlers; + } + + @Override + public ViewSearchBuilder processingVisibilityHandlers(boolean processingVisibilityHandlers) { + this.processVisibilityHandlers = processingVisibilityHandlers; + return this; + } } public static final class LegacyWrapperViewSearchBuilder extends AbstractViewSearchBuilder { @@ -398,6 +443,21 @@ public class ClientHelperImpl implements ClientHelper { return Collections.emptySet(); } + @Override + public ViewSearchBuilder filterCategory(CategoryIdentifier category) { + return this; + } + + @Override + public ViewSearchBuilder filterCategories(Collection> categories) { + return this; + } + + @Override + public Set> getFilteringCategories() { + return Collections.emptySet(); + } + @Override public ViewSearchBuilder addRecipesFor(EntryStack stack) { return this; @@ -445,5 +505,25 @@ public class ClientHelperImpl implements ClientHelper { fillPreferredOpenedCategory(); return this.map; } + + @Override + public boolean isMergingDisplays() { + return true; + } + + @Override + public ViewSearchBuilder mergingDisplays(boolean mergingDisplays) { + return this; + } + + @Override + public boolean isProcessingVisibilityHandlers() { + return false; + } + + @Override + public ViewSearchBuilder processingVisibilityHandlers(boolean processingVisibilityHandlers) { + return this; + } } } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/view/ViewsImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/view/ViewsImpl.java index df371c961..4b2ce42e1 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/view/ViewsImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/view/ViewsImpl.java @@ -90,7 +90,9 @@ public class ViewsImpl implements Views { } Stopwatch stopwatch = Stopwatch.createStarted(); + boolean processingVisibilityHandlers = builder.isProcessingVisibilityHandlers(); Set> categories = builder.getCategories(); + Set> filteringCategories = builder.getFilteringCategories(); List> recipesForStacks = builder.getRecipesFor(); List> usagesForStacks = builder.getUsagesFor(); recipesForStacks = Stream.concat(recipesForStacks.stream(), recipesForStacks.stream().map(EntryStack::wildcard)) @@ -104,14 +106,15 @@ public class ViewsImpl implements Views { Map, List> result = Maps.newLinkedHashMap(); for (CategoryRegistry.CategoryConfiguration categoryConfiguration : CategoryRegistry.getInstance()) { DisplayCategory category = categoryConfiguration.getCategory(); - if (CategoryRegistry.getInstance().isCategoryInvisible(category)) continue; + if (processingVisibilityHandlers && CategoryRegistry.getInstance().isCategoryInvisible(category)) continue; CategoryIdentifier categoryId = categoryConfiguration.getCategoryIdentifier(); + if (!filteringCategories.isEmpty() && !filteringCategories.contains(categoryId)) continue; List allRecipesFromCategory = displayRegistry.get((CategoryIdentifier) categoryId); Set set = Sets.newLinkedHashSet(); if (categories.contains(categoryId)) { for (Display display : allRecipesFromCategory) { - if (displayRegistry.isDisplayVisible(display)) { + if (!processingVisibilityHandlers || displayRegistry.isDisplayVisible(display)) { set.add(display); } } @@ -121,7 +124,7 @@ public class ViewsImpl implements Views { continue; } for (Display display : allRecipesFromCategory) { - if (!displayRegistry.isDisplayVisible(display)) continue; + if (processingVisibilityHandlers && !displayRegistry.isDisplayVisible(display)) continue; if (!recipesForStacks.isEmpty()) { if (isRecipesFor(recipesForStacks, display)) { set.add(display); @@ -137,7 +140,11 @@ public class ViewsImpl implements Views { } for (EntryStack usagesFor : usagesForStacks) { if (isStackWorkStationOfCategory(categoryConfiguration, usagesFor)) { - set.addAll(CollectionUtils.filterToSet(allRecipesFromCategory, displayRegistry::isDisplayVisible)); + if (processingVisibilityHandlers) { + set.addAll(CollectionUtils.filterToSet(allRecipesFromCategory, displayRegistry::isDisplayVisible)); + } else { + set.addAll(allRecipesFromCategory); + } break; } } @@ -151,7 +158,8 @@ public class ViewsImpl implements Views { for (Map.Entry, List>> entry : displayRegistry.getCategoryDisplayGenerators().entrySet()) { CategoryIdentifier categoryId = entry.getKey(); DisplayCategory category = CategoryRegistry.getInstance().get(categoryId).getCategory(); - if (CategoryRegistry.getInstance().isCategoryInvisible(category)) continue; + if (processingVisibilityHandlers && CategoryRegistry.getInstance().isCategoryInvisible(category)) continue; + if (!filteringCategories.isEmpty() && !filteringCategories.contains(categoryId)) continue; Set set = new LinkedHashSet<>(); generatorsCount += entry.getValue().size(); @@ -165,7 +173,9 @@ public class ViewsImpl implements Views { } Consumer displayConsumer = display -> { - CollectionUtils.getOrPutEmptyList(result, CategoryRegistry.getInstance().get(display.getCategoryIdentifier()).getCategory()).add(display); + CategoryIdentifier categoryIdentifier = display.getCategoryIdentifier(); + if (!filteringCategories.isEmpty() && !filteringCategories.contains(categoryIdentifier)) return; + CollectionUtils.getOrPutEmptyList(result, CategoryRegistry.getInstance().get(categoryIdentifier).getCategory()).add(display); }; for (DynamicDisplayGenerator generator : (List>) (List>) displayRegistry.getGlobalDisplayGenerators()) { generatorsCount++; @@ -174,7 +184,7 @@ public class ViewsImpl implements Views { Map, List> resultSpeced = (Map, List>) (Map) new LinkedHashMap<>(result); // optimize displays - if (ConfigObject.getInstance().doMergeDisplayUnderOne()) { + if (builder.isMergingDisplays() && ConfigObject.getInstance().doMergeDisplayUnderOne()) { for (Map.Entry, List> entry : result.entrySet()) { DisplayMerger merger = (DisplayMerger) entry.getKey().getDisplayMerger(); @@ -293,11 +303,13 @@ public class ViewsImpl implements Views { } private static void generateLiveDisplays(DisplayRegistry displayRegistry, DynamicDisplayGenerator generator, ViewSearchBuilder builder, Consumer displayConsumer) { + boolean processingVisibilityHandlers = builder.isProcessingVisibilityHandlers(); + for (EntryStack stack : builder.getRecipesFor()) { Optional> recipeForDisplays = generator.getRecipeFor(stack); if (recipeForDisplays.isPresent()) { for (T display : recipeForDisplays.get()) { - if (displayRegistry.isDisplayVisible(display)) { + if (!processingVisibilityHandlers || displayRegistry.isDisplayVisible(display)) { displayConsumer.accept(display); } } @@ -308,7 +320,7 @@ public class ViewsImpl implements Views { Optional> usageForDisplays = generator.getUsageFor(stack); if (usageForDisplays.isPresent()) { for (T display : usageForDisplays.get()) { - if (displayRegistry.isDisplayVisible(display)) { + if (!processingVisibilityHandlers || displayRegistry.isDisplayVisible(display)) { displayConsumer.accept(display); } } @@ -318,7 +330,7 @@ public class ViewsImpl implements Views { Optional> displaysGenerated = generator.generate(builder); if (displaysGenerated.isPresent()) { for (T display : displaysGenerated.get()) { - if (displayRegistry.isDisplayVisible(display)) { + if (!processingVisibilityHandlers || displayRegistry.isDisplayVisible(display)) { displayConsumer.accept(display); } } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/logging/FileLogger.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/logging/FileLogger.java index d773113d7..b1eb4fe62 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/logging/FileLogger.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/logging/FileLogger.java @@ -23,6 +23,7 @@ package me.shedaniel.rei.impl.common.logging; +import me.shedaniel.rei.impl.common.InternalLogger; import org.apache.commons.io.output.NullOutputStream; import org.apache.logging.log4j.Level; @@ -33,7 +34,7 @@ import java.nio.file.Path; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -public class FileLogger implements Logger { +public class FileLogger implements InternalLogger { private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("HH:mm:ss"); private final Writer writer; diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/logging/Log4JLogger.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/logging/Log4JLogger.java index 087d007b6..1db77dfe7 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/logging/Log4JLogger.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/logging/Log4JLogger.java @@ -23,9 +23,10 @@ package me.shedaniel.rei.impl.common.logging; +import me.shedaniel.rei.impl.common.InternalLogger; import org.apache.logging.log4j.Level; -public class Log4JLogger implements Logger { +public class Log4JLogger implements InternalLogger { private final org.apache.logging.log4j.Logger logger; public Log4JLogger(org.apache.logging.log4j.Logger logger) { diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/logging/Logger.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/logging/Logger.java deleted file mode 100644 index f12bde464..000000000 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/logging/Logger.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020, 2021, 2022 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.common.logging; - -import org.apache.logging.log4j.Level; - -public interface Logger { - void throwException(Throwable throwable); - - void log(Level level, String message); - - void log(Level level, String message, Throwable throwable); - - default void log(Level level, String message, Object... args) { - log(level, String.format(message, args)); - } - - default void fatal(String message) { - log(Level.FATAL, message); - } - - default void fatal(String message, Throwable throwable) { - log(Level.FATAL, message, throwable); - } - - default void fatal(String message, Object... args) { - log(Level.FATAL, String.format(message, args)); - } - - default void error(String message) { - log(Level.ERROR, message); - } - - default void error(String message, Throwable throwable) { - log(Level.ERROR, message, throwable); - } - - default void error(String message, Object... args) { - log(Level.ERROR, String.format(message, args)); - } - - default void warn(String message) { - log(Level.WARN, message); - } - - default void warn(String message, Throwable throwable) { - log(Level.WARN, message, throwable); - } - - default void warn(String message, Object... args) { - log(Level.WARN, String.format(message, args)); - } - - default void info(String message) { - log(Level.INFO, message); - } - - default void info(String message, Throwable throwable) { - log(Level.INFO, message, throwable); - } - - default void info(String message, Object... args) { - log(Level.INFO, String.format(message, args)); - } - - default void debug(String message) { - log(Level.DEBUG, message); - } - - default void debug(String message, Throwable throwable) { - log(Level.DEBUG, message, throwable); - } - - default void debug(String message, Object... args) { - log(Level.DEBUG, String.format(message, args)); - } - - default void trace(String message) { - log(Level.TRACE, message); - } - - default void trace(String message, Throwable throwable) { - log(Level.TRACE, message, throwable); - } - - default void trace(String message, Object... args) { - log(Level.TRACE, String.format(message, args)); - } -} diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/logging/MultiLogger.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/logging/MultiLogger.java index e1148b013..9f3d6fbda 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/logging/MultiLogger.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/logging/MultiLogger.java @@ -23,32 +23,33 @@ package me.shedaniel.rei.impl.common.logging; +import me.shedaniel.rei.impl.common.InternalLogger; import org.apache.logging.log4j.Level; -public class MultiLogger implements Logger { - private final Iterable loggers; +public class MultiLogger implements InternalLogger { + private final Iterable loggers; - public MultiLogger(Iterable loggers) { + public MultiLogger(Iterable loggers) { this.loggers = loggers; } @Override public void throwException(Throwable throwable) { - for (Logger logger : loggers) { + for (InternalLogger logger : loggers) { logger.throwException(throwable); } } @Override public void log(Level level, String message) { - for (Logger logger : loggers) { + for (InternalLogger logger : loggers) { logger.log(level, message); } } @Override public void log(Level level, String message, Throwable throwable) { - for (Logger logger : loggers) { + for (InternalLogger logger : loggers) { logger.log(level, message, throwable); } } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/logging/TransformingLogger.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/logging/TransformingLogger.java new file mode 100644 index 000000000..ed9678c00 --- /dev/null +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/logging/TransformingLogger.java @@ -0,0 +1,54 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 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.common.logging; + +import me.shedaniel.rei.impl.common.InternalLogger; +import org.apache.logging.log4j.Level; + +import java.util.function.UnaryOperator; + +public class TransformingLogger implements InternalLogger { + private final InternalLogger logger; + private final UnaryOperator transformer; + + public TransformingLogger(InternalLogger logger, UnaryOperator transformer) { + this.logger = logger; + this.transformer = transformer; + } + + @Override + public void throwException(Throwable throwable) { + logger.throwException(throwable); + } + + @Override + public void log(Level level, String message) { + logger.log(level, transformer.apply(message)); + } + + @Override + public void log(Level level, String message, Throwable throwable) { + logger.log(level, transformer.apply(message), throwable); + } +} diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/test/REITestPlugin.java b/runtime/src/main/java/me/shedaniel/rei/plugin/test/REITestPlugin.java index 43035f012..7eed62ba2 100644 --- a/runtime/src/main/java/me/shedaniel/rei/plugin/test/REITestPlugin.java +++ b/runtime/src/main/java/me/shedaniel/rei/plugin/test/REITestPlugin.java @@ -33,6 +33,7 @@ import me.shedaniel.rei.api.common.entry.comparison.ItemComparatorRegistry; import me.shedaniel.rei.api.common.plugins.PluginManager; import me.shedaniel.rei.api.common.registry.ReloadStage; import me.shedaniel.rei.api.common.util.EntryStacks; +import me.shedaniel.rei.impl.common.InternalLogger; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; @@ -42,7 +43,6 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.GameType; -import org.apache.logging.log4j.LogManager; import org.jetbrains.annotations.TestOnly; import java.util.Random; @@ -56,7 +56,7 @@ public class REITestPlugin implements REIClientPlugin { @Override public void preStage(PluginManager manager, ReloadStage stage) { - LogManager.getLogger().error("REI Test Plugin is enabled! If you see this unintentionally, please report this!"); + InternalLogger.getInstance().error("REI Test Plugin is enabled! If you see this unintentionally, please report this!"); } @Override -- cgit From caa82617183f2665cb4bd369eab72b996b4ef1e4 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Tue, 12 Apr 2022 12:55:54 +0800 Subject: Fix quark tooltip fighting issues --- .../rei/impl/client/gui/widget/EntryWidget.java | 2 -- .../rei/impl/client/gui/widget/QueuedTooltip.java | 39 +++++++++++++++++----- .../plugin/client/entry/ItemEntryDefinition.java | 11 ------ 3 files changed, 31 insertions(+), 21 deletions(-) (limited to 'runtime/src/main/java') diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java index 3f9cfe4cc..96a19c34d 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryWidget.java @@ -362,11 +362,9 @@ public class EntryWidget extends Slot implements DraggableStackProviderWidget { RenderSystem.disableDepthTest(); RenderSystem.colorMask(true, true, true, false); Rectangle bounds = getInnerBounds(); - setZ(300); fillGradient(matrices, bounds.x, bounds.y, bounds.getMaxX(), bounds.getMaxY(), 0x80ffffff, 0x80ffffff); int darkColor = 0x111111 | ((int) (90 * darkHighlightedAlpha.value()) << 24); fillGradient(matrices, bounds.x, bounds.y, bounds.getMaxX(), bounds.getMaxY(), darkColor, darkColor); - setZ(0); RenderSystem.colorMask(true, true, true, true); RenderSystem.enableDepthTest(); } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/QueuedTooltip.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/QueuedTooltip.java index 586eae71a..5c992d197 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/QueuedTooltip.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/QueuedTooltip.java @@ -29,6 +29,7 @@ import me.shedaniel.math.Point; import me.shedaniel.math.impl.PointHelper; import me.shedaniel.rei.api.client.gui.widgets.Tooltip; import me.shedaniel.rei.api.common.entry.EntryStack; +import me.shedaniel.rei.api.common.util.CollectionUtils; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; @@ -46,17 +47,15 @@ import java.util.List; @Environment(EnvType.CLIENT) public class QueuedTooltip implements Tooltip { private Point location; - private List entries; - private List components; + private List entries; private EntryStack stack = EntryStack.empty(); - private QueuedTooltip(Point location, Collection entries) { + private QueuedTooltip(Point location, Collection entries) { this.location = location; if (this.location == null) { this.location = PointHelper.ofMouse(); } - this.entries = Lists.newArrayList(entries); - this.components = Lists.newArrayList(); + this.entries = (List) Lists.newArrayList(entries); } public static QueuedTooltip impl(Point location, Collection text) { @@ -75,12 +74,12 @@ public class QueuedTooltip implements Tooltip { @Override public List entries() { - return entries; + return (List) (List) entries; } @Override public List components() { - return components; + return CollectionUtils.filterAndMap(entries, TooltipEntryImpl::isTooltipComponent, TooltipEntryImpl::getAsTooltipComponent); } @Override @@ -97,7 +96,7 @@ public class QueuedTooltip implements Tooltip { @Override public Tooltip add(TooltipComponent component) { - components.add(component); + entries.add(new TooltipEntryImpl(component)); return this; } @@ -106,6 +105,13 @@ public class QueuedTooltip implements Tooltip { Tooltip.super.queue(); } + @Override + public Tooltip copy() { + QueuedTooltip tooltip = new QueuedTooltip(location.clone(), entries); + tooltip.withContextStack(getContextStack()); + return tooltip; + } + @Override public EntryStack getContextStack() { return stack; @@ -128,8 +134,25 @@ public class QueuedTooltip implements Tooltip { return obj instanceof Component; } + public boolean isTooltipComponent() { + return obj instanceof TooltipComponent; + } + + public boolean isClientComponent() { + return obj instanceof ClientTooltipComponent; + } + + @Override + public TooltipComponent getAsTooltipComponent() { + return (TooltipComponent) obj; + } + @Override public ClientTooltipComponent getAsComponent() { + if (isTooltipComponent()) { + return ClientTooltipComponent.create((TooltipComponent) obj); + } + return (ClientTooltipComponent) obj; } } diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java index 41c2bda04..f5efc2e4e 100644 --- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java +++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java @@ -295,17 +295,6 @@ public class ItemEntryDefinition implements EntryDefinition, EntrySer Minecraft.getInstance().getItemRenderer().render(value, ItemTransforms.TransformType.GUI, false, matrices, immediate, ITEM_LIGHT, OverlayTexture.NO_OVERLAY, model); matrices.popPose(); - - /*ItemStack value = entry.getValue(); - matrices.pushPose(); - matrices.last().pose().load(RenderSystem.getModelViewStack().last().pose()); - matrices.scale(bounds.getWidth(), (bounds.getWidth() + bounds.getHeight()) / -2f, 1.0F); - RenderSystem.modelViewMatrix = matrices.last().pose(); - PoseStack stack = new PoseStack(); - stack.translate(bounds.getCenterX() / (double) bounds.getWidth(),bounds.getCenterY() * -2.0 / (bounds.getWidth() + bounds.getHeight()),100.0F + entry.getZ()); - Minecraft.getInstance().getItemRenderer().render(value, ItemTransforms.TransformType.GUI, false, stack, immediate, - 0xf000f0, OverlayTexture.NO_OVERLAY, getModelFromStack(value)); - matrices.popPose();*/ } } -- cgit From 9e5b678a2b540ef2963f1c02239e933c3cb04eca Mon Sep 17 00:00:00 2001 From: shedaniel Date: Tue, 12 Apr 2022 17:26:43 +0800 Subject: Fix #808 --- .../main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'runtime/src/main/java') diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java index 02fbe7b05..775b29d9e 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java @@ -376,6 +376,9 @@ public class RoughlyEnoughItemsCoreClient { ClientScreenInputEvent.CHAR_TYPED_PRE.register((minecraftClient, screen, character, keyCode) -> { if (shouldReturn(screen)) return EventResult.pass(); + if (screen.getFocused() != null && screen.getFocused() instanceof EditBox || (screen.getFocused() instanceof RecipeBookComponent && ((RecipeBookComponent) screen.getFocused()).searchBox != null && ((RecipeBookComponent) screen.getFocused()).searchBox.isFocused())) + if (!REIRuntimeImpl.getSearchField().isFocused()) + return EventResult.pass(); resetFocused(screen); if (getOverlay().charTyped(character, keyCode) && resetFocused(screen)) @@ -409,7 +412,8 @@ public class RoughlyEnoughItemsCoreClient { } } if (screen.getFocused() != null && screen.getFocused() instanceof EditBox || (screen.getFocused() instanceof RecipeBookComponent && ((RecipeBookComponent) screen.getFocused()).searchBox != null && ((RecipeBookComponent) screen.getFocused()).searchBox.isFocused())) - return EventResult.pass(); + if (!REIRuntimeImpl.getSearchField().isFocused()) + return EventResult.pass(); resetFocused(screen); if (getOverlay().keyPressed(i, i1, i2) && resetFocused(screen)) -- cgit From 61fdb2dd7a63fd6584466e35819a7623581eaa41 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Tue, 12 Apr 2022 17:44:34 +0800 Subject: Fix #829 --- .../entry/filtering/rules/SearchFilteringRule.java | 27 ++++++++++++++-------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'runtime/src/main/java') diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/filtering/rules/SearchFilteringRule.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/filtering/rules/SearchFilteringRule.java index 58ad942ba..5f5969674 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/filtering/rules/SearchFilteringRule.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/filtering/rules/SearchFilteringRule.java @@ -23,6 +23,7 @@ package me.shedaniel.rei.impl.client.entry.filtering.rules; +import com.google.common.base.Suppliers; import com.google.common.collect.Lists; import me.shedaniel.rei.api.client.search.SearchFilter; import me.shedaniel.rei.api.client.search.SearchProvider; @@ -41,6 +42,7 @@ import net.minecraft.client.gui.screens.Screen; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.util.StringUtil; import java.util.Collection; import java.util.List; @@ -51,23 +53,30 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.function.BiFunction; import java.util.function.Consumer; +import java.util.function.Supplier; @Environment(EnvType.CLIENT) public class SearchFilteringRule extends AbstractFilteringRule { - private SearchFilter filter; + private String filterStr; + private Supplier filter; private boolean show; public SearchFilteringRule() { } - public SearchFilteringRule(SearchFilter filter, boolean show) { - this.filter = filter; + public SearchFilteringRule(String filter, boolean show) { + setFilter(filter); this.show = show; } + public void setFilter(String filter) { + this.filterStr = filter; + this.filter = Suppliers.memoize(() -> StringUtil.isNullOrEmpty(filter) ? SearchFilter.matchAll() : SearchProvider.getInstance().createFilter(filter)); + } + @Override public CompoundTag save(CompoundTag tag) { - tag.putString("filter", filter.getFilter()); + tag.putString("filter", filterStr); tag.putBoolean("show", show); return tag; } @@ -76,7 +85,7 @@ public class SearchFilteringRule extends AbstractFilteringRule> stacks, List>>> completableFutures) { @@ -114,7 +123,7 @@ public class SearchFilteringRule extends AbstractFilteringRule { List> output = Lists.newArrayList(); for (EntryStack stack : partitionStacks) { - if (stack != null && filter.test(stack)) { + if (stack != null && filter.get().test(stack)) { output.add(stack); } } @@ -146,7 +155,7 @@ public class SearchFilteringRule extends AbstractFilteringRule { widget.setMaxLength(9999); if (entry != null) widget.setValue(entry.getWidget().getValue()); - else widget.setValue(rule.filter.getFilter()); + else widget.setValue(rule.filterStr); })); addEmpty(entryConsumer, 10); addText(entryConsumer, new TranslatableComponent("rule.roughlyenoughitems.filtering.search.show").withStyle(ChatFormatting.GRAY)); @@ -157,7 +166,7 @@ public class SearchFilteringRule extends AbstractFilteringRule Date: Tue, 12 Apr 2022 17:45:08 +0800 Subject: Print "Refreshing cached entry list texture..." only when cache entry rendering is enabled --- .../shedaniel/rei/impl/client/gui/widget/CachedEntryListRender.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'runtime/src/main/java') diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/CachedEntryListRender.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/CachedEntryListRender.java index 65447b81b..b9037a3ac 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/CachedEntryListRender.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/CachedEntryListRender.java @@ -35,6 +35,7 @@ import it.unimi.dsi.fastutil.longs.Long2LongMap; import it.unimi.dsi.fastutil.longs.Long2LongOpenHashMap; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.RoughlyEnoughItemsCore; +import me.shedaniel.rei.api.client.config.ConfigObject; import me.shedaniel.rei.api.client.entry.renderer.EntryRenderer; import me.shedaniel.rei.api.client.registry.entry.EntryRegistry; import me.shedaniel.rei.api.common.entry.EntryStack; @@ -76,7 +77,9 @@ public class CachedEntryListRender { } public static void refresh() { - RoughlyEnoughItemsCore.LOGGER.info("Refreshing cached entry list texture..."); + if (ConfigObject.getInstance().doesCacheEntryRendering()) { + RoughlyEnoughItemsCore.LOGGER.info("Refreshing cached entry list texture..."); + } if (cachedTextureLocation != null) { Minecraft.getInstance().getTextureManager().release(cachedTextureLocation); cachedTextureLocation = null; -- cgit From dce7a6b6485b0fba42563115047df2004455d9e2 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Tue, 12 Apr 2022 18:15:33 +0800 Subject: Reposition Reload Search button --- .../rei/impl/client/config/entries/ReloadPluginsEntry.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'runtime/src/main/java') 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 fd715ede5..257751431 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 @@ -96,13 +96,13 @@ public class ReloadPluginsEntry extends AbstractConfigListEntry { Window window = Minecraft.getInstance().getWindow(); this.reloadPluginsButton.active = this.isEditable(); this.reloadPluginsButton.y = y; - this.reloadPluginsButton.setWidth(width / 2 - 6); + this.reloadPluginsButton.setWidth(width / 2 - 2); this.reloadPluginsButton.x = x + entryWidth / 2 - width / 2; this.reloadPluginsButton.render(matrices, mouseX, mouseY, delta); this.reloadSearchButton.active = this.isEditable() && !Argument.SEARCH_CACHE.isEmpty(); this.reloadSearchButton.y = y; - this.reloadSearchButton.setWidth(width / 2 - 6); - this.reloadSearchButton.x = x + entryWidth / 2 + 3; + this.reloadSearchButton.setWidth(width / 2 - 2); + this.reloadSearchButton.x = x + entryWidth / 2 + 2; this.reloadSearchButton.render(matrices, mouseX, mouseY, delta); } -- cgit From 2d787c6e3a1ce87838434c4acdf08ad1f8f5e80c Mon Sep 17 00:00:00 2001 From: shedaniel Date: Tue, 12 Apr 2022 18:23:52 +0800 Subject: Try to prevent async search cache from getting stuck --- .../rei/impl/client/search/argument/Argument.java | 114 +++++++++++---------- .../client/runtime/SearchFilterPrepareWatcher.java | 4 +- 2 files changed, 61 insertions(+), 57 deletions(-) (limited to 'runtime/src/main/java') 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 0844257ad..227d09b4d 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 @@ -242,72 +242,74 @@ public class Argument { public static void prepareFilter(Collection> stacks, Collection> argumentTypes) { if (prepareStage != null || currentStages != null) return; - prepareStart = Util.getEpochMillis(); - prepareStacks = stacks; - prepareStage = new IntIntMutablePair(0, argumentTypes.size()); - currentStages = new IntIntPair[argumentTypes.size()]; - List hashedStacks = CollectionUtils.map(stacks, HashedEntryStackWrapper::new); - int searchPartitionSize = ConfigObject.getInstance().getAsyncSearchPartitionSize(); - boolean async = ConfigObject.getInstance().shouldAsyncSearch() && stacks.size() > searchPartitionSize * 4; - List>> futures = Lists.newArrayList(); - List, CompletableFuture>>> pairs = Lists.newArrayList(); - - for (ArgumentType argumentType : argumentTypes) { - prepareStage.first(prepareStage.firstInt() + 1); - Long2ObjectMap map = getSearchCache(argumentType); - IntIntPair currentStage = currentStages[prepareStage.firstInt() - 1] = new IntIntMutablePair(0, hashedStacks.size()); + try { + prepareStart = Util.getEpochMillis(); + prepareStacks = stacks; + prepareStage = new IntIntMutablePair(0, argumentTypes.size()); + currentStages = new IntIntPair[argumentTypes.size()]; + List hashedStacks = CollectionUtils.map(stacks, HashedEntryStackWrapper::new); + int searchPartitionSize = ConfigObject.getInstance().getAsyncSearchPartitionSize(); + boolean async = ConfigObject.getInstance().shouldAsyncSearch() && stacks.size() > searchPartitionSize * 4; + List>> futures = Lists.newArrayList(); + List, CompletableFuture>>> pairs = Lists.newArrayList(); - if (async) { - for (Collection partitionStacks : CollectionUtils.partition(hashedStacks, searchPartitionSize)) { - CompletableFuture> future = CompletableFuture.supplyAsync(() -> { - Long2ObjectMap out = new Long2ObjectArrayMap<>(searchPartitionSize + 1); - for (HashedEntryStackWrapper stack : partitionStacks) { - if (map.get(stack.hashExact()) == null) { - Object data = argumentType.cacheData(stack.unwrap()); - - if (data != null) { - out.put(stack.hashExact(), data); + for (ArgumentType argumentType : argumentTypes) { + prepareStage.first(prepareStage.firstInt() + 1); + Long2ObjectMap map = getSearchCache(argumentType); + IntIntPair currentStage = currentStages[prepareStage.firstInt() - 1] = new IntIntMutablePair(0, hashedStacks.size()); + + if (async) { + for (Collection partitionStacks : CollectionUtils.partition(hashedStacks, searchPartitionSize)) { + CompletableFuture> future = CompletableFuture.supplyAsync(() -> { + Long2ObjectMap out = new Long2ObjectArrayMap<>(searchPartitionSize + 1); + for (HashedEntryStackWrapper stack : partitionStacks) { + if (map.get(stack.hashExact()) == null) { + Object data = argumentType.cacheData(stack.unwrap()); + + if (data != null) { + out.put(stack.hashExact(), data); + } } } - } - return out; - }).whenComplete((objectLong2ObjectMap, throwable) -> { - currentStage.first(currentStage.firstInt() + partitionStacks.size()); - }); - futures.add(future); - pairs.add(Pair.of(argumentType, future)); - } - } else { - for (HashedEntryStackWrapper stack : hashedStacks) { - currentStage.first(currentStage.firstInt() + 1); - - if (map.get(stack.hashExact()) == null) { - Object data = argumentType.cacheData(stack.unwrap()); + return out; + }).whenComplete((objectLong2ObjectMap, throwable) -> { + currentStage.first(currentStage.firstInt() + partitionStacks.size()); + }); + futures.add(future); + pairs.add(Pair.of(argumentType, future)); + } + } else { + for (HashedEntryStackWrapper stack : hashedStacks) { + currentStage.first(currentStage.firstInt() + 1); - if (data != null) { - map.put(stack.hashExact(), data); + if (map.get(stack.hashExact()) == null) { + Object data = argumentType.cacheData(stack.unwrap()); + + if (data != null) { + map.put(stack.hashExact(), data); + } } } } } - } - - if (async) { - try { - CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).get(10, TimeUnit.SECONDS); - } catch (InterruptedException | ExecutionException | TimeoutException e) { - e.printStackTrace(); - } - for (Pair, CompletableFuture>> pair : pairs) { - Long2ObjectMap now = pair.second().getNow(null); - if (now != null) getSearchCache(pair.left()).putAll(now); + + if (async) { + try { + CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).get(10, TimeUnit.SECONDS); + } catch (InterruptedException | ExecutionException | TimeoutException e) { + e.printStackTrace(); + } + for (Pair, CompletableFuture>> pair : pairs) { + Long2ObjectMap now = pair.second().getNow(null); + if (now != null) getSearchCache(pair.left()).putAll(now); + } } + } finally { + prepareStart = null; + prepareStacks = null; + prepareStage = null; + currentStages = null; } - - prepareStart = null; - prepareStacks = null; - prepareStage = null; - currentStages = null; } public ArgumentType getArgument() { diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/SearchFilterPrepareWatcher.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/SearchFilterPrepareWatcher.java index a6b8a641d..f5fa521da 100644 --- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/SearchFilterPrepareWatcher.java +++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/SearchFilterPrepareWatcher.java @@ -56,7 +56,9 @@ public class SearchFilterPrepareWatcher implements HintProvider { int currentStageTotal = currentStage == null ? 0 : currentStage.secondInt(); double prepareStageProgress = prepareStageTotal == 0 ? 0 : prepareStageCurrent / (double) prepareStageTotal; double currentStageProgress = currentStageTotal == 0 ? 0 : currentStageCurrent / (double) currentStageTotal; - lastProcess = prepareStageTotal == 0 ? 0 : Math.max(0, prepareStageProgress - (1 - currentStageProgress) / prepareStageTotal); + double lastProcess = prepareStageTotal == 0 ? 0 : Math.max(0, prepareStageProgress - (1 - currentStageProgress) / prepareStageTotal); + if (lastProcess < 0.05 || lastProcess > 0.95) return Collections.emptyList(); + this.lastProcess = lastProcess; return ImmutableList.of(new TranslatableComponent("text.rei.caching.search"), new TranslatableComponent("text.rei.caching.search.step", prepareStageCurrent, prepareStageTotal, Math.round(lastProcess * 100))); } -- cgit From c28b4b301c6785eefff7c7f8a51ebb37bd5270ea Mon Sep 17 00:00:00 2001 From: shedaniel Date: Tue, 12 Apr 2022 23:14:33 +0800 Subject: Add supporting me links --- .../rei/impl/client/config/ConfigManagerImpl.java | 32 ++++++-- .../impl/client/config/entries/TitleTextEntry.java | 87 ++++++++++++++++++++++ 2 files changed, 113 insertions(+), 6 deletions(-) create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/TitleTextEntry.java (limited to 'runtime/src/main/java') diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java index 485b90271..078f46344 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java @@ -352,10 +352,6 @@ public class ConfigManagerImpl implements ConfigManager { builder.setGlobalized(true); builder.setGlobalizedExpanded(false); if (Minecraft.getInstance().getConnection() != null && Minecraft.getInstance().getConnection().getRecipeManager() != null) { - builder.getOrCreateCategory(new TranslatableComponent("config.roughlyenoughitems.advanced")).getEntries().add(0, new ReloadPluginsEntry(220)); - builder.getOrCreateCategory(new TranslatableComponent("config.roughlyenoughitems.advanced")).getEntries().add(0, new PerformanceEntry(220)); - } - return builder.setAfterInitConsumer(screen -> { TextListEntry feedbackEntry = ConfigEntryBuilder.create().startTextDescription( new TranslatableComponent("text.rei.feedback", new TranslatableComponent("text.rei.feedback.link") .withStyle(style -> style @@ -366,8 +362,32 @@ public class ConfigManagerImpl implements ConfigManager { )) .withStyle(ChatFormatting.GRAY) ).build(); - feedbackEntry.setScreen((AbstractConfigScreen) screen); - ((GlobalizedClothConfigScreen) screen).listWidget.children().add(0, (AbstractConfigEntry) feedbackEntry); + builder.getOrCreateCategory(new TranslatableComponent("config.roughlyenoughitems.advanced")).getEntries().add(0, feedbackEntry); + builder.getOrCreateCategory(new TranslatableComponent("config.roughlyenoughitems.advanced")).getEntries().add(0, new ReloadPluginsEntry(220)); + builder.getOrCreateCategory(new TranslatableComponent("config.roughlyenoughitems.advanced")).getEntries().add(0, new PerformanceEntry(220)); + } + return builder.setAfterInitConsumer(screen -> { + ((GlobalizedClothConfigScreen) screen).listWidget.children().add(0, (AbstractConfigEntry) new EmptyEntry(4)); + TextListEntry supportText = ConfigEntryBuilder.create().startTextDescription( + new TranslatableComponent("text.rei.support.me.desc", + new TranslatableComponent("text.rei.support.me.patreon") + .withStyle(style -> style + .withColor(TextColor.fromRgb(0xff1fc3ff)) + .withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://patreon.com/shedaniel")) + .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ImmutableTextComponent("https://patreon.com/shedaniel"))) + ), + new TranslatableComponent("text.rei.support.me.bisect") + .withStyle(style -> style + .withColor(TextColor.fromRgb(0xff1fc3ff)) + .withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://www.bisecthosting.com/shedaniel")) + .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ImmutableTextComponent("https://www.bisecthosting.com/shedaniel"))) + ) + ) + .withStyle(ChatFormatting.GRAY) + ).build(); + supportText.setScreen((AbstractConfigScreen) screen); + ((GlobalizedClothConfigScreen) screen).listWidget.children().add(0, (AbstractConfigEntry) supportText); + ((GlobalizedClothConfigScreen) screen).listWidget.children().add(0, (AbstractConfigEntry) new TitleTextEntry(new TranslatableComponent("text.rei.support.me"))); ((GlobalizedClothConfigScreen) screen).listWidget.children().add(0, (AbstractConfigEntry) new EmptyEntry(4)); ScreenHooks.addRenderableWidget(screen, new Button(screen.width - 104, 4, 100, 20, new TranslatableComponent("text.rei.credits"), button -> { CreditsScreen creditsScreen = new CreditsScreen(screen); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/TitleTextEntry.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/TitleTextEntry.java new file mode 100644 index 000000000..3e2bdc48a --- /dev/null +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/TitleTextEntry.java @@ -0,0 +1,87 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 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.client.config.entries; + +import com.mojang.blaze3d.vertex.PoseStack; +import me.shedaniel.clothconfig2.api.AbstractConfigListEntry; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.chat.NarratorChatListener; +import net.minecraft.client.gui.components.events.GuiEventListener; +import net.minecraft.client.gui.narration.NarratableEntry; +import net.minecraft.network.chat.Component; +import net.minecraft.util.Unit; +import org.jetbrains.annotations.ApiStatus; + +import java.util.Collections; +import java.util.List; +import java.util.Optional; + +@ApiStatus.Internal +public class TitleTextEntry extends AbstractConfigListEntry { + private Component text; + + public TitleTextEntry(Component text) { + super(NarratorChatListener.NO_TITLE, false); + this.text = text; + } + + @Override + public Unit getValue() { + return Unit.INSTANCE; + } + + @Override + public Optional getDefaultValue() { + return Optional.of(Unit.INSTANCE); + } + + @Override + public void save() { + } + + @Override + public void render(PoseStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isSelected, float delta) { + sup