FokshaWasTaken / fabric-language-kotlin

Fabric language module for Kotlin.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

maven-badge Files Download

fabric-language-kotlin

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.

Usage

Add it as a dependency (build.gradle and build.gradle.kts):

dependencies {
    // [...]
    modImplementation(group = "net.fabricmc", name = "fabric-language-kotlin", version = "1.7.1+kotlin.1.6.10")
}

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"
            }
        ]
    },
    "depends": {
        "fabric-language-kotlin": ">=1.7.1+kotlin.1.6.10"
    }
}

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.

entrypoints samples

class reference

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()
        }
    }
}

function reference

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()
}

field reference

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.

Bundled libraries

org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10
org.jetbrains.kotlin:kotlin-reflect:1.6.10
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0
org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.6.0
org.jetbrains.kotlinx:kotlinx-serialization-core-jvm:1.3.2
org.jetbrains.kotlinx:kotlinx-serialization-json-jvm:1.3.2
org.jetbrains.kotlinx:kotlinx-serialization-cbor-jvm:1.3.2

Available Versions

https://maven.fabricmc.net/net/fabricmc/fabric-language-kotlin/

Updating README

  • Update the readme in templates/README.template.md.
  • Run ./gradlew processMDTemplates.

About

Fabric language module for Kotlin.

License:Apache License 2.0


Languages

Language:Kotlin 100.0%