forked from teaconmc/SlideShow
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.gradle
137 lines (118 loc) · 4.96 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
import groovy.json.JsonSlurper
import org.apache.tools.ant.filters.ReplaceTokens
plugins {
id "architectury-plugin" version "3.4-SNAPSHOT"
id "de.undercouch.download" version "4.1.2"
id "dev.architectury.loom" version "0.12.0-SNAPSHOT" apply false
id "com.github.johnrengelman.shadow" version "7.1.2" apply false
}
def default_minecraft_version = "1.16.5"
def minecraft_version = rootProject.properties.containsKey("buildVersion") ? rootProject.getProperties().get("buildVersion") : default_minecraft_version
def minecraft_main_version = minecraft_version.split("\\.")[1] as int
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"
architectury {
minecraft = minecraft_version
}
subprojects {
apply plugin: "dev.architectury.loom"
apply plugin: "com.github.johnrengelman.shadow"
loom {
silentMojangMappingsLicense()
}
configurations {
shadowCommon
}
dependencies {
minecraft "com.mojang:minecraft:${minecraft_version}"
implementation "org.apache.httpcomponents:httpclient-cache:4.3.6"
shadowCommon "org.apache.httpcomponents:httpclient-cache:4.3.6"
mappings loom.officialMojangMappings()
}
}
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)
download {
src "https://github.com/jonafanho/Minecraft-Mappings/archive/refs/heads/1.${minecraft_main_version}.zip"
dest "common/src/main/java/org/teacon/slides/mappings/mappings.zip"
overwrite true
retries - 1
}
copy {
outputs.upToDateWhen { false }
from(zipTree("common/src/main/java/org/teacon/slides/mappings/mappings.zip")) { eachFile { file -> file.relativePath = new RelativePath(true, file.relativePath.segments.drop(1) as String[]) } }
into "common/src/main/java/org/teacon/slides/mappings"
filter(ReplaceTokens, tokens: ["package": "org.teacon.slides.mappings"])
}
ant.path { ant.fileset(dir: "common/src/main/java/org/teacon/slides/mappings", includes: "Fabric*.java") }.list().each {
ant.move(file: it, todir: "fabric/src/main/java/org/teacon/slides/mappings")
}
ant.path { ant.fileset(dir: "common/src/main/java/org/teacon/slides/mappings", includes: "Forge*.java") }.list().each {
ant.move(file: it, todir: "forge/src/main/java/org/teacon/slides/mappings")
}
if (minecraft_main_version <= 17) {
copy {
outputs.upToDateWhen { false }
from "fabric/src/main/BlockEntityExtensionTemplate.java"
into "fabric/src/main/java/" + (minecraft_main_version == 16 ? "me/shedaniel" : "dev") + "/architectury/extensions"
filter(ReplaceTokens, tokens: ["package": minecraft_main_version == 16 ? "me.shedaniel" : "dev"])
rename "(.+)Template.java", "\$1.java"
}
}
if (minecraft_main_version != 16) {
ant.delete(dir: "fabric/src/main/java/me")
}
if (minecraft_main_version != 17) {
ant.delete(dir: "fabric/src/main/java/dev")
}
copy {
outputs.upToDateWhen { false }
from "common/src/main/RenderUtils${minecraft_main_version == 16 ? "16" : "17"}.java"
into "common/src/main/java/org/teacon/slides/renderer"
rename "(.+)${minecraft_main_version == 16 ? "16" : "17"}.java", "\$1.java"
}
}
allprojects {
apply plugin: "architectury-plugin"
version = minecraft_version + "-" + rootProject.mod_version
group = rootProject.maven_group
repositories {
maven { url = "https://maven.terraformersmc.com/" }
maven { url "https://jitpack.io" }
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
if (minecraft_main_version == 16) {
def targetVersion = 9
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 ""
}