generated from nea89o/Forge1.8.9Template
-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.gradle.kts
421 lines (396 loc) · 17.1 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
/*
* This file is part of Resourcify
* Copyright (C) 2023-2024 DeDiamondPro
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License Version 3 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import com.matthewprenger.cursegradle.CurseArtifact
import com.matthewprenger.cursegradle.CurseProject
import com.matthewprenger.cursegradle.CurseRelation
import com.matthewprenger.cursegradle.Options
import com.replaymod.gradle.preprocess.PreprocessTask
import gg.essential.gradle.util.noServerRunConfigs
import gg.essential.gradle.util.setJvmDefault
import org.jetbrains.kotlin.com.google.gson.Gson
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
plugins {
alias(libs.plugins.kotlin)
id(egt.plugins.multiversion.get().pluginId)
id(egt.plugins.defaults.get().pluginId)
alias(libs.plugins.shadow)
alias(libs.plugins.blossom)
alias(libs.plugins.minotaur)
alias(libs.plugins.cursegradle)
}
val mod_name: String by project
val mod_version: String by project
val mod_id: String by project
preprocess {
vars.put("MODERN", if (project.platform.mcMinor >= 16) 1 else 0)
keywords.set(
mutableMapOf(
".java" to PreprocessTask.DEFAULT_KEYWORDS,
".kt" to PreprocessTask.DEFAULT_KEYWORDS,
".gradle" to PreprocessTask.DEFAULT_KEYWORDS,
".json" to PreprocessTask.DEFAULT_KEYWORDS,
".mcmeta" to PreprocessTask.DEFAULT_KEYWORDS,
".cfg" to PreprocessTask.CFG_KEYWORDS,
".accesswidener" to PreprocessTask.CFG_KEYWORDS
)
)
}
blossom {
replaceToken("@NAME@", mod_name)
replaceToken("@ID@", mod_id)
replaceToken("@VER@", mod_version)
}
version = mod_version
group = "dev.dediamondpro"
base {
archivesName.set(mod_id)
}
tasks.compileKotlin.setJvmDefault(if (platform.mcVersion >= 11400) "all" else "all-compatibility")
loom.noServerRunConfigs()
loom {
if (project.platform.isLegacyForge) runConfigs {
"client" { programArgs("--tweakClass", "org.spongepowered.asm.launch.MixinTweaker") }
}
// we only use access wideners in 1.20.4 or above
if (project.platform.mcVersion >= 12004) {
accessWidenerPath = project.file("src/main/resources/resourcify.accesswidener")
}
if (project.platform.isForge) forge {
mixinConfig("${project.platform.loaderStr}.mixins.${mod_id}.json")
mixin.defaultRefmapName.set("forge.mixins.${mod_id}.refmap.json")
}
if (project.platform.isNeoForge) mixin {
useLegacyMixinAp = true
defaultRefmapName.set("forge.mixins.${mod_id}.refmap.json")
}
}
if (project.platform.mcVersion != 10809) {
tasks.getByName("validateAccessWidener").dependsOn("preprocessResources")
}
repositories {
maven("https://maven.terraformersmc.com/releases/")
maven("https://repo.essential.gg/repository/maven-public/")
maven("https://maven.dediamondpro.dev/releases")
maven("https://thedarkcolour.github.io/KotlinForForge/")
maven("https://repo.spongepowered.org/maven/")
maven("https://api.modrinth.com/maven")
maven("https://maven.neoforged.net/releases/")
maven("https://maven.terraformersmc.com/releases/")
mavenCentral()
mavenLocal()
}
val shade: Configuration by configurations.creating {
configurations.implementation.get().extendsFrom(this)
}
dependencies {
val elementaPlatform: String? by project
val universalPlatform: String? by project
val universalVersion = if (platform.isNeoForge || (platform.isForge && platform.mcVersion >= 12101))
"363+diamond.neoforge" else libs.versions.universal.get()
if (platform.isFabric) {
val fabricApiVersion: String by project
// TODO: re-enable for 1.21.3 once essential loom has updated
if (platform.mcVersion <= 12001) {
modImplementation(fabricApi.module("fabric-resource-loader-v0", fabricApiVersion))
}
modImplementation("net.fabricmc:fabric-language-kotlin:${libs.versions.fabric.language.kotlin.get()}")
modCompileOnly("gg.essential:elementa-${elementaPlatform ?: platform}:${libs.versions.elementa.get()}")
modCompileOnly("gg.essential:universalcraft-${universalPlatform ?: platform}:${universalVersion}")
modCompileOnly(libs.modMenu)
} else if (platform.isForgeLike) {
if (platform.isLegacyForge) {
shade(libs.bundles.kotlin) { isTransitive = false }
shade(libs.mixin) { isTransitive = false }
annotationProcessor("org.spongepowered:mixin:0.8.5:processor")
} else {
val kotlinForForgeVersion: String by project
if (platform.isNeoForge) {
implementation("thedarkcolour:kotlinforforge-neoforge:$kotlinForForgeVersion")
} else {
implementation("thedarkcolour:kotlinforforge:$kotlinForForgeVersion")
}
}
}
// Always shade and relocate universalcraft to avoid any conflict with essential (even on fabric)
shade("gg.essential:universalcraft-${universalPlatform ?: platform}:$universalVersion") {
isTransitive = false
}
// Always shade elementa since we use a custom version, relocate to avoid conflicts
shade("gg.essential:elementa-${elementaPlatform ?: platform}:${libs.versions.elementa.get()}") {
isTransitive = false
}
// Since elementa is relocated, and MineMark doesn't guarantee backwards compatibility, we need to shade this
shade(libs.bundles.markdown) {
isTransitive = false
}
}
tasks {
withType<KotlinJvmCompile>().configureEach {
compilerOptions {
languageVersion = org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_1_6
apiVersion = org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_1_6
}
}
processResources {
inputs.property("id", mod_id)
inputs.property("name", mod_name)
inputs.property("version", mod_version)
inputs.property("fabricMcVersion", getFabricMcVersionRange())
inputs.property("forgeMcVersion", getForgeMcVersionRange())
filesMatching(listOf("mcmod.info", "META-INF/mods.toml", "META-INF/neoforge.mods.toml", "fabric.mod.json")) {
expand(
mapOf(
"id" to mod_id,
"name" to mod_name,
"version" to mod_version,
"fabricMcVersion" to getFabricMcVersionRange(),
"forgeMcVersion" to getForgeMcVersionRange(),
)
)
}
if (project.platform.mcMinor <= 12) {
dependsOn("generateLangFiles")
from("${project.buildDir}/generated/lang") {
into("assets/$mod_id/lang")
}
exclude("**/assets/$mod_id/lang/*.json")
}
if (project.platform.mcMinor > 16) {
exclude("ssl/*")
}
if (!project.platform.isFabric) exclude("fabric.mod.json", "fabric.mixins.${mod_id}.json")
if (!project.platform.isLegacyForge) exclude("mcmod.info")
if (project.platform.isLegacyForge) exclude("resourcify.accesswidener")
if (!platform.isModLauncher) exclude("pack.mcmeta")
if (!platform.isForgeLike) exclude("forge.mixins.${mod_id}.json")
if (!platform.isForge && (!platform.isNeoForge || platform.mcVersion >= 12005)) exclude("META-INF/mods.toml")
if (!platform.isNeoForge || platform.mcVersion < 12005) exclude("META-INF/neoforge.mods.toml")
}
register("generateLangFiles") {
val gson = Gson()
val generatedDir = File(project.buildDir, "generated/lang")
generatedDir.mkdirs()
rootProject.file("src/main/resources/assets/$mod_id/lang").listFiles()?.filter {
it.extension == "json"
}?.forEach { jsonFile ->
val map: Map<String, String> =
gson.fromJson(jsonFile.reader(), Map::class.java) as Map<String, String>
val fileName = jsonFile.nameWithoutExtension.split("_").let {
"${it[0]}_${if (platform.mcVersion == 10809) it[1].uppercase() else it[1]}.lang"
}
val langFile = File(generatedDir, fileName)
langFile.printWriter().use { out ->
map.forEach { (key, value) ->
out.println("$key=$value")
}
}
}
}
withType<Jar> {
from(rootProject.file("LICENSE"))
from(rootProject.file("LICENSE.LESSER"))
}
named<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>("shadowJar") {
archiveClassifier.set("dev")
configurations = listOf(shade)
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
exclude("META-INF/versions/9/**")
mergeServiceFiles()
relocate("gg.essential.universal", "dev.dediamondpro.resourcify.libs.universal")
relocate("gg.essential.elementa", "dev.dediamondpro.resourcify.libs.elementa")
relocate("dev.dediamondpro.minemark", "dev.dediamondpro.resourcify.libs.minemark")
relocate("org.commonmark", "dev.dediamondpro.resourcify.libs.commonmark")
relocate("org.ccil.cowan.tagsoup", "dev.dediamondpro.resourcify.libs.tagsoup")
if (platform.isForge && platform.mcVersion >= 12100) {
exclude("forge.mixins.resourcify.refmap.json")
archiveFileName.set("$mod_name (${getPrettyVersionRange(true)}-${platform.loaderStr})-${mod_version}.jar")
}
}
remapJar {
if (platform.isForge && platform.mcVersion >= 12100) {
enabled = false
}
input.set(shadowJar.get().archiveFile)
archiveClassifier.set("")
finalizedBy("copyJar")
archiveFileName.set("$mod_name (${getPrettyVersionRange(true)}-${platform.loaderStr})-${mod_version}.jar")
if (platform.isForgeLike && platform.mcVersion >= 12004) {
atAccessWideners.add("resourcify.accesswidener")
}
}
jar {
if (project.platform.isLegacyForge) {
manifest {
attributes(
mapOf(
"ModSide" to "CLIENT",
"TweakOrder" to "0",
"TweakClass" to "org.spongepowered.asm.launch.MixinTweaker",
"ForceLoadAsMod" to true
)
)
}
}
dependsOn(shadowJar)
archiveClassifier.set("")
enabled = false
}
register<Copy>("copyJar") {
File("${project.rootDir}/jars").mkdir()
from(if (platform.isForge && platform.mcVersion >= 12100) shadowJar.get().archiveFile else remapJar.get().archiveFile)
into("${project.rootDir}/jars")
}
clean { delete("${project.rootDir}/jars") }
project.modrinth {
token.set(System.getenv("MODRINTH_TOKEN"))
projectId.set("resourcify")
versionNumber.set(mod_version)
versionName.set("[${getPrettyVersionRange()}-${platform.loaderStr}] Resourcify $mod_version")
uploadFile.set(if (platform.isForge && platform.mcVersion >= 12100) shadowJar.get().archiveFile else remapJar.get().archiveFile)
versionType.set(
when {
mod_version.contains("beta", true) -> "beta"
mod_version.contains("alpha", true) -> "alpha"
else -> "release"
}
)
gameVersions.addAll(getSupportedVersionList())
if (platform.isFabric) {
loaders.add("fabric")
loaders.add("quilt")
} else if (platform.isForge) {
loaders.add("forge")
if (platform.mcVersion == 12001) loaders.add("neoforge")
} else if (platform.isNeoForge) {
loaders.add("neoforge")
}
changelog.set(file("../../changelog.md").readText())
dependencies {
if (platform.isForgeLike && !platform.isLegacyForge) {
required.project("kotlin-for-forge")
} else if (platform.isFabric) {
required.project("fabric-api")
required.project("fabric-language-kotlin")
optional.project("modmenu")
}
}
}
project.curseforge {
project(closureOf<CurseProject> {
apiKey = System.getenv("CURSEFORGE_TOKEN")
id = "870076"
changelog = file("../../changelog.md")
changelogType = "markdown"
if (!platform.isLegacyForge) relations(closureOf<CurseRelation> {
if (platform.isForgeLike && !platform.isLegacyForge) {
requiredDependency("kotlin-for-forge")
} else if (platform.isFabric) {
requiredDependency("fabric-api")
requiredDependency("fabric-language-kotlin")
optionalDependency("modmenu")
}
})
gameVersionStrings.addAll(getSupportedVersionList())
if (platform.isFabric) {
addGameVersion("Fabric")
addGameVersion("Quilt")
} else if (platform.isForge) {
addGameVersion("Forge")
if (platform.mcVersion == 12001) addGameVersion("NeoForge")
} else if (platform.isNeoForge) {
addGameVersion("NeoForge")
}
releaseType = when {
mod_version.contains("beta", true) -> "beta"
mod_version.contains("alpha", true) -> "alpha"
else -> "release"
}
mainArtifact(
if (platform.isForge && platform.mcVersion >= 12100) shadowJar.get().archiveFile else remapJar.get().archiveFile,
closureOf<CurseArtifact> {
displayName = "[${getPrettyVersionRange()}-${platform.loaderStr}] Resourcify $mod_version"
})
})
options(closureOf<Options> {
javaVersionAutoDetect = false
javaIntegration = false
forgeGradleIntegration = false
})
}
register("publish") {
dependsOn(modrinth)
dependsOn(curseforge)
}
}
// Function to get the range of mc versions supported by a version we are building for.
// First value is start of range, second value is end of range or null to leave the range open
fun getSupportedVersionRange(): Pair<String, String?> = when (platform.mcVersion) {
12103 -> "1.21.2" to null
12101 -> "1.21" to "1.21.1"
12006 -> "1.20.5" to "1.20.6"
12004 -> "1.20.2" to "1.20.4"
12001 -> "1.20" to "1.20.1"
11904 -> "1.19.4" to "1.19.4"
11902 -> "1.19" to "1.19.2"
11802 -> "1.18" to "1.18.2"
11602 -> "1.16" to "1.16.5"
11202 -> "1.12.2" to "1.12.2"
10809 -> "1.8.9" to "1.8.9"
else -> error("Undefined version range for ${platform.mcVersion}")
}
fun getPrettyVersionRange(forFile: Boolean = false): String {
val supportedVersionRange = getSupportedVersionRange()
return when {
supportedVersionRange.first == "1.21.2" -> if (forFile) "1.21.3-4" else "1.21.3/4"
supportedVersionRange.first == "1.21.1" -> "1.21.1"
supportedVersionRange.first == supportedVersionRange.second -> supportedVersionRange.first
listOf("1.16", "1.18").contains(supportedVersionRange.first) -> "${supportedVersionRange.first}.x"
else -> "${supportedVersionRange.first}${supportedVersionRange.second?.let { "-$it" } ?: "+"}"
}
}
fun getFabricMcVersionRange(): String {
val supportedVersionRange = getSupportedVersionRange()
if (supportedVersionRange.first == supportedVersionRange.second) return supportedVersionRange.first
return ">=${supportedVersionRange.first}${supportedVersionRange.second?.let { " <=$it" } ?: ""}"
}
fun getForgeMcVersionRange(): String {
val supportedVersionRange = getSupportedVersionRange()
if (supportedVersionRange.first == supportedVersionRange.second) return "[${supportedVersionRange.first}]"
return "[${supportedVersionRange.first},${supportedVersionRange.second?.let { "$it]" } ?: ")"}"
}
fun getSupportedVersionList(): List<String> {
val supportedVersionRange = getSupportedVersionRange()
return when (supportedVersionRange.first) {
"1.21.2" -> listOf("1.21.2", "1.21.3", "1.21.4")
else -> {
val minorVersion = supportedVersionRange.first.let {
if (it.count { c -> c == '.' } == 1) it else it.substringBeforeLast(".")
}
val start = supportedVersionRange.first.let {
if (it.count { c -> c == '.' } == 1) 0 else it.substringAfterLast(".").toInt()
}
val end = supportedVersionRange.second!!.let {
if (it.count { c -> c == '.' } == 1) 0 else it.substringAfterLast(".").toInt()
}
val versions = mutableListOf<String>()
for (i in start..end) {
versions.add("$minorVersion${if (i == 0) "" else ".$i"}")
}
versions
}
}
}