Files

93 lines
4.1 KiB
Groovy

jar {
manifest {
attributes 'TweakClass' : 'customskinloader.tweaker.ModSystemTweaker'
attributes 'TweakName' : rootProject.ext.config.name
attributes 'TweakAuthor' : 'xfl03,JLChnToZ'
attributes 'TweakVersion': version
attributes 'TweakOrder' : '-10'
}
exclude 'net/minecraft/client/renderer/RenderType.class'
exclude 'net/minecraft/client/renderer/texture/**'
exclude 'net/minecraft/client/resources/**'
exclude 'net/minecraft/resources/**'
exclude 'Profile.json'
}
import customskinloader.gradle.util.SourceUtil
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import java.security.MessageDigest
SourceUtil.addDependencies project, project(":Common"), project(":Vanilla/Common")
task afterBuildForVanilla {
doLast {
def file0 = file("build/libs/${archivesBaseName}-${version}.jar")
//copyProfileJson
File profile = project.file("build/resources/main/Profile.json")
File target = rootProject.file(String.format("build/libs/%s-CSL-%s.json", config.minecraft_version, shortVersion))
target.parentFile.mkdirs()
def jsonSlurper = new JsonSlurper()
jsonSlurper.parse(profile, "UTF-8").with { p ->
p.libraries.find({ lib ->
lib.name.startsWith "customskinloader:CustomSkinLoader_"
}).downloads.artifact.with { artifact ->
artifact.sha1 = MessageDigest.getInstance "SHA1" with { digest ->
digest.update file0.bytes
new BigInteger(1, digest.digest()).toString 16 padLeft 40, "0"
}
artifact.size = file0.size()
}
this.plugins.withId "net.minecraftforge.gradle.forge", { plugin ->
// Get the version json from manifest.
// https://github.com/MinecraftForge/ForgeGradle/blob/fc67182a61926f0bdb0d12da5fba7f4322f64d86/src/main/java/net/minecraftforge/gradle/common/BasePlugin.java#L229
jsonSlurper.parse(new URL(jsonSlurper.parse(plugin.cacheFile("McManifest.json")).versions.find { version -> version.id == this.project.ext.config.minecraft_version }.url)).with { ver ->
if (ver.minecraftArguments != null) {
p.put "minecraftArguments", "${ver.minecraftArguments} ${p.arguments.game.join(" ")}"
p.remove "arguments"
} else {
p.remove "minecraftArguments"
}
}
}
target.write JsonOutput.prettyPrint(JsonOutput.toJson(p)), "UTF-8"
}
}
}
afterBuild.finalizedBy afterBuildForVanilla
// Make vanilla remap tsrg file via Fabric tsrg file.
task convertFabricMappingToVanilla {
doLast {
[{ Project p -> p.file(p.ext.config.srg_notch_map) }, { Project p -> p.file("mixin.tsrg") }].each { tsrgGetter ->
def lines = [] as List<String>
def mapping = [:] as Map<String, String>
// Read Fabric tsrg file
tsrgGetter(project(":Fabric")).eachLine { line ->
lines.add line
line.split($/\s/$).with { strs -> strs[strs.length - 1] }.with { str -> mapping.put str, str }
}
// Read Fabric intermediary tiny mappings.
// We don't care about descriptions of the member because all of intermediary names are unique.
new URL("https://raw.githubusercontent.com/FabricMC/intermediary/master/mappings/${project.ext.config.minecraft_version}.tiny").eachLine { line ->
line.split($/\s/$).with { strs ->
if (mapping.containsKey(strs[strs.length - 1])) {
mapping.put strs[strs.length - 1], strs[strs.length - 2]
}
}
}
// Write vanilla tsrg file.
tsrgGetter(project).withWriter { writer ->
lines.each { line ->
line.split($/\s/$).with { strs -> strs[strs.length - 1] }.with { str ->
writer.writeLine line.replace(str, mapping.get(str))
}
}
}
}
}
}