I'm trying to create a HUD overlay to display a timer to the player. However whenever it is rendering it causes the vanilla overlay to do THIS. The player is in survival in that image, and no matter the status effect they look the same. If I remove the lines for drawing text, then the second image is the result. I think the issue may be binding the texture, but given the results of the text drawing I have no idea. Any help here is appreciated this has got me stumped for the past 2 days or so.
This is the code for the GuiHUDCoro class.
@SideOnly(Side.CLIENT)
public class GuiHUDCoro extends Gui {
private boolean showGui = true;
private int overlayW = 138;
private int overlayH = 29;
private int barW = 118;
private int barH = 16;
private int barOffx = 10;
private int barOffy = 6;
private static ResourceLocation backgroundLocation = new ResourceLocation("corolis:textures/gui/overlay.png");
/** Minecraft instance */
protected Minecraft mc = Minecraft.getMinecraft();
public int chatOffset = 0;
//packeted field from packet
public static int timeRemain = 0;
public static int currMax = 0;
public static int sync = 0;
@SubscribeEvent
public void renderOverlay(RenderGameOverlayEvent event)
{
if(timeRemain > 0)
{
GlStateManager.enableAlpha();
mc.getTextureManager().bindTexture(backgroundLocation);
this.zLevel = 0.0f;
drawTexturedModalRect((event.getResolution().getScaledWidth() / 2) - (overlayW / 2), 0, 0, 0, overlayW, overlayH);
//mc.getTextureManager().bindTexture(backgroundLocation);
int i = getTimeScale(barW);
drawTexturedModalRect((event.getResolution().getScaledWidth() / 2) - (overlayW / 2) + barOffx + (barW - i), barOffy, barW - i, 29, i, barH);
//mc.getTextureManager().bindTexture(backgroundLocation);
drawTexturedModalRect((event.getResolution().getScaledWidth() / 2) - (overlayW / 2) + barOffx, barOffy, 0, 45, barW, barH);
this.zLevel = 20.0f;
String s = parseTime();
mc.fontRenderer.drawString(s, (event.getResolution().getScaledWidth() / 2) - mc.fontRenderer.getStringWidth(s) / 2, 10, Integer.parseInt("FFFFFF", 16), true);
mc.fontRenderer.drawString(parseMaxTime(), (event.getResolution().getScaledWidth() / 2) + 74, 3, Integer.parseInt("FFFFFF", 16), true);
}
sync++;
sync %= 10;
if (sync == 0) {
PacketHandler.INSTANCE.sendToServer(new PacketTimeUpdateRequest("com.aubrithehuman.corolis.gui.GuiHUDCoro", "timeRemain", "currMax"));
//System.out.println(timeRemain + " | " + currMax);
}
}
private int getTimeScale(int pixels)
{
int i = currMax;
if (i == 0)
{
i = 18000;
}
return timeRemain * pixels / i +1;
}
private String parseTime() {
String s = String.format("%02d:%02d", (int) timeRemain / 1200, (int) (timeRemain - ((int) (timeRemain / 1200) * 1200)) / 20, timeRemain);
return s;
}
private String parseMaxTime() {
String s = String.format("Max: %02d:%02d", (int) currMax / 1200, (int) (currMax - ((int) (currMax / 1200) * 1200)) / 20, currMax);
return s;
}
}
I have registered the render event with the event bus, is there anywhere else I should have registered it? Given its a Gui and not a GuiScreen I don't know if that was necessary.