Skip to content

Instantly share code, notes, and snippets.

@izzyaxel
Created March 2, 2016 22:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save izzyaxel/1e9983c12cec7bfe0a3d to your computer and use it in GitHub Desktop.
Save izzyaxel/1e9983c12cec7bfe0a3d to your computer and use it in GitHub Desktop.
public class ManaHUD extends Gui
{
final ResourceLocation manaHUD = new ResourceLocation(AAReference.MODID, "textures/gui/hud/manaHUD.png");
final ResourceLocation manaHUDUnderlay = new ResourceLocation(AAReference.MODID, "textures/gui/hud/manaHUDUnderlays.png");
final Minecraft mc = Minecraft.getMinecraft();
final Tessellator tess = Tessellator.instance;
final float adj = 0.00390625F;
@SubscribeEvent()
public void onRender(RenderGameOverlayEvent event)
{
if(!event.isCancelable() && event.type == RenderGameOverlayEvent.ElementType.HOTBAR)
{
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
AAExtendedPlayer props = AAExtPlayerHelper.getIEEP(player);
if(props.hasLearnedAboutmana())
{
double scale = 0.6;
switch(Minecraft.getMinecraft().gameSettings.guiScale)
{
case 0:
scale = 0.5;
break;
case 1:
scale = 1.6;
break;
case 2:
scale = 0.9;
break;
case 3:
scale = 0.8;
break;
default:
break;
}
int xOffset = 4, yOffset = 4, border = 4, iconWidth = 32;
//Underlays
GL11.glPushMatrix();
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glScaled(scale, scale, scale);
GL11.glColor4d(1.0, 1.0, 1.0, 0.8);
this.mc.renderEngine.bindTexture(this.manaHUDUnderlay);
//System.out.print("W: " + props.getWhiteMana() + " U: " + props.getBlueMana() + " B: " + props.getBlackMana() + " G: " + props.getGreenMana() + " R: " + props.getRedMana() + "\r");
//White
AAVector2 lerpWVertsUL = AAVector2.lerpVertsAndUVs(new AAVector2(xOffset, yOffset), new AAVector2(xOffset, yOffset + iconWidth), ((float)props.getWhiteMana() / props.getMaxManaW()));
AAVector2 lerpWVertsUR = AAVector2.lerpVertsAndUVs(new AAVector2(xOffset + iconWidth, yOffset), new AAVector2(xOffset + iconWidth, yOffset + iconWidth), ((float)props.getWhiteMana() / props.getMaxManaW()));
AAVector2 lerpWUVsUL = AAVector2.lerpVertsAndUVs(new AAVector2(0, 0), new AAVector2(0, 32 * this.adj), ((float)props.getWhiteMana() / props.getMaxManaW()));
AAVector2 lerpWUVsUR = AAVector2.lerpVertsAndUVs(new AAVector2(32 * this.adj, 0), new AAVector2(32 * this.adj, 32 * this.adj), ((float)props.getWhiteMana() / props.getMaxManaW()));
//Blue
AAVector2 lerpUVertsUL = AAVector2.lerpVertsAndUVs(new AAVector2(xOffset, yOffset + iconWidth + border), new AAVector2(xOffset, yOffset + (iconWidth * 2) + border), ((float)props.getBlueMana() / props.getMaxManaU()));
AAVector2 lerpUVertsUR = AAVector2.lerpVertsAndUVs(new AAVector2(xOffset + iconWidth, yOffset + iconWidth + border), new AAVector2(xOffset + iconWidth, yOffset + (iconWidth * 2) + border), ((float)props.getBlueMana() / props.getMaxManaU()));
AAVector2 lerpUUVsUL = AAVector2.lerpVertsAndUVs(new AAVector2(32 * this.adj, 0), new AAVector2(32 * this.adj, 32 * this.adj), ((float)props.getBlueMana() / props.getMaxManaU()));
AAVector2 lerpUUVsUR = AAVector2.lerpVertsAndUVs(new AAVector2(64 * this.adj, 0), new AAVector2(64 * this.adj, 32 * this.adj), ((float)props.getBlueMana() / props.getMaxManaU()));
//Black
AAVector2 lerpBVertsUL = AAVector2.lerpVertsAndUVs(new AAVector2(xOffset, yOffset + (iconWidth * 2) + (border * 2)), new AAVector2(xOffset, yOffset + (iconWidth * 3) + (border * 2)), ((float)props.getBlackMana() / props.getMaxManaB()));
AAVector2 lerpBVertsUR = AAVector2.lerpVertsAndUVs(new AAVector2(xOffset + iconWidth, yOffset + (iconWidth * 2) + (border * 2)), new AAVector2(xOffset + iconWidth, yOffset + (iconWidth * 3) + (border * 2)), ((float)props.getBlackMana() / props.getMaxManaB()));
AAVector2 lerpBUVsUL = AAVector2.lerpVertsAndUVs(new AAVector2(64 * this.adj, 0), new AAVector2(64 * this.adj, 32 * this.adj), ((float)props.getBlackMana() / props.getMaxManaB()));
AAVector2 lerpBUVsUR = AAVector2.lerpVertsAndUVs(new AAVector2(96 * this.adj, 0), new AAVector2(96 * this.adj, 32 * this.adj), ((float)props.getBlackMana() / props.getMaxManaB()));
//Green
AAVector2 lerpGVertsUL = AAVector2.lerpVertsAndUVs(new AAVector2(xOffset, yOffset + (iconWidth * 3) + (border * 3)), new AAVector2(xOffset, yOffset + (iconWidth * 4) + (border * 3)), ((float)props.getGreenMana() / props.getMaxManaG()));
AAVector2 lerpGVertsUR = AAVector2.lerpVertsAndUVs(new AAVector2(xOffset + iconWidth, yOffset + (iconWidth * 3) + (border * 3)), new AAVector2(xOffset + iconWidth, yOffset + (iconWidth * 4) + (border * 3)), ((float)props.getGreenMana() / props.getMaxManaG()));
AAVector2 lerpGUVsUL = AAVector2.lerpVertsAndUVs(new AAVector2(96 * this.adj, 0), new AAVector2(96 * this.adj, 32 * this.adj), ((float)props.getGreenMana() / props.getMaxManaG()));
AAVector2 lerpGUVsUR = AAVector2.lerpVertsAndUVs(new AAVector2(128 * this.adj, 0), new AAVector2(128 * this.adj, 32 * this.adj), ((float)props.getGreenMana() / props.getMaxManaG()));
//Red
AAVector2 lerpRVertsUL = AAVector2.lerpVertsAndUVs(new AAVector2(xOffset, yOffset + (iconWidth * 4) + (border * 4)), new AAVector2(xOffset, yOffset + (iconWidth * 5) + (border * 4)), ((float)props.getRedMana() / props.getMaxManaR()));
AAVector2 lerpRVertsUR = AAVector2.lerpVertsAndUVs(new AAVector2(xOffset + iconWidth, yOffset + (iconWidth * 4) + (border * 4)), new AAVector2(xOffset + iconWidth, yOffset + (iconWidth * 5) + (border * 4)), ((float)props.getRedMana() / props.getMaxManaR()));
AAVector2 lerpRUVsUL = AAVector2.lerpVertsAndUVs(new AAVector2(128 * this.adj, 0), new AAVector2(128 * this.adj, 32 * this.adj), ((float)props.getRedMana() / props.getMaxManaR()));
AAVector2 lerpRUVsUR = AAVector2.lerpVertsAndUVs(new AAVector2(160 * this.adj, 0), new AAVector2(160 * this.adj, 32 * this.adj), ((float)props.getRedMana() / props.getMaxManaR()));
//White
this.tess.startDrawingQuads();
this.tess.addVertexWithUV(xOffset, yOffset + iconWidth, this.zLevel, 0 * this.adj, 32 * this.adj);
this.tess.addVertexWithUV(xOffset + iconWidth, yOffset + iconWidth, this.zLevel, 32 * this.adj, 32 * this.adj);
this.tess.addVertexWithUV(lerpWVertsUR.x, lerpWVertsUR.y, this.zLevel, lerpWUVsUR.x, lerpWUVsUR.y);
this.tess.addVertexWithUV(lerpWVertsUL.x, lerpWVertsUL.y, this.zLevel, lerpWUVsUL.x, lerpWUVsUL.y);
this.tess.draw();
//Blue
this.tess.startDrawingQuads();
this.tess.addVertexWithUV(xOffset, yOffset + border + (iconWidth * 2), this.zLevel, 32 * adj, 32 * adj);
this.tess.addVertexWithUV(xOffset + iconWidth, yOffset + border + (iconWidth * 2), this.zLevel, 64 * adj, 32 * adj);
this.tess.addVertexWithUV(lerpUVertsUR.x, lerpUVertsUR.y, this.zLevel, lerpUUVsUR.x, lerpUUVsUR.y);
this.tess.addVertexWithUV(lerpUVertsUL.x, lerpUVertsUL.y, this.zLevel, lerpUUVsUL.x, lerpUUVsUL.y);
this.tess.draw();
//Black
this.tess.startDrawingQuads();
this.tess.addVertexWithUV(xOffset, yOffset + (border * 2) + (iconWidth * 3), this.zLevel, 64 * adj, 32 * adj);
this.tess.addVertexWithUV(xOffset + iconWidth, yOffset + (border * 2) + (iconWidth * 3), this.zLevel, 96 * adj, 32 * adj);
this.tess.addVertexWithUV(lerpBVertsUR.x, lerpBVertsUR.y, this.zLevel, lerpBUVsUR.x, lerpBUVsUR.y);
this.tess.addVertexWithUV(lerpBVertsUL.x, lerpBVertsUL.y, this.zLevel, lerpBUVsUL.x, lerpBUVsUL.y);
this.tess.draw();
//Green
this.tess.startDrawingQuads();
this.tess.addVertexWithUV(xOffset, yOffset + (border * 3) + (iconWidth * 4), this.zLevel, 96 * adj, 32 * adj);
this.tess.addVertexWithUV(xOffset + iconWidth, yOffset + (border * 3) + (iconWidth * 4), this.zLevel, 128 * adj, 32 * adj);
this.tess.addVertexWithUV(lerpGVertsUR.x, lerpGVertsUR.y, this.zLevel, lerpGUVsUR.x, lerpGUVsUR.y);
this.tess.addVertexWithUV(lerpGVertsUL.x, lerpGVertsUL.y, this.zLevel, lerpGUVsUL.x, lerpGUVsUL.y);
this.tess.draw();
//Red
this.tess.startDrawingQuads();
this.tess.addVertexWithUV(xOffset, yOffset + (border * 4) + (iconWidth * 5), this.zLevel, 128 * adj, 32 * adj);
this.tess.addVertexWithUV(xOffset + iconWidth, yOffset + (border * 4) + (iconWidth * 5), this.zLevel, 160 * adj, 32 * adj);
this.tess.addVertexWithUV(lerpRVertsUR.x, lerpRVertsUR.y, this.zLevel, lerpRUVsUR.x, lerpRUVsUR.y);
this.tess.addVertexWithUV(lerpRVertsUL.x, lerpRVertsUL.y, this.zLevel, lerpRUVsUL.x, lerpRUVsUL.y);
this.tess.draw();
GL11.glPopMatrix();
//Icons
GL11.glPushMatrix();
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glScaled(scale, scale, scale);
GL11.glColor4d(1.0, 1.0, 1.0, 1.0);
this.mc.renderEngine.bindTexture(this.manaHUD);
//White
this.drawTexturedModalRect(xOffset, yOffset, 0, 0, iconWidth, iconWidth);
//Blue
this.drawTexturedModalRect(xOffset, yOffset + iconWidth + border, 32, 0, iconWidth, iconWidth);
//Black
this.drawTexturedModalRect(xOffset, yOffset + (iconWidth * 2) + (border * 2), 64, 0, iconWidth, iconWidth);
//Green
this.drawTexturedModalRect(xOffset, yOffset + (iconWidth * 3) + (border * 3), 96, 0, iconWidth, iconWidth);
//Red
this.drawTexturedModalRect(xOffset, yOffset + (iconWidth * 4) + (border * 4), 128, 0, iconWidth, iconWidth);
GL11.glPopMatrix();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment