F键搜索改成按键注册

This commit is contained in:
GaLi 2026-03-02 11:25:45 +08:00
parent 9b4212dda8
commit 12441c80ba
6 changed files with 73 additions and 2 deletions

View File

@ -101,7 +101,10 @@ public final class InputEvents {
return;
}
// 注意不要在 try/catch 之外直接访问 JEI 运行时避免类加载崩溃
if (event.getKeyCode() != GLFW.GLFW_KEY_F) return;
// 检查是否按下了填充搜索框的快捷键
if (!ModKeybindings.FILL_SEARCH_KEY.matches(event.getKeyCode(), event.getScanCode())) {
return;
}
// 仅当鼠标确实悬停在 JEI 配料上时触发
try {

View File

@ -24,6 +24,17 @@ public final class ModKeybindings {
"key.categories.extendedae_plus" // 分类
);
/**
* 填充JEI物品名称到搜索框快捷键
*/
public static final KeyMapping FILL_SEARCH_KEY = new KeyMapping(
"key.extendedae_plus.fill_search", // 翻译键
KeyConflictContext.GUI, // 仅在GUI中生效
InputConstants.Type.KEYSYM, // 键盘按键类型
GLFW.GLFW_KEY_F, // F 默认
"key.categories.extendedae_plus" // 分类
);
/**
* 注册所有快捷键
*
@ -31,5 +42,6 @@ public final class ModKeybindings {
*/
public static void register(net.minecraftforge.client.event.RegisterKeyMappingsEvent event) {
event.register(CREATE_PATTERN_KEY);
event.register(FILL_SEARCH_KEY);
}
}

View File

@ -0,0 +1,50 @@
package com.extendedae_plus.util;
import net.minecraft.world.item.ItemStack;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
/**
* 临时样板存储
* 用于在用户选择供应器之前临时保存创建的样板
*/
public class TempPatternStorage {
private static final Map<UUID, ItemStack> TEMP_PATTERNS = new ConcurrentHashMap<>();
/**
* 存储临时样板
* @param playerId 玩家UUID
* @param pattern 样板物品
*/
public static void store(UUID playerId, ItemStack pattern) {
TEMP_PATTERNS.put(playerId, pattern.copy());
}
/**
* 获取并移除临时样板
* @param playerId 玩家UUID
* @return 样板物品如果不存在返回空
*/
public static ItemStack retrieve(UUID playerId) {
return TEMP_PATTERNS.remove(playerId);
}
/**
* 检查是否有临时样板
* @param playerId 玩家UUID
* @return 是否存在
*/
public static boolean has(UUID playerId) {
return TEMP_PATTERNS.containsKey(playerId);
}
/**
* 清除玩家的临时样板
* @param playerId 玩家UUID
*/
public static void clear(UUID playerId) {
TEMP_PATTERNS.remove(playerId);
}
}

View File

@ -237,5 +237,6 @@
"message.extendedae_plus.pattern_created": "Created pattern: %s",
"key.extendedae_plus.create_pattern": "Create Pattern from JEI",
"key.extendedae_plus.fill_search": "Fill Search Field from JEI",
"key.categories.extendedae_plus": "ExtendedAE Plus"
}

View File

@ -236,5 +236,6 @@
"message.extendedae_plus.pattern_created": "已创建样板: %s",
"key.extendedae_plus.create_pattern": "从JEI创建样板",
"key.extendedae_plus.fill_search": "从JEI填充搜索框",
"key.categories.extendedae_plus": "ExtendedAE Plus"
}

View File

@ -226,5 +226,9 @@
"extendedae_plus.command.server_side_only": "此命令必須在伺服器端執行",
"extendedae_plus.command.storage_manager_not_initialized": "InfinityStorageManager未初始化",
"extendedae_plus.command.gave_infinity_disks": "已發放 %s 個無限磁碟",
"extendedae_plus.command.error": "錯誤: %s"
"extendedae_plus.command.error": "錯誤: %s",
"key.extendedae_plus.create_pattern": "从JEI创建样板",
"key.extendedae_plus.fill_search": "从JEI填充搜索框",
"key.categories.extendedae_plus": "ExtendedAE Plus"
}