添加1024并行处理单元
This commit is contained in:
parent
eca8879841
commit
b87d94dee1
|
|
@ -90,19 +90,9 @@ public final class InputEvents {
|
|||
|
||||
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 接口)
|
||||
// 通用获取显示名称(兼容物品/流体等)
|
||||
String name = JeiRuntimeProxy.getTypedIngredientDisplayName(typed);
|
||||
if (name == null || name.isEmpty()) return;
|
||||
|
||||
// 写入 AE2 终端的搜索框
|
||||
var screen = Minecraft.getInstance().screen;
|
||||
|
|
|
|||
|
|
@ -87,4 +87,30 @@ public final class JeiRuntimeProxy {
|
|||
// 兼容不同 JEI 版本或在启动阶段尚未就绪
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用获取 JEI 悬浮配料的本地化显示名称(适配物品/流体等)。
|
||||
* 若无法安全获取,则返回空字符串。
|
||||
*/
|
||||
public static <T> String getTypedIngredientDisplayName(ITypedIngredient<T> typed) {
|
||||
IJeiRuntime rt = RUNTIME;
|
||||
if (rt == null || typed == null) return "";
|
||||
try {
|
||||
var manager = rt.getIngredientManager();
|
||||
var helper = manager.getIngredientHelper(typed.getType());
|
||||
// JEI 的 IIngredientHelper#getDisplayName 返回 Component(新版本)或 String(旧版本)
|
||||
// 统一转为字符串,使用 toString() 兜底
|
||||
Object display = helper.getDisplayName(typed.getIngredient());
|
||||
if (display == null) return "";
|
||||
// 新版:net.minecraft.network.chat.Component
|
||||
if (display instanceof net.minecraft.network.chat.Component comp) {
|
||||
String s = comp.getString();
|
||||
return s == null ? "" : s;
|
||||
}
|
||||
String s = display.toString();
|
||||
return s == null ? "" : s;
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user