use of hellfirepvp.astralsorcery.common.item.base.AlignmentChargeConsumer in project AstralSorcery by HellFirePvP.
the class AlignmentChargeRenderer method onRenderOverlay.
private void onRenderOverlay(RenderGameOverlayEvent.Post event) {
if (event.getType() != RenderGameOverlayEvent.ElementType.ALL) {
return;
}
if (Minecraft.getInstance().playerController != null && Minecraft.getInstance().playerController.getCurrentGameType() == GameType.SPECTATOR) {
return;
}
if (this.alphaReveal <= 0) {
return;
}
MatrixStack renderStack = event.getMatrixStack();
MainWindow window = event.getWindow();
int screenWidth = window.getScaledWidth();
int screenHeight = window.getScaledHeight();
int barWidth = 194;
int offsetLeft = screenWidth / 2 - barWidth / 2;
// *sigh* vanilla
int offsetTop = screenHeight + 3 - 81;
PlayerEntity player = Minecraft.getInstance().player;
float percFilled = AlignmentChargeHandler.INSTANCE.getFilledPercentage(player, LogicalSide.CLIENT);
boolean hasEnoughCharge = true;
float usagePerc = 0F;
for (EquipmentSlotType type : EquipmentSlotType.values()) {
ItemStack equipped = player.getItemStackFromSlot(type);
if (!equipped.isEmpty() && equipped.getItem() instanceof AlignmentChargeConsumer) {
float chargeRequired = ((AlignmentChargeConsumer) equipped.getItem()).getAlignmentChargeCost(player, equipped);
float max = AlignmentChargeHandler.INSTANCE.getMaximumCharge(player, LogicalSide.CLIENT);
usagePerc = Math.min(chargeRequired / max, percFilled);
hasEnoughCharge = percFilled > usagePerc;
percFilled -= usagePerc;
break;
}
}
Tuple<Float, Float> uvColored = SpritesAS.SPR_OVERLAY_CHARGE.getUVOffset();
Tuple<Float, Float> uvColorless = SpritesAS.SPR_OVERLAY_CHARGE.getUVOffset();
float width = barWidth * percFilled;
float usageWidth = barWidth * usagePerc;
float uLengthCharge = SpritesAS.SPR_OVERLAY_CHARGE.getULength() * percFilled;
float uLengthUsage = SpritesAS.SPR_OVERLAY_CHARGE_COLORLESS.getULength() * usagePerc;
Color usageColor = hasEnoughCharge ? ColorsAS.OVERLAY_CHARGE_USAGE : ColorsAS.OVERLAY_CHARGE_MISSING;
RenderSystem.enableBlend();
RenderSystem.disableAlphaTest();
SpritesAS.SPR_OVERLAY_CHARGE.bindTexture();
RenderingUtils.draw(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR_TEX, buf -> {
RenderingGuiUtils.rect(buf, renderStack, offsetLeft, offsetTop, 10, width, 54).color(1F, 1F, 1F, this.alphaReveal).tex(uvColored.getA(), uvColored.getB() + 0.002F, uLengthCharge, SpritesAS.SPR_OVERLAY_CHARGE.getVWidth() - 0.002F).draw();
});
SpritesAS.SPR_OVERLAY_CHARGE_COLORLESS.bindTexture();
RenderingUtils.draw(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR_TEX, buf -> {
RenderingGuiUtils.rect(buf, renderStack, offsetLeft + width, offsetTop, 10, usageWidth, 54).color(usageColor.getRed(), usageColor.getGreen(), usageColor.getBlue(), (int) (this.alphaReveal * 255F)).tex(uvColorless.getA() + uLengthCharge, uvColorless.getB() + 0.002F, uLengthUsage, SpritesAS.SPR_OVERLAY_CHARGE_COLORLESS.getVWidth() - 0.002F).draw();
});
RenderSystem.enableAlphaTest();
RenderSystem.disableBlend();
BlockAtlasTexture.getInstance().bindTexture();
}
Aggregations