Рендера текста

Версия Minecraft
1.20.1
API
Forge
здравствуйте, я пытаюсь рендерить текст в своей кнопке поверх других виджетов. я хочу что бы ее текст был всегда выше остальных вне зависимости от очереди рендера. как это сделать?
 
Решение
Java:
public class CustomButton extends ButtonWidget {
    @Override
    public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
        // Рендер фона кнопки
        super.renderWidget(guiGraphics, mouseX, mouseY, partialTick);
        
        // Рендер текста в отдельном слое
        guiGraphics.flush();
        RenderSystem.enableDepthTest();
        RenderSystem.depthFunc(GL11.GL_ALWAYS);
        
        PoseStack poseStack = guiGraphics.pose();
        poseStack.pushPose();
        poseStack.translate(0, 0, 999); //приоритет
        
        Font font = Minecraft.getInstance().font;
        int textWidth = font.width(this.getMessage());
        int textX = this.getX() + (this.width - textWidth)...
Java:
public class CustomButton extends ButtonWidget {
    @Override
    public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
        // Рендер фона кнопки
        super.renderWidget(guiGraphics, mouseX, mouseY, partialTick);
        
        // Рендер текста в отдельном слое
        guiGraphics.flush();
        RenderSystem.enableDepthTest();
        RenderSystem.depthFunc(GL11.GL_ALWAYS);
        
        PoseStack poseStack = guiGraphics.pose();
        poseStack.pushPose();
        poseStack.translate(0, 0, 999); //приоритет
        
        Font font = Minecraft.getInstance().font;
        int textWidth = font.width(this.getMessage());
        int textX = this.getX() + (this.width - textWidth) / 2;
        int textY = this.getY() + (this.height - 9) / 2;
        
        guiGraphics.drawString(font, this.getMessage(), textX, textY, 0xFFFFFF, false);
        
        poseStack.popPose();
        guiGraphics.flush();
        RenderSystem.depthFunc(GL11.GL_LEQUAL);
    }
}
 
Назад
Сверху