205 lines
6.7 KiB
Kotlin
205 lines
6.7 KiB
Kotlin
import java.time.OffsetDateTime
|
|
|
|
val mcVersion = stonecutter.current.version
|
|
val loader = stonecutter.branch.id
|
|
|
|
stonecutter.constants {
|
|
put("forge", loader == "forge")
|
|
put("neoforge", loader == "neoforge")
|
|
put("fabric", loader == "fabric")
|
|
}
|
|
|
|
val modId = project.property("mod_id").toString()
|
|
val modVersion = project.property("mod_version").toString()
|
|
val modGroup = project.property("mod_group_id").toString()
|
|
val modName = project.property("mod_name").toString()
|
|
val modLicense = project.property("mod_license").toString()
|
|
val modAuthors = project.property("mod_authors").toString()
|
|
val modDescription = project.property("mod_description").toString()
|
|
|
|
version = modVersion
|
|
group = modGroup
|
|
|
|
base {
|
|
archivesName = modId
|
|
}
|
|
|
|
sourceSets.main {
|
|
java.srcDir("src/client/java")
|
|
}
|
|
|
|
java {
|
|
withSourcesJar()
|
|
val javaVersion = when {
|
|
mcVersion.startsWith("1.21") || mcVersion == "1.20.6" -> 21
|
|
mcVersion.startsWith("1.20") -> 17
|
|
else -> 25
|
|
}
|
|
toolchain {
|
|
languageVersion = JavaLanguageVersion.of(javaVersion)
|
|
}
|
|
}
|
|
|
|
tasks.withType<JavaCompile>().configureEach {
|
|
options.encoding = "UTF-8"
|
|
val javaRelease = when {
|
|
mcVersion.startsWith("1.21") || mcVersion == "1.20.6" -> 21
|
|
mcVersion.startsWith("1.20") -> 17
|
|
else -> 25
|
|
}
|
|
options.release.set(javaRelease)
|
|
}
|
|
|
|
tasks.withType<Javadoc>().configureEach {
|
|
(options as? StandardJavadocDocletOptions)?.addStringOption("Xdoclint:none", "-quiet")
|
|
}
|
|
|
|
tasks.jar {
|
|
manifest {
|
|
attributes(
|
|
"Specification-Title" to modId,
|
|
"Specification-Vendor" to modAuthors,
|
|
"Specification-Version" to "1",
|
|
"Implementation-Title" to project.name,
|
|
"Implementation-Version" to project.version.toString(),
|
|
"Implementation-Vendor" to modAuthors,
|
|
"Implementation-Timestamp" to OffsetDateTime.now().toString()
|
|
)
|
|
}
|
|
}
|
|
|
|
val packFormats = mapOf(
|
|
"1.20.1" to "15", "1.20.2" to "18", "1.20.3" to "22", "1.20.4" to "22",
|
|
"1.20.5" to "32", "1.20.6" to "32", "1.21.11" to "75",
|
|
"26.1" to "84", "26.1.1" to "84", "26.1.2" to "84", "26.2" to "88"
|
|
)
|
|
|
|
val mcVersionRanges = mapOf(
|
|
"1.20.1" to "[1.20.1,1.20.2)", "1.20.2" to "[1.20.2,1.20.3)",
|
|
"1.20.3" to "[1.20.3,1.20.5)", "1.20.4" to "[1.20.3,1.20.5)",
|
|
"1.20.5" to "[1.20.5,1.21)", "1.20.6" to "[1.20.5,1.21)",
|
|
"1.21.11" to "[1.21.11,1.22)", "26.1" to "[26.1,26.1.3)",
|
|
"26.1.1" to "[26.1.1,26.1.3)", "26.1.2" to "[26.1.2,26.1.3)", "26.2" to "[26.2,26.3)"
|
|
)
|
|
|
|
val forgeVersions = mapOf(
|
|
"1.20.1" to "47.4.20", "1.20.2" to "48.1.0",
|
|
"1.20.3" to "49.0.2", "1.20.4" to "49.0.10",
|
|
"1.20.6" to "50.2.0"
|
|
)
|
|
|
|
val neoforgeVersions = mapOf(
|
|
"1.21.11" to "21.11.45", "26.1" to "26.1.2.97",
|
|
"26.1.1" to "26.1.1.15-beta", "26.1.2" to "26.1.2.97", "26.2" to "26.2.0.64"
|
|
)
|
|
|
|
val fabricApiVersions = mapOf(
|
|
"1.21.11" to "0.141.6+1.21.11", "26.1" to "0.145.1+26.1",
|
|
"26.1.1" to "0.145.4+26.1.1", "26.1.2" to "0.155.2+26.1.2", "26.2" to "0.158.0+26.2"
|
|
)
|
|
|
|
val packFormat = packFormats[mcVersion] ?: "15"
|
|
val mcVersionRange = mcVersionRanges[mcVersion] ?: "[$mcVersion,99)"
|
|
|
|
extra["mcVersion"] = mcVersion
|
|
extra["loader"] = loader
|
|
extra["packFormat"] = packFormat
|
|
extra["packFormat"] = packFormat
|
|
extra["mcVersionRange"] = mcVersionRange
|
|
|
|
when (loader) {
|
|
"forge" -> {
|
|
val fv = forgeVersions[mcVersion] ?: ""
|
|
extra["forgeVersion"] = fv
|
|
}
|
|
"neoforge" -> {
|
|
val nv = neoforgeVersions[mcVersion] ?: ""
|
|
extra["neoforgeVersion"] = nv
|
|
}
|
|
"fabric" -> {
|
|
extra["fabricLoaderVersion"] = "0.19.3"
|
|
extra["fabricApiVersion"] = fabricApiVersions[mcVersion] ?: ""
|
|
}
|
|
}
|
|
|
|
when (loader) {
|
|
"forge" -> apply(from = rootProject.file("build.forge.gradle"))
|
|
"neoforge" -> apply(from = rootProject.file("build.neoforge.gradle"))
|
|
"fabric" -> apply(from = rootProject.file("build.fabric.gradle"))
|
|
}
|
|
|
|
if (loader.isNotEmpty()) {
|
|
tasks.processResources {
|
|
val replaceProperties = mutableMapOf(
|
|
"minecraft_version" to mcVersion,
|
|
"minecraft_version_range" to mcVersionRange,
|
|
"mod_id" to modId,
|
|
"mod_name" to modName,
|
|
"mod_license" to modLicense,
|
|
"mod_version" to modVersion,
|
|
"mod_authors" to modAuthors,
|
|
"mod_description" to modDescription,
|
|
"pack_format" to packFormat,
|
|
)
|
|
|
|
when (loader) {
|
|
"forge" -> {
|
|
val fv = forgeVersions[mcVersion] ?: ""
|
|
replaceProperties["forge_version"] = fv
|
|
replaceProperties["forge_version_range"] = "[${fv.substringBefore('.')},${fv.substringBefore('.').toInt() + 1})"
|
|
replaceProperties["loader_version"] = fv
|
|
replaceProperties["loader_version_range"] = replaceProperties["forge_version_range"]!!
|
|
}
|
|
"neoforge" -> {
|
|
val nv = neoforgeVersions[mcVersion] ?: ""
|
|
replaceProperties["neoforge_version"] = nv
|
|
replaceProperties["neoforge_version_range"] = "[${nv.substringBefore('.')},${nv.substringBefore('.').toInt() + 1})"
|
|
replaceProperties["loader_version"] = nv
|
|
replaceProperties["loader_version_range"] = replaceProperties["neoforge_version_range"]!!
|
|
}
|
|
"fabric" -> {
|
|
replaceProperties["fabric_loader_version"] = "0.19.3"
|
|
replaceProperties["fabric_api_version"] = fabricApiVersions[mcVersion] ?: ""
|
|
replaceProperties["loader_version"] = "0.19.3"
|
|
replaceProperties["loader_version_range"] = "[0.16,1)"
|
|
}
|
|
}
|
|
|
|
inputs.properties(replaceProperties)
|
|
val metaFiles = when (loader) {
|
|
"forge" -> listOf("META-INF/mods.toml")
|
|
"neoforge" -> listOf("META-INF/neoforge.mods.toml")
|
|
"fabric" -> listOf("fabric.mod.json")
|
|
else -> listOf("META-INF/mods.toml")
|
|
}
|
|
filesMatching(metaFiles + listOf("pack.mcmeta")) {
|
|
expand(replaceProperties + mapOf("project" to project))
|
|
}
|
|
|
|
doLast {
|
|
val destDir = layout.buildDirectory.dir("resources/main").get().asFile
|
|
val packMetaFile = destDir.resolve("pack.mcmeta")
|
|
val format = packFormat.toInt()
|
|
val useMinFormat = loader != "forge"
|
|
val content = if (useMinFormat) {
|
|
"""{
|
|
"pack": {
|
|
"description": "lightspeed resources",
|
|
"min_format": $format,
|
|
"max_format": $format
|
|
}
|
|
}"""
|
|
} else {
|
|
"""{
|
|
"pack": {
|
|
"description": "lightspeed resources",
|
|
"pack_format": $format
|
|
}
|
|
}"""
|
|
}
|
|
packMetaFile.parentFile.mkdirs()
|
|
packMetaFile.writeText(content)
|
|
}
|
|
}
|
|
}
|