From d5bac2543fee084c2e5aa894963ae6be3f50719f Mon Sep 17 00:00:00 2001 From: thedarkcolour <30441001+thedarkcolour@users.noreply.github.com> Date: Tue, 22 Sep 2020 23:47:26 -0700 Subject: Update to Kotlin for Forge 1.6.0 Close #6 --- build.gradle | 2 +- changelog.md | 4 + gradle.properties | 2 +- .../kotlinforforge/KotlinModContainer.kt | 83 +++++++++++++++++---- .../thedarkcolour/kotlinforforge/forge/Forge.kt | 4 + src/main/resources/META-INF/mods.toml | 1 + .../1.6.0/kotlinforforge-1.6.0-sources.jar | Bin 0 -> 35464 bytes .../1.6.0/kotlinforforge-1.6.0-sources.jar.md5 | 1 + .../1.6.0/kotlinforforge-1.6.0-sources.jar.sha1 | 1 + .../kotlinforforge/1.6.0/kotlinforforge-1.6.0.jar | Bin 0 -> 101438 bytes .../1.6.0/kotlinforforge-1.6.0.jar.md5 | 1 + .../1.6.0/kotlinforforge-1.6.0.jar.sha1 | 1 + .../kotlinforforge/1.6.0/kotlinforforge-1.6.0.pom | 60 +++++++++++++++ .../1.6.0/kotlinforforge-1.6.0.pom.md5 | 1 + .../1.6.0/kotlinforforge-1.6.0.pom.sha1 | 1 + thedarkcolour/kotlinforforge/1.6.0/web.html | 20 +++++ thedarkcolour/kotlinforforge/web.html | 2 + 17 files changed, 167 insertions(+), 17 deletions(-) create mode 100644 thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0-sources.jar create mode 100644 thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0-sources.jar.md5 create mode 100644 thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0-sources.jar.sha1 create mode 100644 thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0.jar create mode 100644 thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0.jar.md5 create mode 100644 thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0.jar.sha1 create mode 100644 thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0.pom create mode 100644 thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0.pom.md5 create mode 100644 thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0.pom.sha1 create mode 100644 thedarkcolour/kotlinforforge/1.6.0/web.html diff --git a/build.gradle b/build.gradle index d3fda5f..4f82dcf 100644 --- a/build.gradle +++ b/build.gradle @@ -22,7 +22,7 @@ apply plugin: 'net.minecraftforge.gradle' apply plugin: 'kotlin' apply plugin: 'org.jetbrains.dokka' -version = "1.5.0" +version = "1.6.0" group = 'thedarkcolour.kotlinforforge' archivesBaseName = 'kotlinforforge' diff --git a/changelog.md b/changelog.md index 955ac4e..1a5b765 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,7 @@ +##Kotlin for Forge 1.6.0 +- Updated to support changes in the Forge API in 1.16.2 and 1.16.3 (KFF should no longer cause crashes) +- Updated to Kotlin 1.4.10 + ##Kotlin for Forge 1.5.0 - Updated to Kotlin 1.4.0 diff --git a/gradle.properties b/gradle.properties index 8a4ba0c..65bbeb0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,6 +3,6 @@ kotlin.code.style=official org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false -kotlin_version=1.4.0 +kotlin_version=1.4.10 coroutines_version = 1.3.9 annotations_version = 20.0.0 \ No newline at end of file diff --git a/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinModContainer.kt b/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinModContainer.kt index 9a7c308..db61225 100644 --- a/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinModContainer.kt +++ b/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinModContainer.kt @@ -15,6 +15,7 @@ import net.minecraftforge.forgespi.language.IModInfo import net.minecraftforge.forgespi.language.ModFileScanData import thedarkcolour.kotlinforforge.eventbus.KotlinEventBus import thedarkcolour.kotlinforforge.kotlin.supply +import java.lang.reflect.Field import java.util.function.Consumer public typealias LifecycleEventListener = (LifecycleEvent) -> Unit @@ -40,17 +41,39 @@ public class KotlinModContainer( */ public val eventBus: KotlinEventBus + private val _triggerMap: MutableMap>? + private val _activityMap: MutableMap? + init { + @Suppress("UNCHECKED_CAST") + _activityMap = try { + ACTIVITY_MAP_FIELD?.get(this) as MutableMap + } catch (e: Exception) { + null + } + @Suppress("UNCHECKED_CAST") + _triggerMap = try { + TRIGGER_MAP_FIELD?.get(this) as MutableMap> + } catch (e: Exception) { + null + } + LOGGER.debug(Logging.LOADING, "Creating KotlinModContainer instance for {} with classLoader {} & {}", className, classLoader, javaClass.classLoader) - triggerMap[ModLoadingStage.CONSTRUCT] = createTrigger(::constructMod, ::afterEvent) - triggerMap[ModLoadingStage.CREATE_REGISTRIES] = createTrigger(::fireEvent, ::afterEvent) - triggerMap[ModLoadingStage.LOAD_REGISTRIES] = createTrigger(::fireEvent, ::afterEvent) - triggerMap[ModLoadingStage.COMMON_SETUP] = createTrigger(::fireEvent, ::afterEvent) - triggerMap[ModLoadingStage.SIDED_SETUP] = createTrigger(::fireEvent, ::afterEvent) - triggerMap[ModLoadingStage.ENQUEUE_IMC] = createTrigger(::fireEvent, ::afterEvent) - triggerMap[ModLoadingStage.PROCESS_IMC] = createTrigger(::fireEvent, ::afterEvent) - triggerMap[ModLoadingStage.COMPLETE] = createTrigger(::fireEvent, ::afterEvent) - triggerMap[ModLoadingStage.GATHERDATA] = createTrigger(::fireEvent, ::afterEvent) + + if (_activityMap != null) { + _activityMap[ModLoadingStage.CONSTRUCT] = Runnable(::constructMod) + } else if (_triggerMap != null) { + _triggerMap[ModLoadingStage.CONSTRUCT] = createTrigger( { constructMod() }, ::afterEvent) + _triggerMap[ModLoadingStage.CREATE_REGISTRIES] = createTrigger(::fireEvent, ::afterEvent) + _triggerMap[ModLoadingStage.LOAD_REGISTRIES] = createTrigger(::fireEvent, ::afterEvent) + _triggerMap[ModLoadingStage.COMMON_SETUP] = createTrigger(::fireEvent, ::afterEvent) + _triggerMap[ModLoadingStage.SIDED_SETUP] = createTrigger(::fireEvent, ::afterEvent) + _triggerMap[ModLoadingStage.ENQUEUE_IMC] = createTrigger(::fireEvent, ::afterEvent) + _triggerMap[ModLoadingStage.PROCESS_IMC] = createTrigger(::fireEvent, ::afterEvent) + _triggerMap[ModLoadingStage.COMPLETE] = createTrigger(::fireEvent, ::afterEvent) + _triggerMap[ModLoadingStage.GATHERDATA] = createTrigger(::fireEvent, ::afterEvent) + } + eventBus = KotlinEventBus(BusBuilder.builder().setExceptionHandler(::onEventFailed).setTrackPhases(false)) contextExtension = supply(KotlinModLoadingContext(this)) } @@ -73,7 +96,13 @@ public class KotlinModContainer( * The `IEventExceptionHandler` that logs * errors in events as errors. */ - private fun onEventFailed(iEventBus: IEventBus, event: Event, iEventListeners: Array, i: Int, throwable: Throwable) { + private fun onEventFailed( + iEventBus: IEventBus, + event: Event, + iEventListeners: Array, + i: Int, + throwable: Throwable + ) { LOGGER.error(EventBusErrorMessage(event, i, iEventListeners, throwable)) } @@ -89,7 +118,7 @@ public class KotlinModContainer( eventBus.post(event) LOGGER.debug(Logging.LOADING, "Fired event for modid $modId : $event") } catch (throwable: Throwable) { - LOGGER.error(Logging.LOADING,"An error occurred while dispatching event ${lifecycleEvent.fromStage()} to $modId") + LOGGER.error(Logging.LOADING, "An error occurred while dispatching event ${lifecycleEvent.fromStage()} to $modId") throw ModLoadingException(modInfo, lifecycleEvent.fromStage(), "fml.modloading.errorduringevent", throwable) } } @@ -107,7 +136,7 @@ public class KotlinModContainer( /** * Initializes [modInstance] and calls the mod constructor */ - private fun constructMod(lifecycleEvent: LifecycleEvent) { + private fun constructMod() { val modClass: Class<*> try { @@ -124,7 +153,7 @@ public class KotlinModContainer( LOGGER.debug(Logging.LOADING, "Loaded mod instance ${getModId()} of type ${modClass.name}") } catch (throwable: Throwable) { LOGGER.error(Logging.LOADING, "Failed to create mod instance. ModID: ${getModId()}, class ${modClass.name}", throwable) - throw ModLoadingException(modInfo, lifecycleEvent.fromStage(), "fml.modloading.failedtoloadmod", throwable, modClass) + throw ModLoadingException(modInfo, ModLoadingStage.CONSTRUCT, "fml.modloading.failedtoloadmod", throwable, modClass) } try { @@ -134,7 +163,7 @@ public class KotlinModContainer( LOGGER.debug(Logging.LOADING, "Completed Automatic Kotlin event subscribers for ${getModId()}") } catch (throwable: Throwable) { LOGGER.error(Logging.LOADING, "Failed to register Automatic Kotlin subscribers. ModID: ${getModId()}, class ${modClass.name}", throwable) - throw ModLoadingException(modInfo, lifecycleEvent.fromStage(), "fml.modloading.failedtoloadmod", throwable, modClass) + throw ModLoadingException(modInfo, ModLoadingStage.CONSTRUCT, "fml.modloading.failedtoloadmod", throwable, modClass) } } @@ -149,6 +178,30 @@ public class KotlinModContainer( override fun getMod(): Any = modInstance override fun acceptEvent(e: Event) { - eventBus.post(e) + try { + LOGGER.debug("Firing event for modid $modId : $e") + eventBus.post(e) + LOGGER.debug("Fired event for modid $modId : $e") + } catch (t: Throwable) { + LOGGER.error("Caught exception during event $e dispatch for modid $modId", t) + throw ModLoadingException(modInfo, modLoadingStage, "fml.modloading.errorduringevent", t) + } + } + + private companion object { + private val TRIGGER_MAP_FIELD: Field? = try { + ModContainer::class.java.getDeclaredField("triggerMap").also { field -> + field.isAccessible = true + } + } catch (e: NoSuchFieldException) { + null + } + private val ACTIVITY_MAP_FIELD: Field? = try { + ModContainer::class.java.getDeclaredField("activityMap").also { field -> + field.isAccessible = true + } + } catch (e: NoSuchFieldException) { + null + } } } \ No newline at end of file diff --git a/src/main/kotlin/thedarkcolour/kotlinforforge/forge/Forge.kt b/src/main/kotlin/thedarkcolour/kotlinforforge/forge/Forge.kt index 01f9e90..44fa17b 100644 --- a/src/main/kotlin/thedarkcolour/kotlinforforge/forge/Forge.kt +++ b/src/main/kotlin/thedarkcolour/kotlinforforge/forge/Forge.kt @@ -76,6 +76,10 @@ public val DIST: Dist = FMLEnvironment.dist * The instance of Minecraft. * Make sure to only call this on the client side. */ +@Deprecated( + message = "Will be removed in 1.7.0 to improve compatibility between Minecraft versions", + replaceWith = ReplaceWith("Minecraft.getInstance()", "net.minecraft.client.Minecraft") +) public val MINECRAFT: Minecraft @OnlyIn(Dist.CLIENT) inline get() = Minecraft.getInstance() diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 47e863b..27b9220 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -1,5 +1,6 @@ modLoader="kotlinforforge" # IModLanguageProvider loaderVersion="[1.4,)" # IModLanguageProvider version +license="GPL v3.0" issueTrackerURL="https://github.com/thedarkcolour/KotlinForForge/issues" # Issues page diff --git a/thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0-sources.jar b/thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0-sources.jar new file mode 100644 index 0000000..dcf2d95 Binary files /dev/null and b/thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0-sources.jar differ diff --git a/thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0-sources.jar.md5 b/thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0-sources.jar.md5 new file mode 100644 index 0000000..797e069 --- /dev/null +++ b/thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0-sources.jar.md5 @@ -0,0 +1 @@ +b1142af56f456c106408978ef1eb7a8f \ No newline at end of file diff --git a/thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0-sources.jar.sha1 b/thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0-sources.jar.sha1 new file mode 100644 index 0000000..94a3822 --- /dev/null +++ b/thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0-sources.jar.sha1 @@ -0,0 +1 @@ +e5489c782e96930d31311145bfbd4e039c1adc47 \ No newline at end of file diff --git a/thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0.jar b/thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0.jar new file mode 100644 index 0000000..9640c0d Binary files /dev/null and b/thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0.jar differ diff --git a/thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0.jar.md5 b/thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0.jar.md5 new file mode 100644 index 0000000..78086b4 --- /dev/null +++ b/thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0.jar.md5 @@ -0,0 +1 @@ +7c1dc80e2c8e6aa4eedeba177e7ada1f \ No newline at end of file diff --git a/thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0.jar.sha1 b/thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0.jar.sha1 new file mode 100644 index 0000000..108c6b5 --- /dev/null +++ b/thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0.jar.sha1 @@ -0,0 +1 @@ +0576ee8ece609f508ce54959a1f93510fc4eef93 \ No newline at end of file diff --git a/thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0.pom b/thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0.pom new file mode 100644 index 0000000..828cb0f --- /dev/null +++ b/thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0.pom @@ -0,0 +1,60 @@ + + + 4.0.0 + thedarkcolour + kotlinforforge + 1.6.0 + + + kt-eap + Kotlin Early Access + https://dl.bintray.com/kotlin/kotlin-eap + + + + + org.jetbrains.kotlin + kotlin-stdlib + 1.4.10 + compile + + + org.jetbrains.kotlin + kotlin-stdlib-jdk7 + 1.4.10 + compile + + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + 1.4.10 + compile + + + org.jetbrains.kotlin + kotlin-reflect + 1.4.10 + compile + + + org.jetbrains + annotations + 19.0.0 + compile + + + org.jetbrains.kotlinx + kotlinx-coroutines-core + 1.3.7 + compile + + + org.jetbrains.kotlinx + kotlinx-coroutines-jdk8 + 1.3.7 + compile + + + diff --git a/thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0.pom.md5 b/thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0.pom.md5 new file mode 100644 index 0000000..cf20807 --- /dev/null +++ b/thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0.pom.md5 @@ -0,0 +1 @@ +6616a46d9a78fb0cec8cf66dc1b63588 \ No newline at end of file diff --git a/thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0.pom.sha1 b/thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0.pom.sha1 new file mode 100644 index 0000000..cecc5b0 --- /dev/null +++ b/thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0.pom.sha1 @@ -0,0 +1 @@ +258bfacceba7b2ecd1ed6d4c6f644a1bdc30c556 \ No newline at end of file diff --git a/thedarkcolour/kotlinforforge/1.6.0/web.html b/thedarkcolour/kotlinforforge/1.6.0/web.html new file mode 100644 index 0000000..d8e1a08 --- /dev/null +++ b/thedarkcolour/kotlinforforge/1.6.0/web.html @@ -0,0 +1,20 @@ + + +Index of /1.6.0/ + +

Index of /kotlinforforge/

+
+
../
+kotlinforforge-1.6.0-sources.jar
+kotlinforforge-1.6.0-sources.jar.sha1
+kotlinforforge-1.6.0-sources.jar.md5
+kotlinforforge-1.6.0.jar
+kotlinforforge-1.6.0.jar.sha1
+kotlinforforge-1.6.0.jar.md5
+kotlinforforge-1.6.0.pom
+kotlinforforge-1.6.0.pom.sha1
+kotlinforforge-1.6.0.pom.md5
+
+
+ + diff --git a/thedarkcolour/kotlinforforge/web.html b/thedarkcolour/kotlinforforge/web.html index fc75942..3a5ec8f 100644 --- a/thedarkcolour/kotlinforforge/web.html +++ b/thedarkcolour/kotlinforforge/web.html @@ -18,6 +18,8 @@ 1.3.1 1.4.0 1.4.1 +1.5.0 +1.6.0 maven-metadata.xml maven-metadata.xml.md5 maven-metadata.xml.sha1 -- cgit