Skip to content

Commit

Permalink
V2.1
Browse files Browse the repository at this point in the history
## Changelog

- Changed the Exclaimation Mark Texture
- Made the Exclaimation Mark have a bobbing animation
- Made it so the HUD stops displaying when in f1
- Increased performance
- Durability now hides if it is full

(I'm sorry for 2 releases in one day and i apologise in advance to anyone who has downloaded the previous version from today.)

(Version support for 1.21 and more will come soon.)
  • Loading branch information
SaolGhra committed Sep 3, 2024
1 parent 3dc4e0d commit 861de95
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ minecraft_version=1.21.1
yarn_mappings=1.21.1+build.3
loader_version=0.15.11
# Mod Properties
mod_version=1.9
mod_version=2.1
maven_group=com.saolghra
archives_base_name=Armor_Hud
# Dependencies
Expand Down
19 changes: 16 additions & 3 deletions src/client/java/com/saolghra/armor_hud/client/ArmorHudOverlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public class ArmorHudOverlay {
public void renderArmorUI(DrawContext context) {
MinecraftClient client = MinecraftClient.getInstance();

if (client.player == null || client.world == null) return;
if (client.options.hudHidden || client.player == null || client.world == null) {
return;
}

// Get armor items
ItemStack[] armorItems = client.player.getInventory().armor.toArray(new ItemStack[0]);
Expand Down Expand Up @@ -76,16 +78,22 @@ public void renderArmorUI(DrawContext context) {
}
}

// Check if the durability is low
private boolean isDurabilityLow(ItemStack item) {
int maxDamage = item.getMaxDamage();
int damage = item.getDamage();
return (maxDamage - damage) / (float) maxDamage < 0.20;
return damage > 0 && (maxDamage - damage) / (float) maxDamage < 0.20;
}

private void drawExclamationMark(DrawContext context, int x, int y) {
long currentTime = System.currentTimeMillis();

// Calculate the bobbing offset using a sine wave function
float bobbingOffset = (float) Math.sin(currentTime / 200.0) * 2; // Adjust the divisor to control speed and amplitude

// Draw the exclamation marks
context.getMatrices().push();
context.getMatrices().translate(x - 5, y + 16, 500);
context.getMatrices().translate(x - 5, y + 16 + bobbingOffset, 500);
context.getMatrices().scale(0.5f, 0.5f, 500f);
context.drawTexture(EXCLAMATION_MARKS_TEXTURE, 0, 0, 0, 0, 22, 22, 22, 22);
context.getMatrices().pop();
Expand All @@ -98,6 +106,11 @@ private void drawTexture(DrawContext context, int x, int y, int u, int v, int wi
private void drawDurabilityBar(DrawContext context, int x, int y, int width, ItemStack item) {
int maxDamage = item.getMaxDamage();
int damage = item.getDamage();

if (damage == 0) {
return;
}

int durability = maxDamage - damage;

// Total width of the durability bar
Expand Down

0 comments on commit 861de95

Please sign in to comment.