diff options
Diffstat (limited to 'versions/src/main/kotlin/cc/polyfrost/oneconfig/utils/KotlinLanguageAdapter.kt')
-rw-r--r-- | versions/src/main/kotlin/cc/polyfrost/oneconfig/utils/KotlinLanguageAdapter.kt | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/versions/src/main/kotlin/cc/polyfrost/oneconfig/utils/KotlinLanguageAdapter.kt b/versions/src/main/kotlin/cc/polyfrost/oneconfig/utils/KotlinLanguageAdapter.kt new file mode 100644 index 0000000..f520f00 --- /dev/null +++ b/versions/src/main/kotlin/cc/polyfrost/oneconfig/utils/KotlinLanguageAdapter.kt @@ -0,0 +1,33 @@ +//#if MC<=11202 +package cc.polyfrost.oneconfig.utils + +import net.minecraftforge.fml.common.FMLModContainer +import net.minecraftforge.fml.common.ILanguageAdapter +import net.minecraftforge.fml.common.ModContainer +import net.minecraftforge.fml.relauncher.Side +import java.lang.reflect.Field +import java.lang.reflect.Method + +/** + * An adapter for FML to allow for the use of Kotlin objects as a mod class. + * This is not required if you use a Kotlin class, only if you use a Kotlin object. + * + * Adapted from Crimson under LGPL 3.0 + * https://github.com/Deftu-Archive/Crimson/blob/main/LICENSE + */ +class KotlinLanguageAdapter : ILanguageAdapter { + + override fun supportsStatics(): Boolean = false + override fun getNewInstance( + container: FMLModContainer, objectClass: Class<*>, classLoader: ClassLoader, factoryMarkedAnnotation: Method + ): Any = objectClass.kotlin.objectInstance ?: objectClass.getDeclaredConstructor().newInstance() + + override fun setProxy(target: Field, proxyTarget: Class<*>, proxy: Any) { + target.set(proxyTarget.kotlin.objectInstance, proxy) + } + + override fun setInternalProxies(mod: ModContainer?, side: Side?, loader: ClassLoader?) { + } + +} +//#endif
\ No newline at end of file |