diff options
author | thedarkcolour <30441001+thedarkcolour@users.noreply.github.com> | 2020-09-22 23:47:26 -0700 |
---|---|---|
committer | thedarkcolour <30441001+thedarkcolour@users.noreply.github.com> | 2020-09-22 23:47:26 -0700 |
commit | d5bac2543fee084c2e5aa894963ae6be3f50719f (patch) | |
tree | 8001027a27d0020bcd55956b6d520b3444540c25 | |
parent | 6e70a0c14e658cd7ccfd4e1846f8967a81290260 (diff) | |
download | KotlinForForge-d5bac2543fee084c2e5aa894963ae6be3f50719f.tar.gz KotlinForForge-d5bac2543fee084c2e5aa894963ae6be3f50719f.tar.bz2 KotlinForForge-d5bac2543fee084c2e5aa894963ae6be3f50719f.zip |
Update to Kotlin for Forge 1.6.0
Close #6
17 files changed, 167 insertions, 17 deletions
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<ModLoadingStage, Consumer<LifecycleEvent>>? + private val _activityMap: MutableMap<ModLoadingStage, Runnable>? + init { + @Suppress("UNCHECKED_CAST") + _activityMap = try { + ACTIVITY_MAP_FIELD?.get(this) as MutableMap<ModLoadingStage, Runnable> + } catch (e: Exception) { + null + } + @Suppress("UNCHECKED_CAST") + _triggerMap = try { + TRIGGER_MAP_FIELD?.get(this) as MutableMap<ModLoadingStage, Consumer<LifecycleEvent>> + } 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<IEventListener>, i: Int, throwable: Throwable) { + private fun onEventFailed( + iEventBus: IEventBus, + event: Event, + iEventListeners: Array<IEventListener>, + 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 Binary files differnew file mode 100644 index 0000000..dcf2d95 --- /dev/null +++ b/thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0-sources.jar 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 Binary files differnew file mode 100644 index 0000000..9640c0d --- /dev/null +++ b/thedarkcolour/kotlinforforge/1.6.0/kotlinforforge-1.6.0.jar 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" + xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <modelVersion>4.0.0</modelVersion> + <groupId>thedarkcolour</groupId> + <artifactId>kotlinforforge</artifactId> + <version>1.6.0</version> + <repositories> + <repository> + <id>kt-eap</id> + <name>Kotlin Early Access</name> + <url>https://dl.bintray.com/kotlin/kotlin-eap</url> + </repository> + </repositories> + <dependencies> + <dependency> + <groupId>org.jetbrains.kotlin</groupId> + <artifactId>kotlin-stdlib</artifactId> + <version>1.4.10</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.jetbrains.kotlin</groupId> + <artifactId>kotlin-stdlib-jdk7</artifactId> + <version>1.4.10</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.jetbrains.kotlin</groupId> + <artifactId>kotlin-stdlib-jdk8</artifactId> + <version>1.4.10</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.jetbrains.kotlin</groupId> + <artifactId>kotlin-reflect</artifactId> + <version>1.4.10</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.jetbrains</groupId> + <artifactId>annotations</artifactId> + <version>19.0.0</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.jetbrains.kotlinx</groupId> + <artifactId>kotlinx-coroutines-core</artifactId> + <version>1.3.7</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.jetbrains.kotlinx</groupId> + <artifactId>kotlinx-coroutines-jdk8</artifactId> + <version>1.3.7</version> + <scope>compile</scope> + </dependency> + </dependencies> +</project> 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 @@ +<html lang="HTML5"> +<link rel="stylesheet" href="../../style.css"> +<head><title>Index of /1.6.0/</title></head> +<body> +<h1>Index of /kotlinforforge/</h1> +<hr> +<pre><a href="../web.html">../</a> +<a href="kotlinforforge-1.6.0-sources.jar">kotlinforforge-1.6.0-sources.jar</a> +<a href="kotlinforforge-1.6.0-sources.jar.sha1">kotlinforforge-1.6.0-sources.jar.sha1</a> +<a href="kotlinforforge-1.6.0-sources.jar.md5">kotlinforforge-1.6.0-sources.jar.md5</a> +<a href="kotlinforforge-1.6.0.jar">kotlinforforge-1.6.0.jar</a> +<a href="kotlinforforge-1.6.0.jar.sha1">kotlinforforge-1.6.0.jar.sha1</a> +<a href="kotlinforforge-1.6.0.jar.md5">kotlinforforge-1.6.0.jar.md5</a> +<a href="kotlinforforge-1.6.0.pom">kotlinforforge-1.6.0.pom</a> +<a href="kotlinforforge-1.6.0.pom.sha1">kotlinforforge-1.6.0.pom.sha1</a> +<a href="kotlinforforge-1.6.0.pom.md5">kotlinforforge-1.6.0.pom.md5</a> +</pre> +<hr> +</body> +</html> 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 @@ <a href="1.3.1/web.html">1.3.1</a> <a href="1.4.0/web.html">1.4.0</a> <a href="1.4.1/web.html">1.4.1</a> +<a href="1.5.0/web.html">1.5.0</a> +<a href="1.6.0/web.html">1.6.0</a> <a href="maven-metadata.xml">maven-metadata.xml</a> <a href="maven-metadata.xml.md5">maven-metadata.xml.md5</a> <a href="maven-metadata.xml.sha1">maven-metadata.xml.sha1</a> |