Reference forge registries directly, when possible
This commit is contained in:
parent
3c0f74bc03
commit
90dd782bcf
@ -16,6 +16,7 @@ import net.minecraft.world.item.Tiers
|
||||
import net.minecraft.world.level.block.Block
|
||||
import net.minecraftforge.data.event.GatherDataEvent
|
||||
import net.minecraftforge.registries.ForgeRegistries
|
||||
import net.minecraftforge.registries.IForgeRegistry
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability
|
||||
import ru.dbotthepony.mc.otm.datagen.DataGen
|
||||
import java.util.stream.Stream
|
||||
@ -60,10 +61,18 @@ interface ForgeTagAppender<T> : MTagAppender<T> {
|
||||
}
|
||||
}
|
||||
|
||||
private fun <T> vanillaLookup(key: ResourceKey<Registry<T>>): (T) -> ResourceLocation? {
|
||||
val registry by lazy { (BuiltInRegistries.REGISTRY.get(key.location()) ?: throw NoSuchElementException("No such registry $key")) as Registry<T> }
|
||||
return { registry.getKey(it) }
|
||||
}
|
||||
|
||||
class TagsProvider(
|
||||
private val event: GatherDataEvent
|
||||
) {
|
||||
inner class Delegate<T>(registry: ResourceKey<Registry<T>>) : MinecraftTagsProvider<T>(event.generator.packOutput, registry, event.lookupProvider, DataGen.MOD_ID, event.existingFileHelper) {
|
||||
inner class Delegate<T> private constructor(key: ResourceKey<Registry<T>>, val lookup: (T) -> ResourceLocation?) : MinecraftTagsProvider<T>(event.generator.packOutput, key, event.lookupProvider, DataGen.MOD_ID, event.existingFileHelper) {
|
||||
constructor(registry: IForgeRegistry<T>) : this(registry.registryKey, registry::getKey)
|
||||
constructor(key: ResourceKey<Registry<T>>) : this(key, vanillaLookup(key))
|
||||
|
||||
init {
|
||||
event.generator.addProvider(true, this)
|
||||
}
|
||||
@ -75,12 +84,10 @@ class TagsProvider(
|
||||
return
|
||||
}
|
||||
|
||||
val registry = (BuiltInRegistries.REGISTRY.get(registryKey.location()) ?: throw NoSuchElementException("No such registry $registryKey")) as Registry<T>
|
||||
|
||||
for ((tag, values) in tags) {
|
||||
tag(tag).also {
|
||||
for (value in values) {
|
||||
it.add(ResourceKey.create(registryKey, registry.getKey(value) ?: throw NoSuchElementException("$value is missing from $registry")))
|
||||
it.add(ResourceKey.create(registryKey, lookup(value) ?: throw NoSuchElementException("$value is missing from $registryKey")))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -176,9 +183,9 @@ class TagsProvider(
|
||||
}
|
||||
}
|
||||
|
||||
val blocks = Delegate(Registries.BLOCK)
|
||||
val items = Delegate(Registries.ITEM)
|
||||
val mobEffects = Delegate(Registries.MOB_EFFECT)
|
||||
val blocks = Delegate(ForgeRegistries.BLOCKS)
|
||||
val items = Delegate(ForgeRegistries.ITEMS)
|
||||
val mobEffects = Delegate(ForgeRegistries.MOB_EFFECTS)
|
||||
|
||||
val androidImmuneEffects = mobEffects.appender(MatteryPlayerCapability.ANDROID_IMMUNE_EFFECTS)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user