From 664815d74ffdc030fd52f0ed0480b1cd615ef384 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Tue, 19 Jul 2022 00:06:17 +0800 Subject: Add InputMethods, Close #574 --- .../rei/api/client/config/ConfigObject.java | 6 + .../me/shedaniel/rei/api/client/gui/Renderer.java | 1 - .../api/client/gui/config/SearchFieldLocation.java | 2 +- .../rei/api/client/gui/widgets/Label.java | 2 - .../rei/api/client/gui/widgets/Tooltip.java | 1 - .../rei/api/client/overlay/ScreenOverlay.java | 6 +- .../rei/api/client/plugins/REIClientPlugin.java | 12 + .../client/registry/transfer/TransferHandler.java | 2 - .../rei/api/client/search/SearchProvider.java | 19 +- .../method/CharacterUnpackingInputMethod.java | 61 +++ .../rei/api/client/search/method/InputMethod.java | 68 +++ .../client/search/method/InputMethodRegistry.java | 49 +++ .../rei/api/common/entry/EntryIngredient.java | 1 - .../shedaniel/rei/api/common/entry/EntryStack.java | 6 +- .../entry/settings/EntrySettingsAdapter.java | 2 - .../rei/api/common/util/CollectionUtils.java | 37 ++ .../rei/plugin/client/DefaultClientPlugin.java | 3 - .../categories/DefaultCompostingCategory.java | 1 - .../categories/DefaultInformationCategory.java | 1 - .../beacon/DefaultBeaconBaseCategory.java | 1 - .../beacon/DefaultBeaconPaymentCategory.java | 1 - .../client/favorites/GameModeFavoriteEntry.java | 1 - .../plugin/client/favorites/TimeFavoriteEntry.java | 1 - .../client/favorites/WeatherFavoriteEntry.java | 1 - .../common/displays/DefaultCompostingDisplay.java | 3 +- .../rei/plugin/common/displays/tag/TagNode.java | 6 +- .../rei/plugin/common/displays/tag/TagNodes.java | 1 - gradle.properties | 2 +- runtime/build.gradle | 6 + .../rei/RoughlyEnoughItemsCoreClient.java | 2 + .../shedaniel/rei/RoughlyEnoughItemsNetwork.java | 1 - .../rei/impl/client/config/ConfigManagerImpl.java | 47 +- .../rei/impl/client/config/ConfigObjectImpl.java | 13 + .../client/config/addon/ConfigAddonsScreen.java | 5 +- .../config/entries/FilteringRulesScreen.java | 5 +- .../client/config/entries/ReloadPluginsEntry.java | 2 +- .../SearchFilterSyntaxHighlightingEntry.java | 4 +- .../entry/type/types/RenderingEntryDefinition.java | 2 - .../favorites/FavoriteEntryTypeRegistryImpl.java | 1 - .../rei/impl/client/gui/InternalTextures.java | 35 ++ .../rei/impl/client/gui/ScreenOverlayImpl.java | 490 +++------------------ .../rei/impl/client/gui/hints/HintProvider.java | 6 + .../rei/impl/client/gui/modules/Menu.java | 3 +- .../rei/impl/client/gui/modules/MenuAccess.java | 64 +++ .../rei/impl/client/gui/modules/MenuHolder.java | 135 ++++++ .../client/gui/modules/entries/SubMenuEntry.java | 4 +- .../gui/modules/entries/ToggleMenuEntry.java | 39 +- .../gui/screen/CompositeDisplayViewingScreen.java | 10 +- .../client/gui/screen/ConfigReloadingScreen.java | 16 +- .../gui/screen/DefaultDisplayViewingScreen.java | 15 +- .../gui/screen/UncertainDisplayViewingScreen.java | 4 - .../client/gui/widget/CachedEntryListRender.java | 3 - .../impl/client/gui/widget/ConfigButtonWidget.java | 185 ++++++++ .../gui/widget/CraftableFilterButtonWidget.java | 163 +++++++ .../client/gui/widget/DisplayCompositeWidget.java | 8 - .../impl/client/gui/widget/EntryHighlighter.java | 64 +++ .../rei/impl/client/gui/widget/EntryWidget.java | 22 +- .../impl/client/gui/widget/InternalWidgets.java | 4 - .../rei/impl/client/gui/widget/MergedWidget.java | 1 - .../rei/impl/client/gui/widget/QueuedTooltip.java | 2 - .../rei/impl/client/gui/widget/TabWidget.java | 10 +- .../client/gui/widget/basewidgets/PanelWidget.java | 7 +- .../gui/widget/basewidgets/TextFieldWidget.java | 184 ++++---- .../widget/entrylist/EntryListSearchManager.java | 16 +- .../gui/widget/entrylist/EntryListWidget.java | 17 +- .../widget/entrylist/PaginatedEntryListWidget.java | 128 +++++- .../widget/entrylist/ScrolledEntryListWidget.java | 13 - .../gui/widget/favorites/FavoritesListWidget.java | 1 - .../gui/widget/favorites/history/DisplayEntry.java | 2 - .../listeners/FavoritesRegionListener.java | 2 - .../panel/rows/FavoritesPanelEntriesRow.java | 1 - .../gui/widget/region/RegionEntryWidget.java | 20 +- .../gui/widget/search/OverlaySearchField.java | 53 ++- .../client/registry/screen/ScreenRegistryImpl.java | 13 +- .../rei/impl/client/search/AsyncSearchManager.java | 24 +- .../rei/impl/client/search/SearchProviderImpl.java | 28 +- .../search/argument/AlternativeArgument.java | 2 + .../rei/impl/client/search/argument/Argument.java | 81 +++- .../client/search/argument/CompoundArgument.java | 2 + .../rei/impl/client/search/argument/IndexSet.java | 173 ++++++++ .../client/search/argument/InputMethodMatcher.java | 129 ++++++ .../argument/type/AlwaysMatchingArgumentType.java | 9 +- .../client/search/argument/type/ArgumentType.java | 10 +- .../argument/type/ArgumentTypesRegistry.java | 14 +- .../argument/type/IdentifierArgumentType.java | 10 +- .../search/argument/type/ModArgumentType.java | 9 +- .../search/argument/type/RegexArgumentType.java | 19 +- .../search/argument/type/TagArgumentType.java | 11 +- .../search/argument/type/TextArgumentType.java | 8 +- .../search/argument/type/TooltipArgumentType.java | 10 +- .../client/search/method/DefaultInputMethod.java | 75 ++++ .../search/method/InputMethodRegistryImpl.java | 104 +++++ .../search/method/unihan/BomopofoInputMethod.java | 141 ++++++ .../search/method/unihan/JyutpingInputMethod.java | 76 ++++ .../search/method/unihan/PinyinInputMethod.java | 135 ++++++ .../search/method/unihan/UniHanInputMethod.java | 82 ++++ .../client/search/method/unihan/UniHanManager.java | 123 ++++++ .../impl/client/subsets/SubsetsRegistryImpl.java | 6 - .../rei/impl/common/entry/AbstractEntryStack.java | 1 - .../settings/EntrySettingsAdapterRegistryImpl.java | 3 - .../common/entry/type/PreFilteredEntryList.java | 8 +- .../entry/type/types/EmptyEntryDefinition.java | 1 - .../rei/impl/common/logging/FilteringLogger.java | 8 - .../autocrafting/DefaultCategoryHandler.java | 3 - .../plugin/client/entry/ItemEntryDefinition.java | 2 - .../client/runtime/DefaultClientRuntimePlugin.java | 18 +- .../plugin/client/runtime/InputMethodWatcher.java | 105 +++++ .../runtime/PluginStageExecutionWatcher.java | 5 + .../client/runtime/SearchBarHighlightWatcher.java | 5 + .../client/runtime/SearchFilterPrepareWatcher.java | 5 + .../assets/roughlyenoughitems/lang/cs_cz.json | 23 + .../assets/roughlyenoughitems/lang/en_us.json | 15 + .../assets/roughlyenoughitems/lang/eo_uy.json | 1 + .../assets/roughlyenoughitems/lang/es_es.json | 86 +++- .../assets/roughlyenoughitems/lang/fr_fr.json | 10 +- .../assets/roughlyenoughitems/lang/it_it.json | 4 + .../assets/roughlyenoughitems/lang/ja_jp.json | 26 +- .../assets/roughlyenoughitems/lang/ko_kr.json | 45 ++ .../assets/roughlyenoughitems/lang/ru_ru.json | 10 + .../assets/roughlyenoughitems/lang/zh_cn.json | 22 + .../assets/roughlyenoughitems/lang/zh_hk.json | 395 +++++++++++++---- .../assets/roughlyenoughitems/lang/zh_tw.json | 22 + runtime/src/test/java/InputMethodTest.java | 99 +++++ 123 files changed, 3365 insertions(+), 963 deletions(-) create mode 100644 api/src/main/java/me/shedaniel/rei/api/client/search/method/CharacterUnpackingInputMethod.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/client/search/method/InputMethod.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/client/search/method/InputMethodRegistry.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/InternalTextures.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/modules/MenuAccess.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/modules/MenuHolder.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/ConfigButtonWidget.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/CraftableFilterButtonWidget.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryHighlighter.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/search/argument/IndexSet.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/search/argument/InputMethodMatcher.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/search/method/DefaultInputMethod.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/search/method/InputMethodRegistryImpl.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/search/method/unihan/BomopofoInputMethod.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/search/method/unihan/JyutpingInputMethod.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/search/method/unihan/PinyinInputMethod.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/search/method/unihan/UniHanInputMethod.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/search/method/unihan/UniHanManager.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/InputMethodWatcher.java create mode 100644 runtime/src/test/java/InputMethodTest.java diff --git a/api/src/main/java/me/shedaniel/rei/api/client/config/ConfigObject.java b/api/src/main/java/me/shedaniel/rei/api/client/config/ConfigObject.java index 3b0e0efbb..4da17b6c0 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/config/ConfigObject.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/config/ConfigObject.java @@ -30,7 +30,9 @@ import me.shedaniel.rei.api.client.favorites.FavoriteEntry; import me.shedaniel.rei.api.client.gui.config.*; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; import java.util.List; @@ -235,6 +237,10 @@ public interface ConfigObject { */ int getMaxRecipesPageHeight(); + @ApiStatus.Experimental + @Nullable + ResourceLocation getInputMethodId(); + boolean doesDisableRecipeBook(); boolean doesFixTabCloseContainer(); diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/Renderer.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/Renderer.java index 317fed296..b2e714e08 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/Renderer.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/Renderer.java @@ -24,7 +24,6 @@ package me.shedaniel.rei.api.client.gui; import com.mojang.blaze3d.vertex.PoseStack; -import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.gui.widgets.Tooltip; import me.shedaniel.rei.api.client.gui.widgets.TooltipContext; diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/config/SearchFieldLocation.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/config/SearchFieldLocation.java index 762ae020f..82d722359 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/config/SearchFieldLocation.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/config/SearchFieldLocation.java @@ -37,6 +37,6 @@ public enum SearchFieldLocation { @Override public String toString() { - return I18n.get("config.roughlyenoughitems.layout.searchFieldLocation.%s", name().toLowerCase(Locale.ROOT)); + return I18n.get("config.roughlyenoughitems.layout.searchFieldLocation.%s".formatted(name().toLowerCase(Locale.ROOT))); } } diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Label.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Label.java index b1d3c0bd9..3f0719bf2 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Label.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Label.java @@ -28,13 +28,11 @@ import me.shedaniel.math.Point; import me.shedaniel.rei.api.client.REIRuntime; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.FormattedText; -import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.function.Function; -import java.util.stream.Stream; public abstract class Label extends WidgetWithBounds { public static final int LEFT_ALIGNED = -1; diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Tooltip.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Tooltip.java index a9caf9577..3e10dd28c 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Tooltip.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Tooltip.java @@ -32,7 +32,6 @@ import me.shedaniel.rei.api.common.util.CollectionUtils; import me.shedaniel.rei.impl.ClientInternals; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; import net.minecraft.network.chat.Component; import net.minecraft.world.inventory.tooltip.TooltipComponent; import org.jetbrains.annotations.ApiStatus; diff --git a/api/src/main/java/me/shedaniel/rei/api/client/overlay/ScreenOverlay.java b/api/src/main/java/me/shedaniel/rei/api/client/overlay/ScreenOverlay.java index a45a854b7..f7f5c481e 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/overlay/ScreenOverlay.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/overlay/ScreenOverlay.java @@ -27,17 +27,15 @@ import me.shedaniel.rei.api.client.gui.drag.DraggingContext; import me.shedaniel.rei.api.client.gui.widgets.WidgetWithBounds; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import org.jetbrains.annotations.ApiStatus; import java.util.Optional; @Environment(EnvType.CLIENT) public abstract class ScreenOverlay extends WidgetWithBounds { - @ApiStatus.Internal - public abstract void closeOverlayMenu(); - public abstract void queueReloadOverlay(); + public abstract void queueReloadSearch(); + public abstract DraggingContext getDraggingContext(); public abstract boolean isNotInExclusionZones(double mouseX, double mouseY); diff --git a/api/src/main/java/me/shedaniel/rei/api/client/plugins/REIClientPlugin.java b/api/src/main/java/me/shedaniel/rei/api/client/plugins/REIClientPlugin.java index f3ff9408d..deeca9ff3 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/plugins/REIClientPlugin.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/plugins/REIClientPlugin.java @@ -33,6 +33,7 @@ import me.shedaniel.rei.api.client.registry.entry.EntryRegistry; import me.shedaniel.rei.api.client.registry.screen.ExclusionZones; 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.method.InputMethodRegistry; import me.shedaniel.rei.api.client.subsets.SubsetsRegistry; import me.shedaniel.rei.api.common.plugins.REIPlugin; import net.fabricmc.api.EnvType; @@ -145,6 +146,17 @@ public interface REIClientPlugin extends REIPlugin { default void registerConfigAddons(ConfigAddonRegistry registry) { } + /** + * Registers new input methods. + * + * @param registry the registry + * @since 8.3 + */ + @ApiStatus.OverrideOnly + @ApiStatus.Experimental + default void registerInputMethods(InputMethodRegistry registry) { + } + @Override default Class getPluginProviderClass() { return REIClientPlugin.class; diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/TransferHandler.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/TransferHandler.java index f1c6e7879..7974ddd7a 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/TransferHandler.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/TransferHandler.java @@ -27,12 +27,10 @@ import me.shedaniel.math.Point; import me.shedaniel.rei.api.client.gui.widgets.Tooltip; import me.shedaniel.rei.api.common.display.Display; import me.shedaniel.rei.api.common.entry.EntryIngredient; -import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.impl.ClientInternals; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.network.chat.Component; import net.minecraft.world.inventory.AbstractContainerMenu; diff --git a/api/src/main/java/me/shedaniel/rei/api/client/search/SearchProvider.java b/api/src/main/java/me/shedaniel/rei/api/client/search/SearchProvider.java index b31c4ee16..a337e5e17 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/search/SearchProvider.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/search/SearchProvider.java @@ -24,10 +24,12 @@ package me.shedaniel.rei.api.client.search; import me.shedaniel.rei.api.client.plugins.REIClientPlugin; +import me.shedaniel.rei.api.client.search.method.InputMethod; import me.shedaniel.rei.api.common.plugins.PluginManager; import me.shedaniel.rei.api.common.registry.Reloadable; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import org.jetbrains.annotations.ApiStatus; @Environment(EnvType.CLIENT) public interface SearchProvider extends Reloadable { @@ -39,8 +41,21 @@ public interface SearchProvider extends Reloadable { * Creates a search filter, which respects user's config options and * respects argument prefixes. * - * @param searchTerm the search term of the filter + * @param filter the search term of the filter * @return the search filter */ - SearchFilter createFilter(String searchTerm); + default SearchFilter createFilter(String filter) { + return createFilter(filter, InputMethod.active()); + } + + /** + * Creates a search filter, which respects user's config options and + * respects argument prefixes. + * + * @param filter the search term of the filter + * @param inputMethod the input method of the filter + * @return the search filter + */ + @ApiStatus.Experimental + SearchFilter createFilter(String filter, InputMethod inputMethod); } diff --git a/api/src/main/java/me/shedaniel/rei/api/client/search/method/CharacterUnpackingInputMethod.java b/api/src/main/java/me/shedaniel/rei/api/client/search/method/CharacterUnpackingInputMethod.java new file mode 100644 index 000000000..f14e1b334 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/client/search/method/CharacterUnpackingInputMethod.java @@ -0,0 +1,61 @@ +/* + * 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.api.client.search.method; + +import it.unimi.dsi.fastutil.ints.IntList; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.stream.Collectors; + +@ApiStatus.Experimental +public interface CharacterUnpackingInputMethod extends InputMethod { + List expendSourceChar(int codePoint); + + @Override + default boolean contains(String str, IntList substr) { + // This is implemented in the runtime + throw new UnsupportedOperationException(); + } + + @Override + @Nullable + default String suggestInputString(String str) { + return str.codePoints().mapToObj(c -> { + List chars = expendSourceChar(c); + String result; + if (chars.isEmpty()) return result = ((char) c) + ""; + result = chars.get(0).phonemes().stream() + .flatMap(integers -> integers.intStream().mapToObj(value -> ((char) value) + "")) + .collect(Collectors.joining()); + if (result.codePointCount(0, result.length()) == 1 && result.codePointAt(0) == c) { + return result; + } + return " " + result + " "; + }).collect(Collectors.joining()).trim().replace(" ", " "); + } + + record ExpendedChar(List phonemes) {} +} diff --git a/api/src/main/java/me/shedaniel/rei/api/client/search/method/InputMethod.java b/api/src/main/java/me/shedaniel/rei/api/client/search/method/InputMethod.java new file mode 100644 index 000000000..90e6ba092 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/client/search/method/InputMethod.java @@ -0,0 +1,68 @@ +/* + * 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.api.client.search.method; + +import me.shedaniel.rei.api.client.config.ConfigObject; +import me.shedaniel.rei.api.common.util.CollectionUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.network.chat.Component; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Executor; + +@ApiStatus.Experimental +public interface InputMethod { + static InputMethod active() { + return InputMethodRegistry.getInstance().getOrDefault(ConfigObject.getInstance().getInputMethodId()); + } + + static List getAllLocales() { + return CollectionUtils.map(Minecraft.getInstance().getLanguageManager().getLanguages(), info -> + new Locale(info.getCode(), Component.literal(info.getName()))); + } + + List getMatchingLocales(); + + Iterable expendFilter(String filter); + + boolean contains(String str, T substr); + + @Nullable + default String suggestInputString(String str) { + return null; + } + + CompletableFuture prepare(Executor executor); + + CompletableFuture dispose(Executor executor); + + Component getName(); + + Component getDescription(); + + record Locale(String code, Component name) {} +} diff --git a/api/src/main/java/me/shedaniel/rei/api/client/search/method/InputMethodRegistry.java b/api/src/main/java/me/shedaniel/rei/api/client/search/method/InputMethodRegistry.java new file mode 100644 index 000000000..357a182cd --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/client/search/method/InputMethodRegistry.java @@ -0,0 +1,49 @@ +/* + * 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.api.client.search.method; + +import me.shedaniel.rei.api.client.plugins.REIClientPlugin; +import me.shedaniel.rei.api.common.plugins.PluginManager; +import me.shedaniel.rei.api.common.registry.Reloadable; +import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; + +import java.util.Map; + +@ApiStatus.Experimental +public interface InputMethodRegistry extends Reloadable { + static InputMethodRegistry getInstance() { + return PluginManager.getClientInstance().get(InputMethodRegistry.class); + } + + void add(ResourceLocation id, InputMethod inputMethod); + + @Nullable + InputMethod get(@Nullable ResourceLocation id); + + InputMethod getOrDefault(@Nullable ResourceLocation id); + + Map> getAll(); +} diff --git a/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryIngredient.java b/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryIngredient.java index ae9925788..fd6302218 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryIngredient.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryIngredient.java @@ -31,7 +31,6 @@ import org.jetbrains.annotations.ApiStatus; import java.util.List; import java.util.function.Predicate; -import java.util.function.Supplier; import java.util.function.UnaryOperator; import java.util.stream.Collector; import java.util.stream.Collectors; diff --git a/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java b/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java index 6e3dbb673..485cfcfef 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java @@ -25,7 +25,6 @@ package me.shedaniel.rei.api.common.entry; import dev.architectury.utils.Env; import dev.architectury.utils.EnvExecutor; -import me.shedaniel.math.Point; import me.shedaniel.rei.api.client.config.ConfigObject; import me.shedaniel.rei.api.client.entry.renderer.EntryRenderer; import me.shedaniel.rei.api.client.entry.renderer.EntryRendererRegistry; @@ -50,7 +49,10 @@ import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import java.util.function.BiFunction; import java.util.function.Function; import java.util.stream.Stream; diff --git a/api/src/main/java/me/shedaniel/rei/api/common/entry/settings/EntrySettingsAdapter.java b/api/src/main/java/me/shedaniel/rei/api/common/entry/settings/EntrySettingsAdapter.java index 6a8506197..dc8ae19ed 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/entry/settings/EntrySettingsAdapter.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/entry/settings/EntrySettingsAdapter.java @@ -24,8 +24,6 @@ package me.shedaniel.rei.api.common.entry.settings; import me.shedaniel.rei.api.common.entry.EntryStack; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; diff --git a/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java b/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java index 44bb9da1f..c80e0dc25 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java @@ -421,4 +421,41 @@ public class CollectionUtils { public static Ingredient toIngredient(Iterable stacks) { return Ingredient.of(StreamSupport.stream(stacks.spliterator(), false)); } + + @SafeVarargs + public static List concatUnmodifiable(List... lists) { + return new ListConcatenationView<>(lists); + } + + /** + * A list which acts as view of the concatenation of a number of lists. + */ + private static class ListConcatenationView extends AbstractList { + private final List[] lists; + + @SafeVarargs + public ListConcatenationView(List... lists) { + this.lists = lists; + } + + @Override + public E get(int ix) { + int localIx = ix; + for (List l : lists) { + if (localIx < 0) throw new IndexOutOfBoundsException(ix); + if (localIx < l.size()) return l.get(localIx); + localIx -= l.size(); + } + return null; + } + + @Override + public int size() { + int size = 0; + for (List l : lists) { + size += l.size(); + } + return size; + } + } } diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java index d4c1877b3..e97098ea7 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java @@ -29,7 +29,6 @@ import com.google.common.collect.Sets; import dev.architectury.injectables.annotations.ExpectPlatform; import dev.architectury.injectables.annotations.PlatformOnly; import dev.architectury.platform.Platform; -import it.unimi.dsi.fastutil.objects.Object2FloatMap; import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet; import it.unimi.dsi.fastutil.objects.ReferenceSet; import me.shedaniel.math.Rectangle; @@ -79,7 +78,6 @@ import net.minecraft.client.gui.screens.inventory.*; import net.minecraft.client.gui.screens.recipebook.RecipeUpdateListener; import net.minecraft.core.Registry; import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.BlockTags; import net.minecraft.tags.ItemTags; @@ -90,7 +88,6 @@ import net.minecraft.world.item.alchemy.PotionBrewing; import net.minecraft.world.item.alchemy.PotionUtils; import net.minecraft.world.item.crafting.*; import net.minecraft.world.level.GameType; -import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.ComposterBlock; import net.minecraft.world.level.block.WeatheringCopper; diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/DefaultCompostingCategory.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/DefaultCompostingCategory.java index 4962c4394..83be73175 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/DefaultCompostingCategory.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/DefaultCompostingCategory.java @@ -49,7 +49,6 @@ import net.minecraft.world.level.block.ComposterBlock; import java.util.ArrayList; import java.util.List; -import java.util.Map; @Environment(EnvType.CLIENT) public class DefaultCompostingCategory implements DisplayCategory { diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/DefaultInformationCategory.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/DefaultInformationCategory.java index 8d8fbf8dd..1e9bab83f 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/DefaultInformationCategory.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/DefaultInformationCategory.java @@ -28,7 +28,6 @@ import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.*; import com.mojang.math.Matrix4f; import me.shedaniel.clothconfig2.ClothConfigInitializer; -import me.shedaniel.clothconfig2.api.ScissorsHandler; import me.shedaniel.clothconfig2.api.scroll.ScrollingContainer; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/beacon/DefaultBeaconBaseCategory.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/beacon/DefaultBeaconBaseCategory.java index 9ea7bc9aa..62874f976 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/beacon/DefaultBeaconBaseCategory.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/beacon/DefaultBeaconBaseCategory.java @@ -26,7 +26,6 @@ package me.shedaniel.rei.plugin.client.categories.beacon; import com.google.common.collect.Lists; import com.mojang.blaze3d.vertex.PoseStack; import me.shedaniel.clothconfig2.ClothConfigInitializer; -import me.shedaniel.clothconfig2.api.ScissorsHandler; import me.shedaniel.clothconfig2.api.scroll.ScrollingContainer; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/beacon/DefaultBeaconPaymentCategory.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/beacon/DefaultBeaconPaymentCategory.java index 478408619..6b19e142c 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/beacon/DefaultBeaconPaymentCategory.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/beacon/DefaultBeaconPaymentCategory.java @@ -26,7 +26,6 @@ package me.shedaniel.rei.plugin.client.categories.beacon; import com.google.common.collect.Lists; import com.mojang.blaze3d.vertex.PoseStack; import me.shedaniel.clothconfig2.ClothConfigInitializer; -import me.shedaniel.clothconfig2.api.ScissorsHandler; import me.shedaniel.clothconfig2.api.scroll.ScrollingContainer; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/GameModeFavoriteEntry.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/GameModeFavoriteEntry.java index b639e8f65..fba8a6ab2 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/GameModeFavoriteEntry.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/GameModeFavoriteEntry.java @@ -26,7 +26,6 @@ package me.shedaniel.rei.plugin.client.favorites; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.serialization.DataResult; import com.mojang.serialization.Lifecycle; -import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.REIRuntime; import me.shedaniel.rei.api.client.config.ConfigObject; diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/TimeFavoriteEntry.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/TimeFavoriteEntry.java index 2dc057a0d..7fc6c03e5 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/TimeFavoriteEntry.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/TimeFavoriteEntry.java @@ -27,7 +27,6 @@ import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.serialization.DataResult; import com.mojang.serialization.Lifecycle; -import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.REIRuntime; import me.shedaniel.rei.api.client.config.ConfigObject; diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/WeatherFavoriteEntry.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/WeatherFavoriteEntry.java index 80373285b..989549922 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/WeatherFavoriteEntry.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/favorites/WeatherFavoriteEntry.java @@ -27,7 +27,6 @@ import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.serialization.DataResult; import com.mojang.serialization.Lifecycle; -import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.REIRuntime; import me.shedaniel.rei.api.client.config.ConfigObject; diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultCompostingDisplay.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultCompostingDisplay.java index bbf31cb38..fb98fcc2a 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultCompostingDisplay.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultCompostingDisplay.java @@ -24,8 +24,6 @@ package me.shedaniel.rei.plugin.common.displays; import it.unimi.dsi.fastutil.objects.Object2FloatMap; -import org.jetbrains.annotations.ApiStatus; - import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.display.basic.BasicDisplay; import me.shedaniel.rei.api.common.entry.EntryIngredient; @@ -33,6 +31,7 @@ import me.shedaniel.rei.api.common.util.EntryIngredients; import me.shedaniel.rei.plugin.common.BuiltinPlugin; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.level.ItemLike; +import org.jetbrains.annotations.ApiStatus; import java.util.Arrays; import java.util.List; diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/tag/TagNode.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/tag/TagNode.java index 2dc2d0265..c2f796a27 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/tag/TagNode.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/tag/TagNode.java @@ -25,13 +25,13 @@ package me.shedaniel.rei.plugin.common.displays.tag; import net.minecraft.core.Holder; import net.minecraft.core.HolderSet; -import net.minecraft.resources.ResourceKey; import net.minecraft.tags.TagKey; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; -import java.util.*; -import java.util.stream.Collectors; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; @ApiStatus.Internal public abstract class TagNode { diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/tag/TagNodes.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/tag/TagNodes.java index 30d28785b..51113aea0 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/tag/TagNodes.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/tag/TagNodes.java @@ -32,7 +32,6 @@ import dev.architectury.utils.EnvExecutor; import io.netty.buffer.Unpooled; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntList; -import it.unimi.dsi.fastutil.objects.Reference2ObjectMap; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; diff --git a/gradle.properties b/gradle.properties index 9672274a3..b31b646e4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,6 +9,6 @@ fabricloader_version=0.14.6 cloth_config_version=7.0.73 modmenu_version=4.0.0 fabric_api=0.55.2+1.19 -architectury_version=5.9.30 +architectury_version=5.9.31 api_exculde= #api_include=me.shedaniel.cloth:cloth-events,me.shedaniel.cloth:config-2,me.sargunvohra.mcmods:autoconfig1u,org.jetbrains:annotations,net.fabricmc.fabric-api:fabric diff --git a/runtime/build.gradle b/runtime/build.gradle index 8feb90d1e..c9e4677bb 100644 --- a/runtime/build.gradle +++ b/runtime/build.gradle @@ -18,6 +18,12 @@ dependencies { modApi("dev.architectury:architectury:${architectury_version}") compileClasspath(annotationProcessor("org.projectlombok:lombok:1.18.22")) compileClasspath(project(path: ":api", configuration: "namedElements")) + testImplementation(project(path: ":api", configuration: "namedElements")) + testImplementation("org.junit.jupiter:junit-jupiter:5.8.2") +} + +test { + useJUnitPlatform() } remapJar { diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java index ac3d399ec..4c01ce177 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java @@ -73,6 +73,7 @@ import me.shedaniel.rei.impl.client.registry.category.CategoryRegistryImpl; import me.shedaniel.rei.impl.client.registry.display.DisplayRegistryImpl; import me.shedaniel.rei.impl.client.registry.screen.ScreenRegistryImpl; import me.shedaniel.rei.impl.client.search.SearchProviderImpl; +import me.shedaniel.rei.impl.client.search.method.InputMethodRegistryImpl; import me.shedaniel.rei.impl.client.subsets.SubsetsRegistryImpl; import me.shedaniel.rei.impl.client.transfer.TransferHandlerRegistryImpl; import me.shedaniel.rei.impl.client.view.ViewsImpl; @@ -224,6 +225,7 @@ public class RoughlyEnoughItemsCoreClient { }, new EntryRendererRegistryImpl(), new ViewsImpl(), + new InputMethodRegistryImpl(), new SearchProviderImpl(), new ConfigManagerImpl(), new EntryRegistryImpl(), diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java index 9258e3a08..01a2cd14c 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java @@ -30,7 +30,6 @@ import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.display.Display; import me.shedaniel.rei.impl.common.transfer.InputSlotCrafter; import net.minecraft.ChatFormatting; -import net.minecraft.Util; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; 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 16fafcbff..64f3a186c 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 @@ -82,6 +82,7 @@ import net.minecraft.network.chat.ClickEvent; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.HoverEvent; import net.minecraft.network.chat.TextColor; +import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; import net.minecraft.world.InteractionResult; import org.jetbrains.annotations.ApiStatus; @@ -138,6 +139,14 @@ public class ConfigManagerImpl implements ConfigManager { } private static Jankson buildJankson(Jankson.Builder builder) { + // ResourceLocation + builder.registerSerializer(ResourceLocation.class, (location, marshaller) -> { + return new JsonPrimitive(location == null ? null : location.toString()); + }); + builder.registerDeserializer(String.class, ResourceLocation.class, (value, marshaller) -> { + return value == null ? null : new ResourceLocation(value); + }); + // CheatingMode builder.registerSerializer(CheatingMode.class, (value, marshaller) -> { if (value == CheatingMode.WHEN_CREATIVE) { @@ -366,12 +375,12 @@ public class ConfigManagerImpl implements ConfigManager { if (Minecraft.getInstance().getConnection() != null && Minecraft.getInstance().getConnection().getRecipeManager() != null) { TextListEntry feedbackEntry = ConfigEntryBuilder.create().startTextDescription( Component.translatable("text.rei.feedback", Component.translatable("text.rei.feedback.link") - .withStyle(style -> style - .withColor(TextColor.fromRgb(0xff1fc3ff)) - .withUnderlined(true) - .withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://forms.gle/5tdnK5WN1wng78pV8")) - .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("https://forms.gle/5tdnK5WN1wng78pV8"))) - )) + .withStyle(style -> style + .withColor(TextColor.fromRgb(0xff1fc3ff)) + .withUnderlined(true) + .withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://forms.gle/5tdnK5WN1wng78pV8")) + .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("https://forms.gle/5tdnK5WN1wng78pV8"))) + )) .withStyle(ChatFormatting.GRAY) ).build(); builder.getOrCreateCategory(Component.translatable("config.roughlyenoughitems.advanced")).getEntries().add(0, feedbackEntry); @@ -389,19 +398,19 @@ public class ConfigManagerImpl implements ConfigManager { ((GlobalizedClothConfigScreen) screen).listWidget.children().add(0, (AbstractConfigEntry) new EmptyEntry(4)); TextListEntry supportText = ConfigEntryBuilder.create().startTextDescription( Component.translatable("text.rei.support.me.desc", - Component.translatable("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, Component.literal("https://patreon.com/shedaniel"))) - ), - Component.translatable("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, Component.literal("https://www.bisecthosting.com/shedaniel"))) - ) - ) + Component.translatable("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, Component.literal("https://patreon.com/shedaniel"))) + ), + Component.translatable("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, Component.literal("https://www.bisecthosting.com/shedaniel"))) + ) + ) .withStyle(ChatFormatting.GRAY) ).build(); supportText.setScreen((AbstractConfigScreen) screen); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java index 6cd6bd754..83964e65c 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java @@ -41,9 +41,11 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; import net.minecraft.world.level.GameType; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -206,6 +208,16 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData { return advanced.layout.maxRecipesPageHeight; } + @Override + @Nullable + public ResourceLocation getInputMethodId() { + return functionality.inputMethod; + } + + public void setInputMethodId(@Nullable ResourceLocation id) { + functionality.inputMethod = id; + } + @Override public boolean doesDisableRecipeBook() { return functionality.disableRecipeBook; @@ -600,6 +612,7 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData { } public static class Functionality { + @ConfigEntry.Gui.Excluded @Nullable private ResourceLocation inputMethod = null; @Comment("Declares whether REI should remove the recipe book.") private boolean disableRecipeBook = false; @Comment("Declares whether mob effects should be on the left side instead of the right side.") private boolean leftSideMobEffects = false; @Comment("Declares whether subsets is enabled.") private boolean isSubsetsEnabled = false; diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/addon/ConfigAddonsScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/addon/ConfigAddonsScreen.java index c04120eea..0fe6a4e85 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/addon/ConfigAddonsScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/addon/ConfigAddonsScreen.java @@ -28,6 +28,7 @@ import com.mojang.blaze3d.vertex.PoseStack; import me.shedaniel.clothconfig2.gui.widget.DynamicElementListWidget; import me.shedaniel.rei.api.client.config.addon.ConfigAddon; import me.shedaniel.rei.api.client.config.addon.ConfigAddonRegistry; +import me.shedaniel.rei.impl.client.gui.InternalTextures; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.events.GuiEventListener; @@ -41,8 +42,6 @@ import net.minecraft.resources.ResourceLocation; import java.util.Collections; import java.util.List; -import static me.shedaniel.rei.impl.client.gui.screen.DefaultDisplayViewingScreen.CHEST_GUI_TEXTURE; - public class ConfigAddonsScreen extends Screen { private AddonsList rulesList; private final Screen parent; @@ -143,7 +142,7 @@ public class ConfigAddonsScreen extends Screen { @Override protected void renderBg(PoseStack matrices, Minecraft client, int mouseX, int mouseY) { super.renderBg(matrices, client, mouseX, mouseY); - RenderSystem.setShaderTexture(0, CHEST_GUI_TEXTURE); + RenderSystem.setShaderTexture(0, InternalTextures.CHEST_GUI_TEXTURE); blit(matrices, x + 3, y + 3, 0, 0, 14, 14); } }; diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringRulesScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringRulesScreen.java index 9e4b311c2..d3da37ef2 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringRulesScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringRulesScreen.java @@ -28,6 +28,7 @@ import com.mojang.blaze3d.vertex.PoseStack; import me.shedaniel.clothconfig2.gui.widget.DynamicElementListWidget; import me.shedaniel.rei.impl.client.entry.filtering.FilteringRule; import me.shedaniel.rei.impl.client.entry.filtering.rules.ManualFilteringRule; +import me.shedaniel.rei.impl.client.gui.InternalTextures; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.events.GuiEventListener; @@ -45,8 +46,6 @@ import java.util.List; import java.util.Objects; import java.util.function.BiFunction; -import static me.shedaniel.rei.impl.client.gui.screen.DefaultDisplayViewingScreen.CHEST_GUI_TEXTURE; - public class FilteringRulesScreen extends Screen { private final FilteringEntry entry; private RulesList rulesList; @@ -191,7 +190,7 @@ public class FilteringRulesScreen extends Screen { @Override protected void renderBg(PoseStack matrices, Minecraft client, int mouseX, int mouseY) { super.renderBg(matrices, client, mouseX, mouseY); - RenderSystem.setShaderTexture(0, CHEST_GUI_TEXTURE); + RenderSystem.setShaderTexture(0, InternalTextures.CHEST_GUI_TEXTURE); blit(matrices, x + 3, y + 3, 0, 0, 14, 14); } }; 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 487b78895..ba0194978 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/ReloadPluginsEntry.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/ReloadPluginsEntry.java @@ -57,7 +57,7 @@ public class ReloadPluginsEntry extends AbstractConfigListEntry { public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { if (PluginManager.areAnyReloading()) { Screen screen = Minecraft.getInstance().screen; - Minecraft.getInstance().setScreen(new ConfigReloadingScreen(() -> Minecraft.getInstance().setScreen(screen))); + Minecraft.getInstance().setScreen(new ConfigReloadingScreen(Component.translatable("text.rei.config.is.reloading"), PluginManager::areAnyReloading, () -> Minecraft.getInstance().setScreen(screen))); } else { super.render(matrices, mouseX, mouseY, delta); } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/SearchFilterSyntaxHighlightingEntry.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/SearchFilterSyntaxHighlightingEntry.java index 1fc3a28bf..ed44ee5a8 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/SearchFilterSyntaxHighlightingEntry.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/SearchFilterSyntaxHighlightingEntry.java @@ -45,7 +45,9 @@ public class SearchFilterSyntaxHighlightingEntry extends TooltipListEntry save; - private final AbstractWidget buttonWidget = new Button(0, 0, 0, 20, NarratorChatListener.NO_TITLE, $ -> {}) { + private final AbstractWidget buttonWidget = new Button(0, 0, 0, 20, NarratorChatListener.NO_TITLE, $ -> { + type = SyntaxHighlightingMode.values()[(type.ordinal() + 1) % SyntaxHighlightingMode.values().length]; + }) { @Override public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { setMessage(Component.literal(type.toString())); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/type/types/RenderingEntryDefinition.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/type/types/RenderingEntryDefinition.java index 8936f4d61..a67cfe78e 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/type/types/RenderingEntryDefinition.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/type/types/RenderingEntryDefinition.java @@ -24,9 +24,7 @@ package me.shedaniel.rei.impl.client.entry.type.types; import com.mojang.blaze3d.vertex.PoseStack; -import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; -import me.shedaniel.math.impl.PointHelper; import me.shedaniel.rei.api.client.entry.renderer.EntryRenderer; import me.shedaniel.rei.api.client.entry.type.BuiltinClientEntryTypes; import me.shedaniel.rei.api.client.gui.Renderer; diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/favorites/FavoriteEntryTypeRegistryImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/favorites/FavoriteEntryTypeRegistryImpl.java index 1ae064940..47996d9d3 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/favorites/FavoriteEntryTypeRegistryImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/favorites/FavoriteEntryTypeRegistryImpl.java @@ -44,7 +44,6 @@ import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Map; diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/InternalTextures.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/InternalTextures.java new file mode 100644 index 000000000..4823008b6 --- /dev/null +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/InternalTextures.java @@ -0,0 +1,35 @@ +/* + * 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.gui; + +import net.minecraft.resources.ResourceLocation; + +public class InternalTextures { + public static final ResourceLocation ARROW_LEFT_TEXTURE = new ResourceLocation("roughlyenoughitems", "textures/gui/arrow_left.png"); + public static final ResourceLocation ARROW_RIGHT_TEXTURE = new ResourceLocation("roughlyenoughitems", "textures/gui/arrow_right.png"); + public static final ResourceLocation ARROW_LEFT_SMALL_TEXTURE = new ResourceLocation("roughlyenoughitems", "textures/gui/arrow_left_small.png"); + public static final ResourceLocation ARROW_RIGHT_SMALL_TEXTURE = new ResourceLocation("roughlyenoughitems", "textures/gui/arrow_right_small.png"); + public static final ResourceLocation CHEST_GUI_TEXTURE = new ResourceLocation("roughlyenoughitems", "textures/gui/recipecontainer.png"); + public static final ResourceLocation CHEST_GUI_TEXTURE_DARK = new ResourceLocation("roughlyenoughitems", "textures/gui/recipecontainer_dark.png"); +} 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 4451a8398..92229af76 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 @@ -27,27 +27,21 @@ import com.google.common.collect.Lists; import com.mojang.blaze3d.platform.Window; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.math.Vector4f; import dev.architectury.injectables.annotations.ExpectPlatform; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import me.shedaniel.math.impl.PointHelper; -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.favorites.Fa