-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathbuild.gradle
More file actions
362 lines (301 loc) · 12.7 KB
/
build.gradle
File metadata and controls
362 lines (301 loc) · 12.7 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
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
/*
* This file is part of the Map Link mod
* licensed under the GNU GPL v3 License.
* (some parts of this file are originally from the Distant Horizons mod by James Seibel)
*
* Copyright (C) 2024 - 2026 Leander Knüttel and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* file changed by: Leander Knüttel
* date: 15.02.2026
*/
plugins {
id "java"
// Plugin to put dependencies inside our final jar
id 'com.gradleup.shadow' version '8.3.6' apply false
// Manifold preprocessor
id "systems.manifold.manifold-gradle-plugin" version "0.0.2-alpha"
id 'dev.architectury.loom' version '1.13-SNAPSHOT' apply false
id 'architectury-plugin' version '3.4-SNAPSHOT'
// Modpublisher: publish to Github, Modrinth and Curseforge in one go
id "com.hypherionmc.modutils.modpublisher" version "2.1.7"
}
/**
* Creates the list of preprocessors to use.
*
* @param mcVers array of all MC versions
* @param mcIndex array index of the currently active MC version
*/
def writeBuildGradlePredefine(List<String> mcVers, int mcIndex)
{
// Build the list of preprocessors to use
StringBuilder sb = new StringBuilder();
sb.append("# DON'T TOUCH THIS FILE, This is handled by the build script\n");
for (int i = 0; i < mcVers.size(); i++)
{
String verStr = mcVers[i].replace(".", "_");
sb.append("MC_" + verStr + "=" + i.toString() + "\n");
if (mcIndex == i)
sb.append("MC_VER=" + i.toString() + "\n");
}
// Check if this is a development build
if (mod_version.toLowerCase().contains("dev"))
{
// WARNING: only use this for logging, we don't want to have confusion
// when a method doesn't work correctly in the release build.
sb.append("DEV_BUILD=\n");
}
new File(projectDir, "build.properties").text = sb.toString()
}
// Transfers the values set in settings.gradle to the rest of the project
project.gradle.ext.getProperties().each { prop ->
rootProject.ext.set(prop.key, prop.value)
}
// Sets up manifold stuff
writeBuildGradlePredefine(rootProject.mcVers, rootProject.mcIndex)
// Sets up the version string (the name we use for our jar)
rootProject.versionStr = rootProject.mod_version + "-" + rootProject.file_name
subprojects { p ->
// Apply plugins
apply plugin: "java"
apply plugin: "com.gradleup.shadow"
apply plugin: "systems.manifold.manifold-gradle-plugin"
apply plugin: "com.hypherionmc.modutils.modpublisher"
apply plugin: 'dev.architectury.loom'
apply plugin: 'architectury-plugin'
// Set the manifold version (may not be required tough)
manifold {
manifoldVersion = rootProject.manifold_version
}
loom {
silentMojangMappingsLicense()
accessWidenerPath = project(":common").file("src/main/resources/${accessWidenerVersion}.${mod_id}.accesswidener")
mixin {
useLegacyMixinAp = false
}
}
dependencies {
annotationProcessor("systems.manifold:manifold-preprocessor:${rootProject.manifold_version}")
minecraft "net.minecraft:minecraft:$rootProject.minecraft_version"
//mappings loom.officialMojangMappings()
mappings loom.layered() {
// Mojmap mappings
officialMojangMappings()
// Parchment mappings (it adds parameter mappings & javadoc)
parchment("org.parchmentmc.data:parchment-${rootProject.parchment_version}@zip")
}
implementation 'com.github.minecraft-dev:annotations:master-SNAPSHOT'
}
// Put stuff from gradle.properties into the mod info
processResources {
def resourceTargets = [ // Location of where to inject the properties
// Properties for each of the loaders
"fabric.mod.json",
"quilt.mod.json",
"META-INF/mods.toml",
"META-INF/neoforge.mods.toml",//for MC >= 1.20.5
"plugin.yml",
"pack.mcmeta",
// The mixins for each of the loaders
rootProject.mod_id + "." + p.name + ".mixins.json"
]
def intoTargets = ["$layout.buildDirectory/resources/main/"] // Location of the built resources folder
// Fix forge version numbering system as it is weird
// For whatever reason forge uses [1.18, 1.18.1, 1.18.2) instead of the standard ["1.18", "1.18.1", "1.18.2"]
def compatible_forgemc_versions = "${compatible_minecraft_versions}".replaceAll("\"", "").replaceAll("]", ",)")
// Quilt's custom contributors system
// This has to be like
// "Person": "Developer", "Another person": "Developer"
def quilt_contributors = []
def mod_author_list = mod_authors.replaceAll("\"", "").replace("[", "").replace("]", "").split(",")
for (dev in mod_author_list) {
quilt_contributors.push("\"${dev.strip()}\": \"Developer\"")
}
quilt_contributors.reverse()
// The left side is what gets replaced in the mod info and the right side is where to get it from in the gradle.properties
def replaceProperties = [
mod_id : mod_id,
version : mod_version,
mod_name : mod_name,
group : maven_group,
authors : mod_authors,
description : mod_description,
homepage : mod_homepage,
source : mod_source,
issues : mod_issues,
mod_license : mod_license,
neoforgeUpdateJSONURL : neoforgeUpdateJSONURL,
forgeUpdateJSONURL : forgeUpdateJSONURL,
minecraft_version : minecraft_version,
compatible_minecraft_versions: compatible_minecraft_versions,
compatible_forgemc_versions : compatible_forgemc_versions,
java_version : java_version,
quilt_contributors : "{"+quilt_contributors.join(", ")+"}",
cloth_config_api_fabric_mod_id: getFabricClothConfigModId(),
cloth_config_api_neoforge_mod_id: getNeoForgeClothConfigModId(),
cloth_config_api_forge_mod_id: getForgeClothConfigModId(),
fabric_incompatibility_list : fabric_incompatibility_list,
fabric_recommend_list : fabric_recommend_list,
]
// replace any properties in the sub-projects with the values defined here
inputs.properties replaceProperties
replaceProperties.put "project", project
filesMatching(resourceTargets) {
expand replaceProperties
}
intoTargets.each { target ->
if (file(target).exists()) {
copy {
from(sourceSets.main.resources) {
include resourceTargets
expand replaceProperties
}
into target
}
}
}
// ==================== Delete un-needed files ====================
// exclude "*.maplink.accesswidener"
//// include "${accessWidenerVersion}.maplink.accesswidener"
// Jank solution to remove all unused accesswideners
// The line above would work..., except that (neo)forge (well, mainly architectury) requires the original accesswidener file, meaning we require this jank solution to keep it
exclude { file ->
if (file.name.contains(".${rootProject.mod_id}.accesswidener") && file.name != "${accessWidenerVersion}.${rootProject.mod_id}.accesswidener") {
return true
}
return false
}
}
}
allprojects { p ->
apply plugin: "java"
apply plugin: "maven-publish"
archivesBaseName = rootProject.mod_id
version = project.name + "-" + rootProject.versionStr
group = rootProject.maven_group
// this is the text that appears at the top of the overview (home) page
// and is used when bookmarking a page
javadoc.title = rootProject.mod_id + "-" + project.name
// Some annotations arent "technically" part of the official java standard,
// so we define it ourself here
javadoc {
configure( options ) {
tags(
'todo:X"',
'apiNote:a:API Note:',
'implSpec:a:Implementation Requirements:',
'implNote:a:Implementation Note:'
)
}
}
repositories {
// The central repo
mavenCentral()
// Used for Google's Collect library
maven { url "https://repo.enonic.com/public/" }
// For parchment mappings
maven { url "https://maven.parchmentmc.org" }
// For Architectury API
maven { url "https://maven.architectury.dev" }
// For Git repositories
maven { url "https://jitpack.io" }
// For Manifold Preprocessor
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
// Required for importing Modrinth mods
maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
content {
includeGroup "maven.modrinth"
}
}
// Required for importing CursedForge mods
maven {
url "https://www.cursemaven.com"
content {
includeGroup "curse.maven"
}
}
// Required for ModMenu
maven { url "https://maven.terraformersmc.com/" }
// Required for ClothConfig
maven { url "https://maven.shedaniel.me/" }
// Required for Mixins & VanillaGradle
maven { url "https://repo.spongepowered.org/maven/" }
// neoforge
maven { url "https://maven.neoforged.net/releases/" }
maven { url "https://maven.neoforged.net/snapshots/" }
maven { url "https://chocolateminecraft.com/maven" }
// These 4 are for importing mods that arnt on CursedForge, Modrinth, GitHub, GitLab or anywhere opensource
flatDir {
dirs "${rootDir}/mods/fabric"
content {
includeGroup "fabric-mod"
}
}
flatDir {
dirs "${rootDir}/mods/quilt"
content {
includeGroup "quilt-mod"
}
}
flatDir {
dirs "${rootDir}/mods/forge"
content {
includeGroup "forge-mod"
}
}
flatDir {
dirs "${rootDir}/mods/neoforge"
content {
includeGroup "neoforge-mod"
}
}
}
tasks.withType(JavaCompile).configureEach {
it.options.release = rootProject.java_version as Integer
it.options.compilerArgs += ["-Xplugin:Manifold"]
it.options.encoding = "UTF-8"
}
tasks.register('copyCommonLoaderResources', Copy) {
from project(":common").file("src/main/resources/${accessWidenerVersion}.${rootProject.mod_id}.accesswidener")
into(file(p.file("build/resources/main")))
rename "${accessWidenerVersion}.${rootProject.mod_id}.accesswidener", "${rootProject.mod_id}.accesswidener"
}
}
def getFabricClothConfigModId(){
if (rootProject.hasProperty("cloth_config_api_fabric_mod_id")){
return cloth_config_api_fabric_mod_id
}
else{
return "cloth-config"
}
}
def getNeoForgeClothConfigModId(){
if (rootProject.hasProperty("cloth_config_api_neoforge_mod_id")){
return cloth_config_api_neoforge_mod_id
}
else{
return "cloth_config"
}
}
def getForgeClothConfigModId(){
if (rootProject.hasProperty("cloth_config_api_forge_mod_id")){
return cloth_config_api_forge_mod_id
}
else{
return "cloth_config"
}
}