A mod that adds your armor to the hud modrinth.com/mod/simple-armor-hud
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge to update to 1.21, fixing #44

Updated to 1.21 and refactored some things

authored by

Legoraft and committed by
GitHub
5fee70df a8c37eb8

+47 -42
+1 -1
build.gradle
··· 18 18 // See https://docs.gradle.org/current/userguide/declaring_repositories.html 19 19 // for more information about repositories. 20 20 maven { url = "https://maven.terraformersmc.com/" } 21 - maven { url = "https://maven.gegy.dev" } 21 + // maven { url = "https://maven.gegy.dev" } 22 22 } 23 23 24 24 loom {
+5 -5
gradle.properties
··· 4 4 5 5 # Fabric Properties 6 6 # check these on https://fabricmc.net/develop 7 - minecraft_version=1.20.6 8 - yarn_mappings=1.20.6+build.3 7 + minecraft_version=1.21 8 + yarn_mappings=1.21+build.2 9 9 loader_version=0.15.11 10 10 11 11 # Mod Properties 12 - mod_version=1.4.3 12 + mod_version=1.4.4 13 13 maven_group=com.armorhud 14 14 archives_base_name=simple-armor-hud 15 15 16 16 # Dependency properties 17 - fabric_version=0.99.0+1.20.6 18 - modmenu_version=10.0.0-beta.1 17 + fabric_version=0.100.3+1.21 18 + modmenu_version=11.0.1
+25 -6
src/client/java/com/armorhud/config/fabricScreen.java src/client/java/com/armorhud/config/configScreen.java
··· 1 1 package com.armorhud.config; 2 2 3 + import net.minecraft.client.gui.DrawContext; 3 4 import net.minecraft.client.gui.screen.Screen; 4 5 import net.minecraft.client.gui.screen.option.GameOptionsScreen; 5 6 import net.minecraft.client.gui.widget.*; 6 7 import net.minecraft.text.Text; 7 8 8 - public class fabricScreen extends GameOptionsScreen { 9 + public class configScreen extends GameOptionsScreen { 9 10 public Screen parent; 10 11 11 - public fabricScreen(Screen parent) { 12 + public configScreen(Screen parent) { 12 13 super(parent, null, Text.translatable("config.title")); 13 14 14 15 this.parent = parent; ··· 18 19 public CyclingButtonWidget betterMountHudToggle; 19 20 public CyclingButtonWidget armorHudToggle; 20 21 public CyclingButtonWidget rightToLeftToggle; 22 + public CyclingButtonWidget disableArmorBar; 21 23 22 - public CyclingButtonWidget disableArmorBar; 24 + public ButtonWidget doneButton; 23 25 24 26 @Override 25 27 protected void init() { 26 - OptionListWidget optionListWidget = this.addDrawableChild(new OptionListWidget(this.client, this.width, this.height, this)); 27 - 28 28 doubleHotbarToggle = CyclingButtonWidget.onOffBuilder(config.DOUBLE_HOTBAR) 29 29 .build(Text.translatable("config.doublehotbar"), ((button, value) -> config.DOUBLE_HOTBAR = !config.DOUBLE_HOTBAR)); 30 30 ··· 38 38 .build(Text.translatable("config.righttoleft"), (button, value) -> config.RTL = !config.RTL); 39 39 40 40 disableArmorBar = CyclingButtonWidget.onOffBuilder(config.DISABLE_ARMOR_BAR) 41 - .build(Text.translatable("config.disablearmorbar"), ((button, value) -> config.DISABLE_ARMOR_BAR = !config.DISABLE_ARMOR_BAR)); 41 + .build(Text.translatable("config.disablearmorbar"), ((button, value) -> config.DISABLE_ARMOR_BAR = !config.DISABLE_ARMOR_BAR)); 42 + 43 + OptionListWidget optionListWidget = this.addDrawableChild(new OptionListWidget(this.client, this.width, this)); 42 44 43 45 optionListWidget.addWidgetEntry(doubleHotbarToggle, betterMountHudToggle); 44 46 optionListWidget.addWidgetEntry(armorHudToggle, rightToLeftToggle); 45 47 optionListWidget.addWidgetEntry(disableArmorBar, null); 48 + 49 + doneButton = ButtonWidget 50 + .builder(Text.translatable("config.done"), button -> close()) 51 + .dimensions(width / 2 - 100, height - 25, 200, 20) 52 + .build(); 53 + 54 + addDrawableChild(doneButton); 55 + } 56 + 57 + @Override 58 + public void render(DrawContext context, int mouseX, int mouseY, float delta) { 59 + super.render(context, mouseX, mouseY, delta); 60 + context.drawCenteredTextWithShadow(textRenderer, super.title, width / 2, 12, 0xffffff); 61 + } 62 + 63 + @Override 64 + protected void addOptions() { 46 65 super.init(); 47 66 } 48 67
+8 -18
src/client/java/com/armorhud/mixin/client/armorHudMixin.java
··· 4 4 import net.minecraft.client.MinecraftClient; 5 5 import net.minecraft.client.gui.DrawContext; 6 6 import net.minecraft.client.gui.hud.InGameHud; 7 + import net.minecraft.client.render.RenderTickCounter; 7 8 import net.minecraft.entity.LivingEntity; 8 9 import net.minecraft.entity.player.PlayerEntity; 9 10 import net.minecraft.item.ItemStack; ··· 16 17 import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 17 18 18 19 @Mixin(InGameHud.class) 19 - 20 20 public abstract class armorHudMixin { 21 21 22 22 @Shadow @Final private MinecraftClient client; 23 23 24 24 @Shadow protected abstract LivingEntity getRiddenEntity(); 25 + 26 + @Shadow public abstract void tick(boolean paused); 25 27 26 28 @Unique int armorHeight; 27 29 28 30 @Inject(at = @At("TAIL"), method = "renderHotbar") 29 - private void renderHud(DrawContext context, float tickDelta, CallbackInfo ci) { 31 + private void renderHud(DrawContext context, RenderTickCounter tickCounter, CallbackInfo ci) { 30 32 if(!config.ARMOR_HUD) { return; } 31 33 32 34 assert client.player != null; 33 35 34 - renderArmor(context, tickDelta); 36 + renderArmor(context, tickCounter); 35 37 moveArmor(context); 36 38 } 37 39 38 40 @Unique 39 - private void renderArmor(DrawContext context, float tickDelta) { 41 + private void renderArmor(DrawContext context, RenderTickCounter tickCounter) { 40 42 int scaledWidth = context.getScaledWindowWidth(); 41 43 42 44 assert client.player != null; ··· 58 60 armorPiece = j; 59 61 } 60 62 61 - renderArmorPiece(context, x, armorHeight, tickDelta, client.player, client.player.getInventory().getArmorStack(armorPiece)); 63 + renderArmorPiece(context, x, armorHeight, tickCounter, client.player, client.player.getInventory().getArmorStack(armorPiece)); 62 64 } 63 65 } 64 66 65 67 // Pretty much the same as renderHotbarItem but with x and y as float parameters. 66 68 @Unique 67 - private void renderArmorPiece(DrawContext context, float x, float y, float tickDelta, PlayerEntity player, ItemStack stack) { 69 + private void renderArmorPiece(DrawContext context, float x, float y, RenderTickCounter tickCounter, PlayerEntity player, ItemStack stack) { 68 70 if (stack.isEmpty()) return; 69 71 70 - // Magic 71 - float f = (float)stack.getBobbingAnimationTime() - tickDelta; 72 72 context.getMatrices().push(); 73 73 context.getMatrices().translate(x, y, 0); 74 74 75 - if (f > 0) { 76 - float g = 1 + f / 5; 77 - context.getMatrices().push(); 78 - context.getMatrices().translate(8, 12, 0); 79 - context.getMatrices().scale(1 / g, (g + 1) / 2, 1); 80 - context.getMatrices().translate(-8, -12, 0); 81 - } 82 75 context.drawItem(player, stack, 0, 0, 1); 83 - if (f > 0) { 84 - context.getMatrices().pop(); 85 - } 86 76 87 77 context.drawItemInSlot(this.client.textRenderer, stack, 0,0); 88 78 context.getMatrices().pop();
+6 -10
src/client/java/com/armorhud/mixin/client/inGameHudMixin.java
··· 1 1 package com.armorhud.mixin.client; 2 2 3 3 import com.armorhud.config.config; 4 + import net.minecraft.client.gui.DrawContext; 4 5 import net.minecraft.client.gui.hud.InGameHud; 5 6 import net.minecraft.entity.player.PlayerEntity; 6 7 import org.jetbrains.annotations.Nullable; 7 8 import org.spongepowered.asm.mixin.Mixin; 8 9 import org.spongepowered.asm.mixin.Shadow; 9 10 import org.spongepowered.asm.mixin.injection.At; 11 + import org.spongepowered.asm.mixin.injection.Inject; 10 12 import org.spongepowered.asm.mixin.injection.ModifyVariable; 13 + import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 11 14 12 15 @Mixin(InGameHud.class) 13 16 14 17 public abstract class inGameHudMixin { 15 18 16 - @Shadow @Nullable protected abstract PlayerEntity getCameraPlayer(); 17 - 18 - @ModifyVariable(method = "renderStatusBars", at = @At("STORE"), ordinal = 11) 19 - public int renderStatusBars(int u) { 20 - PlayerEntity playerEntity = this.getCameraPlayer(); 21 - assert playerEntity != null; 22 - 19 + @Inject(method = "renderArmor", at=@At("HEAD"), cancellable = true) 20 + private static void checkArmor(DrawContext context, PlayerEntity player, int i, int j, int k, int x, CallbackInfo ci) { 23 21 if (config.DISABLE_ARMOR_BAR) { 24 - return 0; 25 - } else { 26 - return playerEntity.getArmor(); 22 + ci.cancel(); 27 23 } 28 24 } 29 25
+2 -2
src/client/java/com/armorhud/util/armorHudModMenu.java
··· 1 1 package com.armorhud.util; 2 2 3 + import com.armorhud.config.configScreen; 3 4 import com.terraformersmc.modmenu.api.ConfigScreenFactory; 4 5 import com.terraformersmc.modmenu.api.ModMenuApi; 5 - import com.armorhud.config.fabricScreen; 6 6 import net.minecraft.client.gui.screen.Screen; 7 7 8 8 public class armorHudModMenu implements ModMenuApi { ··· 13 13 } 14 14 15 15 private Screen createConfigScreen(Screen parent) { 16 - return new fabricScreen(parent); 16 + return new configScreen(parent); 17 17 } 18 18 19 19 }