Giter VIP home page Giter VIP logo

fabric-language-kotlin's Introduction

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:

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.6.0+kotlin.1.5.0")
}

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.6.0+kotlin.1.5.0"
    }
}

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.

See examples in sample-mod/fabric.mod.json.

Bundled libraries

org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.0
org.jetbrains.kotlin:kotlin-reflect:1.5.0
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0-RC
org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.5.0-RC
org.jetbrains.kotlinx:kotlinx-serialization-core-jvm:1.2.0
org.jetbrains.kotlinx:kotlinx-serialization-json-jvm:1.2.0

Available Versions

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

Updating README

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.