Fix some issues regarding datagen

This commit is contained in:
DBotThePony 2023-04-26 16:54:46 +07:00
parent ee2bb3d24e
commit 37a91c525e
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 12 additions and 23 deletions

View File

@ -528,12 +528,11 @@ object DataGen {
event.generator.addProvider(event.includeServer(), matterData)
val registrySetBuilder = RegistrySetBuilder()
val set = registrySetBuilder
.add(Registries.DAMAGE_TYPE, ::registerDamageTypes)
.add(Registries.CONFIGURED_FEATURE, ::registerConfiguredFeatures)
.add(Registries.PLACED_FEATURE, ::registerPlacedFeatures)
event.generator.addProvider(event.includeServer(), DatapackBuiltinEntriesProvider(event.generator.packOutput, event.lookupProvider, set, setOf(MOD_ID)))
event.generator.addProvider(event.includeServer(), DatapackBuiltinEntriesProvider(event.generator.packOutput, event.lookupProvider, registrySetBuilder, setOf(MOD_ID)))
registerDamageTypeTags(tagsProvider.damageTypes)

View File

@ -46,35 +46,29 @@ class TagsProvider(private val event: GatherDataEvent) {
inner class Appender(val tag: TagKey<T>) {
constructor(tag: ResourceLocation) : this(TagKey.create(registryKey, tag))
init {
require(tag.registry == registryKey) { "Trying to create appender for $tag inside registry $registryKey" }
}
private val locations by lazy { tags.computeIfAbsent(tag) { ObjectArraySet() } }
private val rigidLocations by lazy { rigidTags.computeIfAbsent(tag) { ObjectArraySet() } }
private val tagsInTags by lazy { tagInTag.computeIfAbsent(tag) { ObjectArraySet() } }
fun add(value: ResourceLocation): Appender {
if (!locations.add(value)) {
throw IllegalStateException("Tag $tag of registry $registryKey already contains $value")
}
check(locations.add(value)) { "Tag ${tag.location} of registry ${registryKey.location()} already contains $value" }
return this
}
fun add(value: ResourceKey<T>): Appender {
require(value.registry() == registryKey.location()) { "Invalid registry in provided ResourceKey: ${value.registry()} (this tag appender is for $registryKey)" }
if (!rigidLocations.add(value)) {
throw IllegalStateException("Tag $tag of registry ${registryKey.location()} already contains $value")
}
return this
require(value.registry() == registryKey.location()) { "Invalid registry in provided ResourceKey: ${value.registry()} (this tag appender is for ${registryKey.location()})" }
// check(rigidLocations.add(value)) { "Tag ${tag.location} of registry ${registryKey.location()} already contains $value" }
// return this
return add(value.location())
}
fun add(value: TagKey<T>): Appender {
require(value.registry() == registryKey.location()) { "Invalid registry in provided ResourceKey: ${value.registry()} (this tag appender is for $registryKey)" }
if (!tagsInTags.add(value)) {
throw IllegalStateException("Tag $tag of registry ${registryKey.location()} already contains $value")
}
require(value.registry() == registryKey) { "Invalid registry in provided ResourceKey: ${value.registry().location()} (this tag appender is for ${registryKey.location()})" }
check(tagsInTags.add(value)) { "Tag ${tag.location} of registry ${registryKey.location()} already contains $value" }
return this
}
@ -128,10 +122,6 @@ class TagsProvider(private val event: GatherDataEvent) {
fun forge(path: String) = Appender(ResourceLocation("forge", path))
override fun addTags(provider: HolderLookup.Provider) {
if (tags.isEmpty()) {
return
}
for ((tag, values) in tags) {
val appender = tag(tag)