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.

Refactor armorHudMixin for Gui class integration

authored by

rh4htr and committed by
GitHub
aed52d19 5e6581c4

+53 -53
+53 -53
src/client/java/com/armorhud/mixin/client/armorHudMixin.java
··· 3 3 import com.armorhud.armor.ArmorAccessor; 4 4 import com.armorhud.armorHud; 5 5 import com.armorhud.config.config; 6 - import net.minecraft.client.MinecraftClient; 7 - import net.minecraft.client.gui.DrawContext; 8 - import net.minecraft.client.gui.hud.InGameHud; 9 - import net.minecraft.client.option.AttackIndicator; 10 - import net.minecraft.client.render.RenderTickCounter; 11 - import net.minecraft.entity.EquipmentSlot; 12 - import net.minecraft.entity.LivingEntity; 13 - import net.minecraft.entity.player.PlayerEntity; 14 - import net.minecraft.item.ItemStack; 6 + import net.minecraft.client.Minecraft; 7 + import net.minecraft.client.gui.GuiGraphicsExtractor; 8 + import net.minecraft.client.gui.Gui; 9 + import net.minecraft.client.AttackIndicatorStatus; 10 + import net.minecraft.client.DeltaTracker; 11 + import net.minecraft.world.entity.EquipmentSlot; 12 + import net.minecraft.world.entity.LivingEntity; 13 + import net.minecraft.world.entity.player.Player; 14 + import net.minecraft.world.item.ItemStack; 15 15 import org.spongepowered.asm.mixin.Final; 16 16 import org.spongepowered.asm.mixin.Mixin; 17 17 import org.spongepowered.asm.mixin.Shadow; ··· 20 20 import org.spongepowered.asm.mixin.injection.Inject; 21 21 import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 22 22 23 - @Mixin(InGameHud.class) 23 + @Mixin(Gui.class) 24 24 public abstract class armorHudMixin { 25 25 26 - @Shadow @Final private MinecraftClient client; 27 - @Shadow protected abstract LivingEntity getRiddenEntity(); 26 + @Shadow @Final private Minecraft minecraft; 27 + @Shadow protected abstract LivingEntity getPlayerVehicleWithHealth(); 28 28 @Unique int armorHeight; 29 29 @Unique boolean initialized; 30 30 ··· 33 33 @Unique private final int HOTBAR_LEFT_X = -83; 34 34 @Unique private final int HOTBAR_RIGHT_X = 165; 35 35 36 - @Inject(at = @At("TAIL"), method = "renderHotbar") 37 - private void renderHud(DrawContext context, RenderTickCounter tickCounter, CallbackInfo ci) { 36 + @Inject(at = @At("TAIL"), method = "extractItemHotbar") 37 + private void renderHud(GuiGraphicsExtractor graphics, DeltaTracker deltaTracker, CallbackInfo ci) { 38 38 if( !config.ARMOR_HUD ) { return; } 39 39 40 - assert client.player != null; 40 + assert minecraft.player != null; 41 41 42 42 if ( !initialized ) { 43 - armorHud.getArmorAccessor().initialize(client.player); 43 + armorHud.getArmorAccessor().initialize(minecraft.player); 44 44 initialized = true; 45 45 } 46 46 47 47 switch ( config.position.name() ) { 48 48 case "FOODBAR": 49 - renderArmor(context, FOODBAR_X); 49 + renderArmor(graphics, FOODBAR_X); 50 50 break; 51 51 case "HEALTHBAR": 52 - renderArmor(context, HEALTHBAR_X); 52 + renderArmor(graphics, HEALTHBAR_X); 53 53 break; 54 54 case "HOTBAR_LEFT": 55 - renderArmor(context, HOTBAR_LEFT_X); 55 + renderArmor(graphics, HOTBAR_LEFT_X); 56 56 break; 57 57 case "HOTBAR_RIGHT": 58 - if ( client.options.getAttackIndicator().getValue() == AttackIndicator.HOTBAR ) { 59 - renderArmor(context, HOTBAR_RIGHT_X + 25); 58 + if ( minecraft.options.attackIndicator().get() == AttackIndicatorStatus.HOTBAR ) { 59 + renderArmor(graphics, HOTBAR_RIGHT_X + 25); 60 60 } else { 61 - renderArmor(context, HOTBAR_RIGHT_X); 61 + renderArmor(graphics, HOTBAR_RIGHT_X); 62 62 } 63 63 break; 64 64 } 65 65 66 - moveArmor(context); 66 + moveArmor(graphics); 67 67 } 68 68 69 69 @Unique 70 - private void renderArmor(DrawContext context, int startXPosition) { 71 - int scaledWidth = context.getScaledWindowWidth(); 70 + private void renderArmor(GuiGraphicsExtractor context, int startXPosition) { 71 + int scaledWidth = context.guiWidth(); 72 72 73 - assert client.player != null; 73 + assert minecraft.player != null; 74 74 ArmorAccessor armorAccessor = armorHud.getArmorAccessor(); 75 75 76 76 final int hungerWidth = 14; // Magic number to center 4 armor pieces ··· 86 86 EquipmentSlot slot = slots[i]; 87 87 x -= armorWidth; 88 88 89 - if ( slot.isArmorSlot() ) { 90 - renderArmorPiece(context, x, armorHeight, client.player, armorAccessor.getArmorPiece(client.player, slot)); 89 + if ( slot.isArmor() ) { 90 + renderArmorPiece(context, x, armorHeight, minecraft.player, armorAccessor.getArmorPiece(minecraft.player, slot)); 91 91 } 92 92 } 93 93 } else { 94 94 for ( EquipmentSlot slot : slots ) { 95 95 x -= armorWidth; 96 96 97 - if ( slot.isArmorSlot() ) { 98 - renderArmorPiece(context, x, armorHeight, client.player, armorAccessor.getArmorPiece(client.player, slot)); 97 + if ( slot.isArmor() ) { 98 + renderArmorPiece(context, x, armorHeight, minecraft.player, armorAccessor.getArmorPiece(minecraft.player, slot)); 99 99 } 100 100 } 101 101 } ··· 117 117 } 118 118 119 119 @Unique 120 - private void moveArmor(DrawContext context) { 120 + private void moveArmor(GuiGraphicsExtractor context) { 121 121 if ( config.position != config.Position.FOODBAR && config.position != config.Position.HEALTHBAR ) { 122 - int scaledHeight = context.getScaledWindowHeight(); 122 + int scaledHeight = context.guiHeight(); 123 123 124 124 switch ( config.position.name() ) { 125 125 case "HOTBAR_LEFT", "HOTBAR_RIGHT": ··· 130 130 return; 131 131 } 132 132 133 - int scaledHeight = context.getScaledWindowHeight(); 133 + int scaledHeight = context.guiHeight(); 134 134 int healthDisplacement = 0; 135 - assert client.player != null; 135 + assert minecraft.player != null; 136 136 137 137 // Moves armorhud up if player uses double hotbar 138 138 armorHeight = scaledHeight - (config.DOUBLE_HOTBAR ? 76 : 55); ··· 142 142 Note: setting gets turned off above 9 rows of hearts, since the hud will fly off the screen at some point -Dino */ 143 143 144 144 if ( config.position == config.Position.HEALTHBAR ) { 145 - if ( client.player.getMaxHealth() + client.player.getMaxAbsorption() < 180 ) { 145 + if ( minecraft.player.getMaxHealth() + minecraft.player.getMaxAbsorption() < 180 ) { 146 146 /* Displacement calculation extracted for clarity. -Dino 147 147 Calc breaks above 90 hearts since hearts don't get condensed further, so it overshoots down -Dino */ 148 - int playerHealthRows = (int) Math.ceil((client.player.getMaxHealth() + client.player.getMaxAbsorption()) / 20); 148 + int playerHealthRows = (int) Math.ceil((minecraft.player.getMaxHealth() + minecraft.player.getMaxAbsorption()) / 20); 149 149 healthDisplacement = (10 * playerHealthRows) - ((playerHealthRows>2) ? (playerHealthRows -2) * (playerHealthRows -1) : 0); 150 150 151 151 // Moves armorhud up depending on how much health you have, along with negative displacement from higher heart counts -Dino 152 152 armorHeight -= healthDisplacement; 153 153 } 154 154 155 - if ( client.player.isCreative() ) { 155 + if ( minecraft.player.isCreative() ) { 156 156 armorHeight += 16 + healthDisplacement; 157 157 } else if ( config.DISABLE_ARMOR_BAR ) { 158 158 armorHeight += 10; 159 159 } 160 160 } else { 161 - if ( client.player.getAir() < client.player.getMaxAir() || client.player.isSubmergedInWater() && !client.player.isCreative() ) { 161 + if ( minecraft.player.getAirSupply() < minecraft.player.getMaxAirSupply() || minecraft.player.isUnderWater() && !minecraft.player.isCreative() ) { 162 162 armorHeight -= 10; 163 163 } 164 164 165 165 // Moves armorhud down if player is in creative 166 - if ( client.player.isCreative() ) { 166 + if ( minecraft.player.isCreative() ) { 167 167 armorHeight += 16; 168 168 } 169 169 170 170 // Moves armorhud up if player is on mount, like horse 171 - if ( client.player.hasVehicle() && getRiddenEntity() != null ) { 171 + if ( minecraft.player.isPassenger() && getPlayerVehicleWithHealth() != null ) { 172 172 moveRiddenEntity(); 173 173 } 174 174 } ··· 176 176 177 177 @Unique 178 178 private void moveRiddenEntity() { 179 - assert client.player != null; 179 + assert minecraft.player != null; 180 180 181 181 // Check if entity player is riding is alive, like a horse 182 - if ( getRiddenEntity().isAlive() ) { 182 + if ( getPlayerVehicleWithHealth().isAlive() ) { 183 183 184 184 // If horse health is 21, it still displays 10 hearts 185 - if ( getRiddenEntity().getMaxHealth() > 21 ) { 186 - if ( config.BETTER_MOUNT_HUD && !client.player.isCreative() ) { 185 + if ( getPlayerVehicleWithHealth().getMaxHealth() > 21 ) { 186 + if ( config.BETTER_MOUNT_HUD && !minecraft.player.isCreative() ) { 187 187 armorHeight -= 20; 188 188 } else { 189 - armorHeight -= (client.player.isCreative() ? 26 : 10); 189 + armorHeight -= (minecraft.player.isCreative() ? 26 : 10); 190 190 } 191 191 } 192 192 193 193 // Armor hud only has to be moved up if better mount hud is enabled or player is in creative 194 194 else { 195 - if ( config.BETTER_MOUNT_HUD && !client.player.isCreative() ) { 195 + if ( config.BETTER_MOUNT_HUD && !minecraft.player.isCreative() ) { 196 196 armorHeight -= 10; 197 - } else if ( client.player.isCreative() ) { 197 + } else if ( minecraft.player.isCreative() ) { 198 198 armorHeight -= 16; 199 199 } 200 200 } ··· 203 203 204 204 // Pretty much the same as renderHotbarItem but with x and y as float parameters. 205 205 @Unique 206 - private void renderArmorPiece(DrawContext context, float x, float y, PlayerEntity player, ItemStack stack) { 206 + private void renderArmorPiece(GuiGraphicsExtractor context, float x, float y, Player player, ItemStack stack) { 207 207 if ( stack.isEmpty() ) return; 208 208 209 - context.getMatrices().pushMatrix(); 210 - context.getMatrices().translate(x, y); 209 + context.pose().pushMatrix(); 210 + context.pose().translate(x, y); 211 211 212 - context.drawItem(player, stack, 0, 0, 1); 212 + context.item(player, stack, 0, 0, 1); 213 213 214 - context.drawStackOverlay(this.client.textRenderer, stack, 0,0); 215 - context.getMatrices().popMatrix(); 214 + context.itemDecorations(this.minecraft.font, stack, 0,0); 215 + context.pose().popMatrix(); 216 216 } 217 217 218 218 }