From 7574605480cce4b45376b93e3c030dd977313312 Mon Sep 17 00:00:00 2001 From: Username404 Date: Fri, 28 Apr 2023 16:00:28 +0200 Subject: [PATCH] Port to 1.19.4 Signed-off-by: Username404 --- build.gradle.kts | 23 +++++++++--------- common/build.gradle.kts | 2 +- .../snowygui/mixins/OptionValueAccessor.java | 11 +++++++++ .../fr/username404/snowygui/gui/Element.kt | 5 ++++ .../snowygui/gui/feature/DiscordRPC.kt | 4 ++-- .../snowygui/gui/feature/GammaBoost.kt | 13 +++++----- .../username404/snowygui/gui/feature/Macro.kt | 8 +++---- .../snowygui/utils/RenderingUtil.kt | 2 -- .../resources/snowygui-common.mixins.json | 3 ++- fabric/build.gradle.kts | 2 +- .../username404/snowygui/fabric/FabricInit.kt | 5 ++-- .../snowygui/fabric/OkZoomerCompat.kt | 14 ++++------- forge/build.gradle.kts | 2 +- .../username404/snowygui/forge/ForgeInit.kt | 6 ++--- .../username404/snowygui/forge/HudHandler.kt | 8 +++---- .../username404/snowygui/forge/ZoomHandler.kt | 6 ++--- gradle.properties | 24 +++++++++---------- settings.gradle.kts | 1 + 18 files changed, 74 insertions(+), 65 deletions(-) create mode 100644 common/src/main/java/fr/username404/snowygui/mixins/OptionValueAccessor.java diff --git a/build.gradle.kts b/build.gradle.kts index 640b786..8d8079d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,6 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import com.modrinth.minotaur.ModrinthExtension -import com.modrinth.minotaur.request.VersionType +import masecla.modrinth4j.model.version.ProjectVersion.VersionType import com.modrinth.minotaur.dependencies.DependencyType import net.fabricmc.loom.LoomGradleExtension @@ -33,9 +33,9 @@ val sourceJavaVer: String = javaVer val kotlinVer: String by rootProject val kotlinSplitVersion = kotlinVer.split('.') val serializationVer: String by rootProject -val mcBase: String = (rootProject.property("minecraft") as String).also { +val minecraftVersion: String = (rootProject.property("minecraft") as String).also { architectury { minecraft = it } -}.substring(0..3) +} val kotlinX: String = "org.jetbrains.kotlinx" subprojects { @@ -51,7 +51,7 @@ subprojects { apply(plugin = "org.jetbrains.kotlin.plugin.serialization") extensions.configure("loom") { mappingsDep = layered { - officialMojangMappings().parchment("org.parchmentmc.data:parchment-1.18.2:2022.03.13") + officialMojangMappings().parchment("org.parchmentmc.data:parchment-1.19.3:2023.03.12") } silentMojangMappingsLicense() val refmap = "snowygui-${project.name}-refmap.json" @@ -76,7 +76,7 @@ subprojects { implementation("$kotlinX:kotlinx-serialization-json:$serializationVer") listOf( "com.typesafe:config:1.4.2", - "io.github.config4k:config4k:0.4.2", + "io.github.config4k:config4k:0.5.0", "com.github.Vatuu:discord-rpc:1.6.2" ).forEach { implementation(it); shadowC(it) { isTransitive = false; exclude("com.sun.jna") } } "minecraft"("com.mojang:minecraft:${rootProject.property("minecraft")}") @@ -86,7 +86,7 @@ subprojects { extensions.configure("modrinth") { projectId.set("OuGyGg6A") syncBodyFrom.set("$rootDir/README.md") - gameVersions.add(mcBase) + gameVersions.add(minecraftVersion) if (project.name == "forge") dependencies.add(com.modrinth.minotaur.dependencies.VersionDependency("Bxm9xbNJ", DependencyType.REQUIRED)) // Kotlinforforge dependency versionNumber.set(rootProject.version.toString() + "-${project.name}") versionType.set(VersionType.ALPHA.name) @@ -134,6 +134,7 @@ subprojects { flattenpackagehierarchy("$group.snowygui") allowaccessmodification() adaptclassstrings() + dontnote() // This is needed to silence warnings about duplicate classes "$group.**".also { dontnote(it); dontwarn(it) } // kotlinx-serialization related configuration: @@ -169,9 +170,9 @@ subprojects { dependsOn(shrinkJar) val shrinkedJar = shrinkJar.get().outJarFileCollection.singleFile archiveBaseName.set(shadowJar.archiveBaseName) - archiveVersion.set("[${rootProject.version}+$mcBase]") + archiveVersion.set("[${rootProject.version}+$minecraftVersion]") archiveClassifier.set(this@subprojects.name) - input.set(shrinkedJar) + inputFile.set(shrinkedJar) if (!archiveFileName.get().contains("common")) destinationDirectory.set(file("$rootDir/remappedJars")) } getByName("modrinth").dependsOn(build) @@ -206,7 +207,7 @@ allprojects { "-Xbackend-threads=0", "-Xno-param-assertions", "-Xno-call-assertions", "-opt-in=kotlin.RequiresOptIn", "-Xextended-compiler-checks", "-Xassertions=jvm", "-progressive" ) - jvmTarget = if (javaVer.toInt() < 9) "1.$javaVer" else javaVer + jvmTarget = javaVer languageVersion = (kotlinSplitVersion[0] + '.' + (kotlinSplitVersion[1].toShort() + 1).toString()) apiVersion = "${kotlinSplitVersion[0]}.${kotlinSplitVersion[1]}" } @@ -216,7 +217,7 @@ allprojects { encoding = "UTF-8" isFork = true release.set(javaVer.toInt()) - sourceCompatibility = "11" + sourceCompatibility = sourceJavaVer targetCompatibility = javaVer } } @@ -228,7 +229,7 @@ allprojects { } val modProperties = mapOf( "mod_version" to (rootProject.version as String), - "minecraft_version" to mcBase, + "minecraft_version" to minecraftVersion, "java_version" to javaVer, "mod_group" to this@allprojects.group, "fabric_kotlin" to rootProject.property("fabric_language_kotlin"), diff --git a/common/build.gradle.kts b/common/build.gradle.kts index b4f2f7e..a921d0e 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -1,4 +1,4 @@ -architectury { common(false); injectInjectables = false } +architectury { common("fabric", "forge"); injectInjectables = false } dependencies { modImplementation("net.fabricmc:fabric-loader:${rootProject.property("fabric_loader_version")}") modImplementation("me.shedaniel.cloth:cloth-config:${rootProject.property("clothconfig_version")}") { diff --git a/common/src/main/java/fr/username404/snowygui/mixins/OptionValueAccessor.java b/common/src/main/java/fr/username404/snowygui/mixins/OptionValueAccessor.java new file mode 100644 index 0000000..5147bbc --- /dev/null +++ b/common/src/main/java/fr/username404/snowygui/mixins/OptionValueAccessor.java @@ -0,0 +1,11 @@ +package fr.username404.snowygui.mixins; + +import net.minecraft.client.OptionInstance; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(OptionInstance.class) +public interface OptionValueAccessor { + @Accessor("value") + void setValue(Object value); +} diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt index 74d0a2b..79c3980 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt @@ -19,6 +19,11 @@ abstract class Element( open var x = xOrigin; open var y = yOrigin fun isWithinBounds(coordinateX: Double, coordinateY: Double, offsetWidth: Double = 0.0, offsetHeight: Double = 0.0): Boolean = (coordinateX in x..(x + width + offsetWidth)) && (coordinateY in y..(y + height + offsetHeight)) + + @JvmField + protected var focused = false + override fun isFocused() = focused + override fun setFocused(boolean: Boolean) { focused = boolean } companion object { private var caughtError: Boolean = false fun fromRenderable(r: Renderable, x: Double, y: Double, width: Int, height: Int): Element { diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/DiscordRPC.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/DiscordRPC.kt index 1ee7c7a..08c4c30 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/DiscordRPC.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/DiscordRPC.kt @@ -10,8 +10,8 @@ import net.arikia.dev.drpc.DiscordRPC as discord_rpc object DiscordRPC: ButtonImpl() { private val RPCHandlers: DiscordEventHandlers = DiscordEventHandlers.Builder().build() private val RichPresence: DiscordRichPresence.Builder = DiscordRichPresence - .Builder("Playing Minecraft ${Minecraft.getInstance().game.version.name}") - .setDetails("Launched with ${Minecraft.getInstance().launchedVersion}") + .Builder("Playing Minecraft ${Minecraft.getInstance().launchedVersion}") + .setDetails("Launched with ${Minecraft.getInstance().versionType}") .setBigImage("icon", "SnowyGUI") override fun execAction() { if (toggled) discord_rpc.discordUpdatePresence(RichPresence.build()) diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/GammaBoost.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/GammaBoost.kt index 1bdf51b..e28fe7f 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/GammaBoost.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/GammaBoost.kt @@ -1,5 +1,6 @@ package fr.username404.snowygui.gui.feature +import fr.username404.snowygui.mixins.OptionValueAccessor import net.minecraft.client.Minecraft @ButtonInfo(Category.MISC) @@ -8,13 +9,11 @@ object GammaBoost: ButtonImpl() { private var oldGamma = 0.0 override fun execAction() { with(Minecraft.getInstance().options) { - val gamma = gamma().get(); - gamma().set( - if (toggled) { - if (gamma < boost) oldGamma = gamma - boost - } else oldGamma - ) + val gamma = gamma().get() + (gamma() as OptionValueAccessor).setValue(if (toggled) { + if (gamma < boost) oldGamma = gamma + boost + } else oldGamma) } } } \ No newline at end of file diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/Macro.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/Macro.kt index 495e060..30eb7d1 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/Macro.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/Macro.kt @@ -15,10 +15,10 @@ data class Macro( override var title: String = command ): ButtonImpl() { override fun execAction(): Unit = with(Minecraft.getInstance().player!!) { - chat( - "/$command".let { - if (it.startsWith("/say") && !hasPermissions(2)) { - it.drop(5) + connection.sendCommand( + command.let { + if (it.startsWith("say") && !hasPermissions(2)) { + it.drop(4) } else it } ) diff --git a/common/src/main/kotlin/fr/username404/snowygui/utils/RenderingUtil.kt b/common/src/main/kotlin/fr/username404/snowygui/utils/RenderingUtil.kt index 7511073..89ba1ab 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/utils/RenderingUtil.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/utils/RenderingUtil.kt @@ -24,12 +24,10 @@ object RenderingUtil { } fun prepareDraw() { colorShader() - RenderSystem.disableTexture() RenderSystem.enableBlend() RenderSystem.defaultBlendFunc() } fun endDraw() { - RenderSystem.enableTexture() RenderSystem.disableBlend() } fun drawRectangle( diff --git a/common/src/main/resources/snowygui-common.mixins.json b/common/src/main/resources/snowygui-common.mixins.json index 0603454..32639eb 100644 --- a/common/src/main/resources/snowygui-common.mixins.json +++ b/common/src/main/resources/snowygui-common.mixins.json @@ -6,7 +6,8 @@ "KeysAccessor", "KeyMappings", "EndTickMixin", - "TitleScreenMixin" + "TitleScreenMixin", + "OptionValueAccessor" ], "injectors": { "defaultRequire": 1 diff --git a/fabric/build.gradle.kts b/fabric/build.gradle.kts index 987d978..9eff7c7 100644 --- a/fabric/build.gradle.kts +++ b/fabric/build.gradle.kts @@ -23,7 +23,7 @@ dependencies { exclude(group = Groups.FabricApi, module = "fabric-api-base") exclude(group = Groups.FabricApi, module = "fabric-resource-loader-v0") } - implementation(project(path = ":common")) { isTransitive = false } + implementation(project(path = ":common", configuration = "namedElements")) { isTransitive = false } add("developmentFabric", project(path = ":common")) { isTransitive = false } shadowC(project(path = ":common", configuration = "transformProductionFabric")) { isTransitive = false } } diff --git a/fabric/src/main/kotlin/fr/username404/snowygui/fabric/FabricInit.kt b/fabric/src/main/kotlin/fr/username404/snowygui/fabric/FabricInit.kt index 9f073c4..3fed76b 100644 --- a/fabric/src/main/kotlin/fr/username404/snowygui/fabric/FabricInit.kt +++ b/fabric/src/main/kotlin/fr/username404/snowygui/fabric/FabricInit.kt @@ -12,6 +12,7 @@ import kotlin.io.path.exists import kotlin.io.path.isDirectory import kotlin.io.path.listDirectoryEntries import kotlin.io.path.pathString +import kotlin.jvm.optionals.getOrNull class FabricInit: Snowy(), ClientModInitializer { override fun onInitializeClient() { @@ -23,8 +24,8 @@ class FabricInit: Snowy(), ClientModInitializer { } ) } - override val annotatedButtons = FabricLoader.getInstance().allMods.map { - it.getPath(FeaturePackage.replace('.', '/')) + override val annotatedButtons = FabricLoader.getInstance().allMods.mapNotNull { + it.findPath(FeaturePackage.replace('.', '/')).getOrNull() }.filter { it.exists() && it.isDirectory() }.flatMap { buttonsDirectory -> mutableSetOf>().apply { buttonsDirectory.listDirectoryEntries("*.class").forEach { file -> diff --git a/fabric/src/main/kotlin/fr/username404/snowygui/fabric/OkZoomerCompat.kt b/fabric/src/main/kotlin/fr/username404/snowygui/fabric/OkZoomerCompat.kt index 21ddc48..b08ee6b 100644 --- a/fabric/src/main/kotlin/fr/username404/snowygui/fabric/OkZoomerCompat.kt +++ b/fabric/src/main/kotlin/fr/username404/snowygui/fabric/OkZoomerCompat.kt @@ -6,15 +6,9 @@ import net.fabricmc.loader.api.FabricLoader @JvmField var isOkZoomerPresent: Boolean = FabricLoader.getInstance().isModLoaded("okzoomer") private val okZoomerPairs by lazy { - try { - with(Class.forName("io.github.joaoh1.okzoomer.client.utils.ZoomUtils")) { - (getField("zoomDivisor") to null) to (getField("zoomState") to null) - } - } catch (e: ClassNotFoundException) { - with(Class.forName("io.github.ennuil.okzoomer.utils.ZoomUtils").getDeclaredField("zoomerZoom")) { - get(null).javaClass.run { - (getDeclaredField("zoomDivisor") to this@with.get(null)) to (getDeclaredField("zoom") to this@with.get(null)) - } + with(Class.forName("io.github.ennuil.okzoomer.utils.ZoomUtils").getDeclaredField("ZOOMER_ZOOM")) { + get(null).javaClass.run { + (getDeclaredField("zoomDivisor") to this@with.get(null)) to (getDeclaredField("zoom") to this@with.get(null)) } }.apply { first.first.isAccessible = true; second.first.isAccessible = true; } } @@ -22,7 +16,7 @@ private val okZoomerPairs by lazy { fun fabricZoom() { try { with(okZoomerPairs) { - first.run { first.setDouble(second, Zoom.zoomFactor) } + first.run { first.setFloat(second, Zoom.zoomFactor.toFloat()) } second.run { first.setBoolean(second, Zoom.toggled) } } } catch (e: Exception) { diff --git a/forge/build.gradle.kts b/forge/build.gradle.kts index 2044de5..b4e3197 100644 --- a/forge/build.gradle.kts +++ b/forge/build.gradle.kts @@ -7,7 +7,7 @@ dependencies { forge("net.minecraftforge:forge:${rootProject.architectury.minecraft}-${rootProject.property("forge_version")}.+") implementation("thedarkcolour:kotlinforforge:${rootProject.property("kotlinforforge")}") modApi("me.shedaniel.cloth:cloth-config-forge:${rootProject.property("clothconfig_version")}") - implementation(project(path = ":common")) { isTransitive = false } + implementation(project(path = ":common", configuration = "namedElements")) { isTransitive = false } add("developmentForge", project(path = ":common")) { isTransitive = false } shadowC(project(path = ":common", configuration = "transformProductionForge")) { isTransitive = false } }; loom { diff --git a/forge/src/main/kotlin/fr/username404/snowygui/forge/ForgeInit.kt b/forge/src/main/kotlin/fr/username404/snowygui/forge/ForgeInit.kt index 89380ea..e16d636 100644 --- a/forge/src/main/kotlin/fr/username404/snowygui/forge/ForgeInit.kt +++ b/forge/src/main/kotlin/fr/username404/snowygui/forge/ForgeInit.kt @@ -7,7 +7,7 @@ import fr.username404.snowygui.gui.feature.ButtonImpl import net.minecraftforge.fml.ModList import net.minecraftforge.fml.common.Mod import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent -import net.minecraftforge.client.ConfigGuiHandler +import net.minecraftforge.client.ConfigScreenHandler import net.minecraftforge.forgespi.language.ModFileScanData import org.objectweb.asm.Type import thedarkcolour.kotlinforforge.forge.FORGE_BUS @@ -20,8 +20,8 @@ class ForgeInit: Snowy() { private fun initSetup(event: FMLClientSetupEvent) = atInit() private fun configSetup(event: FMLClientSetupEvent) { LOADING_CONTEXT.registerExtensionPoint( - ConfigGuiHandler.ConfigGuiFactory::class.java - ) { ConfigGuiHandler.ConfigGuiFactory { _, parent -> configScreenParent = parent; SnowyConfigScreen } } + ConfigScreenHandler.ConfigScreenFactory::class.java + ) { ConfigScreenHandler.ConfigScreenFactory { _, parent -> configScreenParent = parent; SnowyConfigScreen } } } override val annotatedButtons = ModList.get() // Forge-specific reflection .allScanData diff --git a/forge/src/main/kotlin/fr/username404/snowygui/forge/HudHandler.kt b/forge/src/main/kotlin/fr/username404/snowygui/forge/HudHandler.kt index 2411044..3ad498e 100644 --- a/forge/src/main/kotlin/fr/username404/snowygui/forge/HudHandler.kt +++ b/forge/src/main/kotlin/fr/username404/snowygui/forge/HudHandler.kt @@ -1,15 +1,13 @@ package fr.username404.snowygui.forge import fr.username404.snowygui.EventSnowy -import net.minecraftforge.client.event.RenderGameOverlayEvent +import net.minecraftforge.client.event.RenderGuiEvent import net.minecraftforge.eventbus.api.SubscribeEvent object HudHandler: EventSnowy { override val type: String = "HudRender" @SubscribeEvent - fun handleRendering(event: RenderGameOverlayEvent.Post) { - if (event.type == RenderGameOverlayEvent.ElementType.ALL) { - fire(event.matrixStack) - } + fun handleRendering(event: RenderGuiEvent.Post) { + fire(event.poseStack) } } \ No newline at end of file diff --git a/forge/src/main/kotlin/fr/username404/snowygui/forge/ZoomHandler.kt b/forge/src/main/kotlin/fr/username404/snowygui/forge/ZoomHandler.kt index ec7326a..2c67cc3 100644 --- a/forge/src/main/kotlin/fr/username404/snowygui/forge/ZoomHandler.kt +++ b/forge/src/main/kotlin/fr/username404/snowygui/forge/ZoomHandler.kt @@ -1,12 +1,12 @@ package fr.username404.snowygui.forge import fr.username404.snowygui.gui.feature.Zoom -import net.minecraftforge.client.event.EntityViewRenderEvent +import net.minecraftforge.client.event.ComputeFovModifierEvent import net.minecraftforge.eventbus.api.SubscribeEvent object ZoomHandler { @SubscribeEvent - fun onFOVEvent(event: EntityViewRenderEvent.FieldOfView) { - if (Zoom.toggled) event.fov = Zoom.getNewZoom(event.fov) + fun onFOVEvent(event: ComputeFovModifierEvent) { + if (Zoom.toggled) event.newFovModifier = Zoom.getNewZoom(event.newFovModifier.toDouble()).toFloat() } } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index fcb0966..1f3f56d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,16 +7,16 @@ org.gradle.parallel=true org.gradle.unsafe.configuration-cache=on org.gradle.vfs.watch=true -minecraft=22w16b -forge_version=39.1 -kotlinforforge=3.1.0 -kotlinVer=1.6.0 -kotlin_coroutines_version=1.5.0 -serializationVer=1.2.1 -fabric_loader_version=0.11.7 -fabric_language_kotlin=1.7.0+kotlin.1.6.0 -fabric_resource_loader_version=0.4.24+ec94c6f6e0 -fabric_rendering_api_version=1.10.9+ec94c6f6e0 +minecraft=1.19.4 +forge_version=45.0 +kotlinforforge=4.1.0 +kotlinVer=1.8.20 +kotlin_coroutines_version=1.7.0-RC +serializationVer=1.5.0 +fabric_loader_version=0.14.19 +fabric_language_kotlin=1.9.3+kotlin.1.8.20 +fabric_resource_loader_version=0.11.4+bd913b0d4e +fabric_rendering_api_version=2.1.1+8f878217f4 fabric_api_base_version=0.4.5+ec94c6f6e0 -clothconfig_version=7.0.60 -modmenu_version=3.0.1 +clothconfig_version=10.0.96 +modmenu_version=6.2.1 diff --git a/settings.gradle.kts b/settings.gradle.kts index 34046b8..458a50e 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -11,6 +11,7 @@ pluginManagement { include("common") include("fabric") +include("forge") rootProject.name = "SnowyGUI"