-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.neoforge-hacky.gradle.kts
More file actions
271 lines (232 loc) · 9.84 KB
/
Copy pathbuild.neoforge-hacky.gradle.kts
File metadata and controls
271 lines (232 loc) · 9.84 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
/*
* HCsCR is a third-party mod for Minecraft Java Edition
* that allows removing the end crystals faster.
*
* Copyright (c) 2023 Offenderify
* Copyright (c) 2023-2026 VidTu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
// This is the NeoForge loader buildscript. It is processed by the
// Stonecutter multiple times, for each version and each loader. (compiled once)
// Based on ModDevGradle and processes the preparation/complation/building
// of the most of the mod that is not covered by the Stonecutter or Blossom.
// See "build.fabric-intermediary.gradle.kts" for legacy Intermediary Fabric.
// See "build.fabric-mojmap.gradle.kts" for modern Mojmap Fabric.
// See "build.forge.gradle.kts" for Forge.
// See "build.neoforge.gradle.kts" for NeoForge.
// See "stonecutter.gradle.kts" for the Stonecutter configuration.
// See "settings.gradle.kts" for the Gradle configuration.
// NeoForge 1.20.1 is a piece of hacky mess that's basically Forge 1.20.1 with
// a "95% OFF" discount. It is loosely Forge, but not Forge. It uses Forge
// packages, but diverges from (can't keep up with) the (Lex) MCForge 1.20.1.
// I don't know why support this edge case for approximately 6 or 7 users total.
import com.google.gson.Gson
import com.google.gson.JsonElement
import ru.vidtu.hcscr.buildsrc.Strip
// Plugins.
plugins {
id("java")
alias(libs.plugins.blossom)
alias(libs.plugins.moddevgradle.legacy)
}
// Language.
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
toolchain.languageVersion = JavaLanguageVersion.of(17)
}
// Metadata.
group = "ru.vidtu.hcscr"
base.archivesName = "HCsCR"
version = "${version}+${name}"
description = "Remove your end crystals before the server even knows you hit 'em!"
// Define Stonecutter preprocessor variables/constants.
sc {
// Stonecutter constants.
constants["fabric"] = false
constants["forge"] = true // Yes, that's correct for NeoForge 1.20.1.
constants["hacky_neoforge"] = true // And that's extremely correct.
constants["neoforge"] = false // Yes, that's also correct.
// Stonecutter property path.
properties.tags("1.20.1", "neoforge")
// Stonecutter swaps.
swaps["set_screen"] = "$1.setScreen($2);"
swaps["remove_entity"] = "$1.discard();"
}
legacyForge {
// Minecraft and NeoForge.
val neoforge = "${property("loader")}"
require(neoforge.isNotBlank() && neoforge != "null") { "NeoForge (Hacky) version is not provided via 'loader' in ${project}." }
val extractedMinecraft = neoforge.substringBefore('-')
require(extractedMinecraft == "1.20.1") { "NeoForge (Hacky) version '${neoforge}' provides Minecraft ${extractedMinecraft} in ${project}, but we want 1.20.1." }
enable {
// Set the version.
neoForgeVersion = neoforge
// Enable recompilation for CI.
// NOTE: Bin-patching produces uncompilable artifacts for
// NeoForge 1.20.1, at least for HCsCR. Specifically, it
// has issues with anonymous classes in HStonecutter.java.
setDisableRecompilation(false)
}
// Set up runs.
runs {
// Customize the client run.
register("client") {
// Make client.
client()
// Set up debug VM args.
jvmArguments.addAll(rootDir.resolve("dev/args.vm.txt").readLines()
.filter { it.isNotEmpty() && !it.startsWith('#') && ("line.separator" !in it) })
loggingConfigFile = rootDir.resolve("dev/log4j2.xml")
// Set the run dir.
gameDirectory = rootDir.resolve("run")
}
}
// Register source sets for debugging.
mods {
register("hcscr") {
sourceSet(sourceSets["main"])
}
}
}
mixin {
add(sourceSets["main"], "hcscr.mixins.refmap.json")
config("hcscr.mixins.json")
}
// Repositories for dependencies.
repositories {
mavenCentral()
maven("https://maven.neoforged.net/releases/") // NeoForge.
maven("https://maven.minecraftforge.net/") // Forge.
}
// Dependencies.
dependencies {
// Annotations.
compileOnly(libs.jspecify)
compileOnly(libs.jetbrains.annotations)
compileOnly(libs.error.prone.annotations)
// Mixin.
annotationProcessor("${libs.mixin.get()}:processor")
// MixinExtras.
compileOnly(libs.mixinextras)
annotationProcessor(libs.mixinextras)
// Force non-vulnerable Log4J, so that vulnerability scanners don't scream loud.
// It's also cool for our logging config. (see the "dev/log4j2.xml" file)
implementation(libs.log4j) {
exclude("biz.aQute.bnd")
exclude("com.github.spotbugs")
exclude("org.osgi")
}
}
tasks.withType<JavaCompile> {
// Compile with UTF-8.
options.encoding = "UTF-8"
// Set the compiler debug options.
if ("${findProperty("ru.vidtu.hcscr.debug.javac") ?: findProperty("ru.vidtu.hcscr.debug")}".toBoolean()) {
// Enable local variable names, source file names, line numbers, method parameters, and all compiler warnings.
options.compilerArgs.addAll(listOf("-g", "-parameters", "-Xlint:all"))
} else if ("${findProperty("ru.vidtu.hcscr.slim")}".toBoolean()) {
// Enable all compiler warnings.
options.compilerArgs.addAll(listOf("-g:none", "-Xlint:all"))
} else {
// Enable local variable names, source file names, line numbers, and all compiler warnings.
options.compilerArgs.addAll(listOf("-g", "-Xlint:all"))
}
// Set the Java 17 target.
options.release = 17
// Post-process classes. (strip metadata)
if (!"${findProperty("ru.vidtu.hcscr.debug.metadata") ?: findProperty("ru.vidtu.hcscr.debug")}".toBoolean()) {
doLast {
Strip(destinationDirectory.get().asFile, classpath).use { strip ->
destinationDirectory.asFileTree
.filter { it.name != "package-info.class" }
.forEach { strip.stripBytecode(it) }
}
}
}
}
sourceSets.main {
// Add compile-time stub classes.
java.srcDir("src/main/java-compile")
blossom.javaSources {
// Point to root directory.
templates(rootDir.resolve("src/main/java-templates"))
// Expand compile-time variables.
val fallbackProvider = providers.gradleProperty("ru.vidtu.hcscr.debug")
.orElse(provider { "${gradle.taskGraph.allTasks.any { it.name == "runClient" }}" })
property("debugAsserts", providers.gradleProperty("ru.vidtu.hcscr.debug.asserts").orElse(fallbackProvider))
property("debugLogs", providers.gradleProperty("ru.vidtu.hcscr.debug.logs").orElse(fallbackProvider))
property("debugProfiler", providers.gradleProperty("ru.vidtu.hcscr.debug.profiler").orElse(fallbackProvider))
property("version", "${version}")
property("minecraft", "1.20.1")
}
}
tasks.withType<ProcessResources> {
// Filter with UTF-8.
filteringCharset = "UTF-8"
// Exclude not needed loader entrypoint files.
exclude("fabric.mod.json", "META-INF/neoforge.mods.toml")
// Determine and replace the version range constraints.
val constraints = "${project.property("constraints")}"
require(constraints.isNotBlank() && constraints != "null") { "Constraints are not provided via 'constraints' in ${project}." }
inputs.property("constraints", constraints)
// Expand the updater URL.
inputs.property("forgeUpdaterUrl", "https://raw.githubusercontent.com/VidTu/HCsCR/main/updater_hcscr_neoforge.json")
// Expand version and dependencies.
inputs.property("minecraft", "1.20.1")
inputs.property("mixinJava", 17)
inputs.property("version", version)
inputs.property("platform", "forge") // Yes, that's correct for NeoForge 1.20.1.
filesMatching(listOf("hcscr.mixins.json", "META-INF/mods.toml")) {
expand(inputs.properties)
}
// Minify JSON-alike (including ".mcmeta") and TOML files.
if (!"${findProperty("ru.vidtu.hcscr.debug.resources") ?: findProperty("ru.vidtu.hcscr.debug")}".toBoolean()) {
val files = fileTree(outputs.files.asPath)
doLast {
val jsonAlike = Regex("^.*\\.(?:json|mcmeta)$", RegexOption.IGNORE_CASE)
files.forEach {
if (it.name.matches(jsonAlike)) {
it.writeText(Gson().fromJson(it.readText(), JsonElement::class.java).toString())
} else if (it.name.endsWith(".toml", ignoreCase = true)) {
it.writeText(it.readLines()
.filter { it.isNotEmpty() && !it.startsWith('#') }
.joinToString("\n")
.replace(" = ", "="))
}
}
}
}
}
tasks.withType<Jar> {
// Add LICENSE and NOTICE.
from(rootDir.resolve("LICENSE"))
from(rootDir.resolve("NOTICE"))
// Exclude compile-only code.
exclude("ru/vidtu/hcscr/compile/**")
// Remove package-info.class, unless package debug is on. (to save space)
if (!"${findProperty("ru.vidtu.hcscr.debug.package") ?: findProperty("ru.vidtu.hcscr.debug")}".toBoolean()) {
exclude("**/package-info.class")
}
// Add manifest.
manifest {
attributes("MixinConfigs" to "hcscr.mixins.json")
}
}
// Output into "build/libs" instead of "versions/<ver>/build/libs".
tasks.withType<Jar> {
destinationDirectory = rootProject.layout.buildDirectory.file("libs").get().asFile
}