-
Notifications
You must be signed in to change notification settings - Fork 3
/
fabric.html
268 lines (228 loc) · 8.59 KB
/
fabric.html
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
266
267
268
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Fabric Versions</title>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.14.2/styles/default.min.css"
/>
<style>
code {
white-space: pre-wrap;
}
</style>
</head>
<body>
<h1>Makefile Command Line Generator</h1>
<p>
Minecraft Version:
<select
name="versions"
id="versions"
onchange="updateSelection()"
></select>
</p>
<div name="code">
<pre><code class="makefile">build/libs/hscroll-{minecraft_version}-$(BUILD_VERSION).jar: $(SOURCES)
	./gradlew build -Pminecraft_version={minecraft_version} -Pyarn_mappings={yarn_version} -Ploader_version={loader_version} -Pfabric_version={fabric_version} -Pmod_version={minecraft_version}-$(BUILD_VERSION)
</code></pre>
</div>
<br />
<hr />
<p>
Based off
<a href="https://modmuss50.me/fabric.html"
>https://modmuss50.me/fabric.html</a
>
</p>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.14.2/highlight.min.js"></script>
<script
charset="UTF-8"
src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/languages/makefile.min.js"
></script>
<script>
document.addEventListener("DOMContentLoaded", event => {
document.querySelectorAll("pre code").forEach(block => {
hljs.highlightBlock(block)
})
})
</script>
<script>
document.addEventListener(
"DOMContentLoaded",
function () {
//Taken from https://stackoverflow.com/questions/1144783/how-to-replace-all-occurrences-of-a-string-in-javascript
String.prototype.replaceAll = function (search, replacement) {
var target = this
return target.replace(new RegExp(search, "g"), replacement)
}
getJSON(
"https://meta.fabricmc.net/v1/versions/game",
function (data) {
populateVersions(data)
}
)
},
false
)
var mcVersions
function populateVersions(versions) {
var versionList = document.getElementById("versions")
var stable
for (i in versions) {
var version = versions[i]
if (version.stable && stable == null) {
stable = version.version
}
var option = document.createElement("option")
option.text = version.version
versionList.add(option)
}
mcVersions = versions
var urlParams = new URLSearchParams(window.location.search)
if (urlParams.has("version")) {
versionList.value = urlParams.get("version")
} else {
versionList.value = stable
}
load()
}
function updateSelection() {
var versionList = document.getElementById("versions")
insertParam("version", versionList.value)
}
function load() {
var versionList = document.getElementById("versions")
var urlParams = new URLSearchParams(window.location.search)
var version = versionList.value
if (urlParams.has("version")) {
version = urlParams.get("version")
}
getJSON(
"https://meta.fabricmc.net/v1/versions/loader/" + version,
function (data) {
var meta = data[0]
var codeBlocks = Array.from(
document.getElementsByName("code")
)
codeBlocks.map(block => {
block.innerHTML = block.innerHTML.replaceAll(
"{minecraft_version}",
meta.mappings.gameVersion
)
block.innerHTML = block.innerHTML.replaceAll(
"{yarn_version}",
meta.mappings.version
)
block.innerHTML = block.innerHTML.replaceAll(
"{loader_version}",
meta.loader.version
)
})
}
)
var versionUrl =
"https://maven.fabricmc.net/net/fabricmc/fabric/maven-metadata.xml"
var mavenStr = "net.fabricmc:fabric:"
var newApi = true
for (i in mcVersions) {
var vi = mcVersions[i].version
if (vi === "1.14") {
newApi = false
break
}
if (vi === version) {
break
}
}
if (newApi) {
versionUrl =
"https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api/maven-metadata.xml"
mavenStr = "net.fabricmc.fabric-api:fabric-api:"
}
var branch = "1.15"
//TODO make this better
if (version === "1.14.4") {
branch = "1.14"
}
if (version.startsWith("20w")) {
branch = "1.16"
}
findVersion(versionUrl, branch, function (version) {
Array.from(document.getElementsByName("code")).map(block => {
block.innerHTML = block.innerHTML.replaceAll(
"{fabric_version}",
version
)
})
})
}
function findVersion(url, branch, onLoad) {
var xhttp = new XMLHttpRequest()
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
var parser = new DOMParser()
var xmlDoc = parser.parseFromString(
xhttp.responseText,
"text/xml"
)
var versions = xmlDoc.getElementsByTagName("version")
var latestVersion = xmlDoc.getElementsByTagName(
"release"
)[0].childNodes[0].nodeValue
Object.keys(versions).forEach(function (value, number) {
var version = versions[number].childNodes[0].nodeValue
if (version.endsWith(branch)) {
latestVersion =
versions[number].childNodes[0].nodeValue
}
// console.log(versions[number].childNodes[0].nodeValue)
})
onLoad(latestVersion)
}
}
//Get around caching issues
var milliseconds = new Date().getTime()
url += "?t=" + milliseconds
xhttp.open("GET", url, true)
xhttp.send()
}
function getJSON(url, callback) {
var xhr = new XMLHttpRequest()
xhr.open("GET", url, true)
xhr.responseType = "json"
xhr.onload = function () {
var status = xhr.status
if (status === 200) {
callback(xhr.response)
} else {
console.log("Something went wrong: " + status)
}
}
xhr.send()
}
//Thanks https://stackoverflow.com/questions/486896/adding-a-parameter-to-the-url-with-javascript
function insertParam(key, value) {
key = encodeURI(key)
value = encodeURI(value)
var kvp = document.location.search.substr(1).split("&")
var i = kvp.length
var x
while (i--) {
x = kvp[i].split("=")
if (x[0] == key) {
x[1] = value
kvp[i] = x.join("=")
break
}
}
if (i < 0) {
kvp[kvp.length] = [key, value].join("=")
}
//this will reload the page, it's likely better to store this until finished
document.location.search = kvp.join("&")
}
</script>
</html>