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.

chore: moved moving code around

legoraft ed49dd31 81181f33

+38 -34
+38 -34
src/client/java/com/armorhud/mixin/client/armorHudMixin.java
··· 11 11 import net.minecraft.entity.LivingEntity; 12 12 import net.minecraft.entity.player.PlayerEntity; 13 13 import net.minecraft.item.ItemStack; 14 - import org.slf4j.Logger; 15 - import org.slf4j.LoggerFactory; 16 14 import org.spongepowered.asm.mixin.Final; 17 15 import org.spongepowered.asm.mixin.Mixin; 18 16 import org.spongepowered.asm.mixin.Shadow; ··· 34 32 35 33 @Inject(at = @At("TAIL"), method = "renderHotbar") 36 34 private void renderHud(DrawContext context, RenderTickCounter tickCounter, CallbackInfo ci) { 37 - if(!config.ARMOR_HUD) { return; } 35 + if( !config.ARMOR_HUD ) { return; } 38 36 39 37 assert client.player != null; 40 38 41 - if (!initialized) { 39 + if ( !initialized ) { 42 40 armorHud.getArmorAccessor().initialize(client.player); 43 41 initialized = true; 44 42 } 45 43 46 - switch (config.position.name()) { 44 + switch ( config.position.name() ) { 47 45 case "FOODBAR": 48 46 renderArmor(context, FOODBAR_X); 49 47 break; ··· 78 76 EquipmentSlot slot = slots[i]; 79 77 x -= armorWidth; 80 78 81 - if (slot.isArmorSlot()) { 79 + if ( slot.isArmorSlot() ) { 82 80 renderArmorPiece(context, x, armorHeight, client.player, armorAccessor.getArmorPiece(client.player, slot)); 83 81 } 84 82 } 85 83 } else { 86 - for (EquipmentSlot slot : slots) { 84 + for ( EquipmentSlot slot : slots ) { 87 85 x -= armorWidth; 88 86 89 - if (slot.isArmorSlot()) { 87 + if ( slot.isArmorSlot() ) { 90 88 renderArmorPiece(context, x, armorHeight, client.player, armorAccessor.getArmorPiece(client.player, slot)); 91 89 } 92 90 } ··· 110 108 // Pretty much the same as renderHotbarItem but with x and y as float parameters. 111 109 @Unique 112 110 private void renderArmorPiece(DrawContext context, float x, float y, PlayerEntity player, ItemStack stack) { 113 - if (stack.isEmpty()) return; 111 + if ( stack.isEmpty() ) return; 114 112 115 113 context.getMatrices().pushMatrix(); 116 114 context.getMatrices().translate(x, y); ··· 123 121 124 122 @Unique 125 123 private void moveArmor(DrawContext context) { 126 - int scaledHeight = context.getScaledWindowHeight(); 124 + if ( config.position != config.Position.FOODBAR && config.position != config.Position.HEALTHBAR ) { 125 + return; 126 + } 127 127 128 + int scaledHeight = context.getScaledWindowHeight(); 129 + int healthDisplacement = 0; 128 130 assert client.player != null; 129 131 130 132 // Moves armorhud up if player uses double hotbar ··· 133 135 /* TODO: fix visual bug where remaining hearts available (>20hp) get removed later than armor hud -Dino 134 136 Skips unnecessary checks when Above_Health_Bar is on, not a fan of the extra if statement, but it works -Dino 135 137 Note: setting gets turned off above 9 rows of hearts, since the hud will fly off the screen at some point -Dino */ 136 - if (client.player.getMaxHealth() + client.player.getMaxAbsorption() < 180) { 138 + 139 + if ( config.position == config.Position.HEALTHBAR ) { 140 + if ( client.player.getMaxHealth() + client.player.getMaxAbsorption() < 180 ) { 137 141 /* Displacement calculation extracted for clarity. -Dino 138 142 Calc breaks above 90 hearts since hearts don't get condensed further, so it overshoots down -Dino */ 139 - int playerHealthRows = (int) Math.ceil((client.player.getMaxHealth() + client.player.getMaxAbsorption()) / 20); 140 - int healthDisplacement = (10 * playerHealthRows) - ((playerHealthRows>2) ? (playerHealthRows -2) * (playerHealthRows -1) : 0); 143 + int playerHealthRows = (int) Math.ceil((client.player.getMaxHealth() + client.player.getMaxAbsorption()) / 20); 144 + healthDisplacement = (10 * playerHealthRows) - ((playerHealthRows>2) ? (playerHealthRows -2) * (playerHealthRows -1) : 0); 141 145 142 146 // Moves armorhud up depending on how much health you have, along with negative displacement from higher heart counts -Dino 143 - armorHeight -= healthDisplacement; 147 + armorHeight -= healthDisplacement; 148 + } 144 149 145 - /* Moves armorhud down if player is in creative or Disable_Armor_Bar is on, 146 - formatted as an if-statement for readability -Dino 147 - */ 148 - if(client.player.isCreative()) { 150 + if ( client.player.isCreative() ) { 149 151 armorHeight += 16 + healthDisplacement; 150 - } else if (config.DISABLE_ARMOR_BAR) { 152 + } else if ( config.DISABLE_ARMOR_BAR ) { 151 153 armorHeight += 10; 152 154 } 153 - } else { 154 - // Moves armorhud up if player is underwater 155 - if ((client.player.getAir() < client.player.getMaxAir() || client.player.isSubmergedInWater() && !client.player.isCreative())) { 156 - armorHeight -= 10; 157 - } 155 + } 156 + 157 + if ( client.player.getAir() < client.player.getMaxAir() || client.player.isSubmergedInWater() && !client.player.isCreative() ) { 158 + armorHeight -= 10; 159 + } 158 160 159 161 // Moves armorhud down if player is in creative 160 - armorHeight += (client.player.isCreative() ? 16 : 0); 162 + if ( client.player.isCreative() ) { 163 + armorHeight += 16; 164 + } 161 165 162 166 // Moves armorhud up if player is on mount, like horse 163 - if (client.player.hasVehicle() && getRiddenEntity() != null) { 164 - moveArmorHorse(); 165 - } 167 + if ( client.player.hasVehicle() && getRiddenEntity() != null ) { 168 + moveRiddenEntity(); 166 169 } 167 170 } 168 171 169 172 @Unique 170 - private void moveArmorHorse() { 173 + private void moveRiddenEntity() { 171 174 assert client.player != null; 172 175 173 176 // Check if entity player is riding is alive, like a horse 174 - if (getRiddenEntity().isAlive()) { 177 + if ( getRiddenEntity().isAlive() ) { 178 + 175 179 // If horse health is 21, it still displays 10 hearts 176 - if (getRiddenEntity().getMaxHealth() > 21) { 177 - if (config.BETTER_MOUNT_HUD && !client.player.isCreative()) { 180 + if ( getRiddenEntity().getMaxHealth() > 21 ) { 181 + if ( config.BETTER_MOUNT_HUD && !client.player.isCreative() ) { 178 182 armorHeight -= 20; 179 183 } else { 180 184 armorHeight -= (client.player.isCreative() ? 26 : 10); ··· 183 187 184 188 // Armor hud only has to be moved up if better mount hud is enabled or player is in creative 185 189 else { 186 - if (config.BETTER_MOUNT_HUD && !client.player.isCreative()) { 190 + if ( config.BETTER_MOUNT_HUD && !client.player.isCreative() ) { 187 191 armorHeight -= 10; 188 - } else if (client.player.isCreative()) { 192 + } else if ( client.player.isCreative() ) { 189 193 armorHeight -= 16; 190 194 } 191 195 }