Skip to content

Commit

Permalink
Use JarJar on modern (Neo)Forge
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaming32 committed Mar 24, 2024
1 parent 974b99e commit c39c83d
Showing 1 changed file with 42 additions and 5 deletions.
47 changes: 42 additions & 5 deletions version.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import com.google.gson.stream.JsonWriter
import com.replaymod.gradle.preprocess.PreprocessTask
import groovy.lang.GroovyObjectSupport
import net.raphimc.javadowngrader.gradle.task.DowngradeSourceSetTask
Expand All @@ -17,11 +18,9 @@ plugins {
id("com.modrinth.minotaur") version "2.+"
}


fun Any.setGroovyProperty(name: String, value: Any) = withGroovyBuilder { metaClass }.setProperty(this, name, value)
fun Any.getGroovyProperty(name: String): Any = withGroovyBuilder { metaClass }.getProperty(this, name)!!


val modVersion = project.properties["mod.version"] as String
val mcVersionString by extra(name.substringBefore("-"))
val loaderName by extra(name.substringAfter("-"))
Expand Down Expand Up @@ -179,7 +178,7 @@ repositories {
println("loaderName: $loaderName")
println("mcVersion: $mcVersion")

val shade: Configuration by configurations.creating {
val forgeJarJar: Configuration by configurations.creating {
isTransitive = false
}

Expand All @@ -201,7 +200,7 @@ dependencies {
if (isFabric) {
"include"(dependency)
} else {
"shade"(dependency)
forgeJarJar(dependency)
}
}

Expand Down Expand Up @@ -402,7 +401,45 @@ tasks.processResources {
}

tasks.withType<RemapJarTask> {
shade.files.forEach { from(project.zipTree(it)) }
if (isForgeLike && !forgeJarJar.isEmpty) {
if (mcVersion >= 11800) {
val jarJarMetadata = temporaryDir.resolve("jarjar").resolve("metadata.json")
doFirst {
jarJarMetadata.parentFile.mkdirs()
jarJarMetadata.bufferedWriter().let(::JsonWriter).use { writer ->
writer.setIndent(" ")
writer.beginObject()
writer.name("jars").beginArray()
forgeJarJar.resolvedConfiguration.resolvedArtifacts.forEach { artifact ->
writer.beginObject()
writer.name("identifier").beginObject()
writer.name("group").value(artifact.moduleVersion.id.group)
writer.name("artifact").value(artifact.moduleVersion.id.name)
writer.endObject()
writer.name("version").beginObject()
writer.name("range").value("[${artifact.moduleVersion.id.version},)")
writer.name("artifactVersion").value(artifact.moduleVersion.id.version)
writer.endObject()
writer.name("path").value("META-INF/jarjar/${artifact.file.name}")
writer.name("isObfuscated").value(false)
writer.endObject()
}
writer.endArray()
writer.endObject()
}
}
forgeJarJar.files.forEach { file ->
from(file) {
into("META-INF/jarjar")
}
}
from(jarJarMetadata) {
into("META-INF/jarjar")
}
} else {
forgeJarJar.files.forEach { from(zipTree(it)) }
}
}
manifest {
if (isForge) {
attributes["MixinConfigs"] = "world-host.mixins.json"
Expand Down

0 comments on commit c39c83d

Please sign in to comment.