From 8c13c015031a0de865d2e767cd8e879754f803e2 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Fri, 5 Aug 2022 01:30:08 +0800 Subject: More work --- .../me/shedaniel/rei/REIModMenuEntryPoint.java | 33 -- .../me/shedaniel/rei/RoughlyEnoughItemsCore.java | 79 +-- .../rei/RoughlyEnoughItemsCoreClient.java | 128 +---- .../rei/impl/client/AbstractViewSearchBuilder.java | 50 -- .../rei/impl/client/ClientHelperImpl.java | 84 +-- .../shedaniel/rei/impl/client/ErrorDisplayer.java | 2 +- .../client/LegacyWrapperViewSearchBuilder.java | 145 ----- .../shedaniel/rei/impl/client/REIRuntimeImpl.java | 16 +- .../rei/impl/client/ViewSearchBuilderImpl.java | 144 ----- .../rei/impl/client/gui/ScreenOverlayImpl.java | 88 +-- .../impl/client/gui/craftable/CraftableFilter.java | 80 --- .../impl/client/gui/menu/AbstractMenuEntry.java | 77 +++ .../shedaniel/rei/impl/client/gui/menu/Menu.java | 210 +++++++ .../rei/impl/client/gui/menu/MenuAccess.java | 64 +++ .../rei/impl/client/gui/menu/MenuAccessImpl.java | 135 +++++ .../rei/impl/client/gui/menu/MenuEntry.java | 44 ++ .../client/gui/menu/entries/EmptyMenuEntry.java | 58 ++ .../gui/menu/entries/SeparatorMenuEntry.java | 53 ++ .../impl/client/gui/menu/entries/SubMenuEntry.java | 153 +++++ .../client/gui/menu/entries/TextMenuEntry.java | 70 +++ .../client/gui/menu/entries/ToggleMenuEntry.java | 144 +++++ .../impl/client/gui/modules/AbstractMenuEntry.java | 77 --- .../rei/impl/client/gui/modules/Menu.java | 210 ------- .../rei/impl/client/gui/modules/MenuAccess.java | 64 --- .../rei/impl/client/gui/modules/MenuEntry.java | 44 -- .../rei/impl/client/gui/modules/MenuHolder.java | 135 ----- .../client/gui/modules/entries/EmptyMenuEntry.java | 58 -- .../gui/modules/entries/SeparatorMenuEntry.java | 53 -- .../client/gui/modules/entries/SubMenuEntry.java | 153 ----- .../client/gui/modules/entries/TextMenuEntry.java | 70 --- .../gui/modules/entries/ToggleMenuEntry.java | 144 ----- .../client/gui/performance/PerformanceScreen.java | 199 ------- .../gui/performance/entry/PerformanceEntry.java | 93 --- .../performance/entry/PerformanceEntryImpl.java | 71 --- .../performance/entry/SubCategoryListEntry.java | 177 ------ .../gui/screen/AbstractDisplayViewingScreen.java | 8 +- .../gui/screen/CompositeDisplayViewingScreen.java | 8 +- .../gui/screen/DefaultDisplayViewingScreen.java | 9 +- .../client/gui/screen/WarningAndErrorScreen.java | 338 ----------- .../error/DynamicErrorFreeEntryListWidget.java | 640 +++++++++++++++++++++ .../gui/screen/error/WarningAndErrorScreen.java | 337 +++++++++++ .../impl/client/gui/text/TextTransformations.java | 99 ---- .../gui/toast/CopyRecipeIdentifierToast.java | 1 - .../gui/widget/AutoCraftingButtonWidget.java | 134 +++++ .../gui/widget/BatchedEntryRendererManager.java | 255 -------- .../client/gui/widget/CatchingExceptionUtils.java | 2 +- .../impl/client/gui/widget/ConfigButtonWidget.java | 6 +- .../gui/widget/CraftableFilterButtonWidget.java | 13 +- .../gui/widget/DefaultDisplayChoosePageWidget.java | 16 +- .../gui/widget/DelegateWidgetWithTranslate.java | 133 ----- .../client/gui/widget/DisplayedEntryWidget.java | 136 ++++- .../widget/DynamicErrorFreeEntryListWidget.java | 640 --------------------- .../rei/impl/client/gui/widget/EntryWidget.java | 250 +------- .../impl/client/gui/widget/InternalWidgets.java | 238 +------- .../rei/impl/client/gui/widget/MergedWidget.java | 119 ---- .../rei/impl/client/gui/widget/NoOpWidget.java | 53 -- .../rei/impl/client/gui/widget/OverflowWidget.java | 159 ----- .../impl/client/gui/widget/PaddedCenterWidget.java | 58 -- .../rei/impl/client/gui/widget/PaddedWidget.java | 51 -- .../rei/impl/client/gui/widget/QueuedTooltip.java | 163 ------ .../client/gui/widget/RendererWrappedWidget.java | 72 --- .../rei/impl/client/gui/widget/TooltipImpl.java | 163 ++++++ .../client/gui/widget/VanillaWrappedWidget.java | 82 --- .../client/gui/widget/basewidgets/ArrowWidget.java | 97 ---- .../gui/widget/basewidgets/BurningFireWidget.java | 97 ---- .../gui/widget/basewidgets/ButtonWidget.java | 335 ----------- .../gui/widget/basewidgets/DrawableWidget.java | 50 -- .../basewidgets/FillRectangleDrawableConsumer.java | 65 --- .../client/gui/widget/basewidgets/LabelWidget.java | 310 ---------- .../client/gui/widget/basewidgets/PanelWidget.java | 160 ------ .../gui/widget/basewidgets/TextFieldWidget.java | 627 -------------------- .../basewidgets/TexturedDrawableConsumer.java | 75 --- .../gui/widget/basewidgets/package-info.java | 27 - .../gui/widget/entrylist/EntryListStackEntry.java | 6 +- .../widget/entrylist/PaginatedEntryListWidget.java | 20 +- .../widget/entrylist/ScrolledEntryListWidget.java | 16 +- .../gui/widget/favorites/history/DisplayEntry.java | 2 +- .../panel/rows/FavoritesPanelEntriesRow.java | 2 +- .../gui/widget/region/EntryStacksRegionWidget.java | 8 +- .../client/gui/widget/region/RealRegionEntry.java | 2 +- .../gui/widget/region/RegionEntryWidget.java | 4 +- .../gui/widget/search/DelegateTextField.java | 153 +++++ .../gui/widget/search/OverlaySearchField.java | 112 ++-- .../search/method/unihan/BomopofoInputMethod.java | 142 ----- .../search/method/unihan/JyutpingInputMethod.java | 77 --- .../search/method/unihan/PinyinInputMethod.java | 136 ----- .../search/method/unihan/UniHanInputMethod.java | 82 --- .../client/search/method/unihan/UniHanManager.java | 123 ---- .../impl/client/transfer/MissingStacksTooltip.java | 107 ---- .../transfer/TransferHandlerRegistryImpl.java | 76 --- .../shedaniel/rei/impl/client/view/ViewsImpl.java | 516 ----------------- .../logging/performance/PerformanceLogger.java | 56 -- .../logging/performance/PerformanceLoggerImpl.java | 99 ---- .../rei/impl/common/plugins/PluginManagerImpl.java | 148 ----- .../impl/common/plugins/PluginReloaderImpl.java | 289 ---------- .../rei/impl/common/transfer/InputSlotCrafter.java | 199 ------- .../impl/common/transfer/MenuInfoRegistryImpl.java | 128 ----- .../impl/init/RoughlyEnoughItemsInitializer.java | 3 +- .../rei/impl/init/ServiceBasedPluginDetector.java | 2 +- .../autocrafting/DefaultCategoryHandler.java | 185 ------ .../plugin/client/runtime/InputMethodWatcher.java | 2 +- 101 files changed, 2801 insertions(+), 9325 deletions(-) delete mode 100644 runtime/src/main/java/me/shedaniel/rei/REIModMenuEntryPoint.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/AbstractViewSearchBuilder.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/LegacyWrapperViewSearchBuilder.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/ViewSearchBuilderImpl.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/craftable/CraftableFilter.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/menu/AbstractMenuEntry.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/menu/Menu.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/menu/MenuAccess.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/menu/MenuAccessImpl.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/menu/MenuEntry.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/menu/entries/EmptyMenuEntry.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/menu/entries/SeparatorMenuEntry.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/menu/entries/SubMenuEntry.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/menu/entries/TextMenuEntry.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/menu/entries/ToggleMenuEntry.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/modules/AbstractMenuEntry.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/modules/Menu.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/modules/MenuAccess.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/modules/MenuEntry.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/modules/MenuHolder.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/modules/entries/EmptyMenuEntry.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/modules/entries/SeparatorMenuEntry.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/modules/entries/SubMenuEntry.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/modules/entries/TextMenuEntry.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/modules/entries/ToggleMenuEntry.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/performance/PerformanceScreen.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/performance/entry/PerformanceEntry.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/performance/entry/PerformanceEntryImpl.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/performance/entry/SubCategoryListEntry.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/WarningAndErrorScreen.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/error/DynamicErrorFreeEntryListWidget.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/error/WarningAndErrorScreen.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/text/TextTransformations.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/AutoCraftingButtonWidget.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/BatchedEntryRendererManager.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/DelegateWidgetWithTranslate.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/DynamicErrorFreeEntryListWidget.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/MergedWidget.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/NoOpWidget.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/OverflowWidget.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/PaddedCenterWidget.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/PaddedWidget.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/QueuedTooltip.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/RendererWrappedWidget.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/TooltipImpl.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/VanillaWrappedWidget.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/ArrowWidget.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/BurningFireWidget.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/ButtonWidget.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/DrawableWidget.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/FillRectangleDrawableConsumer.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/LabelWidget.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/PanelWidget.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/TextFieldWidget.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/TexturedDrawableConsumer.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/package-info.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/search/DelegateTextField.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/search/method/unihan/BomopofoInputMethod.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/search/method/unihan/JyutpingInputMethod.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/search/method/unihan/PinyinInputMethod.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/search/method/unihan/UniHanInputMethod.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/search/method/unihan/UniHanManager.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/transfer/MissingStacksTooltip.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/transfer/TransferHandlerRegistryImpl.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/view/ViewsImpl.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/common/logging/performance/PerformanceLogger.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/common/logging/performance/PerformanceLoggerImpl.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginReloaderImpl.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/common/transfer/InputSlotCrafter.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/common/transfer/MenuInfoRegistryImpl.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultCategoryHandler.java (limited to 'runtime/src/main/java/me') diff --git a/runtime/src/main/java/me/shedaniel/rei/REIModMenuEntryPoint.java b/runtime/src/main/java/me/shedaniel/rei/REIModMenuEntryPoint.java deleted file mode 100644 index cba2abecc..000000000 --- a/runtime/src/main/java/me/shedaniel/rei/REIModMenuEntryPoint.java +++ /dev/null @@ -1,33 +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; - -import dev.architectury.platform.Platform; -import me.shedaniel.rei.api.client.config.ConfigManager; - -public class REIModMenuEntryPoint { - public void onInitializeClient() { - Platform.getMod("roughlyenoughitems").registerConfigurationScreen(ConfigManager.getInstance()::getConfigScreen); - } -} diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java index 3e7bba901..018cd2eeb 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java @@ -24,106 +24,29 @@ package me.shedaniel.rei; import dev.architectury.platform.Platform; -import dev.architectury.registry.ReloadListenerRegistry; import dev.architectury.utils.Env; import dev.architectury.utils.EnvExecutor; -import me.shedaniel.rei.api.common.display.DisplaySerializerRegistry; -import me.shedaniel.rei.api.common.entry.comparison.FluidComparatorRegistry; -import me.shedaniel.rei.api.common.entry.comparison.ItemComparatorRegistry; -import me.shedaniel.rei.api.common.entry.settings.EntrySettingsAdapterRegistry; -import me.shedaniel.rei.api.common.entry.type.EntryTypeRegistry; -import me.shedaniel.rei.api.common.fluid.FluidSupportProvider; -import me.shedaniel.rei.api.common.plugins.PluginManager; -import me.shedaniel.rei.api.common.plugins.REIPlugin; -import me.shedaniel.rei.api.common.registry.RecipeManagerContext; -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.logging.performance.PerformanceLogger; -import me.shedaniel.rei.impl.common.logging.performance.PerformanceLoggerImpl; +import me.shedaniel.rei.impl.common.Internals; import me.shedaniel.rei.impl.init.PluginDetector; -import net.minecraft.server.packs.PackType; -import net.minecraft.util.Unit; -import org.apache.commons.lang3.mutable.MutableLong; import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.Nullable; import java.util.List; @ApiStatus.Internal public class RoughlyEnoughItemsCore { - public static final PerformanceLogger PERFORMANCE_LOGGER = new PerformanceLoggerImpl(); public static final List PLUGIN_DETECTORS = Internals.resolveServices(PluginDetector.class); static { - attachCommonInternals(); if (Platform.getEnvironment() == Env.CLIENT) { EnvExecutor.runInEnv(Env.CLIENT, () -> RoughlyEnoughItemsCoreClient::attachClientInternals); } } - public static void attachCommonInternals() { - PluginManager.getInstance().registerReloadable(EntryTypeRegistry.class); - PluginManager.getInstance().registerReloadable(EntrySettingsAdapterRegistry.class); - PluginManager.getInstance().registerReloadable(RecipeManagerContext.class); - PluginManager.getInstance().registerReloadable(ItemComparatorRegistry.class); - PluginManager.getInstance().registerReloadable(FluidComparatorRegistry.class); - PluginManager.getInstance().registerReloadable(DisplaySerializerRegistry.class); - PluginManager.getInstance().registerReloadable(FluidSupportProvider.class); - PluginManager.getServerInstance().registerReloadable(MenuInfoRegistry.class); - Internals.attachInstanceSupplier((Runnable) () -> RoughlyEnoughItemsCore.reloadPlugins(null, null), "reloadREI"); - } - - public static void _reloadPlugins(@Nullable ReloadStage stage) { - if (stage == null) { - for (ReloadStage reloadStage : ReloadStage.values()) { - _reloadPlugins(reloadStage); - } - return; - } - try { - for (PluginManager> instance : PluginManager.getActiveInstances()) { - instance.view().pre(stage); - } - for (PluginManager> instance : PluginManager.getActiveInstances()) { - instance.startReload(stage); - } - for (PluginManager> instance : PluginManager.getActiveInstances()) { - instance.view().post(stage); - } - } catch (Throwable throwable) { - throwable.printStackTrace(); - } - } - - public static void reloadPlugins(MutableLong lastReload, @Nullable ReloadStage start) { - if (lastReload != null) { - if (lastReload.getValue() > 0 && System.currentTimeMillis() - lastReload.getValue() <= 5000) { - InternalLogger.getInstance().warn("Suppressing Reload Plugins of stage " + start); - return; - } - lastReload.setValue(System.currentTimeMillis()); - } - if (start == null) PERFORMANCE_LOGGER.clear(); - if (Platform.getEnvironment() == Env.CLIENT) { - if (RoughlyEnoughItemsCoreClient.reloadPluginsClient(start)) return; - } - _reloadPlugins(start); - } - public void onInitialize() { for (PluginDetector detector : PLUGIN_DETECTORS) { detector.detectCommonPlugins(); detector.detectServerPlugins(); } RoughlyEnoughItemsNetwork.onInitialize(); - - if (Platform.getEnvironment() == Env.SERVER) { - MutableLong lastReload = new MutableLong(-1); - ReloadListenerRegistry.register(PackType.SERVER_DATA, (preparationBarrier, resourceManager, profilerFiller, profilerFiller2, executor, executor2) -> { - return preparationBarrier.wait(Unit.INSTANCE).thenRunAsync(PluginManager::reloadAll, executor2); - }); - } } } diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java index 7c56d41d9..2c8abbdb7 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java @@ -25,56 +25,36 @@ package me.shedaniel.rei; import com.google.common.collect.Lists; import com.mojang.serialization.DataResult; -import dev.architectury.event.Event; -import dev.architectury.event.EventFactory; import dev.architectury.event.EventResult; import dev.architectury.event.events.client.ClientGuiEvent; -import dev.architectury.event.events.client.ClientRecipeUpdateEvent; import dev.architectury.event.events.client.ClientScreenInputEvent; import dev.architectury.networking.NetworkManager; +import dev.architectury.platform.Platform; import me.shedaniel.math.Point; 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.config.addon.ConfigAddonRegistry; -import me.shedaniel.rei.api.client.entry.renderer.EntryRendererRegistry; import me.shedaniel.rei.api.client.favorites.FavoriteEntry; import me.shedaniel.rei.api.client.favorites.FavoriteEntryType; import me.shedaniel.rei.api.client.gui.screen.DisplayScreen; +import me.shedaniel.rei.api.client.gui.widgets.TextField; import me.shedaniel.rei.api.client.gui.widgets.Tooltip; import me.shedaniel.rei.api.client.gui.widgets.TooltipContext; import me.shedaniel.rei.api.client.overlay.ScreenOverlay; -import me.shedaniel.rei.api.client.plugins.REIClientPlugin; import me.shedaniel.rei.api.client.registry.category.CategoryRegistry; -import me.shedaniel.rei.api.client.registry.display.DisplayRegistry; -import me.shedaniel.rei.api.client.registry.entry.CollapsibleEntryRegistry; -import me.shedaniel.rei.api.client.registry.entry.EntryRegistry; import me.shedaniel.rei.api.client.registry.screen.ClickArea; import me.shedaniel.rei.api.client.registry.screen.OverlayDecider; import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry; -import me.shedaniel.rei.api.client.registry.transfer.TransferHandlerRegistry; -import me.shedaniel.rei.api.client.search.SearchProvider; -import me.shedaniel.rei.api.client.search.method.InputMethodRegistry; -import me.shedaniel.rei.api.client.subsets.SubsetsRegistry; -import me.shedaniel.rei.api.client.view.Views; import me.shedaniel.rei.api.common.category.CategoryIdentifier; -import me.shedaniel.rei.api.common.plugins.PluginManager; -import me.shedaniel.rei.api.common.plugins.PluginView; -import me.shedaniel.rei.api.common.plugins.REIPlugin; -import me.shedaniel.rei.api.common.plugins.REIPluginProvider; -import me.shedaniel.rei.api.common.registry.ReloadStage; import me.shedaniel.rei.api.common.util.CollectionUtils; import me.shedaniel.rei.api.common.util.EntryStacks; import me.shedaniel.rei.api.common.util.ImmutableTextComponent; -import me.shedaniel.rei.impl.ClientInternals; +import me.shedaniel.rei.impl.client.ClientInternals; import me.shedaniel.rei.impl.client.REIRuntimeImpl; import me.shedaniel.rei.impl.client.gui.ScreenOverlayImpl; import me.shedaniel.rei.impl.client.gui.widget.CatchingExceptionUtils; -import me.shedaniel.rei.impl.client.gui.widget.QueuedTooltip; +import me.shedaniel.rei.impl.client.gui.widget.TooltipImpl; import me.shedaniel.rei.impl.client.gui.widget.TooltipContextImpl; -import me.shedaniel.rei.impl.client.gui.widget.search.OverlaySearchField; -import me.shedaniel.rei.impl.common.InternalLogger; -import me.shedaniel.rei.impl.common.plugins.PluginManagerImpl; import me.shedaniel.rei.impl.common.util.IssuesDetector; import me.shedaniel.rei.impl.init.PluginDetector; import net.fabricmc.api.EnvType; @@ -101,14 +81,11 @@ import net.minecraft.world.item.Items; import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.item.crafting.Ingredient; import org.apache.commons.lang3.function.TriFunction; -import org.apache.commons.lang3.mutable.MutableLong; import org.jetbrains.annotations.Nullable; -import java.lang.reflect.InvocationTargetException; import java.util.Collection; import java.util.ConcurrentModificationException; import java.util.List; -import java.util.concurrent.*; import java.util.function.BiFunction; import java.util.function.BooleanSupplier; import java.util.function.Function; @@ -117,17 +94,7 @@ import java.util.stream.Stream; @Environment(EnvType.CLIENT) public class RoughlyEnoughItemsCoreClient { - public static final Event PRE_UPDATE_RECIPES = EventFactory.createLoop(); public static boolean isLeftMousePressed = false; - private static final ExecutorService RELOAD_PLUGINS = Executors.newSingleThreadScheduledExecutor(task -> { - Thread thread = new Thread(task, "REI-ReloadPlugins"); - thread.setDaemon(true); - thread.setUncaughtExceptionHandler(($, exception) -> { - InternalLogger.getInstance().throwException(exception); - }); - return thread; - }); - private static final List> RELOAD_TASKS = new CopyOnWriteArrayList<>(); public static void attachClientInternals() { CatchingExceptionUtils.attach(); @@ -138,9 +105,9 @@ public class RoughlyEnoughItemsCoreClient { if (entryType == null) return DataResult.error("Unknown favorite type: " + id + ", json: " + object); return entryType.read(object); }, "favoriteEntryFromJson"); - ClientInternals.attachInstance((BiFunction<@Nullable Point, Collection, Tooltip>) QueuedTooltip::impl, "tooltipProvider"); + ClientInternals.attachInstance((BiFunction<@Nullable Point, Collection, Tooltip>) TooltipImpl::impl, "tooltipProvider"); ClientInternals.attachInstance((TriFunction) TooltipContextImpl::new, "tooltipContextProvider"); - ClientInternals.attachInstance((Function) QueuedTooltip.TooltipEntryImpl::new, "tooltipEntryProvider"); + ClientInternals.attachInstance((Function) TooltipImpl.TooltipEntryImpl::new, "tooltipEntryProvider"); ClientInternals.attachInstance((Function<@Nullable Boolean, ClickArea.Result>) successful -> new ClickArea.Result() { private List> categories = Lists.newArrayList(); private BooleanSupplier execute = () -> { @@ -196,21 +163,6 @@ public class RoughlyEnoughItemsCoreClient { return categories.stream(); } }, "clickAreaHandlerResult"); - ClientInternals.getPluginManager().registerReloadable(EntryRendererRegistry.class); - ClientInternals.getPluginManager().registerReloadable(Views.class); - ClientInternals.getPluginManager().registerReloadable(InputMethodRegistry.class); - ClientInternals.getPluginManager().registerReloadable(SearchProvider.class); - ClientInternals.getPluginManager().registerReloadable(ConfigManager.class); - ClientInternals.getPluginManager().registerReloadable(EntryRegistry.class); - ClientInternals.getPluginManager().registerReloadable(CollapsibleEntryRegistry.class); - ClientInternals.getPluginManager().registerReloadable(CategoryRegistry.class); - ClientInternals.getPluginManager().registerReloadable(DisplayRegistry.class); - ClientInternals.getPluginManager().registerReloadable(ScreenRegistry.class); - ClientInternals.getPluginManager().registerReloadable(FavoriteEntryType.Registry.class); - ClientInternals.getPluginManager().registerReloadable(SubsetsRegistry.class); - ClientInternals.getPluginManager().registerReloadable(TransferHandlerRegistry.class); - ClientInternals.getPluginManager().registerReloadable(REIRuntime.class); - ClientInternals.getPluginManager().registerReloadable(ConfigAddonRegistry.class); } public void onInitializeClient() { @@ -219,7 +171,6 @@ public class RoughlyEnoughItemsCoreClient { for (PluginDetector detector : RoughlyEnoughItemsCore.PLUGIN_DETECTORS) { detector.detectClientPlugins().get().run(); } - loadTestPlugins(); Minecraft client = Minecraft.getInstance(); NetworkManager.registerReceiver(NetworkManager.s2c(), RoughlyEnoughItemsNetwork.CREATE_ITEMS_MESSAGE_PACKET, (buf, context) -> { @@ -258,18 +209,8 @@ public class RoughlyEnoughItemsCoreClient { } } }); - } - - private void loadTestPlugins() { - if (System.getProperty("rei.test", "false").equals("true")) { - try { - PluginView.getClientInstance().registerPlugin((REIPluginProvider) Class.forName("me.shedaniel.rei.plugin.test.REITestPlugin") - .getDeclaredConstructor() - .newInstance()); - } catch (InstantiationException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { - throw new RuntimeException(e); - } - } + + Platform.getMod("roughlyenoughitems").registerConfigurationScreen(ConfigManager.getInstance()::getConfigScreen); } public static boolean shouldReturn(Screen screen) { @@ -299,37 +240,11 @@ public class RoughlyEnoughItemsCoreClient { private void registerEvents() { Minecraft client = Minecraft.getInstance(); final ResourceLocation recipeButtonTex = new ResourceLocation("textures/gui/recipe_button.png"); - MutableLong startReload = new MutableLong(-1); - MutableLong endReload = new MutableLong(-1); - PRE_UPDATE_RECIPES.register(recipeManager -> { - PluginManager.reloadAll(); - RoughlyEnoughItemsCore.reloadPlugins(startReload, ReloadStage.START); - }); - ClientRecipeUpdateEvent.EVENT.register(recipeManager -> { - RoughlyEnoughItemsCore.reloadPlugins(endReload, ReloadStage.END); - }); - ClientGuiEvent.INIT_PRE.register((screen, access) -> { - List stages = ((PluginManagerImpl>) PluginManager.getInstance()).getReloader().getObservedStages(); - - if (Minecraft.getInstance().level != null && Minecraft.getInstance().player != null && stages.contains(ReloadStage.START) - && !stages.contains(ReloadStage.END) && !PluginManager.areAnyReloading() && screen instanceof AbstractContainerScreen) { - for (Future task : RELOAD_TASKS) { - if (!task.isDone()) { - return EventResult.pass(); - } - } - - InternalLogger.getInstance().error("Detected missing stage: END! This is possibly due to issues during client recipe reload! REI will force a reload of the recipes now!"); - RoughlyEnoughItemsCore.reloadPlugins(endReload, ReloadStage.END); - } - - return EventResult.pass(); - }); ClientGuiEvent.INIT_POST.register((screen, access) -> { REIRuntime.getInstance().getOverlay(false, true); if (Minecraft.getInstance().screen == screen) { if (REIRuntime.getInstance().getPreviousScreen() != screen) { - OverlaySearchField searchField = REIRuntimeImpl.getSearchField(); + TextField searchField = REIRuntime.getInstance().getSearchTextField(); if (searchField != null) { searchField.setFocused(false); @@ -382,7 +297,7 @@ public class RoughlyEnoughItemsCoreClient { if (shouldReturn(screen) || screen instanceof DisplayScreen) 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()) + if (REIRuntime.getInstance().getSearchTextField() != null && !REIRuntime.getInstance().getSearchTextField().isFocused()) return EventResult.pass(); resetFocused(screen); if (getOverlay().charTyped(character, keyCode) @@ -419,7 +334,7 @@ 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())) - if (!REIRuntimeImpl.getSearchField().isFocused()) + if (REIRuntime.getInstance().getSearchTextField() != null && !REIRuntime.getInstance().getSearchTextField().isFocused()) return EventResult.pass(); resetFocused(screen); if (getOverlay().keyPressed(i, i1, i2) @@ -431,7 +346,7 @@ public class RoughlyEnoughItemsCoreClient { if (shouldReturn(screen) || screen instanceof DisplayScreen) 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()) + if (REIRuntime.getInstance().getSearchTextField() != null && !REIRuntime.getInstance().getSearchTextField().isFocused()) return EventResult.pass(); resetFocused(screen); if (getOverlay().keyReleased(i, i1, i2) @@ -447,23 +362,4 @@ public class RoughlyEnoughItemsCoreClient { } return true; } - - static boolean reloadPluginsClient(@Nullable ReloadStage start) { - if (ConfigObject.getInstance().doesRegisterRecipesInAnotherThread()) { - Future[] futures = new Future[1]; - CompletableFuture future = CompletableFuture.runAsync(() -> RoughlyEnoughItemsCore._reloadPlugins(start), RELOAD_PLUGINS) - .whenComplete((unused, throwable) -> { - // Remove the future from the list of futures - if (futures[0] != null) { - RELOAD_TASKS.remove(futures[0]); - futures[0] = null; - } - }); - futures[0] = future; - RELOAD_TASKS.add(future); - return true; - } - - return false; - } } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/AbstractViewSearchBuilder.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/AbstractViewSearchBuilder.java deleted file mode 100644 index b0cc20251..000000000 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/AbstractViewSearchBuilder.java +++ /dev/null @@ -1,50 +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.client; - -import me.shedaniel.rei.api.client.gui.screen.DisplayScreen; -import me.shedaniel.rei.api.client.view.ViewSearchBuilder; -import me.shedaniel.rei.impl.display.DisplaySpec; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.screens.Screen; - -import java.util.Collection; -import java.util.stream.Stream; - -abstract class AbstractViewSearchBuilder implements ViewSearchBuilder { - public ViewSearchBuilder fillPreferredOpenedCategory() { - if (getPreferredOpenedCategory() == null) { - Screen currentScreen = Minecraft.getInstance().screen; - if (currentScreen instanceof DisplayScreen displayScreen) { - setPreferredOpenedCategory(displayScreen.getCurrentCategoryId()); - } - } - return this; - } - - @Override - public Stream streamDisplays() { - return buildMapInternal().values().stream().flatMap(Collection::stream); - } -} 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 b690e0932..78128ca0a 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 @@ -27,9 +27,6 @@ import com.google.common.base.Suppliers; import dev.architectury.networking.NetworkManager; import dev.architectury.platform.Platform; import io.netty.buffer.Unpooled; -import it.unimi.dsi.fastutil.longs.Long2LongMap; -import it.unimi.dsi.fastutil.longs.Long2LongMaps; -import it.unimi.dsi.fastutil.longs.Long2LongOpenHashMap; import me.shedaniel.rei.RoughlyEnoughItemsNetwork; import me.shedaniel.rei.api.client.ClientHelper; import me.shedaniel.rei.api.client.config.ConfigManager; @@ -41,12 +38,9 @@ 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.entry.EntryStack; -import me.shedaniel.rei.api.common.entry.comparison.ComparisonContext; -import me.shedaniel.rei.api.common.entry.type.EntryDefinition; import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes; import me.shedaniel.rei.api.common.util.EntryStacks; 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.display.DisplaySpec; @@ -56,13 +50,11 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.gui.screens.inventory.CreativeModeInventoryScreen; -import net.minecraft.core.NonNullList; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; @@ -259,85 +251,34 @@ public class ClientHelperImpl implements ClientHelper { } else return false; } - @ApiStatus.Internal - public Long2LongMap _getInventoryItemsTypes() { - EntryDefinition definition; - try { - definition = VanillaEntryTypes.ITEM.getDefinition(); - } catch (NullPointerException e) { - return Long2LongMaps.EMPTY_MAP; - } - Long2LongOpenHashMap map = new Long2LongOpenHashMap(); - for (NonNullList compartment : Minecraft.getInstance().player.getInventory().compartments) { - for (ItemStack stack : compartment) { - long hash = definition.hash(null, stack, ComparisonContext.FUZZY); - long newCount = map.getOrDefault(hash, 0) + Math.max(0, stack.getCount()); - map.put(hash, newCount); - } - } - return map; - } - - @ApiStatus.Internal - public Long2LongMap _getContainerItemsTypes() { - EntryDefinition definition; - try { - definition = VanillaEntryTypes.ITEM.getDefinition(); - } catch (NullPointerException e) { - return Long2LongMaps.EMPTY_MAP; - } - Long2LongOpenHashMap map = new Long2LongOpenHashMap(); - AbstractContainerMenu menu = Minecraft.getInstance().player.containerMenu; - if (menu != null) { - for (Slot slot : menu.slots) { - ItemStack stack = slot.getItem(); - - if (!stack.isEmpty()) { - long hash = definition.hash(null, stack, ComparisonContext.FUZZY); - long newCount = map.getOrDefault(hash, 0) + Math.max(0, stack.getCount()); - map.put(hash, newCount); - } - } - } - return map; - } - - @ApiStatus.Internal - public void openDisplayViewingScreen(Map, List> map, @Nullable CategoryIdentifier category, List> ingredientNotice, List> resultNotice) { - LegacyWrapperViewSearchBuilder builder = new LegacyWrapperViewSearchBuilder(map); - for (EntryStack stack : ingredientNotice) { - builder.addInputNotice(stack); - } - for (EntryStack stack : resultNotice) { - builder.addOutputNotice(stack); - } - openView(builder.setPreferredOpenedCategory(category)); - } - @Override public boolean openView(ViewSearchBuilder builder) { - Map, List> map = builder.buildMapInternal(); + return openView(builder.buildMapInternal(), builder.getPreferredOpenedCategory(), builder.getUsagesFor(), builder.getRecipesFor()); + } + + public boolean openView(Map, List> map, @Nullable CategoryIdentifier category, + List> usagesFor, List> recipesFor) { if (map.isEmpty()) return false; Screen screen; if (ConfigObject.getInstance().getRecipeScreenType() == DisplayScreenType.COMPOSITE) { - screen = new CompositeDisplayViewingScreen(map, builder.getPreferredOpenedCategory()); + screen = new CompositeDisplayViewingScreen(map, category); } else if (ConfigObject.getInstance().getRecipeScreenType() == DisplayScreenType.UNSET) { ConfigObject.getInstance().setRecipeScreenType(DisplayScreenType.ORIGINAL); ConfigManager.getInstance().saveConfig(); - return openView(builder); + return openView(map, category, usagesFor, recipesFor); // screen = new UncertainDisplayViewingScreen(REIRuntime.getInstance().getPreviousScreen(), DisplayScreenType.UNSET, true, original -> { // ConfigObject.getInstance().setRecipeScreenType(original ? DisplayScreenType.ORIGINAL : DisplayScreenType.COMPOSITE); // ConfigManager.getInstance().saveConfig(); // openView(builder); // }); } else { - screen = new DefaultDisplayViewingScreen(map, builder.getPreferredOpenedCategory()); + screen = new DefaultDisplayViewingScreen(map, category); } if (screen instanceof DisplayScreen displayScreen) { - for (EntryStack stack : builder.getUsagesFor()) { + for (EntryStack stack : usagesFor) { displayScreen.addIngredientToNotice(stack); } - for (EntryStack stack : builder.getRecipesFor()) { + for (EntryStack stack : recipesFor) { displayScreen.addResultToNotice(stack); } } @@ -352,9 +293,4 @@ public class ClientHelperImpl implements ClientHelper { public boolean canUseMovePackets() { return NetworkManager.canServerReceive(RoughlyEnoughItemsNetwork.MOVE_ITEMS_PACKET); } - - public void onInitializeClient() { - ClientInternals.attachInstance(this, ClientHelper.class); - ClientInternals.attachInstance((Supplier) ViewSearchBuilderImpl::new, "viewSearchBuilder"); - } } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/ErrorDisplayer.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/ErrorDisplayer.java index 29b7accfe..82424ac5c 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/ErrorDisplayer.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/ErrorDisplayer.java @@ -24,7 +24,7 @@ package me.shedaniel.rei.impl.client; import me.shedaniel.rei.RoughlyEnoughItemsState; -import me.shedaniel.rei.impl.client.gui.screen.WarningAndErrorScreen; +import me.shedaniel.rei.impl.client.gui.screen.error.WarningAndErrorScreen; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.Screen; diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/LegacyWrapperViewSearchBuilder.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/LegacyWrapperViewSearchBuilder.java deleted file mode 100644 index c199f94e9..000000000 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/LegacyWrapperViewSearchBuilder.java +++ /dev/null @@ -1,145 +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.client; - -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.entry.EntryStack; -import me.shedaniel.rei.impl.display.DisplaySpec; -import org.jetbrains.annotations.Nullable; - -import java.util.*; - -public final class LegacyWrapperViewSearchBuilder extends AbstractViewSearchBuilder { - private final Map, List> map; - @Nullable - private EntryStack inputNotice; - @Nullable - private EntryStack outputNotice; - @Nullable - private CategoryIdentifier preferredOpenedCategory = null; - - public LegacyWrapperViewSearchBuilder(Map, List> map) { - this.map = map; - } - - @Override - public ViewSearchBuilder addCategory(CategoryIdentifier category) { - return this; - } - - @Override - public ViewSearchBuilder addCategories(Collection> categories) { - return this; - } - - @Override - public Set> getCategories() { - 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; - } - - @Override - public List> getRecipesFor() { - return inputNotice == null ? Collections.emptyList() : Collections.singletonList(outputNotice); - } - - @Override - public ViewSearchBuilder addUsagesFor(EntryStack stack) { - return this; - } - - @Override - public List> getUsagesFor() { - return inputNotice == null ? Collections.emptyList() : Collections.singletonList(inputNotice); - } - - @Override - public ViewSearchBuilder setPreferredOpenedCategory(@Nullable CategoryIdentifier category) { - this.preferredOpenedCategory = category; - return this; - } - - @Override - @Nullable - public CategoryIdentifier getPreferredOpenedCategory() { - return this.preferredOpenedCategory; - } - - public LegacyWrapperViewSearchBuilder addInputNotice(@Nullable EntryStack stack) { - this.inputNotice = stack; - return this; - } - - public LegacyWrapperViewSearchBuilder addOutputNotice(@Nullable EntryStack stack) { - this.outputNotice = stack; - return this; - } - - @Override - public Map, List> buildMapInternal() { - 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/REIRuntimeImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java index a63ddc97d..b890bc98a 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java @@ -38,13 +38,12 @@ import me.shedaniel.rei.api.client.config.ConfigObject; import me.shedaniel.rei.api.client.gui.config.DisplayPanelLocation; import me.shedaniel.rei.api.client.gui.config.SearchFieldLocation; import me.shedaniel.rei.api.client.gui.screen.DisplayScreen; -import me.shedaniel.rei.api.client.gui.widgets.TextField; import me.shedaniel.rei.api.client.gui.widgets.Tooltip; import me.shedaniel.rei.api.client.overlay.ScreenOverlay; import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry; import me.shedaniel.rei.api.client.search.SearchProvider; import me.shedaniel.rei.api.common.registry.ReloadStage; -import me.shedaniel.rei.impl.Internals; +import me.shedaniel.rei.impl.common.Internals; import me.shedaniel.rei.impl.client.gui.ScreenOverlayImpl; import me.shedaniel.rei.impl.client.gui.hints.HintProvider; import me.shedaniel.rei.impl.client.gui.widget.CachedEntryListRender; @@ -71,7 +70,6 @@ public class REIRuntimeImpl implements REIRuntime { @ApiStatus.Internal public static boolean isWithinRecipeViewingScreen = false; private ScreenOverlayImpl overlay; - private OverlaySearchField searchField; private AbstractContainerScreen previousContainerScreen = null; private Screen previousScreen = null; private LinkedHashSet lastDisplayScreen = Sets.newLinkedHashSetWithExpectedSize(10); @@ -104,16 +102,6 @@ public class REIRuntimeImpl implements REIRuntime { } } - @Override - @Nullable - public TextField getSearchTextField() { - if (searchField == null) { - searchField = new OverlaySearchField(0, 0, 0, 0); - } - - return searchField; - } - @Nullable public static OverlaySearchField getSearchField() { return (OverlaySearchField) getInstance().getSearchTextField(); @@ -159,7 +147,7 @@ public class REIRuntimeImpl implements REIRuntime { throw new RuntimeException(e); } overlay.init(); - getSearchField().setFocused(false); + overlay.getSearchField().setFocused(false); } return Optional.ofNullable(overlay); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/ViewSearchBuilderImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/ViewSearchBuilderImpl.java deleted file mode 100644 index 3db7d31a9..000000000 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/ViewSearchBuilderImpl.java +++ /dev/null @@ -1,144 +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.client; - -import com.google.common.base.Suppliers; -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.entry.EntryStack; -import me.shedaniel.rei.impl.client.view.ViewsImpl; -import me.shedaniel.rei.impl.display.DisplaySpec; -import org.jetbrains.annotations.Nullable; - -import java.util.*; -import java.util.function.Supplier; - -public 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 - public ViewSearchBuilder addCategory(CategoryIdentifier category) { - this.categories.add(category); - return this; - } - - @Override - public ViewSearchBuilder addCategories(Collection> categories) { - this.categories.addAll(categories); - return this; - } - - @Override - public Set> getCategories() { - return categories; - } - - @Override - public ViewSearchBuilder addRecipesFor(EntryStack stack) { - this.recipesFor.add(stack); - return this; - } - - @Override - public List> getRecipesFor() { - return recipesFor; - } - - @Override - public ViewSearchBuilder addUsagesFor(EntryStack stack) { - this.usagesFor.add(stack); - return this; - } - - @Override - public List> getUsagesFor() { - return usagesFor; - } - - @Override - public ViewSearchBuilder setPreferredOpenedCategory(@Nullable CategoryIdentifier category) { - this.preferredOpenedCategory = category; - return this; - } - - @Override - @Nullable - public CategoryIdentifier getPreferredOpenedCategory() { - 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; - } -} diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java index b4c1987d0..2b3b59a9b 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java @@ -39,6 +39,7 @@ import me.shedaniel.rei.api.client.gui.config.SearchFieldLocation; import me.shedaniel.rei.api.client.gui.drag.DraggingContext; import me.shedaniel.rei.api.client.gui.drag.component.DraggableComponentProvider; import me.shedaniel.rei.api.client.gui.drag.component.DraggableComponentVisitor; +import me.shedaniel.rei.api.client.gui.widgets.TextField; import me.shedaniel.rei.api.client.gui.widgets.Tooltip; import me.shedaniel.rei.api.client.gui.widgets.Widget; import me.shedaniel.rei.api.client.overlay.OverlayListWidget; @@ -49,11 +50,10 @@ import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry; import me.shedaniel.rei.api.client.view.ViewSearchBuilder; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.plugins.PluginManager; -import me.shedaniel.rei.impl.client.REIRuntimeImpl; import me.shedaniel.rei.impl.client.gui.craftable.CraftableFilter; import me.shedaniel.rei.impl.client.gui.dragging.CurrentDraggingStack; -import me.shedaniel.rei.impl.client.gui.modules.MenuAccess; -import me.shedaniel.rei.impl.client.gui.modules.MenuHolder; +import me.shedaniel.rei.impl.client.gui.menu.MenuAccess; +import me.shedaniel.rei.impl.client.gui.menu.MenuAccessImpl; import me.shedaniel.rei.impl.client.gui.widget.*; import me.shedaniel.rei.impl.client.gui.widget.entrylist.EntryListWidget; import me.shedaniel.rei.impl.client.gui.widget.entrylist.PaginatedEntryListWidget; @@ -64,9 +64,6 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.TextComponent; -import net.minecraft.network.chat.TranslatableComponent; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.InteractionResult; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; @@ -82,6 +79,7 @@ public abstract class ScreenOverlayImpl extends ScreenOverlay { private static final List TOOLTIPS = Lists.newArrayList(); private static EntryListWidget entryListWidget = null; private static FavoritesListWidget favoritesListWidget = null; + private static OverlaySearchField searchField = null; private final List widgets = Lists.newLinkedList(); public boolean shouldReload = false; public boolean shouldReloadSearch = false; @@ -91,7 +89,7 @@ public abstract class ScreenOverlayImpl extends ScreenOverlay { private CurrentDraggingStack draggingStack = new CurrentDraggingStack(); @Nullable public DefaultDisplayChoosePageWidget choosePageWidget; - private MenuHolder menuHolder = new MenuHolder(); + private MenuAccessImpl menuAccess = new MenuAccessImpl(); public static EntryListWidget getEntryListWidget() { boolean widgetScrolled = ConfigObject.getInstance().isEntryListWidgetScrolled(); @@ -108,7 +106,7 @@ public abstract class ScreenOverlayImpl extends ScreenOverlay { ScreenOverlayImpl overlay = ScreenOverlayImpl.getInstance(); Rectangle overlayBounds = overlay.bounds; - entryListWidget.updateArea(Objects.requireNonNullElse(overlayBounds, new Rectangle()), REIRuntimeImpl.getSearchField() == null ? "" : REIRuntimeImpl.getSearchField().getText()); + entryListWidget.updateArea(Objects.requireNonNullElse(overlayBounds, new Rectangle()), overlay.getSearchField().getText()); entryListWidget.updateEntriesPosit