Kotlin and Minecraft Forge

Warning

As of Oct. 31, 2016 my Forgelin fork has been discontinued and merged with ShadowMC. All the files remain on GitHub/maven/CurseForge and you can continue using my Forgelin fork, however, it will not receive updates.


So, you wanna use Kotlin in your Forge mod? Well there’s good news, I’ve just released Forgelin, a fork of Emberwalker’s Forgelin, a library that provides utilities for using Kotlin with Minecraft/Forge.

Primarily Forgelin provides a Kotlin langauge adapter that allows your main-mod class to be a object. In order to use the language adapter, you must specify the modLanguageAdapter property in your @Mod annotation to be net.shadowfacts.forgelin.KotlinAdapter.

Additionally, Forgelin provides a number of extensions (which are viewable here) for working with Minecraft/Forge.

While you can shade Forgelin, it is not recommended to do so. It will increase your jar size by approximately 3 megabytes (as Forgelin itself includes the entire Kotlin, standard lib, reflect lib, and runtime) and may cause issues with other mods that shade Kotlin or Forgelin. It is recommended that you have your users download Forgelin from CurseForge.

A bare-bones example mod using Forgelin is available here.