diff options
Diffstat (limited to 'src')
-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 } |