-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
368 lines (306 loc) · 12.4 KB
/
build.gradle.kts
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
363
364
365
366
367
368
/*
* Minecraft Forge, Patchwork Project
* Copyright (c) 2016-2020, 2019-2020
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
import net.fabricmc.lorenztiny.TinyMappingFormat
import org.cadixdev.bombe.type.ObjectType
import org.cadixdev.bombe.type.signature.FieldSignature
import org.cadixdev.lorenz.MappingSet
import org.cadixdev.lorenz.io.srg.tsrg.TSrgMappingFormat
import org.cadixdev.lorenz.model.ClassMapping
import java.nio.file.FileSystems
import java.nio.file.Files
import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream
buildscript {
repositories {
jcenter()
maven {
name = "FabricMC"
url = uri("https://maven.fabricmc.net/")
}
}
dependencies {
classpath("net.fabricmc", "lorenz-tiny", "3.0.0")
}
}
plugins {
id("fabric-loom") version "0.5.43"
id("org.cadixdev.licenser") version "0.5.0"
checkstyle
`maven-publish`
signing
}
group = "net.patchworkmc"
version = "1.0.0-SNAPSHOT"
repositories {
jcenter()
maven {
name = "FabricMC"
url = uri("https://maven.fabricmc.net/")
}
maven {
name = "PatchworkMC"
url = uri("https://dl.bintray.com/patchworkmc/Patchwork-Maven/")
}
maven {
name = "MinecraftForge"
url = uri("https://files.minecraftforge.net/maven/")
}
// For Fabric-ASM
maven {
name = "JitPack"
url = uri("https://jitpack.io/")
}
}
dependencies {
minecraft("net.minecraft", "minecraft", "1.16.4")
mappings(McpMappings("1.16.4", "snapshot", "20201028-1.16.3"))
modImplementation("net.fabricmc", "fabric-loader", "0.10.8")
// Fabric-API
modImplementation("net.fabricmc.fabric-api", "fabric-api", "0.23.2+1.14")
// Annotations
implementation("com.google.code.findbugs", "jsr305", "3.0.2")
val include = mutableSetOf<Dependency>()
// include += implementation("org.ow2.asm", "asm", "7.2")
// include += implementation("org.ow2.asm", "asm-commons", "7.2")
// include += implementation("org.ow2.asm", "asm-tree", "7.2")
// include += implementation("org.ow2.asm", "asm-util", "7.2")
// include += implementation("org.ow2.asm", "asm-analysis", "7.2")
include += implementation("cpw.mods", "modlauncher", "8.0.6")
include += implementation("cpw.mods", "grossjava9hacks", "1.3.+")
include += implementation("net.minecraftforge", "accesstransformers", "2.2.+", classifier = "shadowed")
include += implementation("net.minecraftforge", "eventbus", "3.0.+", classifier = "service")
include += implementation("net.minecraftforge", "forgespi", "3.2.+")
include += implementation("net.minecraftforge", "coremods", "3.0.+")
include += implementation("net.minecraftforge", "unsafe", "0.2.+")
include += implementation("com.electronwill.night-config", "core", "3.6.2")
include += implementation("com.electronwill.night-config", "toml", "3.6.2")
include += implementation("org.jline", "jline", "3.12.+")
include += implementation("org.apache.maven", "maven-artifact", "3.6.0")
include += implementation("net.jodah", "typetools", "0.8.+")
// include += implementation("org.apache.logging.log4j", "log4j-api", "2.11.2")
// include += implementation("org.apache.logging.log4j", "log4j-core", "2.11.2")
include += implementation("net.minecrell", "terminalconsoleappender", "1.2.+")
// include += implementation("net.sf.jopt-simple", "jopt-simple", "5.0.4")
// include += implementation("org.spongepowered", "mixin", "0.8.2")
// include += implementation("com.google.guava", "guava", "21.0")
// include += implementation("com.google.code.gson", "gson", "2.8.0")
// include += implementation("org.lwjgl", "lwjgl", "3.2.2")
// include += implementation("org.lwjgl", "lwjgl-glfw", "3.2.2")
// include += implementation("org.lwjgl", "lwjgl-opengl", "3.2.2")
// include += implementation("org.lwjgl", "lwjgl-stb", "3.2.2")
// Patching
include += modImplementation("com.github.Chocohead", "Fabric-ASM", "v2.1")
include.forEach {
include(it)
}
}
sourceSets {
main {
java.srcDirs(file("src/main/forge"))
java.srcDirs(file("src/main/minecraft"))
}
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
withJavadocJar()
withSourcesJar()
}
minecraft {
accessWidener = file("src/main/resources/crabwork.aw")
}
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
if (JavaVersion.current().isJava9Compatible) {
options.release.set(8)
} else {
sourceCompatibility = "8"
targetCompatibility = "8"
}
}
tasks.withType<Javadoc> {
if (JavaVersion.current().isJava9Compatible) {
(options as StandardJavadocDocletOptions).addBooleanOption("html5", true)
}
}
tasks.withType<AbstractArchiveTask> {
from(file("LICENSE"))
}
tasks.processResources {
filesMatching("fabric.mod.json") {
expand("version" to project.version)
}
}
publishing {
publications {
create<MavenPublication>("mavenJava") {
from(components["java"])
extensions.getByType<SigningExtension>().apply {
if (signatory != null) {
sign(this@create)
}
}
}
}
repositories {
maven {
val releasesRepoUrl = uri("${buildDir}/repos/releases")
val snapshotsRepoUrl = uri("${buildDir}/repos/snapshots")
name = "Project"
url = if (version.toString().endsWith("SNAPSHOT")) snapshotsRepoUrl else releasesRepoUrl
}
}
}
checkstyle {
configFile = file("checkstyle.xml")
toolVersion = "8.38"
}
license {
header = file("HEADER")
include("**/*.java")
}
class McpMappings(private val minecraft: String, private val channel: String, private val mcp: String) :
SelfResolvingDependency {
private val output = file(".gradle/mcp/$version.zip")
private var reason: String? = null
override fun getGroup(): String = "de.oceanlabs"
override fun getName(): String = "mcp_$channel"
override fun getVersion(): String = "$mcp+$minecraft"
override fun contentEquals(dependency: Dependency): Boolean {
return this == dependency
}
override fun copy(): Dependency = McpMappings(minecraft, channel, mcp)
override fun getReason(): String? = reason
override fun because(reason: String?) {
this.reason = reason
}
override fun getBuildDependencies(): TaskDependency = TaskDependency {
setOf()
}
override fun resolve(): MutableSet<File> {
if (!output.exists()) {
output.parentFile.mkdirs()
val intermediaryJar = configurations.detachedConfiguration(
dependencies.create(
"net.fabricmc",
"intermediary",
minecraft,
classifier = "v2"
)
).singleFile
val mcpConfigJar = configurations.detachedConfiguration(
dependencies.create(
"de.oceanlabs.mcp",
"mcp_config",
minecraft
)
).singleFile
val mcpMappingsZip = File.createTempFile(version, ".zip")
mcpMappingsZip.parentFile.mkdirs()
mcpMappingsZip.delete()
uri("https://files.minecraftforge.net/maven/de/oceanlabs/mcp/mcp_$channel/$mcp/mcp_$channel-$mcp.zip").toURL()
.openStream().use { web ->
mcpMappingsZip.outputStream().use { file ->
web.copyTo(file)
}
}
val intermediary = FileSystems.newFileSystem(intermediaryJar.toPath(), null as? ClassLoader?).use {
TinyMappingFormat.DETECT.read(it.getPath("mappings", "mappings.tiny"), "intermediary", "official")
}
val mcpConfig = FileSystems.newFileSystem(mcpConfigJar.toPath(), null as? ClassLoader?).use {
TSrgMappingFormat().read(it.getPath("config", "joined.tsrg"))
}
val (fields, methods) = FileSystems.newFileSystem(mcpMappingsZip.toPath(), null as? ClassLoader?)
.use { fs ->
val fields = Files.readAllLines(fs.getPath("fields.csv"))
.filter { it.isNotEmpty() }
.map { it.split(",") } // Technically we should use a CSV parser...
.map { (getSrgId(it[0]) ?: return@map null) to it[1] }
.filterNotNull()
.toMap()
val methods = Files.readAllLines(fs.getPath("methods.csv"))
.filter { it.isNotEmpty() }
.map { it.split(",") } // Technically we should use a CSV parser...
.map { (getSrgId(it[0]) ?: return@map null) to it[1] }
.filterNotNull()
.toMap()
fields to methods
}
// Combine MCPConfig with the fields and methods
mcpConfig.iterate {
for (fieldMapping in it.fieldMappings) {
getSrgId(fieldMapping.deobfuscatedName)?.let { id -> fields[id] }?.also { name ->
fieldMapping.deobfuscatedName = name
}
}
for (methodMapping in it.methodMappings) {
getSrgId(methodMapping.deobfuscatedName)?.let { id -> methods[id] }?.also { name ->
methodMapping.deobfuscatedName = name
}
}
}
ZipOutputStream(output.outputStream()).use {
it.putNextEntry(ZipEntry("mappings/"))
it.closeEntry()
it.putNextEntry(ZipEntry("mappings/mappings.tiny"))
it.bufferedWriter().use { writer ->
TinyMappingFormat.STANDARD.createWriter(
writer,
"intermediary",
"named"
).write(intermediary.merge(mcpConfig).apply {
// ITS LITERALLY ONE FUCKING FIELD. CHECK IT.
iterate { c ->
for (fieldMapping in c.fieldMappings) {
if (!fieldMapping.signature.type.isPresent) {
FieldSignature::class.java.getDeclaredField("type").apply {
this::class.java.getDeclaredField("modifiers").also { m ->
m.isAccessible = true
m.set(this, 2)
}
isAccessible = true
set(fieldMapping.signature, ObjectType("CONCERN"))
}
}
}
}
})
}
}
}
return mutableSetOf(output)
}
override fun resolve(transitive: Boolean): MutableSet<File> = resolve()
// Technically using the SRG ID is more accurate
private val pattern = Regex(".*_(\\d+)_.*")
private fun getSrgId(name: String): Int? {
return name.replace(pattern, "$1").toIntOrNull()
}
private fun MappingSet.iterate(consumer: (ClassMapping<*, *>) -> Unit) {
for (classMapping in topLevelClassMappings) {
iterate0(classMapping, consumer)
}
}
private fun iterate0(classMapping: ClassMapping<*, *>, consumer: (ClassMapping<*, *>) -> Unit) {
consumer(classMapping)
for (innerClassMapping in classMapping.innerClassMappings) {
iterate0(innerClassMapping, consumer)
}
}
}