diff options
| author | TymanWasTaken <tyman@tyman.tech> | 2021-07-06 17:15:21 -0400 |
|---|---|---|
| committer | TymanWasTaken <tyman@tyman.tech> | 2021-07-06 17:17:22 -0400 |
| commit | a8e475fa0a7977f64f072548459d592274169d66 (patch) | |
| tree | 2f6e3c2fc4aa55c52b848adc493a9ecc842e53f8 /src/main/java/com/thatgravyboat/skyblockhud/core | |
| parent | bb75fd7b83b238f1f922ffc64b2a0a535c5524b7 (diff) | |
| download | skyblockhud-a8e475fa0a7977f64f072548459d592274169d66.tar.gz skyblockhud-a8e475fa0a7977f64f072548459d592274169d66.tar.bz2 skyblockhud-a8e475fa0a7977f64f072548459d592274169d66.zip | |
Format v2
Diffstat (limited to 'src/main/java/com/thatgravyboat/skyblockhud/core')
38 files changed, 4745 insertions, 4447 deletions
diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/BackgroundBlur.java b/src/main/java/com/thatgravyboat/skyblockhud/core/BackgroundBlur.java index 9379d62..e95e896 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/BackgroundBlur.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/BackgroundBlur.java @@ -21,273 +21,288 @@ import org.lwjgl.opengl.GL11; public class BackgroundBlur { - private static HashMap<Float, Framebuffer> blurOutput = new HashMap<>(); - private static HashMap<Float, Long> lastBlurUse = new HashMap<>(); - private static long lastBlur = 0; - private static HashSet<Float> requestedBlurs = new HashSet<>(); - - private static int fogColour = 0; - private static boolean registered = false; - - public static void registerListener() { - if (!registered) { - registered = true; - MinecraftForge.EVENT_BUS.register(new BackgroundBlur()); + private static HashMap<Float, Framebuffer> blurOutput = new HashMap<>(); + private static HashMap<Float, Long> lastBlurUse = new HashMap<>(); + private static long lastBlur = 0; + private static HashSet<Float> requestedBlurs = new HashSet<>(); + + private static int fogColour = 0; + private static boolean registered = false; + + public static void registerListener() { + if (!registered) { + registered = true; + MinecraftForge.EVENT_BUS.register(new BackgroundBlur()); + } } - } - private static boolean shouldBlur = true; + private static boolean shouldBlur = true; - public static void markDirty() { - if (Minecraft.getMinecraft().theWorld != null) { - shouldBlur = true; + public static void markDirty() { + if (Minecraft.getMinecraft().theWorld != null) { + shouldBlur = true; + } } - } - public static void processBlurs() { - if (shouldBlur) { - shouldBlur = false; + public static void processBlurs() { + if (shouldBlur) { + shouldBlur = false; - long currentTime = System.currentTimeMillis(); + long currentTime = System.currentTimeMillis(); - for (float blur : requestedBlurs) { - lastBlur = currentTime; - lastBlurUse.put(blur, currentTime); + for (float blur : requestedBlurs) { + lastBlur = currentTime; + lastBlurUse.put(blur, currentTime); - int width = Minecraft.getMinecraft().displayWidth; - int height = Minecraft.getMinecraft().displayHeight; + int width = Minecraft.getMinecraft().displayWidth; + int height = Minecraft.getMinecraft().displayHeight; - Framebuffer output = blurOutput.computeIfAbsent( - blur, - k -> { - Framebuffer fb = new Framebuffer(width, height, false); - fb.setFramebufferFilter(GL11.GL_NEAREST); - return fb; - } - ); + Framebuffer output = blurOutput.computeIfAbsent( + blur, + k -> { + Framebuffer fb = new Framebuffer(width, height, false); + fb.setFramebufferFilter(GL11.GL_NEAREST); + return fb; + } + ); - output.framebufferWidth = output.framebufferTextureWidth = width; - output.framebufferHeight = output.framebufferTextureHeight = height; + output.framebufferWidth = + output.framebufferTextureWidth = width; + output.framebufferHeight = + output.framebufferTextureHeight = height; - blurBackground(output, blur); - } + blurBackground(output, blur); + } - Set<Float> remove = new HashSet<>(); - for (Map.Entry<Float, Long> entry : lastBlurUse.entrySet()) { - if (currentTime - entry.getValue() > 30 * 1000) { - remove.add(entry.getKey()); - } - } - remove.remove(5f); + Set<Float> remove = new HashSet<>(); + for (Map.Entry<Float, Long> entry : lastBlurUse.entrySet()) { + if (currentTime - entry.getValue() > 30 * 1000) { + remove.add(entry.getKey()); + } + } + remove.remove(5f); - lastBlurUse.keySet().removeAll(remove); - blurOutput.keySet().removeAll(remove); + lastBlurUse.keySet().removeAll(remove); + blurOutput.keySet().removeAll(remove); - requestedBlurs.clear(); + requestedBlurs.clear(); + } } - } - @SubscribeEvent(priority = EventPriority.HIGHEST) - public void onScreenRender(RenderGameOverlayEvent.Pre event) { - if (event.type == RenderGameOverlayEvent.ElementType.ALL) { - processBlurs(); - } - } - - @SubscribeEvent - public void onFogColour(EntityViewRenderEvent.FogColors event) { - fogColour = 0xff000000; - fogColour |= ((int) (event.red * 255) & 0xFF) << 16; - fogColour |= ((int) (event.green * 255) & 0xFF) << 8; - fogColour |= (int) (event.blue * 255) & 0xFF; - } - - private static Shader blurShaderHorz = null; - private static Shader blurShaderVert = null; - private static Framebuffer blurOutputHorz = null; - - /** - * Creates a projection matrix that projects from our coordinate space [0->width; 0->height] to OpenGL coordinate - * space [-1 -> 1; 1 -> -1] (Note: flipped y-axis). - * - * This is so that we can render to and from the framebuffer in a way that is familiar to us, instead of needing to - * apply scales and translations manually. - */ - private static Matrix4f createProjectionMatrix(int width, int height) { - Matrix4f projMatrix = new Matrix4f(); - projMatrix.setIdentity(); - projMatrix.m00 = 2.0F / (float) width; - projMatrix.m11 = 2.0F / (float) (-height); - projMatrix.m22 = -0.0020001999F; - projMatrix.m33 = 1.0F; - projMatrix.m03 = -1.0F; - projMatrix.m13 = 1.0F; - projMatrix.m23 = -1.0001999F; - return projMatrix; - } - - private static void blurBackground(Framebuffer output, float blurFactor) { - if ( - !OpenGlHelper.isFramebufferEnabled() || - !OpenGlHelper.areShadersSupported() - ) return; - - int width = Minecraft.getMinecraft().displayWidth; - int height = Minecraft.getMinecraft().displayHeight; - - GlStateManager.matrixMode(GL11.GL_PROJECTION); - GlStateManager.loadIdentity(); - GlStateManager.ortho(0.0D, width, height, 0.0D, 1000.0D, 3000.0D); - GlStateManager.matrixMode(GL11.GL_MODELVIEW); - GlStateManager.loadIdentity(); - GlStateManager.translate(0.0F, 0.0F, -2000.0F); - - if (blurOutputHorz == null) { - blurOutputHorz = new Framebuffer(width, height, false); - blurOutputHorz.setFramebufferFilter(GL11.GL_NEAREST); + @SubscribeEvent(priority = EventPriority.HIGHEST) + public void onScreenRender(RenderGameOverlayEvent.Pre event) { + if (event.type == RenderGameOverlayEvent.ElementType.ALL) { + processBlurs(); + } } - if (blurOutputHorz == null || output == null) { - return; + + @SubscribeEvent + public void onFogColour(EntityViewRenderEvent.FogColors event) { + fogColour = 0xff000000; + fogColour |= ((int) (event.red * 255) & 0xFF) << 16; + fogColour |= ((int) (event.green * 255) & 0xFF) << 8; + fogColour |= (int) (event.blue * 255) & 0xFF; } - if ( - blurOutputHorz.framebufferWidth != width || - blurOutputHorz.framebufferHeight != height - ) { - blurOutputHorz.createBindFramebuffer(width, height); - blurShaderHorz.setProjectionMatrix(createProjectionMatrix(width, height)); - Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(false); + + private static Shader blurShaderHorz = null; + private static Shader blurShaderVert = null; + private static Framebuffer blurOutputHorz = null; + + /** + * Creates a projection matrix that projects from our coordinate space [0->width; 0->height] to OpenGL coordinate + * space [-1 -> 1; 1 -> -1] (Note: flipped y-axis). + * + * This is so that we can render to and from the framebuffer in a way that is familiar to us, instead of needing to + * apply scales and translations manually. + */ + private static Matrix4f createProjectionMatrix(int width, int height) { + Matrix4f projMatrix = new Matrix4f(); + projMatrix.setIdentity(); + projMatrix.m00 = 2.0F / (float) width; + projMatrix.m11 = 2.0F / (float) (-height); + projMatrix.m22 = -0.0020001999F; + projMatrix.m33 = 1.0F; + projMatrix.m03 = -1.0F; + projMatrix.m13 = 1.0F; + projMatrix.m23 = -1.0001999F; + return projMatrix; } - try { - blurShaderHorz = - new Shader( - Minecraft.getMinecraft().getResourceManager(), - "blur", - Minecraft.getMinecraft().getFramebuffer(), - blurOutputHorz - ); - blurShaderHorz.getShaderManager().getShaderUniform("BlurDir").set(1, 0); - blurShaderHorz.setProjectionMatrix(createProjectionMatrix(width, height)); - } catch (Exception ignored) {} - try { - blurShaderVert = - new Shader( - Minecraft.getMinecraft().getResourceManager(), - "blur", - blurOutputHorz, - output - ); - blurShaderVert.getShaderManager().getShaderUniform("BlurDir").set(0, 1); - blurShaderVert.setProjectionMatrix(createProjectionMatrix(width, height)); - } catch (Exception ignored) {} - if (blurShaderHorz != null && blurShaderVert != null) { - if ( - blurShaderHorz.getShaderManager().getShaderUniform("Radius") == null - ) { - //Corrupted shader? - return; - } - - blurShaderHorz - .getShaderManager() - .getShaderUniform("Radius") - .set(blurFactor); - blurShaderVert - .getShaderManager() - .getShaderUniform("Radius") - .set(blurFactor); - - GL11.glPushMatrix(); - /*GL30.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, Minecraft.getMinecraft().getFramebuffer().framebufferObject); + private static void blurBackground(Framebuffer output, float blurFactor) { + if ( + !OpenGlHelper.isFramebufferEnabled() || + !OpenGlHelper.areShadersSupported() + ) return; + + int width = Minecraft.getMinecraft().displayWidth; + int height = Minecraft.getMinecraft().displayHeight; + + GlStateManager.matrixMode(GL11.GL_PROJECTION); + GlStateManager.loadIdentity(); + GlStateManager.ortho(0.0D, width, height, 0.0D, 1000.0D, 3000.0D); + GlStateManager.matrixMode(GL11.GL_MODELVIEW); + GlStateManager.loadIdentity(); + GlStateManager.translate(0.0F, 0.0F, -2000.0F); + + if (blurOutputHorz == null) { + blurOutputHorz = new Framebuffer(width, height, false); + blurOutputHorz.setFramebufferFilter(GL11.GL_NEAREST); + } + if (blurOutputHorz == null || output == null) { + return; + } + if ( + blurOutputHorz.framebufferWidth != width || + blurOutputHorz.framebufferHeight != height + ) { + blurOutputHorz.createBindFramebuffer(width, height); + blurShaderHorz.setProjectionMatrix( + createProjectionMatrix(width, height) + ); + Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(false); + } + + try { + blurShaderHorz = + new Shader( + Minecraft.getMinecraft().getResourceManager(), + "blur", + Minecraft.getMinecraft().getFramebuffer(), + blurOutputHorz + ); + blurShaderHorz + .getShaderManager() + .getShaderUniform("BlurDir") + .set(1, 0); + blurShaderHorz.setProjectionMatrix( + createProjectionMatrix(width, height) + ); + } catch (Exception ignored) {} + try { + blurShaderVert = + new Shader( + Minecraft.getMinecraft().getResourceManager(), + "blur", + blurOutputHorz, + output + ); + blurShaderVert + .getShaderManager() + .getShaderUniform("BlurDir") + .set(0, 1); + blurShaderVert.setProjectionMatrix( + createProjectionMatrix(width, height) + ); + } catch (Exception ignored) {} + if (blurShaderHorz != null && blurShaderVert != null) { + if ( + blurShaderHorz.getShaderManager().getShaderUniform("Radius") == + null + ) { + //Corrupted shader? + return; + } + + blurShaderHorz + .getShaderManager() + .getShaderUniform("Radius") + .set(blurFactor); + blurShaderVert + .getShaderManager() + .getShaderUniform("Radius") + .set(blurFactor); + + GL11.glPushMatrix(); + /*GL30.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, Minecraft.getMinecraft().getFramebuffer().framebufferObject); GL30.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, output.framebufferObject); GL30.glBlitFramebuffer(0, 0, width, height, 0, 0, output.framebufferWidth, output.framebufferHeight, GL11.GL_COLOR_BUFFER_BIT, GL11.GL_NEAREST);*/ - blurShaderHorz.loadShader(0); - blurShaderVert.loadShader(0); - GlStateManager.enableDepth(); - GL11.glPopMatrix(); + blurShaderHorz.loadShader(0); + blurShaderVert.loadShader(0); + GlStateManager.enableDepth(); + GL11.glPopMatrix(); - Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(false); + Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(false); + } } - } - - public static void renderBlurredBackground( - float blurStrength, - int screenWidth, - int screenHeight, - int x, - int y, - int blurWidth, - int blurHeight - ) { - renderBlurredBackground( - blurStrength, - screenWidth, - screenHeight, - x, - y, - blurWidth, - blurHeight, - false - ); - } - - /** - * Renders a subsection of the blurred framebuffer on to the corresponding section of the screen. - * Essentially, this method will "blur" the background inside the bounds specified by [x->x+blurWidth, y->y+blurHeight] - */ - public static void renderBlurredBackground( - float blurStrength, - int screenWidth, - int screenHeight, - int x, - int y, - int blurWidth, - int blurHeight, - boolean forcedUpdate - ) { - if ( - !OpenGlHelper.isFramebufferEnabled() || - !OpenGlHelper.areShadersSupported() - ) return; - if (blurStrength < 0.5) return; - requestedBlurs.add(blurStrength); - - long currentTime = System.currentTimeMillis(); - if (currentTime - lastBlur > 300) { - shouldBlur = true; - if (currentTime - lastBlur > 400 && forcedUpdate) return; + + public static void renderBlurredBackground( + float blurStrength, + int screenWidth, + int screenHeight, + int x, + int y, + int blurWidth, + int blurHeight + ) { + renderBlurredBackground( + blurStrength, + screenWidth, + screenHeight, + x, + y, + blurWidth, + blurHeight, + false + ); } - if (blurOutput.isEmpty()) return; + /** + * Renders a subsection of the blurred framebuffer on to the corresponding section of the screen. + * Essentially, this method will "blur" the background inside the bounds specified by [x->x+blurWidth, y->y+blurHeight] + */ + public static void renderBlurredBackground( + float blurStrength, + int screenWidth, + int screenHeight, + int x, + int y, + int blurWidth, + int blurHeight, + boolean forcedUpdate + ) { + if ( + !OpenGlHelper.isFramebufferEnabled() || + !OpenGlHelper.areShadersSupported() + ) return; + if (blurStrength < 0.5) return; + requestedBlurs.add(blurStrength); + + long currentTime = System.currentTimeMillis(); + if (currentTime - lastBlur > 300) { + shouldBlur = true; + if (currentTime - lastBlur > 400 && forcedUpdate) return; + } - Framebuffer fb = blurOutput.get(blurStrength); - if (fb == null) { - fb = blurOutput.values().iterator().next(); - } + if (blurOutput.isEmpty()) return; - float uMin = x / (float) screenWidth; - float uMax = (x + blurWidth) / (float) screenWidth; - float vMin = (screenHeight - y) / (float) screenHeight; - float vMax = (screenHeight - y - blurHeight) / (float) screenHeight; - - GlStateManager.depthMask(false); - Gui.drawRect(x, y, x + blurWidth, y + blurHeight, fogColour); - fb.bindFramebufferTexture(); - GlStateManager.color(1f, 1f, 1f, 1f); - RenderUtils.drawTexturedRect( - x, - y, - blurWidth, - blurHeight, - uMin, - uMax, - vMin, - vMax - ); - fb.unbindFramebufferTexture(); - GlStateManager.depthMask(true); - } + Framebuffer fb = blurOutput.get(blurStrength); + if (fb == null) { + fb = blurOutput.values().iterator().next(); + } + + float uMin = x / (float) screenWidth; + float uMax = (x + blurWidth) / (float) screenWidth; + float vMin = (screenHeight - y) / (float) screenHeight; + float vMax = (screenHeight - y - blurHeight) / (float) screenHeight; + + GlStateManager.depthMask(false); + Gui.drawRect(x, y, x + blurWidth, y + blurHeight, fogColour); + fb.bindFramebufferTexture(); + GlStateManager.color(1f, 1f, 1f, 1f); + RenderUtils.drawTexturedRect( + x, + y, + blurWidth, + blurHeight, + uMin, + uMax, + vMin, + vMax + ); + fb.unbindFramebufferTexture(); + GlStateManager.depthMask(true); + } } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/ChromaColour.java b/src/main/java/com/thatgravyboat/skyblockhud/core/ChromaColour.java index c8fc14b..b8e97ee 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/ChromaColour.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/ChromaColour.java @@ -4,111 +4,116 @@ import java.awt.*; public class ChromaColour { - public static String special(int chromaSpeed, int alpha, int rgb) { - return special( - chromaSpeed, - alpha, - (rgb & 0xFF0000) >> 16, - (rgb & 0x00FF00) >> 8, - (rgb & 0x0000FF) - ); - } - - private static final int RADIX = 10; - - public static String special( - int chromaSpeed, - int alpha, - int r, - int g, - int b - ) { - StringBuilder sb = new StringBuilder(); - sb.append(Integer.toString(chromaSpeed, RADIX)).append(":"); - sb.append(Integer.toString(alpha, RADIX)).append(":"); - sb.append(Integer.toString(r, RADIX)).append(":"); - sb.append(Integer.toString(g, RADIX)).append(":"); - sb.append(Integer.toString(b, RADIX)); - return sb.toString(); - } - - private static int[] decompose(String csv) { - String[] split = csv.split(":"); - - int[] arr = new int[split.length]; - - for (int i = 0; i < split.length; i++) { - arr[i] = Integer.parseInt(split[split.length - 1 - i], RADIX); + public static String special(int chromaSpeed, int alpha, int rgb) { + return special( + chromaSpeed, + alpha, + (rgb & 0xFF0000) >> 16, + (rgb & 0x00FF00) >> 8, + (rgb & 0x0000FF) + ); } - return arr; - } - - public static int specialToSimpleRGB(String special) { - int[] d = decompose(special); - int r = d[2]; - int g = d[1]; - int b = d[0]; - int a = d[3]; - int chr = d[4]; - - return (a & 0xFF) << 24 | (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF); - } - - public static int getSpeed(String special) { - return decompose(special)[4]; - } - - public static float getSecondsForSpeed(int speed) { - return ( - (255 - speed) / - 254f * - (MAX_CHROMA_SECS - MIN_CHROMA_SECS) + - MIN_CHROMA_SECS - ); - } - - private static final int MIN_CHROMA_SECS = 1; - private static final int MAX_CHROMA_SECS = 60; - - public static long startTime = -1; - - public static int specialToChromaRGB(String special) { - if (startTime < 0) startTime = System.currentTimeMillis(); - - int[] d = decompose(special); - int chr = d[4]; - int a = d[3]; - int r = d[2]; - int g = d[1]; - int b = d[0]; - - float[] hsv = Color.RGBtoHSB(r, g, b, null); - - if (chr > 0) { - float seconds = getSecondsForSpeed(chr); - hsv[0] += (System.currentTimeMillis() - startTime) / 1000f / seconds; - hsv[0] %= 1; - if (hsv[0] < 0) hsv[0] += 1; + + private static final int RADIX = 10; + + public static String special( + int chromaSpeed, + int alpha, + int r, + int g, + int b + ) { + StringBuilder sb = new StringBuilder(); + sb.append(Integer.toString(chromaSpeed, RADIX)).append(":"); + sb.append(Integer.toString(alpha, RADIX)).append(":"); + sb.append(Integer.toString(r, RADIX)).append(":"); + sb.append(Integer.toString(g, RADIX)).append(":"); + sb.append(Integer.toString(b, RADIX)); + return sb.toString(); + } + + private static int[] decompose(String csv) { + String[] split = csv.split(":"); + + int[] arr = new int[split.length]; + + for (int i = 0; i < split.length; i++) { + arr[i] = Integer.parseInt(split[split.length - 1 - i], RADIX); + } + return arr; } - return ( - (a & 0xFF) << 24 | (Color.HSBtoRGB(hsv[0], hsv[1], hsv[2]) & 0x00FFFFFF) - ); - } + public static int specialToSimpleRGB(String |
