diff options
author | thedarkcolour <30441001+thedarkcolour@users.noreply.github.com> | 2019-11-09 11:12:21 -0800 |
---|---|---|
committer | thedarkcolour <30441001+thedarkcolour@users.noreply.github.com> | 2019-11-09 11:12:21 -0800 |
commit | 00d859187a8ca433028634e56bd30243ddaa69a4 (patch) | |
tree | 0582bdb9aa28e1117c72332535f3805ed8864712 | |
parent | 7716f30272565f750182d58da753cd4cffb88761 (diff) | |
download | KotlinForForge-00d859187a8ca433028634e56bd30243ddaa69a4.tar.gz KotlinForForge-00d859187a8ca433028634e56bd30243ddaa69a4.tar.bz2 KotlinForForge-00d859187a8ca433028634e56bd30243ddaa69a4.zip |
Adding files
29 files changed, 87 insertions, 55 deletions
@@ -2,18 +2,39 @@ Makes Kotlin forge-friendly. To implement in your project, add the following to your build.gradle: -``` +```groovy repositories { maven { - name = "kotlinforforge" - url = "https://cdn.jsdelivr.net/gh/thedarkcolour/KotlinForForge@master/" + name = 'kotlinforforge' + url = 'https://thedarkcolour.github.io/KotlinForForge/' } } dependencies { - implementation 'thedarkcolour:kotlinforforge:0.1.14' + implementation 'thedarkcolour:kotlinforforge:1+' } ``` -Then, in your mods.toml file, change modLoader to "kotlinforforge". +Then, add the following to your mods.toml file: +```toml +modLoader="kotlinforforge" +loaderVersion="[1,)" + +[[dependencies.YOUR_MODID]] + modId="kotlinforforge" + mandatory=true + versionRange="[1,)" + ordering="NONE" + side="BOTH" +``` + +Currently, this mod supports object declarations with @Mod and @EventBusSubscriber annotations. + +It is recommended that you use +```net.minecraftforge.registries.DeferredRegister``` +instead of +```net.minecraftforge.registries.ObjectHolder``` -Currently, this mod allows you to have @Mod object declarations and @Mod.EventBusSubscriber declarations. +You must use +```thedarkcolour.kotlinforforge.KotlinModLoadingContext``` +instead of +```net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext``` diff --git a/build.gradle b/build.gradle index 005d8ae..bcca42e 100644 --- a/build.gradle +++ b/build.gradle @@ -21,7 +21,7 @@ apply plugin: 'eclipse' apply plugin: 'idea' apply plugin: 'kotlin' -version = '0.1.14' +version = '1.0.0' group = 'thedarkcolour.kotlinforforge' // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = 'kotlinforforge' @@ -114,6 +114,20 @@ shadowJar { } } +jar { + manifest { + attributes([ + "Specification-Title": "kotlinforforge", + "Specification-Vendor": "thedarkcolour", + "Specification-Version": "1", // We are version 1 of ourselves + "Implementation-Title": project.name, + "Implementation-Version": "${version}", + "Implementation-Vendor" :"thedarkcolour", + "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") + ]) + } +} + // Example configuration to allow publishing using the maven-publish task // we define a custom artifact that is sourced from the reobfJar output task // and then declare that to be published 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" diff --git a/thedarkcolour/kotlinforforge/0.1.14/kotlinforforge-0.1.14-sources.jar b/thedarkcolour/kotlinforforge/0.1.14/kotlinforforge-0.1.14-sources.jar Binary files differdeleted file mode 100644 index 085ef14..0000000 --- a/thedarkcolour/kotlinforforge/0.1.14/kotlinforforge-0.1.14-sources.jar +++ /dev/null diff --git a/thedarkcolour/kotlinforforge/0.1.14/kotlinforforge-0.1.14-sources.jar.md5 b/thedarkcolour/kotlinforforge/0.1.14/kotlinforforge-0.1.14-sources.jar.md5 deleted file mode 100644 index 1a1490f..0000000 --- a/thedarkcolour/kotlinforforge/0.1.14/kotlinforforge-0.1.14-sources.jar.md5 +++ /dev/null @@ -1 +0,0 @@ -de722d8d8d23859c6679b8deaf445b62
\ No newline at end of file diff --git a/thedarkcolour/kotlinforforge/0.1.14/kotlinforforge-0.1.14-sources.jar.sha1 b/thedarkcolour/kotlinforforge/0.1.14/kotlinforforge-0.1.14-sources.jar.sha1 deleted file mode 100644 index 09f460c..0000000 --- a/thedarkcolour/kotlinforforge/0.1.14/kotlinforforge-0.1.14-sources.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -f936ba9006860b4116162781f15668c4073ec806
\ No newline at end of file diff --git a/thedarkcolour/kotlinforforge/0.1.14/kotlinforforge-0.1.14.jar.md5 b/thedarkcolour/kotlinforforge/0.1.14/kotlinforforge-0.1.14.jar.md5 deleted file mode 100644 index da94729..0000000 --- a/thedarkcolour/kotlinforforge/0.1.14/kotlinforforge-0.1.14.jar.md5 +++ /dev/null @@ -1 +0,0 @@ -60e1f9b114948faa2d78c7b6963a4872
\ No newline at end of file diff --git a/thedarkcolour/kotlinforforge/0.1.14/kotlinforforge-0.1.14.jar.sha1 b/thedarkcolour/kotlinforforge/0.1.14/kotlinforforge-0.1.14.jar.sha1 deleted file mode 100644 index e9f62b3..0000000 --- a/thedarkcolour/kotlinforforge/0.1.14/kotlinforforge-0.1.14.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -742712c81e4efbcef8e5fe5fefee0c928dcfa4ff
\ No newline at end of file diff --git a/thedarkcolour/kotlinforforge/0.1.14/kotlinforforge-0.1.14.pom.md5 b/thedarkcolour/kotlinforforge/0.1.14/kotlinforforge-0.1.14.pom.md5 deleted file mode 100644 index 82d7f26..0000000 --- a/thedarkcolour/kotlinforforge/0.1.14/kotlinforforge-0.1.14.pom.md5 +++ /dev/null @@ -1 +0,0 @@ -efa8d4c4f41b791d50896bdcd81d7e8e
\ No newline at end of file diff --git a/thedarkcolour/kotlinforforge/0.1.14/kotlinforforge-0.1.14.pom.sha1 b/thedarkcolour/kotlinforforge/0.1.14/kotlinforforge-0.1.14.pom.sha1 deleted file mode 100644 index 6d58028..0000000 --- a/thedarkcolour/kotlinforforge/0.1.14/kotlinforforge-0.1.14.pom.sha1 +++ /dev/null @@ -1 +0,0 @@ -71094316222578b98c840ae5bf343c5106121e10
\ No newline at end of file diff --git a/thedarkcolour/kotlinforforge/0.1.14/web.html b/thedarkcolour/kotlinforforge/0.1.14/web.html deleted file mode 100644 index f81ca34..0000000 --- a/thedarkcolour/kotlinforforge/0.1.14/web.html +++ /dev/null @@ -1,15 +0,0 @@ -<html> -<head><title>Index of /kotlinforforge/</title></head> -<body> -<h1>Index of /kotlinforforge/</h1><hr><pre><a href="../web.html">../</a> -<a href="kotlinforforge-0.1.14-sources.jar">kotlinforforge-0.1.14-sources.jar</a> -<a href="kotlinforforge-0.1.14-sources.jar.sha1">kotlinforforge-0.1.14-sources.jar.sha1</a> -<a href="kotlinforforge-0.1.14-sources.jar.md5">kotlinforforge-0.1.14-sources.jar.md5</a> -<a href="kotlinforforge-0.1.14.jar">kotlinforforge-0.1.14.jar</a> -<a href="kotlinforforge-0.1.14.jar.sha1">kotlinforforge-0.1.14.jar.sha1</a> -<a href="kotlinforforge-0.1.14.jar.md5">kotlinforforge-0.1.14.jar.md5</a> -<a href="kotlinforforge-0.1.14.pom">kotlinforforge-0.1.14.pom</a> -<a href="kotlinforforge-0.1.14.pom.sha1">kotlinforforge-0.1.14.pom.sha1</a> -<a href="kotlinforforge-0.1.14.pom.md5">kotlinforforge-0.1.14.pom.md5</a> -</pre><hr></body> -</html> diff --git a/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0-sources.jar b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0-sources.jar Binary files differnew file mode 100644 index 0000000..fdb0c44 --- /dev/null +++ b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0-sources.jar diff --git a/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0-sources.jar.md5 b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0-sources.jar.md5 new file mode 100644 index 0000000..e48a186 --- /dev/null +++ b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0-sources.jar.md5 @@ -0,0 +1 @@ +0fca7a1ebe5aa4bd373846697413708f
\ No newline at end of file diff --git a/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0-sources.jar.sha1 b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0-sources.jar.sha1 new file mode 100644 index 0000000..027bd4c --- /dev/null +++ b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0-sources.jar.sha1 @@ -0,0 +1 @@ +fb64405967002751f7cc7da0877a7f0e1c4fdda7
\ No newline at end of file diff --git a/thedarkcolour/kotlinforforge/0.1.14/kotlinforforge-0.1.14.jar b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.jar Binary files differindex 6b873e2..d48167a 100644 --- a/thedarkcolour/kotlinforforge/0.1.14/kotlinforforge-0.1.14.jar +++ b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.jar diff --git a/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.jar.md5 b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.jar.md5 new file mode 100644 index 0000000..6cc63d3 --- /dev/null +++ b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.jar.md5 @@ -0,0 +1 @@ +51c46fc8b03b372f5a8e06776d065c3d
\ No newline at end of file diff --git a/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.jar.sha1 b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.jar.sha1 new file mode 100644 index 0000000..54e4e7c --- /dev/null +++ b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.jar.sha1 @@ -0,0 +1 @@ +849ca5988926423671abd3a052285cc050b9e3f4
\ No newline at end of file diff --git a/thedarkcolour/kotlinforforge/0.1.14/kotlinforforge-0.1.14.pom b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.pom index 31f5781..f76b5f0 100644 --- a/thedarkcolour/kotlinforforge/0.1.14/kotlinforforge-0.1.14.pom +++ b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.pom @@ -4,7 +4,7 @@ <modelVersion>4.0.0</modelVersion> <groupId>thedarkcolour</groupId> <artifactId>kotlinforforge</artifactId> - <version>0.1.14</version> + <version>1.0.0</version> <dependencies> <dependency> <groupId>org.jetbrains.kotlin</groupId> diff --git a/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.pom.md5 b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.pom.md5 new file mode 100644 index 0000000..99a6664 --- /dev/null +++ b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.pom.md5 @@ -0,0 +1 @@ +e27987735a4086178bbb3759c8f9fde8
\ No newline at end of file diff --git a/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.pom.sha1 b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.pom.sha1 new file mode 100644 index 0000000..04c31d6 --- /dev/null +++ b/thedarkcolour/kotlinforforge/1.0.0/kotlinforforge-1.0.0.pom.sha1 @@ -0,0 +1 @@ +9e66fcb9607e4e8be3496531519e2f6a4f67ead8
\ No newline at end of file diff --git a/thedarkcolour/kotlinforforge/1.0.0/web.html b/thedarkcolour/kotlinforforge/1.0.0/web.html new file mode 100644 index 0000000..6ded7dc --- /dev/null +++ b/thedarkcolour/kotlinforforge/1.0.0/web.html @@ -0,0 +1,15 @@ +<html> +<head><title>Index of /kotlinforforge/</title></head> +<body> +<h1>Index of /kotlinforforge/</h1><hr><pre><a href="../web.html">../</a> +<a href="kotlinforforge-1.0.0-sources.jar">kotlinforforge-1.0.0-sources.jar</a> +<a href="kotlinforforge-1.0.0-sources.jar.sha1">kotlinforforge-1.0.0-sources.jar.sha1</a> +<a href="kotlinforforge-1.0.0-sources.jar.md5">kotlinforforge-1.0.0-sources.jar.md5</a> +<a href="kotlinforforge-1.0.0.jar">kotlinforforge-1.0.0.jar</a> +<a href="kotlinforforge-1.0.0.jar.sha1">kotlinforforge-1.0.0.jar.sha1</a> +<a href="kotlinforforge-1.0.0.jar.md5">kotlinforforge-1.0.0.jar.md5</a> +<a href="kotlinforforge-1.0.0.pom">kotlinforforge-1.0.0.pom</a> +<a href="kotlinforforge-1.0.0.pom.sha1">kotlinforforge-1.0.0.pom.sha1</a> +<a href="kotlinforforge-1.0.0.pom.md5">kotlinforforge-1.0.0.pom.md5</a> +</pre><hr></body> +</html> diff --git a/thedarkcolour/kotlinforforge/maven-metadata.xml b/thedarkcolour/kotlinforforge/maven-metadata.xml index 61af43b..5efbe50 100644 --- a/thedarkcolour/kotlinforforge/maven-metadata.xml +++ b/thedarkcolour/kotlinforforge/maven-metadata.xml @@ -3,10 +3,9 @@ <groupId>thedarkcolour</groupId> <artifactId>kotlinforforge</artifactId> <versioning> - <release>0.1.14</release> + <release>1.0.0</release> <versions> - <version>0.1.14</version> + <version>1.0.0</version> </versions> - <lastUpdated>20190624032818</lastUpdated> </versioning> </metadata> diff --git a/thedarkcolour/kotlinforforge/maven-metadata.xml.md5 b/thedarkcolour/kotlinforforge/maven-metadata.xml.md5 deleted file mode 100644 index a421643..0000000 --- a/thedarkcolour/kotlinforforge/maven-metadata.xml.md5 +++ /dev/null @@ -1 +0,0 @@ -83ea9029d9f76938323c513b1225c370
\ No newline at end of file diff --git a/thedarkcolour/kotlinforforge/maven-metadata.xml.sha1 b/thedarkcolour/kotlinforforge/maven-metadata.xml.sha1 deleted file mode 100644 index 4ad1c68..0000000 --- a/thedarkcolour/kotlinforforge/maven-metadata.xml.sha1 +++ /dev/null @@ -1 +0,0 @@ -ef28fb7b7d4521bd8afb84f0505fed08d672fb1d
\ No newline at end of file diff --git a/thedarkcolour/kotlinforforge/web.html b/thedarkcolour/kotlinforforge/web.html index a75d4b9..fa120b1 100644 --- a/thedarkcolour/kotlinforforge/web.html +++ b/thedarkcolour/kotlinforforge/web.html @@ -2,7 +2,7 @@ <head><title>Index of /kotlinforforge/</title></head> <body> <h1>Index of /kotlinforforge/</h1><hr><pre><a href="../web.html">../</a> -<a href="0.1.14/web.html">0.1.14</a> +<a href="1.0.0/web.html">1.0.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> |