From 481ebb1b602f71fe76149d03c1799792c4874cef Mon Sep 17 00:00:00 2001 From: Username404-59 Date: Mon, 3 May 2021 10:27:38 +0200 Subject: [PATCH] Setup fabric-language-kotlin and kotlinforforge --- build.gradle.kts | 15 ++++++--------- fabric/build.gradle.kts | 1 + .../fr/username404/snowygui/fabric/FabricInit.kt | 2 +- fabric/src/main/resources/fabric.mod.json | 6 +++++- forge/build.gradle.kts | 4 ++++ .../fr/username404/snowygui/forge/ForgeInit.kt | 8 ++++---- forge/src/main/resources/META-INF/mods.toml | 4 ++-- 7 files changed, 23 insertions(+), 17 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 83c1660..b7b39b7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -77,15 +77,12 @@ subprojects { refmapName = "snowygui-common-refmap.json" } dependencies { - shadowC(kotlin("stdlib-jdk8") as String) { - exclude(module = "kotlin-stdlib-common") - exclude(module = "annotations") - } + implementation("$kotlinX:kotlinx-coroutines-core:1.4.0") listOf( - "$kotlinX:kotlinx-coroutines-core:1.5.0-RC", "$kotlinX:kotlinx-datetime:0.2.0", + "com.typesafe:config:1.4.1", "io.github.config4k:config4k:0.4.2" - ).forEach { implementation(it); shadowC(it) } + ).forEach { implementation(it); shadowC(it) { isTransitive = false } } "minecraft"("com.mojang:minecraft:${rootProject.property("minecraft")}") "mappings"(mappingsDep) } @@ -96,7 +93,7 @@ allprojects { apply(plugin = "java") apply(plugin = "architectury-plugin") dependencies { - implementation(kotlin("stdlib-jdk8")) + implementation(kotlin("stdlib-jdk8", "1.4.30")) } java { targetCompatibility = JavaVersion.VERSION_1_8 @@ -104,7 +101,7 @@ allprojects { } tasks { withType(ShadowJar::class) { - relocate("kotlin", "${rootProject.group}.kotlin") + relocate("kotlinx", "${rootProject.group}.kotlinx") relocate("org.jetbrains", "${rootProject.group}.jetbrainslibs") relocate("com.typesafe.config", "${rootProject.group}.typesafe.config") relocate("io.github.config4k", "${rootProject.group}.config4k") @@ -122,7 +119,7 @@ allprojects { freeCompilerArgs = listOf("-Xjvm-default=all", "-Xlambdas=indy") jvmTarget = "1.8" languageVersion = "1.5" - apiVersion = "1.5" + apiVersion = "1.4" } } withType(JavaCompile::class) { diff --git a/fabric/build.gradle.kts b/fabric/build.gradle.kts index 027615c..ea96e2a 100644 --- a/fabric/build.gradle.kts +++ b/fabric/build.gradle.kts @@ -17,6 +17,7 @@ dependencies { include(modApi("${Groups.FabricApi}:fabric-rendering-v1:${rootProject.property("fabric_rendering_api_version")}")!!) include(modApi("${Groups.FabricApi}:fabric-api-base:${rootProject.property("fabric_api_base_version")}")!!) include(modRuntime("${Groups.FabricApi}:fabric-resource-loader-v0:${rootProject.property("fabric_resource_loader_version")}")!!) + modImplementation(group = "net.fabricmc", name = "fabric-language-kotlin", version = "1.5.0+kotlin.1.4.31") modRuntime(modCompileOnly("com.terraformersmc:modmenu:${rootProject.property("modmenu_version")}") { exclude(group = Groups.FabricApi, module = "fabric-api-base") exclude(group = Groups.FabricApi, module = "fabric-resource-loader-v0") 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 01f472c..9b5abe9 100644 --- a/fabric/src/main/kotlin/fr/username404/snowygui/fabric/FabricInit.kt +++ b/fabric/src/main/kotlin/fr/username404/snowygui/fabric/FabricInit.kt @@ -7,7 +7,7 @@ import net.fabricmc.api.ClientModInitializer import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback.EVENT -class FabricInit: Snowy(), ClientModInitializer { +object FabricInit: Snowy(), ClientModInitializer { override fun onInitializeClient() { atInit() EVENT.register( diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 37c8690..d4ddb0f 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -18,7 +18,10 @@ "environment": "client", "entrypoints": { "client": [ - "${mod_group}.snowygui.fabric.FabricInit" + { + "adapter": "kotlin", + "value": "${mod_group}.snowygui.fabric.FabricInit" + } ], "modmenu": [ "${mod_group}.snowygui.fabric.ModMenuConf" @@ -29,6 +32,7 @@ ], "depends": { "fabricloader": ">=0.9.3", + "fabric-language-kotlin": ">=1.4.0+build.1", "fabric-resource-loader-v0": "*", "fabric-rendering-v1": "*", "minecraft": ">=${minecraft_version}" diff --git a/forge/build.gradle.kts b/forge/build.gradle.kts index 350240a..b5e33ad 100644 --- a/forge/build.gradle.kts +++ b/forge/build.gradle.kts @@ -1,6 +1,10 @@ architectury { platformSetupLoomIde(); forge() } +repositories { + maven(url = "https://thedarkcolour.github.io/KotlinForForge/") +} dependencies { forge("net.minecraftforge:forge:${rootProject.architectury.minecraft}-${rootProject.property("forge_version")}.+") + modImplementation("thedarkcolour:kotlinforforge:1.9.0") implementation(project(path = ":common")) { isTransitive = false } add("developmentForge", project(path = ":common")) { isTransitive = false } shadowC(project(path = ":common", configuration = "transformProductionForge")) { isTransitive = false } 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 04de7f5..1a899a1 100644 --- a/forge/src/main/kotlin/fr/username404/snowygui/forge/ForgeInit.kt +++ b/forge/src/main/kotlin/fr/username404/snowygui/forge/ForgeInit.kt @@ -3,10 +3,10 @@ package fr.username404.snowygui.forge import fr.username404.snowygui.Snowy import fr.username404.snowygui.config.SnowyConfigScreen import net.minecraftforge.fml.ExtensionPoint -import net.minecraftforge.fml.ModLoadingContext import net.minecraftforge.fml.common.Mod import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext +import thedarkcolour.kotlinforforge.forge.LOADING_CONTEXT +import thedarkcolour.kotlinforforge.forge.MOD_BUS import java.util.function.BiFunction import java.util.function.Supplier @@ -15,7 +15,7 @@ import java.util.function.Supplier class ForgeInit: Snowy() { private fun initSetup(event: FMLClientSetupEvent) = atInit() private fun configSetup(event: FMLClientSetupEvent) { - ModLoadingContext.get().registerExtensionPoint( + LOADING_CONTEXT.registerExtensionPoint( ExtensionPoint.CONFIGGUIFACTORY, Supplier { return@Supplier BiFunction { mc, screen -> @@ -27,7 +27,7 @@ class ForgeInit: Snowy() { ) } init { - with(FMLJavaModLoadingContext.get().modEventBus) { + with(MOD_BUS) { addListener(this@ForgeInit::initSetup) addListener(this@ForgeInit::configSetup) } diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml index 1490432..e62f234 100644 --- a/forge/src/main/resources/META-INF/mods.toml +++ b/forge/src/main/resources/META-INF/mods.toml @@ -1,5 +1,5 @@ -modLoader = "javafml" -loaderVersion = "[1.7.0,)" +modLoader = "kotlinforforge" +loaderVersion = "[1.9,)" issueTrackerURL = "https://gits.username404.fr/Username404-59/SnowyGUI/issues" license = "MPL-2.0"