generated from LopyMine/Mossy
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.gradle
253 lines (216 loc) · 7.21 KB
/
build.gradle
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
plugins {
id "fabric-loom" version "1.6-SNAPSHOT"
id "dev.kikugie.j52j" version "1.0.2"
}
def modId = project.mod_id
def modName = project.mod_name
def modVersion = project.mod_version
def modMavenGroup = project.mod_group
def modDescription = project.mod_description
def modAuthors = project.mod_authors
def modLicense = project.mod_license
def minecraftVersion = stonecutter.current.version.toString() // Current MC version from "./versions/" folder
def lombokVersion = project.lombok_version
def fabricLoader = findProperty("build.fabric_loader")
def javaVersionAsInt = getJavaVersionAsInteger(minecraftVersion)
def javaVersion = JavaVersion.toVersion(javaVersionAsInt)
println "Using ${javaVersion.toString()} Java"
def fabricAPI = findProperty("build.fabric_api")
version = "${modVersion}+${stonecutter.current.version}"
group = modMavenGroup
j52j {
sources(sourceSets["main"])
}
base {
archivesName = modName
}
repositories {
maven { url "https://maven.quiltmc.org/repository/release/" } // Stil for YACL
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } // Stil for YACL
maven {
name "Terraformers" // ModMenu
url "https://maven.terraformersmc.com/"
}
maven {
name 'Xander Maven' // YACL
url 'https://maven.isxander.dev/releases'
}
maven {
url "https://maven.nucleoid.xyz/"
name "Nucleoid"
}
// For Mod Menu, because at 1.20.4 it needs PlaceHolder API, see https://github.com/TerraformersMC/ModMenu/issues/752
}
dependencies {
minecraft "com.mojang:minecraft:${minecraftVersion}"
mappings "net.fabricmc:yarn:${findProperty("build.yarn")}:v2"
modImplementation "net.fabricmc:fabric-loader:${fabricLoader}"
// Lombok
compileOnly "org.projectlombok:lombok:${lombokVersion}"
annotationProcessor "org.projectlombok:lombok:${lombokVersion}"
// Fabric API
modImplementation "net.fabricmc.fabric-api:fabric-api:${fabricAPI}"
// Mod Menu
modImplementation "com.terraformersmc:modmenu:${findProperty("dep.modmenu")}"
// YACL
def minecraftVersionsWithOldYACLMaven = Set.of("1.19.4", "1.20", "1.20.2", "1.20.3")
if (minecraftVersionsWithOldYACLMaven.contains(minecraftVersion)) {
def property = findProperty("dep.yacl").toString()
def i = property.lastIndexOf("-")
if (i != -1) {
property = property.substring(0, i)
}
modImplementation "dev.isxander.yacl:yet-another-config-lib-fabric:${property}"
} else {
modImplementation "dev.isxander:yet-another-config-lib:${findProperty("dep.yacl")}"
}
}
loom {
mixin {
defaultRefmapName.set("${modId}.refmap.json")
}
def accessWidenerFile = project.rootProject.file("src/main/resources/aws/${minecraftVersion}.accesswidener")
if (accessWidenerFile.exists()) {
accessWidenerPath = accessWidenerFile
}
def playerProperties = getPlayerProperties()
def playerNicknameProperty = playerProperties.get("player_nickname").toString() // Your in-game nickname
def playerNickname = getNickname(playerNicknameProperty)
def playerUuidProperty = playerProperties.get("player_uuid").toString() // Your in-game uuid
def playerUuid = getUUID(playerUuidProperty, playerUuidProperty.indexOf("-") == -1)
runConfigs.configureEach { config ->
config.setIdeConfigGenerated(true) // generate IDE tasks for running client, server and testmod, datagen if those are present
config.setRunDir("../../runs/${config.environment}") // use a global run directory for all versions
if (config.getEnvironment() == "client") { // setting player properties from "./players/player.properties" file
if (playerNickname != null) {
config.programArgs("--username", playerNickname.toString())
}
if (playerUuid != null) {
config.programArgs("--uuid", playerUuid.toString())
}
}
}
}
processResources {
def props = [:]
props.put("mod_id", modId.toString())
props.put("mod_authors", modAuthors.toString())
props.put("mod_group", modMavenGroup)
props.put("mod_description", modDescription.toString())
props.put("mod_name", modName.toString())
props.put("mod_license", modLicense.toString())
props.put("version", version.toString())
props.put("fabric_loader", fabricLoader.toString())
props.put("minecraft", minecraftVersion.toString())
props.put("java", javaVersionAsInt.toString())
props.put("fabric_api", fabricAPI.toString())
props.put("fabric_api_id", stonecutter.compare("1.19.1", minecraftVersion) >= 0 ? "fabric" : "fabric-api")
props.each { key, value ->
inputs.property key, value
}
filesMatching(["fabric.mod.json"]) {
expand(props)
}
filesMatching("aws/*.accesswidener") {
if (!it.getName().startsWith(minecraftVersion)) {
it.exclude()
}
}
filesMatching("mixins/yacl/*.mixins.json5") {
def fileName = it.getName().toString()
def index = fileName.indexOf('-')
if (index != -1 && fileName.substring(0, index) == minecraftVersion) {
expand(props)
} else {
it.exclude()
}
}
filesMatching("mixins/*.mixins.json5") {
def fileName = it.getName().toString()
def index = fileName.indexOf('-')
if (index != -1 && fileName.substring(0, index) == minecraftVersion) {
expand(props)
} else {
it.exclude()
}
}
}
stonecutter {
swap("mod_version", "\"${findProperty("mod_version")}\";")
swap("mod_id", "\"${findProperty("mod_id")}\";")
swap("mod_name", "\"${findProperty("mod_name")}\";")
def yaclVersion = findProperty("dep.yacl").toString()
swap("yacl_version", "\"${yaclVersion.substring(0, yaclVersion.indexOf("+"))}\";")
}
tasks.withType(JavaCompile).configureEach {
it.options.release = (javaVersionAsInt as int)
}
tasks.register('buildAndCollect', Copy) {
group = 'build'
from(tasks.remapJar.archiveFile)
into(rootProject.layout.buildDirectory.file("libs/"))
dependsOn('build')
}
java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
}
jar {
from("LICENSE") {
rename { "${it}_${project.base.archivesName.get()}" }
}
}
String getNickname(String nickname) {
if (nickname == null) {
return null
}
if (!nickname.matches('^[a-zA-Z0-9_]{2,16}$')) {
println "WARNING — Your nickname is wrong, using default nickname 'Player'"
return "Player"
}
return nickname
}
UUID getUUID(String uuid, boolean undashed) {
if (uuid == null) {
return null
}
try {
if (undashed) {
return UUID.fromString(uuid.replaceFirst("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})", '$1-$2-$3-$4-$5'))
}
return UUID.fromString(uuid)
} catch (Exception e) {
e.printStackTrace()
}
println "WARNING — Your UUID is wrong, failed to parse it"
return null
}
// Cannot be static!
int getJavaVersionAsInteger(String minecraftVersion) {
return stonecutter.compare("1.20.5", minecraftVersion) == 1 ?
stonecutter.compare("1.18", minecraftVersion) == 1 ?
stonecutter.compare("1.17", minecraftVersion) == 1 ?
8
:
16
:
17
:
21
}
Properties getPlayerProperties() {
def properties = new Properties()
def playerPropertiesFile = project.rootProject.file("player/player.properties")
if (playerPropertiesFile.exists()) {
playerPropertiesFile.withInputStream { stream ->
properties.load(stream)
}
} else {
println("Failed to find player properties at ${playerPropertiesFile}")
}
return properties
}