diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/RegistryDelegate.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/RegistryDelegate.kt index 1451ff26e..a20ea7def 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/RegistryDelegate.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/RegistryDelegate.kt @@ -12,14 +12,21 @@ import java.util.function.Supplier import kotlin.properties.ReadOnlyProperty import kotlin.reflect.KProperty -class RegistryDelegate(key: String) : ReadOnlyProperty>, Supplier> { - private var value: Supplier?>? = null +class RegistryDelegate(key: String) : ReadOnlyProperty>, Supplier>, Lazy> { + private var _value: Supplier?>? = null + + override val value: ForgeRegistry + get() = get() + + override fun isInitialized(): Boolean { + return _value != null + } val location = ResourceLocation(OverdriveThatMatters.MOD_ID, key) val key: ResourceKey> = ResourceKey.createRegistryKey(location) override fun get(): ForgeRegistry { - 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? ?: throw IllegalStateException("Accessing registry $location too early") } @@ -28,11 +35,11 @@ class RegistryDelegate(key: String) : ReadOnlyProperty> } fun build(event: NewRegistryEvent) { - if (value != null) { + if (_value != null) { throw IllegalStateException("Already built registry $location!") } - value = RegistryBuilder().let { + _value = RegistryBuilder().let { it.setName(location) // it.type = AndroidFeatureType::class.java event.create(it)