Make RegistryDelegate implement Supplier

This commit is contained in:
DBotThePony 2022-11-03 21:38:50 +07:00
parent f01b354cd8
commit 026a670dec
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -12,13 +12,13 @@ import java.util.function.Supplier
import kotlin.properties.ReadOnlyProperty import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty import kotlin.reflect.KProperty
class RegistryDelegate<T>(key: String) : ReadOnlyProperty<Any, ForgeRegistry<T>> { class RegistryDelegate<T>(key: String) : ReadOnlyProperty<Any, ForgeRegistry<T>>, Supplier<ForgeRegistry<T>> {
private var value: Supplier<IForgeRegistry<T>?>? = null private var value: Supplier<IForgeRegistry<T>?>? = null
val location = ResourceLocation(OverdriveThatMatters.MOD_ID, key) val location = ResourceLocation(OverdriveThatMatters.MOD_ID, key)
val key: ResourceKey<Registry<T>> = ResourceKey.createRegistryKey(location) val key: ResourceKey<Registry<T>> = ResourceKey.createRegistryKey(location)
fun get(): ForgeRegistry<T> { override fun get(): ForgeRegistry<T> {
val supp = value ?: throw IllegalStateException("Tried to access uninitialized registry $location") val supp = value ?: throw IllegalStateException("Tried to access uninitialized registry $location")
return supp.get() as ForgeRegistry<T>? ?: throw IllegalStateException("Accessing registry $location too early") return supp.get() as ForgeRegistry<T>? ?: throw IllegalStateException("Accessing registry $location too early")
} }