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);
}
}