aboutsummaryrefslogtreecommitdiff
path: root/runtime/src/main/java/me/shedaniel/rei/plugin
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/src/main/java/me/shedaniel/rei/plugin')
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultCategoryHandler.java3
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java2
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java18
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/InputMethodWatcher.java105
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/PluginStageExecutionWatcher.java5
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/SearchBarHighlightWatcher.java5
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/SearchFilterPrepareWatcher.java5
7 files changed, 137 insertions, 6 deletions
diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultCategoryHandler.java b/runtime/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultCategoryHandler.java
index b90c88707..228672384 100644
--- a/runtime/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultCategoryHandler.java
+++ b/runtime/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultCategoryHandler.java
@@ -42,7 +42,6 @@ import me.shedaniel.rei.api.common.transfer.info.MenuInfoRegistry;
import me.shedaniel.rei.api.common.transfer.info.MenuTransferException;
import me.shedaniel.rei.api.common.util.CollectionUtils;
import me.shedaniel.rei.api.common.util.EntryIngredients;
-import me.shedaniel.rei.api.common.util.EntryStacks;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
@@ -53,10 +52,8 @@ import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack;
-import net.minecraft.world.level.ItemLike;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.List;
@Environment(EnvType.CLIENT)
diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java
index 1309b9533..c53648ce7 100644
--- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java
+++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java
@@ -33,7 +33,6 @@ import dev.architectury.utils.Env;
import dev.architectury.utils.EnvExecutor;
import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet;
import it.unimi.dsi.fastutil.objects.ReferenceSet;
-import me.shedaniel.math.Point;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.client.entry.renderer.AbstractEntryRenderer;
import me.shedaniel.rei.api.client.entry.renderer.BatchedEntryRenderer;
@@ -66,7 +65,6 @@ import net.minecraft.tags.TagKey;
import net.minecraft.world.inventory.tooltip.TooltipComponent;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
-import net.minecraft.world.item.TooltipFlag;
import org.jetbrains.annotations.Nullable;
import java.util.List;
diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java
index 8fa55e5ba..95e77b334 100644
--- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java
+++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java
@@ -27,7 +27,7 @@ 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 dev.architectury.platform.Platform;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.RoughlyEnoughItemsCoreClient;
import me.shedaniel.rei.api.client.ClientHelper;
@@ -48,6 +48,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.util.ClientEntryStacks;
import me.shedaniel.rei.api.common.entry.EntryStack;
import me.shedaniel.rei.api.common.plugins.PluginManager;
@@ -59,6 +60,11 @@ import me.shedaniel.rei.impl.client.REIRuntimeImpl;
import me.shedaniel.rei.impl.client.gui.ScreenOverlayImpl;
import me.shedaniel.rei.impl.client.gui.screen.DefaultDisplayViewingScreen;
import me.shedaniel.rei.impl.client.gui.widget.favorites.FavoritesListWidget;
+import me.shedaniel.rei.impl.client.search.method.DefaultInputMethod;
+import me.shedaniel.rei.impl.client.search.method.unihan.BomopofoInputMethod;
+import me.shedaniel.rei.impl.client.search.method.unihan.JyutpingInputMethod;
+import me.shedaniel.rei.impl.client.search.method.unihan.PinyinInputMethod;
+import me.shedaniel.rei.impl.client.search.method.unihan.UniHanManager;
import me.shedaniel.rei.impl.common.entry.type.EntryRegistryImpl;
import me.shedaniel.rei.impl.common.entry.type.EntryRegistryListener;
import me.shedaniel.rei.plugin.autocrafting.DefaultCategoryHandler;
@@ -89,6 +95,7 @@ public class DefaultClientRuntimePlugin implements REIClientPlugin {
REIRuntimeImpl.getInstance().addHintProvider(watcher);
REIRuntimeImpl.getInstance().addHintProvider(new SearchBarHighlightWatcher());
REIRuntimeImpl.getInstance().addHintProvider(new SearchFilterPrepareWatcher());
+ REIRuntimeImpl.getInstance().addHintProvider(new InputMethodWatcher());
}
@Override
@@ -163,6 +170,15 @@ public class DefaultClientRuntimePlugin implements REIClientPlugin {
registry.register(new DefaultCategoryHandler());
}
+ @Override
+ public void registerInputMethods(InputMethodRegistry registry) {
+ registry.add(DefaultInputMethod.ID, DefaultInputMethod.INSTANCE);
+ UniHanManager manager = new UniHanManager(Platform.getConfigFolder().resolve("roughlyenoughitems/unihan.zip"));
+ registry.add(new ResourceLocation("rei:pinyin"), new PinyinInputMethod(manager));
+ registry.add(new ResourceLocation("rei:jyutping"), new JyutpingInputMethod(manager));
+ registry.add(new ResourceLocation("rei:bomopofo"), new BomopofoInputMethod(manager));
+ }
+
private enum EntryStackFavoriteType implements FavoriteEntryType<EntryStackFavoriteEntry> {
INSTANCE(FavoriteEntryType.ENTRY_STACK);
diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/InputMethodWatcher.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/InputMethodWatcher.java
new file mode 100644
index 000000000..071f11cbc
--- /dev/null
+++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/InputMethodWatcher.java
@@ -0,0 +1,105 @@
+/*
+ * 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.plugin.client.runtime;
+
+import me.shedaniel.math.Color;
+import me.shedaniel.math.Point;
+import me.shedaniel.rei.api.client.config.ConfigManager;
+import me.shedaniel.rei.api.client.config.ConfigObject;
+import me.shedaniel.rei.api.client.gui.widgets.Tooltip;
+import me.shedaniel.rei.api.client.search.method.InputMethod;
+import me.shedaniel.rei.api.client.search.method.InputMethodRegistry;
+import me.shedaniel.rei.api.common.plugins.PluginManager;
+import me.shedaniel.rei.api.common.util.CollectionUtils;
+import me.shedaniel.rei.impl.client.config.ConfigManagerImpl;
+import me.shedaniel.rei.impl.client.gui.ScreenOverlayImpl;
+import me.shedaniel.rei.impl.client.gui.hints.HintProvider;
+import me.shedaniel.rei.impl.client.gui.modules.MenuAccess;
+import me.shedaniel.rei.impl.client.gui.widget.CraftableFilterButtonWidget;
+import me.shedaniel.rei.impl.client.gui.widget.search.OverlaySearchField;
+import me.shedaniel.rei.impl.client.search.method.DefaultInputMethod;
+import net.minecraft.client.Minecraft;
+import net.minecraft.network.chat.Component;
+import net.minecraft.network.chat.MutableComponent;
+import net.minecraft.resources.ResourceLocation;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.Collections;
+import java.util.List;
+
+public class InputMethodWatcher implements HintProvider {
+ @Override
+ public List<Component> provide() {
+ if (PluginManager.areAnyReloading() || OverlaySearchField.isHighlighting) return Collections.emptyList();
+ ResourceLocation id = ConfigObject.getInstance().getInputMethodId();
+ if (id == null) {
+ String languageCode = Minecraft.getInstance().options.languageCode;
+ MutableComponent component = Component.empty();
+ int match = 0;
+ for (InputMethod<?> method : InputMethodRegistry.getInstance().getAll().values()) {
+ if (method instanceof DefaultInputMethod) continue;
+ if (CollectionUtils.anyMatch(method.getMatchingLocales(), locale -> locale.code().equals(languageCode))) {
+ if (!component.getString().isEmpty()) {
+ component.append(", ");
+ }
+
+ component.append(method.getName());
+ match++;
+ }
+ }
+ if (match > 0) {
+ return List.of(Component.translatable("text.rei.input.methods.hint"),
+ Component.literal(" "), component);
+ }
+ }
+
+ return Collections.emptyList();
+ }
+
+ @Override
+ @Nullable
+ public Tooltip provideTooltip(Point mouse) {
+ return null;
+ }
+
+ @Override
+ public Color getColor() {
+ return Color.ofTransparent(0x50ffadca);
+ }
+
+ @Override
+ public List<HintButton> getButtons() {
+ return List.of(
+ new HintButton(Component.translatable("text.rei.input.methods.hint.configure"), bounds -> {
+ MenuAccess access = ScreenOverlayImpl.getInstance().menuAccess();
+ access.openOrClose(CraftableFilterButtonWidget.FILTER_MENU_UUID, bounds.clone(),
+ () -> CraftableFilterButtonWidget.createInputMethodEntries(CraftableFilterButtonWidget.getApplicableInputMethods()));
+ }),
+ new HintButton(Component.translatable("text.rei.input.methods.hint.ignore"), bounds -> {
+ ConfigManagerImpl.getInstance().getConfig().setInputMethodId(new ResourceLocation("rei:default"));
+ ConfigManager.getInstance().saveConfig();
+ })
+ );
+ }
+}
diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/PluginStageExecutionWatcher.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/PluginStageExecutionWatcher.java
index e0f999645..82a1bf512 100644
--- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/PluginStageExecutionWatcher.java
+++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/PluginStageExecutionWatcher.java
@@ -222,4 +222,9 @@ public class PluginStageExecutionWatcher implements HintProvider {
public Color getColor() {
return Color.ofTransparent(0x50ff1500);
}
+
+ @Override
+ public List<HintButton> getButtons() {
+ return Collections.emptyList();
+ }
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/SearchBarHighlightWatcher.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/SearchBarHighlightWatcher.java
index eaa9f0bfa..312a2e787 100644
--- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/SearchBarHighlightWatcher.java
+++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/SearchBarHighlightWatcher.java
@@ -51,4 +51,9 @@ public class SearchBarHighlightWatcher implements HintProvider {
public Color getColor() {
return Color.ofTransparent(0x50f7ed23);
}
+
+ @Override
+ public List<HintButton> getButtons() {
+ return Collections.emptyList();
+ }
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/SearchFilterPrepareWatcher.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/SearchFilterPrepareWatcher.java
index 75fcf95b3..1bc99287f 100644
--- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/SearchFilterPrepareWatcher.java
+++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/SearchFilterPrepareWatcher.java
@@ -82,4 +82,9 @@ public class SearchFilterPrepareWatcher implements HintProvider {
public Color getColor() {
return Color.ofTransparent(0x50de38ff);
}
+
+ @Override
+ public List<HintButton> getButtons() {
+ return Collections.emptyList();
+ }
}