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 pull request #42 from legoraft/dev

Revamped config screen, updated to 1.20.6

authored by

Legoraft and committed by
GitHub
8aaa733f 8f1b20a5

+108 -108
+2 -2
.github/workflows/build.yml
··· 12 12 matrix: 13 13 # Use these Java versions 14 14 java: [ 15 - 17, # Current Java LTS & minimum supported by Minecraft 15 + 21, # Current Java LTS & minimum supported by Minecraft 16 16 ] 17 17 # and run on both Linux and Windows 18 18 os: [ubuntu-22.04, windows-2022] ··· 33 33 - name: build 34 34 run: ./gradlew build 35 35 - name: capture build artifacts 36 - if: ${{ runner.os == 'Linux' && matrix.java == '17' }} # Only upload artifacts built from latest java on one OS 36 + if: ${{ runner.os == 'Linux' && matrix.java == '21' }} # Only upload artifacts built from latest java on one OS 37 37 uses: actions/upload-artifact@v3 38 38 with: 39 39 name: armorhud-mod
+2 -2
build.gradle
··· 1 1 plugins { 2 - id 'fabric-loom' version '1.2-SNAPSHOT' 2 + id 'fabric-loom' version '1.6-SNAPSHOT' 3 3 id 'maven-publish' 4 4 5 5 } ··· 39 39 mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" 40 40 modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" 41 41 42 - include modImplementation("dev.lambdaurora:spruceui:${project.spruceui_version}") 42 + // include modImplementation("dev.lambdaurora:spruceui:${project.spruceui_version}") 43 43 44 44 modApi "com.terraformersmc:modmenu:${project.modmenu_version}" 45 45
+6 -6
gradle.properties
··· 4 4 5 5 # Fabric Properties 6 6 # check these on https://fabricmc.net/develop 7 - minecraft_version=1.20.4 8 - yarn_mappings=1.20.4+build.1 9 - loader_version=0.15.2 7 + minecraft_version=1.20.6 8 + yarn_mappings=1.20.6+build.3 9 + loader_version=0.15.11 10 10 11 11 # Mod Properties 12 12 mod_version=1.4.2 ··· 14 14 archives_base_name=simple-armor-hud 15 15 16 16 # Dependency properties 17 - fabric_version=0.91.3+1.20.4 18 - modmenu_version=9.0.0-pre.1 19 - spruceui_version=5.0.3+1.20.2 17 + fabric_version=0.99.0+1.20.6 18 + modmenu_version=10.0.0-beta.1 19 + spruceui_version=5.0.3+1.20.4
gradle/wrapper/gradle-wrapper.jar

This is a binary file and will not be displayed.

+1 -1
gradle/wrapper/gradle-wrapper.properties
··· 1 1 distributionBase=GRADLE_USER_HOME 2 2 distributionPath=wrapper/dists 3 - distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip 3 + distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip 4 4 networkTimeout=10000 5 5 zipStoreBase=GRADLE_USER_HOME 6 6 zipStorePath=wrapper/dists
+6 -5
gradlew
··· 85 85 APP_BASE_NAME=${0##*/} 86 86 APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 87 87 88 - # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 - DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 - 91 88 # Use the maximum available, or set MAX_FD != -1 to use that value. 92 89 MAX_FD=maximum 93 90 ··· 144 141 case $MAX_FD in #( 145 142 max*) 146 143 # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 147 - # shellcheck disable=SC3045 144 + # shellcheck disable=SC3045 148 145 MAX_FD=$( ulimit -H -n ) || 149 146 warn "Could not query maximum file descriptor limit" 150 147 esac ··· 152 149 '' | soft) :;; #( 153 150 *) 154 151 # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 155 - # shellcheck disable=SC3045 152 + # shellcheck disable=SC3045 156 153 ulimit -n "$MAX_FD" || 157 154 warn "Could not set maximum file descriptor limit to $MAX_FD" 158 155 esac ··· 196 193 set -- "$@" "$arg" # push replacement arg 197 194 done 198 195 fi 196 + 197 + 198 + # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 199 + DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 199 200 200 201 # Collect all arguments for the java command; 201 202 # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
+3 -3
src/client/java/com/armorhud/config/config.java
··· 14 14 public static boolean DOUBLE_HOTBAR = false; 15 15 public static boolean ARMOR_HUD = true; 16 16 public static boolean RTL = false; 17 - public static boolean DISABLE_ARMOR = false; 17 + public static boolean DISABLE_ARMOR_BAR = false; 18 18 19 19 private static final Path CONFIG_PATH = FabricLoader.getInstance().getConfigDir().resolve("armorhud.properties"); 20 20 ··· 23 23 properties.setProperty("double_hotbar", Boolean.toString(DOUBLE_HOTBAR)); 24 24 properties.setProperty("armor_hud", Boolean.toString(ARMOR_HUD)); 25 25 properties.setProperty("right_to_left", Boolean.toString(RTL)); 26 - properties.setProperty("disable_armor", Boolean.toString(DISABLE_ARMOR)); 26 + properties.setProperty("disable_armor_bar", Boolean.toString(DISABLE_ARMOR_BAR)); 27 27 } 28 28 29 29 public void read(Properties properties) { ··· 31 31 DOUBLE_HOTBAR = Boolean.parseBoolean(properties.getProperty("double_hotbar")); 32 32 ARMOR_HUD = Boolean.parseBoolean(properties.getProperty("armor_hud")); 33 33 RTL = Boolean.parseBoolean(properties.getProperty("right_to_left")); 34 - DISABLE_ARMOR = Boolean.parseBoolean(properties.getProperty("disable_armor")); 34 + DISABLE_ARMOR_BAR = Boolean.parseBoolean(properties.getProperty("disable_armor_bar")); 35 35 } 36 36 37 37 public static void save() {
-61
src/client/java/com/armorhud/config/configScreen.java
··· 1 - package com.armorhud.config; 2 - 3 - import dev.lambdaurora.spruceui.Position; 4 - import dev.lambdaurora.spruceui.option.SpruceBooleanOption; 5 - import dev.lambdaurora.spruceui.option.SpruceOption; 6 - import dev.lambdaurora.spruceui.screen.SpruceScreen; 7 - import dev.lambdaurora.spruceui.widget.SpruceButtonWidget; 8 - import dev.lambdaurora.spruceui.widget.container.SpruceOptionListWidget; 9 - import net.minecraft.client.gui.DrawContext; 10 - import net.minecraft.client.gui.screen.Screen; 11 - import net.minecraft.text.Text; 12 - import org.jetbrains.annotations.Nullable; 13 - 14 - public class configScreen extends SpruceScreen { 15 - 16 - private final Screen parent; 17 - 18 - private final SpruceOption doubleHotbarToggle; 19 - private final SpruceOption betterMountHudToggle; 20 - private final SpruceOption armorHudToggle; 21 - private final SpruceOption rightToLeftToggle; 22 - 23 - public configScreen(@Nullable Screen parent) { 24 - super(Text.literal("Armorhud test GUI")); 25 - this.parent = parent; 26 - 27 - this.doubleHotbarToggle = new SpruceBooleanOption("config.doublehotbar", () -> config.DOUBLE_HOTBAR, newValue -> config.DOUBLE_HOTBAR = newValue, Text.translatable("config.description.doublehotbar")); 28 - this.betterMountHudToggle = new SpruceBooleanOption("config.bettermounthud", () -> config.BETTER_MOUNT_HUD, newValue -> config.BETTER_MOUNT_HUD = newValue, Text.translatable("config.description.bettermounthud")); 29 - this.armorHudToggle = new SpruceBooleanOption("config.armorvisible", () -> config.ARMOR_HUD, newValue -> config.ARMOR_HUD = newValue, Text.translatable("config.description.armorvisible")); 30 - this.rightToLeftToggle = new SpruceBooleanOption("config.righttoleft", () -> config.RTL, newValue -> config.RTL = newValue, Text.translatable("config.description.righttoleft")); 31 - } 32 - 33 - @Override 34 - protected void init() { 35 - super.init(); 36 - 37 - SpruceOptionListWidget list = new SpruceOptionListWidget(Position.of(0, 34), this.width, this.height - 69); 38 - list.addOptionEntry(this.armorHudToggle, this.doubleHotbarToggle); 39 - list.addOptionEntry(this.betterMountHudToggle, this.rightToLeftToggle); 40 - 41 - this.addDrawableChild(list); 42 - 43 - this.addDrawableChild(new SpruceButtonWidget(Position.of(this.width / 2 - 100, this.height - 30), 200, 20, Text.translatable("config.done"), button -> close())); 44 - } 45 - 46 - @Override 47 - public void renderTitle(DrawContext context, int MouseX, int MouseY, float delta) { 48 - context.drawCenteredTextWithShadow(this.textRenderer, this.title, this.width / 2, 8, 16777215); 49 - } 50 - 51 - @Override 52 - public void renderBackground(DrawContext context, int mouseX, int mouseY, float delta) { 53 - this.renderBackgroundTexture(context); 54 - } 55 - 56 - public void close() { 57 - config.save(); 58 - this.client.setScreen(parent); 59 - } 60 - 61 - }
+54
src/client/java/com/armorhud/config/fabricScreen.java
··· 1 + package com.armorhud.config; 2 + 3 + import net.minecraft.client.gui.screen.Screen; 4 + import net.minecraft.client.gui.screen.option.GameOptionsScreen; 5 + import net.minecraft.client.gui.tooltip.Tooltip; 6 + import net.minecraft.client.gui.widget.*; 7 + import net.minecraft.text.Text; 8 + 9 + public class fabricScreen extends GameOptionsScreen { 10 + public Screen parent; 11 + 12 + public fabricScreen(Screen parent) { 13 + super(parent, null, Text.translatable("config.title")); 14 + 15 + this.parent = parent; 16 + } 17 + 18 + public CyclingButtonWidget doubleHotbarToggle; 19 + public CyclingButtonWidget betterMountHudToggle; 20 + public CyclingButtonWidget armorHudToggle; 21 + public CyclingButtonWidget rightToLeftToggle; 22 + 23 + public CyclingButtonWidget disableArmorBar; 24 + 25 + @Override 26 + protected void init() { 27 + OptionListWidget optionListWidget = this.addDrawableChild(new OptionListWidget(this.client, this.width, this.height, this)); 28 + 29 + doubleHotbarToggle = CyclingButtonWidget.onOffBuilder(config.DOUBLE_HOTBAR) 30 + .build(Text.translatable("config.doublehotbar"), ((button, value) -> config.DOUBLE_HOTBAR = !config.DOUBLE_HOTBAR)); 31 + 32 + betterMountHudToggle = CyclingButtonWidget.onOffBuilder(config.BETTER_MOUNT_HUD) 33 + .build(Text.translatable("config.bettermounthud"), (button, value) -> config.BETTER_MOUNT_HUD = !config.BETTER_MOUNT_HUD); 34 + 35 + armorHudToggle = CyclingButtonWidget.onOffBuilder(config.ARMOR_HUD) 36 + .build(Text.translatable("config.armorvisible"), (button, value) -> config.ARMOR_HUD = !config.ARMOR_HUD); 37 + 38 + rightToLeftToggle = CyclingButtonWidget.onOffBuilder(config.RTL) 39 + .build(Text.translatable("config.righttoleft"), (button, value) -> config.RTL = !config.RTL); 40 + 41 + disableArmorBar = CyclingButtonWidget.onOffBuilder(config.DISABLE_ARMOR_BAR) 42 + .build(Text.translatable("config.disablearmorbar"), ((button, value) -> config.DISABLE_ARMOR_BAR = !config.DISABLE_ARMOR_BAR)); 43 + 44 + optionListWidget.addWidgetEntry(doubleHotbarToggle, betterMountHudToggle); 45 + super.init(); 46 + } 47 + 48 + @Override 49 + public void close() { 50 + config.save(); 51 + this.client.setScreen(this.parent); 52 + } 53 + 54 + }
+17 -9
src/client/java/com/armorhud/mixin/client/armorHudMixin.java
··· 20 20 public abstract class armorHudMixin { 21 21 22 22 @Shadow @Final private MinecraftClient client; 23 - @Shadow private int scaledWidth; 24 - @Shadow private int scaledHeight; 23 + 25 24 @Shadow protected abstract LivingEntity getRiddenEntity(); 26 25 27 26 @Unique int armorHeight; 28 27 29 28 @Inject(at = @At("TAIL"), method = "renderHotbar") 30 - private void renderHud(float tickDelta, DrawContext context, CallbackInfo ci) { 29 + private void renderHud(DrawContext context, float tickDelta, CallbackInfo ci) { 31 30 if(!config.ARMOR_HUD) { return; } 32 31 33 32 assert client.player != null; 34 33 35 34 renderArmor(context, tickDelta); 36 - moveArmor(); 35 + moveArmor(context); 37 36 } 38 37 39 38 @Unique 40 39 private void renderArmor(DrawContext context, float tickDelta) { 40 + int scaledWidth = context.getScaledWindowWidth(); 41 + 42 + assert client.player != null; 43 + 41 44 final int hungerWidth = 80 + 8; // Bar advances 8 pixels to the left 10 times, 8 is added for the width of the last sprite. 42 45 final int armorWidth = 15; 43 46 final int barWidth = armorWidth * 4; ··· 55 58 armorPiece = j; 56 59 } 57 60 58 - renderArmorPiece(context, x, armorHeight, tickDelta, client.player, client.player.getInventory().getArmorStack(armorPiece), 1); 61 + renderArmorPiece(context, x, armorHeight, tickDelta, client.player, client.player.getInventory().getArmorStack(armorPiece)); 59 62 } 60 63 } 61 64 62 65 // Pretty much the same as renderHotbarItem but with x and y as float parameters. 63 66 @Unique 64 - private void renderArmorPiece(DrawContext context, float x, float y, float tickDelta, PlayerEntity player, ItemStack stack, int seed) { 67 + private void renderArmorPiece(DrawContext context, float x, float y, float tickDelta, PlayerEntity player, ItemStack stack) { 65 68 if (stack.isEmpty()) return; 66 69 67 70 // Magic ··· 76 79 context.getMatrices().scale(1 / g, (g + 1) / 2, 1); 77 80 context.getMatrices().translate(-8, -12, 0); 78 81 } 79 - context.drawItem(player, stack, 0, 0, seed); 82 + context.drawItem(player, stack, 0, 0, 1); 80 83 if (f > 0) { 81 84 context.getMatrices().pop(); 82 85 } ··· 86 89 } 87 90 88 91 @Unique 89 - private void moveArmor() { 92 + private void moveArmor(DrawContext context) { 93 + int scaledHeight = context.getScaledWindowHeight(); 94 + 95 + assert client.player != null; 90 96 91 97 // Moves armorhud up if player uses double hotbar 92 - armorHeight = this.scaledHeight - (config.DOUBLE_HOTBAR ? 76 : 55); 98 + armorHeight = scaledHeight - (config.DOUBLE_HOTBAR ? 76 : 55); 93 99 94 100 // Moves armorhud up if player is underwater 95 101 if (client.player.getAir() < client.player.getMaxAir() || client.player.isSubmergedInWater() && !client.player.isCreative()) { ··· 105 111 } 106 112 } 107 113 114 + @Unique 108 115 private void moveArmorHorse() { 116 + assert client.player != null; 109 117 110 118 // Check if entity player is riding is alive, like a horse 111 119 if (getRiddenEntity().isAlive()) {
+1 -1
src/client/java/com/armorhud/mixin/client/inGameHudMixin.java
··· 20 20 PlayerEntity playerEntity = this.getCameraPlayer(); 21 21 assert playerEntity != null; 22 22 23 - if (config.DISABLE_ARMOR) { 23 + if (config.DISABLE_ARMOR_BAR) { 24 24 return 0; 25 25 } else { 26 26 return playerEntity.getArmor();
+3 -5
src/client/java/com/armorhud/mixin/client/tooltipMixin.java
··· 1 1 package com.armorhud.mixin.client; 2 2 3 + import net.minecraft.client.gui.DrawContext; 3 4 import net.minecraft.client.gui.hud.InGameHud; 4 5 import org.spongepowered.asm.mixin.Mixin; 5 - import org.spongepowered.asm.mixin.Shadow; 6 6 import org.spongepowered.asm.mixin.injection.At; 7 7 import org.spongepowered.asm.mixin.injection.ModifyVariable; 8 8 9 9 @Mixin(InGameHud.class) 10 10 11 11 public abstract class tooltipMixin { 12 - 13 - @Shadow private int scaledHeight; 14 12 15 13 @ModifyVariable(method = "renderHeldItemTooltip", at = @At("STORE"), ordinal = 2) 16 - public int renderHeldItemTooltip(int k) { 17 - return this.scaledHeight - 62; 14 + public int renderHeldItemTooltip(int k, DrawContext context) { 15 + return context.getScaledWindowWidth() - 62; 18 16 } 19 17 20 18 }
+7 -2
src/client/java/com/armorhud/util/armorHudModMenu.java
··· 1 1 package com.armorhud.util; 2 2 3 - import com.armorhud.config.configScreen; 4 3 import com.terraformersmc.modmenu.api.ConfigScreenFactory; 5 4 import com.terraformersmc.modmenu.api.ModMenuApi; 5 + import com.armorhud.config.fabricScreen; 6 + import net.minecraft.client.gui.screen.Screen; 6 7 7 8 public class armorHudModMenu implements ModMenuApi { 8 9 9 10 @Override 10 11 public ConfigScreenFactory<?> getModConfigScreenFactory() { 11 - return configScreen::new; 12 + return this::createConfigScreen; 13 + } 14 + 15 + private Screen createConfigScreen(Screen parent) { 16 + return new fabricScreen(parent); 12 17 } 13 18 14 19 }
+3 -5
src/main/resources/assets/simple-armor-hud/lang/en_us.json
··· 6 6 "config.bettermounthud": "Better Mount Hud", 7 7 "config.armorvisible": "Armor visible", 8 8 "config.righttoleft": "Right to left display", 9 - "config.done": "Done", 9 + "config.disablearmorbar": "Disable armor bar", 10 10 11 - "config.description.doublehotbar": "Ensures complatibility between double hotbar and armor hud", 12 - "config.description.bettermounthud": "Makes better mount hud compatible", 13 - "config.description.armorvisible": "Toggles the visibility of the armor hud", 14 - "config.description.righttoleft": "Displays the armor from right to left instead of left to right" 11 + "config.title": "Armor hud config screen", 12 + "config.done": "Done" 15 13 }
+3 -6
src/main/resources/assets/simple-armor-hud/lang/nl_nl.json
··· 5 5 "config.doublehotbar": "Double Hotbar", 6 6 "config.bettermounthud": "Better Mount Hud", 7 7 "config.armorvisible": "Harnas-hud zichtbaar", 8 + "config.disablearmorbar": "Harnasbalk uitzetten", 9 + 8 10 "config.righttoleft": "Rechts naar links display", 9 - "config.done": "Gereed", 10 - 11 - "config.description.doublehotbar": "Zorgt voor compatibiliteit met de double hotbar mod", 12 - "config.description.bettermounthud": "Maakt armor hud compatibel met de better mount hud mod", 13 - "config.description.armorvisible": "Zet de zichtbaarheid van het harnas aan of uit", 14 - "config.description.righttoleft": "Laat de harnas-hud van rechts naar links zien in plaats van links naar rechts" 11 + "config.done": "Gereed" 15 12 }