-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbuild.gradle.kts
231 lines (195 loc) · 7.02 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
import net.fabricmc.loom.api.mappings.layered.MappingContext
import net.fabricmc.loom.api.mappings.layered.MappingLayer
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace
import net.fabricmc.loom.api.mappings.layered.spec.MappingsSpec
import net.fabricmc.loom.configuration.providers.mappings.intermediary.IntermediaryMappingLayer
import net.fabricmc.loom.configuration.providers.mappings.utils.DstNameFilterMappingVisitor
import net.fabricmc.loom.util.download.DownloadException
import net.fabricmc.mappingio.MappingVisitor
import net.fabricmc.mappingio.adapter.MappingDstNsReorder
import net.fabricmc.mappingio.adapter.MappingSourceNsSwitch
import net.fabricmc.mappingio.format.proguard.ProGuardFileReader
import net.fabricmc.mappingio.tree.MemoryMappingTree
import java.io.IOException
import java.io.UncheckedIOException
import java.nio.file.Files
import java.nio.file.Path
import java.util.regex.Pattern
plugins {
id("fabric-loom") version "1.8.+"
`java-library`
`maven-publish`
}
base.archivesName.set("pridelib")
val minecraftVersion = project.property("minecraft_version") as String
version = project.property("mod_version") as String
group = "io.github.queerbric"
// This field defines the Java version your mod target.
val targetJavaVersion = 21
val testmod: SourceSet by sourceSets.creating {
this.compileClasspath += sourceSets.main.get().compileClasspath
this.runtimeClasspath += sourceSets.main.get().runtimeClasspath
}
loom {
runtimeOnlyLog4j = true
accessWidenerPath = file("src/main/resources/pride.accesswidener")
runs {
register("testmodClient") {
client()
source(testmod)
}
}
}
repositories {
maven {
name = "Gegy"
url = uri("https://maven.gegy.dev/releases/")
}
maven {
name = "ParchmentMC"
url = uri("https://maven.parchmentmc.org")
}
mavenLocal()
}
// Based off Loom, this is required as the releases at the time of writing this buildscript have
// a flaw with the mapping layering preventing the usage of the usual MojangMappingLayer.
@Suppress("UnstableApiUsage")
internal data class MojangMappingLayer(
val clientMappings: Path, val serverMappings: Path, val nameSyntheticMembers: Boolean,
val intermediaryMappings: MemoryMappingTree, val logger: Logger
) : MappingLayer {
@Throws(IOException::class)
override fun visit(mappingVisitor: MappingVisitor) {
val mojmap = MemoryMappingTree()
// Filter out field names matching the pattern
val nameFilter = DstNameFilterMappingVisitor(mojmap, SYNTHETIC_NAME_PATTERN)
// Make official the source namespace
val nsSwitch = MappingSourceNsSwitch(if (nameSyntheticMembers) mojmap else nameFilter, MappingsNamespace.OFFICIAL.toString())
Files.newBufferedReader(clientMappings).use { clientBufferedReader ->
Files.newBufferedReader(serverMappings).use { serverBufferedReader ->
ProGuardFileReader.read(
clientBufferedReader,
MappingsNamespace.NAMED.toString(),
MappingsNamespace.OFFICIAL.toString(),
nsSwitch
)
ProGuardFileReader.read(
serverBufferedReader,
MappingsNamespace.NAMED.toString(),
MappingsNamespace.OFFICIAL.toString(),
nsSwitch
)
}
}
intermediaryMappings.accept(MappingDstNsReorder(mojmap, MappingsNamespace.INTERMEDIARY.toString()))
val switch = MappingSourceNsSwitch(MappingDstNsReorder(mappingVisitor, MappingsNamespace.NAMED.toString()), MappingsNamespace.INTERMEDIARY.toString(), true)
mojmap.accept(switch)
}
override fun getSourceNamespace(): MappingsNamespace {
return MappingsNamespace.INTERMEDIARY
}
override fun dependsOn(): List<Class<out MappingLayer?>> {
return listOf(IntermediaryMappingLayer::class.java)
}
companion object {
private val SYNTHETIC_NAME_PATTERN: Pattern = Pattern.compile("^(access|this|val\\\$this|lambda\\$.*)\\$[0-9]+$")
}
}
@Suppress("UnstableApiUsage")
internal data class MojangMappingsSpec(val nameSyntheticMembers: Boolean) : MappingsSpec<MojangMappingLayer?> {
override fun createLayer(context: MappingContext): MojangMappingLayer {
val versionInfo = context.minecraftProvider().versionInfo
val clientDownload = versionInfo.download(MANIFEST_CLIENT_MAPPINGS)
val serverDownload = versionInfo.download(MANIFEST_SERVER_MAPPINGS)
if (clientDownload == null) {
throw RuntimeException("Failed to find official mojang mappings for " + context.minecraftVersion())
}
val clientMappings = context.workingDirectory("mojang").resolve("client.txt")
val serverMappings = context.workingDirectory("mojang").resolve("server.txt")
try {
context.download(clientDownload.url())
.sha1(clientDownload.sha1())
.downloadPath(clientMappings)
context.download(serverDownload.url())
.sha1(serverDownload.sha1())
.downloadPath(serverMappings)
} catch (e: DownloadException) {
throw UncheckedIOException("Failed to download mappings", e)
}
return MojangMappingLayer(
clientMappings,
serverMappings,
nameSyntheticMembers,
context.intermediaryTree().get(),
context.logger
)
}
companion object {
// Keys in dependency manifest
private const val MANIFEST_CLIENT_MAPPINGS = "client_mappings"
private const val MANIFEST_SERVER_MAPPINGS = "server_mappings"
}
}
dependencies {
minecraft("com.mojang:minecraft:${minecraftVersion}")
@Suppress("UnstableApiUsage")
mappings(loom.layered {
addLayer(MojangMappingsSpec(false))
// Parchment is currently broken when used with the hacked mojmap layer due to remapping shenanigans.
//parchment("org.parchmentmc.data:parchment-${minecraftVersion}:${project.property("parchment_version")}@zip")
mappings("dev.lambdaurora:yalmm:${minecraftVersion}+build.${project.property("yalmm_version")}")
})
modImplementation("net.fabricmc:fabric-loader:${project.property("loader_version")}")
modImplementation(fabricApi.module("fabric-resource-loader-v0", project.property("fabric_api_version") as String))
"testmodImplementation"(sourceSets.main.get().output)
}
java {
sourceCompatibility = JavaVersion.toVersion(targetJavaVersion)
targetCompatibility = JavaVersion.toVersion(targetJavaVersion)
withSourcesJar()
}
tasks.withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
options.release.set(targetJavaVersion)
}
tasks.processResources {
inputs.property("version", project.version)
filesMatching("fabric.mod.json") {
expand("version" to project.version)
}
}
tasks.jar {
from("LICENSE") {
rename { "${it}_${base.archivesName.get()}" }
}
}
// configure the maven publication
publishing {
publications {
create<MavenPublication>("maven") {
from(components["java"])
pom {
name = "Pride Lib"
description = "A unified library for data-driven flags"
}
}
}
repositories {
mavenLocal()
maven {
name = "BuildDirLocal"
url = uri("${layout.buildDirectory.get()}/repo")
}
val prideLibMaven = System.getenv("PRIDELIB_MAVEN")
if (prideLibMaven != null) {
maven {
name = "PrideLibMaven"
url = uri(prideLibMaven)
credentials {
username = (project.findProperty("gpr.user") ?: System.getenv("MAVEN_USERNAME")) as String
password = (project.findProperty("gpr.key") ?: System.getenv("MAVEN_PASSWORD")) as String
}
}
}
}
}