Make RegistryDelegate implement Supplier
This commit is contained in:
parent
f01b354cd8
commit
026a670dec
@ -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")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user