要在Minecraft 1.12.2 Forge mod中添加一个状态栏到玩家属性中,你需要执行以下步骤:

  1. 创建一个新的类来处理状态栏的更新和渲染。你可以命名为"CustomStatusBar"或者其他适合的名称。
public class CustomStatusBar {
    private static final ResourceLocation TEXTURE = new ResourceLocation("modid", "textures/gui/status_bar.png");

    public static void renderStatusBar(ScaledResolution resolution, int x, int y, float current, float max) {
        Minecraft mc = Minecraft.getMinecraft();
        mc.getTextureManager().bindTexture(TEXTURE);

        // 渲染状态栏的背景
        mc.ingameGUI.drawTexturedModalRect(x, y, 0, 0, 100, 10);

        // 渲染状态栏的当前值
        int width = (int) (current / max * 100);
        mc.ingameGUI.drawTexturedModalRect(x, y, 0, 10, width, 10);
    }
}
  1. 在你的mod的主类中注册一个事件监听器来处理状态栏的渲染。你可以在preInit或者init方法中添加以下代码:
public class YourModMainClass {
    @Mod.EventHandler
    public void init(FMLInitializationEvent event) {
        MinecraftForge.EVENT_BUS.register(this);
    }

    @SubscribeEvent
    public void onRenderGameOverlay(RenderGameOverlayEvent.Post event) {
        if (event.getType() == RenderGameOverlayEvent.ElementType.FOOD) {
            ScaledResolution resolution = new ScaledResolution(Minecraft.getMinecraft());
            CustomStatusBar.renderStatusBar(resolution, 10, 10, player.getFoodStats().getFoodLevel(), 20);
        }
    }
}

上述代码假设你是在渲染食物状态栏后渲染你的自定义状态栏。你可以根据需要选择其他的游戏界面元素。

  1. 创建一个状态栏的纹理图像(status_bar.png),并将其放置在你的mod的资源文件夹下的textures/gui目录中。

  2. 编译并运行你的mod。

这样,你的mod就会在玩家属性栏中添加一个自定义状态栏了。你可以根据需要进行进一步的修改和美化

Minecraft 1122 stable-39 Forge mod制作添加一个状态条在玩家属性里

原文地址: http://www.cveoy.top/t/topic/iy9b 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录