-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle
285 lines (251 loc) · 10.2 KB
/
build.gradle
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
plugins {
id 'java'
// https://github.com/architectury/architectury-loom
id 'dev.architectury.loom' version '1.7-SNAPSHOT' apply false
// https://docs.papermc.io/paper/dev/userdev
id 'io.papermc.paperweight.userdev' version '1.7.4' apply false
// https://github.com/jpenilla/run-task
id 'xyz.jpenilla.run-paper' version '2.3.1' apply false
// https://github.com/Fallen-Breath/yamlang
id 'me.fallenbreath.yamlang' version '1.4.0'
}
repositories {
maven {
url 'https://jitpack.io'
}
maven {
url 'https://www.cursemaven.com'
}
maven {
url = "https://api.modrinth.com/maven"
}
maven {
url 'https://maven.neoforged.net/releases'
}
maven {
name = 'papermc'
url = 'https://repo.papermc.io/repository/maven-public/'
}
}
def use_architectury_loom = project.platform in ['fabric', 'quilt', 'forge', 'neoforge']
def use_paperweight = project.platform in ['paper']
if (use_architectury_loom) {
apply plugin: 'dev.architectury.loom'
}
if (use_paperweight) {
apply plugin: 'io.papermc.paperweight.userdev'
apply plugin: 'xyz.jpenilla.run-paper'
}
static Number convertVersion(String version) {
def parts = version.split('\\.')*.toInteger()
def major = parts[0] * 10000
def minor = parts[1] * 100
def patch = parts.size() > 2 ? parts[2] : 0
return major + minor + patch
}
def mcVersion = convertVersion(project.minecraft_version)
String MOD_ICON_PATH = 'assets/kyoyu/icon.png'
String LANG_DIR = 'assets/kyoyu/lang'
JavaVersion JAVA_COMPATIBILITY
if (mcVersion >= 12005) {
JAVA_COMPATIBILITY = JavaVersion.VERSION_21
} else if (mcVersion >= 11800) {
JAVA_COMPATIBILITY = JavaVersion.VERSION_17
} else if (mcVersion >= 11700) {
JAVA_COMPATIBILITY = JavaVersion.VERSION_16
} else {
JAVA_COMPATIBILITY = JavaVersion.VERSION_1_8
}
JavaVersion MIXIN_COMPATIBILITY_LEVEL = JAVA_COMPATIBILITY
String modVersionSuffix = ''
String artifactVersion = project.mod_version
String artifactVersionSuffix = ''
// 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") {
String buildNumber = System.getenv("BUILD_ID")
modVersionSuffix += buildNumber != null ? ('+build.' + buildNumber) : '-SNAPSHOT'
artifactVersionSuffix = '-SNAPSHOT' // A non-release artifact is always a SNAPSHOT artifact
}
String fullModVersion = project.mod_version + modVersionSuffix
String fullProjectVersion = "v${artifactVersion}-mc${project.minecraft_version}-${project.platform}${modVersionSuffix}"
String fullArtifactVersion = "${artifactVersion}-mc${project.minecraft_version}-${project.platform}${artifactVersionSuffix}"
// Example version values:
// artifactVersion 1.0.3 (the base mod version)
// modVersionSuffix +build.88 (use github action build number if possible)
// artifactVersionSuffix -SNAPSHOT
// fullModVersion 1.0.3+build.88 (the actual mod version to use in the mod)
// fullProjectVersion v1.0.3-mc1.15.2-fabric+build.88 (in build output jar name)
// fullArtifactVersion 1.0.3-mc1.15.2-fabric-SNAPSHOT (maven artifact version)
version = fullProjectVersion
group = project.maven_group
base { archivesName.set("${project.mod_name}") }
stonecutter.const('FABRIC', project.platform == 'fabric')
stonecutter.const('QUILT', project.platform == 'quilt')
stonecutter.const('FORGE', project.platform == 'forge')
stonecutter.const('NEOFORGE', project.platform == 'neoforge')
stonecutter.const('PAPER', project.platform == 'paper')
stonecutter.const('client', project.hasProperty('litematica_version') && project.hasProperty('malilib_version'))
stonecutter.swap("mod_version", "\"${fullArtifactVersion}\";")
if (use_architectury_loom) {
configurations {
modRuntimeOnly.exclude group: 'net.fabricmc', module: 'fabric-loader'
}
}
dependencies {
// loom
if (use_architectury_loom) {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings loom.officialMojangMappings()
// mappings loom.layered {
// mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
//
// // https://github.com/architectury/architectury-loom/issues/214
// if (project.platform == 'neoforge' && project.hasProperty('yarn_mappings_patch')) {
// it.mappings("dev.architectury:yarn-mappings-patch-neoforge:${project.yarn_mappings_patch}")
// }
// }
}
if (use_paperweight) {
paperweight.paperDevBundle("${project.minecraft_version}-R0.1-SNAPSHOT")
}
if (project.platform == 'fabric') {
modImplementation "net.fabricmc:fabric-loader:${project.fabric_loader_version}"
}
if (project.platform == 'forge') {
forge "net.minecraftforge:forge:${project.minecraft_version}-${project.forge_version}"
compileOnly "org.spongepowered:mixin:0.8.5"
}
if (project.platform == 'neoforge') {
neoForge "net.neoforged:neoforge:${project.neoforge_version}"
}
if (project.platform == 'paper') {
compileOnly "io.papermc.paper:paper-api:${project.minecraft_version}-R0.1-SNAPSHOT"
}
if (project.hasProperty('litematica_version')) {
modImplementation "maven.modrinth:litematica:${project.litematica_version}"
}
if (project.hasProperty('malilib_version')) {
modImplementation "maven.modrinth:malilib:${project.malilib_version}"
if (project.platform == 'fabric') {
modImplementation(fabricApi.module("fabric-networking-api-v1", project.fabric_api_version))
modImplementation(fabricApi.module("fabric-resource-loader-v0", project.fabric_api_version))
}
}
implementation("com.google.code.gson:gson:${project.gson_version}")
}
if (use_architectury_loom) {
loom {
def commonVmArgs = ['-Dmixin.debug.export=true', '-Dmixin.debug.countInjections=true']
runConfigs.configureEach {
// to make sure it generates all "Minecraft Client (:subproject_name)" applications
ideConfigGenerated = true
vmArgs commonVmArgs
}
if (project.platform == 'forge') {
forge {
mixinConfigs = ['kyoyu.mixins.json', 'kyoyu.client.mixins.json']
}
}
}
remapJar {
remapperIsolation = true
}
}
processResources {
outputs.upToDateWhen { false }
inputs.property "id", project.mod_id
inputs.property "name", project.mod_name
inputs.property "version", fullModVersion
inputs.property "minecraft_dependency", project.minecraft_dependency
def good_files = [] as Set
def all_files = [] as Set
[
'fabric': ['kyoyu.mixins.json', 'kyoyu.client.mixins.json', 'fabric.mod.json'],
'forge': ['kyoyu.mixins.json', 'kyoyu.client.mixins.json', 'META-INF', 'META-INF/mods.toml', 'pack.mcmeta'],
'neoforge': ['kyoyu.mixins.json', 'kyoyu.client.mixins.json', 'META-INF', 'META-INF/neoforge.mods.toml', 'pack.mcmeta'],
'paper': ['plugin.yml'],
].forEach { brand, paths ->
all_files.addAll(paths)
if (brand == project.platform) {
good_files.addAll(paths)
}
}
all_files.forEach { it2 ->
def path = it2 as String
if (good_files.contains(path)) {
filesMatching(path) {
def valueMap = [
"id": project.mod_id,
"name": project.mod_name,
"version": fullModVersion,
"minecraft_dependency": project.minecraft_dependency,
"description": project.mod_description,
"authors": project.mod_authors,
"homepage": project.mod_homepage,
"sources": project.mod_sources,
"issue": project.mod_issue,
"java_compatibility_level": "JAVA_${MIXIN_COMPATIBILITY_LEVEL.ordinal() + 1}",
]
expand valueMap
}
} else {
exclude path
}
}
if (project.platform in ['forge', 'neoforge']) {
// forge requires the mod icon file to be at the resource root
filesMatching(MOD_ICON_PATH) { f -> f.path = new File(f.path).getName() }
}
}
// https://github.com/Fallen-Breath/yamlang
yamlang {
targetSourceSets = [sourceSets.main]
inputDir = LANG_DIR
}
tasks.withType(JavaCompile).configureEach {
options.encoding = "UTF-8"
options.compilerArgs << "-Xlint:deprecation" << "-Xlint:unchecked"
if (JAVA_COMPATIBILITY <= JavaVersion.VERSION_1_8) {
// suppressed "source/target value 8 is obsolete and will be removed in a future release"
options.compilerArgs << '-Xlint:-options'
}
}
java {
sourceCompatibility = JAVA_COMPATIBILITY
targetCompatibility = JAVA_COMPATIBILITY
// Configure the java toolchain. This allows gradle to auto-provision JDK 21 on systems that only have JDK 11 installed for example.
toolchain.languageVersion = JavaLanguageVersion.of(JAVA_COMPATIBILITY.ordinal() + 1)
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()
}
stonecutter {
java {
withSourcesJar()
sourceCompatibility = JAVA_COMPATIBILITY
targetCompatibility = JAVA_COMPATIBILITY
}
}
jar {
from(rootProject.file('LICENSE')) {
rename { "${it}_${project.archives_base_name}" }
}
}
if (use_paperweight) {
tasks.assemble {
dependsOn(tasks.reobfJar)
}
tasks {
runServer {
dependsOn(tasks.assemble)
minecraftVersion(project.minecraft_version)
}
reobfJar {
// This is an example of how you might change the output location for reobfJar. It's recommended not to do this
// for a variety of reasons, however it's asked frequently enough that an example of how to do it is included here.
outputJar = layout.buildDirectory.file("libs/${project.mod_name}-${fullProjectVersion}.jar")
}
}
}