-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle
179 lines (148 loc) · 6.31 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
import groovy.json.JsonSlurper
import org.apache.tools.ant.filters.ReplaceTokens
plugins {
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "1.1-SNAPSHOT" apply false
id "de.undercouch.download" version "4.1.2"
id "com.github.johnrengelman.shadow" version "7.1.0"
id "base"
}
String default_minecraft_version = "1.19.2"
String minecraft_version = rootProject.properties.containsKey("buildVersion") ? rootProject.getProperties().get("buildVersion") : default_minecraft_version
int minecraft_main_version = minecraft_version.split("\\.")[1] as int
String minecraft_version_int = minecraft_version.split("\\.")[0] +
minecraft_version.split("\\.")[1].padLeft(2, '0') +
(minecraft_version.split("\\.").length > 2 ? minecraft_version.split("\\.")[2].padLeft(2, '0') : "00")
boolean is_1_19_3 = minecraft_version == "1.19.3"
String parchment_version = is_1_19_3 ? "N/A" : new XmlSlurper().parse("https://ldtteam.jfrog.io/artifactory/parchmentmc-internal/org/parchmentmc/data/parchment-${minecraft_version}/maven-metadata.xml").versioning.release
rootProject.ext.fabric_loader_version = new JsonSlurper().parse(("https://meta.fabricmc.net/v2/versions/loader/" + minecraft_version).toURL())[0]["loader"]["version"]
rootProject.ext.forge_version = minecraft_version + "-" + new JsonSlurper().parse(("https://files.minecraftforge.net/net/minecraftforge/forge/promotions_slim.json").toURL())["promos"][minecraft_version + "-latest"]
rootProject.ext.fabric_api_version = getModrinthVersion("fabric", minecraft_version, "fabric-api")
rootProject.ext.mod_menu_version = getModrinthVersion("fabric", minecraft_version, "modmenu")
rootProject.ext.architectury_version = getModrinthVersion("forge", minecraft_version, "architectury-api").split("\\+")[0]
rootProject.ext.architectury_id = minecraft_main_version == 16 ? "me.shedaniel" : "dev.architectury"
architectury {
minecraft = minecraft_version
}
subprojects {
apply plugin: "dev.architectury.loom"
loom {
silentMojangMappingsLicense()
}
configurations {
shadowCommon
}
dependencies {
annotationProcessor 'systems.manifold:manifold-preprocessor:2022.1.29'
minecraft "com.mojang:minecraft:${minecraft_version}"
mappings is_1_19_3 ? loom.officialMojangMappings() : loom.layered() {
officialMojangMappings()
parchment("org.parchmentmc.data:parchment-${minecraft_version}:${parchment_version}@zip")
}
implementation files("../checkouts/mtr-common.jar")
implementation "org.msgpack:msgpack-core:${rootProject.messagepack_version}"
shadowCommon "org.msgpack:msgpack-core:${rootProject.messagepack_version}"
}
}
task setupLibrary() {
doLast {
download {
src "https://www.minecrafttransitrailway.com/libs/${rootProject.mtr_version}/MTR-common-${minecraft_version}-${rootProject.mtr_version}-dev.jar"
dest "checkouts/mtr-common.jar"
overwrite true
}
download {
src "https://www.minecrafttransitrailway.com/libs/${rootProject.mtr_version}/MTR-fabric-${minecraft_version}-${rootProject.mtr_version}-dev-shadow.jar"
dest "checkouts/mtr-fabric.jar"
overwrite true
}
download {
src "https://www.minecrafttransitrailway.com/libs/${rootProject.mtr_version}/MTR-forge-${minecraft_version}-${rootProject.mtr_version}-dev-shadow.jar"
dest "checkouts/mtr-forge.jar"
overwrite true
}
}
}
task setupFiles() {
download {
src "https://github.com/jonafanho/Minecraft-Mappings/archive/refs/heads/1.${minecraft_main_version}${is_1_19_3 ? ".3" : ""}.zip"
dest "common/src/main/java/mtr/mappings/files.zip"
overwrite true
}
copy {
outputs.upToDateWhen { false }
from(zipTree("common/src/main/java/mtr/mappings/files.zip")) { eachFile { file -> file.relativePath = new RelativePath(true, file.relativePath.segments.drop(1) as String[]) } }
into "common/src/main/java/mtr/mappings"
filter(ReplaceTokens, tokens: ["package": "jp.roimu_616.highrails.mappings; import mtr.mappings.*"])
}
ant.path { ant.fileset(dir: "common/src/main/java/mtr/mappings", includes: "Fabric*.java") }.list().each {
ant.move(file: it, todir: "fabric/src/main/java/mtr/mappings")
}
ant.path { ant.fileset(dir: "common/src/main/java/mtr/mappings", includes: "Forge*.java") }.list().each {
ant.move(file: it, todir: "forge/src/main/java/mtr/mappings")
}
ant.delete(dir: "common/src/main/java/mtr/mappings")
copy {
outputs.upToDateWhen { false }
from "checkouts/mtr-fabric.jar"
into "fabric/run/mods"
}
copy {
outputs.upToDateWhen { false }
from "checkouts/mtr-forge.jar"
into "forge/run/mods"
}
copy {
outputs.upToDateWhen { false }
from "common/src/main/BuildConfig.java"
into "common/src/main/java/mtr"
filter(ReplaceTokens, tokens: ["version": minecraft_version + "-" + rootProject.mod_version])
rename "(.+)Template.java", "\$1.java"
}
}
allprojects {
apply plugin: "architectury-plugin"
version = minecraft_version + "-" + project.mod_version
group = project.maven_group
repositories {
maven { url = "https://jitpack.io/" }
maven { url = "https://maven.terraformersmc.com/" }
maven { url = "https://maven.parchmentmc.org/" }
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
if (minecraft_main_version == 16) {
def targetVersion = 8
if (JavaVersion.current().isJava9Compatible()) {
options.release.set(targetVersion)
}
} else if (minecraft_main_version == 17) {
options.release.set(16)
} else {
options.release.set(17)
}
options.compilerArgs += ['-Xplugin:Manifold', '-AMC_VERSION=' + minecraft_version_int]
}
afterEvaluate {
for (def task in it.tasks) {
if (task != rootProject.tasks.setupFiles) {
task.dependsOn rootProject.tasks.setupFiles
}
}
rootProject.tasks.build.dependsOn rootProject.tasks.setupLibrary
}
}
static def getModrinthVersion(loader, minecraftVersion, projectId) {
def versionsArray = new JsonSlurper().parse(("https://api.modrinth.com/v2/project/" + projectId + "/version").toURL())
for (def versionElement : versionsArray) {
if (versionElement["loaders"].contains(loader) && versionElement["game_versions"].contains(minecraftVersion)) {
return versionElement["version_number"]
}
}
return ""
}
static def getParchmentVersion(minecraftVersion) {
def url = "https://ldtteam.jfrog.io/artifactory/parchmentmc-internal/org/parchmentmc/data/parchment-" + minecraftVersion + "/maven-metadata.xml"
def data = new XmlParser().parse(url)
return data.versioning.latest.text()
}