Fabric language module for Kotlin. Adds support for using a Kotlin object
as the main mod class and bundles the Kotlin libraries and runtime for you.
Add it as a dependency:
Repositories for build.gradle.kts
repositories {
// [...]
maven(url = "http://maven.fabricmc.net/") {
name = "Fabric"
}
}
Repositories for build.gradle:
repositories {
// [...]
maven {
url = "http://maven.fabricmc.net/"
name = "Fabric"
}
}
Dependencies (build.gradle and build.gradle.kts):
dependencies {
// [...]
modImplementation(group = "net.fabricmc", name = "fabric-language-kotlin", version = "1.3.50-SNAPSHOT")
}
Use the kotlin
adapter for your mod by setting the adapter
property in the fabric.mod.json
file.
Remember to the add a dependency entry to your fabric.mod.json
file:
{
"schemaVersion": 1,
"entrypoints": {
"main": [
{
"adapter": "kotlin",
"value": "package.ClassName"
}
]
},
"requires": {
"fabric-language-kotlin": ">=1.3.50"
}
}
For more info reference format:modjson.
Do not forget to set the schemaVersion
to 1
or it will fall back to schema 0
and will not attempt to load entrypoints.
As a class
Click to view code
{
"adapter": "kotlin",
"value": "mymod.MyMod"
}
package mymod
class MyMod : ModInitializer {
override fun onInitialize() {
TODO()
}
}
As an object
Click to view code
{
"adapter": "kotlin",
"value": "mymod.MyMod"
}
package mymod
object MyMod : ModInitializer {
override fun onInitialize() {
TODO()
}
}
As a companion object
Click to view code
{
"adapter": "kotlin",
"value": "mymod.MyMod$Companion"
}
package mymod
class MyMod {
companion object : ModInitializer {
override fun onInitialize() {
TODO()
}
}
}
Functions do not get returned but executed, so they have to only contain initialization code, not return a initializer type.
In an object
Click to view code
{
"adapter": "kotlin",
"value": "mymod.MyMod::init"
}
package mymod
object MyMod {
fun init() {
TODO()
}
}
In a companion object
Click to view code
{
"adapter": "kotlin",
"value": "mymod.MyMod$Companion::init"
}
package mymod
class MyMod {
companion object {
fun init() {
TODO()
}
}
}
As a top level function
Click to view code
The classname gets constructed by taking the filename and appending Kt
.
{
"adapter": "kotlin",
"value": "mymod.MyModKt::init"
}
File: src/main/kotlin/mymod/MyMod.kt
package mymod
fun init() {
TODO()
}
In an object
Click to view code
{
"adapter": "kotlin",
"value": "mymod.MyMod::initializer"
}
package mymod
object MyMod {
val initializer = ModInitializer {
TODO()
}
}
In a companion object
Click to view code
{
"adapter": "kotlin",
"value": "mymod.MyMod$Companion::initializer"
}
package mymod
class MyMod {
companion object {
val initializer = ModInitializer {
TODO()
}
}
}
Companion objects can be used by appending $Companion
to the class.
Take care of processResource
there, it might try to expand it, in that case escape it.
See examples in sample-mod/fabric.mod.json.
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.50
org.jetbrains.kotlin:kotlin-reflect:1.3.50
org.jetbrains:annotations:17.0.0
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.0
org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.3.0
https://maven.fabricmc.net/net/fabricmc/fabric-language-kotlin/
- Update the readme in
temaplates/README.template.md
. - Run
./gradlew processMDTemplates
.