-
Notifications
You must be signed in to change notification settings - Fork 7
/
build.gradle
165 lines (138 loc) · 6.08 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
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"
}
String default_minecraft_version = "1.16.5"
String minecraft_version = rootProject.properties.containsKey("buildVersion") ? rootProject.getProperties().get("buildVersion") : default_minecraft_version
int minecraft_main_version = minecraft_version.split("\\.")[1] as int
def is_1_19_3 = minecraft_version == "1.19.3" || minecraft_version == "1.19.4"
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.architectury_version = getModrinthVersion("forge", minecraft_version, "architectury-api").split("\\+")[0]
rootProject.ext.architectury_id = minecraft_main_version == 16 ? "me.shedaniel" : "dev.architectury"
rootProject.ext.mod_menu_version = getModrinthVersion("fabric", minecraft_version, "modmenu")
architectury {
minecraft = minecraft_version
}
subprojects {
apply plugin: "dev.architectury.loom"
loom {
silentMojangMappingsLicense()
mixin {
defaultRefmapName.set("msd-refmap.json")
}
}
configurations {
shadowCommon
}
dependencies {
minecraft "com.mojang:minecraft:${minecraft_version}"
mappings loom.officialMojangMappings()
implementation files("../checkouts/mtr-common.jar")
implementation "org.msgpack:msgpack-core:${rootProject.messagepack_version}"
implementation "org.codehaus.groovy:groovy-json:3.0.9"
}
}
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() {
System.out.println("Fabric Loader: " + rootProject.fabric_loader_version)
System.out.println("Forge: " + rootProject.forge_version)
System.out.println("Fabric API: " + rootProject.fabric_api_version)
System.out.println("Architectury: " + rootProject.architectury_version)
System.out.println("Mod Menu: " + rootProject.mod_menu_version)
download {
src "https://github.com/jonafanho/Minecraft-Mappings/archive/refs/heads/${is_1_19_3 ? minecraft_version : "1." + minecraft_main_version}.zip"
dest "common/src/main/java/top/mcmtr/mappings/files.zip"
overwrite true
}
copy {
outputs.upToDateWhen { false }
from(zipTree("common/src/main/java/top/mcmtr/mappings/files.zip")) { eachFile { file -> file.relativePath = new RelativePath(true, file.relativePath.segments.drop(1) as String[]) } }
into "common/src/main/java/top/mcmtr/mappings"
filter(ReplaceTokens, tokens: ["package": "top.mcmtr.mappings; import mtr.mappings.*"])
}
ant.path { ant.fileset(dir: "common/src/main/java/top/mcmtr/mappings", includes: "Fabric*.java") }.list().each {
ant.move(file: it, todir: "fabric/src/main/java/top/mcmtr/mappings")
}
ant.path { ant.fileset(dir: "common/src/main/java/top/mcmtr/mappings", includes: "Forge*.java") }.list().each {
ant.move(file: it, todir: "forge/src/main/java/top/mcmtr/mappings")
}
ant.delete(dir: "common/src/main/java/top/mcmtr/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/latest-msd-addon.json"
into "build/latest"
filter(ReplaceTokens, tokens: ["version": rootProject.mod_version])
}
}
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/" }
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
if (minecraft_main_version == 16) {
def targetVersion = 8
if (JavaVersion.current().isJava9Compatible()) {
options.release = targetVersion
}
} else if (minecraft_main_version == 17) {
options.release = 16
} else {
options.release = 17
}
}
afterEvaluate {
for (def task in it.tasks) {
if (task != rootProject.tasks.setupFiles) {
task.dependsOn rootProject.tasks.setupFiles
}
}
}
}
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 ""
}