-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
243 lines (205 loc) · 8.04 KB
/
build.gradle.kts
File metadata and controls
243 lines (205 loc) · 8.04 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
plugins {
kotlin("jvm")
kotlin("plugin.serialization")
id("dev.isxander.modstitch.base") version "0.7.0-unstable"
id("fabric-loom") version "1.14.6" apply false
id("me.modmuss50.mod-publish-plugin")
id("me.fallenbreath.yamlang") version "1.5.0"
}
fun prop(name: String) : String {
return findProperty(name)?.toString() ?: throw IllegalArgumentException("Missing property: $name")
}
fun ifFindProperty(name: String, consumer: (prop: String) -> Unit) {
(findProperty(name) as? String?)
?.let(consumer)
}
// Variables
class ModData {
val id = prop("mod.id")
val name = prop("mod.name")
val version = prop("mod.version")
val group = prop("mod.group")
}
val mod = ModData()
val minecraft = stonecutter.current.project.substringBeforeLast('-')
val minecraftVersionRange = prop("mod.mc_version_range")
// See https://stonecutter.kikugie.dev/stonecutter/guide/comments#condition-constants
val loader: String = name.split("-")[1]
stonecutter {
constants {
match(loader, "fabric", "neoforge", "forge")
put("do-a-barrel-roll", hasProperty("deps.dabr"))
}
}
base { archivesName.set("${mod.id}-$loader") }
group = mod.group
version = "${mod.version}+mc$minecraft"
tasks.withType<Jar> {
from(rootDir.resolve("LICENSE"))
}
modstitch {
minecraftVersion = minecraft
val j21: Boolean = stonecutter.eval(minecraft, ">=1.20.6")
javaVersion = if (j21) 21 else 17
java {
withSourcesJar()
}
kotlin {
jvmToolchain(if (j21) 21 else 17)
}
// If parchment doesnt exist for a version yet you can safely
// omit the "deps.parchment" property from your versioned gradle.properties
parchment {
ifFindProperty("deps.parchment") { mappingsVersion = it }
}
metadata {
modId = mod.id
modName = mod.name
modVersion = mod.version
fun <K : Any, V : Any> MapProperty<K, V>.populate(block: MapProperty<K, V>.() -> Unit) {
block()
}
val refmapString = ",\"refmap\": \"${mod.id}.refmap.json\""
replacementProperties.populate {
// You can put any other replacement properties/metadata here that
// modstitch doesn't initially support. Some examples below.
put("mc", minecraftVersionRange)
put("fml", if (loader == "neoforge") "1" else "45")
put("mnd", if (loader == "neoforge") "type = \"required\"" else "mandatory = true")
put("refmap", if (loader == "forge") refmapString else "")
}
overwriteProjectVersionAndGroup = false
}
// Fabric Loom (Fabric)
loom {
fabricLoaderVersion = prop("deps.fabric_loader")
// Configure loom like normal in this block.
configureLoom {
@Suppress("UnstableApiUsage")
mixin {
useLegacyMixinAp = false
}
runConfigs.all {
ideConfigGenerated(environment == "client")
runDir("../../run")
}
}
}
// ModDevGradle (NeoForge, Forge, Forgelike)
moddevgradle {
ifFindProperty("deps.forge") { forgeVersion = it }
ifFindProperty("deps.neoforge") { neoForgeVersion = it }
// Configures client and server runs for MDG, it is not done by default
defaultRuns(server = false)
// This block configures the `neoforge` extension that MDG exposes by default,
// you can configure MDG like normal from here
configureNeoForge {
runs.all {
gameDirectory = layout.projectDirectory.dir("../../run")
}
}
}
mixin {
// You do not need to specify mixins in any mods.json/toml file if this is set to
// true, it will automatically be generated.
addMixinsToModManifest = true
configs.register(mod.id) { side = CLIENT }
// Most of the time you wont ever need loader specific mixins.
// If you do, simply make the mixin file and add it like so for the respective loader:
// if (isLoom) configs.register("examplemod-fabric")
// if (isModDevGradleRegular) configs.register("examplemod-neoforge")
// if (isModDevGradleLegacy) configs.register("examplemod-forge")
}
}
// All dependencies should be specified through modstitch's proxy configuration.
// Wondering where the "repositories" block is? Go to "stonecutter.gradle.kts"
// If you want to create proxy configurations for more source sets, such as client source sets,
// use the modstitch.createProxyConfigurations(sourceSets["client"]) function.
dependencies {
modstitchImplementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.9.0")
modstitch.loom {
modstitchModImplementation("net.fabricmc.fabric-api:fabric-api:${property("deps.fapi")}")
modstitchModImplementation("net.fabricmc:fabric-language-kotlin:${property("deps.flk")}+kotlin.2.1.0")
modstitchModImplementation("com.terraformersmc:modmenu:${property("deps.modmenu")}")
}
modstitch.moddevgradle {
modstitchModImplementation("thedarkcolour:kotlinforforge${if (modstitch.isModDevGradleRegular) "-neoforge" else ""}:${property("deps.kff")}")
}
// Anything else in the dependencies block will be used for all platforms.
modstitchModImplementation("dev.architectury:architectury-${loader}:${property("deps.arch_api")}")
modstitchModImplementation("dev.isxander:yet-another-config-lib:${property("deps.yacl")}")
ifFindProperty("deps.dabr") {
val legacyPermsApi: Boolean = loader == "fabric" && stonecutter.eval(minecraft, "<1.21.6")
modstitchModImplementation("nl.enjarai:do-a-barrel-roll:$it") {
if (legacyPermsApi) exclude("me.lucko")
}
if (legacyPermsApi) {
modstitchModImplementation("com.github.Octol1ttle:fabric-permissions-api:v0.2")
}
}
}
yamlang {
targetSourceSets.set(mutableListOf(sourceSets["main"]))
inputDir.set("assets/${mod.id}/lang")
}
// Publishing
publishMods {
val modrinthToken = findProperty("modrinthToken")
val curseforgeToken = findProperty("curseforgeToken")
dryRun = modrinthToken == null || curseforgeToken == null
modstitch.onEnable {
file = modstitch.finalJarTask.flatMap { it.archiveFile }
}
additionalFiles.from(tasks.named<Jar>("sourcesJar").flatMap { it.archiveFile })
displayName = "${mod.name} ${mod.version} for ${loader.replaceFirstChar { it.uppercase() }} ${property("mod.mc_title")}"
version = "${mod.version}+mc$minecraft-$loader"
changelog = rootProject.file("CHANGELOG.md").readText()
type = STABLE
modLoaders.add(loader)
if (loader == "fabric") {
modLoaders.add("quilt")
}
val targets = property("mod.mc_targets").toString().split(' ')
modrinth {
projectId = property("publish.modrinth").toString()
accessToken = modrinthToken.toString()
targets.forEach(minecraftVersions::add)
if (loader == "fabric") {
requires("fabric-language-kotlin")
optional("modmenu")
} else {
requires("kotlin-for-forge")
}
requires("architectury-api")
requires("yacl")
}
curseforge {
projectId = property("publish.curseforge").toString()
accessToken = curseforgeToken.toString()
targets.forEach(minecraftVersions::add)
if (loader == "fabric") {
requires("fabric-language-kotlin")
optional("modmenu")
} else {
requires("kotlin-for-forge")
}
requires("architectury-api")
requires("yacl")
}
}
val buildAndCollect = tasks.register<Copy>("buildAndCollect") {
group = "build"
from(modstitch.finalJarTask.get().archiveFile)
into(rootProject.layout.buildDirectory.file("libs/${project.property("mod.version")}"))
dependsOn("build")
}
if (stonecutter.current.isActive) {
rootProject.tasks.register("buildActive") {
group = "project"
dependsOn(buildAndCollect)
}
rootProject.tasks.register("runActive") {
group = "project"
dependsOn(tasks.named("runClient"))
}
}