forked from TerraFirmaGreg-Team/Core-Modern
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
297 lines (251 loc) · 8.64 KB
/
build.gradle
File metadata and controls
297 lines (251 loc) · 8.64 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
buildscript {
repositories {
// These repositories are only for Gradle plugins
maven { url = 'https://repo.spongepowered.org/repository/maven-public/' }
mavenCentral()
maven {
name = "NeoForged"
url = 'https://maven.neoforged.net/releases'
content {
includeGroup "net.neoforged"
}
}
}
}
plugins {
id 'java'
id 'java-library'
id 'idea'
id 'net.neoforged.moddev.legacyforge' version "${mdg_legacy_version}"
id 'com.diffplug.spotless' version "${spotless_version}"
id "com.github.ManifestClasspath" version "0.1.0-RELEASE"
}
apply from: 'gradle/scripts/repositories.gradle'
apply from: 'gradle/scripts/dependencies.gradle'
apply from: 'gradle/scripts/spotless.gradle'
base {
version = "${mod_version}"
group = "${mod_package}"
archivesName = "${mod_name}-${mod_name_suffix}"
}
idea {
module {
downloadSources = true
downloadJavadoc = true
}
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
mixin {
var refMap = add sourceSets.main, "${mod_id}.refmap.json"
jar.from refMap
config "${mod_id}.mixins.json"
}
sourceSets {
main.resources {
srcDir 'src/main/resources'
srcDir 'src/generated/resources'
}
dev {
java.srcDir("src/dev/java")
resources.srcDir("src/dev/resources")
compileClasspath += sourceSets.main.compileClasspath
runtimeClasspath += sourceSets.main.runtimeClasspath
}
}
// gradle-local.properties should have the following:
// enable_copy_to_instance = true/false -- Whether to copy the output jar to the modpack mods folder whenever core is rebuilt
// instance_path = path -- Path to modpack folder
String instancePath
Boolean enableCopyToInstance
if (project.rootProject.file("gradle-local.properties").exists()) {
Properties localProperties = new Properties()
localProperties.load(project.rootProject.file('gradle-local.properties').newDataInputStream())
instancePath = localProperties.get("instance_path")
enableCopyToInstance = localProperties.getProperty("enable_copy_to_instance")?.toBoolean() ?: false
} else {
instancePath = ""
enableCopyToInstance = false
}
legacyForge {
version = "${minecraft_version}-${forge_version}"
runs {
configureEach {
gameDirectory = project.file('run')
systemProperty 'forge.logging.markers', 'REGISTRIES'
systemProperty 'forge.logging.console.level', 'INFO'
}
client {
client()
ideName = "Client"
sourceSet = sourceSets.dev
gameDirectory = project.file('run/client')
}
client2 {
client()
ideName = "Client2"
sourceSet = sourceSets.dev
programArgument '--username'
programArgument 'Dev2'
gameDirectory = project.file('run/client2')
}
server {
server()
ideName = "Server"
sourceSet = sourceSets.dev
gameDirectory = project.file('run/server')
programArgument '--nogui'
}
data {
data()
ideName = "Data"
gameDirectory = project.file('run/data')
sourceSet = sourceSets.dev
// Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources.
programArguments.addAll "--mod", "$mod_id", "--all"
programArguments.addAll '--output', file('src/generated/resources/').getAbsolutePath()
programArguments.addAll '--existing', file('src/main/resources/').getAbsolutePath()
programArguments.addAll '--existing', file("$instancePath/kubejs").getAbsolutePath()
String[] existingMods = new String[] {
"tfg", "gtceu", "tfc", "firmalife", "species",
"ad_astra", "wan_ancient_beasts", "rnr"
}
for (String mod : existingMods) {
programArguments.addAll '--existing-mod', mod
}
}
}
mods {
"${mod_id}" {
sourceSet sourceSets.main
}
}
}
processResources {
var replaceProperties = [
'mod_id' : "${mod_id}",
'mod_name' : "${mod_name}",
'mod_version' : "${mod_version}",
'mod_description' : "${mod_description}",
'mod_authors' : "${mod_authors}",
'mod_credits' : "${mod_credits}",
'mod_url' : "${mod_url}",
'mod_logo_path' : "${mod_logo_path}",
'minecraft_version' : "${minecraft_version}",
'forge_version' : "${forge_version}",
'forge_version_range' : "${loader_version_range}",
'loader_version_range' : "${loader_version_range}"
]
var filterList = [
'META-INF/mods.toml',
'pack.mcmeta'
]
inputs.properties replaceProperties
duplicatesStrategy = DuplicatesStrategy.INCLUDE
filesMatching(filterList) { fcd ->
fcd.expand(replaceProperties + [project: project])
}
}
processDevResources {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}
tasks.withType(Jar).configureEach {
manifest.attributes([
"Specification-Title" : "${mod_id}",
"Specification-Vendor" : "${mod_authors}",
"Specification-Version" : "1",
"Implementation-Title" : "${mod_name}",
"Implementation-Version" : "${mod_version}",
"Implementation-Vendor" : "${mod_authors}",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
"MixinConfigs" : "${mod_id}.mixins.json"
])
}
tasks.withType(JavaCompile).configureEach {
options.encoding = "UTF-8"
options.compilerArgs << "-Xlint:-removal"
options.compilerArgs << "-Aquiet=true" // Suppress mixin notes
}
// Fix a bug in Species that only shows up when running from dev env
// Compile our patched Species.class, and use it instead of the normal one in the species-3.5.jar.
// Put the result in run/server/mods
tasks.register("patchSpeciesJar", Jar) {
dependsOn compileDevJava
archiveFileName = 'species-3.5.jar'
destinationDirectory = file("run/server/mods")
from({
configurations.compileClasspath
.filter { it.name.contains("species-3.5") }
.collect { zipTree(it) }
}) {
exclude "com/ninni/species/Species.class"
}
from(sourceSets.dev.output.classesDirs) {
include 'com/ninni/species/Species.class'
}
manifest {
attributes(
'MixinConfigs': 'species.mixins.json',
'Specification-Title': 'species',
'Implementation-Title': 'species',
'Implementation-Version': '3.5'
)
}
}
// Prepare server: patch Species, accept EULA, set offline mode
tasks.register("prepareServerDev") {
dependsOn patchSpeciesJar
def serverDir = file("run/server")
def propsFile = file("${serverDir}/server.properties")
outputs.file(propsFile)
doLast {
serverDir.mkdirs()
// Create or patch server.properties to set online-mode=false
if (propsFile.exists()) {
def content = propsFile.text
if (content.contains('online-mode=')) {
content = content.replaceAll(/online-mode=\w+/, 'online-mode=false')
} else {
content += '\nonline-mode=false'
}
propsFile.text = content
} else {
propsFile.text = 'online-mode=false\n'
}
}
}
// Runs Species patch before runServer.
allprojects {
tasks.matching { it.name == "prepareServerRun" }.configureEach {
dependsOn("prepareServerDev")
}
}
if (enableCopyToInstance) {
tasks.register('replaceInstanceJar', Copy) {
String modsDir = file("$instancePath/mods").getAbsolutePath()
// Delete old core
fileTree(modsDir).matching {
include { file ->
file.name ==~ /TerraFirmaGreg-Core-Modern.+/
}
} each { it.delete() }
// Copy new core
copy {
from "${buildDir}/libs"
into modsDir
include "TerraFirmaGreg-Core-Modern-${version}.jar"
}
outputs.cacheIf { false }
}
tasks.withType(Jar).configureEach {
finalizedBy(tasks.named("replaceInstanceJar"))
}
}
configurations.configureEach {
resolutionStrategy {
cacheChangingModulesFor 0, 'seconds'
}
}