forked from zbx1425/mtr-nte
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
208 lines (167 loc) · 5.97 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
import org.apache.tools.ant.filters.ReplaceTokens
import java.time.Instant
plugins {
id "architectury-plugin" version "+"
id "dev.architectury.loom" version "+" apply false
id "de.undercouch.download" version "4.1.2"
id "com.github.johnrengelman.shadow" version "7.1.0"
id "io.github.pacifistmc.forgix" version "1.2.6"
id "base"
}
apply from: "build_dep_ver.gradle"
rootProject.ext.assetExcludeFont = rootProject.properties.containsKey("assetExcludeFont")
architectury {
minecraft = minecraft_version
}
configure(subprojects.findAll {it.name != 'rhino'}) {
apply plugin: "dev.architectury.loom"
loom {
silentMojangMappingsLicense()
}
configurations {
shadowCommon
}
dependencies {
annotationProcessor 'systems.manifold:manifold-preprocessor:+'
minecraft "com.mojang:minecraft:${minecraft_version}"
mappings parchment_version == "" ? loom.officialMojangMappings() : loom.layered() {
officialMojangMappings()
parchment("org.parchmentmc.data:parchment-${minecraft_version}:${parchment_version}@zip")
}
implementation files("../checkouts/mtr-common.jar")
implementation "org.msgpack:msgpack-core:${rootProject.messagepack_version}"
implementation project(":rhino")
shadowCommon project(":rhino")
}
build.finalizedBy(mergeJars)
assemble.finalizedBy(mergeJars)
}
task setupLibrary() {
doLast {
String baseURL = is_1_20 ? "https://storage.zbx1425.cn/mtr-artifacts/libs/" : "https://www.minecrafttransitrailway.com/libs/"
download {
src "${baseURL}${rootProject.mtr_version}/MTR-common-${minecraft_version}-${rootProject.mtr_version}-dev.jar"
dest "checkouts/mtr-common.jar"
overwrite true
}
download {
src "${baseURL}${rootProject.mtr_version}/MTR-fabric-${minecraft_version}-${rootProject.mtr_version}-dev-shadow.jar"
dest "checkouts/mtr-fabric.jar"
overwrite true
}
download {
src "${baseURL}${rootProject.mtr_version}/MTR-forge-${minecraft_version}-${rootProject.mtr_version}-dev-shadow.jar"
dest "checkouts/mtr-forge.jar"
overwrite true
}
}
String minecraftMappingsBaseURL = "https://github.com/zbx1425/Minecraft-Mappings/archive/refs/heads/"
download {
src "${minecraftMappingsBaseURL}${is_1_19_3 ? minecraft_version : "1." + minecraft_main_version}.zip"
dest "common/src/main/java/cn/zbx1425/mtrsteamloco/mappings/files.zip"
overwrite true
}
copy {
outputs.upToDateWhen { false }
from(zipTree("common/src/main/java/cn/zbx1425/mtrsteamloco/mappings/files.zip")) { eachFile { file -> file.relativePath = new RelativePath(true, file.relativePath.segments.drop(1) as String[]) } }
into "common/src/main/java/cn/zbx1425/mtrsteamloco/mappings"
filter(ReplaceTokens, tokens: ["package": "cn.zbx1425.mtrsteamloco.mappings; import mtr.mappings.*"])
}
ant.path { ant.fileset(dir: "common/src/main/java/cn/zbx1425/mtrsteamloco/mappings", includes: "Fabric*.java") }.list().each {
ant.move(file: it, todir: "fabric/src/main/java/cn/zbx1425/mtrsteamloco/mappings")
}
ant.path { ant.fileset(dir: "common/src/main/java/cn/zbx1425/mtrsteamloco/mappings", includes: "Forge*.java") }.list().each {
ant.move(file: it, todir: "forge/src/main/java/cn/zbx1425/mtrsteamloco/mappings")
}
ant.delete(dir: "common/src/main/java/cn/zbx1425/mtrsteamloco/mappings")
copy {
outputs.upToDateWhen { false }
from "checkouts/mtr-fabric.jar"
into "fabric/run/mods"
}
copy {
outputs.upToDateWhen { false }
from "checkouts/mtr-forge.jar"
into "forge/run/mods"
}
}
task setupFiles() {
copy {
outputs.upToDateWhen { false }
from "common/src/main/BuildConfigTemplate.java"
into "common/src/main/java/cn/zbx1425/mtrsteamloco"
filter(ReplaceTokens, tokens: [
"version": rootProject.mod_version + "+" + minecraft_version,
"protocol_version": rootProject.mod_protocol_version,
"build_time": Instant.now().epochSecond.toString()
])
rename "(.+)Template.java", "\$1.java"
}
}
configure(allprojects.findAll {it.name != 'rhino'}) {
apply plugin: "architectury-plugin"
version = rootProject.mod_version + "+" + minecraft_version
group = project.maven_group
repositories {
maven { url = "https://maven.terraformersmc.com/" }
maven { url = "https://maven.parchmentmc.org/" }
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
if (minecraft_main_version == 16) {
def targetVersion = 8
if (JavaVersion.current().isJava9Compatible()) {
options.release.set(targetVersion)
}
} else if (minecraft_main_version == 17) {
options.release.set(16)
} else {
options.release.set(17)
}
options.compilerArgs += ['-Xplugin:Manifold', '-AMC_VERSION=' + minecraft_version_int]
}
afterEvaluate {
for (def task in it.tasks) {
if (task != rootProject.tasks.setupFiles) {
task.dependsOn rootProject.tasks.setupFiles
}
}
if (System.env.GITHUB_ACTIONS) {
rootProject.tasks.build.dependsOn rootProject.tasks.setupLibrary
}
}
}
forgix {
group = "cn.zbx1425"
mergedJarName = "MTR-NTE" + "-" + rootProject.mod_version + "+" + minecraft_version + ".jar"
outputDir = "build/"
forge {
projectName = "forge"
jarLocation = "build/libs/forge" + "-" + rootProject.mod_version + "+" + minecraft_version + ".jar"
}
fabric {
projectName = "fabric"
jarLocation = "build/libs/fabric" + "-" + rootProject.mod_version + "+" + minecraft_version + ".jar"
}
}
import org.gradle.api.internal.file.copy.CopyAction;
import org.gradle.api.internal.file.copy.CopyActionProcessingStream;
class DummyArchiveTask extends AbstractArchiveTask {
protected CopyAction createCopyAction() {
return new DummyCopyAction();
}
class DummyCopyAction implements CopyAction {
@Override
WorkResult execute(CopyActionProcessingStream stream) {
return WorkResults.didWork(true);
}
}
}
tasks.register('dummyForgixOutput', DummyArchiveTask) {
// Forgix's mergeJars task doesn't extend AbstractArchiveTask.
// This is to make github.com/teaconmc/longjing happy.
destinationDirectory = file("build/")
archiveBaseName = "MTR-NTE"
archiveVersion = rootProject.mod_version + "+" + minecraft_version
archiveExtension = "jar"
}