Open RegistryDelegate to public
This commit is contained in:
parent
0202683e77
commit
f01b354cd8
@ -3,8 +3,6 @@ package ru.dbotthepony.mc.otm.registry
|
||||
import net.minecraft.advancements.CriteriaTriggers
|
||||
import net.minecraft.client.renderer.item.ItemProperties
|
||||
import net.minecraft.core.BlockPos
|
||||
import net.minecraft.core.Registry
|
||||
import net.minecraft.resources.ResourceKey
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.world.damagesource.DamageSource
|
||||
import net.minecraft.world.entity.EntityType
|
||||
@ -17,10 +15,7 @@ import net.minecraft.world.level.material.MaterialColor
|
||||
import net.minecraftforge.eventbus.api.IEventBus
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent
|
||||
import net.minecraftforge.registries.ForgeRegistry
|
||||
import net.minecraftforge.registries.IForgeRegistry
|
||||
import net.minecraftforge.registries.NewRegistryEvent
|
||||
import net.minecraftforge.registries.RegistryBuilder
|
||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters
|
||||
import ru.dbotthepony.mc.otm.android.AndroidFeatureType
|
||||
import ru.dbotthepony.mc.otm.android.feature.EnderTeleporterFeature
|
||||
@ -51,37 +46,6 @@ import ru.dbotthepony.mc.otm.triggers.NanobotsArmorTrigger
|
||||
import ru.dbotthepony.mc.otm.triggers.PhantomSpawnDeniedTrigger
|
||||
import ru.dbotthepony.mc.otm.triggers.ShockwaveDamageMobTrigger
|
||||
import ru.dbotthepony.mc.otm.triggers.ShockwaveTrigger
|
||||
import java.util.function.Supplier
|
||||
import kotlin.properties.ReadOnlyProperty
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
private class RegistryDelegate<T>(key: String) : ReadOnlyProperty<Any, ForgeRegistry<T>> {
|
||||
private var value: Supplier<IForgeRegistry<T>?>? = null
|
||||
|
||||
val location = ResourceLocation(OverdriveThatMatters.MOD_ID, key)
|
||||
val key: ResourceKey<Registry<T>> = ResourceKey.createRegistryKey(location)
|
||||
|
||||
fun get(): ForgeRegistry<T> {
|
||||
val supp = value ?: throw IllegalStateException("Tried to access uninitialized registry $location")
|
||||
return supp.get() as ForgeRegistry<T>? ?: throw IllegalStateException("Accessing registry $location too early")
|
||||
}
|
||||
|
||||
override fun getValue(thisRef: Any, property: KProperty<*>): ForgeRegistry<T> {
|
||||
return get()
|
||||
}
|
||||
|
||||
fun build(event: NewRegistryEvent) {
|
||||
if (value != null) {
|
||||
throw IllegalStateException("Already built registry $location!")
|
||||
}
|
||||
|
||||
value = RegistryBuilder<T>().let {
|
||||
it.setName(location)
|
||||
// it.type = AndroidFeatureType::class.java
|
||||
event.create(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object MRegistry {
|
||||
private val features = RegistryDelegate<AndroidFeatureType<*>>("android_features")
|
||||
|
@ -0,0 +1,41 @@
|
||||
package ru.dbotthepony.mc.otm.registry
|
||||
|
||||
import net.minecraft.core.Registry
|
||||
import net.minecraft.resources.ResourceKey
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraftforge.registries.ForgeRegistry
|
||||
import net.minecraftforge.registries.IForgeRegistry
|
||||
import net.minecraftforge.registries.NewRegistryEvent
|
||||
import net.minecraftforge.registries.RegistryBuilder
|
||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters
|
||||
import java.util.function.Supplier
|
||||
import kotlin.properties.ReadOnlyProperty
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
class RegistryDelegate<T>(key: String) : ReadOnlyProperty<Any, ForgeRegistry<T>> {
|
||||
private var value: Supplier<IForgeRegistry<T>?>? = null
|
||||
|
||||
val location = ResourceLocation(OverdriveThatMatters.MOD_ID, key)
|
||||
val key: ResourceKey<Registry<T>> = ResourceKey.createRegistryKey(location)
|
||||
|
||||
fun get(): ForgeRegistry<T> {
|
||||
val supp = value ?: throw IllegalStateException("Tried to access uninitialized registry $location")
|
||||
return supp.get() as ForgeRegistry<T>? ?: throw IllegalStateException("Accessing registry $location too early")
|
||||
}
|
||||
|
||||
override fun getValue(thisRef: Any, property: KProperty<*>): ForgeRegistry<T> {
|
||||
return get()
|
||||
}
|
||||
|
||||
fun build(event: NewRegistryEvent) {
|
||||
if (value != null) {
|
||||
throw IllegalStateException("Already built registry $location!")
|
||||
}
|
||||
|
||||
value = RegistryBuilder<T>().let {
|
||||
it.setName(location)
|
||||
// it.type = AndroidFeatureType::class.java
|
||||
event.create(it)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user