Skip to content

Commit

Permalink
Import architectury into addArchApi conf and remap before adding to m…
Browse files Browse the repository at this point in the history
…odApi conf
  • Loading branch information
mrmelon54 committed Mar 29, 2024
1 parent de5ffa6 commit dd1fc49
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ loom {
configurations {
compile
mappings
addArchApi
}



import net.fabricmc.tinyremapper.NonClassCopyMode
import net.fabricmc.tinyremapper.OutputConsumerPath
import net.fabricmc.tinyremapper.TinyRemapper
Expand All @@ -44,15 +44,14 @@ dependencies {
// We depend on fabric loader here to use the fabric @Environment annotations and get the mixin dependencies
// Do NOT use other classes from fabric loader
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
addArchApi "${rootProject.architectury_group}:architectury:${rootProject.architectury_version}"

modApi("me.shedaniel.cloth:cloth-config-fabric:${rootProject.cloth_config_version}") {
exclude(group: "net.fabricmc.fabric-api")
}
modApi("com.terraformersmc:modmenu:${rootProject.modmenu_version}") {
exclude(group: "net.fabricmc.fabric-api")
}

compileOnlyApi files(remappedArchPath)
}

static void runMappingsOnJar(File input, File output, File mappingsTiny, String fromM, String toM) {
Expand All @@ -75,40 +74,44 @@ static void runMappingsOnJar(File input, File output, File mappingsTiny, String
}
}

gradle.projectsEvaluated {
tasks.register('applyMappings') {
if (new File(remappedArchPath.toUri()).exists()) {
println "Remapped Architectury is already up-to-date"
return
}

var archJarPath = "/${rootProject.architectury_group.replaceAll("\\.", "/")}/architectury/${rootProject.architectury_version}/architectury-${rootProject.architectury_version}.jar"
tasks.register('applyMappings') {
File remappedArchFile = new File(remappedArchPath.toUri())
if (!remappedArchFile.exists()) {
var archJarPath = "/architectury-${rootProject.architectury_version}.jar"
println "Searching for architectury jar: $archJarPath"
File archJar = project.configurations.getByName('compileClasspath').files.find { it.path.endsWith(archJarPath) }

File archJar = configurations.addArchApi.files.find { it.path.endsWith(archJarPath) }
println "Found matching jar: ${archJar.name}"
println "Using mappings: ${mappingsTiny.name}"

runMappingsOnJar(archJar, new File(remappedArchPath.toUri()), mappingsTiny, "official", "named")
runMappingsOnJar(archJar, remappedArchFile, mappingsTiny, "official", "named")

println "Remapping completed successfully."
}
println "Adding remapped Architectury dependency"
dependencies {
modApi files(remappedArchPath)
}
return
}

compileJava.dependsOn applyMappings
compileJava.dependsOn applyMappings

tasks.register('undoApplyMappings') {
doLast {
File mergedJar = new File(rootProject.layout.projectDirectory.asFile, "Merged/${rootProject.forgix_merged_jar}")
File remapFile = new File(mergedJar.parentFile, mergedJar.name + ".remapped.jar")
runMappingsOnJar(mergedJar, remapFile, mappingsTiny, "named", "official")
mergedJar.delete()
Files.copy(remapFile.toPath(), mergedJar.toPath(), StandardCopyOption.REPLACE_EXISTING)
remapFile.delete()
}
tasks.register('undoApplyMappings') {
doLast {
File mergedJar = new File(rootProject.layout.projectDirectory.asFile, "Merged/${rootProject.forgix_merged_jar}")
File remapFile = new File(mergedJar.parentFile, mergedJar.name + ".remapped.jar")
runMappingsOnJar(mergedJar, remapFile, mappingsTiny, "named", "official")
mergedJar.delete()
Files.copy(remapFile.toPath(), mergedJar.toPath(), StandardCopyOption.REPLACE_EXISTING)
remapFile.delete()
}

rootProject.tasks['mergeJars'].finalizedBy undoApplyMappings
}

rootProject.tasks['mergeJars'].finalizedBy undoApplyMappings


publishing {
publications {
mavenCommon(MavenPublication) {
Expand Down

0 comments on commit dd1fc49

Please sign in to comment.