Advertisement
Scouter456

Untitled

May 7th, 2023
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.05 KB | None | 0 0
  1. public class AmberProtectionOverlay {
  2.     private static final ResourceLocation AMBER_PROTECTION_TEXTURE = new ResourceLocation(UnusualPrehistory.MODID, "textures/amber_protection/amber_protection.png");
  3.     private static final ResourceLocation AMBER_PROTECTION_HALF_TEXTURE = new ResourceLocation(UnusualPrehistory.MODID, "textures/amber_protection/amber_protection_half.png");
  4.  
  5.     //Should be equal to max health
  6.     private static final int MAX_PROTECTION_LEVELS_PER_ROW = 20;
  7.     private static final int BLIT_SIZE = 9;
  8.     private static final int BLIT_SPACING = 8;
  9.     private static final int ROW_HEIGHT_OFFSET = 10;
  10.     private static final int HEART_WIDTH_OFFSET = 80;
  11.     public static final IGuiOverlay HUD_AMBER_PROTECTION = (gui, poseStack, partialTick, width, height) -> {
  12.         int centerX = width / 2;
  13.         int bottomY = height;
  14.         int numProtectionLevels = ClientAmberProtectionData.getAmberProtection();
  15.  
  16.         boolean shouldBlit = numProtectionLevels > 0;
  17.         boolean isCreative = Minecraft.getInstance().player.isCreative();
  18.  
  19.         int blitX = centerX - 91;
  20.         int blitY = bottomY - 39;
  21.         int xOffset = 0;
  22.  
  23.         for (int level = 0; level <= numProtectionLevels && shouldBlit && !isCreative; level++) {
  24.             int rowMultpl = Mth.absFloor(level / MAX_PROTECTION_LEVELS_PER_ROW);
  25.             blitY = blitY - (rowMultpl * ROW_HEIGHT_OFFSET);
  26.             xOffset = (HEART_WIDTH_OFFSET * rowMultpl);
  27.  
  28.             if (level % 2 == 0) {
  29.                 blitX = centerX - 91 + ((level / 2) * BLIT_SPACING) - xOffset;
  30.             }
  31.  
  32.  
  33.             if (level < numProtectionLevels) {
  34.  
  35.                 if (level % 2 == 0) {
  36.                     RenderSystem.setShaderTexture(0, AMBER_PROTECTION_HALF_TEXTURE);
  37.                 } else {
  38.                     RenderSystem.setShaderTexture(0, AMBER_PROTECTION_TEXTURE);
  39.                 }
  40.                 gui.blit(poseStack, blitX, blitY, 0, 0, BLIT_SIZE, BLIT_SIZE, BLIT_SIZE, BLIT_SIZE);
  41.             } else {
  42.                 break;
  43.             }
  44.         }
  45.     };
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement