-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
common.gradle.kts
347 lines (294 loc) · 11.9 KB
/
common.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
import kotlin.reflect.KProperty
import kotlin.reflect.jvm.jvmErasure
import org.gradle.jvm.tasks.Jar
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("maven-publish")
id("dev.architectury.loom")
kotlin("jvm")
id("com.replaymod.preprocess")
id("me.fallenbreath.yamlang")
}
val loaderName = if (project.name.endsWith("-common")) "common" else loom.platform.get().name.lowercase()
assert(loaderName in listOf("common", "fabric", "forge", "neoforge"))
assert(project.name.endsWith("-$loaderName"))
enum class Loader {
COMMON,
FABRIC,
FORGE,
NEOFORGE,
;
val isCommon get() = this == COMMON
val isFabric get() = this == FABRIC
val isForge get() = this == FORGE
val isNeoForge get() = this == NEOFORGE
val isForgeLike get() = this == FORGE || this == NEOFORGE
}
val loader = when (loaderName) {
"common" -> Loader.COMMON
"fabric" -> Loader.FABRIC
"forge" -> Loader.FORGE
"neoforge" -> Loader.NEOFORGE
else -> throw AssertionError("invalid loader '$loaderName'")
}
fun Boolean.toInt() = if (this) 1 else 0
val mcVersion: Int by project.extra
preprocess {
vars.put("MC", mcVersion)
vars.put("FABRIC", loader.isFabric.toInt())
vars.put("FORGE", loader.isForge.toInt())
vars.put("NEOFORGE", loader.isNeoForge.toInt())
vars.put("FORGELIKE", loader.isForgeLike.toInt())
}
@Suppress("PropertyName")
class Props {
// automatically convert to other types from the string properties
private inner class Prop {
@Suppress("UNCHECKED_CAST")
operator fun <T> getValue(thisRef: Any?, property: KProperty<*>): T = when (property.returnType.jvmErasure) {
Boolean::class -> project.extra[property.name].toString().toBoolean()
Int::class -> project.extra[property.name].toString().toInt()
List::class -> project.extra[property.name].toString().split(',')
else -> project.extra[property.name]
} as T
}
private val prop = Prop()
//// Global Properties ////
val fabric_loader_version: String by prop
val mod_id: String by prop
val mod_name: String by prop
val mod_authors: List<String> by prop
val mod_version: String by prop
val mod_description: String by prop
val maven_group: String by prop
val archives_base_name: String by prop
val license: String by prop
val homepage_url: String by prop
val sources_url: String by prop
val issues_url: String by prop
val fabric_kotlin_version: String by prop
val forge_kotlin_version: String by prop
val mixinextras_version: String by prop
val conditional_mixin_version: String by prop
val run_with_compat_mods: Boolean by prop
//// Version Specific Properties ////
val minecraft_version: String by prop
val yarn_mappings: String by prop
val minecraft_version_range_fabric: String by prop
val minecraft_version_range_forge: String by prop
val forge_version: String by prop
val forge_version_range: String by prop
val neoforge_version: String by prop
val neoforge_version_range: String by prop
val cloth_version: String by prop
val clumps_version: String by prop
val early_loading_screen_version: String by prop
val fabric_api_version: String by prop
val modmenu_version: String by prop
val trinkets_version: String by prop
val cca_version: String by prop
val curios_version: String by prop
}
val props: Props = Props()
loom {
runConfigs.all {
// to make sure it generates all "Minecraft Client (:subproject_name)" applications
isIdeConfigGenerated = !loader.isCommon
runDir = "../../run-$loaderName"
vmArg("-Dmixin.debug.export=true")
}
if (loader.isForge) {
forge.mixinConfigs = listOf(
"${props.mod_id}.mixins.json",
"${props.mod_id}-forge.mixins.json",
)
// workaround for https://github.com/SpongePowered/Mixin/issues/560
// TODO: remove this when Mixin 0.8.6 is out or you find another proper fix
forge.useCustomMixin = false
@Suppress("UnstableApiUsage")
mixin.useLegacyMixinAp = false
}
rootDir.resolve("src/main/resources/${props.mod_id}.accesswidener").let {
if (it.exists()) {
accessWidenerPath = it
}
}
}
repositories {
when (loader) {
Loader.COMMON -> {}
Loader.FABRIC -> {
// Mod Menu and Trinkets
maven("https://maven.terraformersmc.com/releases/")
// Cardinal Components (for Trinkets)
maven("https://maven.ladysnake.org/releases")
}
Loader.NEOFORGE -> {
// NeoForge
maven("https://maven.neoforged.net/releases")
}
Loader.FORGE -> {
// MixinExtras
mavenCentral()
}
}
if (!loader.isFabric) {
// Kotlin for Forge
maven("https://thedarkcolour.github.io/KotlinForForge/")
// Curios API
maven("https://maven.theillusivec4.top/")
}
// Cloth Config
maven("https://maven.shedaniel.me/")
// Conditional Mixin
maven("https://jitpack.io")
// Other mods from Modrinth
maven("https://api.modrinth.com/maven")
}
dependencies {
minecraft("com.mojang:minecraft:${props.minecraft_version}")
mappings("net.fabricmc:yarn:${props.yarn_mappings}:v2")
// outside the fabric specific projects this should only be used for the @Environment annotation
modImplementation("net.fabricmc:fabric-loader:${props.fabric_loader_version}")
fun modCompat(dependencyNotation: String, dependencyConfiguration: ExternalModuleDependency.() -> Unit = {}) =
if (props.run_with_compat_mods) {
modImplementation(dependencyNotation, dependencyConfiguration)
} else {
modCompileOnly(dependencyNotation, dependencyConfiguration)
}
when (loader) {
Loader.COMMON -> {
modCompileOnly("me.shedaniel.cloth:cloth-config-fabric:${props.cloth_version}") {
exclude(group = "net.fabricmc.fabric-api")
}
modCompileOnly("com.github.Fallen-Breath.conditional-mixin:conditional-mixin-common:${props.conditional_mixin_version}")
}
Loader.FABRIC -> {
modLocalRuntime("maven.modrinth:early-loading-screen:${props.early_loading_screen_version}")
modImplementation("net.fabricmc.fabric-api:fabric-api:${props.fabric_api_version}")
include(modImplementation("com.github.Fallen-Breath.conditional-mixin:conditional-mixin-fabric:${props.conditional_mixin_version}")!!)
modImplementation("net.fabricmc:fabric-language-kotlin:${props.fabric_kotlin_version}")
modImplementation("com.terraformersmc:modmenu:${props.modmenu_version}")
modImplementation("me.shedaniel.cloth:cloth-config-fabric:${props.cloth_version}") {
exclude(group = "net.fabricmc.fabric-api")
}
// other mods we do integration with
// - Trinkets
modCompat("dev.emi:trinkets:${props.trinkets_version}")
// before 3.8.1 these weren't included as modApi but as modImplementation in Trinkets, so we must add them ourselves
if (mcVersion < 12004) {
modCompileOnly("dev.onyxstudios.cardinal-components-api:cardinal-components-base:${props.cca_version}")
modCompileOnly("dev.onyxstudios.cardinal-components-api:cardinal-components-entity:${props.cca_version}")
}
}
Loader.FORGE -> {
"forge"("net.minecraftforge:forge:${props.forge_version}")
include(modImplementation("com.github.Fallen-Breath.conditional-mixin:conditional-mixin-forge:${props.conditional_mixin_version}")!!)
implementation("thedarkcolour:kotlinforforge:${props.forge_kotlin_version}")
modImplementation("me.shedaniel.cloth:cloth-config-forge:${props.cloth_version}")
compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:0.3.5")!!)
implementation(include("io.github.llamalad7:mixinextras-forge:0.3.5")!!)
// other mods we do integration with
// - Curios API
modCompat("top.theillusivec4.curios:curios-forge:${props.curios_version}")
}
Loader.NEOFORGE -> {
"neoForge"("net.neoforged:neoforge:${props.neoforge_version}")
include(modImplementation("com.github.Fallen-Breath.conditional-mixin:conditional-mixin-neoforge:${props.conditional_mixin_version}")!!)
implementation("thedarkcolour:kotlinforforge-neoforge:${props.forge_kotlin_version}")
modImplementation("me.shedaniel.cloth:cloth-config-neoforge:${props.cloth_version}")
// other mods we do integration with
// - Curios API
modCompat("top.theillusivec4.curios:curios-neoforge:${props.curios_version}")
}
}
// other mods we do integration with
modCompat("maven.modrinth:clumps:${props.clumps_version}")
}
var versionSuffix = ""
// detect github action environment variables
// https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
if (System.getenv("BUILD_RELEASE") != "true") {
val buildNumber = System.getenv("BUILD_ID")
versionSuffix += buildNumber?.let { "+build.$it" } ?: "-SNAPSHOT"
}
val fullModVersion = props.mod_version + versionSuffix
tasks.named<ProcessResources>("processResources") {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
val authors = props.mod_authors.joinToString(if (loader.isFabric) "\",\"" else ", ")
val versionsMap = mapOf(
11904 to 13,
12001 to 15,
12002 to 18,
12004 to 22,
)
val replaceProperties = mapOf(
"minecraft_version_range_fabric" to props.minecraft_version_range_fabric,
"minecraft_version_range_forge" to props.minecraft_version_range_forge,
"fabric_loader_version" to props.fabric_loader_version,
"forge_version_range" to props.forge_version_range,
"neoforge_version_range" to props.neoforge_version_range,
"fabric_kotlin_version" to props.fabric_kotlin_version,
"forge_kotlin_version" to props.forge_kotlin_version,
"description" to props.mod_description,
"homepage_url" to props.homepage_url,
"sources_url" to props.sources_url,
"issues_url" to props.issues_url,
"mod_id" to props.mod_id,
"mod_name" to props.mod_name,
"version" to fullModVersion,
"license" to props.license,
"authors" to authors,
"pack_format_number" to versionsMap[mcVersion],
)
inputs.properties(replaceProperties)
filesMatching(listOf("fabric.mod.json", "META-INF/mods.toml", "pack.mcmeta")) {
expand(replaceProperties + mapOf("project" to project))
}
if (!loader.isFabric) {
exclude {
it.file.name == "fabric.mod.json"
}
}
}
// https://github.com/Fallen-Breath/yamlang
yamlang {
targetSourceSets = listOf(sourceSets.main.get())
inputDir = "assets/${props.mod_id}/lang"
}
base {
archivesName = "${props.archives_base_name}-mc${props.minecraft_version}-$loaderName"
}
version = "v$fullModVersion"
group = props.maven_group
tasks.withType<JavaCompile> {
sourceCompatibility = "17"
targetCompatibility = "17"
options.encoding = "UTF-8"
}
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions.jvmTarget = "17"
kotlinOptions.freeCompilerArgs = listOf("-Xjvm-default=all")
}
java {
withSourcesJar()
}
tasks.named<Jar>("jar") {
from(rootProject.file("LICENSE")) {
rename { "${it}_${props.archives_base_name}" }
}
}
// configure the maven publication
publishing {
publications {
create<MavenPublication>("mavenJava") {
artifactId = base.archivesName.get()
from(components["java"])
}
}
// select the repositories you want to publish to
repositories {
// uncomment to publish to the local maven
// mavenLocal()
}
}