mirror of
https://github.com/architectury/architectury-plugin.git
synced 2026-03-28 20:27:01 -05:00
Remember to remap mixin shadows
This commit is contained in:
@@ -5,10 +5,16 @@ package me.shedaniel.architect.plugin
|
||||
import me.shedaniel.architect.plugin.utils.GradleSupport
|
||||
import me.shedaniel.architect.plugin.utils.Transform
|
||||
import net.fabricmc.loom.LoomGradleExtension
|
||||
import net.fabricmc.loom.util.LoggerFilter
|
||||
import net.fabricmc.loom.util.MixinRefmapHelper
|
||||
import net.fabricmc.tinyremapper.OutputConsumerPath
|
||||
import net.fabricmc.tinyremapper.TinyRemapper
|
||||
import net.fabricmc.tinyremapper.TinyUtils
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.jvm.tasks.Jar
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
|
||||
open class TransformTask : Jar() {
|
||||
@@ -18,10 +24,56 @@ open class TransformTask : Jar() {
|
||||
@TaskAction
|
||||
fun doTask() {
|
||||
val input: Path = this.input.asFile.get().toPath()
|
||||
val intermediate: Path = input.parent.resolve(input.toFile().nameWithoutExtension + "-intermediate.jar")
|
||||
val output: Path = this.archiveFile.get().asFile.toPath()
|
||||
|
||||
project.logger.lifecycle(":transforming " + input.fileName + " => " + output.fileName)
|
||||
Transform.transform(input, output, transformExpectPlatform())
|
||||
if (addRefmap) {
|
||||
val loomExtension = project.extensions.getByType(LoomGradleExtension::class.java)
|
||||
var remapperBuilder = TinyRemapper.newRemapper()
|
||||
for (mixinMapFile in loomExtension.allMixinMappings) {
|
||||
if (mixinMapFile.exists()) {
|
||||
remapperBuilder = remapperBuilder.withMappings(
|
||||
TinyUtils.createTinyMappingProvider(
|
||||
mixinMapFile.toPath(),
|
||||
"named",
|
||||
"intermediary"
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
val remapper = remapperBuilder.build()
|
||||
|
||||
val classpathFiles: Set<File> = LinkedHashSet(
|
||||
project.configurations.getByName("compileClasspath").files
|
||||
)
|
||||
val classpath = classpathFiles.asSequence().map { obj: File -> obj.toPath() }.filter { p: Path ->
|
||||
input != p && Files.exists(p)
|
||||
}.toList().toTypedArray()
|
||||
|
||||
println("Failed to remap $input to $intermediate")
|
||||
LoggerFilter.replaceSystemOut()
|
||||
try {
|
||||
OutputConsumerPath.Builder(intermediate).build().use { outputConsumer ->
|
||||
outputConsumer.addNonClassFiles(input)
|
||||
remapper.readClassPath(*classpath)
|
||||
remapper.readInputs(input)
|
||||
remapper.apply(outputConsumer)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
remapper.finish()
|
||||
throw RuntimeException("Failed to remap $input to $intermediate", e)
|
||||
}
|
||||
|
||||
remapper.finish()
|
||||
} else {
|
||||
Files.copy(input, intermediate)
|
||||
}
|
||||
|
||||
project.logger.lifecycle(":transforming " + input.fileName + " => " + intermediate.fileName)
|
||||
Transform.transform(intermediate, output, transformExpectPlatform())
|
||||
|
||||
Files.deleteIfExists(intermediate)
|
||||
|
||||
if (addRefmap) {
|
||||
val loomExtension = project.extensions.getByType(LoomGradleExtension::class.java)
|
||||
|
||||
Reference in New Issue
Block a user