aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/kotlin/thedarkcolour/kotlinforforge/AutoKotlinEventBusSubscriber.kt25
-rw-r--r--src/main/kotlin/thedarkcolour/kotlinforforge/KotlinForForge.kt2
-rw-r--r--src/main/kotlin/thedarkcolour/kotlinforforge/forge/Forge.kt22
3 files changed, 31 insertions, 18 deletions
diff --git a/src/main/kotlin/thedarkcolour/kotlinforforge/AutoKotlinEventBusSubscriber.kt b/src/main/kotlin/thedarkcolour/kotlinforforge/AutoKotlinEventBusSubscriber.kt
index 78325ee..3f4698f 100644
--- a/src/main/kotlin/thedarkcolour/kotlinforforge/AutoKotlinEventBusSubscriber.kt
+++ b/src/main/kotlin/thedarkcolour/kotlinforforge/AutoKotlinEventBusSubscriber.kt
@@ -53,20 +53,23 @@ public object AutoKotlinEventBusSubscriber {
val modid = annotationData.annotationData.getOrDefault("modid", mod.modId)
val busTargetHolder = annotationData.annotationData.getOrDefault("bus", ModAnnotation.EnumHolder(null, "FORGE")) as ModAnnotation.EnumHolder
val busTarget = Mod.EventBusSubscriber.Bus.valueOf(busTargetHolder.value)
- val ktObject = Class.forName(annotationData.classType.className, true, classLoader).kotlin.objectInstance
- if (ktObject != null && mod.modId == modid && DIST in sides) {
- try {
- LOGGER.debug(Logging.LOADING, "Auto-subscribing kotlin object ${annotationData.classType.className} to $busTarget")
+ if (mod.modId == modid && DIST in sides) {
+ val ktObject = Class.forName(annotationData.classType.className, true, classLoader).kotlin.objectInstance
- if (busTarget == Mod.EventBusSubscriber.Bus.MOD) {
- MOD_BUS.register(ktObject)
- } else {
- FORGE_BUS.register(ktObject)
+ if (ktObject != null) {
+ try {
+ LOGGER.debug(Logging.LOADING, "Auto-subscribing kotlin object ${annotationData.classType.className} to $busTarget")
+
+ if (busTarget == Mod.EventBusSubscriber.Bus.MOD) {
+ MOD_BUS.register(ktObject)
+ } else {
+ FORGE_BUS.register(ktObject)
+ }
+ } catch (e: Throwable) {
+ LOGGER.fatal(Logging.LOADING, "Failed to load mod class ${annotationData.classType} for @EventBusSubscriber annotation", e)
+ throw RuntimeException(e)
}
- } catch (e: Throwable) {
- LOGGER.fatal(Logging.LOADING, "Failed to load mod class ${annotationData.classType} for @EventBusSubscriber annotation", e)
- throw RuntimeException(e)
}
}
}
diff --git a/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinForForge.kt b/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinForForge.kt
index 237c445..168d3f0 100644
--- a/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinForForge.kt
+++ b/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinForForge.kt
@@ -5,7 +5,7 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext
/**
* Set `modLoader` in mods.toml to
- * `"kotlinforforge"` and loaderVersion to `"[1.4,)"`.
+ * `"kotlinforforge"` and loaderVersion to `"[1.7,)"`.
*
* Make sure to use [KotlinModLoadingContext]
* instead of [FMLJavaModLoadingContext].
diff --git a/src/main/kotlin/thedarkcolour/kotlinforforge/forge/Forge.kt b/src/main/kotlin/thedarkcolour/kotlinforforge/forge/Forge.kt
index 44fa17b..8289456 100644
--- a/src/main/kotlin/thedarkcolour/kotlinforforge/forge/Forge.kt
+++ b/src/main/kotlin/thedarkcolour/kotlinforforge/forge/Forge.kt
@@ -78,7 +78,8 @@ public val DIST: Dist = FMLEnvironment.dist
*/
@Deprecated(
message = "Will be removed in 1.7.0 to improve compatibility between Minecraft versions",
- replaceWith = ReplaceWith("Minecraft.getInstance()", "net.minecraft.client.Minecraft")
+ replaceWith = ReplaceWith("Minecraft.getInstance()", "net.minecraft.client.Minecraft"),
+ level = DeprecationLevel.ERROR,
)
public val MINECRAFT: Minecraft
@OnlyIn(Dist.CLIENT)
@@ -87,8 +88,11 @@ public val MINECRAFT: Minecraft
/** @since 1.0.0
* An alternative to [net.minecraftforge.fml.DistExecutor.callWhenOn]
* that inlines the callable.
+ *
+ * @since 1.6.1
+ * No longer an inline function to maintain side safety
*/
-public inline fun <T> callWhenOn(dist: Dist, toRun: () -> T): T? {
+public fun <T> callWhenOn(dist: Dist, toRun: () -> T): T? {
return if (DIST == dist) {
try {
toRun()
@@ -103,8 +107,11 @@ public inline fun <T> callWhenOn(dist: Dist, toRun: () -> T): T? {
/** @since 1.0.0
* An alternative to [net.minecraftforge.fml.DistExecutor.runWhenOn]
* that inlines the runnable.
+ *
+ * @since 1.6.1
+ * No longer an inline function to maintain side safety
*/
-public inline fun runWhenOn(dist: Dist, toRun: () -> Unit) {
+public fun runWhenOn(dist: Dist, toRun: () -> Unit) {
if (DIST == dist) {
toRun()
}
@@ -113,8 +120,11 @@ public inline fun runWhenOn(dist: Dist, toRun: () -> Unit) {
/** @since 1.0.0
* An alternative to [net.minecraftforge.fml.DistExecutor.runForDist]
* that inlines the function call.
+ *
+ * @since 1.6.1
+ * No longer an inline function to maintain side safety
*/
-public inline fun <T> runForDist(clientTarget: () -> T, serverTarget: () -> T): T {
+public fun <T> runForDist(clientTarget: () -> T, serverTarget: () -> T): T {
return when (DIST) {
Dist.CLIENT -> clientTarget()
Dist.DEDICATED_SERVER -> serverTarget()
@@ -186,8 +196,8 @@ public inline fun <reified T : IForgeRegistryEntry<in T>> objectHolder(namespace
*/
public inline fun <reified T : IForgeRegistryEntry<in T>> objectHolder(registryName: String): ReadOnlyProperty<Any?, T> {
return ObjectHolderDelegate(
- registryName = GameData.checkPrefix(registryName, true),
- registry = ObjectHolderDelegate.getRegistry(T::class.java)
+ registryName = GameData.checkPrefix(registryName, true),
+ registry = ObjectHolderDelegate.getRegistry(T::class.java)
)
}