KotlinLangForge
This mod provides a Kotlin language adapter for Forge and NeoForge platforms, allowing developers to create mods using the modern Kotlin programming language.
For Developers
To integrate the Kotlin adapter into your project, add the following lines to your (neoforge.)mods.toml configuration file:
modLoader = "klf"
loaderVersion = "[1,)"
After this, you can initialize your mod in the standard way. It's important that the class annotated with @Mod is either an object or a class with a public constructor. The constructor can take the following four parameters (they should not duplicate):
- IEventBus
- ModContainer
- KotlinModContainer
- Dist
Versioning System
The "language provider" version is used exclusively by KotlinLangForge and serves to distinguish different language adapter implementations across Minecraft versions:
| Minecraft Version | Language Provider Version | Supported Loaders |
|---|---|---|
| 1.16.5 | 1.0 | Forge |
| 1.17.1 - 1.20.4 | 2.0 | Forge, NeoForge |
| 1.20.5 - 1.21.x | 3.0 | NeoForge |
To include libraries in your project, use the following dependency in build.gradle.kts:
repositories {
maven("https://repo.nyon.dev/releases")
}
dependencies {
modImplementation("dev.nyon:KotlinLangForge:$version-$kotlinVersion-$lpVersion+$loader")
}
Working with Events
For automatic event handler registration, add the @EventBusSubscriber annotation to the class. You can also annotate a method with SubscribeEvent to configure listener parameters, but this is not required. KotlinLangForge automatically finds events in all class methods and determines which event bus to use.
Important for Forge developers: Private event handlers are not supported in Forge and may cause crashes!
Mod Bus is available via dev.nyon.klf.MOD_BUS.
Included Libraries
- org.jetbrains.kotlin:kotlin-stdlib:2.2.20
- org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.2.20
- org.jetbrains.kotlin:kotlin-stdlib-jdk7:2.2.20
- org.jetbrains.kotlin:kotlin-reflect:2.2.20
- org.jetbrains.kotlinx:kotlinx-serialization-core:1.9.0
- org.jetbrains.kotlinx:kotlinx-serialization-json:1.9.0
- org.jetbrains.kotlinx:kotlinx-serialization-cbor:1.9.0
- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2
- org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.10.2
- org.jetbrains.kotlinx:kotlinx-datetime:0.7.1-0.6.x-compat
- org.jetbrains.kotlinx:kotlinx-io-core:0.8.0
- org.jetbrains.kotlinx:kotlinx-io-bytestring:0.8.0
- org.jetbrains.kotlinx:atomicfu:0.29.0