diff options
author | thedarkcolour <30441001+thedarkcolour@users.noreply.github.com> | 2020-12-19 09:54:05 -0800 |
---|---|---|
committer | thedarkcolour <30441001+thedarkcolour@users.noreply.github.com> | 2020-12-19 09:54:05 -0800 |
commit | 668b5c35ea900750c35f2ea8d878c1c5e6a04607 (patch) | |
tree | e63f4c0e5e886256a762d409dcc73fc9d5e5321d /src/main | |
parent | 7653b26a950d3313f3f159ab76eec1f186055ac8 (diff) | |
download | KotlinForForge-668b5c35ea900750c35f2ea8d878c1c5e6a04607.tar.gz KotlinForForge-668b5c35ea900750c35f2ea8d878c1c5e6a04607.tar.bz2 KotlinForForge-668b5c35ea900750c35f2ea8d878c1c5e6a04607.zip |
Kotlin for Forge 1.7.0
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/kotlin/thedarkcolour/kotlinforforge/forge/Forge.kt | 9 | ||||
-rw-r--r-- | src/main/kotlin/thedarkcolour/kotlinforforge/forge/KDeferredRegister.kt | 14 |
2 files changed, 21 insertions, 2 deletions
diff --git a/src/main/kotlin/thedarkcolour/kotlinforforge/forge/Forge.kt b/src/main/kotlin/thedarkcolour/kotlinforforge/forge/Forge.kt index 8289456..7cc7616 100644 --- a/src/main/kotlin/thedarkcolour/kotlinforforge/forge/Forge.kt +++ b/src/main/kotlin/thedarkcolour/kotlinforforge/forge/Forge.kt @@ -247,6 +247,9 @@ private class SidedDelegate<T>(private val clientValue: () -> T, private val ser * @since 1.4.0 * [ObjectHolderDelegate] can now be used with the [KDeferredRegister]. * + * @since 1.7.0 + * [ObjectHolderDelegate] now implements () -> T. + * * @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 @@ -255,7 +258,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>>, Supplier<T> { +) : ReadOnlyProperty<Any?, T>, Consumer<Predicate<ResourceLocation>>, Supplier<T>, () -> T { /** * Should be initialized by [accept]. If you don't register * a value for [registryName] during the appropriate registry event @@ -275,6 +278,10 @@ public data class ObjectHolderDelegate<T : IForgeRegistryEntry<in T>>( return value } + override fun invoke(): T { + return value + } + /** * Refreshes the value of this ObjectHolder. * diff --git a/src/main/kotlin/thedarkcolour/kotlinforforge/forge/KDeferredRegister.kt b/src/main/kotlin/thedarkcolour/kotlinforforge/forge/KDeferredRegister.kt index e4f40e9..9e063a2 100644 --- a/src/main/kotlin/thedarkcolour/kotlinforforge/forge/KDeferredRegister.kt +++ b/src/main/kotlin/thedarkcolour/kotlinforforge/forge/KDeferredRegister.kt @@ -47,6 +47,7 @@ public class KDeferredRegister<V : IForgeRegistryEntry<V>>( } } + /** * Adds a registry object to this deferred registry. * @@ -56,7 +57,7 @@ public class KDeferredRegister<V : IForgeRegistryEntry<V>>( * * @return A new [ObjectHolderDelegate] with the given registry name and value */ - public fun <T : V> register(name: String, supplier: () -> T): ReadOnlyProperty<Any?, T> { + public fun <T : V> registerObject(name: String, supplier: () -> T): ObjectHolderDelegate<T> { val key = ResourceLocation(modid, name) val a = ObjectHolderDelegate<T>(key, registry) @@ -65,6 +66,17 @@ public class KDeferredRegister<V : IForgeRegistryEntry<V>>( return a } + /** + * Older function that only returns a property delegate. + */ + @Deprecated( + message = "Use `registerObject` for ObjectHolderDelegate return type", + replaceWith = ReplaceWith("registerObject(name, supplier)") + ) + public fun <T : V> register(name: String, supplier: () -> T): ReadOnlyProperty<Any?, T> { + return registerObject(name, supplier) + } + public fun getEntries(): Set<ObjectHolderDelegate<out V>> { return entries.keys } |