From 5ccd33e901341a03ecac08d3445a32d47dbcc523 Mon Sep 17 00:00:00 2001 From: Luke Schwager Date: Wed, 7 Feb 2024 13:45:02 -0800 Subject: [PATCH] kotlinify --- build.gradle | 5 +++++ gradle.properties | 2 ++ settings.gradle | 3 +++ src/main/java/net/fabricmc/example/ExampleMod.java | 14 -------------- .../kotlin/net/fabricmc/example/ExampleModKt.kt | 12 ++++++++++++ src/main/resources/fabric.mod.json | 8 ++++++-- 6 files changed, 28 insertions(+), 16 deletions(-) delete mode 100644 src/main/java/net/fabricmc/example/ExampleMod.java create mode 100644 src/main/kotlin/net/fabricmc/example/ExampleModKt.kt diff --git a/build.gradle b/build.gradle index 1556d3a..630cade 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,7 @@ plugins { id "fabric-loom" version "1.5-SNAPSHOT" id "legacy-looming" version "1.5-SNAPSHOT" // Version must be the same as fabric-loom's id "maven-publish" + id "org.jetbrains.kotlin.jvm" } base.archivesName = project.archives_base_name @@ -33,6 +34,8 @@ dependencies { // You can retrieve a specific api module using this notation. // modImplementation(legacy.apiModule("legacy-fabric-item-groups-v1", project.fabric_version)) + + modImplementation "net.fabricmc:fabric-language-kotlin:${project.fabric_language_kotlin_version}" } processResources { @@ -84,3 +87,5 @@ publishing { // mavenLocal() } } + +compileKotlin.kotlinOptions.jvmTarget = "1.8" diff --git a/gradle.properties b/gradle.properties index 61eea8f..77004f3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,6 +10,8 @@ org.gradle.jvmargs=-Xmx1G # Legacy Fabric API # Also available for mc 1.7.10, 1.8, 1.9.4, 1.10.2, 1.11.2 and 1.12.2 fabric_version = 1.9.1+1.8.9 + fabric_language_kotlin_version = 1.10.17+kotlin.1.9.22 + kotlin_version = 1.9.22 # Mod Properties mod_version = 1.0.0 diff --git a/settings.gradle b/settings.gradle index 9e190a0..8033b4b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -10,4 +10,7 @@ pluginManagement { } gradlePluginPortal() } + plugins { + id "org.jetbrains.kotlin.jvm" version kotlin_version + } } diff --git a/src/main/java/net/fabricmc/example/ExampleMod.java b/src/main/java/net/fabricmc/example/ExampleMod.java deleted file mode 100644 index e5ed082..0000000 --- a/src/main/java/net/fabricmc/example/ExampleMod.java +++ /dev/null @@ -1,14 +0,0 @@ -package net.fabricmc.example; - -import net.fabricmc.api.ModInitializer; - -public class ExampleMod implements ModInitializer { - @Override - public void onInitialize() { - // This code runs as soon as Minecraft is in a mod-load-ready state. - // However, some things (like resources) may still be uninitialized. - // Proceed with mild caution. - - System.out.println("Hello Fabric world!"); - } -} diff --git a/src/main/kotlin/net/fabricmc/example/ExampleModKt.kt b/src/main/kotlin/net/fabricmc/example/ExampleModKt.kt new file mode 100644 index 0000000..8bf47ed --- /dev/null +++ b/src/main/kotlin/net/fabricmc/example/ExampleModKt.kt @@ -0,0 +1,12 @@ +package net.fabricmc.example + +import net.fabricmc.api.ModInitializer + + +// if you wish for a different type of entrypoint, check the documentation here: https://github.com/FabricMC/fabric-language-kotlin?tab=readme-ov-file#entrypoint-samples + +class ExampleModKt : ModInitializer { + override fun onInitialize() { + println("Hello Fabric world!") + } +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 6835dad..0288217 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -16,7 +16,10 @@ "environment": "*", "entrypoints": { "main": [ - "net.fabricmc.example.ExampleMod" + { + "adapter": "kotlin", + "value": "net.fabricmc.example.ExampleModKt" + } ] }, "mixins": [ @@ -27,6 +30,7 @@ "minecraft": "1.8.9" }, "suggests": { - "another-mod": "*" + "another-mod": "*", + "fabric-language-kotlin": ">=1.10.17+kotlin.1.9.22" } }