forked from Gaming32/world-host
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.gradle.kts
507 lines (452 loc) · 15.9 KB
/
version.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
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
import com.replaymod.gradle.preprocess.PreprocessTask
import groovy.lang.GroovyObjectSupport
import org.jetbrains.kotlin.daemon.common.toHexString
import xyz.wagyourtail.unimined.api.mapping.task.ExportMappingsTask
import xyz.wagyourtail.unimined.api.minecraft.task.RemapJarTask
import xyz.wagyourtail.unimined.internal.mapping.MappingsProvider
import xyz.wagyourtail.unimined.internal.mapping.task.ExportMappingsTaskImpl
import xyz.wagyourtail.unimined.internal.minecraft.resolver.MinecraftDownloader
import xyz.wagyourtail.unimined.util.capitalized
import xyz.wagyourtail.unimined.util.sourceSets
import java.net.NetworkInterface
import java.nio.file.Path
plugins {
java
`maven-publish`
id("io.github.gaming32.gradle.preprocess")
id("xyz.wagyourtail.unimined")
id("com.modrinth.minotaur") version "2.8.7"
id("xyz.wagyourtail.jvmdowngrader") version "1.0.1"
}
fun Any.setGroovyProperty(name: String, value: Any) = withGroovyBuilder { metaClass }.setProperty(this, name, value)
fun Any.getGroovyProperty(name: String): Any = withGroovyBuilder { metaClass }.getProperty(this, name)!!
group = "io.github.gaming32"
val modVersion = project.properties["mod.version"] as String
val mcVersionString by extra(name.substringBefore("-"))
val loaderName by extra(name.substringAfter("-"))
val isFabric = loaderName == "fabric"
val isForge = loaderName == "forge"
val isNeoForge = loaderName == "neoforge"
val isForgeLike = isForge || isNeoForge
base.archivesName.set(rootProject.name)
// major.minor.?patch
// to MMmmPP
val mcVersion by extra(mcVersionString.split(".").map { it.toInt() }
.let {
it[0] * 1_00_00 + it[1] * 1_00 + it.getOrElse(2) { 0 }
})
println("MC_VERSION: $mcVersionString $mcVersion")
version = "${modVersion}+${mcVersionString}-${loaderName}"
repositories {
mavenCentral()
maven("https://maven.fabricmc.net")
maven("https://maven.minecraftforge.net")
maven("https://maven.neoforged.net/releases")
}
java {
withSourcesJar()
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}
tasks.compileJava {
options.release = 21
options.compilerArgs.add("-Xlint:all")
}
unimined.minecraft {
version(mcVersionString)
if ((mcVersion != 1_20_01 || !isForge) && mcVersion < 1_20_05) {
side("client")
}
mappings {
intermediary()
if (mcVersion <= 1_19_00) {
searge()
}
mojmap()
when {
mcVersion >= 1_21_00 -> "1.21:2024.07.28"
mcVersion >= 1_20_05 -> "1.20.6:2024.06.16"
mcVersion >= 1_20_04 -> "1.20.4:2024.04.14"
mcVersion >= 1_20_03 -> "1.20.3:2023.12.31"
mcVersion >= 1_20_02 -> "1.20.2:2023.12.10"
mcVersion >= 1_20_01 -> "1.20.1:2023.09.03"
mcVersion >= 1_19_04 -> "1.19.4:2023.06.26"
mcVersion >= 1_19_03 -> "1.19.3:2023.06.25"
mcVersion >= 1_19_00 -> "1.19.2:2022.11.27"
mcVersion >= 1_18_00 -> "1.18.2:2022.11.06"
mcVersion >= 1_17_00 -> "1.17.1:2021.12.12"
mcVersion >= 1_16_00 -> "1.16.5:2022.03.06"
else -> null
}?.let {
parchment(it.substringBefore(":"), it.substringAfter(":"))
}
if (mcVersion <= 1_19_00) {
stub.withMappings("searge", listOf("mojmap")) {
c("net/minecraft/client/gui/chat/NarratorChatListener", "net/minecraft/client/GameNarrator")
}
}
devFallbackNamespace("official")
}
when {
isFabric -> fabric {
loader("0.15.11")
}
isForge -> minecraftForge {
loader(when(mcVersion) {
1_20_01 -> "47.1.3"
1_19_04 -> "45.1.0"
1_19_02 -> "43.2.0"
1_18_02 -> "40.2.0"
else -> throw IllegalStateException("Unknown Forge version for $mcVersionString")
})
mixinConfig("world-host.mixins.json")
}
isNeoForge -> neoForge {
loader(when (mcVersion) {
1_21_01 -> "1"
1_20_06 -> "115"
1_20_04 -> "167"
else -> throw IllegalStateException("Unknown NeoForge version for $mcVersionString")
})
minecraftRemapper.config {
ignoreConflicts(true)
}
}
else -> throw IllegalStateException()
}
val mcJavaVersion = (minecraftData as MinecraftDownloader).metadata.javaVersion
if (mcJavaVersion < java.sourceCompatibility) {
println("Classes need downgrading to Java $mcJavaVersion")
tasks.downgradeJar {
downgradeTo = mcJavaVersion
}
tasks.shadeDowngradedApi {
downgradeTo = mcJavaVersion
shadePath = { "io/github/gaming32/worldhost" }
}
defaultRemapJar = false
remap(tasks.shadeDowngradedApi.get(), "remapJar")
tasks.assemble.get().dependsOn("remapJar")
}
runs {
config("client") {
javaVersion = JavaVersion.VERSION_21
}
val usernameSuffix = NetworkInterface.getNetworkInterfaces()
.nextElement()
.hardwareAddress
.toHexString()
.substring(0, 10)
for (name in listOf("host", "joiner")) {
val runName = "test${name.capitalized()}"
val user = name.uppercase()
val provider = (minecraftData as MinecraftDownloader).provider
provider.provideRunClientTask(runName, file("run/$runName"))
configFirst(runName) {
description = "Test $user"
args = args!!.map { if (it == "Dev") "$user$usernameSuffix" else it }
jvmArgs(
"-Dworld-host-testing.enabled=true",
"-Dworld-host-testing.user=$user",
"-Ddevauth.enabled=false"
)
javaVersion = JavaVersion.VERSION_21
}
}
}
}
val minecraft = unimined.minecrafts[sourceSets.main.get()]
// jank hax to pretend to be arch-loom
class LoomGradleExtension : GroovyObjectSupport() {
var mappingConfiguration: Any? = null
}
val loom = LoomGradleExtension()
extensions.add("loom", loom)
val mappingsConfig = object {
var tinyMappings: Path? = null
var tinyMappingsWithSrg: Path? = null
}
loom.setGroovyProperty("mappingConfiguration", mappingsConfig)
val tinyMappings: File = file("${projectDir}/build/tmp/tinyMappings.tiny").also { file ->
val export = ExportMappingsTaskImpl.ExportImpl(minecraft.mappings as MappingsProvider).apply {
location = file
type = ExportMappingsTask.MappingExportTypes.TINY_V2
setSourceNamespace("official")
setTargetNamespaces(listOf("intermediary", "mojmap"))
renameNs[minecraft.mappings.getNamespace("mojmap")] = "named"
}
export.validate()
export.exportFunc((minecraft.mappings as MappingsProvider).mappingTree)
}
mappingsConfig.setGroovyProperty("tinyMappings", tinyMappings.toPath())
if (isForge) {
val tinyMappingsWithSrg: File = file("${projectDir}/build/tmp/tinyMappingsWithSrg.tiny").also { file ->
val export = ExportMappingsTaskImpl.ExportImpl(minecraft.mappings as MappingsProvider).apply {
location = file
type = ExportMappingsTask.MappingExportTypes.TINY_V2
setSourceNamespace("official")
setTargetNamespaces(listOf("intermediary", "searge", "mojmap"))
renameNs[minecraft.mappings.getNamespace("mojmap")] = "named"
renameNs[minecraft.mappings.getNamespace("searge")] = "srg"
}
export.validate()
export.exportFunc((minecraft.mappings as MappingsProvider).mappingTree)
}
mappingsConfig.setGroovyProperty("tinyMappingsWithSrg", tinyMappingsWithSrg.toPath())
}
repositories {
maven("https://maven.quiltmc.org/repository/release/")
maven("https://maven.terraformersmc.com/releases")
maven("https://maven.isxander.dev/releases")
maven("https://pkgs.dev.azure.com/djtheredstoner/DevAuth/_packaging/public/maven/v1")
maven("https://repo.viaversion.com")
maven("https://maven.wagyourtail.xyz/snapshots")
maven("https://maven.maxhenkel.de/repository/public")
maven("https://api.modrinth.com/maven") {
content {
includeGroup("maven.modrinth")
}
}
maven("https://jitpack.io")
}
println("loaderName: $loaderName")
println("mcVersion: $mcVersion")
val forgeJarJar: Configuration by configurations.creating {
isTransitive = false
}
val modCompileOnly: Configuration by configurations.creating {
configurations.getByName("compileOnly").extendsFrom(this)
}
val modRuntimeOnly: Configuration by configurations.creating {
configurations.getByName("runtimeOnly").extendsFrom(this)
}
minecraft.apply {
mods.remap(modCompileOnly)
mods.remap(modRuntimeOnly)
}
dependencies {
val include = configurations["include"]
val modImplementation = configurations["modImplementation"]
val minecraftLibraries = configurations["minecraftLibraries"]
include(implementation("org.quiltmc.parsers:json:0.3.0")!!)
include(implementation("org.semver4j:semver4j:5.3.0")!!)
if (isForgeLike) {
minecraftLibraries("org.quiltmc.parsers:json:0.3.0")
}
if (isFabric) {
when (mcVersion) {
1_21_01 -> "11.0.1"
1_20_06 -> "10.0.0-beta.1"
1_20_04 -> "9.0.0"
1_20_01 -> "7.2.2"
1_19_04 -> "6.3.1"
1_19_02 -> "4.2.0-beta.2"
1_18_02 -> "3.2.5"
else -> null
}?.let {
modImplementation("com.terraformersmc:modmenu:$it")
}
}
when {
isFabric -> "fabric"
isForge -> "forge-latest"
isNeoForge -> "neoforge"
else -> null
}?.let { modRuntimeOnly("me.djtheredstoner:DevAuth-$it:1.2.1") }
if (isFabric) {
when (mcVersion) {
1_21_01 -> "0.102.0+1.21.1"
1_20_06 -> "0.100.0+1.20.6"
1_20_04 -> "0.97.1+1.20.4"
1_20_01 -> "0.92.2+1.20.1"
1_19_04 -> "0.87.2+1.19.4"
1_19_02 -> "0.77.0+1.19.2"
1_18_02 -> "0.77.0+1.18.2"
else -> null
}?.let { fapiVersion ->
val resourceLoader = fabricApi.fabricModule("fabric-resource-loader-v0", fapiVersion)
include(modImplementation(resourceLoader)!!)
for (module in listOf(
"fabric-screen-api-v1",
"fabric-key-binding-api-v1",
"fabric-lifecycle-events-v1"
)) {
modRuntimeOnly(fabricApi.fabricModule(module, fapiVersion))
}
}
}
if (isFabric) {
modCompileOnly("dev.isxander:main-menu-credits:1.1.2") {
isTransitive = false
}
}
if (mcVersion >= 1_20_04 && isFabric) {
modCompileOnly("de.florianmichael:viafabricplus:3.0.2") {
isTransitive = false
}
}
compileOnly("de.maxhenkel.voicechat:voicechat-api:2.5.0")
when (mcVersion) {
1_21_01 -> "2.5.20"
1_20_06 -> "2.5.20"
1_20_04 -> "2.5.20"
1_20_01 -> "2.5.20"
1_19_04 -> "2.5.12"
1_19_02 -> "2.5.20"
1_18_02 -> "2.5.20"
else -> null
}?.let {
modCompileOnly("maven.modrinth:simple-voice-chat:$loaderName-$mcVersionString-$it")
}
compileOnly("com.demonwav.mcdev:annotations:2.1.0")
// Resolves javac warnings about Guava
compileOnly("com.google.errorprone:error_prone_annotations:2.11.0")
}
preprocess {
fun Boolean.toInt() = if (this) 1 else 0
disableRemapping = true
vars.putAll(mapOf(
"FABRIC" to isFabric.toInt(),
"FORGE" to isForge.toInt(),
"NEOFORGE" to isNeoForge.toInt(),
"FORGELIKE" to isForgeLike.toInt(),
"MC" to mcVersion,
))
patternAnnotation.set("io.github.gaming32.worldhost.versions.Pattern")
keywords.value(keywords.get())
keywords.put(".json", PreprocessTask.DEFAULT_KEYWORDS.copy(eval = "//??"))
keywords.put(".toml", PreprocessTask.CFG_KEYWORDS.copy(eval = "#??"))
}
//println("Parallel: ${gradle.startParameter.isParallelProjectExecutionEnabled}")
modrinth {
val isStaging = true
token.set(project.properties["modrinth.token"] as String? ?: System.getenv("MODRINTH_TOKEN"))
projectId.set(if (isStaging) "world-host-staging" else "world-host")
versionNumber.set(version.toString())
val loadersText = when {
isFabric -> "Fabric"
isForge -> "Forge"
isNeoForge -> "NeoForge"
else -> throw IllegalStateException()
}
versionName.set("[$loadersText $mcVersionString] World Host $modVersion")
uploadFile.set(tasks.named("remapJar"))
additionalFiles.add(tasks.named("sourcesJar"))
gameVersions.add(mcVersionString)
when (mcVersion) {
1_19_04 -> "23w13a_or_b"
1_20_01 -> "1.20"
1_20_04 -> "1.20.3"
1_20_06 -> "1.20.5"
else -> null
}?.let(gameVersions::add)
loaders.add(loaderName)
dependencies {
if (isFabric) {
optional.project("modmenu")
}
}
rootProject.file("changelogs/$modVersion.md").let {
if (it.exists()) {
println("Setting changelog file to $it")
changelog.set(it.readText())
} else {
println("Changelog file $it does not exist!")
}
}
}
tasks.processResources {
// TODO: Remove pack.mcmeta in 1.20.4
filesMatching("pack.mcmeta") {
expand("pack_format" to when {
mcVersion >= 1_21_00 -> 34
mcVersion >= 1_20_05 -> 32
mcVersion >= 1_20_03 -> 22
mcVersion >= 1_20_02 -> 18
mcVersion >= 1_20_00 -> 15
mcVersion >= 1_19_04 -> 13
mcVersion >= 1_19_03 -> 12
mcVersion >= 1_19_00 -> 9
mcVersion >= 1_18_00 -> 8
mcVersion >= 1_17_00 -> 7
mcVersion >= 1_16_02 -> 6
mcVersion >= 1_15_00 -> 5
mcVersion >= 1_13_00 -> 4
mcVersion >= 1_11_00 -> 3
mcVersion >= 1_09_00 -> 2
mcVersion >= 1_06_01 -> 1
else -> return@filesMatching
})
}
filesMatching("fabric.mod.json") {
filter {
if (it.trim().startsWith("//")) "" else it
}
}
filesMatching(listOf(
"fabric.mod.json",
"META-INF/mods.toml",
"META-INF/neoforge.mods.toml",
"*.mixins.json"
)) {
expand(mapOf(
"version" to version,
"mc_version" to mcVersionString
))
}
if (isFabric) {
exclude("pack.mcmeta", "META-INF/mods.toml", "META-INF/neoforge.mods.toml")
} else {
exclude("fabric.mod.json")
if (isNeoForge && mcVersion >= 1_20_05) {
exclude("META-INF/mods.toml")
} else {
exclude("META-INF/neoforge.mods.toml")
}
}
doLast {
val resources = "${layout.buildDirectory.get()}/resources/main"
if (isForgeLike) {
copy {
from(file("$resources/assets/world-host/icon.png"))
into(resources)
}
delete(file("$resources/assets/world-host/icon.png"))
} else {
delete(file("$resources/pack.mcmeta"))
}
}
}
tasks.jar {
archiveClassifier = "dev"
}
tasks.withType<RemapJarTask> {
if (isForgeLike && !forgeJarJar.isEmpty) {
forgeJarJar.files.forEach { from(zipTree(it)) }
}
manifest {
when {
isForge -> {
attributes["MixinConfigs"] = "world-host.mixins.json"
}
isFabric -> {
attributes["Fabric-Loom-Mixin-Remap-Type"] = "static"
}
}
}
from("$rootDir/LICENSE")
mixinRemap {
disableRefmap()
}
}
publishing {
publications {
create<MavenPublication>("maven") {
artifactId = "world-host"
artifact(tasks.named("remapJar"))
artifact(tasks.named("sourcesJar")) {
classifier = "sources"
}
}
}
}