add mapping layering

This commit is contained in:
moehreag 2024-07-02 00:06:16 +02:00
parent 6896a02d2c
commit 3883c9cafd
4 changed files with 114 additions and 11 deletions

View file

@ -12,5 +12,4 @@ object Constants {
const val GEN_RUN_CONFIGS_TASK = "genRunConfigs"
const val RUN_CLIENT_TASK = "runClient"
const val RUNT_SERVER_TASK = "runServer"
const val DEV_NAMESPACE = "named"
}

View file

@ -1,7 +1,9 @@
package dev.frogmc.phytotelma.ext
import dev.frogmc.phytotelma.PhytotelmaPlugin
import dev.frogmc.phytotelma.mappings.filterClasses
import dev.frogmc.phytotelma.mappings.renameDstNamespace
import dev.frogmc.phytotelma.mappings.renameNamespaces
import dev.frogmc.thyroxine.api.data.MappingBundle
import dev.frogmc.thyroxine.parser.tiny.TinyV2Parser
import dev.frogmc.thyroxine.provider.MojmapProvider
@ -57,6 +59,27 @@ abstract class MinecraftConfiguration @Inject constructor(
}
}
fun parchment(action: Action<ParchmentConfiguration>): Provider<MappingBundle> {
return project.provider {
val conf = objects.newInstance(ParchmentConfiguration::class.java)
conf.gameVersion = version
action.execute(conf)
val cacheDir = PhytotelmaPlugin.globalCacheDir
if (conf.version == null) {
conf.version = ParchmentProvider.findForMinecraftVersion(conf.gameVersion)
}
mappingsName = "parchment(${conf.gameVersion}, ${conf.version})"
targetNamespace = "parchment"
return@provider ParchmentProvider.getParchment(
version,
cacheDir.resolve("org/parchmentmc/parchment/${conf.gameVersion}/${conf.version}")
).renameNamespaces("mojmap", "parchment")
}
}
fun mojmap(): Provider<MappingBundle> {
return project.provider {
val cacheDir = PhytotelmaPlugin.globalCacheDir
@ -76,13 +99,32 @@ abstract class MinecraftConfiguration @Inject constructor(
if (conf.version == null) {
error("No version provided for quilt mappings!")
}
mappingsName = "quilt(${conf.version})"
targetNamespace = "quilt"
mappingsName = "quilt-mappings(${conf.version})"
targetNamespace = "quilt-mappings"
// Use qm via intermediary because hashed publications are broken
return@provider twoStepMappings(
"net.fabricmc:intermediary:$version:v2",
"org.quiltmc:quilt-mappings:${conf.version}:intermediary-v2"
).renameDstNamespace(targetNamespace)
).filterClasses { !it.startsWith("net/minecraft/unmapped") }
.flatten(true).renameDstNamespace(targetNamespace)
}
}
fun yarn(action: Action<VersionConfiguration>): Provider<MappingBundle> {
return project.provider {
val conf = objects.newInstance(VersionConfiguration::class.java)
action.execute(conf)
if (conf.version == null) {
error("No version provided for yarn!")
}
mappingsName = "yarn(${conf.version})"
targetNamespace = "yarn"
// Use qm via intermediary because hashed publications are broken
return@provider twoStepMappings(
"net.fabricmc:intermediary:$version:v2",
"net.fabricmc:yarn:${conf.version}:v2"
).filterClasses { !it.startsWith("net/minecraft/class_") }
.flatten(true).renameDstNamespace(targetNamespace)
}
}
@ -127,6 +169,41 @@ abstract class MinecraftConfiguration @Inject constructor(
}
}
fun layer(action: Action<LayerConfiguration>): Provider<MappingBundle> {
return project.provider {
val conf = objects.newInstance(LayerConfiguration::class.java)
action.execute(conf)
var back = MappingBundle()
var name = "layer["
val layers = conf.layers.mapIndexed {index, provider ->
val bundle = provider.get().flatten(true)
if (index == 0) {
name+=mappingsName
back.insert(bundle)
return@mapIndexed bundle
}
name+=", $mappingsName"
back = back.flatten(false)
val prevDst = back.data[0].dstNamespace
val dst = bundle.data[0].dstNamespace
val remapped = MappingBundle.merge(bundle.reverse(), back)
.flatten(prevDst, dst)
.insert(back.docsForNamespace(dst))
back.insert(remapped)
return@mapIndexed remapped
}
mappingsName = "$name]"
val result = MappingBundle.merge(*layers.toTypedArray())
.flatten("official", layers.last().dstNamespaces()[0])
targetNamespace = result.data[0].dstNamespace
return@provider result
}
}
private fun twoStepMappings(intermediary: String, mappings: String): MappingBundle {
return MappingBundle.merge(tinyMappings(intermediary), tinyMappings(mappings))
}
@ -163,7 +240,7 @@ abstract class MinecraftConfiguration @Inject constructor(
}
abstract class LayerConfiguration {
internal val layers = mutableListOf<Provider<MappingBundle>>()
/*internal*/ val layers = mutableListOf<Provider<MappingBundle>>()
fun add(mappings: Provider<MappingBundle>): LayerConfiguration {
layers.add(mappings)
return this

View file

@ -62,7 +62,7 @@ abstract class PhytotelmaGradleExtensionImpl @Inject constructor(
println("Preparing Parchment...")
val javadocs = ProjectStorage.get(project).mappings!!
options[IFabricJavadocProvider.PROPERTY_NAME] =
FrogJavadocProvider(javadocs.docsForNamespace(Constants.DEV_NAMESPACE))
FrogJavadocProvider(javadocs.get(ProjectStorage.get(project).targetNamespace))
println("Decompiling...")
val logger = PrintStreamLogger(PrintStream(System.out))

View file

@ -4,10 +4,9 @@ import dev.frogmc.thyroxine.api.data.DocumentationData
import dev.frogmc.thyroxine.api.data.MappingBundle
import dev.frogmc.thyroxine.api.data.MappingData
fun MappingBundle.renameDstNamespace(newDst: String): MappingBundle {
val renamed = MappingBundle()
val oldData = flattenData()
val newData = MappingData(oldData.srcNamespace, newDst)
fun MappingBundle.renameNamespaces(newSrc: String?, newDst: String): MappingBundle {
val oldData = if (srcNamespaces().size > 1 || dstNamespaces().size > 1) flattenData() else data[0]
val newData = MappingData(newSrc ?: oldData.srcNamespace, newDst)
val newDocs = DocumentationData(newDst)
oldData.apply {
@ -17,5 +16,33 @@ fun MappingBundle.renameDstNamespace(newDst: String): MappingBundle {
newData.parameters.putAll(parameters)
}
return renamed.insert(newData, newDocs.insert(get(oldData.dstNamespace)))
return MappingBundle(newData, get(oldData.dstNamespace)?.let { newDocs.insert(it) })
}
fun MappingBundle.renameDstNamespace(newDst: String): MappingBundle {
return renameNamespaces(null, newDst)
}
fun MappingBundle.filterClasses(filter: (String) -> Boolean): MappingBundle {
val oldData = data.last()
val newData = MappingData(oldData.srcNamespace, oldData.dstNamespace)
val oldDocs = if (documentation.isNotEmpty()) documentation.last() else null
oldData.apply {
newData.classes.putAll(classes.filter { filter.invoke(it.value) })
newData.fields.putAll(fields.filter { newData.classes.containsKey(it.key.owner) })
newData.methods.putAll(methods.filter { newData.classes.containsKey(it.key.owner) })
newData.parameters.putAll(parameters.filter { newData.classes.containsKey(it.key.owner) })
}
val bundle = MappingBundle(data.subList(0, data.size-1).plus(newData), mutableListOf())
if (oldDocs != null) {
val newDocs = DocumentationData(newData.dstNamespace)
newDocs.classes.addAll(oldDocs.classes.filter { filter.invoke(it.name) })
bundle.insert(newDocs)
}
return bundle
}