diff options
99 files changed, 2341 insertions, 965 deletions
diff --git a/api/OneConfig.api b/api/OneConfig.api index 24a9286..da10ec7 100644 --- a/api/OneConfig.api +++ b/api/OneConfig.api @@ -466,17 +466,6 @@ public abstract interface class cc/polyfrost/oneconfig/gui/GuiPause { public abstract fun doesGuiPauseGame ()Z } -public class cc/polyfrost/oneconfig/gui/HudGui : cc/polyfrost/oneconfig/libs/universal/UScreen, cc/polyfrost/oneconfig/gui/GuiPause { - public fun <init> (Z)V - public fun doesGuiPauseGame ()Z - public fun initScreen (II)V - public fun onDrawScreen (Lcc/polyfrost/oneconfig/libs/universal/UMatrixStack;IIF)V - public fun onKeyPressed (ICLcc/polyfrost/oneconfig/libs/universal/UKeyboard$Modifiers;)V - public fun onMouseClicked (DDI)V - public fun onMouseReleased (DDI)V - public fun onScreenClose ()V -} - public class cc/polyfrost/oneconfig/gui/OneConfigGui : cc/polyfrost/oneconfig/libs/universal/UScreen, cc/polyfrost/oneconfig/gui/GuiPause { public static field INSTANCE Lcc/polyfrost/oneconfig/gui/OneConfigGui; public field allowClose Z @@ -565,12 +554,12 @@ public class cc/polyfrost/oneconfig/gui/elements/BasicButton : cc/polyfrost/onec protected field icon1 Lcc/polyfrost/oneconfig/internal/assets/SVGs; protected field icon2 Lcc/polyfrost/oneconfig/internal/assets/SVGs; protected field text Ljava/lang/String; - public field x I - public field y I + public field x F + public field y F public fun <init> (IILcc/polyfrost/oneconfig/internal/assets/SVGs;ILcc/polyfrost/oneconfig/utils/color/ColorPalette;)V public fun <init> (IILjava/lang/String;ILcc/polyfrost/oneconfig/utils/color/ColorPalette;)V public fun <init> (IILjava/lang/String;Lcc/polyfrost/oneconfig/internal/assets/SVGs;Lcc/polyfrost/oneconfig/internal/assets/SVGs;ILcc/polyfrost/oneconfig/utils/color/ColorPalette;)V - public fun draw (JII)V + public fun draw (JFF)V public fun getPage ()Lcc/polyfrost/oneconfig/gui/pages/Page; public fun getText ()Ljava/lang/String; public fun hasClickAction ()Z @@ -603,7 +592,7 @@ public class cc/polyfrost/oneconfig/gui/elements/BasicElement { public fun <init> (IILcc/polyfrost/oneconfig/utils/color/ColorPalette;ZF)V public fun <init> (IIZ)V public fun disable (Z)V - public fun draw (JII)V + public fun draw (JFF)V public fun getHeight ()I public fun getWidth ()I public fun ignoreBlockedTouches (Z)V @@ -618,12 +607,12 @@ public class cc/polyfrost/oneconfig/gui/elements/BasicElement { public fun setHeight (I)V public fun setToggled (Z)V public fun setWidth (I)V - public fun update (II)V + public fun update (FF)V } public class cc/polyfrost/oneconfig/gui/elements/ColorSelector { - public fun <init> (Lcc/polyfrost/oneconfig/config/core/OneColor;II)V - public fun <init> (Lcc/polyfrost/oneconfig/config/core/OneColor;IIZ)V + public fun <init> (Lcc/polyfrost/oneconfig/config/core/OneColor;FF)V + public fun <init> (Lcc/polyfrost/oneconfig/config/core/OneColor;FFZ)V public fun draw (J)V public fun getColor ()Lcc/polyfrost/oneconfig/config/core/OneColor; public fun isAlphaAllowed ()Z @@ -634,7 +623,7 @@ public class cc/polyfrost/oneconfig/gui/elements/ColorSelector { public class cc/polyfrost/oneconfig/gui/elements/ModCard : cc/polyfrost/oneconfig/gui/elements/BasicElement { public fun <init> (Lcc/polyfrost/oneconfig/config/data/Mod;ZZZLcc/polyfrost/oneconfig/gui/pages/ModsPage;)V - public fun draw (JII)V + public fun draw (JFF)V public fun getModData ()Lcc/polyfrost/oneconfig/config/data/Mod; public fun isActive ()Z public fun isDisabled ()Z @@ -648,11 +637,11 @@ public class cc/polyfrost/oneconfig/gui/elements/Slider : cc/polyfrost/oneconfig protected field dragPointerSize F protected field value F public fun <init> (IFFF)V - public fun draw (JII)V + public fun draw (JFF)V public fun getValue ()F public fun isDragging ()Z public fun setValue (F)V - public fun update (II)V + public fun update (FF)V } public class cc/polyfrost/oneconfig/gui/elements/config/ConfigButton : cc/polyfrost/oneconfig/config/elements/BasicOption { @@ -750,7 +739,7 @@ public class cc/polyfrost/oneconfig/gui/elements/config/ConfigTextBox : cc/polyf public class cc/polyfrost/oneconfig/gui/elements/text/NumberInputField : cc/polyfrost/oneconfig/gui/elements/text/TextInputField { public fun <init> (IIFFFF)V public fun arrowsClicked ()Z - public fun draw (JII)V + public fun draw (JFF)V public fun getCurrentValue ()F public fun onClose ()V public fun setCurrentValue (F)V @@ -778,12 +767,12 @@ public class cc/polyfrost/oneconfig/gui/elements/text/TextInputField : cc/polyfr protected field startLine I protected field vg J protected field wrappedText Ljava/util/ArrayList; - protected field x I - protected field y I + protected field x F + protected field y F public fun <init> (IILjava/lang/String;ZZ)V public fun <init> (IILjava/lang/String;ZZLcc/polyfrost/oneconfig/internal/assets/SVGs;)V public fun <init> (IIZLjava/lang/String;)V - public fun draw (JII)V + public fun draw (JFF)V public fun getInput ()Ljava/lang/String; public fun getLines ()I public fun getPassword ()Z @@ -849,76 +838,121 @@ public abstract class cc/polyfrost/oneconfig/gui/pages/Page { public fun scrollWithDraw (JII)V } +public abstract class cc/polyfrost/oneconfig/hud/BasicHud : cc/polyfrost/oneconfig/hud/Hud { + protected field bgColor Lcc/polyfrost/oneconfig/config/core/OneColor; + protected field border Z + protected field borderColor Lcc/polyfrost/oneconfig/config/core/OneColor; + protected field borderSize F + protected field cornerRadius F + protected field paddingX F + protected field paddingY F + protected field rounded Z + public fun <init> ()V + public fun <init> (Z)V + public fun <init> (ZFF)V + public fun <init> (ZFFF)V + public fun <init> (ZFFFZFFFLcc/polyfrost/oneconfig/config/core/OneColor;ZFLcc/polyfrost/oneconfig/config/core/OneColor;)V + public fun drawAll (Lcc/polyfrost/oneconfig/libs/universal/UMatrixStack;Z)V + protected fun drawBackground (FFFFF)V + public fun setScale (FZ)V + protected fun shouldDrawBackground ()Z +} + public class cc/polyfrost/oneconfig/hud/HUDUtils { public fun <init> ()V public static fun addHudOptions (Lcc/polyfrost/oneconfig/config/elements/OptionPage;Ljava/lang/reflect/Field;Ljava/lang/Object;Lcc/polyfrost/oneconfig/config/Config;)V } public abstract class cc/polyfrost/oneconfig/hud/Hud { - public field bgColor Lcc/polyfrost/oneconfig/config/core/OneColor; - public field border Z - public field borderColor Lcc/polyfrost/oneconfig/config/core/OneColor; - public field borderSize F - public field cornerRadius F - public field enabled Z - public field paddingX F - public field paddingY F - public field rounded Z - public field scale F + protected field enabled Z + public final field position Lcc/polyfrost/oneconfig/hud/Position; + protected field scale F public field showInChat Z public field showInDebug Z public field showInGuis Z - public field xUnscaled D - public field yUnscaled D + public fun <init> ()V public fun <init> (Z)V - public fun <init> (ZII)V - public fun <init> (ZIIFZIIILcc/polyfrost/oneconfig/config/core/OneColor;ZFLcc/polyfrost/oneconfig/config/core/OneColor;)V - public fun <init> (ZIII)V - public abstract fun draw (Lcc/polyfrost/oneconfig/libs/universal/UMatrixStack;IIF)V - public fun drawAll (Lcc/polyfrost/oneconfig/libs/universal/UMatrixStack;FFFZ)V - public fun drawBackground ()Z - public fun drawExample (Lcc/polyfrost/oneconfig/libs/universal/UMatrixStack;IIF)V - public fun drawExampleAll (Lcc/polyfrost/oneconfig/libs/universal/UMatrixStack;FFFZ)V - public fun getExampleHeight (F)I - public fun getExampleWidth (F)I - public abstract fun getHeight (F)I - public abstract fun getWidth (F)I - public fun getXScaled (I)F - public fun getYScaled (I)F + public fun <init> (ZFF)V + public fun <init> (ZFFF)V + protected abstract fun draw (Lcc/polyfrost/oneconfig/libs/universal/UMatrixStack;FFFZ)V + public fun drawAll (Lcc/polyfrost/oneconfig/libs/universal/UMatrixStack;Z)V + protected abstract fun getHeight (FZ)F + public fun getScale ()F + protected abstract fun getWidth (FZ)F public fun isEnabled ()Z + protected fun preRender (Z)V public fun setConfig (Lcc/polyfrost/oneconfig/config/Config;)V + public fun setScale (FZ)V + protected fun shouldShow ()Z +} + +public class cc/polyfrost/oneconfig/hud/Position { + public fun <init> (FFFF)V + public fun <init> (FFFFFF)V + public fun getBottomY ()F + public fun getBottomY (F)F + public fun getCenterX ()F + public fun getCenterX (F)F + public fun getCenterY ()F + public fun getCenterY (F)F + public fun getHeight ()F + public fun getRightX ()F + public fun getRightX (F)F + public fun getWidth ()F + public fun getX ()F + public fun getX (F)F + public fun getY ()F + public fun getY (F)F + public fun setPosition (FF)V + public fun setPosition (FFFF)V + public fun setSize (FF)V + public fun updateSizePosition (FF)V +} + +public final class cc/polyfrost/oneconfig/hud/Position$AnchorPosition : java/lang/Enum { + public static final field BOTTOM_CENTER Lcc/polyfrost/oneconfig/hud/Position$AnchorPosition; + public static final field BOTTOM_LEFT Lcc/polyfrost/oneconfig/hud/Position$AnchorPosition; + public static final field BOTTOM_RIGHT Lcc/polyfrost/oneconfig/hud/Position$AnchorPosition; + public static final field MIDDLE_CENTER Lcc/polyfrost/oneconfig/hud/Position$AnchorPosition; + public static final field MIDDLE_LEFT Lcc/polyfrost/oneconfig/hud/Position$AnchorPosition; + public static final field MIDDLE_RIGHT Lcc/polyfrost/oneconfig/hud/Position$AnchorPosition; + public static final field TOP_CENTER Lcc/polyfrost/oneconfig/hud/Position$AnchorPosition; + public static final field TOP_LEFT Lcc/polyfrost/oneconfig/hud/Position$AnchorPosition; + public static final field TOP_RIGHT Lcc/polyfrost/oneconfig/hud/Position$AnchorPosition; + public final field x F + public final field y F + public static fun valueOf (Ljava/lang/String;)Lcc/polyfrost/oneconfig/hud/Position$AnchorPosition; + public static fun values ()[Lcc/polyfrost/oneconfig/hud/Position$AnchorPosition; } public abstract class cc/polyfrost/oneconfig/hud/SingleTextHud : cc/polyfrost/oneconfig/hud/TextHud { - public field brackets Z - public field title Ljava/lang/String; - public field titleLocation I + protected field brackets Z + protected field title Ljava/lang/String; + protected field titleLocation I public fun <init> (Ljava/lang/String;Z)V public fun <init> (Ljava/lang/String;ZII)V protected final fun getCompleteText (Ljava/lang/String;)Ljava/lang/String; - protected fun getExampleLines (Ljava/util/List;)V - protected fun getExampleLinesFrequent (Ljava/util/List;)V - protected fun getExampleText ()Ljava/lang/String; - protected fun getExampleTextFrequent ()Ljava/lang/String; - protected fun getLines (Ljava/util/List;)V - protected fun getLinesFrequent (Ljava/util/List;)V - protected abstract fun getText ()Ljava/lang/String; - protected fun getTextFrequent ()Ljava/lang/String; -} - -public abstract class cc/polyfrost/oneconfig/hud/TextHud : cc/polyfrost/oneconfig/hud/Hud { - public field color Lcc/polyfrost/oneconfig/config/core/OneColor; + protected fun getLines (Ljava/util/List;Z)V + protected fun getLinesFrequent (Ljava/util/List;Z)V + protected abstract fun getText (Z)Ljava/lang/String; + protected fun getTextFrequent (Z)Ljava/lang/String; +} + +public abstract class cc/polyfrost/oneconfig/hud/TextHud : cc/polyfrost/oneconfig/hud/BasicHud { + protected field color Lcc/polyfrost/oneconfig/config/core/OneColor; protected field lines Ljava/util/List; - public field textType I + protected field textType I public fun <init> (Z)V public fun <init> (ZII)V - public fun draw (Lcc/polyfrost/oneconfig/libs/universal/UMatrixStack;IIF)V - protected fun getExampleLines (Ljava/util/List;)V - protected fun getExampleLinesFrequent (Ljava/util/List;)V - public fun getHeight (F)I - protected abstract fun getLines (Ljava/util/List;)V - protected fun getLinesFrequent (Ljava/util/List;)V - public fun getWidth (F)I + public fun draw (Lcc/polyfrost/oneconfig/libs/universal/UMatrixStack;FFFZ)V + protected fun drawLine (Ljava/lang/String;FFF)V + protected fun getHeight (FZ)F + protected fun getLineWidth (Ljava/lang/String;F)F + protected abstract fun getLines (Ljava/util/List;Z)V + protected fun getLinesFrequent (Ljava/util/List;Z)V + protected fun getWidth (FZ)F + protected fun preRender (Z)V + public fun shouldDrawBackground ()Z } public class cc/polyfrost/oneconfig/images/Image { @@ -1003,18 +1037,49 @@ public abstract interface class cc/polyfrost/oneconfig/platform/MousePlatform { public abstract fun isButtonDown (I)Z } +public abstract interface class cc/polyfrost/oneconfig/platform/NanoVGPlatform { + public static final field NVG_ANTIALIAS I + public static final field NVG_DEBUG I + public static final field NVG_IMAGE_NODELETE I + public static final field NVG_STENCIL_STROKES I + public abstract fun nnvgCreate (I)J + public abstract fun nnvgDelete (J)V + public abstract fun nnvglCreateImageFromHandle (JIIII)I + public abstract fun nnvglImageHandle (JI)I + public abstract fun nnvgluBindFramebuffer (JJ)V + public abstract fun nnvgluCreateFramebuffer (JIII)J + public abstract fun nnvgluDeleteFramebuffer (JJ)V + public abstract fun nvgCreate (I)J + public abstract fun nvgDelete (J)V + public abstract fun nvglCreateImageFromHandle (JIIII)I + public abstract fun nvglImageHandle (JI)I + public abstract fun nvgluBindFramebuffer (JLorg/lwjgl/nanovg/NVGLUFramebuffer;)V + public abstract fun nvgluCreateFramebuffer (JIII)Lorg/lwjgl/nanovg/NVGLUFramebuffer; + public abstract fun nvgluDeleteFramebuffer (JLorg/lwjgl/nanovg/NVGLUFramebuffer;)V + public abstract fun triggerStaticInitialization ()V +} + public abstract interface class cc/polyfrost/oneconfig/platform/Platform { public static fun getGLPlatform ()Lcc/polyfrost/oneconfig/platform/GLPlatform; public static fun getGuiPlatform ()Lcc/polyfrost/oneconfig/platform/GuiPlatform; public static fun getI18nPlatform ()Lcc/polyfrost/oneconfig/platform/I18nPlatform; public static fun getInstance ()Lcc/polyfrost/oneconfig/platform/Platform; + public abstract fun getLoader ()Lcc/polyfrost/oneconfig/platform/Platform$Loader; public static fun getLoaderPlatform ()Lcc/polyfrost/oneconfig/platform/LoaderPlatform; public abstract fun getMinecraftVersion ()I public static fun getMousePlatform ()Lcc/polyfrost/oneconfig/platform/MousePlatform; + public static fun getNanoVGPlatform ()Lcc/polyfrost/oneconfig/platform/NanoVGPlatform; public static fun getServerPlatform ()Lcc/polyfrost/oneconfig/platform/ServerPlatform; public abstract fun isCallingFromMinecraftThread ()Z } +public final class cc/polyfrost/oneconfig/platform/Platform$Loader : java/lang/Enum { + public static final field FABRIC Lcc/polyfrost/oneconfig/platform/Platform$Loader; + public static final field FORGE Lcc/polyfrost/oneconfig/platform/Platform$Loader; + public static fun valueOf (Ljava/lang/String;)Lcc/polyfrost/oneconfig/platform/Platform$Loader; + public static fun values ()[Lcc/polyfrost/oneconfig/platform/Platform$Loader; +} + public class cc/polyfrost/oneconfig/platform/Platform$PlatformHolder { } @@ -1053,7 +1118,6 @@ public final class cc/polyfrost/oneconfig/renderer/RenderManager { public static fun drawInfo (JLcc/polyfrost/oneconfig/config/data/InfoType;FFF)V public static fun drawLine (JFFFFFI)V public static fun drawRect (JFFFFI)V - public static fun drawRectangle (JFFFFI)V public static fun drawRoundImage (JLcc/polyfrost/oneconfig/internal/assets/Images;FFFFF)V public static fun drawRoundImage (JLjava/lang/String;FFFFF)V public static fun drawRoundedRect (JFFFFIF)V @@ -1129,7 +1193,7 @@ public class cc/polyfrost/oneconfig/renderer/scissor/Scissor { public field y F public fun <init> (FFFF)V public fun <init> (Lcc/polyfrost/oneconfig/renderer/scissor/Scissor;)V - public fun isInScissor (II)Z + public fun isInScissor (FF)Z } public class cc/polyfrost/oneconfig/renderer/scissor/ScissorManager { @@ -1152,16 +1216,16 @@ public final class cc/polyfrost/oneconfig/utils/IOUtils { public final class cc/polyfrost/oneconfig/utils/InputUtils { public fun <init> ()V public static fun blockAllInput ()Lcc/polyfrost/oneconfig/renderer/scissor/Scissor; - public static fun blockInputArea (IIII)Lcc/polyfrost/oneconfig/renderer/scissor/Scissor; - public static fun isAreaClicked (IIII)Z - public static fun isAreaClicked (IIIIZ)Z - public static fun isAreaHovered (IIII)Z - public static fun isAreaHovered (IIIIZ)Z + public static fun blockInputArea (FFFF)Lcc/polyfrost/oneconfig/renderer/scissor/Scissor; + public static fun isAreaClicked (FFFF)Z + public static fun isAreaClicked (FFFFZ)Z + public static fun isAreaHovered (FFFF)Z + public static fun isAreaHovered (FFFFZ)Z public static fun isBlockingInput ()Z public static fun isClicked ()Z public static fun isClicked (Z)Z - public static fun mouseX ()I - public static fun mouseY ()I + public static fun mouseX ()F + public static fun mouseY ()F public static fun stopBlock (Lcc/polyfrost/oneconfig/renderer/scissor/Scissor;)V public static fun stopBlockingInput ()V } @@ -1263,6 +1327,7 @@ public abstract class cc/polyfrost/oneconfig/utils/commands/PlatformCommandManag public abstract interface annotation class cc/polyfrost/oneconfig/utils/commands/annotations/Command : java/lang/annotation/Annotation { public abstract fun aliases ()[Ljava/lang/String; + public abstract fun color ()Lcc/polyfrost/oneconfig/libs/universal/ChatColor; public abstract fun description ()Ljava/lang/String; public abstract fun helpCommand ()Z public abstract fun value ()Ljava/lang/String; @@ -1282,6 +1347,7 @@ public abstract interface annotation class cc/polyfrost/oneconfig/utils/commands public abstract interface annotation class cc/polyfrost/oneconfig/utils/commands/annotations/SubCommand : java/lang/annotation/Annotation { public abstract fun aliases ()[Ljava/lang/String; + public abstract fun color ()Lcc/polyfrost/oneconfig/libs/universal/ChatColor; public abstract fun description ()Ljava/lang/String; public abstract fun value ()Ljava/lang/String; } @@ -1467,19 +1533,16 @@ public final class cc/polyfrost/oneconfig/utils/gui/GuiUtils { public abstract class cc/polyfrost/oneconfig/utils/gui/OneUIScreen : cc/polyfrost/oneconfig/libs/universal/UScreen, cc/polyfrost/oneconfig/gui/GuiPause { public fun <init> ()V public fun <init> (Z)V + public fun doesGuiPauseGame ()Z public abstract fun draw (JF)V - public fun getMouseX ()I - public fun getMouseY ()I + protected fun getMouseX ()F + protected fun getMouseY ()F public fun ignoreMinecraftScale ()Z - public fun initScreen (II)V public fun isBlockingClicks ()Z - public fun isClicked ()Z - public fun isClicked (Z)Z - public fun isMouseDown ()Z - public fun onDrawScreen (Lcc/polyfrost/oneconfig/libs/universal/UMatrixStack;IIF)V - public fun onMouseClicked (DDI)V - public abstract fun onScreenClose ()V - public abstract fun onScreenOpen ()V + protected fun isClicked ()Z + protected fun isClicked (Z)Z + protected fun isMouseDown ()Z + public final fun onDrawScreen (Lcc/polyfrost/oneconfig/libs/universal/UMatrixStack;IIF)V public fun shouldBlockClicks (Z)V } diff --git a/build.gradle.kts b/build.gradle.kts index 056d1d1..89d44d9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -114,7 +114,7 @@ dependencies { shade("org.spongepowered:mixin:0.7.11-SNAPSHOT") { isTransitive = false } - shade("cc.polyfrost:lwjgl-1.8.9-forge:1.0.0-alpha5") + shade("cc.polyfrost:lwjgl-1.8.9-forge:1.0.0-alpha8") shadeNoPom(prebundle(shadeRelocated)) configurations.named(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME) { extendsFrom(shadeNoPom) } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 92f06b5..2ec77e5 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/lwjgl/1.16.2-fabric/api/1.16.2-fabric.api b/lwjgl/1.16.2-fabric/api/1.16.2-fabric.api new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/lwjgl/1.16.2-fabric/api/1.16.2-fabric.api diff --git a/lwjgl/build.gradle.kts b/lwjgl/build.gradle.kts index fcc5511..925fb4d 100644 --- a/lwjgl/build.gradle.kts +++ b/lwjgl/build.gradle.kts @@ -16,7 +16,7 @@ val mod_name: String by project val mod_version: String by project val mod_id: String by project -version = "1.0.0-alpha5" +version = "1.0.0-alpha8" repositories { maven("https://repo.polyfrost.cc/releases") @@ -50,19 +50,27 @@ dependencies { shadeRuntimeOnly("org.lwjgl:lwjgl:$lwjgl:natives-macos") shadeRuntimeOnly("org.lwjgl:lwjgl-stb:$lwjgl:natives-macos") shadeRuntimeOnly("org.lwjgl:lwjgl-tinyfd:$lwjgl:natives-macos") + shadeRuntimeOnly("org.lwjgl:lwjgl:$lwjgl:natives-macos-arm64") + shadeRuntimeOnly("org.lwjgl:lwjgl-stb:$lwjgl:natives-macos-arm64") + shadeRuntimeOnly("org.lwjgl:lwjgl-tinyfd:$lwjgl:natives-macos-arm64") } shadeCompileOnly("org.lwjgl:lwjgl-nanovg:$lwjgl") { - isTransitive = platform.isLegacyForge + isTransitive = false } shadeRuntimeOnly("org.lwjgl:lwjgl-nanovg:$lwjgl:natives-windows") { - isTransitive = platform.isLegacyForge + isTransitive = false } shadeRuntimeOnly("org.lwjgl:lwjgl-nanovg:$lwjgl:natives-linux") { - isTransitive = platform.isLegacyForge + isTransitive = false } shadeRuntimeOnly("org.lwjgl:lwjgl-nanovg:$lwjgl:natives-macos") { - isTransitive = platform.isLegacyForge + isTransitive = false + } + // force 3.3.1 for this, because + // if the user is actually running M1+, LWJGL must be 3.3.0+ + shadeRuntimeOnly("org.lwjgl:lwjgl-nanovg:3.3.1:natives-macos-arm64") { + isTransitive = false } } @@ -70,10 +78,10 @@ tasks { named<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>("shadowJar") { archiveClassifier.set("") configurations = listOf(shadeCompileOnly, shadeRuntimeOnly) - exclude("META-INF/versions/**") - exclude("**/module-info.class") - exclude("**/package-info.class") if (platform.isLegacyForge) { + exclude("META-INF/versions/**") + exclude("**/module-info.class") + exclude("**/package-info.class") relocate("org.lwjgl", "org.lwjgl3") { include("org.lwjgl.PointerBuffer") include("org.lwjgl.BufferUtils") diff --git a/lwjgl/root.gradle.kts b/lwjgl/root.gradle.kts index d2dc0c7..2c4ada8 100644 --- a/lwjgl/root.gradle.kts +++ b/lwjgl/root.gradle.kts @@ -10,7 +10,9 @@ plugins { preprocess { "1.8.9-forge"(10809, "srg") { "1.12.2-forge"(11202, "srg") { - "1.16.2-forge"(11602, "srg") + "1.16.2-forge"(11602, "srg") { + "1.16.2-fabric"(11602, "yarn") + } } } }
\ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 1ac4f26..e5fe21b 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -40,7 +40,8 @@ project(":platform").apply { listOf( "1.8.9-forge", "1.12.2-forge", - "1.16.2-forge" + "1.16.2-forge", + "1.16.2-fabric" ).forEach { version -> include(":platform:$version") include(":lwjgl:$version") diff --git a/src/main/java/cc/polyfrost/oneconfig/config/Config.java b/src/main/java/cc/polyfrost/oneconfig/config/Config.java index 8a5608e..1b5c5e6 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/Config.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/Config.java @@ -24,7 +24,10 @@ import cc.polyfrost.oneconfig.utils.JsonUtils; import cc.polyfrost.oneconfig.utils.gui.GuiUtils; import com.google.gson.*; -import java.io.*; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.nio.charset.StandardCharsets; diff --git a/src/main/java/cc/polyfrost/oneconfig/config/core/OneKeyBind.java b/src/main/java/cc/polyfrost/oneconfig/config/core/OneKeyBind.java index 791bc4a..7e844f0 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/core/OneKeyBind.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/core/OneKeyBind.java @@ -14,7 +14,6 @@ public class OneKeyBind { keyBinds.add(key); } } - public boolean isActive() { if (keyBinds.size() == 0) return false; for (int keyBind : keyBinds) { diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/GuiPause.java b/src/main/java/cc/polyfrost/oneconfig/gui/GuiPause.java index 44b2b5c..344f7bb 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/GuiPause.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/GuiPause.java @@ -5,5 +5,6 @@ package cc.polyfrost.oneconfig.gui; * Minecraft itself. */ public interface GuiPause { + @SuppressWarnings("unused") boolean doesGuiPauseGame(); } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java deleted file mode 100644 index fc90c01..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java +++ /dev/null @@ -1,292 +0,0 @@ -package cc.polyfrost.oneconfig.gui; - -import cc.polyfrost.oneconfig.hud.Hud; -import cc.polyfrost.oneconfig.internal.config.core.ConfigCore; -import cc.polyfrost.oneconfig.internal.hud.HudCore; -import cc.polyfrost.oneconfig.libs.universal.UKeyboard; -import cc.polyfrost.oneconfig.libs.universal.UMatrixStack; -import cc.polyfrost.oneconfig.libs.universal.UResolution; -import cc.polyfrost.oneconfig.libs.universal.UScreen; -import cc.polyfrost.oneconfig.renderer.RenderManager; -import cc.polyfrost.oneconfig.utils.gui.GuiUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.awt.*; -import java.util.ArrayList; - -public class HudGui extends UScreen implements GuiPause { - private Hud editingHud; - private boolean isDragging; - private boolean isScaling; - private final boolean openOneConfigOnClose; - private int xOffset; - private int yOffset; - - public HudGui(boolean openOneConfigOnClose) { - super(); - this.openOneConfigOnClose = openOneConfigOnClose; - } - - @Override - public void initScreen(int width, int height) { - HudCore.editing = true; - UKeyboard.allowRepeatEvents(true); - super.initScreen(width, height); - } - - @Override - public void onDrawScreen(@NotNull UMatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { - RenderManager.drawGlRect(0, 0, UResolution.getScaledWidth(), UResolution.getScaledHeight(), new Color(80, 80, 80, 50).getRGB()); - - if (isDragging) { - setPosition(mouseX - xOffset, mouseY - yOffset, true); - } - - for (Hud hud : HudCore.huds) { - if (hud.isEnabled()) processHud(matrixStack, hud, mouseX); - } - } - - private void processHud(UMatrixStack matrixStack, Hud hud, int mouseX) { - if (hud == editingHud && isScaling) { - float xFloat = hud.getXScaled(UResolution.getScaledWidth()); - float yFloat = hud.getYScaled(UResolution.getScaledHeight()); - float pos = getXSnapping(mouseX, true); - float newWidth = pos - xFloat; - float newScale = newWidth / ((hud.getWidth(hud.scale) + hud.paddingX * hud.scale) / hud.scale); - if (newScale > 20) - newScale = 20; - else if (newScale < 0.3) - newScale = 0.3f; - hud.scale = newScale; - - if (xFloat / UResolution.getScaledWidth() > 0.5) - editingHud.xUnscaled = (xFloat + (hud.getWidth(hud.scale) + hud.paddingX * hud.scale)) / (double) UResolution.getScaledWidth(); - if (yFloat / UResolution.getScaledHeight() > 0.5) - editingHud.yUnscaled = (yFloat + (hud.getHeight(hud.scale) + hud.paddingY * hud.scale)) / (double) UResolution.getScaledHeight(); - } - - int width = (int) (hud.getExampleWidth(hud.scale) + hud.paddingX * hud.scale); - int height = (int) (hud.getExampleHeight(hud.scale) + hud.paddingY * hud.scale); - int x = (int) hud.getXScaled(UResolution.getScaledWidth()); - int y = (int) hud.getYScaled(UResolution.getScaledHeight()); - - hud.drawExampleAll(matrixStack, x, y, hud.scale, true); - int color = new Color(215, 224, 235).getRGB(); - if (editingHud == hud) { - color = new Color(43, 159, 235).getRGB(); - if (isDragging) - RenderManager.drawGlRect(x, y, width, height, new Color(108, 176, 255, 60).getRGB()); - } - int finalColor = color; - RenderManager.setupAndDraw(true, (vg) -> { - RenderManager.drawLine(vg, x - 2 / 4f, y, x + width + 2 / 4f, y, 1, finalColor); - RenderManager.drawLine(vg, x, y, x, y + height, 1, finalColor); - RenderManager.drawLine(vg, x + width, y, x + width, y + height, 1, finalColor); - RenderManager.drawLine(vg, x - 2 / 4f, y + height, x + width + 2 / 4f, y + height, 1, finalColor); - }); - - if (hud == editingHud && !isDragging) { - RenderManager.setupAndDraw(true, (vg) -> RenderManager.drawCircle(vg, x + width, y + height, 3, new Color(43, 159, 235).getRGB())); - } - } - - private void setPosition(float newX, float newY, boolean snap) { - float width = editingHud.getWidth(editingHud.scale) + editingHud.paddingX * editingHud.scale; - float height = editingHud.getHeight(editingHud.scale) + editingHud.paddingY * editingHud.scale; - - if (newX < 0) - newX = 0; - else if (newX + width > UResolution.getScaledWidth()) - newX = UResolution.getScaledWidth() - width; - if (newY < 0) - newY = 0; - else if (newY + height > UResolution.getScaledHeight()) - newY = UResolution.getScaledHeight() - height; - - if (snap) { - float snapX = getXSnapping(newX, false); - float snapY = getYSnapping(newY); - if (snapX != newX || snapY != newY) { - newX = snapX; - newY = snapY; - } - } - - if (newX / UResolution.getScaledWidth() <= 0.5) - editingHud.xUnscaled = newX / (double) UResolution.getScaledWidth(); - else - editingHud.xUnscaled = (newX + width) / (double) UResolution.getScaledWidth(); - if (newY / UResolution.getScaledHeight() <= 0.5) - editingHud.yUnscaled = newY / (double) UResolution.getScaledHeight(); - else - editingHud.yUnscaled = (newY + height) / (double) UResolution.getScaledHeight(); - } - - private float getXSnapping(float pos, boolean rightOnly) { - float width = editingHud.getWidth(editingHud.scale) + editingHud.paddingX * editingHud.scale; - ArrayList<Float> verticalLines = new ArrayList<>(); - for (Hud hud : HudCore.huds) { - if (!hud.isEnabled()) continue; - verticalLines.addAll(getXSnappingHud(hud)); - } - getSpaceSnapping(verticalLines); - verticalLines.add(UResolution.getScaledWidth() / 2f); - float smallestDiff = -1; - float smallestLine = 0; - float smallestOffset = 0; - for (float lineX : verticalLines) { - for (float offset = 0; offset <= (rightOnly ? 0 : width); offset += width / 2f) { - if (Math.abs(lineX - pos - offset) < 5 && (Math.abs(lineX - pos - offset) < smallestDiff || smallestDiff == -1)) { - smallestDiff = Math.abs(lineX - pos); - smallestLine = lineX; - smallestOffset = offset; - } - } - } - if (smallestDiff != -1) { - float finalSmallestLine = smallestLine; - RenderManager.setupAndDraw(true, (vg) -> RenderManager.drawLine(vg, finalSmallestLine, 0, finalSmallestLine, UResolution.getScaledHeight(), 1, new Color(255, 255, 255).getRGB())); - return smallestLine - smallestOffset; - } - return pos; - } - - private ArrayList<Float> getXSnappingHud(Hud hud) { - ArrayList<Float> verticalLines = new ArrayList<>(); - if (hud == editingHud) return verticalLines; - int hudWidth = (int) (hud.getWidth(hud.scale) + hud.paddingX * hud.scale); - int hudX = (int) hud.getXScaled(UResolution.getScaledWidth()); - verticalLines.add((float) hudX); - verticalLines.add((float) (hudX + hudWidth)); - return verticalLines; - } - - private float getYSnapping(float pos) { - float height = editingHud.getHeight(editingHud.scale) + editingHud.paddingY * editingHud.scale; - ArrayList<Float> horizontalLines = new ArrayList<>(); - for (Hud hud : HudCore.huds) { - if (!hud.isEnabled()) continue; - horizontalLines.addAll(getYSnappingHud(hud)); - } - getSpaceSnapping(horizontalLines); - horizontalLines.add(UResolution.getScaledHeight() / 2f); - float smallestDiff = -1; - float smallestLine = 0; - float smallestOffset = 0; - for (float lineY : horizontalLines) { - for (float offset = 0; offset <= height; offset += height / 2f) { - if (Math.abs(lineY - pos - offset) < 5 && (Math.abs(lineY - pos - offset) < smallestDiff || smallestDiff == -1)) { - smallestDiff = Math.abs(lineY - pos); - smallestLine = lineY; - smallestOffset = offset; - } - } - } - if (smallestDiff != -1) { - float finalSmallestLine = smallestLine; - RenderManager.setupAndDraw(true, (vg) -> RenderManager.drawLine(vg, 0, finalSmallestLine, UResolution.getScaledWidth(), finalSmallestLine, 1, new Color(255, 255, 255).getRGB())); - return smallestLine - smallestOffset; - } - return pos; - } - - private ArrayList<Float> getYSnappingHud(Hud hud) { - ArrayList<Float> horizontalLines = new ArrayList<>(); - if (hud == editingHud) return horizontalLines; - int hudHeight = (int) (hud.getHeight(hud.scale) + hud.paddingY * hud.scale); - int hudY = (int) hud.getYScaled(UResolution.getScaledHeight()); - horizontalLines.add((float) hudY); - horizontalLines.add((float) (hudY + hudHeight)); - return horizontalLines; - } - - private void getSpaceSnapping(ArrayList<Float> lines) { - ArrayList<Float> newLines = new ArrayList<>(); - for (int i = 0; i < lines.size(); i++) { - for (int l = i + 1; l < lines.size(); l++) { - newLines.add(Math.max(lines.get(i), lines.get(l)) + Math.abs(lines.get(i) - lines.get(l))); - newLines.add(Math.min(lines.get(i), lines.get(l)) - Math.abs(lines.get(i) - lines.get(l))); - } - } - lines.addAll(newLines); - } - - @Override - public void onMouseClicked(double mouseX, double mouseY, int mouseButton) { - super.onMouseClicked(mouseX, mouseY, mouseButton); - if (mouseButton == 0) { - if (editingHud != null) { - int width = (int) (editingHud.getWidth(editingHud.scale) + editingHud.paddingX * editingHud.scale); - int height = (int) (editingHud.getHeight(editingHud.scale) + editingHud.paddingY * editingHud.scale); - float x = editingHud.getXScaled(UResolution.getScaledWidth()); - float y = editingHud.getYScaled(UResolution.getScaledHeight()); - if (mouseX >= x + width - 3 && mouseX <= x + width + 3 && mouseY >= y + height - 3 && mouseY <= y + height + 3) { - isScaling = true; - return; - } - } - editingHud = null; - for (Hud hud : HudCore.huds) { - if (!hud.isEnabled()) continue; - if (mouseClickedHud(hud, (int) mouseX, (int) mouseY)) - break; - } - } - } - - private boolean mouseClickedHud(Hud hud, int mouseX, int mouseY) { - int width = (int) (hud.getWidth(hud.scale) + hud.paddingX * hud.scale); - int height = (int) (hud.getHeight(hud.scale) + hud.paddingY * hud.scale); - float x = hud.getXScaled(UResolution.getScaledWidth()); - float y = hud.getYScaled(UResolution.getScaledHeight()); - if (mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + height) { - editingHud = hud; - xOffset = (int) (mouseX - x); - yOffset = (int) (mouseY - y); - isDragging = true; - return true; - } - return false; - } - - @Override - public void onMouseReleased(double mouseX, double mouseY, int state) { - super.onMouseReleased(mouseX, mouseY, state); - isDragging = false; - isScaling = false; - } - - @Override - public void onKeyPressed(int keyCode, char typedChar, @Nullable UKeyboard.Modifiers modifiers) { - if (editingHud != null) { - float x = editingHud.getXScaled(UResolution.getScaledWidth()); - float y = editingHud.getYScaled(UResolution.getScaledHeight()); - if (keyCode == UKeyboard.KEY_UP) { - setPosition(x, y - 1, false); - } else if (keyCode == UKeyboard.KEY_DOWN) { - setPosition(x, y + 1, false); - } else if (keyCode == UKeyboard.KEY_LEFT) { - setPosition(x - 1, y, false); - } else if (keyCode == UKeyboard.KEY_RIGHT) { - setPosition(x + 1, y, false); - } - } - super.onKeyPressed(keyCode, typedChar, modifiers); - } - - @Override - public void onScreenClose() { - super.onScreenClose(); - HudCore.editing = false; - UKeyboard.allowRepeatEvents(false); - ConfigCore.saveAll(); - if(openOneConfigOnClose) GuiUtils.displayScreen(OneConfigGui.create()); - } - - @Override - public boolean doesGuiPauseGame() { - return false; - } -}
\ No newline at end of file diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java index 41d0b4f..1d40d0a 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java @@ -85,13 +85,13 @@ public class OneConfigGui extends UScreen implements GuiPause { int x = (int) ((UResolution.getWindowWidth() - 1280 * scale) / 2f / scale); int y = (int) ((UResolution.getWindowHeight() - 800 * scale) / 2f / scale); RenderManager.scale(vg, scale, scale); - if (Colors.ROUNDED_CORNERS) { - RenderManager.drawDropShadow(vg, x, y, 1280, 800, 32, 0, 20); - RenderManager.drawRoundedRect(vg, x + 224, y, 1056, 800, Colors.GRAY_800, Colors.CORNER_RADIUS_WIN); - RenderManager.drawRoundedRect(vg, x, y, 244, 800, Colors.GRAY_800_95, Colors.CORNER_RADIUS_WIN); - RenderManager.drawRect(vg, x + 224, y, 20, 800, Colors.GRAY_800); - RenderManager.drawHollowRoundRect(vg, x - 1, y - 1, 1282, 802, 0x4DCCCCCC, 20, scale < 1 ? 1 / scale : 1); - } + + RenderManager.drawDropShadow(vg, x, y, 1280, 800, 32, 0, 20); + RenderManager.drawRoundedRect(vg, x + 224, y, 1056, 800, Colors.GRAY_800, 20f); + RenderManager.drawRoundedRect(vg, x, y, 244, 800, Colors.GRAY_800_95, 20f); + RenderManager.drawRect(vg, x + 224, y, 20, 800, Colors.GRAY_800); + RenderManager.drawHollowRoundRect(vg, x - 1, y - 1, 1282, 802, 0x4DCCCCCC, 20, scale < 1 ? 1 / scale : 1); + RenderManager.drawLine(vg, x + 224, y + 72, x + 1280, y + 72, 1, Colors.GRAY_700); RenderManager.drawLine(vg, x + 224, y, x + 222, y + 800, 1, Colors.GRAY_700); diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java b/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java index d1b5532..ebfc8cb 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java @@ -10,6 +10,7 @@ import cc.polyfrost.oneconfig.gui.pages.ModsPage; import cc.polyfrost.oneconfig.internal.assets.Colors; import cc.polyfrost.oneconfig.internal.assets.SVGs; import cc.polyfrost.oneconfig.internal.config.Preferences; +import cc.polyfrost.oneconfig.internal.gui.HudGui; import cc.polyfrost.oneconfig.renderer.RenderManager; import cc.polyfrost.oneconfig.renderer.font.Fonts; import cc.polyfrost.oneconfig.utils.color.ColorPalette; @@ -43,7 +44,7 @@ public class SideBar { buttons.get(0).setClickAction(new CreditsPage()); buttons.get(2).setClickAction(new ModsPage()); buttons.get(8).setClickAction(new ModConfigPage(Preferences.getInstance().mod.defaultPage, true)); - HUDButton.setClickAction(() -> GuiUtils.displayScreen(new HudGui(true))); + HUDButton.setClickAction(() -> GuiUtils.displayScreen(new HudGui())); CloseButton.setClickAction(GuiUtils::closeScreen); for (BasicButton button : buttons) { if (button.hasClickAction()) continue; diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java index 7869114..1691eca 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java @@ -16,9 +16,9 @@ public class BasicButton extends BasicElement { protected SVGs icon1, icon2; private final int alignment; private final float fontSize, cornerRadius; - private final int xSpacing, xPadding; + private final float xSpacing, xPadding; private final int iconSize; - public int x, y; + public float x, y; public static final int ALIGNMENT_LEFT = 0; public static final int ALIGNMENT_CENTER = 2; public static final int ALIGNMENT_JUSTIFIED = 3; @@ -57,7 +57,7 @@ public class BasicButton extends BasicElement { } @Override - public void draw(long vg, int x, int y) { + public void draw(long vg, float x, float y) { this.x = x; this.y = y; this.update(x, y); diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java index 6f203c4..ef98120 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java @@ -72,13 +72,13 @@ public class BasicElement { /** * Draw script for the element. - * <br> <b>Make sure to call {@link #update(int x, int y)} to update the elements states!</b> + * <br> <b>Make sure to call {@link #update(float, float)} to update the elements states!</b> * * @param vg NanoVG context (see {@link RenderManager}) * @param x x position of the element * @param y y position of the element */ - public void draw(long vg, int x, int y) { + public void draw(long vg, float x, float y) { this.update(x, y); RenderManager.drawRoundedRect(vg, x, y, width, height, currentColor, radius); } @@ -86,7 +86,7 @@ public class BasicElement { /** * Update this element's clicked, hovered, toggled, and pressed states, invoke any necessary methods, and update the color animation. */ - public void update(int x, int y) { + public void update(float x, float y) { if (disabled) { hovered = false; pressed = false; diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java index 1fed640..568567d 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java @@ -45,21 +45,21 @@ public class ColorSelector { private final ColorSlider topSlider = new ColorSlider(384, 0, 360, 127); private final ColorSlider bottomSlider = new ColorSlider(384, 0, 255, 100); private final Slider speedSlider = new Slider(296, 1, 32, 0); - private int x; - private int y; + private float x; + private float y; private Animation barMoveAnimation = new DummyAnimation(18); private Animation moveAnimation = new DummyAnimation(1); - private int mouseX, mouseY; + private float mouseX, mouseY; private int mode = 0; private boolean dragging, mouseWasDown; private final boolean hasAlpha; private Scissor inputScissor = null; - public ColorSelector(OneColor color, int mouseX, int mouseY) { + public ColorSelector(OneColor color, float mouseX, float mouseY) { this(color, mouseX, mouseY, true); } - public ColorSelector(OneColor color, int mouseX, int mouseY, boolean hasAlpha) { + public ColorSelector(OneColor color, float mouseX, float mouseY, boolean hasAlpha) { this.color = color; this.hasAlpha = hasAlpha; buttons.add(new BasicButton(124, 28, "HSB Box", BasicButton.ALIGNMENT_CENTER, ColorPalette.TERTIARY)); @@ -82,12 +82,12 @@ public class ColorSelector { this.y = Math.max(0, mouseY - 776); if (color.getDataBit() != -1) mode = 2; if (mode == 0 || mode == 2) { - this.mouseX = (int) (color.getSaturation() / 100f * 384 + x + 16); - this.mouseY = (int) (Math.abs(color.getBrightness() / 100f - 1f) * 288 + y + 120); + this.mouseX = (color.getSaturation() / 100f * 384 + x + 16); + this.mouseY = (Math.abs(color.getBrightness() / 100f - 1f) * 288 + y + 120); } else { topSlider.setValue(color.getBrightness() / 100f * 360f); - this.mouseX = (int) (Math.sin(Math.toRadians(-color.getHue()) + 1.5708) * (saturationInput.getCurrentValue() / 100 * 144) + x + 208); - this.mouseY = (int) (Math.cos(Math.toRadians(-color.getHue()) + 1.5708) * (saturationInput.getCurrentValue() / 100 * 144) + y + 264); + this.mouseX = (float) (Math.sin(Math.toRadians(-color.getHue()) + 1.5708) * (saturationInput.getCurrentValue() / 100 * 144) + x + 208); + this.mouseY = (float) (Math.cos(Math.toRadians(-color.getHue()) + 1.5708) * (saturationInput.getCurrentValue() / 100 * 144) + y + 264); } //for(OneColor color1 : OneConfigConfig.recentColors) { // recentColors.add(new ColorBox(color1)); @@ -178,7 +178,7 @@ public class ColorSelector { setColorFromXY(); if (mode != 2) color.setChromaSpeed(-1); - drawColorSelector(vg, mode, (int) (x * percentMoveMain), y); + drawColorSelector(vg, mode, (x * percentMoveMain), y); if (dragging && InputUtils.isClicked(true)) { dragging = false; } @@ -209,7 +209,7 @@ public class ColorSelector { } } - private void drawColorSelector(long vg, int mode, int x, int y) { + private void drawColorSelector(long vg, int mode, float x, float y) { switch (mode) { default: case 0: @@ -242,8 +242,8 @@ public class ColorSelector { private void doDrag() { if (InputUtils.isAreaHovered(x, y, 368, 64) && Platform.getMousePlatform().isButtonDown(0) && !dragging) { - int dx = (int) (Platform.getMousePlatform().getMouseDX() / (OneConfigGui.INSTANCE == null ? 1 : OneConfigGui.INSTANCE.getScaleFactor())); - int dy = (int) (Platform.getMousePlatform().getMouseDY() / (OneConfigGui.INSTANCE == null ? 1 : OneConfigGui.INSTANCE.getScaleFactor())); + float dx = (float) (Platform.getMousePlatform().getMouseDX() / (OneConfigGui.INSTANCE == null ? 1 : OneConfigGui.INSTANCE.getScaleFactor())); + float dy = (float) (Platform.getMousePlatform().getMouseDY() / (OneConfigGui.INSTANCE == null ? 1 : OneConfigGui.INSTANCE.getScaleFactor())); x += dx; mouseX += dx; y -= dy; @@ -279,8 +279,8 @@ public class ColorSelector { } break; case 1: - int circleCenterX = x + 208; - int circleCenterY = y + 264; + float circleCenterX = x + 208; + float circleCenterY = y + 264; double squareDist = Math.pow((circleCenterX - InputUtils.mouseX()), 2) + Math.pow((circleCenterY - InputUtils.mouseY()), 2); hovered = squareDist < 144 * 144 && Platform.getMousePlatform().isButtonDown(0); isMouseDown = Platform.getMousePlatform().isButtonDown(0); @@ -293,8 +293,8 @@ public class ColorSelector { if (angle < 0) angle += 360; if ((squareDist / (144 * 144) > 1f)) { saturation = 100; - mouseX = (int) (Math.sin(Math.toRadians(-angle) + 1.5708) * 144 + x + 208); - mouseY = (int) (Math.cos(Math.toRadians(-angle) + 1.5708) * 144 + y + 264); + mouseX = (float) (Math.sin(Math.toRadians(-angle) + 1.5708) * 144 + x + 208); + mouseY = (float) (Math.cos(Math.toRadians(-angle) + 1.5708) * 144 + y + 264); } else { saturation = (int) (squareDist / (144 * 144) * 100); mouseX = InputUtils.mouseX(); @@ -309,14 +309,14 @@ public class ColorSelector { private void setXYFromColor() { bottomSlider.setValue(color.getAlpha()); if (mode == 1) { - mouseX = (int) (Math.sin(Math.toRadians(-color.getHue()) + 1.5708) * (saturationInput.getCurrentValue() / 100 * 144) + x + 208); - mouseY = (int) (Math.cos(Math.toRadians(-color.getHue()) + 1.5708) * (saturationInput.getCurrentValue() / 100 * 144) + y + 264); + mouseX = (float) (Math.sin(Math.toRadians(-color.getHue()) + 1.5708) * (saturationInput.getCurrentValue() / 100 * 144) + x + 208); + mouseY = (float) (Math.cos(Math.toRadians(-color.getHue()) + 1.5708) * (saturationInput.getCurrentValue() / 100 * 144) + y + 264); topSlider.setValue(color.getBrightness() / 100f * 360f); } if (mode == 0 || mode == 2) { topSlider.setValue(color.getHue()); - mouseX = (int) (saturationInput.getCurrentValue() / 100f * 384 + x + 16); - mouseY = (int) (Math.abs(brightnessInput.getCurrentValue() / 100f - 1f) * 288 + y + 120); + mouseX = (saturationInput.getCurrentValue() / 100f * 384 + x + 16); + mouseY = (Math.abs(brightnessInput.getCurrentValue() / 100f - 1f) * 288 + y + 120); } } @@ -429,7 +429,7 @@ public class ColorSelector { } @Override - public void draw(long vg, int x, int y) { + public void draw(long vg, float x, float y) { if (!disabled) update(x, y); else RenderManager.setAlpha(vg, 0.5f); super.dragPointerSize = 15f; @@ -469,7 +469,7 @@ public class ColorSelector { } @Override - public void draw(long vg, int x, int y) { + public void draw(long vg, float x, float y) { RenderManager.drawRoundedRect(vg, x, y, 32, 32, toggled ? Colors.PRIMARY_600 : Colors.GRAY_300, 12f); RenderManager.drawRoundedRect(vg, x + 2, y + 2, 28, 28, Colors.GRAY_800, 10f); RenderManager.drawRoundedRect(vg, x + 4, y + 4, 24, 24, color.getRGB(), 8f); diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java index eebdba1..ffac8e3 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java @@ -42,7 +42,7 @@ public class ModCard extends BasicElement { } @Override - public void draw(long vg, int x, int y) { + public void draw(long vg, float x, float y) { super.update(x, y); String cleanName = modData.name.replaceAll("§.", ""); Scissor scissor = ScissorManager.scissor(vg, x, y, width, height); diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/Slider.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/Slider.java index dda5621..a22064c 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/Slider.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/Slider.java @@ -21,7 +21,7 @@ public class Slider extends BasicElement { } @Override - public void draw(long vg, int x, int y) { + public void draw(long vg, float x, float y) { if(!disabled) update(x, y); else RenderManager.setAlpha(vg, 0.5f); RenderManager.drawRoundedRect(vg, x, y + 2, width, height - 4, Colors.GRAY_300, 3f); @@ -32,18 +32,18 @@ public class Slider extends BasicElement { } - public void update(int x, int y) { + public void update(float x, float y) { super.update(x, y); boolean isMouseDown = Platform.getMousePlatform().isButtonDown(0); boolean hovered = InputUtils.isAreaHovered(x - 6, y - 3, width + 12, height + 6); if (hovered && isMouseDown && !mouseWasDown) dragging = true; mouseWasDown = isMouseDown; if (dragging) { - value = ((float) InputUtils.mouseX() - x) / width; + value = (InputUtils.mouseX() - x) / width; } if (dragging && InputUtils.isClicked(true)) { dragging = false; - value = ((float) InputUtils.mouseX() - x) / width; + value = (InputUtils.mouseX() - x) / width; } if (value < 0) value = 0; diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/NumberInputField.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/NumberInputField.java index d7e29f5..5162ecb 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/NumberInputField.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/NumberInputField.java @@ -27,7 +27,7 @@ public class NumberInputField extends TextInputField { } @Override - public void draw(long vg, int x, int y) { + public void draw(long vg, float x, float y) { super.errored = false; if(disabled) RenderManager.setAlpha(vg, 0.5f); RenderManager.drawRoundedRect(vg, x + width + 4, y, 12, 28, Colors.GRAY_500, 6f); diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java index 054915c..3c2cb1c 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java @@ -26,7 +26,7 @@ public class TextInputField extends BasicElement { protected boolean password; protected int caretPos; - protected int x, y; + protected float x, y; protected float start, end; protected int startLine, endLine; protected long vg; @@ -95,7 +95,7 @@ public class TextInputField extends BasicElement { } @Override - public void draw(long vg, int x, int y) { + public void draw(long vg, float x, float y) { this.x = x; this.y = y; this.vg = vg; @@ -206,12 +206,12 @@ public class TextInputField extends BasicElement { if(disabled) RenderManager.setAlpha(vg, 0.5f); if (toggled) { if (multiLine) { - int lineY = y + 20 + getCaretLine(caretPos) * 24; + float lineY = y + 20 + getCaretLine(caretPos) * 24; RenderManager.drawLine(vg, x + width + 12, lineY - 10, x + width + 12, lineY + 10, 1, Colors.WHITE); } else if (!centered) { - RenderManager.drawLine(vg, x + width + 12, (float) y + height / 2f - 10, x + width + 12, (float) y + height / 2f + 10, 1, Colors.WHITE); + RenderManager.drawLine(vg, x + width + 12, y + height / 2f - 10, x + width + 12, y + height / 2f + 10, 1, Colors.WHITE); } else { - RenderManager.drawLine(vg, x + this.width / 2f - halfTextWidth + width, (float) y + height / 2f - 10, x + this.width / 2f - halfTextWidth + width, (float) y + height / 2f + 10, 1, Colors.WHITE); + RenderManager.drawLine(vg, x + this.width / 2f - halfTextWidth + width, y + height / 2f - 10, x + this.width / 2f - halfTextWidth + width, y + height / 2f + 10, 1, Colors.WHITE); } } @@ -228,7 +228,7 @@ public class TextInputField extends BasicElement { if (!password) { if (multiLine) { - int textY = y + 20; + float textY = y + 20; for (String line : wrappedText) { RenderManager.drawText(vg, line, x + 12, textY, color, 14f, Fonts.REGULAR); textY += 24; @@ -453,7 +453,7 @@ public class TextInputField extends BasicElement { } } - private int calculatePos(int pos, String string) { + private int calculatePos(float pos, String string) { if (centered) pos -= 12; String s1 = ""; int i; diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java index 028f098..5a5970a 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java @@ -52,7 +52,7 @@ public abstract class Page { final float scrollBarLength = (728f / maxScroll) * 728f; Scissor scissor = ScissorManager.scissor(vg, x, y + scissorOffset, x + 1056, y + 728 - scissorOffset); Scissor inputScissor = InputUtils.blockInputArea(x, y,1056, scissorOffset); - int dWheel = (int) Platform.getMousePlatform().getDWheel(); + float dWheel = (float) Platform.getMousePlatform().getDWheel(); if (dWheel != 0) { scrollTarget += dWheel; diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java b/src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java new file mode 100644 index 0000000..cb8a2d4 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java @@ -0,0 +1,116 @@ +package cc.polyfrost.oneconfig.hud; + +import cc.polyfrost.oneconfig.config.core.OneColor; +import cc.polyfrost.oneconfig.libs.universal.UMatrixStack; +import cc.polyfrost.oneconfig.renderer.RenderManager; + +public abstract class BasicHud extends Hud { + protected boolean rounded; + protected boolean border; + protected OneColor bgColor; + protected OneColor borderColor; + protected float cornerRadius; + protected float borderSize; + protected float paddingX; + protected float paddingY; + + /** + * @param enabled If the hud is enabled + * @param x X-coordinate of hud on a 1080p display + * @param y Y-coordinate of hud on a 1080p display + * @param scale Scale of the hud + * @param rounded If the corner is rounded or not + * @param cornerRadius Radius of the corner + * @param paddingX Horizontal background padding + * @param paddingY Vertical background padding + * @param bgColor Background color + * @param border If the hud has a border or not + * @param borderSize Thickness of the border + * @param borderColor The color of the border + */ + public BasicHud(boolean enabled, float x, float y, float scale, boolean rounded, float cornerRadius, float paddingX, float paddingY, OneColor bgColor, boolean border, float borderSize, OneColor borderColor) { + super(enabled, x, y, scale); + this.rounded = rounded; + this.cornerRadius = cornerRadius; + this.paddingX = paddingX; + this.paddingY = paddingY; + this.bgColor = bgColor; + this.border = border; + this.borderSize = borderSize; + this.borderColor = borderColor; + position.setSize(getWidth(scale, true) + paddingX * scale * 2f, getHeight(scale, true) + paddingY * scale * 2f); + } + + /** + * @param enabled If the hud is enabled + * @param x X-coordinate of hud on a 1080p display + * @param y Y-coordinate of hud on a 1080p display + * @param scale Scale of the hud + */ + public BasicHud(boolean enabled, float x, float y, float scale) { + this(enabled, x, y, scale, false, 2, 5, 5, new OneColor(0, 0, 0, 120), false, 2, new OneColor(0, 0, 0)); + } + + /** + * @param enabled If the hud is enabled + * @param x X-coordinate of hud on a 1080p display + * @param y Y-coordinate of hud on a 1080p display + */ + public BasicHud(boolean enabled, float x, float y) { + this(enabled, x, y, 1, false, 2, 5, 5, new OneColor(0, 0, 0, 120), false, 2, new OneColor(0, 0, 0)); + } + + /** + * @param enabled If the hud is enabled + */ + public BasicHud(boolean enabled) { + this(enabled, 0, 0, 1, false, 2, 5, 5, new OneColor(0, 0, 0, 120), false, 2, new OneColor(0, 0, 0)); + } + + public BasicHud() { + this(false, 0, 0, 1, false, 2, 5, 5, new OneColor(0, 0, 0, 120), false, 2, new OneColor(0, 0, 0)); + } + + @Override + public void drawAll(UMatrixStack matrices, boolean example) { + if (!example && !shouldShow()) return; + preRender(example); + position.setSize(getWidth(scale, example) + paddingX * scale * 2f, getHeight(scale, example) + paddingY * scale * 2f); + if (shouldDrawBackground()) + drawBackground(position.getX(), position.getY(), position.getWidth(), position.getHeight(), scale); + draw(matrices, position.getX() + paddingX * scale, position.getY() + paddingY * scale, scale, example); + } + + /** + * Set a new scale value + * + * @param scale The new scale + * @param example If the HUD is being rendered in example form + */ + @Override + public void setScale(float scale, boolean example) { + this.scale = scale; + position.updateSizePosition(getWidth(scale, example) + paddingX * scale * 2f, getHeight(scale, example) + paddingY * scale * 2f); + } + + /** + * @return If the background should be drawn + */ + protected boolean shouldDrawBackground() { + return true; + } + + protected void drawBackground(float x, float y, float width, float height, float scale) { + RenderManager.setupAndDraw(true, (vg) -> { + if (rounded) { + RenderManager.drawRoundedRect(vg, x, y, width, height, bgColor.getRGB(), cornerRadius * scale); + if (border) + RenderManager.drawHollowRoundRect(vg, x - borderSize * scale, y - borderSize * scale, width + borderSize * scale, height + borderSize * scale, borderColor.getRGB(), cornerRadius * scale, borderSize * scale); + } else { + RenderManager.drawRect(vg, x, y, width, height, bgColor.getRGB()); + if (border) + RenderManager.drawHollowRoundRect(vg, x - borderSize * scale, y - borderSize * scale, width + borderSize * scale, height + borderSize * scale, borderColor.getRGB(), 0, borderSize * scale); + } + }); + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java b/src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java index a67177c..bff1b70 100644 --- a/src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java @@ -6,42 +6,52 @@ import cc.polyfrost.oneconfig.config.core.ConfigUtils; import cc.polyfrost.oneconfig.config.elements.BasicOption; import cc.polyfrost.oneconfig.config.elements.OptionPage; import cc.polyfrost.oneconfig.gui.elements.config.*; +import cc.polyfrost.oneconfig.hud.BasicHud; +import cc.polyfrost.oneconfig.hud.Hud; import cc.polyfrost.oneconfig.internal.hud.HudCore; import java.lang.reflect.Field; import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; public class HUDUtils { public static void addHudOptions(OptionPage page, Field field, Object instance, Config config) { HUD hudAnnotation = field.getAnnotation(HUD.class); + field.setAccessible(true); Hud hud = (Hud) ConfigUtils.getField(field, instance); if (hud == null) return; hud.setConfig(config); HudCore.huds.add(hud); String category = hudAnnotation.category(); String subcategory = hudAnnotation.subcategory(); - ArrayList<BasicOption> options = ConfigUtils.getSubCategory(page, hudAnnotation.category(), hudAnnotation.subcategory()).options; + ArrayList<BasicOption> options = new ArrayList<>(); try { + ArrayList<Field> fieldArrayList = ConfigUtils.getClassFields(hud.getClass()); + HashMap<String, Field> fields = new HashMap<>(); + for (Field f : fieldArrayList) fields.put(f.getName(), f); options.add(new ConfigHeader(field, hud, hudAnnotation.name(), category, subcategory, 2)); - options.add(new ConfigSwitch(hud.getClass().getField("enabled"), hud, "Enabled", category, subcategory, 2)); + options.add(new ConfigSwitch(fields.get("enabled"), hud, "Enabled", category, subcategory, 2)); options.addAll(ConfigUtils.getClassOptions(hud)); - options.add(new ConfigCheckbox(hud.getClass().getField("rounded"), hud, "Rounded corners", category, subcategory, 1)); - options.get(options.size() - 1).addDependency(hud::isEnabled); - options.add(new ConfigCheckbox(hud.getClass().getField("border"), hud, "Outline/border", category, subcategory, 1)); - options.get(options.size() - 1).addDependency(hud::isEnabled); - options.add(new ConfigColorElement(hud.getClass().getField("bgColor"), hud, "Background color:", category, subcategory, 1, true)); - options.get(options.size() - 1).addDependency(hud::isEnabled); - options.add(new ConfigColorElement(hud.getClass().getField("borderColor"), hud, "Border color:", category, subcategory, 1, true)); - options.get(options.size() - 1).addDependency(() -> hud.isEnabled() && hud.border); - options.add(new ConfigSlider(hud.getClass().getField("cornerRadius"), hud, "Corner radius:", category, subcategory, 0, 10, 0)); - options.get(options.size() - 1).addDependency(() -> hud.isEnabled() && hud.rounded); - options.add(new ConfigSlider(hud.getClass().getField("borderSize"), hud, "Border thickness:", category, subcategory, 0, 10, 0)); - options.get(options.size() - 1).addDependency(() -> hud.isEnabled() && hud.border); - options.add(new ConfigSlider(hud.getClass().getField("paddingX"), hud, "X-Padding", category, subcategory, 0, 50, 0)); - options.get(options.size() - 1).addDependency(hud::isEnabled); - options.add(new ConfigSlider(hud.getClass().getField("paddingY"), hud, "Y-Padding", category, subcategory, 0, 50, 0)); - options.get(options.size() - 1).addDependency(hud::isEnabled); - } catch (NoSuchFieldException ignored) { + if (hud instanceof BasicHud) { + options.add(new ConfigCheckbox(fields.get("rounded"), hud, "Rounded corners", category, subcategory, 1)); + options.add(new ConfigCheckbox(fields.get("border"), hud, "Outline/border", category, subcategory, 1)); + options.add(new ConfigColorElement(fields.get("bgColor"), hud, "Background color:", category, subcategory, 1, true)); + options.add(new ConfigColorElement(fields.get("borderColor"), hud, "Border color:", category, subcategory, 1, true)); + options.get(options.size() - 1).addDependency(() -> ((BasicHud) hud).border); + options.add(new ConfigSlider(fields.get("cornerRadius"), hud, "Corner radius:", category, subcategory, 0, 10, 0)); + options.get(options.size() - 1).addDependency(() -> ((BasicHud) hud).rounded); + options.add(new ConfigSlider(fields.get("borderSize"), hud, "Border thickness:", category, subcategory, 0, 10, 0)); + options.get(options.size() - 1).addDependency(() -> ((BasicHud) hud).border); + options.add(new ConfigSlider(fields.get("paddingX"), hud, "X-Padding", category, subcategory, 0, 50, 0)); + options.add(new ConfigSlider(fields.get("paddingY"), hud, "Y-Padding", category, subcategory, 0, 50, 0)); + } + for (BasicOption option : options) { + if (option.name.equals("Enabled")) continue; + option.addDependency(hud::isEnabled); + } + } catch (Exception ignored) { } + ConfigUtils.getSubCategory(page, hudAnnotation.category(), hudAnnotation.subcategory()).options.addAll(options); } } diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/Hud.java b/src/main/java/cc/polyfrost/oneconfig/hud/Hud.java index 05a4f76..a8c51bd 100644 --- a/src/main/java/cc/polyfrost/oneconfig/hud/Hud.java +++ b/src/main/java/cc/polyfrost/oneconfig/hud/Hud.java @@ -2,11 +2,9 @@ package cc.polyfrost.oneconfig.hud; import cc.polyfrost.oneconfig.config.Config; import cc.polyfrost.oneconfig.config.annotations.Switch; -import cc.polyfrost.oneconfig.config.core.OneColor; import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.libs.universal.UMatrixStack; import cc.polyfrost.oneconfig.platform.Platform; -import cc.polyfrost.oneconfig.renderer.RenderManager; /** * Represents a HUD element in OneConfig. @@ -15,7 +13,7 @@ import cc.polyfrost.oneconfig.renderer.RenderManager; * If you simply want to display text, extend {@link TextHud} or {@link SingleTextHud}, * whichever applies to the use case. Then, override the required methods. * <p> - * If you want to display something else, extend this class and override {@link Hud#getWidth(float)}, {@link Hud#getHeight(float)}, and {@link Hud#draw(UMatrixStack, int, int, float)} with the width, height, and the drawing code respectively. + * If you want to display something else, extend this class and override {@link Hud#getWidth(float, boolean)}, {@link Hud#getHeight(float, boolean)}, and {@link Hud#draw(UMatrixStack, float, float, float, boolean)} with the width, height, and the drawing code respectively. * </p> * <p> * It should also be noted that additional options to the HUD can be added simply by declaring them. @@ -39,50 +37,10 @@ import cc.polyfrost.oneconfig.renderer.RenderManager; * * }</pre> */ public abstract class Hud { - public boolean enabled; + protected boolean enabled; transient private Config config; - public boolean rounded; - public boolean border; - public OneColor bgColor; - public OneColor borderColor; - public float cornerRadius; - public float borderSize; - public double xUnscaled; - public double yUnscaled; - public float scale; - public float paddingX; - public float paddingY; - - /** - * @param enabled If the hud is enabled - * @param x X-coordinate of hud on a 1080p display - * @param y Y-coordinate of hud on a 1080p display - * @param scale Scale of the hud - * @param rounded If the corner is rounded or not - * @param cornerRadius Radius of the corner - * @param paddingX Horizontal background padding - * @param paddingY Vertical background padding - * @param bgColor Background color - * @param border If the hud has a border or not - * @param borderSize Thickness of the border - * @param borderColor The color of the border - */ - public Hud(boolean enabled, int x, int y, float scale, boolean rounded, int cornerRadius, int paddingX, int paddingY, OneColor bgColor, boolean border, float borderSize, OneColor borderColor) { - this.enabled = enabled; - this.scale = scale; - this.rounded = rounded; - this.cornerRadius = cornerRadius; - this.paddingX = paddingX; - this.paddingY = paddingY; - this.bgColor = bgColor; - this.border = border; - this.borderSize = borderSize; - this.borderColor = borderColor; - if (x / 1920d <= 0.5d) xUnscaled = x / 1920d; - else xUnscaled = (x + getWidth(scale)) / 1920d; - if (y / 1080d <= 0.5d) yUnscaled = y / 1080d; - else yUnscaled = (y + getHeight(scale)) / 1090d; - } + public final Position position; + protected float scale; /** * @param enabled If the hud is enabled @@ -90,8 +48,10 @@ public abstract class Hud { * @param y Y-coordinate of hud on a 1080p display * @param scale Scale of the hud */ - public Hud(boolean enabled, int x, int y, int scale) { - this(enabled, x, y, scale, false, 2, 5, 5, new OneColor(0, 0, 0, 120), false, 2, new OneColor(0, 0, 0)); + public Hud(boolean enabled, float x, float y, float scale) { + this.enabled = enabled; + this.scale = scale; + position = new Position(x, y, getWidth(scale, true), getHeight(scale, true)); } /** @@ -99,153 +59,103 @@ public abstract class Hud { * @param x X-coordinate of hud on a 1080p display * @param y Y-coordinate of hud on a 1080p display */ - public Hud(boolean enabled, int x, int y) { - this(enabled, x, y, 1, false, 2, 5, 5, new OneColor(0, 0, 0, 120), false, 2, new OneColor(0, 0, 0)); + public Hud(boolean enabled, float x, float y) { + this(enabled, x, y, 1); } /** * @param enabled If the hud is enabled */ public Hud(boolean enabled) { - this(enabled, 0, 0, 1, false, 2, 5, 5, new OneColor(0, 0, 0, 120), false, 2, new OneColor(0, 0, 0)); + this(enabled, 0, 0, 1); } - /** - * Function called when drawing the hud - * - * @param x Top left x-coordinate of the hud - * @param y Top left y-coordinate of the hud - * @param scale Scale of the hud - */ - public abstract void draw(UMatrixStack matrices, int x, int y, float scale); + public Hud() { + this(false, 0, 0, 1); + } /** - * Function called when drawing the example version of the hud. - * This is used in for example, the hud editor gui. + * Function called when drawing the hud * - * @param x Top left x-coordinate of the hud - * @param y Top left y-coordinate of the hud - * @param scale Scale of the hud + * @param matrices The UMatrixStack used for rendering in higher versions + * @param x Top left x-coordinate of the hud + * @param y Top left y-coordinate of the hud + * @param scale Scale of the hud + * @param example If the HUD is being rendered in example form */ - public void drawExample(UMatrixStack matrices, int x, int y, float scale) { - draw(matrices, x, y, scale); - } + protected abstract void draw(UMatrixStack matrices, float x, float y, float scale, boolean example); /** - * @param scale Scale of the hud + * @param scale Scale of the hud + * @param example If the HUD is being rendered in example form * @return The width of the hud */ - public abstract int getWidth(float scale); + protected abstract float getWidth(float scale, boolean example); /** - * @param scale Scale of the hud + * @param scale Scale of the hud + * @param example If the HUD is being rendered in example form * @return The height of the hud */ - public abstract int getHeight(float scale); - - /** - * @param scale Scale of the hud - * @return The width of the example version of the hud - */ - public int getExampleWidth(float scale) { - return getWidth(scale); - } - - /** - * @param scale Scale of the hud - * @return The height of the example version of the hud - */ - public int getExampleHeight(float scale) { - return getHeight(scale); - } + protected abstract float getHeight(float scale, boolean example); /** - * @return If the background should be drawn + * Function to do things before rendering anything + * + * @param example If the HUD is being rendered in example form */ - public boolean drawBackground() { - return true; + protected void preRender(boolean example) { } /** * Draw the background, the hud and all childed huds, used by HudCore - * - * @param x X-coordinate - * @param y Y-coordinate - * @param scale Scale of the hud - * @param background If background should be drawn or not */ - public void drawAll(UMatrixStack matrices, float x, float y, float scale, boolean background) { - if (!showInGuis && Platform.getGuiPlatform().getCurrentScreen() != null && !(Platform.getGuiPlatform().getCurrentScreen() instanceof OneConfigGui)) return; - if (!showInChat && Platform.getGuiPlatform().isInChat()) return; - if (!showInDebug && Platform.getGuiPlatform().isInDebug()) return; - if (background && drawBackground()) drawBackground(x, y, getWidth(scale), getHeight(scale), scale); - draw(matrices, (int) (x + paddingX * scale / 2f), (int) (y + paddingY * scale / 2f), scale); + public void drawAll(UMatrixStack matrices, boolean example) { + if (!example && !shouldShow()) return; + preRender(example); + position.setSize(getWidth(scale, example), getHeight(scale, example)); + draw(matrices, position.getX(), position.getY(), scale, example); } - /** - * Draw example version of the background, the hud and all childed huds, used by HudGui - * - * @param x X-coordinate - * @param y Y-coordinate - * @param scale Scale of the hud - * @param background If background should be drawn or not - */ - public void drawExampleAll(UMatrixStack matrices, float x, float y, float scale, boolean background) { - if (background) drawBackground(x, y, getWidth(scale), getHeight(scale), scale); - drawExample(matrices, (int) (x + paddingX * scale / 2f), (int) (y + paddingY * scale / 2f), scale); + protected boolean shouldShow() { + if (!showInGuis && Platform.getGuiPlatform().getCurrentScreen() != null && !(Platform.getGuiPlatform().getCurrentScreen() instanceof OneConfigGui)) + return false; + if (!showInChat && Platform.getGuiPlatform().isInChat()) return false; + return showInDebug || !Platform.getGuiPlatform().isInDebug(); } /** - * Draw example version of the background, the hud and all childed huds, used by HudGui - * - * @param x X-coordinate - * @param y Y-coordinate - * @param width Width of the hud - * @param height Height of the hud - * @param scale Scale of the hud + * @return If the hud is enabled */ - private void drawBackground(float x, float y, float width, float height, float scale) { - RenderManager.setupAndDraw(true, (vg) -> { - if (rounded) { - RenderManager.drawRoundedRect(vg, x, y, (width + paddingX * scale), (height + paddingY * scale), bgColor.getRGB(), cornerRadius * scale); - if (border) - RenderManager.drawHollowRoundRect(vg, x - borderSize * scale, y - borderSize * scale, (width + paddingX * scale) + borderSize * scale, (height + paddingY * scale) + borderSize * scale, borderColor.getRGB(), cornerRadius * scale, borderSize * scale); - } else { - RenderManager.drawRect(vg, x, y, (width + paddingX * scale), (height + paddingY * scale), bgColor.getRGB()); - if (border) - RenderManager.drawHollowRoundRect(vg, x - borderSize * scale, y - borderSize * scale, (width + paddingX * scale) + borderSize * scale, (height + paddingY * scale) + borderSize * scale, borderColor.getRGB(), 0, borderSize * scale); - } - }); + public boolean isEnabled() { + return enabled && (config == null || config.enabled); } /** - * @param screenWidth width of the screen - * @return X-coordinate of the hud + * Set the config to disable accordingly, intended for internal use + * + * @param config The config instance */ - public float getXScaled(int screenWidth) { - if (xUnscaled <= 0.5) - return (int) (screenWidth * xUnscaled); - return (float) (screenWidth - (1d - xUnscaled) * screenWidth - (getWidth(scale) + paddingX * scale)); + public void setConfig(Config config) { + this.config = config; } /** - * @param screenHeight height of the screen - * @return Y-coordinate of the hud + * @return The scale of the Hud */ - public float getYScaled(int screenHeight) { - if (yUnscaled <= 0.5) return (int) (screenHeight * yUnscaled); - return (float) (screenHeight - (1d - yUnscaled) * screenHeight - (getHeight(scale) + paddingY * scale)); + public float getScale() { + return scale; } /** - * @return If the hud is enabled + * Set a new scale value + * + * @param scale The new scale + * @param example If the HUD is being rendered in example form */ - public boolean isEnabled() { - return enabled && (config == null || config.enabled); - } - - public void setConfig(Config config) { - this.config = config; + public void setScale(float scale, boolean example) { + this.scale = scale; + position.updateSizePosition(getWidth(scale, example), getHeight(scale, example)); } @Switch( diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/Position.java b/src/main/java/cc/polyfrost/oneconfig/hud/Position.java new file mode 100644 index 0000000..1b3bbb7 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/hud/Position.java @@ -0,0 +1,279 @@ +package cc.polyfrost.oneconfig.hud; + +import cc.polyfrost.oneconfig.config.annotations.Exclude; +import cc.polyfrost.oneconfig.libs.universal.UResolution; +import com.google.gson.annotations.SerializedName; + +public class Position { + private AnchorPosition anchor; + private float x; + private float y; + @Exclude + private float width; + @Exclude + private float height; + + /** + * Position object used for huds + * + * @param x The X coordinate + * @param y The Y coordinate + * @param width The width of the HUD + * @param height The height of the HUD + * @param screenWidth The width of the screen to initialize the position width + * @param screenHeight The height of the screen to initialize the position width + */ + public Position(float x, float y, float width, float height, float screenWidth, float screenHeight) { + setSize(width, height); + setPosition(x, y, screenWidth, screenHeight); + } + + /** + * Position object used for huds + * + * @param x The X coordinate + * @param y The Y coordinate + * @param width The width of the HUD + * @param height The height of the HUD + */ + public Position(float x, float y, float width, float height) { + this(x, y, width, height, 1920, 1080); + } + + /** + * Set the position + * + * @param x The X coordinate + * @param y The Y coordinate + * @param screenWidth The screen width + * @param screenHeight The screen height + */ + public void setPosition(float x, float y, float screenWidth, float screenHeight) { + float rightX = x + width; + float bottomY = y + height; + + if (x <= screenWidth / 3f && y <= screenHeight / 3f) + this.anchor = AnchorPosition.TOP_LEFT; + else if (rightX >= screenWidth / 3f * 2f && y <= screenHeight / 3f) + this.anchor = AnchorPosition.TOP_RIGHT; + else if (x <= screenWidth / 3f && bottomY >= screenHeight / 3f * 2f) + this.anchor = AnchorPosition.BOTTOM_LEFT; + else if (rightX >= screenWidth / 3f * 2f && bottomY >= screenHeight / 3f * 2f) + this.anchor = AnchorPosition.BOTTOM_RIGHT; + else if (y <= screenHeight / 3f) + this.anchor = AnchorPosition.TOP_CENTER; + else if (x <= screenWidth / 3f) + this.anchor = AnchorPosition.MIDDLE_LEFT; + else if (rightX >= screenWidth / 3f * 2f) + this.anchor = AnchorPosition.MIDDLE_RIGHT; + else if (bottomY >= screenHeight / 3f * 2f) + this.anchor = AnchorPosition.BOTTOM_CENTER; + else + this.anchor = AnchorPosition.MIDDLE_CENTER; + + this.x = x - getAnchorX(screenWidth) + getAnchorX(width); + this.y = y - getAnchorY(screenHeight) + getAnchorY(height); + } + + /** + * Set the position + * + * @param x The X coordinate + * @param y The Y coordinate + */ + public void setPosition(float x, float y) { + setPosition(x, y, UResolution.getScaledWidth(), UResolution.getScaledHeight()); + } + + /** + * Set the size of the position + * + * @param width The width + * @param height The height + */ + public void setSize(float width, float height) { + this.width = width; + this.height = height; + } + + /** + * Update the position so the top left corner stays in the same spot + * + * @param width The width + * @param height The height + */ + public void updateSizePosition(float width, float height) { + float x = getX(); + float y = getY(); + setSize(width, height); + setPosition(x, y); + } + + /** + * Get the X coordinate scaled to the size of the screen + * + * @param screenWidth The width of the screen + * @return The X coordinate + */ + public float getX(float screenWidth) { + return x + getAnchorX(screenWidth) - getAnchorX(width); + } + + /** + * Get the X coordinate scaled to the size of the screen + * + * @return The X coordinate + */ + public float getX() { + return getX(UResolution.getScaledWidth()); + } + + /** + * Get the Y coordinate scaled to the size of the screen + * + * @param screenHeight The height of the screen + * @return The Y coordinate + */ + public float getY(float screenHeight) { + return y + getAnchorY(screenHeight) - getAnchorY(height); + } + + /** + * Get the Y coordinate scaled to the size of the screen + * + * @return The Y coordinate + */ + public float getY() { + return getY(UResolution.getScaledHeight()); + } + + /** + * Get the X coordinate scaled to the size of the screen of the right corner + * + * @param screenWidth The width of the screen + * @return The X coordinate of the right corner + */ + public float getRightX(float screenWidth) { + return getX(screenWidth) + width; + } + + /** + * Get the X coordinate scaled to the size of the screen of the right corner + * + * @return The X coordinate of the right corner + */ + public float getRightX() { + return getRightX(UResolution.getScaledWidth()); + } + + /** + * Get the Y coordinate scaled to the size of the screen of the bottom corner + * + * @param screenHeight The width of the screen + * @return The Y coordinate of the bottom corner + */ + public float getBottomY(float screenHeight) { + return getY(screenHeight) + height; + } + + /** + * Get the Y coordinate scaled to the size of the screen of the bottom corner + * + * @return The Y coordinate of the bottom corner + */ + public float getBottomY() { + return getBottomY(UResolution.getScaledHeight()); + } + + /** + * Get the center X coordinate + * + * @param screenWidth The width of the screen + * @return The center X coordinate + */ + public float getCenterX(float screenWidth) { + return getX(screenWidth) + width / 2f; + } + + /** + * Get the center X coordinate + * + * @return The center X coordinate + */ + public float getCenterX() { + return getCenterX(UResolution.getScaledWidth()); + } + + /** + * Get the center Y coordinate + * + * @param screenHeight The width of the screen + * @return The center Y coordinate + */ + public float getCenterY(float screenHeight) { + return getY(screenHeight) + height / 2f; + } + + /** + * Get the center Y coordinate + * + * @return The center Y coordinate + */ + public float getCenterY() { + return getCenterY(UResolution.getScaledHeight()); + } + + /** + * @return The width of the position + */ + public float getWidth() { + return width; + } + + /** + * @return The height of the position + */ + public float getHeight() { + return height; + } + + private float getAnchorX(float value) { + return value * anchor.x; + } + + private float getAnchorY(float value) { + return value * anchor.y; + } + + /** + * Position of the anchors were the position is relative too + */ + public enum AnchorPosition { + @SerializedName("0") + TOP_LEFT(0f, 0f), + @SerializedName("1") + TOP_CENTER(0.5f, 0f), + @SerializedName("2") + TOP_RIGHT(1f, 0f), + @SerializedName("3") + MIDDLE_LEFT(0f, 0.5f), + @SerializedName("4") + MIDDLE_CENTER(0.5f, 0.5f), + @SerializedName("5") + MIDDLE_RIGHT(1f, 0.5f), + @SerializedName("6") + BOTTOM_LEFT(0f, 1f), + @SerializedName("7") + BOTTOM_CENTER(0.5f, 1f), + @SerializedName("8") + BOTTOM_RIGHT(1f, 1f); + + public final float x; + public final float y; + + AnchorPosition(float x, float y) { + this.x = x; + this.y = y; + } + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/SingleTextHud.java b/src/main/java/cc/polyfrost/oneconfig/hud/SingleTextHud.java index d3ce8f2..5380be5 100644 --- a/src/main/java/cc/polyfrost/oneconfig/hud/SingleTextHud.java +++ b/src/main/java/cc/polyfrost/oneconfig/hud/SingleTextHud.java @@ -22,56 +22,25 @@ public abstract class SingleTextHud extends TextHud { * * @return The new text */ - protected abstract String getText(); + protected abstract String getText(boolean example); /** * This function is called every frame * * @return The new text, null to use the cached value */ - protected String getTextFrequent() { + protected String getTextFrequent(boolean example) { return null; } - /** - * This function is called every tick in the move GUI - * - * @return The new text - */ - protected String getExampleText() { - return getText(); - } - - /** - * This function is called every frame in the move GUI - * - * @return The new text, null to use the cached value - */ - protected String getExampleTextFrequent() { - return getTextFrequent(); - } - - @Override - protected void getLines(List<String> lines) { - lines.add(getCompleteText(getText())); - } - - @Override - protected void getLinesFrequent(List<String> lines) { - String text = getTextFrequent(); - if (text == null) return; - lines.clear(); - lines.add(getCompleteText(text)); - } - @Override - protected void getExampleLines(List<String> lines) { - lines.add(getCompleteText(getExampleText())); + protected void getLines(List<String> lines, boolean example) { + lines.add(getCompleteText(getText(example))); } @Override - protected void getExampleLinesFrequent(List<String> lines) { - String text = getExampleTextFrequent(); + protected void getLinesFrequent(List<String> lines, boolean example) { + String text = getTextFrequent(example); if (text == null) return; lines.clear(); lines.add(getCompleteText(text)); @@ -104,16 +73,16 @@ public abstract class SingleTextHud extends TextHud { @Switch( name = "Brackets" ) - public boolean brackets = false; + protected boolean brackets = false; @Text( name = "Title" ) - public String title; + protected String title; @Dropdown( name = "Title Location", options = {"Left", "Right"} ) - public int titleLocation = 0; + protected int titleLocation = 0; }
\ No newline at end of file diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java b/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java index 8dd8ac3..b4857d8 100644 --- a/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java +++ b/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java @@ -15,21 +15,20 @@ import cc.polyfrost.oneconfig.renderer.RenderManager; import java.util.ArrayList; import java.util.List; -public abstract class TextHud extends Hud { +public abstract class TextHud extends BasicHud { protected transient List<String> lines = new ArrayList<>(); private transient int width; - private transient int height; @Color( name = "Text Color" ) - public OneColor color = new OneColor(255, 255, 255); + protected OneColor color = new OneColor(255, 255, 255); @Dropdown( name = "Text Type", options = {"No Shadow", "Shadow", "Full Shadow"} ) - public int textType = 0; + protected int textType = 0; public TextHud(boolean enabled, int x, int y) { super(enabled, x, y); @@ -45,59 +44,72 @@ public abstract class TextHud extends Hud { * * @param lines Empty ArrayList to add your hud text too */ - protected abstract void getLines(List<String> lines); + protected abstract void getLines(List<String> lines, boolean example); /** * This function is called every frame * * @param lines The current lines of the hud */ - protected void getLinesFrequent(List<String> lines) { + protected void getLinesFrequent(List<String> lines, boolean example) { + } + + @Override + public void draw(UMatrixStack matrices, float x, float y, float scale, boolean example) { + if (lines == null || lines.size() == 0) return; + float textY = y; + for (String line : lines) { + drawLine(line, x, textY, scale); + textY += 12 * scale; + } } /** - * This function is called every tick in the move GUI + * Function that can be overwritten to implement different behavior easily * - * @param lines Empty ArrayList to add your hud text too + * @param line The line + * @param x The X coordinate + * @param y The Y coordinate + * @param scale The scale */ - protected void getExampleLines(List<String> lines) { - getLines(lines); + protected void drawLine(String line, float x, float y, float scale) { + RenderManager.drawScaledString(line, x, y, color.getRGB(), RenderManager.TextType.toType(textType), scale); } /** - * This function is called every frame in the move GUI + * Function that can be overwritten to implement different behavior easily * - * @param lines The current lines of the hud + * @param line The line + * @return The width of the line (scaled accordingly) */ - protected void getExampleLinesFrequent(List<String> lines) { - getLinesFrequent(lines); + protected float getLineWidth(String line, float scale) { + return Platform.getGLPlatform().getStringWidth(line) * scale; } @Override - public void draw(UMatrixStack matrices, int x, int y, float scale) { - if (!HudCore.editing) getLinesFrequent(lines); - else getExampleLinesFrequent(lines); - if (lines == null) return; + protected void preRender(boolean example) { + getLinesFrequent(lines, example); + } - int textY = y; - width = 0; + @Override + protected float getWidth(float scale, boolean example) { + if (lines == null) return 0; + float width = 0; for (String line : lines) { - RenderManager.drawScaledString(line, x, textY, color.getRGB(), RenderManager.TextType.toType(textType), scale); - width = Math.max(width, Platform.getGLPlatform().getStringWidth(line)); - textY += 12 * scale; + width = Math.max(width, getLineWidth(line, scale)); } - height = (int) ((textY - y) / scale - 3); + return width; } @Override - public int getWidth(float scale) { - return (int) (width * scale); + protected float getHeight(float scale, boolean example) { + return lines == null ? 0 : (lines.size() * 12 - 4) * scale; } @Override - public int getHeight(float scale) { - return (int) (height * scale); + public boolean shouldDrawBackground() { + return super.shouldDrawBackground() && lines != null && lines.size() > 0; } private class TickHandler { @@ -105,8 +117,7 @@ public abstract class TextHud extends Hud { private void onTick(TickEvent event) { if (event.stage != Stage.START || !isEnabled()) return; lines.clear(); - if (!HudCore.editing) getLines(lines); - else getExampleLines(lines); + getLines(lines, HudCore.editing); } } }
\ No newline at end of file diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/assets/Colors.java b/src/main/java/cc/polyfrost/oneconfig/internal/assets/Colors.java index 84f766f..9362873 100644 --- a/src/main/java/cc/polyfrost/oneconfig/internal/assets/Colors.java +++ b/src/main/java/cc/polyfrost/oneconfig/internal/assets/Colors.java @@ -42,9 +42,6 @@ public class Colors { public static final int ERROR_800_80 = new Color(145, 24, 24, 204).getRGB(); // Red 800 public static final int ERROR_300 = new Color(253, 155, 155).getRGB(); public static final int ERROR_300_80 = new Color(253, 155, 155, 204).getRGB(); - public static boolean ROUNDED_CORNERS = true; - public static final float CORNER_RADIUS_WIN = 20f; - public static final float CORNER_RADIUS = 12f; /** List of all colors used by Minecraft in its code. * Source: <a href="https://www.digminecraft.com/lists/color_list_pc.php">Click Here</a> @@ -71,7 +68,5 @@ public class Colors { public static final int GRAY = new Color(170, 170, 170).getRGB(); // Mapped to 7 public static final int DARK_GRAY = new Color(85, 85, 85).getRGB(); // Mapped to 8 public static final int BLACK = new Color(0, 0, 0).getRGB(); // Mapped to 0 - - } } diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/command/OneConfigCommand.java b/src/main/java/cc/polyfrost/oneconfig/internal/command/OneConfigCommand.java index 93d3c42..8aca921 100644 --- a/src/main/java/cc/polyfrost/oneconfig/internal/command/OneConfigCommand.java +++ b/src/main/java/cc/polyfrost/oneconfig/internal/command/OneConfigCommand.java @@ -1,6 +1,6 @@ package cc.polyfrost.oneconfig.internal.command; -import cc.polyfrost.oneconfig.gui.HudGui; +import cc.polyfrost.oneconfig.internal.gui.HudGui; import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.utils.gui.GuiUtils; import cc.polyfrost.oneconfig.utils.InputUtils; @@ -23,7 +23,7 @@ public class OneConfigCommand { private static class HUDSubCommand { @Main private static void main() { - GuiUtils.displayScreen(new HudGui(false)); + GuiUtils.displayScreen(new HudGui()); } } diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/config/Preferences.java b/src/main/java/cc/polyfrost/oneconfig/internal/config/Preferences.java index cb93f0a..bf290b7 100644 --- a/src/main/java/cc/polyfrost/oneconfig/internal/config/Preferences.java +++ b/src/main/java/cc/polyfrost/oneconfig/internal/config/Preferences.java @@ -1,5 +1,6 @@ package cc.polyfrost.oneconfig.internal.config; +import cc.polyfrost.oneconfig.config.annotations.Exclude; import cc.polyfrost.oneconfig.config.annotations.KeyBind; import cc.polyfrost.oneconfig.config.annotations.Slider; import cc.polyfrost.oneconfig.config.annotations.Switch; @@ -9,7 +10,6 @@ import cc.polyfrost.oneconfig.internal.gui.BlurHandler; import cc.polyfrost.oneconfig.libs.universal.UKeyboard; import cc.polyfrost.oneconfig.platform.Platform; import cc.polyfrost.oneconfig.utils.TickDelay; -import cc.polyfrost.oneconfig.utils.gui.GuiUtils; public class Preferences extends InternalConfig { @Switch( @@ -23,10 +23,6 @@ public class Preferences extends InternalConfig { ) public static OneKeyBind oneConfigKeyBind = new OneKeyBind(UKeyboard.KEY_RSHIFT); - @Switch( - name = "Easter Egg 1" - ) - public static boolean easterEgg1 = true; @Switch( name = "Use custom GUI scale", @@ -43,6 +39,7 @@ public class Preferences extends InternalConfig { ) public static float customScale = 1f; + @Exclude private static Preferences INSTANCE; public Preferences() { diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/config/compatibility/vigilance/VigilanceConfig.java b/src/main/java/cc/polyfrost/oneconfig/internal/config/compatibility/vigilance/VigilanceConfig.java index 689bf25..87ffc47 100644 --- a/src/main/java/cc/polyfrost/oneconfig/internal/config/compatibility/vigilance/VigilanceConfig.java +++ b/src/main/java/cc/polyfrost/oneconfig/internal/config/compatibility/vigilance/VigilanceConfig.java @@ -184,13 +184,10 @@ public class VigilanceConfig extends Config { } @Override - protected void setColor(OneColor color) { - if (cachedColor != color) { - Color newColor = new Color(color.getRGB(), true); - try { - this.color.set(parent, newColor); - } catch (IllegalAccessException ignored) { - } + protected void set(Object color) throws IllegalAccessException { + if (color instanceof OneColor) { + Color newColor = ((OneColor) color).toJavaColor(); + this.color.set(parent, newColor); } } } diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/gui/HudGui.java b/src/main/java/cc/polyfrost/oneconfig/internal/gui/HudGui.java new file mode 100644 index 0000000..1710832 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/internal/gui/HudGui.java @@ -0,0 +1,269 @@ +package cc.polyfrost.oneconfig.internal.gui; + +import cc.polyfrost.oneconfig.gui.GuiPause; +import cc.polyfrost.oneconfig.gui.OneConfigGui; +import cc.polyfrost.oneconfig.hud.Hud; +import cc.polyfrost.oneconfig.hud.Position; +import cc.polyfrost.oneconfig.internal.hud.utils.GrabOffset; +import cc.polyfrost.oneconfig.internal.hud.utils.SnappingLine; +import cc.polyfrost.oneconfig.internal.config.core.ConfigCore; +import cc.polyfrost.oneconfig.internal.hud.HudCore; +import cc.polyfrost.oneconfig.libs.universal.UKeyboard; +import cc.polyfrost.oneconfig.libs.universal.UMatrixStack; +import cc.polyfrost.oneconfig.libs.universal.UResolution; +import cc.polyfrost.oneconfig.libs.universal.UScreen; +import cc.polyfrost.oneconfig.renderer.RenderManager; +import cc.polyfrost.oneconfig.utils.MathUtils; +import cc.polyfrost.oneconfig.utils.gui.GuiUtils; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.awt.*; +import java.util.ArrayList; +import java.util.HashMap; + +public class HudGui extends UScreen implements GuiPause { + private static final int SNAPPING_DISTANCE = 10; + private final HashMap<Hud, GrabOffset> editingHuds = new HashMap<>(); + private boolean isDragging; + private boolean isSelecting; + private float selectX; + private float selectY; + private boolean isScaling; + + public HudGui() { + super(); + } + + @Override + public void initScreen(int width, int height) { + HudCore.editing = true; + UKeyboard.allowRepeatEvents(true); + super.initScreen(width, height); + } + + @Override + public void onDrawScreen(@NotNull UMatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { + int lineWidth = Math.max(1, Math.round(Math.min(UResolution.getWindowWidth() / 1920f, UResolution.getWindowHeight() / 1080f))); + if (isDragging) { + RenderManager.setupAndDraw(vg -> setHudPositions(vg, mouseX, mouseY, true, true, lineWidth)); + } else if (isSelecting) { + getHudsInRegion(selectX, selectY, mouseX, mouseY); + } else if (isScaling && editingHuds.size() == 1) { + RenderManager.setupAndDraw(vg -> { + Hud hud = (Hud) editingHuds.keySet().toArray()[0]; + Position position = hud.position; + float scaleX = getXSnapping(vg, lineWidth, mouseX, position.getWidth(), false); + hud.setScale(MathUtils.clamp((scaleX - position.getX()) / (position.getWidth() / hud.getScale()), 0.3f, 10f), true); + }); + } + + float scaleFactor = (float) UResolution.getScaleFactor(); + for (Hud hud : HudCore.huds) { + if (!hud.isEnabled()) continue; + Position position = hud.position; + hud.drawAll(matrixStack, true); + if (editingHuds.containsKey(hud)) + RenderManager.setupAndDraw(true, vg -> RenderManager.drawRect(vg, position.getX(), position.getY(), position.getWidth(), position.getHeight(), new Color(0, 128, 128, 60).getRGB())); + RenderManager.setupAndDraw(vg -> { + RenderManager.drawLine(vg, position.getX() * scaleFactor - lineWidth / 2f, position.getY() * scaleFactor - lineWidth / 2f, position.getRightX() * scaleFactor + lineWidth / 2f, position.getY() * scaleFactor - lineWidth / 2f, lineWidth, new Color(255, 255, 255).getRGB()); + RenderManager.drawLine(vg, position.getX() * scaleFactor - lineWidth / 2f, position.getBottomY() * scaleFactor + lineWidth / 2f, position.getRightX() * scaleFactor + lineWidth / 2f, position.getBottomY() * scaleFactor + lineWidth / 2f, lineWidth, new Color(255, 255, 255).getRGB()); + RenderManager.drawLine(vg, position.getX() * scaleFactor - lineWidth / 2f, position.getY() * scaleFactor - lineWidth / 2f, position.getX() * scaleFactor - lineWidth / 2f, position.getBottomY() * scaleFactor + lineWidth / 2f, lineWidth, new Color(255, 255, 255).getRGB()); + RenderManager.drawLine(vg, position.getRightX() * scaleFactor + lineWidth / 2f, position.getY() * scaleFactor - lineWidth / 2f, position.getRightX() * scaleFactor + lineWidth / 2f, position.getBottomY() * scaleFactor + lineWidth / 2f, lineWidth, new Color(255, 255, 255).getRGB()); + }); + if (editingHuds.containsKey(hud) && editingHuds.size() == 1) + RenderManager.setupAndDraw(true, vg -> RenderManager.drawRect(vg, position.getRightX() - 4, position.getBottomY() - 4, 8, 8, new Color(0, 128, 128, 200).getRGB())); + } + + if (isSelecting) + RenderManager.setupAndDraw(true, vg -> RenderManager.drawRect(vg, selectX, selectY, mouseX - selectX, mouseY - selectY, new Color(0, 0, 255, 100).getRGB())); + } + + @Override + public void onMouseClicked(double mouseX, double mouseY, int mouseButton) { + super.onMouseClicked(mouseX, mouseY, mouseButton); + if (mouseButton != 0) return; + isDragging = false; + isSelecting = false; + isScaling = false; + if (editingHuds.size() == 1) { + Position position = ((Hud) editingHuds.keySet().toArray()[0]).position; + if (mouseX >= position.getRightX() - 7 && mouseX <= position.getRightX() + 7 && mouseY >= position.getBottomY() - 7 && mouseY <= position.getBottomY() + 7) { + isScaling = true; + return; + } + } + for (Hud hud : HudCore.huds) { + if (!hud.isEnabled() || !mouseClickedHud(hud, (float) mouseX, (float) mouseY)) continue; + if (!editingHuds.containsKey(hud)) { + if (!UKeyboard.isCtrlKeyDown()) editingHuds.clear(); + editingHuds.put(hud, new GrabOffset()); + } + isDragging = true; + editingHuds.forEach((hud2, grabOffset) -> grabOffset.setOffset((float) (mouseX - hud2.position.getX()), (float) (mouseY - hud2.position.getY()))); + return; + } + isSelecting = true; + selectX = (float) mouseX; + selectY = (float) mouseY; + } + + @Override + public void onMouseReleased(double mouseX, double mouseY, int state) { + isDragging = false; + isSelecting = false; + isScaling = false; + super.onMouseReleased(mouseX, mouseY, state); + } + + @Override + public void onKeyPressed(int keyCode, char typedChar, @Nullable UKeyboard.Modifiers modifiers) { + if (isDragging) return; + editingHuds.forEach((hud, grabOffset) -> grabOffset.setOffset(-hud.position.getX(), -hud.position.getY())); + if (keyCode == UKeyboard.KEY_UP) { + setHudPositions(0f, -1f, false); + } else if (keyCode == UKeyboard.KEY_DOWN) { + setHudPositions(0f, 1f, false); + } else if (keyCode == UKeyboard.KEY_LEFT) { + setHudPositions(-1f, 0f, false); + } else if (keyCode == UKeyboard.KEY_RIGHT) { + setHudPositions(1f, 0f, false); + } + super.onKeyPressed(keyCode, typedChar, modifiers); + } + + @Override + public void onScreenClose() { + super.onScreenClose(); + HudCore.editing = false; + UKeyboard.allowRepeatEvents(false); + ConfigCore.saveAll(); + GuiUtils.displayScreen(OneConfigGui.create()); + } + + @Override + public boolean doesGuiPauseGame() { + return false; + } + + private void getHudsInRegion(float x1, float y1, float x2, float y2) { + if (x1 > x2) { + float temp = x1; + x1 = x2; + x2 = temp; + } + if (y1 > y2) { + float temp = y1; + y1 = y2; + y2 = temp; + } + + editingHuds.clear(); + for (Hud hud : HudCore.huds) { + if (!hud.isEnabled()) continue; + Position pos = hud.position; + if ((x1 <= pos.getX() && x2 >= pos.getX() || x1 <= pos.getRightX() && x2 >= pos.getRightX()) + && (y1 <= pos.getY() && y2 >= pos.getY() || y1 <= pos.getBottomY() && y2 >= pos.getBottomY())) + editingHuds.put(hud, new GrabOffset()); + } + } + + private void setHudPositions(long vg, float mouseX, float mouseY, boolean snap, boolean locked, int lineWidth) { + for (Hud hud : editingHuds.keySet()) { + GrabOffset grabOffset = editingHuds.get(hud); + Position position = hud.position; + float x = mouseX - grabOffset.getX(); + float y = mouseY - grabOffset.getY(); + + if (editingHuds.size() == 1 && snap) { + x = getXSnapping(vg, lineWidth, x, position.getWidth(), true); + y = getYSnapping(vg, lineWidth, y, position.getHeight(), true); + } + + if (locked) { + if (x < 0) x = 0; + else if (x + position.getWidth() > UResolution.getScaledWidth()) + x = UResolution.getScaledWidth() - position.getWidth(); + if (y < 0) y = 0; + else if (y + position.getHeight() > UResolution.getScaledHeight()) + y = UResolution.getScaledHeight() - position.getHeight(); + } + + position.setPosition(x, y); + } + } + + private void setHudPositions(float mouseX, float mouseY, boolean locked) { + setHudPositions(0, mouseX, mouseY, false, locked, 0); + } + + private boolean mouseClickedHud(Hud hud, float mouseX, float mouseY) { + Position position = hud.position; + return mouseX >= position.getX() && mouseX <= position.getRightX() && + mouseY >= position.getY() && mouseY <= position.getBottomY(); + } + + private float getXSnapping(long vg, float lineWidth, float x, float width, boolean multipleSides) { + ArrayList<Float> lines = getXSnappingLines(); + ArrayList<SnappingLine> snappingLines = new ArrayList<>(); + float closest = (float) (SNAPPING_DISTANCE / UResolution.getScaleFactor()); + for (Float line : lines) { + SnappingLine snappingLine = new SnappingLine(line, x, width, multipleSides); + if (Math.round(snappingLine.getDistance()) == Math.round(closest)) snappingLines.add(snappingLine); + else if (snappingLine.getDistance() < closest) { + closest = snappingLine.getDistance(); + snappingLines.clear(); + snappingLines.add(snappingLine); + } + } + if (snappingLines.isEmpty()) return x; + for (SnappingLine snappingLine : snappingLines) { + snappingLine.drawLine(vg, lineWidth, true); + } + return snappingLines.get(0).getPosition(); + } + + private ArrayList<Float> getXSnappingLines() { + ArrayList<Float> lines = new ArrayList<>(); + lines.add(UResolution.getScaledWidth() / 2f); + for (Hud hud : HudCore.huds) { + if (!hud.isEnabled() || editingHuds.containsKey(hud)) continue; + lines.add(hud.position.getX()); + lines.add(hud.position.getCenterX()); + lines.add(hud.position.getRightX()); + } + return lines; + } + + private float getYSnapping(long vg, float lineWidth, float y, float height, boolean multipleSides) { + ArrayList<Float> lines = getYSnappingLines(); + ArrayList<SnappingLine> snappingLines = new ArrayList<>(); + float closest = (float) (SNAPPING_DISTANCE / UResolution.getScaleFactor()); + for (Float line : lines) { + SnappingLine snappingLine = new SnappingLine(line, y, height, multipleSides); + if (Math.round(snappingLine.getDistance()) == Math.round(closest)) snappingLines.add(snappingLine); + else if (snappingLine.getDistance() < closest) { + closest = snappingLine.getDistance(); + snappingLines.clear(); + snappingLines.add(snappingLine); + } + } + if (snappingLines.isEmpty()) return y; + for (SnappingLine snappingLine : snappingLines) { + snappingLine.drawLine(vg, lineWidth, false); + } + return snappingLines.get(0).getPosition(); + } + + private ArrayList<Float> getYSnappingLines() { + ArrayList<Float> lines = new ArrayList<>(); + lines.add(UResolution.getScaledHeight() / 2f); + for (Hud hud : HudCore.huds) { + if (!hud.isEnabled() || editingHuds.containsKey(hud)) continue; + lines.add(hud.position.getY()); + lines.add(hud.position.getCenterY()); + lines.add(hud.position.getBottomY()); + } + return lines; + } +}
\ No newline at end of file diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java b/src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java index 31604ed..812a8e4 100644 --- a/src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java +++ b/src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java @@ -16,7 +16,7 @@ public class HudCore { if (editing) return; for (Hud hud : huds) { if (!hud.isEnabled()) continue; - hud.drawAll(event.matrices, hud.getXScaled(UResolution.getScaledWidth()), hud.getYScaled(UResolution.getScaledHeight()), hud.scale, true); + hud.drawAll(event.matrices, false); } } } diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/hud/utils/GrabOffset.java b/src/main/java/cc/polyfrost/oneconfig/internal/hud/utils/GrabOffset.java new file mode 100644 index 0000000..122ff77 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/internal/hud/utils/GrabOffset.java @@ -0,0 +1,27 @@ +package cc.polyfrost.oneconfig.internal.hud.utils; + +public class GrabOffset { + private float offsetX; + private float offsetY; + + public GrabOffset(float offsetX, float offsetY) { + setOffset(offsetX, offsetY); + } + + public GrabOffset() { + this(0, 0); + } + + public void setOffset(float offsetX, float offsetY) { + this.offsetX = offsetX; + this.offsetY = offsetY; + } + + public float getX() { + return offsetX; + } + + public float getY() { + return offsetY; + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/hud/utils/SnappingLine.java b/src/main/java/cc/polyfrost/oneconfig/internal/hud/utils/SnappingLine.java new file mode 100644 index 0000000..2a89e1f --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/internal/hud/utils/SnappingLine.java @@ -0,0 +1,49 @@ +package cc.polyfrost.oneconfig.internal.hud.utils; + +import cc.polyfrost.oneconfig.libs.universal.UResolution; +import cc.polyfrost.oneconfig.renderer.RenderManager; + +import java.awt.*; + +public class SnappingLine { + private static final int COLOR = new Color(138, 43, 226).getRGB(); + private final float line; + private final float distance; + private final float position; + + public SnappingLine(float line, float left, float size, boolean multipleSides) { + this.line = line; + float center = left + size / 2f; + float right = left + size; + float leftDistance = Math.abs(line - left); + float centerDistance = Math.abs(line - center); + float rightDistance = Math.abs(line - right); + if (!multipleSides || leftDistance <= centerDistance && leftDistance <= rightDistance) { + distance = leftDistance; + position = line; + } else if (centerDistance <= rightDistance) { + distance = centerDistance; + position = line - size / 2f; + } else { + distance = rightDistance; + position = line - size; + } + } + + public void drawLine(long vg, float lineWidth, boolean isX) { + float pos = (float) (line * UResolution.getScaleFactor() - lineWidth / 2f); + if (isX) { + RenderManager.drawLine(vg, pos, 0, pos, UResolution.getWindowHeight(), lineWidth, COLOR); + } else { + RenderManager.drawLine(vg, 0, pos, UResolution.getWindowWidth(), pos, lineWidth, COLOR); + } + } + + public float getPosition() { + return position; + } + + public float getDistance() { + return distance; + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/init/OneConfigInit.java b/src/main/java/cc/polyfrost/oneconfig/internal/init/OneConfigInit.java index 1f70815..60480a2 100644 --- a/src/main/java/cc/polyfrost/oneconfig/internal/init/OneConfigInit.java +++ b/src/main/java/cc/polyfrost/oneconfig/internal/init/OneConfigInit.java @@ -2,10 +2,15 @@ package cc.polyfrost.oneconfig.internal.init; import org.spongepowered.asm.mixin.Mixins; +import java.io.File; + @SuppressWarnings("unused") public class OneConfigInit { public static void initialize(String[] args) { Mixins.addConfiguration("mixins.oneconfig.json"); + final File oneConfigDir = new File("./OneConfig"); + oneConfigDir.mkdirs(); + new File(oneConfigDir, "profiles").mkdirs(); } } diff --git a/src/main/java/cc/polyfrost/oneconfig/platform/NanoVGPlatform.java b/src/main/java/cc/polyfrost/oneconfig/platform/NanoVGPlatform.java new file mode 100644 index 0000000..af269ce --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/platform/NanoVGPlatform.java @@ -0,0 +1,42 @@ +package cc.polyfrost.oneconfig.platform; + +import org.jetbrains.annotations.Nullable; +import org.lwjgl.nanovg.NVGLUFramebuffer; + +public interface NanoVGPlatform { + int NVG_ANTIALIAS = 1; + int NVG_STENCIL_STROKES = 2; + int NVG_DEBUG = 4; + int NVG_IMAGE_NODELETE = 65536; + + int nnvglCreateImageFromHandle(long var0, int var2, int var3, int var4, int var5); + + int nvglCreateImageFromHandle(long ctx, int textureId, int w, int h, int flags); + + int nnvglImageHandle(long var0, int var2); + + int nvglImageHandle(long ctx, int image); + + long nnvgCreate(int var0); + + long nvgCreate(int flags); + + void nnvgDelete(long var0); + + void nvgDelete(long ctx); + + long nnvgluCreateFramebuffer(long var0, int var2, int var3, int var4); + + @Nullable + NVGLUFramebuffer nvgluCreateFramebuffer(long ctx, int w, int h, int imageFlags); + + void nnvgluBindFramebuffer(long var0, long var2); + + void nvgluBindFramebuffer(long ctx, @Nullable NVGLUFramebuffer fb); + + void nnvgluDeleteFramebuffer(long var0, long var2); + + void nvgluDeleteFramebuffer(long ctx, NVGLUFramebuffer fb); + + void triggerStaticInitialization(); +} diff --git a/src/main/java/cc/polyfrost/oneconfig/platform/Platform.java b/src/main/java/cc/polyfrost/oneconfig/platform/Platform.java index 62e9e2a..0fc2626 100644 --- a/src/main/java/cc/polyfrost/oneconfig/platform/Platform.java +++ b/src/main/java/cc/polyfrost/oneconfig/platform/Platform.java @@ -37,10 +37,16 @@ public interface Platform { return PlatformHolder.INSTANCE.i18nPlatform; } + static NanoVGPlatform getNanoVGPlatform() { + return PlatformHolder.INSTANCE.nvgPlatform; + } + boolean isCallingFromMinecraftThread(); int getMinecraftVersion(); + Loader getLoader(); + class PlatformHolder { private PlatformHolder() { @@ -53,5 +59,12 @@ public interface Platform { GLPlatform glPlatform = ServiceLoader.load(GLPlatform.class, GLPlatform.class.getClassLoader()).iterator().next(); GuiPlatform guiPlatform = ServiceLoader.load(GuiPlatform.class, GuiPlatform.class.getClassLoader()).iterator().next(); I18nPlatform i18nPlatform = ServiceLoader.load(I18nPlatform.class, I18nPlatform.class.getClassLoader()).iterator().next(); + + NanoVGPlatform nvgPlatform = ServiceLoader.load(NanoVGPlatform.class, NanoVGPlatform.class.getClassLoader()).iterator().next(); + } + + enum Loader { + FORGE, + FABRIC } } diff --git a/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java b/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java index 93c3c94..5f8ea11 100644 --- a/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java +++ b/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java @@ -7,6 +7,7 @@ import cc.polyfrost.oneconfig.internal.assets.Images; import cc.polyfrost.oneconfig.internal.assets.SVGs; import cc.polyfrost.oneconfig.libs.universal.UGraphics; import cc.polyfrost.oneconfig.libs.universal.UResolution; +import cc.polyfrost.oneconfig.platform.NanoVGPlatform; import cc.polyfrost.oneconfig.platform.Platform; import cc.polyfrost.oneconfig.renderer.font.Font; import cc.polyfrost.oneconfig.renderer.font.FontManager; @@ -14,7 +15,6 @@ import cc.polyfrost.oneconfig.utils.InputUtils; import cc.polyfrost.oneconfig.utils.NetworkUtils; import org.lwjgl.nanovg.NVGColor; import org.lwjgl.nanovg.NVGPaint; -import org.lwjgl.nanovg.NanoVGGL2; import org.lwjgl.opengl.GL11; import java.util.function.LongConsumer; @@ -52,7 +52,7 @@ public final class RenderManager { */ public static void setupAndDraw(boolean mcScaling, LongConsumer consumer) { if (vg == -1) { - vg = NanoVGGL2.nvgCreate(NanoVGGL2.NVG_ANTIALIAS); + vg = Platform.getNanoVGPlatform().nvgCreate(NanoVGPlatform.NVG_ANTIALIAS); if (vg == -1) { throw new RuntimeException("Failed to create nvg context"); } @@ -86,24 +86,6 @@ public final class RenderManager { * @param height The height. * @param color The color. */ - public static void drawRectangle(long vg, float x, float y, float width, float height, int color) { // TODO make everything use this one day - if (Colors.ROUNDED_CORNERS) { - drawRoundedRect(vg, x, y, width, height, color, Colors.CORNER_RADIUS); - } else { - drawRect(vg, x, y, width, height, color); - } - } - - /** - * Draws a rectangle with the given parameters. - * - * @param vg The NanoVG context. - * @param x The x position. - * @param y The y position. - * @param width The width. - * @param height The height. - * @param color The color. - */ public static void drawRect(long vg, float x, float y, float width, float height, int color) { nvgBeginPath(vg); nvgRect(vg, x, y, width, height); @@ -330,12 +312,12 @@ public final class RenderManager { * <p><b>This does NOT scale to Minecraft's GUI scale!</b></p> * * @see RenderManager#drawText(long, String, float, float, int, float, Font) - * @see InputUtils#isAreaClicked(int, int, int, int) + * @see InputUtils#isAreaClicked(float, float, float, float) */ public static void drawURL(long vg, String url, float x, float y, float size, Font font) { drawText(vg, url, x, y, Colors.PRIMARY_500, size, font); float length = getTextWidth(vg, url, size, font); - drawRectangle(vg, x, y + size / 2, length, 1, Colors.PRIMARY_500); + drawRect(vg, x, y + size / 2, length, 1, Colors.PRIMARY_500); if (InputUtils.isAreaClicked((int) (x - 2), (int) (y - 1), (int) (length + 4), (int) (size / 2 + 3))) { NetworkUtils.browseLink(url); } @@ -723,7 +705,7 @@ public final class RenderManager { Platform.getGLPlatform().drawText(text, x * (1 / scale), y * (1 / scale), color, true); break; case FULL: - drawBorderedText(text, x, y, color, 100); + drawBorderedText(text, x * (1 / scale), y * (1 / scale), color, 100); break; } UGraphics.GL.popMatrix(); diff --git a/src/main/java/cc/polyfrost/oneconfig/renderer/TextRenderer.java b/src/main/java/cc/polyfrost/oneconfig/renderer/TextRenderer.java index 95071d1..ed77942 100644 --- a/src/main/java/cc/polyfrost/oneconfig/renderer/TextRenderer.java +++ b/src/main/java/cc/polyfrost/oneconfig/renderer/TextRenderer.java @@ -122,12 +122,12 @@ public class TextRenderer { * <p><b>This does NOT scale to Minecraft's GUI scale!</b></p> * * @see RenderManager#drawText(long, String, float, float, int, float, Font) - * @see InputUtils#isAreaClicked(int, int, int, int) + * @see InputUtils#isAreaClicked(float, float, float, float) */ public static void drawURL(long vg, String url, float x, float y, float size, Font font) { drawText(vg, url, x, y, Colors.PRIMARY_500, size, font); float length = getTextWidth(vg, url, size, font); - RenderManager.drawRectangle(vg, x, y + size / 2, length, 1, Colors.PRIMARY_500); + RenderManager.drawRect(vg, x, y + size / 2, length, 1, Colors.PRIMARY_500); if (InputUtils.isAreaClicked((int) (x - 2), (int) (y - 1), (int) (length + 4), (int) (size / 2 + 3))) { NetworkUtils.browseLink(url); } diff --git a/src/main/java/cc/polyfrost/oneconfig/renderer/scissor/Scissor.java b/src/main/java/cc/polyfrost/oneconfig/renderer/scissor/Scissor.java index 62854ef..7ced323 100644 --- a/src/main/java/cc/polyfrost/oneconfig/renderer/scissor/Scissor.java +++ b/src/main/java/cc/polyfrost/oneconfig/renderer/scissor/Scissor.java @@ -25,7 +25,7 @@ public class Scissor { this.height = scissor.height; } - public boolean isInScissor(int x, int y) { + public boolean isInScissor(float x, float y) { return x >= this.x && x <= this.x + this.width && y >= this.y && y <= this.y + this.height; } } diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java index 6582eaa..9466841 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java @@ -22,9 +22,9 @@ public final class InputUtils { * * @return true if mouse is over region, false if not. */ - public static boolean isAreaHovered(int x, int y, int width, int height, boolean ignoreBlock) { - int mouseX = mouseX(); - int mouseY = mouseY(); + public static boolean isAreaHovered(float x, float y, float width, float height, boolean ignoreBlock) { + float mouseX = mouseX(); + float mouseY = mouseY(); return (ignoreBlock || blockScissors.size() == 0 || !shouldBlock(mouseX, mouseY)) && mouseX > x && mouseY > y && mouseX < x + width && mouseY < y + height; } @@ -33,7 +33,7 @@ public final class InputUtils { * * @return true if mouse is over region, false if not. */ - public static boolean isAreaHovered(int x, int y, int width, int height) { + public static boolean isAreaHovered(float x, float y, float width, float height) { return isAreaHovered(x, y, width, height, false); } @@ -46,9 +46,9 @@ public final class InputUtils { * @param height the height of the region * @param ignoreBlock if true, will ignore * @return true if the mouse is clicked and is over the region, false if not - * @see InputUtils#isAreaHovered(int, int, int, int) + * @see InputUtils#isAreaHovered(float, float, float, float) */ - public static boolean isAreaClicked(int x, int y, int width, int height, boolean ignoreBlock) { + public static boolean isAreaClicked(float x, float y, float width, float height, boolean ignoreBlock) { return isAreaHovered(x, y, width, height, ignoreBlock) && isClicked(false); } @@ -60,9 +60,9 @@ public final class InputUtils { * @param width the width of the region * @param height the height of the region * @return true if the mouse is clicked and is over the region, false if not - * @see InputUtils#isAreaClicked(int, int, int, int, boolean) + * @see InputUtils#isAreaClicked(float, float, float, float, boolean) */ - public static boolean isAreaClicked(int x, int y, int width, int height) { + public static boolean isAreaClicked(float x, float y, float width, float height) { return isAreaClicked(x, y, width, height, false); } @@ -95,9 +95,9 @@ public final class InputUtils { * * @return the current mouse X position */ - public static int mouseX() { - if (OneConfigGui.INSTANCE == null) return (int) Platform.getMousePlatform().getMouseX(); //todo stop casting and actually use doubles - return (int) (Platform.getMousePlatform().getMouseX() / OneConfigGui.INSTANCE.getScaleFactor()); + public static float mouseX() { + if (OneConfigGui.INSTANCE == null) return (float) Platform.getMousePlatform().getMouseX(); + return (float) (Platform.getMousePlatform().getMouseX() / OneConfigGui.INSTANCE.getScaleFactor()); } /** @@ -109,9 +109,9 @@ public final class InputUtils { * * @return the current mouse Y position */ - public static int mouseY() { - if (OneConfigGui.INSTANCE == null) return (int) (UResolution.getWindowHeight() - Math.abs(Platform.getMousePlatform().getMouseY())); - return (int) ((UResolution.getWindowHeight() - Math.abs(Platform.getMousePlatform().getMouseY())) / OneConfigGui.INSTANCE.getScaleFactor()); + public static float mouseY() { + if (OneConfigGui.INSTANCE == null) return (float) (UResolution.getWindowHeight() - Math.abs(Platform.getMousePlatform().getMouseY())); + return (float) ((UResolution.getWindowHeight() - Math.abs(Platform.getMousePlatform().getMouseY())) / OneConfigGui.INSTANCE.getScaleFactor()); } /** @@ -122,7 +122,7 @@ public final class InputUtils { * @param width Width * @param height Height */ - public static Scissor blockInputArea(int x, int y, int width, int height) { + public static Scissor blockInputArea(float x, float y, float width, float height) { Scissor scissor = new Scissor(new Scissor(x, y, width, height)); blockScissors.add(scissor); return scissor; @@ -160,7 +160,7 @@ public final class InputUtils { return blockScissors.size() > 0; } - private static boolean shouldBlock(int x, int y) { + private static boolean shouldBlock(float x, float y) { for (Scissor block : blockScissors) { if (block.isInScissor(x, y)) return true; } diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/commands/CommandManager.java b/src/main/java/cc/polyfrost/oneconfig/utils/commands/CommandManager.java index 16a2f8d..14a40c1 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/commands/CommandManager.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/commands/CommandManager.java @@ -1,5 +1,6 @@ package cc.polyfrost.oneconfig.utils.commands; +import cc.polyfrost.oneconfig.libs.universal.ChatColor; import cc.polyfrost.oneconfig.utils.commands.annotations.Command; import cc.polyfrost.oneconfig.utils.commands.annotations.Main; import cc.polyfrost.oneconfig.utils.commands.annotations.SubCommand; @@ -63,7 +64,8 @@ public class CommandManager { if (clazz.isAnnotationPresent(Command.class)) { final Command annotation = clazz.getAnnotation(Command.class); - final InternalCommand root = new InternalCommand(annotation.value(), annotation.aliases(), annotation.description().trim().isEmpty() ? "Main command for " + annotation.value() : annotation.description(), null); + final InternalCommand root = new InternalCommand(annotation.value(), annotation.aliases(), annotation.description().trim().isEmpty() + ? "Main command for " + annotation.value() : annotation.description(), annotation.color(), null); for (Method method : clazz.getDeclaredMethods()) { if (method.isAnnotationPresent(Main.class) && method.getParameterCount() == 0) { root.invokers.add(new InternalCommand.InternalCommandInvoker(annotation.value(), annotation.aliases(), method, root)); @@ -79,7 +81,7 @@ public class CommandManager { for (Class<?> clazz : classes) { if (clazz.isAnnotationPresent(SubCommand.class)) { SubCommand annotation = clazz.getAnnotation(SubCommand.class); - InternalCommand command = new InternalCommand(annotation.value(), annotation.aliases(), annotation.description(), parent); + InternalCommand command = new InternalCommand(annotation.value(), annotation.aliases(), annotation.description(), annotation.color() == ChatColor.RESET ? parent.color : annotation.color(), parent); for (Method method : clazz.getDeclaredMethods()) { if (method.isAnnotationPresent(Main.class)) { command.invokers.add(new InternalCommand.InternalCommandInvoker(annotation.value(), annotation.aliases(), method, command)); @@ -103,15 +105,17 @@ public class CommandManager { public final String name; public final String[] aliases; public final String description; + public final ChatColor color; public final ArrayList<InternalCommandInvoker> invokers = new ArrayList<>(); public final InternalCommand parent; public final ArrayList<InternalCommand> children = new ArrayList<>(); - public InternalCommand(String name, String[] aliases, String description, InternalCommand parent) { + public InternalCommand(String name, String[] aliases, String description, ChatColor color, InternalCommand parent) { this.name = name; this.aliases = aliases; this.description = description; this.parent = parent; + this.color = color; } public boolean isValid(String name, boolean tabCompletion) { diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/commands/PlatformCommandManager.java b/src/main/java/cc/polyfrost/oneconfig/utils/commands/PlatformCommandManager.java index 1ab356c..617694c 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/commands/PlatformCommandManager.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/commands/PlatformCommandManager.java @@ -13,18 +13,19 @@ public abstract class PlatformCommandManager { //TODO: someone make the help command actually look nice lmao protected String sendHelpCommand(CommandManager.InternalCommand root) { StringBuilder builder = new StringBuilder(); - builder.append(ChatColor.GOLD).append("Help for ").append(ChatColor.BOLD).append(root.name).append(ChatColor.RESET).append(ChatColor.GOLD).append(":\n"); - if (!root.description.isEmpty()) { - builder.append("\n").append(ChatColor.GOLD).append("Description: ").append(ChatColor.BOLD).append(root.description); - } - for (CommandManager.InternalCommand command : root.children) { - runThroughCommandsHelp(root.name, command, builder); - } - builder.append("\n").append(ChatColor.GOLD).append("Aliases: ").append(ChatColor.BOLD); + builder.append(root.color).append("Help for ").append(ChatColor.BOLD).append(root.name).append(ChatColor.RESET).append(root.color); int index = 0; for (String alias : root.aliases) { + if(index == 0) builder.append(" ("); ++index; - builder.append(alias).append(index < root.aliases.length ? ", " : ""); + builder.append("/").append(alias).append(index < root.aliases.length ? ", " : ")"); + } + builder.append(":\n"); + if (!root.description.isEmpty()) { + builder.append("\n").append(root.color).append("/").append(root.name).append(": ").append(ChatColor.BOLD).append(root.description); + } + for (CommandManager.InternalCommand command : root.children) { + runThroughCommandsHelp(root.name, command, builder); } builder.append("\n"); return builder.toString(); @@ -36,12 +37,12 @@ public abstract class PlatformCommandManager { if (declaringClass.isAnnotationPresent(SubCommand.class)) { String description = declaringClass.getAnnotation(SubCommand.class).description(); if (!description.isEmpty()) { - builder.append("\n").append(ChatColor.GOLD).append("Description: ").append(ChatColor.BOLD).append(description); + builder.append("\n"); } } } for (CommandManager.InternalCommand.InternalCommandInvoker invoker : command.invokers) { - builder.append("\n").append(ChatColor.GOLD).append("/").append(append).append(" ").append(command.name); + builder.append("\n").append(command.color).append("/").append(append).append(" ").append(command.name); for (Parameter parameter : invoker.method.getParameters()) { String name = parameter.getName(); if (parameter.isAnnotationPresent(Name.class)) { @@ -49,8 +50,14 @@ public abstract class PlatformCommandManager { } builder.append(" <").append(name).append(">"); } + int index = 0; + for (String alias : command.aliases) { + if(index == 0) builder.append(" ("); + ++index; + builder.append(alias).append(index < command.aliases.length ? ", " : ")"); + } if (!command.description.trim().isEmpty()) { - builder.append(": ").append(ChatColor.BOLD).append(command.description); + builder.append(": ").append(ChatColor.BOLD).append(command.color).append(command.description); } } for (CommandManager.InternalCommand subCommand : command.children) { diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/Command.java b/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/Command.java index 41909c0..2bbf0bd 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/Command.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/Command.java @@ -1,6 +1,7 @@ package cc.polyfrost.oneconfig.utils.commands.annotations; import cc.polyfrost.oneconfig.internal.command.OneConfigCommand; +import cc.polyfrost.oneconfig.libs.universal.ChatColor; import cc.polyfrost.oneconfig.utils.commands.CommandManager; import cc.polyfrost.oneconfig.utils.commands.arguments.ArgumentParser; @@ -108,6 +109,13 @@ public @interface Command { String description() default ""; /** + * The color of the command. + * + * @return The color of the command. + */ + ChatColor color() default ChatColor.GOLD; + + /** * Whether the command generates a help command. */ boolean helpCommand() default true; diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/SubCommand.java b/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/SubCommand.java index 1bfbd53..eddca3c 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/SubCommand.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/SubCommand.java @@ -1,5 +1,7 @@ package cc.polyfrost.oneconfig.utils.commands.annotations; +import cc.polyfrost.oneconfig.libs.universal.ChatColor; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -34,4 +36,11 @@ public @interface SubCommand { * @return The description of the command. */ String description() default ""; + + /** + * The color of the command. + * + * @return The color of the command. + */ + ChatColor color() default ChatColor.RESET; } diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/gui/GuiUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/gui/GuiUtils.java index 63203e4..969654e 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/gui/GuiUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/gui/GuiUtils.java @@ -24,7 +24,6 @@ public final class GuiUtils { * Displays a screen after a tick, preventing mouse sync issues. * * @param screen the screen to display. - * @deprecated Not actually deprecated, but should not be used. */ @Deprecated public static void displayScreen(Object screen) { diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/gui/OneUIScreen.java b/src/main/java/cc/polyfrost/oneconfig/utils/gui/OneUIScreen.java index 2dd961e..6a64251 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/gui/OneUIScreen.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/gui/OneUIScreen.java @@ -37,16 +37,12 @@ public abstract class OneUIScreen extends UScreen implements GuiPause { } @Override - public void onDrawScreen(@NotNull UMatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { + public final void onDrawScreen(@NotNull UMatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { super.onDrawScreen(matrixStack, mouseX, mouseY, partialTicks); RenderManager.setupAndDraw(ignoreMinecraftScale(), vg -> draw(vg, partialTicks)); mouseDown = Platform.getMousePlatform().isButtonDown(0); } - /** - * This method is called when the screen is first opened. You can use it to set variables, initialize things, etc. - */ - public abstract void onScreenOpen(); /** * Use this method to draw things on the screen. It is called every render tick, and has a handy <code>vg</code> (NanoVG context) that can be used with the {@link RenderManager} to draw things. @@ -59,18 +55,7 @@ public abstract class OneUIScreen extends UScreen implements GuiPause { public abstract void draw(long vg, float partialTicks); /** - * This method is called when the screen is closed. You can use it to clean up things, etc. - */ - @Override - public abstract void onScreenClose(); - - @Override - public void initScreen(int width, int height) { - onScreenOpen(); - } - - /** - * Use this method to set weather or not to use the Minecraft scale on the GUI. Its default is true, and that is recommended for the NanoVG rendering. + * Use this method to set whether to use the Minecraft scale on the GUI. Its default is true, and that is recommended for the NanoVG rendering. */ public boolean ignoreMinecraftScale() { return true; @@ -79,42 +64,37 @@ public abstract class OneUIScreen extends UScreen implements GuiPause { /** * Get the current x position of the mouse. */ - public int getMouseX() { + protected float getMouseX() { return InputUtils.mouseX(); } /** * Get the current y position of the mouse. */ - public int getMouseY() { + protected float getMouseY() { return InputUtils.mouseY(); } - @Override - public void onMouseClicked(double mouseX, double mouseY, int mouseButton) { - super.onMouseClicked(mouseX, mouseY, mouseButton); - } - /** * Retrieve the click status of the mouse. This method uses a boolean to store the status of the mouse, so it will only return true once per click. (very useful) * * @param ignoreBlockClicks whether to ignore the current click blocker. */ - public boolean isClicked(boolean ignoreBlockClicks) { + protected boolean isClicked(boolean ignoreBlockClicks) { return mouseDown && !Platform.getMousePlatform().isButtonDown(0) && (!blockClicks || ignoreBlockClicks); } /** * Retrieve the click status of the mouse. This method uses a boolean to store the status of the mouse, so it will only return true once per click. (very useful) */ - public boolean isClicked() { + protected boolean isClicked() { return isClicked(false); } /** * Retrieve weather or not the mouse is currently down. Will constantly return true if its clicked. See {@link #isClicked()} for a method that only executes once per tick. */ - public boolean isMouseDown() { + protected boolean isMouseDown() { return Platform.getMousePlatform().isButtonDown(0); } @@ -131,4 +111,9 @@ public abstract class OneUIScreen extends UScreen implements GuiPause { public boolean isBlockingClicks() { return blockClicks; } + + @Override + public boolean doesGuiPauseGame() { + return false; + } } diff --git a/src/main/resources/assets/oneconfig/textures/entity/pig/technocrown.png b/src/main/resources/assets/oneconfig/textures/entity/pig/technocrown.png Binary files differdeleted file mode 100644 index b04b745..0000000 --- a/src/main/resources/assets/oneconfig/textures/entity/pig/technocrown.png +++ /dev/null diff --git a/versions/1.12.2-1.16.2.txt b/versions/1.12.2-1.16.2.txt index 5d0f09b..68a6805 100644 --- a/versions/1.12.2-1.16.2.txt +++ b/versions/1.12.2-1.16.2.txt @@ -27,4 +27,6 @@ org.spongepowered.asm.lib.tree.FieldInsnNode org.objectweb.asm.tree.FieldInsnNod org.spongepowered.asm.lib.tree.MethodInsnNode org.objectweb.asm.tree.MethodInsnNode org.spongepowered.asm.lib.tree.InsnList org.objectweb.asm.tree.InsnList org.spongepowered.asm.lib.tree.InsnNode org.objectweb.asm.tree.InsnNode -org.spongepowered.asm.lib.tree.JumpInsnNode org.objectweb.asm.tree.JumpInsnNode
\ No newline at end of file +org.spongepowered.asm.lib.tree.JumpInsnNode org.objectweb.asm.tree.JumpInsnNode + +org.lwjgl.nanovg.NanoVGGL2 org.lwjgl.nanovg.NanoVGGL3
\ No newline at end of file diff --git a/versions/1.12.2-forge/api/1.12.2-forge.api b/versions/1.12.2-forge/api/1.12.2-forge.api index b073db3..a948ea0 100644 --- a/versions/1.12.2-forge/api/1.12.2-forge.api +++ b/versions/1.12.2-forge/api/1.12.2-forge.api @@ -64,8 +64,28 @@ public class cc/polyfrost/oneconfig/platform/impl/MousePlatformImpl : cc/polyfro public fun isButtonDown (I)Z } +public class cc/polyfrost/oneconfig/platform/impl/NanoVGPlatformImpl : cc/polyfrost/oneconfig/platform/NanoVGPlatform { + public fun <init> ()V + public fun nnvgCreate (I)J + public fun nnvgDelete (J)V + public fun nnvglCreateImageFromHandle (JIIII)I + public fun nnvglImageHandle (JI)I + public fun nnvgluBindFramebuffer (JJ)V + public fun nnvgluCreateFramebuffer (JIII)J + public fun nnvgluDeleteFramebuffer (JJ)V + public fun nvgCreate (I)J + public fun nvgDelete (J)V + public fun nvglCreateImageFromHandle (JIIII)I + public fun nvglImageHandle (JI)I + public fun nvgluBindFramebuffer (JLorg/lwjgl/nanovg/NVGLUFramebuffer;)V + public fun nvgluCreateFramebuffer (JIII)Lorg/lwjgl/nanovg/NVGLUFramebuffer; + public fun nvgluDeleteFramebuffer (JLorg/lwjgl/nanovg/NVGLUFramebuffer;)V + public fun triggerStaticInitialization ()V +} + public class cc/polyfrost/oneconfig/platform/impl/PlatformImpl : cc/polyfrost/oneconfig/platform/Platform { public fun <init> ()V + public fun getLoader ()Lcc/polyfrost/oneconfig/platform/Platform$Loader; public fun getMinecraftVersion ()I public fun isCallingFromMinecraftThread ()Z } diff --git a/versions/1.12.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java b/versions/1.12.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java index 9492238..e318ba1 100644 --- a/versions/1.12.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java +++ b/versions/1.12.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java @@ -32,11 +32,6 @@ public class MinecraftMixin { Runtime.getRuntime().addShutdownHook(new Thread(() -> EventManager.INSTANCE.post(new ShutdownEvent()))); } - @Inject(method = "init", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/client/FMLClientHandler;beginMinecraftLoading(Lnet/minecraft/client/Minecraft;Ljava/util/List;Lnet/minecraft/client/resources/IReloadableResourceManager;Lnet/minecraft/client/resources/data/MetadataSerializer;)V", remap = false), remap = true) - private void onPreLaunch(CallbackInfo ci) { - OneConfig.preLaunch(); - } - @Inject(method = "init", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/client/FMLClientHandler;onInitializationComplete()V", shift = At.Shift.AFTER, remap = false), remap = true) private void onInit(CallbackInfo ci) { EventManager.INSTANCE.post(new InitializationEvent()); diff --git a/versions/1.16.2-fabric/api/1.16.2-fabric.api b/versions/1.16.2-fabric/api/1.16.2-fabric.api new file mode 100644 index 0000000..51e5d73 --- /dev/null +++ b/versions/1.16.2-fabric/api/1.16.2-fabric.api @@ -0,0 +1,122 @@ +public class cc/polyfrost/oneconfig/events/event/ChatReceiveEvent : cc/polyfrost/oneconfig/events/event/CancellableEvent { + public final field message Lnet/minecraft/text/Text; + public fun <init> (Lnet/minecraft/text/Text;)V + public fun getFullyUnformattedMessage ()Ljava/lang/String; +} + +public class cc/polyfrost/oneconfig/events/event/ReceivePacketEvent : cc/polyfrost/oneconfig/events/event/CancellableEvent { + public final field packet Lnet/minecraft/network/Packet; + public fun <init> (Lnet/minecraft/network/Packet;)V +} + +public class cc/polyfrost/oneconfig/events/event/ScreenOpenEvent : cc/polyfrost/oneconfig/events/event/CancellableEvent { + public final field screen Lnet/minecraft/client/gui/screen/Screen; + public fun <init> (Lnet/minecraft/client/gui/screen/Screen;)V +} + +public class cc/polyfrost/oneconfig/events/event/SendPacketEvent : cc/polyfrost/oneconfig/events/event/CancellableEvent { + public final field packet Lnet/minecraft/network/Packet; + public fun <init> (Lnet/minecraft/network/Packet;)V +} + +public class cc/polyfrost/oneconfig/events/event/TimerUpdateEvent { + public final field timer Lnet/minecraft/client/render/RenderTickCounter; + public final field updatedDeltaTicks Z + public fun <init> (Lnet/minecraft/client/render/RenderTickCounter;Z)V +} + +public class cc/polyfrost/oneconfig/platform/impl/GLPlatformImpl : cc/polyfrost/oneconfig/platform/GLPlatform { + public fun <init> ()V + public fun drawRect (FFFFI)V + public fun drawText (Lcc/polyfrost/oneconfig/libs/universal/UMatrixStack;Ljava/lang/String;FFIZ)F + public fun enableStencil ()V + public fun getStringWidth (Ljava/lang/String;)I +} + +public class cc/polyfrost/oneconfig/platform/impl/GuiPlatformImpl : cc/polyfrost/oneconfig/platform/GuiPlatform { + public fun <init> ()V + public fun getCurrentScreen ()Ljava/lang/Object; + public fun isInChat ()Z + public fun isInDebug ()Z + public fun setCurrentScreen (Ljava/lang/Object;)V +} + +public class cc/polyfrost/oneconfig/platform/impl/I18nPlatformImpl : cc/polyfrost/oneconfig/platform/I18nPlatform { + public fun <init> ()V + public fun format (Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String; +} + +public class cc/polyfrost/oneconfig/platform/impl/LoaderPlatformImpl : cc/polyfrost/oneconfig/platform/LoaderPlatform { + public fun <init> ()V + public fun getActiveModContainer ()Lcc/polyfrost/oneconfig/platform/LoaderPlatform$ActiveMod; + public fun hasActiveModContainer ()Z + public fun isModLoaded (Ljava/lang/String;)Z +} + +public class cc/polyfrost/oneconfig/platform/impl/MousePlatformImpl : cc/polyfrost/oneconfig/platform/MousePlatform { + public fun <init> ()V + public fun getButtonState (I)I + public fun getDWheel ()D + public fun getMouseDX ()D + public fun getMouseDY ()D + public fun getMouseX ()D + public fun getMouseY ()D + public fun isButtonDown (I)Z +} + +public class cc/polyfrost/oneconfig/platform/impl/NanoVGPlatformImpl : cc/polyfrost/oneconfig/platform/NanoVGPlatform { + public fun <init> ()V + public fun nnvgCreate (I)J + public fun nnvgDelete (J)V + public fun nnvglCreateImageFromHandle (JIIII)I + public fun nnvglImageHandle (JI)I + public fun nnvgluBindFramebuffer (JJ)V + public fun nnvgluCreateFramebuffer (JIII)J + public fun nnvgluDeleteFramebuffer (JJ)V + public fun nvgCreate (I)J + public fun nvgDelete (J)V + public fun nvglCreateImageFromHandle (JIIII)I + public fun nvglImageHandle (JI)I + public fun nvgluBindFramebuffer (JLorg/lwjgl/nanovg/NVGLUFramebuffer;)V + public fun nvgluCreateFramebuffer (JIII)Lorg/lwjgl/nanovg/NVGLUFramebuffer; + public fun nvgluDeleteFramebuffer (JLorg/lwjgl/nanovg/NVGLUFramebuffer;)V + public fun triggerStaticInitialization ()V +} + +public class cc/polyfrost/oneconfig/platform/impl/PlatformImpl : cc/polyfrost/oneconfig/platform/Platform { + public fun <init> ()V + public fun getLoader ()Lcc/polyfrost/oneconfig/platform/Platform$Loader; + public fun getMinecraftVersion ()I + public fun isCallingFromMinecraftThread ()Z +} + +public class cc/polyfrost/oneconfig/platform/impl/ServerPlatformImpl : cc/polyfrost/oneconfig/platform/ServerPlatform { + public fun <init> ()V + public fun getServerBrand ()Ljava/lang/String; + public fun inMultiplayer ()Z +} + +public class cc/polyfrost/oneconfig/utils/commands/PlatformCommandManagerImpl : cc/polyfrost/oneconfig/utils/commands/PlatformCommandManager { + public fun <init> ()V + public fun handleNewParser (Lcc/polyfrost/oneconfig/utils/commands/arguments/ArgumentParser;Ljava/lang/Class;)V +} + +public final class cc/polyfrost/oneconfig/utils/dsl/DSLsKt { + public static final fun getMc ()Lnet/minecraft/client/MinecraftClient; +} + +public final class cc/polyfrost/oneconfig/utils/dsl/GuiUtilsDSLKt { + public static final fun openScreen (Lnet/minecraft/client/gui/screen/Screen;I)V + public static synthetic fun openScreen$default (Lnet/minecraft/client/gui/screen/Screen;IILjava/lang/Object;)V +} + +public final class cc/polyfrost/oneconfig/utils/gui/GuiUtils { + public fun <init> ()V + public static fun closeScreen ()V + public static fun displayScreen (Ljava/lang/Object;)V + public static fun displayScreen (Lnet/minecraft/client/gui/screen/Screen;)V + public static fun displayScreen (Lnet/minecraft/client/gui/screen/Screen;I)V + public static fun getDeltaTime ()F + public static fun getScreenQueue ()Ljava/util/Deque; +} + diff --git a/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/hook/FramebufferHook.java b/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/hook/FramebufferHook.java new file mode 100644 index 0000000..d0125ea --- /dev/null +++ b/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/hook/FramebufferHook.java @@ -0,0 +1,6 @@ +package cc.polyfrost.oneconfig.internal.hook; + +public interface FramebufferHook { + boolean isStencilEnabled(); + void enableStencil(); +} diff --git a/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/mixin/FramebufferMixin.java b/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/mixin/FramebufferMixin.java new file mode 100644 index 0000000..5f182c5 --- /dev/null +++ b/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/mixin/FramebufferMixin.java @@ -0,0 +1,62 @@ +package cc.polyfrost.oneconfig.internal.mixin; + +import cc.polyfrost.oneconfig.internal.hook.FramebufferHook; +import com.mojang.blaze3d.platform.FramebufferInfo; +import com.mojang.blaze3d.platform.GlStateManager; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gl.Framebuffer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import java.nio.IntBuffer; + +/** + * Modified from MinecraftForge + * <a href="https://github.com/MinecraftForge/MinecraftForge/blob/1.19.x/LICENSE.txt">...</a> + */ +@Mixin(Framebuffer.class) +public abstract class FramebufferMixin implements FramebufferHook { + @Shadow public int textureWidth; + @Shadow public int textureHeight; + @Shadow private int depthAttachment; + + @Shadow public abstract void resize(int width, int height, boolean getError); + + @Shadow public int viewportWidth; + @Shadow public int viewportHeight; + private boolean stencilEnabled = false; + + @Redirect(method = "initFbo", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/platform/GlStateManager;texImage2D(IIIIIIIILjava/nio/IntBuffer;)V", ordinal = 0)) + private void stencilSupport(int target, int level, int internalFormat, int width, int height, int border, int format, int type, IntBuffer pixels) { + if (stencilEnabled) { + GlStateManager.texImage2D(3553, 0, 36013, textureWidth, textureHeight, 0, 34041, 36269, null); + } else { + GlStateManager.texImage2D(3553, 0, 6402, textureWidth, textureHeight, 0, 6402, 5126, null); + } + } + + @Redirect(method = "initFbo", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/platform/GlStateManager;framebufferTexture2D(IIIII)V", ordinal = 1)) + private void stencilSupport(int target, int attachment, int textureTarget, int texture, int level) { + if (stencilEnabled) { + GlStateManager.framebufferTexture2D(FramebufferInfo.FRAME_BUFFER, 36096, 3553, depthAttachment, 0); + GlStateManager.framebufferTexture2D(FramebufferInfo.FRAME_BUFFER, 36128, 3553, depthAttachment, 0); + } else { + GlStateManager.framebufferTexture2D(FramebufferInfo.FRAME_BUFFER, FramebufferInfo.DEPTH_ATTACHMENT, 3553, depthAttachment, 0); + } + } + + @Override + public boolean isStencilEnabled() { + return stencilEnabled; + } + + @Override + public void enableStencil() { + if (!this.stencilEnabled) { + this.stencilEnabled = true; + resize(viewportWidth, viewportHeight, MinecraftClient.IS_SYSTEM_MAC); + } + } +} diff --git a/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/mixin/GameRendererAccessor.java b/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/mixin/GameRendererAccessor.java new file mode 100644 index 0000000..0ebe121 --- /dev/null +++ b/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/mixin/GameRendererAccessor.java @@ -0,0 +1,12 @@ +package cc.polyfrost.oneconfig.internal.mixin; + +import net.minecraft.client.render.GameRenderer; +import net.minecraft.util.Identifier; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +@Mixin(GameRenderer.class) +public interface GameRendererAccessor { + @Invoker + void invokeLoadShader(Identifier identifier); +} diff --git a/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/mixin/GuiIngameForgeMixin.java b/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/mixin/GuiIngameForgeMixin.java new file mode 100644 index 0000000..6a8d283 --- /dev/null +++ b/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/mixin/GuiIngameForgeMixin.java @@ -0,0 +1,19 @@ +package cc.polyfrost.oneconfig.internal.mixin; + +import cc.polyfrost.oneconfig.events.EventManager; +import cc.polyfrost.oneconfig.events.event.HudRenderEvent; +import cc.polyfrost.oneconfig.libs.universal.UMatrixStack; +import net.minecraft.client.gui.hud.InGameHud; +import net.minecraft.client.util.math.MatrixStack; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(InGameHud.class) +public class GuiIngameForgeMixin { + @Inject(method = "render", at = @At("TAIL")) + private void onRenderGameOverlay(MatrixStack matrices, float tickDelta, CallbackInfo ci) { + EventManager.INSTANCE.post(new HudRenderEvent(new UMatrixStack(matrices), tickDelta)); + } +}
\ No newline at end of file diff --git a/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/mixin/KeyboardMixin.java b/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/mixin/KeyboardMixin.java new file mode 100644 index 0000000..7d0a33f --- /dev/null +++ b/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/mixin/KeyboardMixin.java @@ -0,0 +1,20 @@ +package cc.polyfrost.oneconfig.internal.mixin; + +import cc.polyfrost.oneconfig.events.EventManager; +import cc.polyfrost.oneconfig.events.event.KeyInputEvent; +import net.minecraft.client.Keyboard; +import net.minecraft.client.MinecraftClient; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(Keyboard.class) +public class KeyboardMixin { + @Inject(method = "onKey", at = @At("TAIL")) + private void onKeyEvent(long windowPointer, int key, int scanCode, int action, int modifiers, CallbackInfo ci) { + if (windowPointer == MinecraftClient.getInstance().getWindow().getHandle()) { + EventManager.INSTANCE.post(new KeyInputEvent()); + } + } +} diff --git a/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java b/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java new file mode 100644 index 0000000..0acb015 --- /dev/null +++ b/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java @@ -0,0 +1,60 @@ +package cc.polyfrost.oneconfig.internal.mixin; + +import cc.polyfrost.oneconfig.events.EventManager; +import cc.polyfrost.oneconfig.events.event.*; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.render.RenderTickCounter; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(MinecraftClient.class) +public class MinecraftMixin { + @Final + @Shadow + private RenderTickCounter renderTickCounter; + + @Inject(method = "stop", at = @At("HEAD")) + private void onShutdown(CallbackInfo ci) { + EventManager.INSTANCE.post(new PreShutdownEvent()); + } + + @Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/profiler/Profiler;swap(Ljava/lang/String;)V", ordinal = 0)) + private void onRenderTickStart(CallbackInfo ci) { + EventManager.INSTANCE.post(new RenderEvent(Stage.START, renderTickCounter.tickDelta)); + } + + @Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/profiler/Profiler;pop()V", shift = At.Shift.AFTER, ordinal = 4)) + private void onRenderTickEnd(CallbackInfo ci) { + EventManager.INSTANCE.post(new RenderEvent(Stage.END, renderTickCounter.tickDelta)); + } + + @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/profiler/Profiler;push(Ljava/lang/String;)V", ordinal = 0)) + private void onClientTickStart(CallbackInfo ci) { + EventManager.INSTANCE.post(new TickEvent(Stage.START)); + } + + @Inject(method = "tick", at = @At("TAIL")) + private void onClientTickEnd(CallbackInfo ci) { + EventManager.INSTANCE.post(new TickEvent(Stage.END)); + } + + @Inject(method = "openScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;requestRespawn()V", shift = At.Shift.BY, by = 2), cancellable = true) + private void onGuiOpenEvent(Screen screen, CallbackInfo ci) { + ScreenOpenEvent event = new ScreenOpenEvent(screen); + EventManager.INSTANCE.post(event); + if (event.isCancelled) { + ci.cancel(); + } + } + + @Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/RenderTickCounter;beginRenderTick(J)I", shift = At.Shift.AFTER)) + private void onDeltaTickTimerUpdate(CallbackInfo ci) { + EventManager.INSTANCE.post(new TimerUpdateEvent(renderTickCounter, true)); + } +}
\ No newline at end of file diff --git a/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MouseAccessor.java b/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MouseAccessor.java new file mode 100644 index 0000000..2765b3a --- /dev/null +++ b/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MouseAccessor.java @@ -0,0 +1,17 @@ +package cc.polyfrost.oneconfig.internal.mixin; + +import net.minecraft.client.Mouse; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(Mouse.class) +public interface MouseAccessor { + @Accessor("eventDeltaWheel") + double getEventDeltaWheel(); + + @Accessor + double getCursorDeltaX(); + + @Accessor + double getCursorDeltaY(); +} diff --git a/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MouseMixin.java b/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MouseMixin.java new file mode 100644 index 0000000..c088c32 --- /dev/null +++ b/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MouseMixin.java @@ -0,0 +1,20 @@ +package cc.polyfrost.oneconfig.internal.mixin; + +import cc.polyfrost.oneconfig.events.EventManager; +import cc.polyfrost.oneconfig.events.event.MouseInputEvent; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.Mouse; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(Mouse.class) +public class MouseMixin { + @Inject(method = "onMouseButton", at = @At("TAIL")) + private void onMouse(long handle, int button, int action, int mods, CallbackInfo ci) { + if (handle == MinecraftClient.getInstance().getWindow().getHandle()) { + EventManager.INSTANCE.post(new MouseInputEvent()); + } + } +} diff --git a/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetHandlerPlayClientMixin.java b/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetHandlerPlayClientMixin.java new file mode 100644 index 0000000..cdd673a --- /dev/null +++ b/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetHandlerPlayClientMixin.java @@ -0,0 +1,25 @@ +package cc.polyfrost.oneconfig.internal.mixin; + +import cc.polyfrost.oneconfig.events.EventManager; +import cc.polyfrost.oneconfig.events.event.ChatReceiveEvent; +import net.minecraft.client.network.ClientPlayNetworkHandler; +import net.minecraft.network.packet.s2c.play.GameMessageS2CPacket; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(value = ClientPlayNetworkHandler.class, priority = Integer.MAX_VALUE) +public class NetHandlerPlayClientMixin { + + @Inject(method = "onGameMessage", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/InGameHud;addChatMessage(Lnet/minecraft/network/MessageType;Lnet/minecraft/text/Text;Ljava/util/UUID;)V"), cancellable = true) + private void onClientChat(GameMessageS2CPacket packet, CallbackInfo ci) { + if (packet.getLocation().getId() == 0) { + ChatReceiveEvent event = new ChatReceiveEvent(packet.getMessage()); + EventManager.INSTANCE.post(event); + if (event.isCancelled) { + ci.cancel(); + } + } + } +}
\ No newline at end of file diff --git a/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetworkManagerMixin.java b/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetworkManagerMixin.java new file mode 100644 index 0000000..825effa --- /dev/null +++ b/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetworkManagerMixin.java @@ -0,0 +1,42 @@ +package cc.polyfrost.oneconfig.internal.mixin; + +import cc.polyfrost.oneconfig.events.EventManager; +import cc.polyfrost.oneconfig.events.event.ReceivePacketEvent; +import cc.polyfrost.oneconfig.events.event.SendPacketEvent; +import io.netty.channel.ChannelHandlerContext; +import io.netty.util.concurrent.Future; +import io.netty.util.concurrent.GenericFutureListener; +import net.minecraft.network.ClientConnection; +import net.minecraft.network.Packet; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(value = ClientConnection.class, priority = Integer.MAX_VALUE) +public class NetworkManagerMixin { + + @Inject(method = "send(Lnet/minecraft/network/Packet;Lio/netty/util/concurrent/GenericFutureListener;)V", at = @At("HEAD"), cancellable = true) + private void onSendPacket(Packet<?> packet, GenericFutureListener<? extends Future<? super Void>> callback, CallbackInfo ci) { + onSendPacket(packet, ci); + } + + @Inject(method = "send(Lnet/minecraft/network/Packet;)V", at = @At("HEAD"), cancellable = true) + private void onSendPacket(Packet<?> packet, CallbackInfo ci) { + SendPacketEvent event = new SendPacketEvent(packet); + EventManager.INSTANCE.post(event); + if (event.isCancelled) { + ci.cancel(); + } + } + + + @Inject(method = "channelRead0(Lio/netty/channel/ChannelHandlerContext;Lnet/minecraft/network/Packet;)V", at = @At("HEAD"), cancellable = true) + private void onReceivePacket(ChannelHandlerContext channelHandlerContext, Packet<?> packet, CallbackInfo ci) { + ReceivePacketEvent event = new ReceivePacketEvent(packet); + EventManager.INSTANCE.post(event); + if (event.isCancelled) { + ci.cancel(); + } + } +}
\ No newline at end of file diff --git a/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/mixin/TickTimeTrackerMixin.java b/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/mixin/TickTimeTrackerMixin.java new file mode 100644 index 0000000..8b655d8 --- /dev/null +++ b/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/mixin/TickTimeTrackerMixin.java @@ -0,0 +1,24 @@ +package cc.polyfrost.oneconfig.internal.mixin; + +import cc.polyfrost.oneconfig.events.EventManager; +import cc.polyfrost.oneconfig.events.event.ShutdownEvent; +import cc.polyfrost.oneconfig.events.event.StartEvent; +import net.minecraft.util.profiler.TickTimeTracker; +import cc.polyfrost.oneconfig.internal.OneConfig; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.function.IntSupplier; +import java.util.function.LongSupplier; + +@Mixin(TickTimeTracker.class) +public class TickTimeTrackerMixin { + @Inject(method = "<init>", at = @At("RETURN")) + private void onStart(LongSupplier longSupplier, IntSupplier intSupplier, CallbackInfo ci) { + OneConfig.init(); + EventManager.INSTANCE.post(new StartEvent()); + Runtime.getRuntime().addShutdownHook(new Thread(() -> EventManager.INSTANCE.post(new ShutdownEvent()))); + } +} diff --git a/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/mixin/WorldClientMixin.java b/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/mixin/WorldClientMixin.java new file mode 100644 index 0000000..4fc4ba5 --- /dev/null +++ b/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/mixin/WorldClientMixin.java @@ -0,0 +1,24 @@ +package cc.polyfrost.oneconfig.internal.mixin; + +import cc.polyfrost.oneconfig.events.EventManager; +import cc.polyfrost.oneconfig.events.event.WorldLoadEvent; +import net.minecraft.client.network.ClientPlayNetworkHandler; +import net.minecraft.client.render.WorldRenderer; +import net.minecraft.client.world.ClientWorld; +import net.minecraft.util.registry.RegistryKey; +import net.minecraft.world.World; +import net.minecraft.world.dimension.DimensionType; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.function.Supplier; + +@Mixin(ClientWorld.class) +public class WorldClientMixin { + @Inject(method = "<init>", at = @At("RETURN")) + private void onWorldLoad(ClientPlayNetworkHandler clientPlayNetworkHandler, ClientWorld.Properties properties, RegistryKey<World> registryKey, DimensionType dimensionType, int i, Supplier<World> supplier, WorldRenderer worldRenderer, boolean bl, long l, CallbackInfo ci) { + EventManager.INSTANCE.post(new WorldLoadEvent()); + } +}
\ No newline at end of file diff --git a/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigPreLaunch.java b/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigPreLaunch.java new file mode 100644 index 0000000..ca57970 --- /dev/null +++ b/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigPreLaunch.java @@ -0,0 +1,11 @@ +package cc.polyfrost.oneconfig.internal.plugin; + +import cc.polyfrost.oneconfig.internal.init.OneConfigInit; +import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; + +public class OneConfigPreLaunch implements PreLaunchEntrypoint { + @Override + public void onPreLaunch() { + OneConfigInit.initialize(new String[]{}); + } +} diff --git a/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/utils/commands/PlatformCommandManagerImpl.java b/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/utils/commands/PlatformCommandManagerImpl.java new file mode 100644 index 0000000..674d7b9 --- /dev/null +++ b/versions/1.16.2-fabric/src/main/java/cc/polyfrost/oneconfig/utils/commands/PlatformCommandManagerImpl.java @@ -0,0 +1,122 @@ +package cc.polyfrost.oneconfig.utils.commands; + +import cc.polyfrost.oneconfig.libs.universal.ChatColor; +import cc.polyfrost.oneconfig.libs.universal.UChat; +import cc.polyfrost.oneconfig.utils.commands.annotations.Command; +import cc.polyfrost.oneconfig.utils.commands.annotations.Greedy; +import cc.polyfrost.oneconfig.utils.commands.arguments.ArgumentParser; +import cc.polyfrost.oneconfig.utils.commands.arguments.Arguments; +import com.mojang.brigadier.StringReader; +import com.mojang.brigadier.arguments.ArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.suggestion.Suggestions; +import com.mojang.brigadier.suggestion.SuggestionsBuilder; +import net.minecraft.server.command.ServerCommandSource; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Parameter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.concurrent.CompletableFuture; + +import static cc.polyfrost.oneconfig.utils.commands.CommandManager.METHOD_RUN_ERROR; + +public class PlatformCommandManagerImpl extends PlatformCommandManager { + + final HashMap<Class<?>, Pair<ArgumentType<Object>, ArgumentType<Object>>> parsers = new HashMap<>(); // non-greedy, greedy + + @Override + void createCommand(CommandManager.InternalCommand root, Command annotation) { + LiteralArgumentBuilder<ServerCommandSource> builder = net.minecraft.server.command.CommandManager.literal(annotation.value()); + if (!root.invokers.isEmpty()) { + builder.executes((context -> + { + try { + root.invokers.get(0).method.invoke(null); + return 1; + } catch (IllegalAccessException | InvocationTargetException | IllegalArgumentException | + ExceptionInInitializerError e) { + UChat.chat(ChatColor.RED.toString() + ChatColor.BOLD + METHOD_RUN_ERROR); + return 0; + } + })); + } + if (annotation.helpCommand()) { + builder.then(net.minecraft.server.command.CommandManager.literal("help").executes((context -> + { + UChat.chat(sendHelpCommand(root)); + return 1; + }))); + } + for (CommandManager.InternalCommand command : root.children) { + loopThroughChildren(command, builder, null); + } + } + + private void loopThroughChildren(CommandManager.InternalCommand command, LiteralArgumentBuilder<ServerCommandSource> root, LiteralArgumentBuilder<ServerCommandSource> builder) { + if (command.invokers.isEmpty() || command.children.isEmpty()) return; + if (builder == null) { + builder = root.then(net.minecraft.server.command.CommandManager.literal(command.name)); + } else { + builder = builder.then(net.minecraft.server.command.CommandManager.literal(command.name)); + } + for (CommandManager.InternalCommand.InternalCommandInvoker invoker : command.invokers) { + for (Parameter parameter : invoker.method.getParameters()) { + Pair<ArgumentType<Object>, ArgumentType<Object>> pair = parsers.get(parameter.getType()); + builder.then(net.minecraft.server.command.CommandManager.argument(parameter.getName(), parameter.isAnnotationPresent(Greedy.class) ? pair.getRight() : pair.getLeft())); + } + builder.executes((context -> + { + try { + ArrayList<Object> args = new ArrayList<>(invoker.method.getParameterCount()); + for (Parameter parameter: invoker.method.getParameters()) { + args.add(context.getArgument(parameter.getName(), Object.class)); + } + invoker.method.invoke(null, args); + return 1; + } catch (Exception e) { + e.printStackTrace(); + UChat.chat(ChatColor.RED.toString() + ChatColor.BOLD + METHOD_RUN_ERROR); + return 0; + } + })); + } + for (CommandManager.InternalCommand child : command.children) { + loopThroughChildren(child, root, builder); + } + } + + @Override + public void handleNewParser(ArgumentParser<?> parser, Class<?> clazz) { + parsers.put(clazz, new ImmutablePair<ArgumentType<Object>, ArgumentType<Object>>(new ArgumentType() { + + @Override + public Object parse(StringReader reader) { + final String text = reader.getRemaining(); + reader.setCursor(reader.getTotalLength()); + return parser.parse(new Arguments(text.split("\\s+"), false)); + } + + @Override + public CompletableFuture<Suggestions> listSuggestions(CommandContext context, SuggestionsBuilder builder) { + return ArgumentType.super.listSuggestions(context, builder); + } + }, new ArgumentType() { + + @Override + public Object parse(StringReader reader) { + final String text = reader.getRemaining(); + reader.setCursor(reader.getTotalLength()); + return parser.parse(new Arguments(text.split("\\s+"), true)); + } + + @Override + public CompletableFuture<Suggestions> listSuggestions(CommandContext context, SuggestionsBuilder builder) { + return ArgumentType.super.listSuggestions(context, builder); + } + })); + } +} diff --git a/versions/1.16.2-forge/api/1.16.2-forge.api b/versions/1.16.2-forge/api/1.16.2-forge.api index fae79fb..cbd559e 100644 --- a/versions/1.16.2-forge/api/1.16.2-forge.api +++ b/versions/1.16.2-forge/api/1.16.2-forge.api @@ -64,8 +64,28 @@ public class cc/polyfrost/oneconfig/platform/impl/MousePlatformImpl : cc/polyfro public fun isButtonDown (I)Z } +public class cc/polyfrost/oneconfig/platform/impl/NanoVGPlatformImpl : cc/polyfrost/oneconfig/platform/NanoVGPlatform { + public fun <init> ()V + public fun nnvgCreate (I)J + public fun nnvgDelete (J)V + public fun nnvglCreateImageFromHandle (JIIII)I + public fun nnvglImageHandle (JI)I + public fun nnvgluBindFramebuffer (JJ)V + public fun nnvgluCreateFramebuffer (JIII)J + public fun nnvgluDeleteFramebuffer (JJ)V + public fun nvgCreate (I)J + public fun nvgDelete (J)V + public fun nvglCreateImageFromHandle (JIIII)I + public fun nvglImageHandle (JI)I + public fun nvgluBindFramebuffer (JLorg/lwjgl/nanovg/NVGLUFramebuffer;)V + public fun nvgluCreateFramebuffer (JIII)Lorg/lwjgl/nanovg/NVGLUFramebuffer; + public fun nvgluDeleteFramebuffer (JLorg/lwjgl/nanovg/NVGLUFramebuffer;)V + public fun triggerStaticInitialization ()V +} + public class cc/polyfrost/oneconfig/platform/impl/PlatformImpl : cc/polyfrost/oneconfig/platform/Platform { public fun <init> ()V + public fun getLoader ()Lcc/polyfrost/oneconfig/platform/Platform$Loader; public fun getMinecraftVersion ()I public fun isCallingFromMinecraftThread ()Z } diff --git a/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/ClientModLoaderMixin.java b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/ClientModLoaderMixin.java index a3832d0..08ede6e 100644 --- a/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/ClientModLoaderMixin.java +++ b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/ClientModLoaderMixin.java @@ -1,8 +1,10 @@ +//#if FORGE==1 package cc.polyfrost.oneconfig.internal.mixin; import cc.polyfrost.oneconfig.events.EventManager; import cc.polyfrost.oneconfig.events.event.InitializationEvent; import cc.polyfrost.oneconfig.internal.OneConfig; +import cc.polyfrost.oneconfig.internal.init.OneConfigInit; import net.minecraftforge.fml.client.ClientModLoader; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -13,7 +15,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; public class ClientModLoaderMixin { @Inject(method = "begin", at = @At("HEAD")) private static void onBegin(CallbackInfo ci) { - OneConfig.preLaunch(); + OneConfigInit.initialize(new String[]{}); } @Inject(method = "lambda$finishModLoading$9", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/GameSettings;loadOptions()V", remap = true), remap = false) @@ -22,3 +24,4 @@ public class ClientModLoaderMixin { OneConfig.init(); } } +//#endif
\ No newline at end of file diff --git a/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/KeyboardListenerMixin.java b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/KeyboardMixin.java index c7e6327..2a28d66 100644 --- a/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/KeyboardListenerMixin.java +++ b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/KeyboardMixin.java @@ -9,7 +9,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(KeyboardListener.class) -public class KeyboardListenerMixin { +public class KeyboardMixin { @Inject(method = "onKeyEvent", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/client/ForgeHooksClient;fireKeyInput(IIII)V")) private void onKeyEvent(long windowPointer, int key, int scanCode, int action, int modifiers, CallbackInfo ci) { EventManager.INSTANCE.post(new KeyInputEvent()); diff --git a/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MouseHelperAccessor.java b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MouseAccessor.java index d04ecb1..9cc518d 100644 --- a/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MouseHelperAccessor.java +++ b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MouseAccessor.java @@ -5,7 +5,7 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; @Mixin(MouseHelper.class) -public interface MouseHelperAccessor { - @Accessor - double getAccumulatedScrollDelta(); +public interface MouseAccessor { + @Accessor("accumulatedScrollDelta") + double getEventDeltaWheel(); } diff --git a/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MouseHelperMixin.java b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MouseMixin.java index 42dd283..525f187 100644 --- a/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MouseHelperMixin.java +++ b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MouseMixin.java @@ -9,7 +9,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(MouseHelper.class) -public class MouseHelperMixin { +public class MouseMixin { @Inject(method = "mouseButtonCallback", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/client/ForgeHooksClient;fireMouseInput(III)V")) private void onMouse(long handle, int button, int action, int mods, CallbackInfo ci) { EventManager.INSTANCE.post(new MouseInputEvent()); diff --git a/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/TimeTrackerMixin.java b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/TickTimeTrackerMixin.java index dd9920e..572076d 100644 --- a/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/TimeTrackerMixin.java +++ b/versions/1.16.2-forge/src/main/java/cc/polyfrost/oneconfig/internal/mixin/TickTimeTrackerMixin.java @@ -13,7 +13,7 @@ import java.util.function.IntSupplier; import java.util.function.LongSupplier; @Mixin(TimeTracker.class) -public class TimeTrackerMixin { +public class TickTimeTrackerMixin { @Inject(method = "<init>", at = @At("RETURN")) private void onStart(LongSupplier longSupplier, IntSupplier intSupplier, CallbackInfo ci) { EventManager.INSTANCE.post(new StartEvent()); diff --git a/versions/1.8.9-forge/api/1.8.9-forge.api b/versions/1.8.9-forge/api/1.8.9-forge.api index da98be5..44cd883 100644 --- a/versions/1.8.9-forge/api/1.8.9-forge.api +++ b/versions/1.8.9-forge/api/1.8.9-forge.api @@ -64,8 +64,28 @@ public class cc/polyfrost/oneconfig/platform/impl/MousePlatformImpl : cc/polyfro public fun isButtonDown (I)Z } +public class cc/polyfrost/oneconfig/platform/impl/NanoVGPlatformImpl : cc/polyfrost/oneconfig/platform/NanoVGPlatform { + public fun <init> ()V + public fun nnvgCreate (I)J + public fun nnvgDelete (J)V + public fun nnvglCreateImageFromHandle (JIIII)I + public fun nnvglImageHandle (JI)I + public fun nnvgluBindFramebuffer (JJ)V + public fun nnvgluCreateFramebuffer (JIII)J + public fun nnvgluDeleteFramebuffer (JJ)V + public fun nvgCreate (I)J + public fun nvgDelete (J)V + public fun nvglCreateImageFromHandle (JIIII)I + public fun nvglImageHandle (JI)I + public fun nvgluBindFramebuffer (JLorg/lwjgl/nanovg/NVGLUFramebuffer;)V + public fun nvgluCreateFramebuffer (JIII)Lorg/lwjgl/nanovg/NVGLUFramebuffer; + public fun nvgluDeleteFramebuffer (JLorg/lwjgl/nanovg/NVGLUFramebuffer;)V + public fun triggerStaticInitialization ()V +} + public class cc/polyfrost/oneconfig/platform/impl/PlatformImpl : cc/polyfrost/oneconfig/platform/Platform { public fun <init> ()V + public fun getLoader ()Lcc/polyfrost/oneconfig/platform/Platform$Loader; public fun getMinecraftVersion ()I public fun isCallingFromMinecraftThread ()Z } diff --git a/versions/build.gradle.kts b/versions/build.gradle.kts index e8c161d..87c6b64 100644 --- a/versions/build.gradle.kts +++ b/versions/build.gradle.kts @@ -1,6 +1,5 @@ import gg.essential.gradle.util.RelocationTransform.Companion.registerRelocationAttribute import gg.essential.gradle.util.noServerRunConfigs -import gg.essential.gradle.util.prebundle import net.fabricmc.loom.task.RemapSourcesJarTask import java.text.SimpleDateFormat @@ -105,7 +104,6 @@ val shade: Configuration by configurations.creating { configurations.api.get().extendsFrom(this) } -val shadeNoPom: Configuration by configurations.creating val shadeNoPom2: Configuration by configurations.creating sourceSets { @@ -121,53 +119,43 @@ dependencies { isTransitive = false } - shadeRelocated("gg.essential:universalcraft-$platform:211") { - isTransitive = false - } + include("gg.essential:universalcraft-$platform:211", relocate = true, transitive = false, mod = true) - shadeRelocated("com.github.KevinPriv:keventbus:c52e0a2ea0") { - isTransitive = false - } + include("com.github.KevinPriv:keventbus:c52e0a2ea0", relocate = true, transitive = false) - @Suppress("GradlePackageUpdate") shadeRelocated("com.github.ben-manes.caffeine:caffeine:2.9.3") + @Suppress("GradlePackageUpdate") include("com.github.ben-manes.caffeine:caffeine:2.9.3", relocate = true) // for other mods and universalcraft val kotlinVersion: String by project val coroutinesVersion: String by project val serializationVersion: String by project val atomicfuVersion: String by project - shade("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion") - shade("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion") - shade("org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion") - shade("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion") - - shade("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion") - shade("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:$coroutinesVersion") - shade("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:$coroutinesVersion") - shade("org.jetbrains.kotlinx:kotlinx-serialization-core-jvm:$serializationVersion") - shade("org.jetbrains.kotlinx:kotlinx-serialization-json-jvm:$serializationVersion") - shade("org.jetbrains.kotlinx:kotlinx-serialization-cbor-jvm:$serializationVersion") - shade("org.jetbrains.kotlinx:atomicfu-jvm:$atomicfuVersion") + include("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion") + include("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion") + include("org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion") + include("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion") + + include("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion") + include("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:$coroutinesVersion") + include("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:$coroutinesVersion") + include("org.jetbrains.kotlinx:kotlinx-serialization-core-jvm:$serializationVersion") + include("org.jetbrains.kotlinx:kotlinx-serialization-json-jvm:$serializationVersion") + include("org.jetbrains.kotlinx:kotlinx-serialization-cbor-jvm:$serializationVersion") + include("org.jetbrains.kotlinx:atomicfu-jvm:$atomicfuVersion") if (platform.isLegacyForge) { - shade("org.spongepowered:mixin:0.7.11-SNAPSHOT") { - isTransitive = false - } + include("org.spongepowered:mixin:0.7.11-SNAPSHOT", pom = false, transitive = false) } shadeProject(project(":")) { isTransitive = false } - shade("cc.polyfrost:lwjgl-$platform:1.0.0-alpha5") - val prebundled = prebundle(shadeRelocated) - modCompileOnly(prebundled) - modRuntimeOnly(prebundled) - shadeNoPom2(prebundled) + include("cc.polyfrost:lwjgl-$platform:1.0.0-alpha8") dokkaHtmlPlugin("org.jetbrains.dokka:kotlin-as-java-plugin:1.6.21") - configurations.named(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME) { extendsFrom(shadeNoPom); extendsFrom(shadeProject) } - configurations.named(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME) { extendsFrom(shadeNoPom); extendsFrom(shadeProject) } + configurations.named(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME) { extendsFrom(shadeProject) } + configurations.named(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME) { extendsFrom(shadeProject) } } tasks { @@ -233,7 +221,7 @@ tasks { val shadowJar = named<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>("shadowJar") { archiveClassifier.set("full-dev") - configurations = listOf(shade, shadeNoPom, shadeNoPom2, shadeProject) + configurations = listOf(shade, shadeNoPom2, shadeProject, shadeRelocated) duplicatesStrategy = DuplicatesStrategy.EXCLUDE dependsOn(jar) } @@ -248,8 +236,8 @@ tasks { } jar { duplicatesStrategy = DuplicatesStrategy.EXCLUDE - dependsOn(shadeNoPom, shadeNoPom2, shadeProject) - from(ArrayList<File>().run { addAll(shadeNoPom); addAll(shadeNoPom2); addAll(shadeProject); this } + dependsOn(shadeNoPom2, shadeProject, shadeRelocated) + from(ArrayList<File>().run { addAll(shadeNoPom2); addAll(shadeProject); addAll(shadeRelocated); this } .map { if (it.isDirectory) it else zipTree(it) }) manifest { attributes( @@ -319,6 +307,9 @@ tasks { archiveClassifier.set("sources") } doLast { + archiveFile.orNull?.asFile?.let { + it.copyTo(File(it.parentFile, it.nameWithoutExtension + "-dev" + it.extension.let { if (it.isBlank()) "" else ".$it" }), overwrite = true) + } archiveClassifier.set("sources") } } @@ -366,4 +357,103 @@ publishing { } } } +} + +fun DependencyHandlerScope.include(dependency: Any, pom: Boolean = true, mod: Boolean = false) { + if (platform.isForge) { + if (pom) { + shade(dependency) + } else { + shadeNoPom2(dependency) + compileOnly(dependency) + runtimeOnly(dependency) + } + } else { + if (pom) { + if (mod) { + modApi(dependency) + } else { + api(dependency) + } + } else { + if (mod) { + modCompileOnly(dependency) + modRuntimeOnly(dependency) + } else { + compileOnly(dependency) + runtimeOnly(dependency) + } + } + "include"(dependency) + } +} + +fun DependencyHandlerScope.include(dependency: ModuleDependency, pom: Boolean = true, mod: Boolean = false, relocate: Boolean = false, transitive: Boolean = true) { + if (platform.isForge) { + if (relocate) { + shadeRelocated(dependency) { isTransitive = transitive } + compileOnly(dependency) { isTransitive = transitive; attributes { attribute(relocated, true) } } + runtimeOnly(dependency) { isTransitive = transitive; attributes { attribute(relocated, true) } } + } else { + if (pom) { + shade(dependency) { isTransitive = transitive } + } else { + shadeNoPom2(dependency) { isTransitive = transitive } + compileOnly(dependency) { isTransitive = transitive } + runtimeOnly(dependency) { isTransitive = transitive } + } + } + } else { + if (pom && !relocate) { + if (mod) { + modApi(dependency) { isTransitive = transitive } + } else { + api(dependency) { isTransitive = transitive } + } + } else { + if (mod) { + modCompileOnly(dependency) { isTransitive = transitive; if (relocate) attributes { attribute(relocated, true) } } + modRuntimeOnly(dependency) { isTransitive = transitive; if (relocate) attributes { attribute(relocated, true) } } + } else { + compileOnly(dependency) { isTransitive = transitive; if (relocate) attributes { attribute(relocated, true) } } + runtimeOnly(dependency) { isTransitive = transitive; if (relocate) attributes { attribute(relocated, true) } } + } + } + "include"(dependency) { isTransitive = transitive; if (relocate) attributes { attribute(relocated, true) } } + } +} + +fun DependencyHandlerScope.include(dependency: String, pom: Boolean = true, mod: Boolean = false, relocate: Boolean = false, transitive: Boolean = true) { + if (platform.isForge) { + if (relocate) { + shadeRelocated(dependency) { isTransitive = transitive } + compileOnly(dependency) { isTransitive = transitive; attributes { attribute(relocated, true) } } + runtimeOnly(dependency) { isTransitive = transitive; attributes { attribute(relocated, true) } } + } else { + if (pom) { + shade(dependency) { isTransitive = transitive } + } else { + shadeNoPom2(dependency) { isTransitive = transitive } + compileOnly(dependency) { isTransitive = transitive } + runtimeOnly(dependency) { isTransitive = transitive } + } + } + } else { + if (pom && !relocate) { + if (mod) { + modApi(dependency) { isTransitive = transitive } + } else { + api(dependency) { isTransitive = transitive } + } + } else { + if (mod) { + modCompileOnly(dependency) { isTransitive = transitive; if (relocate) attributes { attribute(relocated, true) } } + modRuntimeOnly(dependency) { isTransitive = transitive; if (relocate) attributes { attribute(relocated, true) } } + } else { + compileOnly(dependency) { isTransitive = transitive; if (relocate) attributes { attribute(relocated, true) } } + runtimeOnly(dependency) { isTransitive = transitive; if (relocate) attributes { attribute(relocated, true) } } + } + } + "include"(dependency) { isTransitive = transitive; if (relocate) attributes { attribute(relocated, true) } } + } }
\ No newline at end of file diff --git a/versions/root.gradle.kts b/versions/root.gradle.kts index 6a09be5..0b57e5a 100644 --- a/versions/root.gradle.kts +++ b/versions/root.gradle.kts @@ -10,7 +10,9 @@ plugins { preprocess { "1.8.9-forge"(10809, "srg") { "1.12.2-forge"(11202, "srg", file("1.8.9-1.12.2.txt")) { - "1.16.2-forge"(11602, "srg", file("1.12.2-1.16.2.txt")) + "1.16.2-forge"(11602, "srg", file("1.12.2-1.16.2.txt")) { + "1.16.2-fabric"(11602, "yarn") + } } } }
\ No newline at end of file diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java b/versions/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java index 4f73198..7eb5ef9 100644 --- a/versions/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java +++ b/versions/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java @@ -24,43 +24,32 @@ import java.io.File; //#if MC<=11202 @net.minecraftforge.fml.common.Mod(modid = "@ID@", name = "@NAME@", version = "@VER@") //#else +//#if FORGE==1 //$$ @net.minecraftforge.fml.common.Mod("@ID@") //#endif +//#endif public class OneConfig { public OneConfig() { EventManager.INSTANCE.register(this); } - public static final File oneConfigDir = new File("./OneConfig"); public static final Logger LOGGER = LogManager.getLogger("@NAME@"); - private static boolean preLaunched = false; private static boolean initialized = false; /** - * Called before mods are loaded. + * Called after mods are loaded. * <p><b>SHOULD NOT BE CALLED!</b></p> */ - public static void preLaunch() { - if (preLaunched) return; - oneConfigDir.mkdirs(); - new File(oneConfigDir, "profiles").mkdirs(); + @SuppressWarnings("ResultOfMethodCallIgnored") + public static void init() { + if (initialized) return; if (OneConfigConfig.getInstance() == null) { OneConfigConfig.getInstance(); } if (Preferences.getInstance() == null) { Preferences.getInstance(); } - preLaunched = true; - } - - /** - * Called after mods are loaded. - * <p><b>SHOULD NOT BE CALLED!</b></p> - */ - @SuppressWarnings("ResultOfMethodCallIgnored") - public static void init() { - if (initialized) return; GuiUtils.getDeltaTime(); // called to make sure static initializer is called try { EventManager.INSTANCE.register(BlurHandler.INSTANCE); diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/internal/eggs/TechnobladeCrownRenderer.java b/versions/src/main/java/cc/polyfrost/oneconfig/internal/eggs/TechnobladeCrownRenderer.java deleted file mode 100644 index f5e7bed..0000000 --- a/versions/src/main/java/cc/polyfrost/oneconfig/internal/eggs/TechnobladeCrownRenderer.java +++ /dev/null @@ -1,39 +0,0 @@ -//#if MC<=11202 -package cc.polyfrost.oneconfig.internal.eggs; - -import cc.polyfrost.oneconfig.internal.config.Preferences; -import net.minecraft.client.model.ModelPig; -import net.minecraft.client.renderer.entity.RenderPig; -import net.minecraft.client.renderer.entity.layers.LayerRenderer; -import net.minecraft.entity.passive.EntityPig; -import net.minecraft.util.ResourceLocation; - -/** - * Adapted from technomodel under MIT - * <a href="https://github.com/thecolonel63/technomodel/blob/master/LICENSE">...</a> - */ -public class TechnobladeCrownRenderer<T extends EntityPig> implements LayerRenderer<T> { - - private static final ResourceLocation CROWN_TEXTURE = new ResourceLocation("oneconfig", "textures/entity/pig/technocrown.png"); - private final RenderPig renderer; - private final ModelPig pigModel = new ModelPig(0.5F); - - public TechnobladeCrownRenderer(RenderPig renderPig) { - renderer = renderPig; - } - - @Override - public void doRenderLayer(T entitylivingbaseIn, float f, float g, float partialTicks, float h, float i, float j, float scale) { - if (Preferences.easterEgg1 && entitylivingbaseIn.hasCustomName() && entitylivingbaseIn.getCustomNameTag().equals("Technoblade")) { - this.renderer.bindTexture(CROWN_TEXTURE); - this.pigModel.setModelAttributes(renderer.getMainModel()); - this.pigModel.render(entitylivingbaseIn, f, g, h, i, j, scale); - } - } - - @Override - public boolean shouldCombineTextures() { - return true; - } -} -//#endif
\ No newline at end of file diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/internal/gui/impl/BlurHandlerImpl.java b/versions/src/main/java/cc/polyfrost/oneconfig/internal/gui/impl/BlurHandlerImpl.java index 3424d2b..f4d15a4 100644 --- a/versions/src/main/java/cc/polyfrost/oneconfig/internal/gui/impl/BlurHandlerImpl.java +++ b/versions/src/main/java/cc/polyfrost/oneconfig/internal/gui/impl/BlurHandlerImpl.java @@ -7,6 +7,9 @@ import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.internal.config.Preferences; import cc.polyfrost.oneconfig.internal.gui.BlurHandler; import cc.polyfrost.oneconfig.internal.mixin.ShaderGroupAccessor; +//#if FABRIC==1 +//$$ import cc.polyfrost.oneconfig.internal.mixin.GameRendererAccessor; +//#endif import cc.polyfrost.oneconfig.libs.eventbus.Subscribe; import cc.polyfrost.oneconfig.libs.universal.UMinecraft; import cc.polyfrost.oneconfig.libs.universal.UScreen; @@ -102,7 +105,11 @@ public class BlurHandlerImpl implements BlurHandler { // a one of ours, we should load our own blur! if (!isShaderActive() && gui instanceof OneConfigGui && Preferences.enableBlur) { + //#if FABRIC==1 + //$$ ((GameRendererAccessor) UMinecraft.getMinecraft().gameRenderer).invokeLoadShader(this.blurShader); + //#else UMinecraft.getMinecraft().entityRenderer.loadShader(this.blurShader); + //#endif this.start = System.currentTimeMillis(); this.progress = 0; diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java b/versions/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java index 23d7d84..d49ea5d 100644 --- a/versions/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java +++ b/versions/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java @@ -32,11 +32,6 @@ public class MinecraftMixin { Runtime.getRuntime().addShutdownHook(new Thread(() -> EventManager.INSTANCE.post(new ShutdownEvent()))); } - @Inject(method = "startGame", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/client/FMLClientHandler;beginMinecraftLoading(Lnet/minecraft/client/Minecraft;Ljava/util/List;Lnet/minecraft/client/resources/IReloadableResourceManager;)V", remap = false), remap = true) - private void onPreLaunch(CallbackInfo ci) { - OneConfig.preLaunch(); - } - @Inject(method = "startGame", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/client/FMLClientHandler;onInitializationComplete()V", shift = At.Shift.AFTER, remap = false), remap = true) private void onInit(CallbackInfo ci) { EventManager.INSTANCE.post(new InitializationEvent()); diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/internal/mixin/RenderPigMixin.java b/versions/src/main/java/cc/polyfrost/oneconfig/internal/mixin/RenderPigMixin.java deleted file mode 100644 index 1bd1fae..0000000 --- a/versions/src/main/java/cc/polyfrost/oneconfig/internal/mixin/RenderPigMixin.java +++ /dev/null @@ -1,25 +0,0 @@ -//#if MC<=11202 -package cc.polyfrost.oneconfig.internal.mixin; - -import cc.polyfrost.oneconfig.internal.eggs.TechnobladeCrownRenderer; -import net.minecraft.client.model.ModelBase; -import net.minecraft.client.renderer.entity.RenderLiving; -import net.minecraft.client.renderer.entity.RenderManager; -import net.minecraft.client.renderer.entity.RenderPig; -import net.minecraft.entity.passive.EntityPig; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(RenderPig.class) -public abstract class RenderPigMixin extends RenderLiving<EntityPig> { - public RenderPigMixin(RenderManager renderManager, ModelBase modelBase, float f) { - super(renderManager, modelBase, f); - } - @Inject(method = "<init>", at = @At("TAIL")) - private void addCrown(RenderManager renderManager, ModelBase modelBase, float f, CallbackInfo ci) { - addLayer(new TechnobladeCrownRenderer<>((RenderPig) (Object) this)); - } -} -//#endif
\ No newline at end of file diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigMixinPlugin.java b/versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigMixinPlugin.java index 6a76a09..0ef5414 100644 --- a/versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigMixinPlugin.java +++ b/versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigMixinPlugin.java @@ -43,11 +43,16 @@ public class OneConfigMixinPlugin implements IMixinConfigPlugin { public List<String> getMixins() { if (Platform.getInstance().getMinecraftVersion() >= 11600) { ArrayList<String> mixins = new ArrayList<>(); - mixins.add("ClientModLoaderMixin"); - mixins.add("KeyboardListenerMixin"); - mixins.add("MouseHelperAccessor"); - mixins.add("MouseHelperMixin"); - mixins.add("TimeTrackerMixin"); + if (Platform.getInstance().getLoader() == Platform.Loader.FORGE) { + mixins.add("ClientModLoaderMixin"); + } else { + mixins.add("FramebufferMixin"); + mixins.add("GameRendererAccessor"); + } + mixins.add("KeyboardMixin"); + mixins.add("MouseAccessor"); + mixins.add("MouseMixin"); + mixins.add("TickTimeTrackerMixin"); return mixins; } else { return null; diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/GLPlatformImpl.java b/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/GLPlatformImpl.java index b53b357..16ff25c 100644 --- a/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/GLPlatformImpl.java +++ b/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/GLPlatformImpl.java @@ -7,9 +7,13 @@ import cc.polyfrost.oneconfig.platform.GLPlatform; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; + +//#if FORGE==1 import net.minecraft.client.shader.Framebuffer; +//#else +//$$ import cc.polyfrost.oneconfig.internal.hook.FramebufferHook; +//#endif -@SuppressWarnings("unused") public class GLPlatformImpl implements GLPlatform { @Override @@ -48,7 +52,11 @@ public class GLPlatformImpl implements GLPlatform { @Override public void enableStencil() { + //#if FORGE==1 Framebuffer framebuffer = UMinecraft.getMinecraft().getFramebuffer(); + //#else + //$$ FramebufferHook framebuffer = ((FramebufferHook) UMinecraft.getMinecraft().getFramebuffer()); + //#endif if (!framebuffer.isStencilEnabled()) { framebuffer.enableStencil(); } diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/GuiPlatformImpl.java b/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/GuiPlatformImpl.java index 6ea3c03..e4628c1 100644 --- a/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/GuiPlatformImpl.java +++ b/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/GuiPlatformImpl.java @@ -6,7 +6,6 @@ import cc.polyfrost.oneconfig.platform.GuiPlatform; import net.minecraft.client.gui.GuiChat; import net.minecraft.client.gui.GuiScreen; -@SuppressWarnings("unused") public class GuiPlatformImpl implements GuiPlatform { @Override diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/I18nPlatformImpl.java b/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/I18nPlatformImpl.java index 1913238..6245bc4 100644 --- a/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/I18nPlatformImpl.java +++ b/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/I18nPlatformImpl.java @@ -3,7 +3,6 @@ package cc.polyfrost.oneconfig.platform.impl; import cc.polyfrost.oneconfig.platform.I18nPlatform; import net.minecraft.client.resources.I18n; -@SuppressWarnings("unused") public class I18nPlatformImpl implements I18nPlatform { @Override diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/LoaderPlatformImpl.java b/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/LoaderPlatformImpl.java index c984ac3..f4a78ac 100644 --- a/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/LoaderPlatformImpl.java +++ b/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/LoaderPlatformImpl.java @@ -2,17 +2,26 @@ package cc.polyfrost.oneconfig.platform.impl; import cc.polyfrost.oneconfig.platform.LoaderPlatform; //#if MC>=11600 -//$$ import net.minecraftforge.fml.ModList; + //#if FORGE==1 + //$$ import net.minecraftforge.fml.ModList; + //#else + //$$ import net.fabricmc.loader.api.FabricLoader; + //#endif //#endif +//#if FORGE==1 import net.minecraftforge.fml.common.Loader; import net.minecraftforge.fml.common.ModContainer; +//#endif -@SuppressWarnings("unused") public class LoaderPlatformImpl implements LoaderPlatform { @Override public boolean isModLoaded(String id) { //#if MC>=11600 - //$$ return ModList.get().isLoaded(id); + //#if FORGE==1 + //$$ return ModList.get().isLoaded(id); + //#else + //$$ return FabricLoader.getInstance().isModLoaded(id); + //#endif //#else return Loader.isModLoaded(id); //#endif @@ -20,17 +29,25 @@ public class LoaderPlatformImpl implements LoaderPlatform { @Override public boolean hasActiveModContainer() { + //#if FORGE==1 return Loader.instance().activeModContainer() != null; + //#else + //$$ return false; + //#endif } @Override public ActiveMod getActiveModContainer() { + //#if FORGE==1 ModContainer container = Loader.instance().activeModContainer(); if (container == null) return null; - //#if MC==11202 - return new ActiveMod(container.getName(), container.getModId(), container.getVersion()); + //#if MC==11202 + return new ActiveMod(container.getName(), container.getModId(), container.getVersion()); + //#else + //$$ return new ActiveMod(container.getModInfo().getDisplayName(), container.getModId(), container.getModInfo().getVersion().getQualifier()); + //#endif //#else - //$$ return new ActiveMod(container.getModInfo().getDisplayName(), container.getModId(), container.getModInfo().getVersion().getQualifier()); + //$$ return null; //#endif } } diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/MousePlatformImpl.java b/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/MousePlatformImpl.java index e368a91..74fdd04 100644 --- a/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/MousePlatformImpl.java +++ b/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/MousePlatformImpl.java @@ -3,13 +3,12 @@ package cc.polyfrost.oneconfig.platform.impl; import cc.polyfrost.oneconfig.platform.MousePlatform; //#if MC>=11600 //$$ import cc.polyfrost.oneconfig.libs.universal.UMinecraft; -//$$ import cc.polyfrost.oneconfig.internal.mixin.MouseHelperAccessor; +//$$ import cc.polyfrost.oneconfig.internal.mixin.MouseAccessor; //$$ import org.lwjgl.glfw.GLFW; //#else import org.lwjgl.input.Mouse; //#endif -@SuppressWarnings("unused") public class MousePlatformImpl implements MousePlatform { //#if MC>11600 @@ -37,7 +36,7 @@ public class MousePlatformImpl implements MousePlatform { @Override public double getDWheel() { //#if MC>=11600 - //$$ double scrollDelta = ((MouseHelperAccessor) UMinecraft.getMinecraft().mouseHelper).getAccumulatedScrollDelta(); + //$$ double scrollDelta = ((MouseAccessor) UMinecraft.getMinecraft().mouseHelper).getEventDeltaWheel(); //$$ double amount = scrollDelta - prevScroll; //$$ prevScroll = scrollDelta; //$$ return amount; @@ -49,7 +48,11 @@ public class MousePlatformImpl implements MousePlatform { @Override public double getMouseDX() { //#if MC>=11600 - //$$ return UMinecraft.getMinecraft().mouseHelper.getXVelocity(); + //#if FORGE==1 + //$$ return UMinecraft.getMinecraft().mouseHelper.getXVelocity(); + //#else + //$$ return ((MouseAccessor) UMinecraft.getMinecraft().mouse).getCursorDeltaX(); + //#endif //#else return Mouse.getDX(); //#endif @@ -58,7 +61,11 @@ public class MousePlatformImpl implements MousePlatform { @Override public double getMouseDY() { //#if MC>=11600 - //$$ return UMinecraft.getMinecraft().mouseHelper.getYVelocity(); + //#if FORGE==1 + //$$ return UMinecraft.getMinecraft().mouseHelper.getYVelocity(); + //#else + //$$ return ((MouseAccessor) UMinecraft.getMinecraft().mouse).getCursorDeltaY(); + //#endif //#else return Mouse.getDY(); //#endif diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/NanoVGPlatformImpl.java b/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/NanoVGPlatformImpl.java new file mode 100644 index 0000000..8469fcc --- /dev/null +++ b/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/NanoVGPlatformImpl.java @@ -0,0 +1,88 @@ +package cc.polyfrost.oneconfig.platform.impl; + +import cc.polyfrost.oneconfig.platform.NanoVGPlatform; +import org.jetbrains.annotations.Nullable; +import org.lwjgl.nanovg.NVGLUFramebuffer; +import org.lwjgl.nanovg.NanoVGGL2; + +public class NanoVGPlatformImpl implements NanoVGPlatform { + @Override + public int nnvglCreateImageFromHandle(long var0, int var2, int var3, int var4, int var5) { + return NanoVGGL2.nnvglCreateImageFromHandle(var0, var2, var3, var4, var5); + } + + @Override + public int nvglCreateImageFromHandle(long ctx, int textureId, int w, int h, int flags) { + return NanoVGGL2.nvglCreateImageFromHandle(ctx, textureId, w, h, flags); + } + + @Override + public int nnvglImageHandle(long var0, int var2) { + return NanoVGGL2.nnvglImageHandle(var0, var2); + } + + @Override + public int nvglImageHandle(long ctx, int image) { + return NanoVGGL2.nvglImageHandle(ctx, image); + } + + @Override + public long nnvgCreate(int var0) { + return NanoVGGL2.nnvgCreate(var0); + } + + @Override + public long nvgCreate(int flags) { + return NanoVGGL2.nvgCreate(flags); + } + + @Override + public void nnvgDelete(long var0) { + NanoVGGL2.nnvgDelete(var0); + } + + @Override + public void nvgDelete(long ctx) { + NanoVGGL2.nvgDelete(ctx); + } + + @Override + public long nnvgluCreateFramebuffer(long var0, int var2, int var3, int var4) { + return NanoVGGL2.nnvgluCreateFramebuffer(var0, var2, var3, var4); + } + + @Nullable + @Override + public NVGLUFramebuffer nvgluCreateFramebuffer(long ctx, int w, int h, int imageFlags) { + return NanoVGGL2.nvgluCreateFramebuffer(ctx, w, h, imageFlags); + } + + @Override + public void nnvgluBindFramebuffer(long var0, long var2) { + NanoVGGL2.nnvgluBindFramebuffer(var0, var2); + } + + @Override + public void nvgluBindFramebuffer(long ctx, @Nullable NVGLUFramebuffer fb) { + NanoVGGL2.nvgluBindFramebuffer(ctx, fb); + } + + @Override + public void nnvgluDeleteFramebuffer(long var0, long var2) { + NanoVGGL2.nnvgluDeleteFramebuffer(var0, var2); + } + + @Override + public void nvgluDeleteFramebuffer(long ctx, NVGLUFramebuffer fb) { + NanoVGGL2.nvgluDeleteFramebuffer(ctx, fb); + } + + @Override + public void triggerStaticInitialization() { + try { + Class.forName(NanoVGGL2.class.getName()); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/PlatformImpl.java b/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/PlatformImpl.java index 91edc53..ef22285 100644 --- a/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/PlatformImpl.java +++ b/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/PlatformImpl.java @@ -3,7 +3,6 @@ package cc.polyfrost.oneconfig.platform.impl; import cc.polyfrost.oneconfig.platform.Platform; import net.minecraft.client.Minecraft; -@SuppressWarnings("unused") public class PlatformImpl implements Platform { @Override public boolean isCallingFromMinecraftThread() { @@ -38,4 +37,13 @@ public class PlatformImpl implements Platform { return 10800; //#endif } + + @Override + public Loader getLoader() { + //#if FORGE==1 + return Loader.FORGE; + //#else + //$$ return Loader.FABRIC; + //#endif + } } diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/ServerPlatformImpl.java b/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/ServerPlatformImpl.java index 81454b0..8f145d3 100644 --- a/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/ServerPlatformImpl.java +++ b/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/ServerPlatformImpl.java @@ -4,7 +4,6 @@ import cc.polyfrost.oneconfig.libs.universal.UMinecraft; import cc.polyfrost.oneconfig.platform.ServerPlatform; import net.minecraft.client.entity.EntityPlayerSP; -@SuppressWarnings("unused") public class ServerPlatformImpl implements ServerPlatform { @Override diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/test/TestBasicHud_Test.java b/versions/src/main/java/cc/polyfrost/oneconfig/test/TestBasicHud_Test.java new file mode 100644 index 0000000..805937f --- /dev/null +++ b/versions/src/main/java/cc/polyfrost/oneconfig/test/TestBasicHud_Test.java @@ -0,0 +1,23 @@ +package cc.polyfrost.oneconfig.test; + +import cc.polyfrost.oneconfig.hud.BasicHud; +import cc.polyfrost.oneconfig.internal.assets.Images; +import cc.polyfrost.oneconfig.libs.universal.UMatrixStack; +import cc.polyfrost.oneconfig.renderer.RenderManager; + +public class TestBasicHud_Test extends BasicHud { + @Override + protected void draw(UMatrixStack matrices, float x, float y, float scale, boolean example) { + RenderManager.setupAndDraw(true, vg -> RenderManager.drawImage(vg, Images.HUE_GRADIENT, x, y, 50 * scale, 50f * scale)); + } + + @Override + protected float getWidth(float scale, boolean example) { + return 50 * scale; + } + + @Override + protected float getHeight(float scale, boolean example) { + return 50 * scale; + } +} diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/test/TestConfig_Test.java b/versions/src/main/java/cc/polyfrost/oneconfig/test/TestConfig_Test.java index 772bba7..09b3fe5 100644 --- a/versions/src/main/java/cc/polyfrost/oneconfig/test/TestConfig_Test.java +++ b/versions/src/main/java/cc/polyfrost/oneconfig/test/TestConfig_Test.java @@ -126,6 +126,12 @@ public class TestConfig_Test extends Config { ) public TestMultilineHud_Test multilineHud = new TestMultilineHud_Test(); + @HUD( + name = "Test Basic HUD", + category = "HUD" + ) + public TestBasicHud_Test basicHud = new TestBasicHud_Test(); + public TestConfig_Test() { super(new Mod("Test Mod", ModType.UTIL_QOL, new VigilanceMigrator("./config/testConfig.toml")), "hacksConfig.json"); initialize(); diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/test/TestHud_Test.java b/versions/src/main/java/cc/polyfrost/oneconfig/test/TestHud_Test.java index ae557c7..4b380ca 100644 --- a/versions/src/main/java/cc/polyfrost/oneconfig/test/TestHud_Test.java +++ b/versions/src/main/java/cc/polyfrost/oneconfig/test/TestHud_Test.java @@ -15,7 +15,7 @@ public class TestHud_Test extends SingleTextHud { } @Override - public String getText() { + public String getText(boolean example) { times++; return String.valueOf(times); } diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/test/TestKotlinNanoVGGui_Test.kt b/versions/src/main/java/cc/polyfrost/oneconfig/test/TestKotlinNanoVGGui_Test.kt new file mode 100644 index 0000000..fd6df6b --- /dev/null +++ b/versions/src/main/java/cc/polyfrost/oneconfig/test/TestKotlinNanoVGGui_Test.kt @@ -0,0 +1,45 @@ +package cc.polyfrost.oneconfig.test + +import cc.polyfrost.oneconfig.renderer.font.Fonts +import cc.polyfrost.oneconfig.utils.dsl.* +import cc.polyfrost.oneconfig.utils.gui.OneUIScreen +import java.awt.Color +import kotlin.system.measureTimeMillis + +/** + * A kotlinified version of [TestNanoVGGui_Test]. + * Uses OneConfig's Kotlin DSL to render instead of RenderManager + * + * @see nanoVG + * @see TestNanoVGGui_Test + */ +class TestKotlinNanoVGGui_Test : OneUIScreen() { + + override fun draw(vg: Long, partialTicks: Float) { + nanoVG(vg) { + val millis = measureTimeMillis { + drawRect(0f, 0f, 100f, 100f, Color.BLUE.rgb) + drawRoundedRect( + 305f, 305f, 100f, 100f, 8f, Color.YELLOW.rgb + ) + drawText( + "Hello!", 100f, 100f, Color.WHITE.rgb, 50f, Fonts.BOLD + ) + drawLine( + 0f, 0f, 100f, 100f, 7f, Color.PINK.rgb + ) + drawCircle( + 200f, 200f, 50f, Color.WHITE.rgb + ) + } + drawText( + millis.toString() + "ms", + 500f, + 500f, + Color.WHITE.rgb, + 100f, + Fonts.BOLD + ) + } + } +}
\ No newline at end of file diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/test/TestMultilineHud_Test.java b/versions/src/main/java/cc/polyfrost/oneconfig/test/TestMultilineHud_Test.java index 1665062..f71b01d 100644 --- a/versions/src/main/java/cc/polyfrost/oneconfig/test/TestMultilineHud_Test.java +++ b/versions/src/main/java/cc/polyfrost/oneconfig/test/TestMultilineHud_Test.java @@ -10,7 +10,8 @@ public class TestMultilineHud_Test extends TextHud { } @Override - protected void getLines(List<String> lines) { + protected void getLines(List<String> lines, boolean example) { lines.add(String.valueOf(System.currentTimeMillis())); + lines.add("HEY!"); } } diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/test/TestNanoVGGui_Test.java b/versions/src/main/java/cc/polyfrost/oneconfig/test/TestNanoVGGui_Test.java index e8b6b91..4182bb6 100644 --- a/versions/src/main/java/cc/polyfrost/oneconfig/test/TestNanoVGGui_Test.java +++ b/versions/src/main/java/cc/polyfrost/oneconfig/test/TestNanoVGGui_Test.java @@ -2,25 +2,27 @@ package cc.polyfrost.oneconfig.test; import cc.polyfrost.oneconfig.renderer.RenderManager; import cc.polyfrost.oneconfig.renderer.font.Fonts; -import cc.polyfrost.oneconfig.libs.universal.UMatrixStack; -import cc.polyfrost.oneconfig.libs.universal.UScreen; -import org.jetbrains.annotations.NotNull; +import cc.polyfrost.oneconfig.utils.gui.OneUIScreen; import java.awt.*; -public class TestNanoVGGui_Test extends UScreen { +/** + * A GUI that uses RenderManager, NanoVG, and OneUIScreen to render a simple GUI. + * + * @see OneUIScreen + * @see TestKotlinNanoVGGui_Test + * @see RenderManager + */ +public class TestNanoVGGui_Test extends OneUIScreen { @Override - public void onDrawScreen(@NotNull UMatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { - super.onDrawScreen(matrixStack, mouseX, mouseY, partialTicks); + public void draw(long vg, float partialTicks) { long startTime = System.nanoTime(); - RenderManager.setupAndDraw((vg) -> { - RenderManager.drawRect(vg, 0, 0, 100, 100, Color.BLUE.getRGB()); - RenderManager.drawRoundedRect(vg, 305, 305, 100, 100, Color.YELLOW.getRGB(), 8); - RenderManager.drawText(vg, "Hello!", 100, 100, Color.WHITE.getRGB(), 50, Fonts.BOLD); - RenderManager.drawLine(vg, 0, 0, 100, 100, 7, Color.PINK.getRGB()); - RenderManager.drawCircle(vg, 200, 200, 50, Color.WHITE.getRGB()); - RenderManager.drawText(vg, (float) (System.nanoTime() - startTime) / 1000000f + "ms", 500, 500, Color.WHITE.getRGB(), 100, Fonts.BOLD); - }); + RenderManager.drawRect(vg, 0, 0, 100, 100, Color.BLUE.getRGB()); + RenderManager.drawRoundedRect(vg, 305, 305, 100, 100, Color.YELLOW.getRGB(), 8); + RenderManager.drawText(vg, "Hello!", 100, 100, Color.WHITE.getRGB(), 50, Fonts.BOLD); + RenderManager.drawLine(vg, 0, 0, 100, 100, 7, Color.PINK.getRGB()); + RenderManager.drawCircle(vg, 200, 200, 50, Color.WHITE.getRGB()); + RenderManager.drawText(vg, (float) (System.nanoTime() - startTime) / 1000000f + "ms", 500, 500, Color.WHITE.getRGB(), 100, Fonts.BOLD); } } diff --git a/versions/src/main/resources/META-INF/services/cc.polyfrost.oneconfig.platform.NanoVGPlatform b/versions/src/main/resources/META-INF/services/cc.polyfrost.oneconfig.platform.NanoVGPlatform new file mode 100644 index 0000000..7d256b7 --- /dev/null +++ b/versions/src/main/resources/META-INF/services/cc.polyfrost.oneconfig.platform.NanoVGPlatform @@ -0,0 +1 @@ +cc.polyfrost.oneconfig.platform.impl.NanoVGPlatformImpl
\ No newline at end of file diff --git a/versions/src/main/resources/fabric.mod.json b/versions/src/main/resources/fabric.mod.json new file mode 100644 index 0000000..23d8e97 --- /dev/null +++ b/versions/src/main/resources/fabric.mod.json @@ -0,0 +1,35 @@ +{ + "schemaVersion": 1, + "id": "${id}", + "name": "${name}", + "version": "${version}", + "description": "OneConfig", + "authors": [ + "Polyfrost" + ], + "contact": { + "homepage": "https://polyfrost.cc", + "sources": "https://github.com/Polyfrost/OneConfig", + "issues": "https://inv.wtf/polyfrost" + }, + "license": "LGPL-3.0", + "environment": "client", + "mixins": [ + "mixins.oneconfig.json" + ], + "entrypoints": { + "preLaunch": [ + "cc.polyfrost.oneconfig.internal.plugin.OneConfigPreLaunch" + ] + }, + "depends": { + "fabricloader": ">=0.12.0", + "minecraft": "${mcVersionStr}", + "java": ">=${java}" + }, + "custom": { + "modmenu": { + "badges": [ "library" ] + } + } +}
\ No newline at end of file diff --git a/versions/src/main/resources/mixins.oneconfig.json b/versions/src/main/resources/mixins.oneconfig.json index 1486c9d..4a03fd0 100644 --- a/versions/src/main/resources/mixins.oneconfig.json +++ b/versions/src/main/resources/mixins.oneconfig.json @@ -14,7 +14,6 @@ "NetHandlerPlayClientMixin", "NetworkManagerMixin", "OptifineConfigMixin", - "RenderPigMixin", "ShaderGroupAccessor", "VigilantMixin", "WorldClientMixin" |