-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.gradle
More file actions
360 lines (324 loc) · 14.2 KB
/
Copy pathcommon.gradle
File metadata and controls
360 lines (324 loc) · 14.2 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
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
// project.mcVersion is the integer encoding declared in root build.gradle's
// preprocess block. Format: <major:1><minor:2><patch:2>, always 5 digits.
// Mojang dropped the leading "1." at MC 26, but we keep the implicit "1."
// in our encoding so all integers stay 5 digits and comparisons stay
// monotonic 鈥?e.g. MC "26.1" is encoded as 1_26_01 (= 12601), NOT 26_01_00.
final int mcVersion = project.mcVersion
final boolean unobfuscated = mcVersion >= 1_26_00
apply plugin: 'maven-publish'
apply plugin: unobfuscated ? 'net.fabricmc.fabric-loom' : 'net.fabricmc.fabric-loom-remap'
apply plugin: 'com.replaymod.preprocess'
configurations {
// On <1_26_00 (loom-remap mode) CFM-style remap pulls fabric-loader as a transitive
// mod dep, which then double-loads at runtime. Excluding it from modRuntimeOnly
// keeps the dev runtime clean. On 26.1+ Loom never transitively pulls a second
// copy, so no exclude is needed 鈥?and excluding from runtimeClasspath would strip
// KnotClient from :runClient's launch classpath.
if (!unobfuscated) {
modRuntimeOnly.exclude group: 'net.fabricmc', module: 'fabric-loader'
}
}
version = project.mod_version
group = project.maven_group
base {
archivesName = project.archives_base_name
}
repositories {
maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
}
}
JavaVersion JAVA_COMPATIBILITY
if (mcVersion >= 1_26_00) {
JAVA_COMPATIBILITY = JavaVersion.VERSION_25
} else if (mcVersion >= 1_20_05) {
JAVA_COMPATIBILITY = JavaVersion.VERSION_21
} else if (mcVersion >= 1_18_00) {
JAVA_COMPATIBILITY = JavaVersion.VERSION_17
} else {
JAVA_COMPATIBILITY = JavaVersion.VERSION_1_8
}
dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
if (!unobfuscated) {
mappings loom.officialMojangMappings()
}
// from https://github.com/TISUnion/Carpet-TIS-Addition/blob/master/common.gradle#L41-L54
def processDependency = { dep ->
// https://github.com/FabricMC/fabric-loader/issues/783
if (dep instanceof ModuleDependency) {
if (!(dep.group == 'net.fabricmc' && dep.name == 'fabric-loader')) {
dep.exclude group: 'net.fabricmc', module: 'fabric-loader'
}
}
return dep
}
def autoImplementation = { Object... args -> processDependency(unobfuscated ? implementation(*args) : modImplementation(*args)) }
autoImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
autoImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
autoImplementation "maven.modrinth:sodium:${project.sodium_dependency}"
// Annotation-only (CLASS retention). MC 1.21.11+ pulls jspecify in transitively;
// older vanilla doesn't, so declare it compileOnly to keep the @Nullable usages
// consistent across versions without forcing a runtime dependency.
compileOnly "org.jspecify:jspecify:1.0.0"
testImplementation platform("org.junit:junit-bom:5.11.4")
testImplementation "org.junit.jupiter:junit-jupiter"
testRuntimeOnly "org.junit.platform:junit-platform-launcher"
}
test {
useJUnitPlatform()
}
List<String> MIXIN_CONFIG_PATHS = [
"gallium-glowoutline.mixins.json"
]
// Mixin classes whose target class only exists on >=1_26_00 (kept as empty stubs
// in source on older versions). They must be removed from mixins.json on those
// versions because the Mixin loader chokes on entries without a @Mixin annotation.
List<String> STUB_MIXIN_CLASSES_PRE_1_26 = [
"GuiGraphicsExtractorMixin",
"ProjectionMatrixBufferMixin",
"accessor.GameRendererAccessor"
]
// Mirror image: mixin classes that only carry a real @Mixin on <1_26_00. On
// 26.1+ they collapse to empty stubs and would similarly break the loader.
List<String> STUB_MIXIN_CLASSES_FROM_1_26 = [
"GuiGraphicsItemMixin",
"PerspectiveProjectionMatrixBufferMixin",
"CachedPerspectiveProjectionMatrixBufferMixin",
"accessor.GuiRendererAccessor"
]
// Mixins whose target API only matches its <1_21_11 shape 鈥?collapse to empty
// stubs on 1.21.11+. Strip on 1.21.11 AND 26.1.
List<String> STUB_MIXIN_CLASSES_FROM_1_21_11 = [
"ArmedEntityRenderStateMixin"
]
// Mixins/accessors built on the 1.21.9 entity submit-node rendering system
// (SubmitNodeCollector/Storage, FeatureRenderDispatcher) or on 1.21.9-only
// content (shelves). They are real on 1_21_09+ and collapse to empty stubs on
// 1.21.6鈥?.21.8, so the Mixin loader would reject them there. Strip on <1_21_09.
List<String> STUB_MIXIN_CLASSES_PRE_1_21_09 = [
"ShelfRendererMixin",
"ShelfRenderStateMixin",
"accessor.FeatureRenderDispatcherAccessor"
]
// Mixins whose target class only exists on >=1_21_06 (absent on 1.21.5).
// 1.21.6 introduced the GUI deferred render-state system (GuiRenderState,
// GuiItemRenderState, GuiElementRenderState, GuiRenderer, TextureSetup),
// blaze3D buffer/texture classes (Std140Builder, GpuTextureView), and
// projection-matrix buffer classes (PerspectiveProjectionMatrixBuffer,
// CachedPerspectiveProjectionMatrixBuffer). Mixins targeting any of these
// collapse to empty stubs on 1.21.5 and must be stripped from mixins.json.
//
// GuiGraphicsItemMixin is NOT in this list: GuiGraphics exists on 1.21.5 and
// the 1.21.5 //#else branch carries a real @Mixin(GuiGraphics.class) for the
// 1.21.5 GUI glow capture path (immediate-mode tee around the inner
// ItemStackRenderState.render call). It still shows up in
// STUB_MIXIN_CLASSES_FROM_1_26 because 26.1 dropped that path in favor of
// GuiGraphicsExtractorMixin on the deferred render-state.
List<String> STUB_MIXIN_CLASSES_PRE_1_21_06 = [
"accessor.GuiRendererAccessor",
"GuiRendererMixin",
"GuiItemRenderStateMixin",
"GuiItemAtlasMixin",
"PerspectiveProjectionMatrixBufferMixin",
"CachedPerspectiveProjectionMatrixBufferMixin"
]
// Mixins that are real on 1.21.5 and collapse to stubs from 1.21.6 onwards.
// Used for UBO compatibility shims; MC 鈮?.21.6 supports UBOs natively.
List<String> STUB_MIXIN_CLASSES_FROM_1_21_06 = [
"ShaderUboCompatMixin"
]
// Mixins whose target API was introduced in 1.21.5's render-graph rewrite.
// 1.21.4 still uses direct GL calls and has no GlCommandEncoder.
List<String> STUB_MIXIN_CLASSES_PRE_1_21_05 = [
"GlCommandEncoderMixin"
]
// Mixins whose target class was introduced in 1.21.4. 1.21.3 stores hand items
// (rightHandItem/leftHandItem) directly on LivingEntityRenderState as raw
// ItemStacks, so the ArmedEntityRenderState side-channel mixin has no class
// to attach to and is collapsed to an empty stub on this version.
List<String> STUB_MIXIN_CLASSES_PRE_1_21_04 = [
"ArmedEntityRenderStateMixin"
]
// Mixins whose target class was introduced in 1.21.2's rendering rework and is
// absent on 1.21.1. ItemEntityRenderState/ItemFrameRenderState are the entity
// render-state side-channels (1.21.1 renders entities directly, no render state),
// and ShaderManager is the 1.21.2 shader loader (1.21.1 uses ShaderInstance and
// the direct-compile path runs UboRewriter itself). All collapse to empty stubs
// on 1.21.1 and must be stripped from mixins.json.
List<String> STUB_MIXIN_CLASSES_PRE_1_21_02 = [
"ItemEntityRenderStateMixin",
"ItemFrameRenderStateMixin",
"ItemInHandLayerMixin",
"ShaderUboCompatMixin"
]
List<String> ACTIVE_STUB_MIXINS = []
ACTIVE_STUB_MIXINS += unobfuscated ? STUB_MIXIN_CLASSES_FROM_1_26 : STUB_MIXIN_CLASSES_PRE_1_26
if (mcVersion >= 1_21_11) {
ACTIVE_STUB_MIXINS += STUB_MIXIN_CLASSES_FROM_1_21_11
}
if (mcVersion < 1_21_06) {
ACTIVE_STUB_MIXINS += STUB_MIXIN_CLASSES_PRE_1_21_06
}
if (mcVersion < 1_21_05) {
ACTIVE_STUB_MIXINS += STUB_MIXIN_CLASSES_PRE_1_21_05
}
if (mcVersion < 1_21_04) {
ACTIVE_STUB_MIXINS += STUB_MIXIN_CLASSES_PRE_1_21_04
}
if (mcVersion < 1_21_02) {
ACTIVE_STUB_MIXINS += STUB_MIXIN_CLASSES_PRE_1_21_02
}
if (mcVersion >= 1_21_06) {
ACTIVE_STUB_MIXINS += STUB_MIXIN_CLASSES_FROM_1_21_06
}
if (mcVersion < 1_21_09) {
ACTIVE_STUB_MIXINS += STUB_MIXIN_CLASSES_PRE_1_21_09
}
loom {
runConfigs.configureEach {
ideConfigGenerated = true
runDir '../../run'
}
if (!unobfuscated) {
mixin {
useLegacyMixinAp = true
}
}
}
processResources {
inputs.property "version", project.mod_version
// Declare the stub list as an input so changes to it (or to the mcVersion
// gating that picks the list) invalidate the task and re-run the strip.
inputs.property "stubMixins", ACTIVE_STUB_MIXINS
// The Sodium config_api_user entrypoint targets net.caffeinemc.mods.sodium.api.config,
// which is the Sodium 0.8.x configuration API. Sodium 0.6.13 / 0.7.3 (used on
// 1.21.3-1.21.10) don't ship it. On 1.21.1 the entrypoint is NOT emitted even
// though GalliumSodiumConfig is compiled (we have both 0.6 and 0.8 on the compile
// classpath); instead Gallium.onInitializeClient reflectively calls
// ConfigManager.registerConfigEntryPoint() when Sodium 0.8 is detected at runtime.
// This prevents NoClassDefFoundError on Sodium 0.6 (ConfigEntryPoint interface absent).
// Strip on versions without the 0.8 API to keep fabric.mod.json valid; the
// leading comma + interpolation lives in the template.
final String sodiumConfigEntrypoint = (mcVersion >= 1_21_11) ? ''',
"sodium:config_api_user": [
"cn.spectra.gallium.compat.sodium.GalliumSodiumConfig"
]''' : ''
filesMatching("fabric.mod.json") {
expand(
"description": project.mod_description,
"homepage": project.mod_homepage,
"id": project.mod_id,
"name": project.mod_name,
"license": project.mod_license,
"version": project.mod_version,
"minecraft_dependency": project.minecraft_dependency,
"java_version": JAVA_COMPATIBILITY.majorVersion,
"sources": project.mod_sources,
"sodium_config_entrypoint": sodiumConfigEntrypoint
)
}
filesMatching(MIXIN_CONFIG_PATHS) {
filter { s ->
s.replace('{{COMPATIBILITY_LEVEL}}', "JAVA_${JAVA_COMPATIBILITY.majorVersion}")
}
}
// Strip stub mixin entries from mixins.json: their target class doesn't
// exist on this side of the version split, so the source has //#if-gated
// empty stubs that the Mixin loader would reject. Must operate on the
// final resource (after preprocess + filter) to guarantee well-formed
// JSON, hence doLast on processResources.
doLast {
validateStubsListed(destinationDir, MIXIN_CONFIG_PATHS, ACTIVE_STUB_MIXINS)
stripStubMixins(destinationDir, MIXIN_CONFIG_PATHS, ACTIVE_STUB_MIXINS)
}
}
// Sanity check: every stub we expect to strip should actually appear in the mixin config
// pre-strip. If a name in the STUB list is missing, it's almost certainly a typo or a
// rename that drifted between common.gradle and mixins.json 鈥?surface that at build time
// instead of leaving the next reviewer to chase a runtime "unable to find @Mixin" crash.
def validateStubsListed(File destinationDir, List<String> mixinConfigPaths, List<String> stubs) {
if (stubs.isEmpty()) return
def slurper = new groovy.json.JsonSlurper()
for (String name : mixinConfigPaths) {
File f = new File(destinationDir, name)
if (!f.exists()) continue
def parsed = slurper.parse(f, 'UTF-8')
if (!(parsed instanceof Map)) continue
Set<String> declared = new HashSet<>()
for (String key : ['client', 'server', 'mixins']) {
def list = parsed[key]
if (list instanceof List) {
for (def entry : list) {
if (entry != null) declared.add(entry.toString())
}
}
}
def missing = stubs.findAll { !declared.contains(it) }
if (!missing.isEmpty()) {
throw new GradleException(
"STUB_MIXIN_CLASSES list out of sync with ${name}: " +
"missing entries ${missing}. Either remove them from the stub list, " +
"or add a corresponding line to ${name} so the strip pass actually runs.")
}
}
}
def stripStubMixins(File destinationDir, List<String> mixinConfigPaths, List<String> stubs) {
// Parse the file as JSON and rewrite the "client"/"mixins"/"server" lists with stubs
// removed. Previously this was a line-oriented regex pass, which only worked because
// Loom currently emits one entry per line 鈥?any future change to the JSON formatting
// would silently leave stubs in place and crash the Mixin loader at startup.
def slurper = new groovy.json.JsonSlurper()
def stubSet = stubs as Set
def filterList = { Object value ->
if (!(value instanceof List)) return value
return value.findAll { entry -> !stubSet.contains(entry?.toString()) }
}
for (String name : mixinConfigPaths) {
File f = new File(destinationDir, name)
if (!f.exists()) continue
def parsed = slurper.parse(f, 'UTF-8')
if (!(parsed instanceof Map)) continue
boolean changed = false
for (String key : ['client', 'server', 'mixins']) {
if (!parsed.containsKey(key)) continue
def filtered = filterList(parsed[key])
if (filtered != parsed[key]) {
parsed[key] = filtered
changed = true
}
}
if (changed) {
f.setText(groovy.json.JsonOutput.prettyPrint(groovy.json.JsonOutput.toJson(parsed)), 'UTF-8')
}
}
}
tasks.withType(JavaCompile).configureEach {
options.encoding = "UTF-8"
options.release = JAVA_COMPATIBILITY.majorVersion as Integer
options.compilerArgs << "-Xlint:deprecation"
}
java {
sourceCompatibility = JAVA_COMPATIBILITY
targetCompatibility = JAVA_COMPATIBILITY
withSourcesJar()
toolchain {
languageVersion = JavaLanguageVersion.of(JAVA_COMPATIBILITY.majorVersion as Integer)
}
}
jar {
from(rootProject.file('LICENSE')) {
rename { "${it}_${project.archives_base_name}" }
}
}
publishing {
publications {
create('mavenJava', MavenPublication) {
artifactId = base.archivesName.get()
from components.java
}
}
repositories {
}
}