AE2 物品渲染钩子(AE2 Item Render Hook)

基本信息

属性 值
实现类 com.caedis.duradisplay.utils.AppEngItemRenderHook
AE2 API appeng.api.storage.IItemDisplayRegistry.ItemRenderHook
注册入口 AppEngItemRenderHook.init(),在 DuraDisplay.init 中调用
触发位置 AE2 Api.INSTANCE.registries().itemDisplay().addPostItemRenderHook(...)

功能

在 AE2 自己的物品渲染管线后追加一个 postItemRenderHook,让 AE2 GUI 中的物品也享受 DuraDisplay overlay。由于 AE2 不走原版 RenderItem.renderItemOverlayIntoGUI,单 mixin 重定向无法覆盖,必须额外注册 AE2 的 hook。

渲染行为

public boolean renderOverlay(FontRenderer fr, TextureManager tm, ItemStack is, int x, int y) {
    if (!DurabilityRenderer.Execute) return false;       // 在不应渲染的 GUI 内,让 AE2 走原版
    if (!DuraDisplayConfig.Enable) return false;          // 全局关闭
    DurabilityRenderer.Render(fr, is, x, y);             // 渲染所有 enabled 的 overlay
    return false;                                        // 不取消 AE2 自己的渲染
}
  • 返回 false:让 AE2 继续自己的渲染(不取消)
  • 不抛 NoClassDefFoundError:在 DuraDisplay.init 用 try/catch 包裹;AE2 不存在时仅记日志

showDurabilityItem 也重写:

public boolean showDurability(ItemStack is) {
    var item = is.getItem();
    if (item == null) return false;
    return !DuraDisplayConfig.Enable && item.showDurabilityBar(is);
}

含义:仅在 DuraDisplay 全局关闭时让 AE2 显示原版耐久度条;启用 DuraDisplay 时由 renderOverlay 自行渲染(且不显式拒绝 AE2 的耐久度条)。

init 触发点

@Mod.EventHandler
public void init(FMLInitializationEvent event) {
    if (FMLCommonHandler.instance().getSide().isClient()) {
        DuraDisplayConfig.loadConfig();
        FMLCommonHandler.instance().bus().register(this);
    }
    try {
        AppEngItemRenderHook.init();   // AE2 缺失时抛 NoClassDefFoundError
    } catch (NoClassDefFoundError e) {
        DuraDisplay.LOG.info("AE2 not found, skipping AppEngItemRenderHook");
    }
}

与 DurabilityRenderer.Execute 的关系

Execute 由 渲染系统 的两个 mixin(MixinGuiScreen、MixinGuiContainerCreative)控制:当处于原版 GuiScreen.drawScreen 或创造物品栏背景层期间,Execute=false,本 hook 立刻 return false,把渲染交还给 AE2,避免双重显示。

相关条目