-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
259 lines (211 loc) · 7.45 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
val modId: String by project
val modVersion: String by project
val minecraftVersion = libs.versions.minecraft.get()
val forgeVersion = libs.versions.forge.get()
val hcVersion = libs.versions.hc.get()
val authData = if (project.file("auth.data").exists()) project.file("auth.data").readText().trim() else ""
plugins {
java
idea
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.architectury.loom)
alias(libs.plugins.yamlang)
}
java.withSourcesJar()
sourceSets {
create("api") {
kotlin.srcDirs("src/api/java", "src/api/kotlin")
java.srcDirs("src/api/java")
compileClasspath += main.get().compileClasspath
}
main {
compileClasspath += sourceSets["api"].output
runtimeClasspath += sourceSets["api"].output
resources.srcDir(file("src/generated"))
}
}
loom {
silentMojangMappingsLicense()
val awFile = project.file("src/main/resources/$modId.accesswidener")
if (awFile.exists()) accessWidenerPath = awFile
forge {
convertAccessWideners = true
extraAccessWideners.add(loom.accessWidenerPath.get().asFile.name)
mixinConfigs("$modId.mixins.json")
}
runs {
named("client") {
client()
if (authData.isNotEmpty()) {
val lines = authData.lines()
if (lines.isNotEmpty()) {
println("UUID: ${lines[0]}")
println("USERNAME: ${lines[1]}")
programArgs("--uuid", lines[0], "--username", lines[1], /*"-XX:+AllowEnhancedClassRedefinition"*/)
}
}
mods {
create(modId) {
sourceSet(sourceSets["api"])
sourceSet(sourceSets.main.get())
}
}
}
named("server") {
server()
mods {
create(modId) {
sourceSet(sourceSets["api"])
sourceSet(sourceSets.main.get())
}
}
}
create("data") {
data()
programArgs("--all", "--mod", modId)
programArgs("--output", file("src/generated").absolutePath)
}
}
}
version = "$minecraftVersion-$modVersion"
base {
archivesName = "archivesName".fromProperties
}
repositories {
mavenCentral()
maven("https://maven.0mods.team/releases") // Kotlin Extras
maven("https://maven.minecraftforge.net/") // MinecraftForge
maven("https://maven.architectury.dev/") // Architectury API
maven("https://maven.fabricmc.net/") // Loom
maven("https://maven.parchmentmc.org") // Mappings
maven("https://maven.blamejared.com/") // CT
maven("https://modmaven.dev") // JEI
maven("https://maven.tterrag.com/") // CTM
maven("https://repo.spongepowered.org/repository/maven-public/") // Mixins
maven("https://maven.saps.dev/releases") // Kubejs
maven("https://api.modrinth.com/maven") // Modrinth maven for some mods
maven("https://maven.terraformersmc.com/") // Mixin Extras
maven("https://jitpack.io")
flatDir { dir("libs") }
}
dependencies {
minecraft(libs.minecraft)
mappings(loom.layered {
officialMojangMappings()
parchment("org.parchmentmc.data:parchment-${minecraftVersion}:${libs.versions.parchment.get()}@zip")
})
compileOnly(libs.mixin)
compileOnly(libs.mixinextras.common)
forge("net.minecraftforge:forge:${minecraftVersion}-${forgeVersion}")
modImplementation(libs.hollowcore.forge.mcReplace)
equalDepend(libs.mixinextras.forge)
compileOnlyMinecraft(libs.kotlin.stdlib)
compileOnlyMinecraft(libs.kotlin.coroutines)
compileOnlyMinecraft(libs.kotlin.coroutines.jvm)
compileOnlyMinecraft(libs.kotlin.serialization)
compileOnlyMinecraft(libs.kotlin.serialization.json)
modImplementation(libs.jei.mcReplace)
modImplementation(libs.crafttweaker.forge.mcReplace)
modImplementation(libs.jade.forge)
modImplementation(libs.mysticalAgriculture)
modCompileOnly(libs.kubejs.forge)
modRuntimeOnly(libs.cucumber)
prepareHCDeps()
annotationProcessor(libs.mixinextras.common)
annotationProcessor(libs.crafttweaker.annotationProcessor)
}
tasks {
jar {
from(sourceSets["api"].output)
}
compileKotlin {
useDaemonFallbackStrategy = false
compilerOptions.freeCompilerArgs.add("-Xjvm-default=all")
}
processResources {
from(project.sourceSets.main.get().resources)
val replacement = mapOf(
"modId" to modId, "modVersion" to modVersion, "modName" to "modName".fromProperties,
"modCredits" to "modCredits".fromProperties, "modAuthors" to "modAuthors".fromProperties,
"modDesc" to "modDesc".fromProperties, "forgeVersionRange" to forgeVersion.range,
"minecraftVersionRange" to minecraftVersion.mcRange, "loaderVersionRange" to forgeVersion.range,
"modLicense" to "modLicense".fromProperties, "hcVersionRange" to "[$hcVersion,)"
)
filesMatching(listOf("META-INF/mods.toml", "pack.mcmeta", "*.mixins.json")) {
expand(replacement)
}
inputs.properties(replacement)
}
withType<JavaCompile> {
options.encoding = "UTF-8"
options.release = 17
}
task("removeOldJar") {
val f = file("build/libs")
if (f.exists() && f.isDirectory) {
f.listFiles()?.forEach { it.delete() }
}
}
val jt = task<Jar>("apiJar") {
archiveClassifier = "api"
from(sourceSets["api"].output)
dependsOn("removeOldJar")
}
val sourcesAPI = task<Jar>("apiSources") {
archiveClassifier = "api-sources"
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from(sourceSets["api"].allSource)
dependsOn("apiJar")
}
named("sourcesJar").get().dependsOn("apiSources")
artifacts {
archives(jt)
archives(sourcesAPI)
}
}
kotlin {
jvmToolchain(17)
}
yamlang {
targetSourceSets = listOf(sourceSets.main.get())
inputDir = "assets/$modId/lang"
}
val String.fromProperties
get() = project.properties[this].toString()
fun DependencyHandlerScope.prepareHCDeps() {
minecraftRuntimeLibraries(libs.ktoml.core.jvm)
minecraftRuntimeLibraries(libs.imageio.apng)
minecraftRuntimeLibraries(libs.joml)
minecraftRuntimeLibraries(libs.kotgl.matrix)
compileOnlyMinecraft(libs.kool.editor)
compileOnlyMinecraft(libs.kool.editor.model)
compileOnlyMinecraft(libs.kool.core)
minecraftRuntimeLibraries(libs.kotlin.reflect) { exclude("org.jetbrains.kotlin") }
}
fun DependencyHandlerScope.compileOnlyMinecraft(dependency: Any) {
compileOnly(dependency)
minecraftRuntimeLibraries(dependency)
}
fun DependencyHandlerScope.equalDepend(dependency: Any) {
implementation(dependency)
include(dependency)
}
val String.range: String
get() {
val ver = this.split('.')[0]
return "[$ver,)"
}
val String.mcRange: String
get() {
val ver = this.split('.').last()
val buildedVersion = "${this.split('.').first()}.${this.split('.')[1]}.${ver.toInt() + 1}"
return "[$this,$buildedVersion)"
}
val Provider<MinimalExternalModuleDependency>.mcReplace: String
get() {
val group = this.get().module.group
val name = this.get().module.name
val version = this.get().version
return "${group}:${name.replace("mc_version", minecraftVersion)}:$version"
}