diff options
author | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2022-05-14 00:59:25 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-14 09:59:25 +0200 |
commit | 2c592090b9448203559e01326bc2c2d995b15d53 (patch) | |
tree | 821d347aefc828c214d817c8b7be8cf3c0b0ea9f /src/main/java/cc/polyfrost/oneconfig/lwjgl | |
parent | 4b8f98aa1435817c13e7083e30896ef8b5cbdaf0 (diff) | |
download | OneConfig-2c592090b9448203559e01326bc2c2d995b15d53.tar.gz OneConfig-2c592090b9448203559e01326bc2c2d995b15d53.tar.bz2 OneConfig-2c592090b9448203559e01326bc2c2d995b15d53.zip |
de-minecraftify a lot of things + use mixin instead of reflection (#11)
* de-minecraftify
* use mixin instead of reflection
* lol
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/lwjgl')
4 files changed, 26 insertions, 73 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/BlurHandler.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/BlurHandler.java index 7fc725a..973677e 100644 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/BlurHandler.java +++ b/src/main/java/cc/polyfrost/oneconfig/lwjgl/BlurHandler.java @@ -1,11 +1,12 @@ package cc.polyfrost.oneconfig.lwjgl; import cc.polyfrost.oneconfig.gui.OneConfigGui; +import cc.polyfrost.oneconfig.mixin.ShaderGroupAccessor; +import gg.essential.universal.UMinecraft; +import gg.essential.universal.UScreen; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.renderer.EntityRenderer; import net.minecraft.client.shader.Shader; -import net.minecraft.client.shader.ShaderGroup; import net.minecraft.client.shader.ShaderUniform; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.GuiOpenEvent; @@ -15,7 +16,6 @@ import net.minecraftforge.fml.common.gameevent.TickEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import java.lang.reflect.Field; import java.util.List; /** @@ -34,8 +34,6 @@ import java.util.List; public class BlurHandler { private final ResourceLocation blurShader = new ResourceLocation("shaders/post/fade_in_blur.json"); private final Logger logger = LogManager.getLogger("OneConfig - Blur"); - private final Minecraft mc = Minecraft.getMinecraft(); - private Field shaderList = null; private long start; private float lastProgress = 0; @@ -56,22 +54,17 @@ public class BlurHandler { @SubscribeEvent public void onRenderTick(final TickEvent.RenderTickEvent event) { - this.mc.mcProfiler.startSection("blur"); - if (event.phase != TickEvent.Phase.END) { - this.mc.mcProfiler.endSection(); return; } // Only blur on our own menus - if (this.mc.currentScreen == null) { - this.mc.mcProfiler.endSection(); + if (UScreen.getCurrentScreen() == null) { return; } // Only update the shader if one is active - if (!this.mc.entityRenderer.isShaderActive()) { - this.mc.mcProfiler.endSection(); + if (!UMinecraft.getMinecraft().entityRenderer.isShaderActive()) { return; } @@ -81,7 +74,6 @@ public class BlurHandler { // will skip the frame update, which (hopefully) resolves the issue // with the heavy computations after the "animation" is complete. if (progress == this.lastProgress) { - this.mc.mcProfiler.endSection(); return; } @@ -92,11 +84,10 @@ public class BlurHandler { // Why is this being computed every tick? Surely there is a better way? // This needs to be optimized. try { - final List<Shader> listShaders = getShaderList(); + final List<Shader> listShaders = ((ShaderGroupAccessor) Minecraft.getMinecraft().entityRenderer.getShaderGroup()).getListShaders(); // Should not happen. Something bad happened. if (listShaders == null) { - this.mc.mcProfiler.endSection(); return; } @@ -114,8 +105,6 @@ public class BlurHandler { } catch (IllegalArgumentException ex) { this.logger.error("An error.png occurred while updating OneConfig's blur. Please report this!", ex); } - - this.mc.mcProfiler.endSection(); } /** @@ -125,35 +114,27 @@ public class BlurHandler { */ public void reloadBlur(GuiScreen gui) { // Don't do anything if no world is loaded - if (this.mc.theWorld == null) { + if (UMinecraft.getWorld() == null) { return; } - EntityRenderer er = this.mc.entityRenderer; - // If a shader is not already active and the UI is // a one of ours, we should load our own blur! - if (!er.isShaderActive() && gui instanceof OneConfigGui) { - this.mc.entityRenderer.loadShader(this.blurShader); - try { - shaderList = ShaderGroup.class.getDeclaredField("listShaders"); - shaderList.setAccessible(true); - } catch (NoSuchFieldException ignored) { - } + if (!UMinecraft.getMinecraft().entityRenderer.isShaderActive() && gui instanceof OneConfigGui) { + UMinecraft.getMinecraft().entityRenderer.loadShader(this.blurShader); this.start = System.currentTimeMillis(); // If a shader is active and the incoming UI is null or we have blur disabled, stop using the shader. - } else if (er.isShaderActive() && (gui == null)) { - String name = er.getShaderGroup().getShaderGroupName(); + } else if (UMinecraft.getMinecraft().entityRenderer.isShaderActive() && (gui == null)) { + String name = UMinecraft.getMinecraft().entityRenderer.getShaderGroup().getShaderGroupName(); // Only stop our specific blur ;) if (!name.endsWith("fade_in_blur.json")) { return; } - er.stopUseShader(); - shaderList = null; + UMinecraft.getMinecraft().entityRenderer.stopUseShader(); } } @@ -165,13 +146,4 @@ public class BlurHandler { private float getBlurStrengthProgress() { return Math.min((System.currentTimeMillis() - this.start) / 50F, 5.0F); } - - private List<Shader> getShaderList() { - if (shaderList == null) return null; - try { - return (List<Shader>) shaderList.get(this.mc.entityRenderer.getShaderGroup()); - } catch (IllegalAccessException ignored) { - return null; - } - } } diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java index d23f1dd..4276865 100644 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java +++ b/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java @@ -6,18 +6,15 @@ import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.lwjgl.image.Image; import cc.polyfrost.oneconfig.lwjgl.image.ImageLoader; import cc.polyfrost.oneconfig.lwjgl.image.Images; -import net.minecraft.client.Minecraft; +import gg.essential.universal.UGraphics; +import gg.essential.universal.UMinecraft; +import gg.essential.universal.UResolution; import net.minecraft.client.gui.Gui; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.shader.Framebuffer; import org.lwjgl.nanovg.NVGColor; import org.lwjgl.nanovg.NVGPaint; -import org.lwjgl.opengl.Display; import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL14; -import java.awt.*; import java.util.function.LongConsumer; import static org.lwjgl.nanovg.NanoVG.*; @@ -46,18 +43,17 @@ public final class RenderManager { FontManager.INSTANCE.initialize(vg); } - Framebuffer fb = Minecraft.getMinecraft().getFramebuffer(); + Framebuffer fb = UMinecraft.getMinecraft().getFramebuffer(); if (!fb.isStencilEnabled()) { fb.enableStencil(); } GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); if (mcScaling) { - ScaledResolution resolution = new ScaledResolution(Minecraft.getMinecraft()); - nvgBeginFrame(vg, (float) resolution.getScaledWidth_double(), (float) resolution.getScaledHeight_double(), resolution.getScaleFactor()); + nvgBeginFrame(vg, (float) UResolution.getScaledWidth(), (float) UResolution.getScaledHeight(), (float) UResolution.getScaleFactor()); } else { // If we get blurry problems with high DPI monitors, 1 might need to be replaced with Display.getPixelScaleFactor() - nvgBeginFrame(vg, Display.getWidth(), Display.getHeight(), 1); + nvgBeginFrame(vg, UResolution.getWindowWidth(), UResolution.getWindowHeight(), 1); } consumer.accept(vg); @@ -305,33 +301,15 @@ public final class RenderManager { // gl - public static void glColor(Color color) { - glColor(color.getRGB()); - } - - public static void drawScaledString(String text, float x, float y, int color, boolean shadow, float scale) { - GL11.glPushMatrix(); - GL11.glScalef(scale, scale, 1); - Minecraft.getMinecraft().fontRendererObj.drawString(text, x * (1 / scale), y * (1 / scale), color, shadow); - GL11.glPopMatrix(); - } - public static void glColor(int color) { - float f = (float) (color >> 24 & 255) / 255.0F; - float f1 = (float) (color >> 16 & 255) / 255.0F; - float f2 = (float) (color >> 8 & 255) / 255.0F; - float f3 = (float) (color & 255) / 255.0F; - GL11.glColor4f(f1, f2, f3, f); + public static void drawScaledString(String text, float x, float y, int color, boolean shadow, float scale) { //todo replace eventually with either nanovg or UMatrixStack + UGraphics.GL.pushMatrix(); + UGraphics.GL.scale(scale, scale, 1); + UMinecraft.getFontRenderer().drawString(text, x * (1 / scale), y * (1 / scale), color, shadow); + UGraphics.GL.popMatrix(); } public static void drawGlRect(int x, int y, int width, int height, int color) { Gui.drawRect(x, y, x + width, y + height, color); } - - - - // other minecraft functions - public static void displayGuiScreen(GuiScreen guiScreen) { - Minecraft.getMinecraft().displayGuiScreen(guiScreen); - } } diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/plugin/ClassTransformer.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/plugin/ClassTransformer.java index 858d615..8e388dc 100644 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/plugin/ClassTransformer.java +++ b/src/main/java/cc/polyfrost/oneconfig/lwjgl/plugin/ClassTransformer.java @@ -10,6 +10,7 @@ import org.objectweb.asm.tree.*; * Taken from LWJGLTwoPointFive under The Unlicense * <a href="https://github.com/DJtheRedstoner/LWJGLTwoPointFive/blob/master/LICENSE/">https://github.com/DJtheRedstoner/LWJGLTwoPointFive/blob/master/LICENSE/</a> */ +@SuppressWarnings("unused") public class ClassTransformer implements IClassTransformer { @Override public byte[] transform(String name, String transformedName, byte[] basicClass) { diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/plugin/LoadingPlugin.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/plugin/LoadingPlugin.java index b2ae799..6cd8911 100644 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/plugin/LoadingPlugin.java +++ b/src/main/java/cc/polyfrost/oneconfig/lwjgl/plugin/LoadingPlugin.java @@ -1,5 +1,6 @@ package cc.polyfrost.oneconfig.lwjgl.plugin; +import cc.polyfrost.oneconfig.init.OneConfigInit; import net.minecraft.launchwrapper.Launch; import net.minecraft.launchwrapper.LaunchClassLoader; import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin; @@ -20,6 +21,7 @@ public class LoadingPlugin implements IFMLLoadingPlugin { f_exceptions.setAccessible(true); Set<String> exceptions = (Set<String>) f_exceptions.get(Launch.classLoader); exceptions.remove("org.lwjgl."); + OneConfigInit.initialize(new String[]{}); } catch (Exception e) { throw new RuntimeException("e"); } |