One more data provider

This commit is contained in:
DBotThePony 2023-01-07 16:12:41 +07:00
parent 7e6381ad74
commit be2dcc6bae
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -3,6 +3,7 @@ package ru.dbotthepony.mc.otm.matter
import net.minecraft.data.CachedOutput
import net.minecraft.data.DataGenerator
import net.minecraft.data.DataProvider
import net.minecraft.data.PackOutput
import net.minecraft.resources.ResourceLocation
import net.minecraft.tags.TagKey
import net.minecraft.world.item.Item
@ -11,13 +12,13 @@ import net.minecraftforge.data.event.GatherDataEvent
import ru.dbotthepony.mc.otm.core.Decimal
import ru.dbotthepony.mc.otm.core.registryName
import java.util.Collections
import java.util.concurrent.CompletableFuture
import java.util.function.Consumer
@Suppress("FunctionName", "unused")
open class MatterDataProvider(protected val dataGenerator: DataGenerator, val namespace: String?) : DataProvider {
open class MatterDataProvider(protected val dataGenerator: DataGenerator, val modid: String) : DataProvider {
constructor(event: GatherDataEvent) : this(event.generator, event.modContainer.namespace)
protected val pathProvider: DataGenerator.PathProvider = dataGenerator.createPathProvider(DataGenerator.Target.DATA_PACK, MatterManager.MATTER_DIRECTORY)
protected val actions = LinkedHashMap<ResourceLocation, AbstractRegistryAction>()
sealed class Configuration(val name: ResourceLocation) {
@ -911,14 +912,10 @@ open class MatterDataProvider(protected val dataGenerator: DataGenerator, val na
}
protected fun updateLocation(input: ResourceLocation, prefix: String): ResourceLocation {
if (namespace != null) {
if (input.namespace == namespace) {
if (input.namespace == modid) {
return ResourceLocation(input.namespace, prefix + input.path)
} else {
return ResourceLocation(namespace, prefix + input.namespace + "/" + input.path)
}
} else {
return ResourceLocation(input.namespace, prefix + input.path)
return ResourceLocation(modid, prefix + input.namespace + "/" + input.path)
}
}
@ -1204,13 +1201,18 @@ open class MatterDataProvider(protected val dataGenerator: DataGenerator, val na
protected val added = ArrayList<AbstractRegistryAction>()
val addedView: List<AbstractRegistryAction> = Collections.unmodifiableList(added)
final override fun run(output: CachedOutput) {
final override fun run(output: CachedOutput): CompletableFuture<*> {
addActions()
val promises = ArrayList<CompletableFuture<*>>()
val path = dataGenerator.packOutput.getOutputFolder(PackOutput.Target.DATA_PACK).resolve(modid).resolve(MatterManager.MATTER_DIRECTORY)
for ((key, value) in actions) {
DataProvider.saveStable(output, value.toJson(), pathProvider.json(key))
promises.add(DataProvider.saveStable(output, value.toJson(), path.resolve("$key.json")))
added.add(value)
}
return CompletableFuture.allOf(*promises.toTypedArray())
}
override fun getName(): String {