添加f键自动在ae搜索功能
This commit is contained in:
parent
e109b843f0
commit
3b9ff09ac4
|
|
@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx1G
|
|||
loom.platform = forge
|
||||
|
||||
# Mod properties
|
||||
mod_version = 1.3.2
|
||||
mod_version = 1.3.2-beta
|
||||
maven_group = com.extendedae_plus
|
||||
archives_name = extendedae_plus
|
||||
|
||||
|
|
|
|||
|
|
@ -13,11 +13,16 @@ import com.extendedae_plus.network.PullFromJeiOrCraftC2SPacket;
|
|||
import appeng.api.stacks.GenericStack;
|
||||
import appeng.integration.modules.jei.GenericEntryStackHelper;
|
||||
import mezz.jei.api.ingredients.ITypedIngredient;
|
||||
import mezz.jei.api.constants.VanillaTypes;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.ScreenEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import appeng.client.gui.me.common.MEStorageScreen;
|
||||
import com.extendedae_plus.mixin.accessor.MEStorageScreenAccessor;
|
||||
|
||||
@Mod.EventBusSubscriber(modid = ExtendedAEPlus.MODID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.FORGE)
|
||||
public final class InputEvents {
|
||||
|
|
@ -76,4 +81,42 @@ public final class InputEvents {
|
|||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onKeyPressedPre(ScreenEvent.KeyPressed.Pre event) {
|
||||
if (event.getKeyCode() != GLFW.GLFW_KEY_F) return;
|
||||
|
||||
// 仅当鼠标确实悬停在 JEI 配料上时触发
|
||||
Optional<ITypedIngredient<?>> hovered = JeiRuntimeProxy.getIngredientUnderMouse();
|
||||
if (hovered.isEmpty()) return;
|
||||
|
||||
ITypedIngredient<?> typed = hovered.get();
|
||||
|
||||
String name = null;
|
||||
try {
|
||||
if (typed.getType() == VanillaTypes.ITEM_STACK) {
|
||||
//noinspection unchecked
|
||||
ItemStack stack = ((ITypedIngredient<ItemStack>) typed).getIngredient();
|
||||
if (stack != null) {
|
||||
name = stack.getHoverName().getString();
|
||||
}
|
||||
}
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
|
||||
if (name == null || name.isEmpty()) return; // 非物品类型暂不处理(避免依赖未知 JEI 接口)
|
||||
|
||||
// 写入 AE2 终端的搜索框
|
||||
var screen = Minecraft.getInstance().screen;
|
||||
if (screen instanceof MEStorageScreen<?> me) {
|
||||
try {
|
||||
MEStorageScreenAccessor acc = (MEStorageScreenAccessor) (Object) me;
|
||||
acc.ext$getSearchField().setValue(name);
|
||||
acc.ext$setSearchText(name); // 同步到 Repo 并刷新
|
||||
event.setCanceled(true);
|
||||
return;
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,4 +74,18 @@ public final class JeiRuntimeProxy {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将文本写入 JEI 的搜索过滤框。
|
||||
* 若 JEI runtime 不可用则静默返回。
|
||||
*/
|
||||
public static void setIngredientFilterText(String text) {
|
||||
IJeiRuntime rt = RUNTIME;
|
||||
if (rt == null) return;
|
||||
try {
|
||||
rt.getIngredientFilter().setFilterText(text == null ? "" : text);
|
||||
} catch (Throwable ignored) {
|
||||
// 兼容不同 JEI 版本或在启动阶段尚未就绪
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
package com.extendedae_plus.mixin.accessor;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
|
||||
import appeng.client.gui.me.common.MEStorageScreen;
|
||||
import appeng.client.gui.widgets.AETextField;
|
||||
|
||||
@Mixin(value = MEStorageScreen.class, remap = false)
|
||||
public interface MEStorageScreenAccessor {
|
||||
@Accessor("searchField")
|
||||
AETextField ext$getSearchField();
|
||||
|
||||
@Invoker("setSearchText")
|
||||
void ext$setSearchText(String text);
|
||||
}
|
||||
|
|
@ -15,7 +15,8 @@
|
|||
"ae2.QuartzCuttingKnifeItemMixin",
|
||||
"accessor.AEBaseScreenAccessor",
|
||||
"accessor.AbstractContainerScreenAccessor",
|
||||
"accessor.ScreenAccessor"
|
||||
"accessor.ScreenAccessor",
|
||||
"accessor.MEStorageScreenAccessor"
|
||||
],
|
||||
"mixins": [
|
||||
"ContainerExPatternProviderMixin",
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user