Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.79 KB | None | 0 0
  1. package me.adeptr.client.gui;
  2.  
  3. import java.awt.Color;
  4.  
  5. import org.lwjgl.opengl.GL11;
  6.  
  7. import net.minecraft.client.Minecraft;
  8. import net.minecraft.client.gui.Gui;
  9. import net.minecraft.client.gui.ScaledResolution;
  10. import net.minecraft.client.renderer.GlStateManager;
  11. import net.minecraft.client.renderer.texture.TextureManager;
  12. import net.minecraft.client.shader.Framebuffer;
  13. import net.minecraft.util.ResourceLocation;
  14.  
  15. public class SplashProgress {
  16.  
  17. private static final int MAX = 7;
  18. private static int PROGRESS = 0;
  19. private static String CURRENT = "";
  20. private static ResourceLocation splash;
  21. private static UnicodeFontRenderer ufr;
  22.  
  23. public static void update() {
  24. if(Minecraft.getMinecraft() == null || Minecraft.getMinecraft().getLanguageManager() == null) {
  25. return;
  26. }
  27. drawSplash(Minecraft.getMinecraft().getTextureManager());
  28. }
  29.  
  30. public static void setProgress(int givenProgress, String givenText) {
  31. PROGRESS = givenProgress;
  32. CURRENT = givenText;
  33. update();
  34. }
  35.  
  36. public static void drawSplash(TextureManager tm) {
  37.  
  38. ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft());
  39. int scaleFactor = scaledResolution.getScaleFactor();
  40.  
  41. Framebuffer framebuffer = new Framebuffer(scaledResolution.getScaledWidth() * scaleFactor, scaledResolution.getScaledHeight() * scaleFactor, true);
  42. framebuffer.bindFramebuffer(false);
  43.  
  44. GlStateManager.matrixMode(GL11.GL_PROJECTION);
  45. GlStateManager.loadIdentity();
  46. GlStateManager.ortho(0.0D, (double)scaledResolution.getScaledWidth(), (double)scaledResolution.getScaledHeight(), 0.0D, 1000.0D, 3000.0D);
  47. GlStateManager.matrixMode(GL11.GL_MODELVIEW);
  48. GlStateManager.loadIdentity();
  49. GlStateManager.translate(0.0F, 0.0F, -2000.0F);
  50. GlStateManager.disableLighting();
  51. GlStateManager.disableFog();
  52. GlStateManager.disableDepth();
  53. GlStateManager.enableTexture2D();
  54.  
  55. if(splash == null) {
  56. splash = new ResourceLocation("Arcenia/splash.png");
  57. }
  58.  
  59. tm.bindTexture(splash);
  60.  
  61. GlStateManager.resetColor();
  62. GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
  63.  
  64. Gui.drawScaledCustomSizeModalRect(0, 0, 0, 0, 1920, 1000, scaledResolution.getScaledWidth(), scaledResolution.getScaledHeight(), 1920, 1000);
  65. drawProgress();
  66. framebuffer.unbindFramebuffer();
  67. framebuffer.framebufferRender(scaledResolution.getScaledWidth() * scaleFactor, scaledResolution.getScaledHeight() * scaleFactor);
  68.  
  69. GlStateManager.enableAlpha();
  70. GlStateManager.alphaFunc(516, 0.1F);
  71.  
  72. Minecraft.getMinecraft().updateDisplay();
  73.  
  74. }
  75.  
  76. private static void drawProgress() {
  77.  
  78. if(Minecraft.getMinecraft().gameSettings == null || Minecraft.getMinecraft().getTextureManager() == null) {
  79. return;
  80. }
  81.  
  82. if(ufr == null) {
  83. ufr = UnicodeFontRenderer.getFontOnPC("Arial", 20);
  84. }
  85.  
  86. ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft());
  87.  
  88. double nProgress = (double)PROGRESS;
  89. double calc = (nProgress / MAX * sr.getScaledWidth());
  90.  
  91. Gui.drawRect(0, sr.getScaledHeight() - 35, sr.getScaledWidth(), sr.getScaledHeight(), new Color(0, 0, 0, 50).getRGB());
  92.  
  93. GlStateManager.resetColor();
  94. resetTextureState();
  95.  
  96. ufr.drawString(CURRENT, 20, sr.getScaledHeight() - 25, 0xFFFFFFFF);
  97.  
  98. String step = PROGRESS + "/" + MAX;
  99. ufr.drawString(step, sr.getScaledWidth() - 20 - ufr.getStringWidth(step), sr.getScaledHeight() - 25, 0xe1e1e1FF);
  100.  
  101. GlStateManager.resetColor();
  102. resetTextureState();
  103.  
  104. Gui.drawRect(0, sr.getScaledHeight() - 2, (int)calc, sr.getScaledHeight(), new Color(149, 201, 144).getRGB());
  105.  
  106. Gui.drawRect(0, sr.getScaledHeight() - 2, sr.getScaledWidth(), sr.getScaledHeight(), new Color(0, 0, 0, 10).getRGB());
  107.  
  108. }
  109.  
  110. private static void resetTextureState() {
  111. GlStateManager.textureState[GlStateManager.activeTextureUnit].textureName = -1;
  112. }
  113.  
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement