From 3d05249dadaa2f3b2b58d7aecbe5518b09d35d78 Mon Sep 17 00:00:00 2001 From: thedarkcolour <30441001+thedarkcolour@users.noreply.github.com> Date: Sun, 16 Aug 2020 19:27:23 -0700 Subject: Update Kotlin for Forge 1.4.0 --- .gitignore | 1 - README.md | 2 +- build.gradle | 8 +- changelog.md | 6 ++ gradle.properties | 3 +- gradle/wrapper/gradle-wrapper.properties | 2 +- .../thedarkcolour/kotlinforforge/forge/Forge.kt | 27 +++++-- .../kotlinforforge/forge/KDeferredRegister.kt | 84 +++++++++++++++++++++ src/main/resources/META-INF/mods.toml | 4 +- .../1.4.0/kotlinforforge-1.4.0-sources.jar | Bin 0 -> 17992 bytes .../1.4.0/kotlinforforge-1.4.0-sources.jar.md5 | 1 + .../1.4.0/kotlinforforge-1.4.0-sources.jar.sha1 | 1 + .../kotlinforforge/1.4.0/kotlinforforge-1.4.0.jar | Bin 0 -> 97443 bytes .../1.4.0/kotlinforforge-1.4.0.jar.md5 | 1 + .../1.4.0/kotlinforforge-1.4.0.jar.sha1 | 1 + .../kotlinforforge/1.4.0/kotlinforforge-1.4.0.pom | 60 +++++++++++++++ .../1.4.0/kotlinforforge-1.4.0.pom.md5 | 1 + .../1.4.0/kotlinforforge-1.4.0.pom.sha1 | 1 + thedarkcolour/kotlinforforge/1.4.0/web.html | 20 +++++ thedarkcolour/kotlinforforge/maven-metadata.xml | 3 +- 20 files changed, 206 insertions(+), 20 deletions(-) create mode 100644 src/main/kotlin/thedarkcolour/kotlinforforge/forge/KDeferredRegister.kt create mode 100644 thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0-sources.jar create mode 100644 thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0-sources.jar.md5 create mode 100644 thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0-sources.jar.sha1 create mode 100644 thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0.jar create mode 100644 thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0.jar.md5 create mode 100644 thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0.jar.sha1 create mode 100644 thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0.pom create mode 100644 thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0.pom.md5 create mode 100644 thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0.pom.sha1 create mode 100644 thedarkcolour/kotlinforforge/1.4.0/web.html diff --git a/.gitignore b/.gitignore index 38d5de4..096ab59 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,3 @@ run # Files from Forge MDK forge*changelog.txt gradle -lib diff --git a/README.md b/README.md index 29e3554..886a612 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ repositories { dependencies { // Use the latest version of KotlinForForge - implementation 'thedarkcolour:kotlinforforge:1.2.3' + implementation 'thedarkcolour:kotlinforforge:1.4.0' } compileKotlin { diff --git a/build.gradle b/build.gradle index af88d50..b789ad0 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.3.1" +version = "1.4.0" group = 'thedarkcolour.kotlinforforge' archivesBaseName = 'kotlinforforge' @@ -69,10 +69,6 @@ repositories { name = 'Yarn Mappings' url = 'https://maven.tterrag.com/' } - maven { - name = 'Kotlin Early Access' - url = 'https://dl.bintray.com/kotlin/kotlin-eap' - } maven { name = 'Dokka' url = 'https://dl.bintray.com/kotlin/dokka' @@ -140,7 +136,5 @@ dokka { configuration { reportUndocumented = true - - samples = ["$rootDir/src/test/kotlin/thedarkcolour/example/ExampleMod.kt".toString()] } } \ No newline at end of file diff --git a/changelog.md b/changelog.md index c44571e..3827933 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,9 @@ +##Kotlin for Forge 1.4.0 +- Kotlin Gradle Plugin now requires Gradle 5.3. Update by changing the version of the gradle wrapper in `gradle/wrapper/gradle-wrapper.properties`. +- Added a `KDeferredRegistry` similar to Forge's `DeferredRegistry` but works with `ObjectHolderDelegate`s instead of `RegistryObject`s. +- Fixed a typo in the KDoc for `MOD_BUS` that falsely stated `AttachCapabilitiesEvent` was fired on the mod-specific event bus. +- Updated to Kotlin 1.4.0-rc + ##Kotlin for Forge 1.3.1 - Bumped version range to work with 1.16 Forge when it comes out. diff --git a/gradle.properties b/gradle.properties index 8ee44fd..9b8074d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,8 @@ # Sets default memory used for gradle commands. Can be overridden by user or command line properties. # This is required to provide enough memory for the Minecraft decompilation process. +kotlin.code.style=official org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false -kotlin_version=1.4-M2 +kotlin_version=1.4.0-rc coroutines_version = 1.3.7 annotations_version = 19.0.0 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index c7a095a..d662651 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ #Sat Oct 19 12:21:43 PDT 2019 -distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.3-all.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStorePath=wrapper/dists diff --git a/src/main/kotlin/thedarkcolour/kotlinforforge/forge/Forge.kt b/src/main/kotlin/thedarkcolour/kotlinforforge/forge/Forge.kt index 37cc207..01f9e90 100644 --- a/src/main/kotlin/thedarkcolour/kotlinforforge/forge/Forge.kt +++ b/src/main/kotlin/thedarkcolour/kotlinforforge/forge/Forge.kt @@ -18,6 +18,7 @@ import thedarkcolour.kotlinforforge.eventbus.KotlinEventBusWrapper import java.util.* import java.util.function.Consumer import java.util.function.Predicate +import java.util.function.Supplier import kotlin.collections.HashMap import kotlin.properties.ReadOnlyProperty import kotlin.reflect.KProperty @@ -49,7 +50,7 @@ public val FORGE_BUS: KotlinEventBusWrapper = KotlinEventBusWrapper(MinecraftFor * * Examples: * @see net.minecraftforge.fml.event.lifecycle.InterModProcessEvent - * @see net.minecraftforge.event.AttachCapabilitiesEvent + * @see net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent * @see net.minecraftforge.event.RegistryEvent */ public val MOD_BUS: KotlinEventBus @@ -158,19 +159,26 @@ public fun sidedDelegate(clientValue: () -> T, serverValue: () -> T): ReadOn /** @since 1.2.2 * Creates a new [ObjectHolderDelegate] with the specified [registryName]. * - * This delegate serves as an alternative to using the - * `@ObjectHolder` annotation, making it easier to use in Kotlin. + * Provides ObjectHolders as property delegates instead of magic annotations. */ public inline fun > objectHolder(registryName: ResourceLocation): ReadOnlyProperty { return ObjectHolderDelegate(registryName, ObjectHolderDelegate.getRegistry(T::class.java)) } +/** @since 1.2.2 + * Creates a new with the specified [namespace] and [registryName]. + * + * Provides ObjectHolders as property delegates instead of magic annotations. + */ +public inline fun > objectHolder(namespace: String, registryName: String): ReadOnlyProperty { + return ObjectHolderDelegate(ResourceLocation(namespace, registryName), ObjectHolderDelegate.getRegistry(T::class.java)) +} + /** @since 1.2.2 * Creates a new [ObjectHolderDelegate]. * This overload uses a string instead of a ResourceLocation. * - * This delegate serves as an alternative to using the - * `@ObjectHolder` annotation, making it easier to use in Kotlin. + * Provides ObjectHolders as property delegates instead of magic annotations. */ public inline fun > objectHolder(registryName: String): ReadOnlyProperty { return ObjectHolderDelegate( @@ -222,6 +230,9 @@ private class SidedDelegate(private val clientValue: () -> T, private val ser * This class has proper implementations of * [copy], [hashCode], [equals], and [toString]. * + * @since 1.4.0 + * [ObjectHolderDelegate] can now be used with the [KDeferredRegister]. + * * @param T the type of object this delegates to * @property registryName the registry name of the object this delegate references * @property registry the registry the object of this delegate is in @@ -230,7 +241,7 @@ private class SidedDelegate(private val clientValue: () -> T, private val ser public data class ObjectHolderDelegate>( private val registryName: ResourceLocation, private val registry: IForgeRegistry<*>, -) : ReadOnlyProperty, Consumer> { +) : ReadOnlyProperty, Consumer>, Supplier { /** * Should be initialized by [accept]. If you don't register * a value for [registryName] during the appropriate registry event @@ -242,6 +253,10 @@ public data class ObjectHolderDelegate>( ObjectHolderRegistry.addHandler(this) } + override fun get(): T { + return value + } + override fun getValue(thisRef: Any?, property: KProperty<*>): T { return value } diff --git a/src/main/kotlin/thedarkcolour/kotlinforforge/forge/KDeferredRegister.kt b/src/main/kotlin/thedarkcolour/kotlinforforge/forge/KDeferredRegister.kt new file mode 100644 index 0000000..f556d0f --- /dev/null +++ b/src/main/kotlin/thedarkcolour/kotlinforforge/forge/KDeferredRegister.kt @@ -0,0 +1,84 @@ +package thedarkcolour.kotlinforforge.forge + +import net.minecraft.util.ResourceLocation +import net.minecraftforge.event.RegistryEvent +import net.minecraftforge.eventbus.api.IEventBus +import net.minecraftforge.fml.RegistryObject +import net.minecraftforge.registries.DeferredRegister +import net.minecraftforge.registries.IForgeRegistry +import net.minecraftforge.registries.IForgeRegistryEntry +import net.minecraftforge.registries.RegistryManager +import thedarkcolour.kotlinforforge.eventbus.KotlinEventBus +import kotlin.properties.ReadOnlyProperty + +/** + * Alternative version of [DeferredRegister] that creates + * [ObjectHolderDelegate] instances instead of [RegistryObject]. + */ +public class KDeferredRegister>( + public val registry: IForgeRegistry, + public val modid: String, +) { + /** + * A map of all registry objects and their value suppliers. + */ + private val entries = HashMap, () -> V>() + + /** + * Alternative constructor that uses a class instead of a registry. + */ + public constructor(registryClass: Class, modid: String) : this(RegistryManager.ACTIVE.getRegistry(registryClass), modid) + + /** + * Registers this deferred register to the `KotlinEventBus`. + */ + public fun register(bus: KotlinEventBus) { + bus.addGenericListener(registry.registrySuperType, ::addEntries) + } + + /** + * Registers this deferred register to the `IEventBus`. + */ + @Deprecated("Use a KotlinEventBus. Forge's EventBus does not support function references for event listeners.") + public fun register(bus: IEventBus) { + // function references are not supported by Forge's eventbus + bus.addGenericListener(registry.registrySuperType) { event: RegistryEvent.Register -> + addEntries(event) + } + } + + /** + * Adds a registry object to this deferred registry. + * + * @param name the path of the new registry object's registry name with namespace [modid] + * @param supplier the function to initialize the value of the new registry object with and + * to reset the value when forge adds reloadable registries. + * + * @return A new [ObjectHolderDelegate] with the given registry name and value + */ + public fun register(name: String, supplier: () -> T): ReadOnlyProperty { + val key = ResourceLocation(modid, name) + val a = ObjectHolderDelegate(key, registry) + + entries[a] = { supplier().setRegistryName(key) } + + return a + } + + public fun getEntries(): Set> { + return entries.keys + } + + /** + * Adds all entries in this registry to the corresponding game registries. + */ + private fun addEntries(event: RegistryEvent.Register) { + val registry = event.registry + + for ((objectHolder, supplier) in entries) { + registry.register(supplier()) + // pass true to always update the entry + objectHolder.accept { true } + } + } +} \ No newline at end of file diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 6de045b..47e863b 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -1,5 +1,5 @@ modLoader="kotlinforforge" # IModLanguageProvider -loaderVersion="[1.3,)" # IModLanguageProvider version +loaderVersion="[1.4,)" # IModLanguageProvider version issueTrackerURL="https://github.com/thedarkcolour/KotlinForForge/issues" # Issues page @@ -31,6 +31,6 @@ Kotlin for Forge. Allows mods to use the Kotlin programming language. [[mods]] #mandatory displayName="Kotlin for Forge" # Name of mod modId="kotlinforforge" # Modid -version="1.3.1" # Version of kotlinforforge +version="1.4.0" # Version of kotlinforforge authors="TheDarkColour" # Author credits="Herobrine knows all." # Credits \ No newline at end of file diff --git a/thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0-sources.jar b/thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0-sources.jar new file mode 100644 index 0000000..6672a1c Binary files /dev/null and b/thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0-sources.jar differ diff --git a/thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0-sources.jar.md5 b/thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0-sources.jar.md5 new file mode 100644 index 0000000..b930d81 --- /dev/null +++ b/thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0-sources.jar.md5 @@ -0,0 +1 @@ +68cdfaa0ece056da7ce802127cc42619 \ No newline at end of file diff --git a/thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0-sources.jar.sha1 b/thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0-sources.jar.sha1 new file mode 100644 index 0000000..41a58f8 --- /dev/null +++ b/thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0-sources.jar.sha1 @@ -0,0 +1 @@ +a42a29eadc06ad37bf4ad406ee159cf1d19fb37d \ No newline at end of file diff --git a/thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0.jar b/thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0.jar new file mode 100644 index 0000000..57824be Binary files /dev/null and b/thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0.jar differ diff --git a/thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0.jar.md5 b/thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0.jar.md5 new file mode 100644 index 0000000..3b560f4 --- /dev/null +++ b/thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0.jar.md5 @@ -0,0 +1 @@ +391fbc8ab89f83e543e3db36b8524fa7 \ No newline at end of file diff --git a/thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0.jar.sha1 b/thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0.jar.sha1 new file mode 100644 index 0000000..468c193 --- /dev/null +++ b/thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0.jar.sha1 @@ -0,0 +1 @@ +fb9879c25a4e195d292557ca15c5320b06b848b4 \ No newline at end of file diff --git a/thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0.pom b/thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0.pom new file mode 100644 index 0000000..ad226df --- /dev/null +++ b/thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0.pom @@ -0,0 +1,60 @@ + + + 4.0.0 + thedarkcolour + kotlinforforge + 1.4.0 + + + kt-eap + Kotlin Early Access + https://dl.bintray.com/kotlin/kotlin-eap + + + + + org.jetbrains.kotlin + kotlin-stdlib + 1.4.0-rc + compile + + + org.jetbrains.kotlin + kotlin-stdlib-jdk7 + 1.4.0-rc + compile + + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + 1.4.0-rc + compile + + + org.jetbrains.kotlin + kotlin-reflect + 1.4.0-rc + 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.4.0/kotlinforforge-1.4.0.pom.md5 b/thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0.pom.md5 new file mode 100644 index 0000000..75bc6a4 --- /dev/null +++ b/thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0.pom.md5 @@ -0,0 +1 @@ +0c93001a8e0fc1b0581f168e3e481df2 \ No newline at end of file diff --git a/thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0.pom.sha1 b/thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0.pom.sha1 new file mode 100644 index 0000000..b5a7c34 --- /dev/null +++ b/thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0.pom.sha1 @@ -0,0 +1 @@ +dd94be86370e56223dc59a4f4db1ba2afd48d04f \ No newline at end of file diff --git a/thedarkcolour/kotlinforforge/1.4.0/web.html b/thedarkcolour/kotlinforforge/1.4.0/web.html new file mode 100644 index 0000000..809ed85 --- /dev/null +++ b/thedarkcolour/kotlinforforge/1.4.0/web.html @@ -0,0 +1,20 @@ + + +Index of /1.4.0/ + +

Index of /kotlinforforge/

+
+
../
+kotlinforforge-1.4.0-sources.jar
+kotlinforforge-1.4.0-sources.jar.sha1
+kotlinforforge-1.4.0-sources.jar.md5
+kotlinforforge-1.4.0.jar
+kotlinforforge-1.4.0.jar.sha1
+kotlinforforge-1.4.0.jar.md5
+kotlinforforge-1.4.0.pom
+kotlinforforge-1.4.0.pom.sha1
+kotlinforforge-1.4.0.pom.md5
+
+
+ + diff --git a/thedarkcolour/kotlinforforge/maven-metadata.xml b/thedarkcolour/kotlinforforge/maven-metadata.xml index fd4e68f..6745bc5 100644 --- a/thedarkcolour/kotlinforforge/maven-metadata.xml +++ b/thedarkcolour/kotlinforforge/maven-metadata.xml @@ -3,7 +3,7 @@ thedarkcolour kotlinforforge - 1.3.1 + 1.4.0 1.0.0 1.0.1 @@ -13,6 +13,7 @@ 1.2.2 1.3.0 1.3.1 + 1.4.0 -- cgit