Skip to content

Commit

Permalink
Merge pull request #28 from legoraft/dev
Browse files Browse the repository at this point in the history
Fixed modmenu integration and cleaned up code
  • Loading branch information
legoraft authored Oct 26, 2023
2 parents 6921db0 + 14678da commit fc6109b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 39 deletions.
76 changes: 38 additions & 38 deletions src/client/java/com/armorhud/mixin/client/armorHudMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,71 +19,71 @@
public abstract class armorHudMixin {

@Shadow @Final private MinecraftClient client;

@Shadow private int scaledWidth;

@Shadow private int scaledHeight;

@Shadow protected abstract LivingEntity getRiddenEntity();

@Shadow protected abstract void renderHotbarItem(DrawContext context, int x, int y, float f, PlayerEntity player, ItemStack stack, int seed);

@Inject(at = @At("TAIL"), method = "renderHotbar")
int armorHeight;

@Inject(at = @At("TAIL"), method = "renderHotbar")
private void renderHud(float tickDelta, DrawContext context, CallbackInfo ci) {
if(!config.ARMOR_HUD) { return; }

assert client.player != null;

int h = 68;
int i;
renderArmor(context, tickDelta);
moveArmor();

if (config.DOUBLE_HOTBAR) {
i = this.scaledHeight - 76;
} else {
i = this.scaledHeight - 55;
}

private void renderArmor(DrawContext context, float tickDelta) {
int armorX = 68;

for (int j = 0; j < 4; j++) {
renderHotbarItem(context, this.scaledWidth / 2 + armorX, armorHeight, tickDelta, client.player, client.player.getInventory().getArmorStack(j), 1);
armorX -= 15;
}
}

private void moveArmor() {

// Moves armorhud up if player uses double hotbar
armorHeight = this.scaledHeight - (config.DOUBLE_HOTBAR ? 76 : 55);

// Moves armorhud up if player is underwater
if (client.player.getAir() < client.player.getMaxAir() || client.player.isSubmergedInWater() && !client.player.isCreative()) {
i -= 10;
armorHeight -= 10;
}

// Moves armorhud down if player is in creative
if (client.player.isCreative()) {
i += 16;
}
armorHeight += (client.player.isCreative() ? 16 : 0);

// Moves armorhud up if player is on mount
if (client.player.hasVehicle() && getRiddenEntity() != null) {
if (getRiddenEntity().isAlive()) {
if (getRiddenEntity().getMaxHealth() > 21) {
if (config.BETTER_MOUNT_HUD) {
i -= 20;
} else {
if (client.player.isCreative()) {
i -= 26;
} else {
i -= 10;
}
}
moveArmorHorse();
}
}

private void moveArmorHorse() {

if (getRiddenEntity().isAlive()) {
if (getRiddenEntity().getMaxHealth() > 21) {
if (config.BETTER_MOUNT_HUD && !client.player.isCreative()) {
armorHeight -= 20;
} else {
armorHeight -= (client.player.isCreative() ? 26 : 10);
}
else {
if (config.BETTER_MOUNT_HUD) {
i -= 10;
} else if (client.player.isCreative()) {
i -= 16;
}
}
else {
if (config.BETTER_MOUNT_HUD && !client.player.isCreative()) {
armorHeight -= 10;
} else if (client.player.isCreative()) {
armorHeight -= 16;
}
}
}

// Render all armor items from player
for (int j = 0; j < 4; j++) {
renderHotbarItem(context, this.scaledWidth / 2 + h, i, tickDelta, client.player, client.player.getInventory().getArmorStack(j), 1);
h -= 15;
}

}

}
3 changes: 2 additions & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"entrypoints": {
"client": [
"com.armorhud.armorHud"
]
],
"modmenu": [ "com.armorhud.armorHudModMenu" ]
},
"mixins": [
"simple-armor-hud.mixins.json",
Expand Down

0 comments on commit fc6109b

Please sign in to comment.