aboutsummaryrefslogtreecommitdiff
path: root/versions/src
diff options
context:
space:
mode:
authorWyvest <45589059+Wyvest@users.noreply.github.com>2022-07-16 22:06:35 +0900
committerGitHub <noreply@github.com>2022-07-16 22:06:35 +0900
commit153558c19436c6945a5ac534b035b4e3ced1bcaa (patch)
tree7645b2e1dcae0fd76177c1f811bb91ad5afc5ccb /versions/src
parentdd540a76db067e7f6fe06e882f49fcf5c2b97fe2 (diff)
downloadOneConfig-153558c19436c6945a5ac534b035b4e3ced1bcaa.tar.gz
OneConfig-153558c19436c6945a5ac534b035b4e3ced1bcaa.tar.bz2
OneConfig-153558c19436c6945a5ac534b035b4e3ced1bcaa.zip
Kotlin Language Adapter (1.12-) (#56)
"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."
Diffstat (limited to 'versions/src')
-rw-r--r--versions/src/main/kotlin/cc/polyfrost/oneconfig/utils/KotlinLanguageAdapter.kt33
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