Skip to content

Commit

Permalink
Add heart icons to health bars.
Browse files Browse the repository at this point in the history
  • Loading branch information
Provismet committed Nov 28, 2023
1 parent b627b63 commit 0979632
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/main/java/com/provismet/provihealth/hud/TargetHealthBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

public class TargetHealthBar implements HudRenderCallback {
private static final Identifier BARS = ProviHealthClient.identifier("textures/gui/healthbars/bars.png");
private static final Identifier HEART = new Identifier("hud/heart/full");
private static final Identifier VEHICLE_HEART = new Identifier("hud/heart/vehicle_full");

private static final int BAR_WIDTH = 128;
private static final int BAR_HEIGHT = 10;
private static final int MOUNT_BAR_HEIGHT = 6;
Expand Down Expand Up @@ -84,7 +87,20 @@ public void onHudRender (DrawContext drawContext, float tickDelta) {

drawContext.drawTexture(BorderRegistry.getBorder(target.getGroup()), 0, 0, FRAME_LENGTH, FRAME_LENGTH, 48f, 0f, FRAME_LENGTH, FRAME_LENGTH, FRAME_LENGTH * 2, FRAME_LENGTH); // Portrait Background
drawContext.drawText(MinecraftClient.getInstance().textRenderer, target.getName(), FRAME_LENGTH, BAR_Y - BAR_HEIGHT, 0xFFFFFF, true); // Name
drawContext.drawText(MinecraftClient.getInstance().textRenderer, String.format("%d/%d", Math.round(this.target.getHealth()), Math.round(this.target.getMaxHealth())), FRAME_LENGTH, BAR_Y + BAR_HEIGHT + (vehicleMaxHealthDeep > 0f ? MOUNT_BAR_HEIGHT : 0) + 2, 0xFFFFFF, true); // Health Value
int healthX = drawContext.drawText(MinecraftClient.getInstance().textRenderer, String.format("%d/%d", Math.round(this.target.getHealth()), Math.round(this.target.getMaxHealth())), FRAME_LENGTH, BAR_Y + BAR_HEIGHT + (vehicleMaxHealthDeep > 0f ? MOUNT_BAR_HEIGHT : 0) + 2, 0xFFFFFF, true); // Health Value
drawContext.drawGuiTexture(HEART, healthX, BAR_Y + BAR_HEIGHT + (vehicleMaxHealthDeep > 0f ? MOUNT_BAR_HEIGHT : 0) + 1, 11, 11);

if (vehicleMaxHealthDeep > 0f) {
String mountHealthString = String.format("%d/%d", Math.round(vehicleHealthDeep), Math.round(vehicleMaxHealthDeep));
int mountHealthWidth = MinecraftClient.getInstance().textRenderer.getWidth(mountHealthString) + 11;
int expectedLeftPixel = BAR_X + BAR_WIDTH - mountHealthWidth - 3;

if (expectedLeftPixel < healthX) expectedLeftPixel = healthX + 12;

int mountHealthX = drawContext.drawText(MinecraftClient.getInstance().textRenderer, mountHealthString, expectedLeftPixel, BAR_Y + BAR_HEIGHT + (vehicleMaxHealthDeep > 0f ? MOUNT_BAR_HEIGHT : 0) + 2, 0xFFFFFF, true);
drawContext.drawGuiTexture(VEHICLE_HEART, mountHealthX, BAR_Y + BAR_HEIGHT + (vehicleMaxHealthDeep > 0f ? MOUNT_BAR_HEIGHT : 0) + 1, 11, 11);
}

if (BorderRegistry.getItem(this.target.getGroup()) != null) drawContext.drawItem(BorderRegistry.getItem(this.target.getGroup()), BAR_X + BAR_WIDTH - 16, BAR_Y - 16);

float prevTargetHeadYaw = this.target.getHeadYaw();
Expand Down

0 comments on commit 0979632

Please sign in to comment.