aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/kotlin/thedarkcolour/kotlinforforge/AutoKotlinEventBusSubscriber.kt23
-rw-r--r--src/main/kotlin/thedarkcolour/kotlinforforge/KotlinForForge.kt5
-rw-r--r--src/main/kotlin/thedarkcolour/kotlinforforge/KotlinModContainer.kt5
-rw-r--r--src/main/kotlin/thedarkcolour/kotlinforforge/KotlinModLoadingContext.kt2
-rw-r--r--src/main/resources/META-INF/mods.toml5
5 files changed, 20 insertions, 20 deletions
diff --git a/src/main/kotlin/thedarkcolour/kotlinforforge/AutoKotlinEventBusSubscriber.kt b/src/main/kotlin/thedarkcolour/kotlinforforge/AutoKotlinEventBusSubscriber.kt
index b77a567..e36f9ce 100644
--- a/src/main/kotlin/thedarkcolour/kotlinforforge/AutoKotlinEventBusSubscriber.kt
+++ b/src/main/kotlin/thedarkcolour/kotlinforforge/AutoKotlinEventBusSubscriber.kt
@@ -1,6 +1,7 @@
package thedarkcolour.kotlinforforge
import net.minecraftforge.api.distmarker.Dist
+import net.minecraftforge.common.MinecraftForge
import net.minecraftforge.fml.Logging
import net.minecraftforge.fml.ModContainer
import net.minecraftforge.fml.common.Mod
@@ -11,7 +12,6 @@ import org.objectweb.asm.Type
import thedarkcolour.kotlinforforge.KotlinForForge.logger
import java.util.*
import java.util.stream.Collectors
-import kotlin.reflect.full.companionObjectInstance
/**
* Handles [net.minecraftforge.fml.common.Mod.EventBusSubscriber]
@@ -39,9 +39,9 @@ object AutoKotlinEventBusSubscriber {
* You must define the [net.minecraftforge.eventbus.api.SubscribeEvent] methods inside the companion object.
* Example Usage:
*
- * @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
* public class ExampleSubscriberClass {
*
+ * @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
* companion object ExampleSubscriberCompanion {
* @SubscribeEvent
* public fun onItemRegistry(event: RegistryEvent.Register<Item>) {
@@ -65,25 +65,20 @@ object AutoKotlinEventBusSubscriber {
val modid = annotationData.annotationData.getOrDefault("modid", mod.modId)
val busTargetHolder: ModAnnotation.EnumHolder = annotationData.annotationData.getOrDefault("bus", ModAnnotation.EnumHolder(null, "FORGE")) as ModAnnotation.EnumHolder
val busTarget = Mod.EventBusSubscriber.Bus.valueOf(busTargetHolder.value)
- val clazz = Class.forName(annotationData.classType.className, true, classLoader)
- val ktClass = clazz.kotlin
- val ktObject = ktClass.objectInstance
+ val ktObject = Class.forName(annotationData.classType.className, true, classLoader).kotlin.objectInstance
if (ktObject != null && mod.modId == modid && sides.contains(FMLEnvironment.dist)) {
try {
logger.debug(Logging.LOADING, "Auto-subscribing kotlin object {} to {}", annotationData.classType.className, busTarget)
- busTarget.bus().get().register(ktObject)
+ if (busTarget == Mod.EventBusSubscriber.Bus.MOD) {
+ // Gets the correct mod loading context
+ KotlinModLoadingContext.get().getEventBus().register(ktObject)
+ } else {
+ MinecraftForge.EVENT_BUS.register(ktObject)
+ }
} catch (e: Throwable) {
logger.fatal(Logging.LOADING, "Failed to load mod class {} for @EventBusSubscriber annotation", annotationData.classType, e)
throw RuntimeException(e)
}
- } else if (ktClass.companionObjectInstance != null) {
- try {
- logger.debug(Logging.LOADING, "Auto-subscribing kotlin companion object from {} to {}", ktClass.simpleName, busTarget)
- busTarget.bus().get().register(ktClass.companionObjectInstance)
- } catch (e: Throwable) {
- logger.fatal(Logging.LOADING, "Failed to load kotlin companion object {} for @EventBusSubscriber annotation", annotationData.classType, e)
- throw RuntimeException(e)
- }
}
}
}
diff --git a/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinForForge.kt b/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinForForge.kt
index e697f10..337f82a 100644
--- a/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinForForge.kt
+++ b/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinForForge.kt
@@ -1,11 +1,14 @@
package thedarkcolour.kotlinforforge
import net.minecraftforge.fml.common.Mod
+import net.minecraftforge.registries.DeferredRegister
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger
/**
- * Set 'modLoader' in mods.toml to "kotlinforforge".
+ * Set 'modLoader' in mods.toml to "kotlinforforge" and loaderVersion to "1".
+ *
+ * It is recommended that you use [DeferredRegister] instead of ObjectHolders.
*/
@Mod("kotlinforforge")
object KotlinForForge {
diff --git a/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinModContainer.kt b/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinModContainer.kt
index 26a65ea..28722cd 100644
--- a/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinModContainer.kt
+++ b/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinModContainer.kt
@@ -54,8 +54,11 @@ class KotlinModContainer(info: IModInfo, className: String, loader: ClassLoader,
private fun fireEvent(lifecycleEvent: LifecycleEventProvider.LifecycleEvent) {
val event = lifecycleEvent.getOrBuildEvent(this)
- logger.debug(Logging.LOADING, "Firing event for modid {} : {}", this.getModId(), event)
+ logger.debug(Logging.LOADING, "Firing event for modid {} : {}", getModId(), event)
+ // Now actually fires the event
try {
+ eventBus.post(event)
+ logger.debug(Logging.LOADING, "Fired event for modid {} : {}", getModId(), event)
} catch (e: Throwable) {
logger.error(Logging.LOADING,"An error occurred while dispatching event {} to {}", lifecycleEvent.fromStage(), modId)
diff --git a/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinModLoadingContext.kt b/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinModLoadingContext.kt
index 4b7edc0..766b64d 100644
--- a/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinModLoadingContext.kt
+++ b/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinModLoadingContext.kt
@@ -10,7 +10,7 @@ class KotlinModLoadingContext internal constructor(private val container: Kotlin
companion object {
@JvmStatic
- fun get() {
+ fun get(): KotlinModLoadingContext {
return ModLoadingContext.get().extension()
}
}
diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml
index ff8cd97..e79af5b 100644
--- a/src/main/resources/META-INF/mods.toml
+++ b/src/main/resources/META-INF/mods.toml
@@ -1,9 +1,8 @@
modLoader="kotlinforforge" # IModLanguageProvider
-loaderVersion="[25,)" # IModLanguageProvider version
+loaderVersion="[1,)" # IModLanguageProvider version
issueTrackerURL="https://github.com/thedarkcolour/Future-MC/issues" # Issues page
-
#displayURL="https://minecraft.curseforge.com/projects/kotlinforforge" #optional
description='''
@@ -14,7 +13,7 @@ Kotlin for Forge. Allows mods to use the Kotlin programming language.
[[dependencies.kotlinforforge]] #optional
modId="forge" #mandatory
mandatory=true #mandatory
- versionRange="[25,)" #mandatory
+ versionRange="[28,)" #mandatory
# An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory
ordering="NONE"