diff options
author | thedarkcolour <30441001+thedarkcolour@users.noreply.github.com> | 2020-08-16 19:27:23 -0700 |
---|---|---|
committer | thedarkcolour <30441001+thedarkcolour@users.noreply.github.com> | 2020-08-16 19:27:23 -0700 |
commit | 3d05249dadaa2f3b2b58d7aecbe5518b09d35d78 (patch) | |
tree | bc60252fe092b2830781281fce2458baf89db718 | |
parent | 1f5749dbd4eff6a5e78307e89c0e9c1a595bcb97 (diff) | |
download | KotlinForForge-3d05249dadaa2f3b2b58d7aecbe5518b09d35d78.tar.gz KotlinForForge-3d05249dadaa2f3b2b58d7aecbe5518b09d35d78.tar.bz2 KotlinForForge-3d05249dadaa2f3b2b58d7aecbe5518b09d35d78.zip |
Update Kotlin for Forge 1.4.0
20 files changed, 206 insertions, 20 deletions
@@ -24,4 +24,3 @@ run # Files from Forge MDK forge*changelog.txt gradle -lib @@ -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' @@ -70,10 +70,6 @@ repositories { 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 <T> 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 <reified T : IForgeRegistryEntry<in T>> objectHolder(registryName: ResourceLocation): ReadOnlyProperty<Any?, T> { 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 <reified T : IForgeRegistryEntry<in T>> objectHolder(namespace: String, registryName: String): ReadOnlyProperty<Any?, T> { + 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 <reified T : IForgeRegistryEntry<in T>> objectHolder(registryName: String): ReadOnlyProperty<Any?, T> { return ObjectHolderDelegate( @@ -222,6 +230,9 @@ private class SidedDelegate<T>(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<T>(private val clientValue: () -> T, private val ser public data class ObjectHolderDelegate<T : IForgeRegistryEntry<in T>>( private val registryName: ResourceLocation, private val registry: IForgeRegistry<*>, -) : ReadOnlyProperty<Any?, T>, Consumer<Predicate<ResourceLocation>> { +) : ReadOnlyProperty<Any?, T>, Consumer<Predicate<ResourceLocation>>, Supplier<T> { /** * 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<T : IForgeRegistryEntry<in T>>( 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<V : IForgeRegistryEntry<V>>( + public val registry: IForgeRegistry<V>, + public val modid: String, +) { + /** + * A map of all registry objects and their value suppliers. + */ + private val entries = HashMap<ObjectHolderDelegate<out V>, () -> V>() + + /** + * Alternative constructor that uses a class instead of a registry. + */ + public constructor(registryClass: Class<V>, 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<V> -> + 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 <T : V> register(name: String, supplier: () -> T): ReadOnlyProperty<Any?, T> { + val key = ResourceLocation(modid, name) + val a = ObjectHolderDelegate<T>(key, registry) + + entries[a] = { supplier().setRegistryName(key) } + + return a + } + + public fun getEntries(): Set<ObjectHolderDelegate<out V>> { + return entries.keys + } + + /** + * Adds all entries in this registry to the corresponding game registries. + */ + private fun addEntries(event: RegistryEvent.Register<V>) { + 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 Binary files differnew file mode 100644 index 0000000..6672a1c --- /dev/null +++ b/thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0-sources.jar 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 Binary files differnew file mode 100644 index 0000000..57824be --- /dev/null +++ b/thedarkcolour/kotlinforforge/1.4.0/kotlinforforge-1.4.0.jar 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 @@ +<?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.4.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.0-rc</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.jetbrains.kotlin</groupId> + <artifactId>kotlin-stdlib-jdk7</artifactId> + <version>1.4.0-rc</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.jetbrains.kotlin</groupId> + <artifactId>kotlin-stdlib-jdk8</artifactId> + <version>1.4.0-rc</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.jetbrains.kotlin</groupId> + <artifactId>kotlin-reflect</artifactId> + <version>1.4.0-rc</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.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 @@ +<html lang="HTML5"> +<link rel="stylesheet" href="../../style.css"> +<head><title>Index of /1.4.0/</title></head> +<body> +<h1>Index of /kotlinforforge/</h1> +<hr> +<pre><a href="../web.html">../</a> +<a href="kotlinforforge-1.4.0-sources.jar">kotlinforforge-1.4.0-sources.jar</a> +<a href="kotlinforforge-1.4.0-sources.jar.sha1">kotlinforforge-1.4.0-sources.jar.sha1</a> +<a href="kotlinforforge-1.4.0-sources.jar.md5">kotlinforforge-1.4.0-sources.jar.md5</a> +<a href="kotlinforforge-1.4.0.jar">kotlinforforge-1.4.0.jar</a> +<a href="kotlinforforge-1.4.0.jar.sha1">kotlinforforge-1.4.0.jar.sha1</a> +<a href="kotlinforforge-1.4.0.jar.md5">kotlinforforge-1.4.0.jar.md5</a> +<a href="kotlinforforge-1.4.0.pom">kotlinforforge-1.4.0.pom</a> +<a href="kotlinforforge-1.4.0.pom.sha1">kotlinforforge-1.4.0.pom.sha1</a> +<a href="kotlinforforge-1.4.0.pom.md5">kotlinforforge-1.4.0.pom.md5</a> +</pre> +<hr> +</body> +</html> 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 @@ <groupId>thedarkcolour</groupId> <artifactId>kotlinforforge</artifactId> <versioning> - <release>1.3.1</release> + <release>1.4.0</release> <versions> <version>1.0.0</version> <version>1.0.1</version> @@ -13,6 +13,7 @@ <version>1.2.2</version> <version>1.3.0</version> <version>1.3.1</version> + <version>1.4.0</version> </versions> </versioning> </metadata> |