FabricMC / fabric-language-kotlin

Fabric language module for Kotlin.
Apache License 2.0
293 stars 33 forks source link

fabric-language-kotlin

maven-badge modrinth-badge curseforge-badge

Fabric language module for Kotlin. Adds support for Kotlin exclusive entrypoints and bundles the Kotlin Stdlib as well as common kotlinx libraries.

Usage

Dependency

Add it as a dependency to your Gradle project:

dependencies {
    modImplementation("net.fabricmc:fabric-language-kotlin:1.12.2+kotlin.2.0.20")
}

Adapter

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.12.2+kotlin.2.0.20"
    }
}

For more info reference the fabric.mod.json documentation.

Do not forget to set the schemaVersion to 1 or it will fall back to schema 0 and will not attempt to load entrypoints.

Entrypoint samples

Kind Class reference Function reference Field reference
class ```json { "adapter": "kotlin", "value": "mymod.MyMod" } ``` ```kotlin package mymod class MyMod : ModInitializer { override fun onInitialize() { TODO() } } ```
object ```json { "adapter": "kotlin", "value": "mymod.MyMod" } ``` ```kotlin package mymod object MyMod : ModInitializer { override fun onInitialize() { TODO() } } ``` ```json { "adapter": "kotlin", "value": "mymod.MyMod::init" } ``` ```kotlin package mymod object MyMod { fun init() { TODO() } } ``` ```json { "adapter": "kotlin", "value": "mymod.MyMod::initializer" } ``` ```kotlin package mymod object MyMod { val initializer = ModInitializer { TODO() } } ```
companion object ```json { "adapter": "kotlin", "value": "mymod.MyMod$Companion" } ``` ```kotlin package mymod class MyMod { companion object : ModInitializer { override fun onInitialize() { TODO() } } } ``` ```json { "adapter": "kotlin", "value": "mymod.MyMod$Companion::init" } ``` ```kotlin package mymod class MyMod { companion object { fun init() { TODO() } } } ``` ```json { "adapter": "kotlin", "value": "mymod.MyMod$Companion::initializer" } ``` ```kotlin package mymod class MyMod { companion object { val initializer = ModInitializer { TODO() } } } ```
top level ```json { "adapter": "kotlin", "value": "mymod.MyModKt::init" } ``` File: `src/main/kotlin/mymod/MyMod.kt` ```kotlin package mymod fun init() { TODO() } ```

Companion objects can be used by appending $Companion to the class. Take care of processResources there, it might try to expand it, in that case escape it.

Bundled libraries

org.jetbrains.kotlin namespace:

org.jetbrains.kotlinx namespace:

Available Versions

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

Updating README