-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.gradle.kts
473 lines (429 loc) · 17.9 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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import net.fabricmc.loom.task.RemapJarTask
plugins {
id("dev.architectury.loom") version "1.7-SNAPSHOT"
id("com.gradleup.shadow")
id("io.github.null2264.preprocess")
id("me.modmuss50.mod-publish-plugin") version "0.3.5"
}
val isForge = project.name.endsWith("forge")
val isNeo = project.name.endsWith("neoforge")
val isFabric = project.name.endsWith("fabric")
val mcVersionStr = project.name.split("-")[0]
val (major, minor, patch) = mcVersionStr
.split(".")
.toMutableList()
.apply { if (this.size < 3) this.add("") }
val mcVersion: Int = "${major}${minor.padStart(2, '0')}${patch.padStart(2, '0')}".toInt()
// TODO: addingVersion - Add "-" suffix to support snapshots
val supportedVersionRange: List<String?> = mapOf(
11605 to listOf(null, "1.16.5"),
11802 to listOf(null, "1.18.2"),
11902 to listOf("1.19-", "1.19.2"),
11904 to listOf("1.19.3-", "1.19.4"),
12001 to listOf("1.20-", "1.20.1"),
12002 to listOf("1.20.2-", if (!isNeo) "1.20.4" else "1.20.3"),
12004 to listOf(null, "1.20.4"), // for Neo
12006 to listOf("1.20.5-", "1.20.6"),
12101 to listOf("1.21-", "1.21.1"),
12103 to listOf("1.21.2-", null),
)[mcVersion] ?: listOf()
preprocess {
vars.put("MC", mcVersion)
vars.put("FABRIC",
when {
// isFabric && isQuilt -> 2
// isFabric && !isQuilt -> 1
isFabric -> 1
else -> 0
}
)
vars.put("FORGE",
when {
isForge && isNeo -> 2
isForge && !isNeo -> 1
else -> 0
}
)
patternAnnotation.set("io.github.null2264.gradle.Pattern")
}
repositories {
maven("https://jitpack.io")
maven {
url = uri("https://maven.blamejared.com/")
content {
includeGroup("mezz.jei")
}
}
maven("https://maven.shedaniel.me/")
maven("https://maven.terraformersmc.com/")
maven("https://api.modrinth.com/maven/")
maven("https://cursemaven.com/")
maven("https://mvn.devos.one/snapshots/")
maven("https://maven.jamieswhiteshirt.com/libs-release")
maven("https://maven.tterrag.com/")
maven("https://maven.theillusivec4.top/")
maven("https://maven.neoforged.net/releases")
maven("https://raw.githubusercontent.com/Fuzss/modresources/main/maven/")
mavenLocal()
}
base.archivesName.set(project.properties["archives_base_name"] as? String ?: "")
val buildNumber: String? = System.getenv("GITHUB_RUN_NUMBER")
project.version = (project.properties["mod_version"] as? String ?: "") + "+${mcVersionStr}" + (if (buildNumber != null) "b${buildNumber}-" else "-") + (project.properties["version_stage"] ?: "") + (if (isFabric) "-fabric" else (if (isNeo) "-neoforge" else "-forge"))
group = project.properties["maven_group"] as String
loom {
silentMojangMappingsLicense()
runConfigs {
named("client") {
runDir = "../../run/client"
ideConfigGenerated(true)
}
named("server") {
runDir = "../../run/server"
ideConfigGenerated(true)
}
}
if (!isFabric && !isNeo) {
forge {
mixinConfigs = listOf(
"cobblegen.mixins.json"
)
}
}
}
val shade: Configuration by configurations.creating {
configurations.modImplementation.get().extendsFrom(this)
}
dependencies {
// TODO(addingVersion): For snapshots
val mc: Map<Int, String> = mapOf(
)
minecraft("com.mojang:minecraft:${mc[mcVersion] ?: mcVersionStr}")
mappings(loom.officialMojangMappings())
if (isFabric) {
if (mcVersion <= 11902 && project.properties["recipe_viewer"] == "rei")
modImplementation("net.fabricmc:fabric-loader:0.14.14") // I don't get it, REI hate 0.14.21 in 1.19.2 or lower, wtf?
else if (mcVersion <= 12001)
modImplementation("net.fabricmc:fabric-loader:0.14.21")
else
modImplementation("net.fabricmc:fabric-loader:0.16.7")
// For testing
if (project.properties["recipe_viewer"] != "none" && mcVersion > 11605)
// TODO: addingVersion
modLocalRuntime("net.fabricmc.fabric-api:fabric-api:" + mapOf(
11605 to "0.42.0+1.16",
11802 to "0.76.0+1.18.2",
11902 to "0.76.0+1.19.2",
11904 to "0.83.0+1.19.4",
12001 to "0.83.1+1.20.1",
12002 to "0.89.0+1.20.2",
12006 to "0.100.8+1.20.6",
12101 to "0.106.0+1.21.1",
12103 to "0.106.1+1.21.3",
)[mcVersion])
} else {
if (!isNeo) {
"forge"("net.minecraftforge:forge:${mcVersionStr}-" + mapOf(
11605 to "36.2.41",
11802 to "40.2.9",
11902 to "43.2.14",
11904 to "45.1.0",
12001 to "47.0.3",
12002 to "48.0.13",
// LexForge is no longer supported
)[mcVersion])
} else {
// TODO: addingVersion
// snapshot version format:
// "20.5.0-alpha.${mc[mcVersion]}.+"
"neoForge"("net.neoforged:neoforge:" + mapOf(
12002 to "20.2.86",
12004 to "20.4.237",
12006 to "20.6.121",
12101 to "21.1.72",
12103 to "21.3.1-beta",
)[mcVersion])
}
}
shade("blue.endless:jankson:${project.properties["jankson_version"]}")
if (!isFabric)
"forgeRuntimeLibrary"("blue.endless:jankson:${project.properties["jankson_version"]}")
shade("systems.manifold:manifold-ext-rt:${project.properties["manifold_version"]}")
if (!isFabric)
"forgeRuntimeLibrary"("systems.manifold:manifold-ext-rt:${project.properties["manifold_version"]}")
annotationProcessor("systems.manifold:manifold-ext:${project.properties["manifold_version"]}")
testAnnotationProcessor("systems.manifold:manifold-ext:${project.properties["manifold_version"]}")
// Don't wanna deal with these atm
if (mcVersion > 11605) {
// These act like a dummy, technically only here to provide their modules/packages
if (isFabric) {
modCompileOnly("io.github.fabricators_of_create:Porting-Lib:${project.properties["port_lib_version_1_18_2"]}")
modCompileOnly("com.simibubi.create:create-fabric-${project.properties["minecraft_version_1_18_2"]}:${project.properties["create_version_1_18_2"]}")
} else {
modCompileOnly("com.simibubi.create:create-1.18.2:0.5.1.e-318:slim") { isTransitive = false }
}
// <- EMI
if (mcVersion <= 11802 && isFabric) {
modCompileOnly("dev.emi:emi:0.7.3+${mcVersionStr}:api")
if (project.properties["recipe_viewer"] == "emi")
modLocalRuntime("dev.emi:emi:0.7.3+${mcVersionStr}")
} else {
// TODO: addingVersion - EMI. They didn't break API on MC version upgrade so mismatch should be fine
val suffix = mapOf(
11902 to "1.19.2",
11904 to "1.19.4",
12001 to "1.20.1",
12002 to "1.20.2",
12004 to "1.20.2", // For Neo, the same 1.20.2
12006 to "1.20.6",
12101 to "1.21.1",
12103 to "1.21.1", // FIXME: .
)
val emiVersion = "1.1.18+${suffix[mcVersion] ?: "1.20.2"}"
// EMI support multiple platform since 1.0.0
// EMI seems to also skip 1.19 and 1.19.1
modCompileOnly("dev.emi:emi-${if (isFabric) "fabric" else (if (mcVersion >= 12006) "neoforge" else "forge")}:$emiVersion:api")
if (project.properties["recipe_viewer"] == "emi" && suffix[mcVersion] != null)
modLocalRuntime("dev.emi:emi-${if (isFabric) "fabric" else (if (mcVersion >= 12006) "neoforge" else "forge")}:$emiVersion")
}
// EMI ->
// <- REI
// TODO: addingVersion - REI
val reiVersions = mapOf(
11802 to "8.3.618",
11902 to "9.1.619",
11904 to "11.0.621",
12001 to "12.0.625",
12002 to "13.0.685",
12004 to "13.0.685", // for Neo
12006 to "15.0.787",
12101 to "16.0.788",
12103 to "17.0.789",
)
val reiFallback = "17.0.789"
// Use the full package instead of 'api-' for (neo)forge, since the 'api-' didn't include @REIPlugin*
modCompileOnly("me.shedaniel:RoughlyEnoughItems-${if (isFabric) "api-fabric" else if (!isNeo) "forge" else "neoforge"}:${reiVersions[mcVersion] ?: reiFallback}")
if (mcVersion >= 12002) { // FIXME: Not sure why it's not included
modCompileOnly("me.shedaniel.cloth:basic-math:0.6.1")
modCompileOnly("dev.architectury:architectury:11.1.13")
}
if (project.properties["recipe_viewer"] == "rei" && reiVersions[mcVersion] != null) {
if (mcVersion == 11902) // REI's stupid dep bug
modLocalRuntime("dev.architectury:architectury-fabric:6.5.77")
modLocalRuntime("me.shedaniel:RoughlyEnoughItems-${if (isFabric) "fabric" else "forge"}:${reiVersions[mcVersion]}")
}
// REI ->
// <- JEI
// TODO: addingVersion - JEI
val jeiVersions = mapOf(
11802 to "10.2.1.1004",
11902 to "11.6.0.1015",
11904 to "13.1.0.13",
12001 to "15.0.0.12",
12002 to "16.0.0.28",
12004 to "16.0.0.28", // for Neo
12006 to "18.0.0.62",
12101 to "19.21.0.246",
12103 to null,
)
val jeiVersion = jeiVersions[mcVersion]
// <- fallback - should be the latest version
val fallbackJeiVer = "19.21.0.246"
val fallbackJeiMcVer = "1.21.1"
// fallback ->
val jeiMc = mapOf(
12004 to "1.20.2", // for Neo
12103 to fallbackJeiMcVer,
)
modCompileOnly("mezz.jei:jei-${jeiMc[mcVersion] ?: mcVersionStr}-common-api:${jeiVersion ?: fallbackJeiVer}")
modCompileOnly("mezz.jei:jei-${jeiMc[mcVersion] ?: mcVersionStr}-${if (isFabric) "fabric" else "forge"}-api:${jeiVersion ?: fallbackJeiVer}")
if (project.properties["recipe_viewer"] == "jei" && jeiVersion != null)
modLocalRuntime("mezz.jei:jei-${jeiMc[mcVersion] ?: mcVersionStr}-${if (isFabric) "fabric" else "forge"}:${jeiVersion}")
// JEI ->
/* FIXME: Broken, somehow
if (mcVersion == 11802 && isFabric) {
modLocalRuntime("com.tterrag.registrate_fabric:Registrate:MC1.18.2-1.1.7")
modLocalRuntime("io.github.fabricators_of_create:Porting-Lib:${project.port_lib_version_1_18_2}")
modLocalRuntime("com.simibubi.create:create-fabric-${project.minecraft_version_1_18_2}:${project.create_version_1_18_2}")
}
*/
} else {
// slf4j is not included by MC in 1.16.5
shade("org.slf4j:slf4j-api:1.7.36")
shade("org.apache.logging.log4j:log4j-slf4j-impl:2.8.1")
if (!isFabric) {
"forgeRuntimeLibrary"("org.slf4j:slf4j-api:1.7.36")
"forgeRuntimeLibrary"("org.apache.logging.log4j:log4j-slf4j-impl:2.8.1")
}
}
}
val shadowJar by tasks.getting(ShadowJar::class) {
isZip64 = true
relocate("blue.endless.jankson", "io.github.null2264.shadowed.jankson")
if (mcVersion <= 11605) {
relocate("org.slf4j", "io.github.null2264.shadowed.slf4j")
relocate("org.apache.logging", "io.github.null2264.shadowed.log4j")
}
relocate("manifold", "io.github.null2264.shadowed.manifold")
if (isFabric) {
exclude("META-INF/mods.toml")
exclude("META-INF/neoforge.mods.toml")
} else if (isForge) {
exclude("fabric.mod.json")
exclude(if (isNeo && mcVersion >= 12006) "META-INF/mods.toml" else "META-INF/neoforge.mods.toml")
}
exclude("architectury.common.json")
configurations = listOf(shade)
archiveClassifier.set("dev-shade")
}
artifacts.add("archives", shadowJar)
val remapJar by tasks.getting(RemapJarTask::class) {
dependsOn(shadowJar)
inputFile.set(shadowJar.archiveFile)
}
val processResources by tasks.getting(ProcessResources::class) {
val metadataVersion = "${project.properties["mod_version"]}-${project.properties["version_stage"]}"
val metadataMCVersion =
if (supportedVersionRange[0] != null) (
(if (isFabric) ">=" else "[") +
supportedVersionRange[0] +
(if (supportedVersionRange[1] == null)
(if (isFabric) "" else ",)")
else ((if (isFabric) " <=" else ",") + supportedVersionRange[1] + (if (isFabric) "" else "]")))
) else (if (isFabric) supportedVersionRange[1] else "[${supportedVersionRange[1]}]")
val properties = mapOf(
"version" to metadataVersion,
"mcversion" to metadataMCVersion,
"forge" to (if (isNeo) "neoforge" else "forge"),
)
inputs.properties(properties)
filteringCharset = Charsets.UTF_8.name()
val metadataFilename =
if (isFabric) {
"fabric.mod.json"
} else {
if (isNeo && mcVersion >= 12006) "META-INF/neoforge.mods.toml" else "META-INF/mods.toml"
}
filesMatching(metadataFilename) {
filter { line -> if (line.trim().startsWith("//")) "" else line } // strip comments
expand(properties)
}
}
val targetJavaVersion = if (mcVersion >= 12006) 21 else (if (mcVersion >= 11700) 17 else 8)
tasks.withType<JavaCompile>().configureEach {
// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
// If Javadoc is generated, this must be specified in that task too.
options.encoding = "UTF-8"
if (targetJavaVersion > 8) {
options.release = targetJavaVersion
}
}
java {
val javaVersion = JavaVersion.toVersion(targetJavaVersion)
if (JavaVersion.current() != javaVersion) {
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
}
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()
}
tasks.jar {
from("LICENSE") {
rename { "${it}_${base.archivesName.get()}" }
}
}
if (JavaVersion.current() != JavaVersion.VERSION_1_8 &&
sourceSets.main.get().allJava.files.any {it.name == "module-info.java"}) {
tasks.withType<JavaCompile>() {
// if you DO define a module-info.java file:
options.compilerArgs.addAll(listOf("-Xplugin:Manifold", "--module-path", classpath.asPath))
}
} else {
tasks.withType<JavaCompile>() {
// If you DO NOT define a module-info.java file:
options.compilerArgs.addAll(listOf("-Xplugin:Manifold"))
}
}
// TODO: addingVersion
val mcReleaseVersions = mapOf<Int, List<String>>(
11605 to listOf("1.16.5"),
11802 to listOf("1.18.2"),
11902 to listOf("1.19", "1.19.1", "1.19.2"),
11904 to listOf("1.19.3", "1.19.4"),
12001 to listOf("1.20", "1.20.1"),
12002 to listOf("1.20.2", "1.20.3").let {
val rt = it.toMutableList()
if (!isNeo) rt.add("1.20.4")
rt
},
12004 to listOf("1.20.4"), // for Neo
12006 to listOf("1.20.5", "1.20.6"),
12101 to listOf("1.21", "1.21.1"),
12103 to listOf("1.21.2", "1.21.3")
)[mcVersion] ?: throw IllegalStateException("Should not be empty!")
// These overwrites mcReleaseVersions
val cfSnapshots = mapOf<Int, List<String>>(
// 12102 to listOf("1.21.2-Snapshot"),
)[mcVersion]
// These overwrites mcReleaseVersions
val mrSnapshots = mapOf<Int, List<String>>(
// 12102 to listOf("1.21.2-pre3"),
)[mcVersion]
publishMods {
file.set(tasks.remapJar.get().archiveFile)
displayName.set("[${if (isFabric) "FABRIC" else (if (isNeo) "NEOFORGE" else "FORGE")} MC${mcReleaseVersions[0] + (if (mcReleaseVersions.size > 1) "+" else "")}] v${project.properties["mod_version"]}-${project.properties["version_stage"]}${if (mcVersion <= 11605) " (LITE)" else ""}")
changelog.set(System.getenv("CHANGELOG") ?: "Please visit our [releases](https://github.com/null2264/CobbleGen/releases) for a changelog")
version.set(project.version.toString())
if (isFabric) {
modLoaders.add("fabric")
modLoaders.add("quilt")
} else {
if (mcVersion <= 12002 && !isNeo) // No more LexForge, LexForge is too buggy
modLoaders.add("forge")
if (mcVersion == 12001 || isNeo)
modLoaders.add("neoforge")
}
type = when(project.properties["version_stage"]) {
"ALPHA" -> ALPHA
"BETA" -> BETA
else -> STABLE
}
val cfToken = System.getenv("CURSEFORGE")
if (cfToken != null) {
curseforge {
accessToken = cfToken
projectId.set(project.properties["curseforge_project"] as String)
if (cfSnapshots == null) {
for (mcVer in mcReleaseVersions) {
minecraftVersions.add(mcVer)
}
} else {
for (mcVer in cfSnapshots) {
minecraftVersions.add(mcVer)
}
}
embeds {
slug = "jankson"
}
}
}
val mrToken = System.getenv("MODRINTH")
if (mrToken != null) {
modrinth {
accessToken = mrToken
projectId.set(project.properties["modrinth_project"] as String)
if (mrSnapshots == null) {
for (mcVer in mcReleaseVersions) {
minecraftVersions.add(mcVer)
}
} else {
for (mcVer in mrSnapshots) {
minecraftVersions.add(mcVer)
}
}
}
}
}