-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
293 lines (244 loc) · 8.38 KB
/
build.gradle.kts
File metadata and controls
293 lines (244 loc) · 8.38 KB
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
plugins {
id("com.google.devtools.ksp") version "2.2.20-2.0.4"
id("dev.isxander.modstitch.base") version "0.7.0-unstable"
id("dev.kikugie.fletching-table") version "0.1.0-alpha.22"
id("me.modmuss50.mod-publish-plugin") version "0.8.4"
id("com.github.ben-manes.versions") version "0.53.0"
`maven-publish`
kotlin("jvm") version "2.2.20"
}
fun <T> ifPresent(name: String, required: Boolean = false, block: (String) -> T?): T? =
(System.getenv(name) ?: findProperty(name)
?.toString()?.takeIf { it.isNotBlank() })
.let { if (required && it == null) error("Property $name is required") else it }
?.let(block)
fun prop(name: String, required: Boolean = false): String? =
ifPresent(name, required) { it }
val mcVersion = stonecutter.current.version
val mcRange = prop("mcRange") ?: mcVersion
val loaderName = when {
modstitch.isLoom -> "fabric"
modstitch.isModDevGradle -> "neoforge"
modstitch.isModDevGradleLegacy -> "forge"
else -> error("Unknown loader: $this")
}
val projectModId = prop("mod.id", true)!!
val projectModGroup = prop("mod.group", true)!!
val projectModVersion = prop("mod.version", true)!!
val projectModRepo = prop("mod.repo", true)!!
modstitch.apply {
minecraftVersion = mcVersion
javaVersion = listOf(
("1.20.5" to 21),
("1.18" to 17),
("1.17" to 16),
("1.12" to 8)
).firstOrNull { (ver, _) ->
stonecutter.eval(mcVersion, ">=$ver")
}?.second ?: error("Unknown java version for minecraft $mcVersion")
finalJarTask {
archiveFileName = "$projectModId-$projectModVersion+$mcRange-$loaderName.jar"
}
parchment {
ifPresent("deps.parchment") {
// optional
mappingsVersion = it
minecraftVersion = mcVersion
}
}
metadata {
modId = projectModId
modVersion = projectModVersion
modName = "Sol Chat"
modDescription =
"""
SolChat is heavily inspired by LunaChat.
It allows players to type in romaji and automatically converts their messages into Japanese,
making it easy to chat in Japanese even without an IME.
""".trimIndent()
modGroup = projectModGroup
modAuthor = "alinco8"
modLicense = "MIT"
replacementProperties = mapOf(
"mod_issue_tracker" to "$projectModRepo/issues",
"mod_home_url" to projectModRepo,
"mod_source_url" to projectModRepo,
"pack_format" to when (mcVersion) {
"1.16", "1.16.1" -> 5
"1.16.2", "1.16.3", "1.16.4", "1.16.5" -> 6
"1.17", "1.17.1" -> 7
"1.18", "1.18.1", "1.18.2" -> 8
"1.19", "1.19.1", "1.19.2" -> 9
"1.19.3", "1.19.4" -> 13
"1.20", "1.20.1" -> 15
"1.20.2" -> 18
"1.20.3", "1.20.4" -> 22
"1.20.5", "1.20.6" -> 32
"1.21", "1.21.1" -> 34
"1.21.2", "1.21.3" -> 42
"1.21.4" -> 46
"1.21.5" -> 55
"1.21.6" -> 63
"1.21.7", "1.21.8" -> 64
"1.21.9", "1.21.10" -> 65
else -> throw IllegalArgumentException(
"Please store the resource pack version for $mcVersion in build.gradle.kts!"
)
}.toString()
)
}
loom {
fabricLoaderVersion = "0.17.3"
configureLoom {}
}
moddevgradle {
ifPresent("deps.forge") { forgeVersion = it }
ifPresent("deps.neoform") { neoFormVersion = it }
ifPresent("deps.neoforge") { neoForgeVersion = it }
ifPresent("deps.mcp") { mcpVersion = it }
defaultRuns()
configureNeoForge {
runs.all {
disableIdeRun()
}
}
}
mixin {
addMixinsToModManifest = true
configs.register(projectModId)
}
}
stonecutter {
constants.put("fabric", loaderName == "fabric")
constants.put("neoforge", loaderName == "neoforge")
constants.put("forge", loaderName == "forge")
}
fletchingTable {
lang.create("main") {
patterns.add("assets/lang/*.yml -> /assets/$projectModId/lang")
}
lang.all {
sortKeys = true
prettyPrint = true
}
}
dependencies {
fun modDependency(
id: String,
artifactGetter: (String) -> String,
api: Boolean = false,
withRuntime: Boolean = true,
required: Boolean = true,
version: String? = null,
) {
artifactGetter(version ?: prop("deps.$id", required) ?: return).let {
when (api to withRuntime) {
true to false -> {
modstitchModCompileOnlyApi(it)
}
true to true -> {
modstitchModApi(it)
}
false to false -> {
modstitchModCompileOnly(it)
}
false to true -> {
modstitchModImplementation(it)
}
else -> error("Unreachable")
}
}
}
modstitch.loom {
modDependency(
"fabric_api",
{ "net.fabricmc.fabric-api:fabric-api:$it" },
api = true
)
modDependency(
"kotlin",
{ "net.fabricmc:fabric-language-kotlin:$it" },
version = "1.13.6+kotlin.2.2.20"
)
}
modstitch.moddevgradle {
modDependency(
"kotlin",
{ "thedarkcolour:kotlinforforge-neoforge:$it" },
api = true
)
}
}
publishMods {
from(rootProject.publishMods)
dryRun = rootProject.publishMods.dryRun
displayName = "$projectModVersion for $mcRange $loaderName"
modLoaders.add(loaderName)
modstitch.onEnable {
file = modstitch.finalJarTask.flatMap { it.archiveFile }
}
fun versionList(versions: String) = prop(versions)
?.split(",")
?.map { it.trim() }
?: emptyList()
val stableMcVersions = versionList("pub.stableMC")
val sharedSlugs = listOf<String>()
val neoSlugs = listOf(
"kotlin-for-forge",
)
val fabricSlugs = listOf(
"fabric-language-kotlin",
"fabric-api",
)
val modrinthId = prop("modrinth.id", true)!!
modrinthId.isNotBlank().let {
val token = prop("modrinth.token") ?: return@let
modrinth {
projectId = modrinthId
accessToken = token
minecraftVersions.add(mcVersion)
minecraftVersions.addAll(stableMcVersions)
minecraftVersions.addAll(versionList("pub.modrinthMC"))
announcementTitle =
"Download $mcRange for ${loaderName.replaceFirstChar { it.uppercase() }} from Modrinth"
when (loaderName) {
"neoforge" -> {
sharedSlugs.forEach { requires { slug = it } }
neoSlugs.forEach { requires { slug = it } }
}
"fabric" -> {
sharedSlugs.forEach { requires { slug = it } }
fabricSlugs.forEach { requires { slug = it } }
}
else -> error("Unknown loader $loaderName")
}
println("Modrinth publishing is successfully configured")
}
}
val curseforgeId = prop("curseforge.id", true)!!
curseforgeId.isNotBlank().let {
val token = prop("curseforge.token") ?: return@let
curseforge {
projectId = curseforgeId
accessToken = token
minecraftVersions.add(mcVersion)
minecraftVersions.addAll(stableMcVersions)
minecraftVersions.addAll(versionList("pub.modrinthMC"))
serverRequired
announcementTitle =
"Download $mcRange for ${loaderName.replaceFirstChar { it.uppercase() }} from Modrinth"
when (loaderName) {
"neoforge" -> {
sharedSlugs.forEach { requires { slug = it } }
neoSlugs.forEach { requires { slug = it } }
}
"fabric" -> {
sharedSlugs.forEach { requires { slug = it } }
fabricSlugs.forEach { requires { slug = it } }
}
else -> error("Unknown loader $loaderName")
}
println("CurseForge publishing is successfully configured")
}
}
}