From b5a1aea2239b0beace4d4407d2ab75294c6eab12 Mon Sep 17 00:00:00 2001 From: nextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com> Date: Tue, 10 May 2022 18:51:51 +0100 Subject: reduce dependency on minecraft --- .../oneconfig/config/interfaces/Config.java | 4 +- .../java/cc/polyfrost/oneconfig/gui/SideBar.java | 7 ++-- .../cc/polyfrost/oneconfig/gui/pages/HomePage.java | 2 - .../cc/polyfrost/oneconfig/lwjgl/OneColor.java | 9 ++++- .../polyfrost/oneconfig/lwjgl/RenderManager.java | 43 +++++++++++++--------- 5 files changed, 37 insertions(+), 28 deletions(-) (limited to 'src/main/java/cc') diff --git a/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java b/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java index e8ffe42..756d3c3 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java @@ -10,8 +10,8 @@ import cc.polyfrost.oneconfig.config.profiles.Profiles; import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.gui.elements.config.*; import cc.polyfrost.oneconfig.gui.pages.ModConfigPage; +import cc.polyfrost.oneconfig.lwjgl.RenderManager; import com.google.gson.*; -import net.minecraft.client.Minecraft; import java.io.*; import java.lang.reflect.Field; @@ -182,6 +182,6 @@ public class Config { */ public void openGui() { if (mod == null) return; - Minecraft.getMinecraft().displayGuiScreen(new OneConfigGui(new ModConfigPage(mod.defaultPage))); + RenderManager.displayGuiScreen(new OneConfigGui(new ModConfigPage(mod.defaultPage))); } } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java b/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java index 978f420..1850367 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java @@ -8,7 +8,6 @@ import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.lwjgl.image.Images; import cc.polyfrost.oneconfig.utils.MathUtils; -import net.minecraft.client.Minecraft; import java.util.ArrayList; import java.util.List; @@ -29,12 +28,12 @@ public class SideBar { btnList.add(new BasicButton(192, 36, "Screenshots", Images.SCREENSHOT, null, -3, BasicButton.ALIGNMENT_LEFT)); btnList.add(new BasicButton(192, 36, "HUD Settings", Images.HUD_SETTINGS, null, -3, BasicButton.ALIGNMENT_LEFT)); btnList.add(new BasicButton(192, 36, "Preferences", Images.PREFERENCES, null, -3, BasicButton.ALIGNMENT_LEFT)); - btnList.add(new BasicButton(192, 36, "Close", Images.CLOSE, null, -1, BasicButton.ALIGNMENT_LEFT, () -> Minecraft.getMinecraft().displayGuiScreen(null))); + btnList.add(new BasicButton(192, 36, "Close", Images.CLOSE, null, -1, BasicButton.ALIGNMENT_LEFT, () -> RenderManager.displayGuiScreen(null))); btnList.add(new BasicButton(192, 36, "Minimize", Images.MINIMIZE, null, -1, BasicButton.ALIGNMENT_LEFT, () -> { OneConfigGui.instanceToRestore = OneConfigGui.INSTANCE; - Minecraft.getMinecraft().displayGuiScreen(null); + RenderManager.displayGuiScreen(null); })); - btnList.add(new BasicButton(192, 36, "Edit HUD", Images.HUD, null, 0, BasicButton.ALIGNMENT_LEFT, () -> Minecraft.getMinecraft().displayGuiScreen(new HudGui()))); + btnList.add(new BasicButton(192, 36, "Edit HUD", Images.HUD, null, 0, BasicButton.ALIGNMENT_LEFT, () -> RenderManager.displayGuiScreen(new HudGui()))); } public void draw(long vg, int x, int y) { diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/HomePage.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/HomePage.java index 9b54bff..dd73183 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/HomePage.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/HomePage.java @@ -12,8 +12,6 @@ import cc.polyfrost.oneconfig.utils.InputUtils; import java.awt.*; -import java.awt.*; - public class HomePage extends Page { private final BasicButton btn = new BasicButton(184, 36, "Socials", Images.SHARE, Images.LAUNCH, 1, BasicButton.ALIGNMENT_CENTER); diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/OneColor.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/OneColor.java index 423ecee..7a4ae1e 100644 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/OneColor.java +++ b/src/main/java/cc/polyfrost/oneconfig/lwjgl/OneColor.java @@ -155,7 +155,7 @@ public class OneColor { /** * Get the RGBA color from the HSB color, and apply the alpha. */ - public int HSBAtoRGBA(float hue, float saturation, float brightness, int alpha) { + public static int HSBAtoRGBA(float hue, float saturation, float brightness, int alpha) { int temp = Color.HSBtoRGB(hue / 360f, saturation / 100f, brightness / 100f); return ((temp & 0x00ffffff) | (alpha << 24)); } @@ -163,7 +163,7 @@ public class OneColor { /** * Get the HSBA color from the RGBA color. */ - public short[] RGBAtoHSBA(int rgba) { + public static short[] RGBAtoHSBA(int rgba) { short[] hsb = new short[4]; float[] hsbArray = Color.RGBtoHSB((rgba >> 16 & 255), (rgba >> 8 & 255), (rgba & 255), null); hsb[0] = (short) (hsbArray[0] * 360); @@ -181,4 +181,9 @@ public class OneColor { rgba = Integer.parseInt(hex, 16); hsba = RGBAtoHSBA(rgba); } + + @Override + public String toString() { + return "OneColor{rgba=[r=" + getRed() + ", g=" + getGreen() + ", b=" + getBlue() + ", a=" + getAlpha() + "], hsba=[h=" + getHue() + ", s=" + getSaturation() + ", b=" + getBrightness() + ", a=" + getAlpha() + "], hex=" + getHex() + "}"; + } } diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java index 979acde..297fcfc 100644 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java +++ b/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java @@ -1,15 +1,15 @@ package cc.polyfrost.oneconfig.lwjgl; import cc.polyfrost.oneconfig.config.OneConfigConfig; -import cc.polyfrost.oneconfig.lwjgl.font.Font; import cc.polyfrost.oneconfig.lwjgl.font.FontManager; 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 net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.ScaledResolution; -import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.shader.Framebuffer; import org.lwjgl.nanovg.NVGColor; import org.lwjgl.nanovg.NVGPaint; @@ -63,7 +63,7 @@ public final class RenderManager { nvgEndFrame(vg); - GlStateManager.popAttrib(); + GL11.glPopAttrib(); } public static void drawRectangle(long vg, float x, float y, float width, float height, int color) { // TODO make everything use this one day @@ -314,10 +314,10 @@ public final class RenderManager { } public static void drawScaledString(String text, float x, float y, int color, boolean shadow, float scale) { - GlStateManager.pushMatrix(); - GlStateManager.scale(scale, scale, 1); + GL11.glPushMatrix(); + GL11.glScalef(scale, scale, 1); Minecraft.getMinecraft().fontRendererObj.drawString(text, x * (1 / scale), y * (1 / scale), color, shadow); - GlStateManager.popMatrix(); + GL11.glPopMatrix(); } public static void glColor(int color) { @@ -325,29 +325,36 @@ public final class RenderManager { float f1 = (float) (color >> 16 & 255) / 255.0F; float f2 = (float) (color >> 8 & 255) / 255.0F; float f3 = (float) (color & 255) / 255.0F; - GlStateManager.color(f1, f2, f3, f); + GL11.glColor4f(f1, f2, f3, f); } public static void drawDottedLine(float sx, float sy, float ex, float ey, int width, int factor, int color) { - GlStateManager.pushMatrix(); + GL11.glPushMatrix(); GL11.glLineStipple(factor, (short) 0xAAAA); GL11.glEnable(GL11.GL_LINE_STIPPLE); - GlStateManager.pushMatrix(); - GlStateManager.disableTexture2D(); - GlStateManager.enableBlend(); - GlStateManager.disableAlpha(); - GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + GL11.glPushMatrix(); + GL11.glDisable(GL11.GL_TEXTURE_2D); + GL11.glEnable(GL11.GL_BLEND); + GL11.glDisable(GL11.GL_ALPHA); + OpenGlHelper.glBlendFunc(770, 771, 1, 0); glColor(color); GL11.glLineWidth(width); GL11.glBegin(GL11.GL_LINES); GL11.glVertex2d(sx, sy); GL11.glVertex2d(ex, ey); GL11.glEnd(); - GlStateManager.disableBlend(); - GlStateManager.enableAlpha(); - GlStateManager.enableTexture2D(); - GlStateManager.popMatrix(); + GL11.glDisable(GL11.GL_BLEND); + GL11.glEnable(GL11.GL_ALPHA); + GL11.glEnable(GL11.GL_TEXTURE_2D); + GL11.glPopMatrix(); GL11.glDisable(GL11.GL_LINE_STIPPLE); - GlStateManager.popMatrix(); + GL11.glPopMatrix(); + } + + + + // other minecraft functions + public static void displayGuiScreen(GuiScreen guiScreen) { + Minecraft.getMinecraft().displayGuiScreen(guiScreen); } } -- cgit