diff --git a/build.gradle.kts b/build.gradle.kts index b66e18b..7dfba54 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,75 +1,37 @@ @file:Suppress("UnstableApiUsage", "PropertyName") -import org.polyfrost.gradle.util.noServerRunConfigs -import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar +import dev.deftu.gradle.utils.GameSide -// Adds support for kotlin, and adds the Polyfrost Gradle Toolkit -// which we use to prepare the environment. plugins { - kotlin("jvm") - id("org.polyfrost.multi-version") - id("org.polyfrost.defaults.repo") - id("org.polyfrost.defaults.java") - id("org.polyfrost.defaults.loom") - id("com.github.johnrengelman.shadow") - id("net.kyori.blossom") version "1.3.2" - id("signing") java + kotlin("jvm") + id("dev.deftu.gradle.multiversion") + id("dev.deftu.gradle.tools") + id("dev.deftu.gradle.tools.resources") + id("dev.deftu.gradle.tools.bloom") + id("dev.deftu.gradle.tools.shadow") + id("dev.deftu.gradle.tools.minecraft.loom") } -// Gets the mod name, version and id from the `gradle.properties` file. -val mod_name: String by project -val mod_version: String by project -val mod_id: String by project -val mod_archives_name: String by project - -// Replaces the variables in `ExampleMod.java` to the ones specified in `gradle.properties`. -blossom { - replaceToken("@VER@", mod_version) - replaceToken("@NAME@", mod_name) - replaceToken("@ID@", mod_id) -} - -// Sets the mod version to the one specified in `gradle.properties`. Make sure to change this following semver! -version = mod_version -// Sets the group, make sure to change this to your own. It can be a website you own backwards or your GitHub username. -// e.g. com.github. or com. -group = "org.polyfrost" - -// Sets the name of the output jar (the one you put in your mods folder and send to other people) -// It outputs all versions of the mod into the `build` directory. -base { - archivesName.set("$mod_archives_name-$platform") -} +toolkitLoomHelper { + // Adds OneConfig to our project + useOneConfig(mcData, "commands", "config", "config-impl", "events", "internal", "ui") + useDevAuth() -// Configures the Polyfrost Loom, our plugin fork to easily set up the programming environment. -loom { // Removes the server configs from IntelliJ IDEA, leaving only client runs. // If you're developing a server-side mod, you can remove this line. - noServerRunConfigs() + disableRunConfigs(GameSide.SERVER) - // Adds the tweak class if we are building legacy version of forge as per the documentation (https://docs.polyfrost.org) - if (project.platform.isLegacyForge) { - runConfigs { - "client" { - programArgs("--tweakClass", "cc.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker") - property("mixin.debug.export", "true") - } - } - } - // Configures the mixins if we are building for forge, useful for when we are dealing with cross-platform projects. - if (project.platform.isForge) { - forge { - mixinConfig("mixins.${mod_id}.json") - } + // Sets up our Mixin refmap naming + if (!mcData.isNeoForge) { + useMixinRefMap(modData.id) } - // Configures the name of the mixin "refmap" using an experimental loom api. - mixin.defaultRefmapName.set("mixins.${mod_id}.refmap.json") -} -// Creates the shade/shadow configuration, so we can include libraries inside our mod, rather than having to add them separately. -val shade: Configuration by configurations.creating { - configurations.implementation.get().extendsFrom(this) + // Adds the tweak class if we are building legacy version of forge as per the documentation (https://docs.polyfrost.org) + if (mcData.isLegacyForge) { + useTweaker("org.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker", GameSide.CLIENT) + useForgeMixin(modData.id) // Configures the mixins if we are building for forge, useful for when we are dealing with cross-platform projects. + } } // Configures the output directory for when building from the `src/resources` directory. @@ -84,109 +46,14 @@ sourceSets { // Adds the Polyfrost maven repository so that we can get the libraries necessary to develop the mod. repositories { + mavenLocal() maven("https://repo.polyfrost.org/releases") } // Configures the libraries/dependencies for your mod. dependencies { - // Adds the OneConfig library, so we can develop with it. - modCompileOnly("cc.polyfrost:oneconfig-$platform:0.2.2-alpha+") - - modRuntimeOnly("me.djtheredstoner:DevAuth-${if (platform.isFabric) "fabric" else if (platform.isLegacyForge) "forge-legacy" else "forge-latest"}:1.1.2") - // If we are building for legacy forge, includes the launch wrapper with `shade` as we configured earlier. - if (platform.isLegacyForge) { + if (mcData.isLegacyForge) { compileOnly("org.spongepowered:mixin:0.7.11-SNAPSHOT") - shade("cc.polyfrost:oneconfig-wrapper-launchwrapper:1.0.0-beta17") - } -} - -tasks { - // Processes the `src/resources/mcmod.info or fabric.mod.json` and replaces - // the mod id, name and version with the ones in `gradle.properties` - processResources { - inputs.property("id", mod_id) - inputs.property("name", mod_name) - val java = if (project.platform.mcMinor >= 18) { - 17 // If we are playing on version 1.18, set the java version to 17 - } else { - // Else if we are playing on version 1.17, use java 16. - if (project.platform.mcMinor == 17) - 16 - else - 8 // For all previous versions, we **need** java 8 (for Forge support). - } - val compatLevel = "JAVA_${java}" - inputs.property("java", java) - inputs.property("java_level", compatLevel) - inputs.property("version", mod_version) - inputs.property("mcVersionStr", project.platform.mcVersionStr) - filesMatching(listOf("mcmod.info", "mixins.${mod_id}.json", "mods.toml")) { - expand( - mapOf( - "id" to mod_id, - "name" to mod_name, - "java" to java, - "java_level" to compatLevel, - "version" to mod_version, - "mcVersionStr" to project.platform.mcVersionStr - ) - ) - } - filesMatching("fabric.mod.json") { - expand( - mapOf( - "id" to mod_id, - "name" to mod_name, - "java" to java, - "java_level" to compatLevel, - "version" to mod_version, - "mcVersionStr" to project.platform.mcVersionStr.substringBeforeLast(".") + ".x" - ) - ) - } - } - - // Configures the resources to include if we are building for forge or fabric. - withType(Jar::class.java) { - if (project.platform.isFabric) { - exclude("mcmod.info", "mods.toml") - } else { - exclude("fabric.mod.json") - if (project.platform.isLegacyForge) { - exclude("mods.toml") - } else { - exclude("mcmod.info") - } - } - } - - // Configures our shadow/shade configuration, so we can - // include some dependencies within our mod jar file. - named("shadowJar") { - archiveClassifier.set("dev") // TODO: machete gets confused by the `dev` prefix. - configurations = listOf(shade) - duplicatesStrategy = DuplicatesStrategy.EXCLUDE - } - - remapJar { - inputFile.set(shadowJar.get().archiveFile) - archiveClassifier.set("") - } - - jar { - // Sets the jar manifest attributes. - if (platform.isLegacyForge) { - manifest.attributes += mapOf( - "ModSide" to "CLIENT", // We aren't developing a server-side mod, so this is fine. - "ForceLoadAsMod" to true, // We want to load this jar as a mod, so we force Forge to do so. - "TweakOrder" to "0", // Makes sure that the OneConfig launch wrapper is loaded as soon as possible. - "MixinConfigs" to "mixins.${mod_id}.json", // We want to use our mixin configuration, so we specify it here. - "TweakClass" to "cc.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker" // Loads the OneConfig launch wrapper. - ) - } - dependsOn(shadowJar) - archiveClassifier.set("") - enabled = false } } diff --git a/gradle.properties b/gradle.properties index a33a772..f6bf04e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,13 +1,13 @@ -# gradle.properties file -- CHANGE THE VALUES STARTING WITH `mod_*` AND REMOVE THIS COMMENT. +# gradle.properties file -- CHANGE THE VALUES STARTING WITH `mod.*` AND REMOVE THIS COMMENT. # Sets the name of your mod. -mod_name=PolyCrosshair +mod.name=PolyCrosshair # Sets the id of your mod that mod loaders use to recognize it. -mod_id=polycrosshair +mod.id=polycrosshair # Sets the version of your mod. Make sure to update this when you make changes according to semver. -mod_version=1.0.3 +mod.version=1.0.3 # Sets the name of the jar file that you put in your 'mods' folder. -mod_archives_name=PolyCrosshair +mod.group=org.polyfrost # Gradle Configuration -- DO NOT TOUCH THESE VALUES. polyfrost.defaults.loom=3 diff --git a/root.gradle.kts b/root.gradle.kts index 87b0240..a013e9f 100644 --- a/root.gradle.kts +++ b/root.gradle.kts @@ -1,11 +1,7 @@ plugins { - kotlin("jvm") version "1.9.10" apply false - id("org.polyfrost.multi-version.root") - id("com.github.johnrengelman.shadow") version "8.1.1" apply false + id("dev.deftu.gradle.multiversion-root") } preprocess { - "1.12.2-forge"(11202, "srg") { - "1.8.9-forge"(10809, "srg") - } + "1.8.9-forge"(10809, "srg") } diff --git a/settings.gradle.kts b/settings.gradle.kts index a8b5001..70cb3f4 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,21 +1,34 @@ -@file:Suppress("PropertyName") +import groovy.lang.MissingPropertyException pluginManagement { repositories { + // Repositories + maven("https://maven.deftu.dev/releases") + maven("https://maven.fabricmc.net") + maven("https://maven.architectury.dev/") + maven("https://maven.minecraftforge.net") + maven("https://repo.essential.gg/repository/maven-public") + maven("https://server.bbkr.space/artifactory/libs-release/") + maven("https://jitpack.io/") + + // Snapshots + maven("https://maven.deftu.dev/snapshots") + mavenLocal() + + // Default repositories gradlePluginPortal() mavenCentral() - maven("https://repo.polyfrost.org/releases") // Adds the Polyfrost maven repository to get Polyfrost Gradle Toolkit } + plugins { - val pgtVersion = "0.6.2" // Sets the default versions for Polyfrost Gradle Toolkit - id("org.polyfrost.multi-version.root") version pgtVersion + kotlin("jvm") version("2.0.0") + id("dev.deftu.gradle.multiversion-root") version("2.11.2") } } -val mod_name: String by settings - -// Configures the root project Gradle name based on the value in `gradle.properties` -rootProject.name = mod_name +val projectName: String = extra["mod.name"]?.toString() + ?: throw MissingPropertyException("mod.name has not been set.") +rootProject.name = projectName rootProject.buildFileName = "root.gradle.kts" // Adds all of our build target versions to the classpath if we need to add version-specific code. @@ -27,4 +40,4 @@ listOf( projectDir = file("versions/$version") buildFileName = "../../build.gradle.kts" } -} +} \ No newline at end of file diff --git a/src/main/java/org/polyfrost/crosshair/mixin/GuiIngameMixin.java b/src/main/java/org/polyfrost/crosshair/mixin/GuiIngameMixin.java index 7a06f72..ef22656 100644 --- a/src/main/java/org/polyfrost/crosshair/mixin/GuiIngameMixin.java +++ b/src/main/java/org/polyfrost/crosshair/mixin/GuiIngameMixin.java @@ -2,7 +2,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiIngame; -import org.polyfrost.crosshair.config.ModConfig; +import org.polyfrost.crosshair.config.PolyCrosshairConfig; import org.polyfrost.crosshair.config.RenderConfig; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.*; @@ -12,9 +12,9 @@ public class GuiIngameMixin { @Inject(method = "showCrosshair", at = @At("HEAD"), cancellable = true) private void check(CallbackInfoReturnable cir) { - RenderConfig cfg = ModConfig.INSTANCE.getRenderConfig(); + RenderConfig cfg = PolyCrosshairConfig.INSTANCE.getRenderConfig(); Minecraft mc = Minecraft.getMinecraft(); - if (!ModConfig.INSTANCE.enabled) return; + if (!PolyCrosshairConfig.INSTANCE.enabled) return; if ((!cfg.getShowInGuis() && mc.currentScreen != null) || (!cfg.getShowInThirdPerson() && mc.gameSettings.thirdPersonView != 0)) { cir.setReturnValue(false); } diff --git a/src/main/kotlin/org/polyfrost/crosshair/PolyCrosshair.kt b/src/main/kotlin/org/polyfrost/crosshair/PolyCrosshair.kt index 7f12c3d..74387ca 100644 --- a/src/main/kotlin/org/polyfrost/crosshair/PolyCrosshair.kt +++ b/src/main/kotlin/org/polyfrost/crosshair/PolyCrosshair.kt @@ -1,27 +1,26 @@ package org.polyfrost.crosshair -import cc.polyfrost.oneconfig.config.core.ConfigUtils -import cc.polyfrost.oneconfig.events.EventManager -import cc.polyfrost.oneconfig.events.event.ShutdownEvent -import cc.polyfrost.oneconfig.libs.eventbus.Subscribe import net.minecraftforge.common.MinecraftForge import net.minecraftforge.fml.common.Mod import net.minecraftforge.fml.common.event.FMLInitializationEvent import net.minecraftforge.fml.common.event.FMLPostInitializationEvent -import org.polyfrost.crosshair.config.ModConfig +import org.polyfrost.crosshair.config.PolyCrosshairConfig import org.polyfrost.crosshair.render.CrosshairRenderer +import org.polyfrost.oneconfig.api.event.v1.EventManager +import org.polyfrost.oneconfig.api.event.v1.events.ShutdownEvent +import org.polyfrost.oneconfig.api.event.v1.invoke.impl.Subscribe import java.io.File @Mod( modid = PolyCrosshair.MODID, name = PolyCrosshair.NAME, version = PolyCrosshair.VERSION, - modLanguageAdapter = "cc.polyfrost.oneconfig.utils.KotlinLanguageAdapter" + modLanguageAdapter = "org.polyfrost.oneconfig.utils.v1.forge.KotlinLanguageAdapter" ) object PolyCrosshair { - const val MODID = "@ID@" - const val NAME = "@NAME@" - const val VERSION = "@VER@" + const val MODID = "@MOD_ID@" + const val NAME = "@MOD_NAME@" + const val VERSION = "@MOD_VERSION@" val path = "${ConfigUtils.getProfileDir().absolutePath}/${MODID}/caches/" @@ -31,7 +30,7 @@ object PolyCrosshair { fun onFMLInitialization(event: FMLInitializationEvent) { clearCaches() dir.mkdirs() - ModConfig + PolyCrosshairConfig MinecraftForge.EVENT_BUS.register(CrosshairRenderer) EventManager.INSTANCE.register(this) } diff --git a/src/main/kotlin/org/polyfrost/crosshair/config/CrosshairEntry.kt b/src/main/kotlin/org/polyfrost/crosshair/config/CrosshairEntry.kt index e482bd7..9887cb2 100644 --- a/src/main/kotlin/org/polyfrost/crosshair/config/CrosshairEntry.kt +++ b/src/main/kotlin/org/polyfrost/crosshair/config/CrosshairEntry.kt @@ -29,9 +29,9 @@ class CrosshairEntry( @Button(name = "Transform", text = "Reset", size = 1) var transformReset = Runnable { runAsync { - val img = ModConfig.newCurrentCrosshair.img - ModConfig.newCurrentCrosshair.loadFrom(CrosshairEntry()) - ModConfig.newCurrentCrosshair.img = img + val img = PolyCrosshairConfig.newCurrentCrosshair.img + PolyCrosshairConfig.newCurrentCrosshair.loadFrom(CrosshairEntry()) + PolyCrosshairConfig.newCurrentCrosshair.img = img save(Drawer.saveFromDrawer(false)) } } diff --git a/src/main/kotlin/org/polyfrost/crosshair/config/Drawer.kt b/src/main/kotlin/org/polyfrost/crosshair/config/Drawer.kt index f95d00b..3f39061 100644 --- a/src/main/kotlin/org/polyfrost/crosshair/config/Drawer.kt +++ b/src/main/kotlin/org/polyfrost/crosshair/config/Drawer.kt @@ -2,26 +2,13 @@ package org.polyfrost.crosshair.config -import cc.polyfrost.oneconfig.config.core.OneColor -import cc.polyfrost.oneconfig.config.elements.BasicOption -import cc.polyfrost.oneconfig.gui.OneConfigGui -import cc.polyfrost.oneconfig.gui.animations.Animation -import cc.polyfrost.oneconfig.gui.animations.DummyAnimation -import cc.polyfrost.oneconfig.gui.animations.EaseOutQuad -import cc.polyfrost.oneconfig.gui.elements.BasicButton -import cc.polyfrost.oneconfig.images.OneImage -import cc.polyfrost.oneconfig.libs.universal.UKeyboard -import cc.polyfrost.oneconfig.renderer.scissor.ScissorHelper -import cc.polyfrost.oneconfig.utils.IOUtils -import cc.polyfrost.oneconfig.utils.InputHandler -import cc.polyfrost.oneconfig.utils.color.ColorPalette -import cc.polyfrost.oneconfig.utils.dsl.mc -import cc.polyfrost.oneconfig.utils.dsl.nanoVGHelper -import cc.polyfrost.oneconfig.utils.dsl.runAsync +import dev.deftu.clipboard.BufferedClipboardImage +import dev.deftu.clipboard.Clipboard import org.polyfrost.crosshair.elements.ColorSelector import org.polyfrost.crosshair.elements.PresetElement import org.polyfrost.crosshair.render.CrosshairRenderer import org.polyfrost.crosshair.utils.* +import org.polyfrost.oneconfig.utils.v1.dsl.runAsync import java.awt.Image import java.awt.Toolkit import java.awt.datatransfer.DataFlavor @@ -59,28 +46,31 @@ object Drawer : BasicOption(null, null, "", "", "", "", 2) { var inArea = false init { - toBufferedImage(ModConfig.newCurrentCrosshair.img)?.let { it -> + toBufferedImage(PolyCrosshairConfig.newCurrentCrosshair.img)?.let { it -> if (it.width == 0 || it.height == 0) return@let - loadImage(it, false, ModConfig.newCurrentCrosshair)?.let { + loadImage(it, false, PolyCrosshairConfig.newCurrentCrosshair)?.let { CrosshairRenderer.updateTexture(it) } } + resetButton.setClickAction { runAsync { reset() } } + saveButton.setClickAction { runAsync { save(saveFromDrawer(false)) } } + exportButton.setClickAction { runAsync { saveFromDrawer(false)?.let { copy(it.image) } } - } + importButton.setClickAction { runAsync { var image: Image? = null @@ -97,9 +87,11 @@ object Drawer : BasicOption(null, null, "", "", "", "", 2) { } catch (_: Exception) { } + if (image == null) { - image = IOUtils.getImageFromClipboard() + image = BufferedClipboardImage.toBufferedImage(Clipboard.getInstance().image) } + if (image != null) { loadImage(image!!.toBufferedImage(), true) } else { @@ -121,13 +113,13 @@ object Drawer : BasicOption(null, null, "", "", "", "", 2) { moveQueue.clear() } - for (posY in 0..= ModConfig.canvaSize || pos.y >= ModConfig.canvaSize) { + if (pos.x >= PolyCrosshairConfig.canvaSize || pos.y >= PolyCrosshairConfig.canvaSize) { pixels[i.key].isToggled = false continue } @@ -251,12 +243,12 @@ object Drawer : BasicOption(null, null, "", "", "", "", 2) { fun move(x: Int, y: Int) { val newPositions = HashMap() - for (i in ModConfig.drawer) { + for (i in PolyCrosshairConfig.drawer) { val pos = indexToPos(i.key) val posX = pos.x + x val posY = pos.y + y pixels[i.key].isToggled = false - if (posX !in 0..() - @DualOption( - name = "Mode", - left = "Vanilla", - right = "Custom", - size = 2 + val isCustom: Boolean + get() = mode == 1 + + @RadioButton( + title = "Mode", + options = ["Vanilla", "Custom"] ) - var mode = false + var mode = 0 @CustomOption var newCrosshairs = arrayListOf(CrosshairEntry()) diff --git a/src/main/kotlin/org/polyfrost/crosshair/config/RenderConfig.kt b/src/main/kotlin/org/polyfrost/crosshair/config/RenderConfig.kt index f60af58..26e7ade 100644 --- a/src/main/kotlin/org/polyfrost/crosshair/config/RenderConfig.kt +++ b/src/main/kotlin/org/polyfrost/crosshair/config/RenderConfig.kt @@ -1,49 +1,49 @@ package org.polyfrost.crosshair.config -import cc.polyfrost.oneconfig.config.annotations.Color -import cc.polyfrost.oneconfig.config.annotations.Slider -import cc.polyfrost.oneconfig.config.annotations.Switch -import cc.polyfrost.oneconfig.config.core.OneColor +import org.polyfrost.oneconfig.api.config.v1.annotations.Color +import org.polyfrost.oneconfig.api.config.v1.annotations.Slider +import org.polyfrost.oneconfig.api.config.v1.annotations.Switch +import org.polyfrost.polyui.color.PolyColor class RenderConfig { - @Switch(name = "Dynamic Color (Overlay)") + @Switch(title = "Dynamic Color (Overlay)") var dynamicColor = false - @Switch(name = "Invert Color") + @Switch(title = "Invert Color") var invertColor = true - @Slider(name = "Overlay Opacity", min = 0f, max = 100f) + @Slider(title = "Overlay Opacity", min = 0f, max = 100f) var dynamicOpacity = 100 - @Switch(name = "Hostile") + @Switch(title = "Hostile") var hostile = false - @Color(name = "Color") - var hostileColor = OneColor(-1) + @Color(title = "Color") + var hostileColor = PolyColor.WHITE - @Switch(name = "Passive") + @Switch(title = "Passive") var passive = false - @Color(name = "Color") - var passiveColor = OneColor(-1) + @Color(title = "Color") + var passiveColor = PolyColor.WHITE - @Switch(name = "Players") + @Switch(title = "Players") var player = false - @Color(name = "Color") - var playerColor = OneColor(-1) + @Color(title = "Color") + var playerColor = PolyColor.WHITE - @Switch(name = "Show in F3 (Debug)") + @Switch(title = "Show in F3 (Debug)") var showInDebug = false - @Switch(name = "Show in GUIs") + @Switch(title = "Show in GUIs") var showInGuis = true - @Switch(name = "Show in Third Person") + @Switch(title = "Show in Third Person") var showInThirdPerson = true - @Switch(name = "Show in Spectator Mode") + @Switch(title = "Show in Spectator Mode") var showInSpectator = false var didPatcherMigration = false diff --git a/src/main/kotlin/org/polyfrost/crosshair/elements/ColorSelector.kt b/src/main/kotlin/org/polyfrost/crosshair/elements/ColorSelector.kt index 1b6cd72..d419ab4 100644 --- a/src/main/kotlin/org/polyfrost/crosshair/elements/ColorSelector.kt +++ b/src/main/kotlin/org/polyfrost/crosshair/elements/ColorSelector.kt @@ -3,12 +3,11 @@ package org.polyfrost.crosshair.elements import cc.polyfrost.oneconfig.gui.OneConfigGui import cc.polyfrost.oneconfig.gui.elements.BasicElement -import cc.polyfrost.oneconfig.gui.elements.ColorSelector import cc.polyfrost.oneconfig.internal.assets.Images import cc.polyfrost.oneconfig.renderer.NanoVGHelper import cc.polyfrost.oneconfig.utils.InputHandler import cc.polyfrost.oneconfig.utils.dsl.renderTick -import org.polyfrost.crosshair.config.ModConfig +import org.polyfrost.crosshair.config.PolyCrosshairConfig import java.awt.Color class ColorSelector : BasicElement(64, 32, false) { @@ -20,7 +19,7 @@ class ColorSelector : BasicElement(64, 32, false) { if (OneConfigGui.INSTANCE == null) return val nanoVGHelper = NanoVGHelper.INSTANCE - var color = ModConfig.penColor + var color = PolyCrosshairConfig.penColor element.update(x, y, inputHandler) nanoVGHelper.drawHollowRoundRect(vg, x, y - 1, 64f, 32f, Color(73, 79, 92, 255).rgb, 12f, 2f) @@ -37,7 +36,7 @@ class ColorSelector : BasicElement(64, 32, false) { } if (OneConfigGui.INSTANCE.currentColorSelector !== colorSelector) open = false else if (open) color = (OneConfigGui.INSTANCE.color) - ModConfig.penColor = color + PolyCrosshairConfig.penColor = color } } \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/crosshair/render/CrosshairRenderer.kt b/src/main/kotlin/org/polyfrost/crosshair/render/CrosshairRenderer.kt index 0685a63..43c3ca9 100644 --- a/src/main/kotlin/org/polyfrost/crosshair/render/CrosshairRenderer.kt +++ b/src/main/kotlin/org/polyfrost/crosshair/render/CrosshairRenderer.kt @@ -1,10 +1,6 @@ @file:Suppress("UnstableAPIUsage") package org.polyfrost.crosshair.render -import cc.polyfrost.oneconfig.config.core.OneColor -import cc.polyfrost.oneconfig.images.OneImage -import cc.polyfrost.oneconfig.libs.universal.UResolution -import cc.polyfrost.oneconfig.utils.dsl.mc import net.minecraft.client.gui.Gui import net.minecraft.client.renderer.EntityRenderer import net.minecraft.client.renderer.GlStateManager as GL @@ -20,8 +16,13 @@ import net.minecraftforge.client.event.RenderGameOverlayEvent import net.minecraftforge.client.event.TextureStitchEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import org.lwjgl.opengl.GL11 -import org.polyfrost.crosshair.config.ModConfig +import org.polyfrost.crosshair.config.PolyCrosshairConfig import org.polyfrost.crosshair.mixin.GuiIngameAccessor +import org.polyfrost.oneconfig.utils.v1.OneImage +import org.polyfrost.polyui.color.PolyColor +import org.polyfrost.polyui.color.argb +import org.polyfrost.universal.UResolution +import org.polyfrost.utils.v1.dsl.mc import java.awt.image.BufferedImage import kotlin.math.ceil @@ -67,7 +68,7 @@ object CrosshairRenderer { @SubscribeEvent fun cancel(event: RenderGameOverlayEvent.Pre) { - if (event.type != RenderGameOverlayEvent.ElementType.CROSSHAIRS || !ModConfig.enabled) return + if (event.type != RenderGameOverlayEvent.ElementType.CROSSHAIRS || !PolyCrosshairConfig.enabled) return GL.enableAlpha() event.isCanceled = true } @@ -78,14 +79,14 @@ object CrosshairRenderer { } fun drawCrosshair(entityRenderer: EntityRenderer) { - if (!ModConfig.enabled) return + if (!PolyCrosshairConfig.enabled) return if ((mc.ingameGUI as? GuiIngameAccessor)?.shouldShowCrosshair() == false) return entityRenderer.setupOverlayRendering() GL.pushMatrix() GL.tryBlendFuncSeparate(770, 771, 1, 0) GL.enableBlend() - val renderConfig = ModConfig.renderConfig + val renderConfig = PolyCrosshairConfig.renderConfig if (renderConfig.invertColor) { GL.tryBlendFuncSeparate(GL11.GL_ONE_MINUS_DST_COLOR, GL11.GL_ONE_MINUS_SRC_COLOR, 1, 0) } @@ -93,23 +94,23 @@ object CrosshairRenderer { GL11.glColor4f(1f, 1f, 1f, 1f) - (if (ModConfig.mode) textureLocation else vanillaLocation).let { mc.textureManager.bindTexture(it) } + (if (PolyCrosshairConfig.isCustom) textureLocation else vanillaLocation).let { mc.textureManager.bindTexture(it) } val mcScale = UResolution.scaleFactor.toFloat() GL.scale(1 / mcScale, 1 / mcScale, 1f) - val crosshair = ModConfig.newCurrentCrosshair + val crosshair = PolyCrosshairConfig.newCurrentCrosshair GL.translate(crosshair.offsetX.toFloat(), crosshair.offsetY.toFloat(), 0f) GL.translate((UResolution.windowWidth / 2).toFloat(), (UResolution.windowHeight / 2).toFloat(), 0f) GL.rotate(crosshair.rotation.toFloat(), 0f, 0f, 1f) val scale = crosshair.scale / 100f - val textureSize = if (ModConfig.mode) drawingImage.width else 16 + val textureSize = if (PolyCrosshairConfig.isCustom) drawingImage.width else 16 val size = ceil(textureSize * mcScale * scale).toInt() - val translation = if (ModConfig.mode) if (crosshair.centered) (-size / 2).toFloat() else (-(size - mcScale) / 2).toInt().toFloat() else ceil(-7 * mcScale * scale) + val translation = if (PolyCrosshairConfig.isCustom) if (crosshair.centered) (-size / 2).toFloat() else (-(size - mcScale) / 2).toInt().toFloat() else ceil(-7 * mcScale * scale) GL.translate(translation, translation, 0f) Gui.drawScaledCustomSizeModalRect(0, 0, 0f, 0f, textureSize, textureSize, size, size, textureSize.toFloat(), textureSize.toFloat()) val c = getColor() - if (c.rgb != -1) { - if (ModConfig.mode) mc.textureManager.bindTexture(whiteTextureLocation) - GL11.glColor4f(c.red / 255f, c.green / 255f, c.blue / 255f, renderConfig.dynamicOpacity / 100f) + if (c.rgba != -1) { + if (PolyCrosshairConfig.isCustom) mc.textureManager.bindTexture(whiteTextureLocation) + GL11.glColor4f(c.r / 255f, c.g / 255f, c.b / 255f, renderConfig.dynamicOpacity / 100f) Gui.drawScaledCustomSizeModalRect(0, 0, 0f, 0f, textureSize, textureSize, size, size, textureSize.toFloat(), textureSize.toFloat()) } if (renderConfig.invertColor) { @@ -120,19 +121,17 @@ object CrosshairRenderer { GL.popMatrix() } - val WHITE = OneColor(-1) - - private fun getColor(): OneColor { - with(ModConfig.renderConfig) { - val entity = mc.objectMouseOver?.entityHit ?: return WHITE - if (entity.isInvisible) return WHITE + private fun getColor(): PolyColor { + with(PolyCrosshairConfig.renderConfig) { + val entity = mc.objectMouseOver?.entityHit ?: return PolyColor.WHITE + if (entity.isInvisible) return PolyColor.WHITE if (dynamicColor) { if (hostile && entity is IMob) return hostileColor if (passive && (entity is EntityVillager || entity is EntityAnimal || entity is EntityAmbientCreature || entity is EntityWaterMob)) return passiveColor if (player && entity is EntityPlayer) return playerColor } } - return WHITE + return PolyColor.WHITE } } \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/crosshair/utils/Utils.kt b/src/main/kotlin/org/polyfrost/crosshair/utils/Utils.kt index 7413558..e817f7e 100644 --- a/src/main/kotlin/org/polyfrost/crosshair/utils/Utils.kt +++ b/src/main/kotlin/org/polyfrost/crosshair/utils/Utils.kt @@ -2,19 +2,22 @@ package org.polyfrost.crosshair.utils -import cc.polyfrost.oneconfig.images.OneImage -import cc.polyfrost.oneconfig.utils.* +import dev.deftu.clipboard.BufferedClipboardImage +import dev.deftu.clipboard.Clipboard import org.polyfrost.crosshair.PolyCrosshair import org.polyfrost.crosshair.config.CrosshairEntry -import org.polyfrost.crosshair.config.ModConfig +import org.polyfrost.crosshair.config.PolyCrosshairConfig +import org.polyfrost.oneconfig.api.ui.v1.Notifications +import org.polyfrost.oneconfig.utils.v1.OneImage import java.awt.Image import java.awt.image.BufferedImage import java.io.ByteArrayInputStream import java.io.ByteArrayOutputStream import java.util.* import javax.imageio.ImageIO +import kotlin.io.path.Path -fun notify(message: String) = Notifications.INSTANCE.send(PolyCrosshair.NAME, message) +fun notify(message: String) = Notifications.enqueue(Notifications.Type.Info, PolyCrosshair.NAME, message) fun posToIndex(x: Int, y: Int): Int = x + y * 32 @@ -25,23 +28,23 @@ fun indexToPos(index: Int): Pos = fun export(image: BufferedImage?, name: String): String { image ?: return "" val path = PolyCrosshair.path + name + ".png" - OneImage(image).save(path) + OneImage(image).save(Path(path)) return path } fun save(image: OneImage?) { image ?: return val base64 = toBase64(image.image) - ModConfig.newCrosshairs.forEach { + PolyCrosshairConfig.newCrosshairs.forEach { if (it.img == base64) { - it.loadFrom(ModConfig.newCurrentCrosshair) + it.loadFrom(PolyCrosshairConfig.newCurrentCrosshair) return } } val entry = CrosshairEntry() - entry.loadFrom(ModConfig.newCurrentCrosshair) + entry.loadFrom(PolyCrosshairConfig.newCurrentCrosshair) entry.img = base64 - ModConfig.newCrosshairs.add(entry) + PolyCrosshairConfig.newCrosshairs.add(entry) } fun toBufferedImage(string: String): BufferedImage? { @@ -49,6 +52,17 @@ fun toBufferedImage(string: String): BufferedImage? { return ImageIO.read(ByteArrayInputStream(bytes)) } +fun toBufferedImage(image: Image): BufferedImage { + if (image is BufferedImage) return image + + val bufferedImage = BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB) + val graphics = bufferedImage.createGraphics() + graphics.drawImage(image, 0, 0, null) + graphics.dispose() + + return bufferedImage +} + fun toBase64(image: BufferedImage): String { val byteOut = ByteArrayOutputStream() ImageIO.write(image, "png", byteOut) @@ -59,6 +73,6 @@ fun toBase64(image: BufferedImage): String { fun copy(image: Image?) { image ?: return - IOUtils.copyImageToClipboard(image) + Clipboard.getInstance().image = BufferedClipboardImage.toClipboardImage(toBufferedImage(image)) notify("Crosshair has been copied to clipboard.") }