generated from FabricMC/fabric-example-mod
-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
build.gradle.kts
265 lines (220 loc) · 8.15 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
import net.fabricmc.loom.task.RemapJarTask
import java.util.*
plugins {
id("dev.architectury.loom")
}
class ModData {
val id = property("mod_id").toString()
val name = property("mod_name").toString()
val version = property("mod_version").toString()
val group = property("mod_group").toString()
val minecraftDependency = property("minecraft_dependency").toString()
val description = property("mod_description").toString()
}
class LoaderData {
private val name = loom.platform.get().name.lowercase()
val isFabric = name == "fabric"
val isForge = name == "forge"
val isNeoForge = name == "neoforge"
fun getVersion() : String? {
return if (isForge) {
property("loader_forge")?.toString()
} else if (isNeoForge) {
property("loader_neoforge")?.toString()
} else if (isFabric) {
property("loader_fabric")?.toString()
} else {
null
}
}
override fun toString(): String {
return name
}
}
class MinecraftVersionData {
private val name = stonecutter.current.version.substringBeforeLast("-")
val needsJava21 = greaterOrEqual("1.20.5")
fun greaterThan(other: String) : Boolean {
return stonecutter.compare(name, other.lowercase()) > 0
}
fun lessThan(other: String) : Boolean {
return stonecutter.compare(name, other.lowercase()) < 0
}
fun greaterOrEqual(other: String) : Boolean {
return stonecutter.compare(name, other.lowercase()) >= 0
}
fun lessOrEqual(other: String) : Boolean {
return stonecutter.compare(name, other.lowercase()) <= 0
}
override fun equals(other: Any?) : Boolean {
return name == other
}
override fun toString(): String {
return name
}
override fun hashCode(): Int {
var result = name.hashCode()
result = 31 * result + needsJava21.hashCode()
return result
}
}
val mod = ModData()
val loader = LoaderData()
val minecraftVersion = MinecraftVersionData()
version = mod.version
group = mod.group
base.archivesName.set("${mod.name}-mc$minecraftVersion-$loader".lowercase(Locale.getDefault()))
repositories {
mavenCentral()
mavenLocal()
maven { url = uri("https://api.modrinth.com/maven") }
maven { url = uri("https://maven.neoforged.net/releases") }
maven { url = uri("https://files.minecraftforge.net/maven/") }
maven { url = uri("https://libraries.minecraft.net/") }
}
dependencies {
// just for IDE not complaining (its already included in the shadow jar of core-${mod_brand})
// + needed for runtime in dev env
implementation(project(":core"))
implementation(project(":loader-core"))
testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.2")
// TODO fix dev env launch
minecraft("com.mojang:minecraft:$minecraftVersion")
// Mappings have to be patched for new neoforge
if (loader.isNeoForge && minecraftVersion.equals("1.20.6")) {
mappings(
loom.layered {
mappings("net.fabricmc:yarn:${property("yarn_mappings")}:v2")
mappings("dev.architectury:yarn-mappings-patch-neoforge:1.20.6+build.4")
}
)
} else if (loader.isNeoForge && minecraftVersion.greaterOrEqual("1.21")) {
mappings(
loom.layered {
mappings("net.fabricmc:yarn:${property("yarn_mappings")}:v2")
mappings("dev.architectury:yarn-mappings-patch-neoforge:1.21+build.4")
}
)
} else {
mappings("net.fabricmc:yarn:${property("yarn_mappings")}:v2")
}
if (loader.isFabric) {
setOf(
"fabric-api-base", // Required by modules below
"fabric-resource-loader-v0", // Required for translatable texts
"fabric-registry-sync-v0", // Required for custom sounds
"fabric-networking-api-v1" // Required by registry sync module
).forEach {
include(modImplementation(fabricApi.module(it, property("fabric_version") as String))!!) // TODO transitive false
}
if (minecraftVersion.lessThan("1.19.2")) {
include(modImplementation(fabricApi.module("fabric-command-api-v1", property("fabric_version") as String))!!) // TODO transitive false
} else {
include(modImplementation(fabricApi.module("fabric-command-api-v2", property("fabric_version") as String))!!) // TODO transitive false
}
// JiJ mixin extras, fabric loader 0.15.7 has it but many people are using older versions
include(implementation(annotationProcessor("io.github.llamalad7:mixinextras-fabric:${property("mixin_extras")}")!!)!!)
}
if (loader.isFabric) {
modImplementation("net.fabricmc:fabric-loader:${loader.getVersion()}")
} else if (loader.isForge) {
"forge"("net.minecraftforge:forge:$minecraftVersion-${loader.getVersion()}")
// For pseudo mixin (compat with Forgified Fabric API)
compileOnly(fabricApi.module("fabric-networking-api-v1", "0.92.2+1.20.1")) // version is not important
implementation(annotationProcessor("io.github.llamalad7:mixinextras-common:${property("mixin_extras")}")!!)
implementation(include("io.github.llamalad7:mixinextras-forge:${property("mixin_extras")}")!!)
} else if (loader.isNeoForge) {
// For pseudo mixin (compat with Forgified Fabric API)
compileOnly(fabricApi.module("fabric-networking-api-v1", "0.92.2+1.20.1")) // version is not important
"neoForge"("net.neoforged:neoforge:${loader.getVersion()}")
// Bundle mixin extras to 1.20.2 since it has too old version of it
if (minecraftVersion.equals("1.20.2")) {
implementation(include("io.github.llamalad7:mixinextras-neoforge:${property("mixin_extras")}")!!)
}
}
}
loom {
runConfigs["client"].apply {
ideConfigGenerated(true)
vmArgs("-Dmixin.debug.export=true")
runDir = "../../run"
}
runConfigs["server"].apply {
ideConfigGenerated(true)
vmArgs("-Dmixin.debug.export=true")
runDir = "../../run"
}
if (loader.isForge) {
forge {
convertAccessWideners = true
mixinConfigs = listOf("automodpack-main.mixins.json")
}
}
accessWidenerPath = file("../../src/main/resources/automodpack.accesswidener")
}
if (stonecutter.current.isActive) {
rootProject.tasks.register("buildActive") {
group = "project"
dependsOn(tasks.named("build"))
}
}
tasks.processResources {
val map = mapOf(
"id" to mod.id,
"name" to mod.name,
"version" to mod.version,
"minecraft_dependency" to mod.minecraftDependency,
"description" to mod.description
)
inputs.properties(map)
if (loader.isFabric) {
exclude("META-INF/neoforge.mods.toml")
exclude("META-INF/mods.toml")
filesMatching("fabric.mod.json") {
expand(map)
}
} else if (loader.isNeoForge) {
exclude("fabric.mod.json")
exclude("META-INF/mods.toml")
filesMatching("META-INF/neoforge.mods.toml") {
expand(map)
}
} else if (loader.isForge) {
exclude("fabric.mod.json")
exclude("META-INF/neoforge-mods.toml")
filesMatching("META-INF/mods.toml") {
expand(map)
}
}
if (loader.isForge || loader.isNeoForge) {
filesMatching("assets/automodpack/icon.png") {
path = "icon.png"
}
}
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from("../../src/main/resources") {
include("META-INF/services/**")
}
}
// If false, build can stuck on remapping
tasks.named<RemapJarTask>("remapJar") {
remapperIsolation.set(true)
}
java {
if (minecraftVersion.needsJava21) {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
} else {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
withSourcesJar()
}
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}
tasks.named<Jar>("jar") {
from(rootProject.file("LICENSE")) {
rename { "${it}_${mod.id}" }
}
}