forked from modmuss50/fabric-versions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
269 lines (226 loc) · 9.19 KB
/
index.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
269
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Fabric 版本</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.14.2/styles/default.min.css" />
</head>
<body>
<h1>Fabric 模组开发依赖</h1>
<img alt="Discord" src="https://img.shields.io/discord/507304429255393322.svg?label=discord" />
<img alt="GitHub stars" src="https://img.shields.io/github/stars/FabricMC/yarn.svg?label=Yarn&style=social" />
<img alt="GitHub stars" src="https://img.shields.io/github/stars/FabricMC/fabric.svg?label=Fabric&style=social" />
<p>您可以从此页面来查找 Fabric 模组开发时所用的基本依赖。</p>
<h2>Fabric 依赖版本</h2>
<p>Minecraft 版本: <select name="versions" id="versions" onchange="updateSelection()"> </select> </p>
<p>注意 fabric-api 版本可能并非对应给定 Minecraft 版本. 请查看 <a href="https://minecraft.curseforge.com/projects/fabric/files">CurseForge</a> 页面.</p>
<h3>build.gradle</h3>
<div name="code">
<pre><code class="gradle">dependencies {
minecraft "com.mojang:minecraft:{minecraft_version}"
mappings "net.fabricmc:yarn:{yarn_version}:v2"
modImplementation "net.fabricmc:fabric-loader:{loader_version}"
//Fabric api
modImplementation "{fabric_maven}{fabric_version}"
}</code></pre>
</div>
<h3>gradle.properties (示例模组)</h3>
<div name="code">
<pre><code class="properties">minecraft_version={minecraft_version}
yarn_mappings={yarn_version}
loader_version={loader_version}
#Fabric api
fabric_version={fabric_version}</code></pre>
</div>
<br />
<hr />
<h2>迁移映射表</h2>
<p>映射表可以使用以下命令自动更新. 请查看 <a href="https://fabricmc.net/wiki/tutorial:migratemappings">百科</a> 页面获取帮助.</p>
<div name="code">
<pre><code class="bash">gradlew migrateMappings --mappings "{yarn_version}"</code></pre>
</div>
<hr />
<h2>Fabric-Loom 版本</h2>
<h4>对于 Minecraft 1.18 及以上版本必须 Fabric-Loom <strong>0.10-SNAPSHOT</strong> (不稳定)</h4>
<h4>对于 Minecraft 1.17 及以下版本推荐 Fabric-Loom <strong>0.9-SNAPSHOT</strong></h4>
<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/gradle.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 = document.getElementsByName("code");
for (i in codeBlocks) {
var block = codeBlocks[i];
if (!block.innerHTML) {
continue;
}
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("1.16")) {
branch = "1.16"
}
if (version.startsWith("20w") || version.startsWith("1.17")) {
branch = "1.17"
}
if (version.startsWith("21w") || version.startsWith("1.18")) {
branch = "1.18"
}
if (version === "1.16.1") {
branch = "1.16.1"
}
if (version === "20w14infinite") {
branch = "20w14infinite"
}
findVersion(versionUrl, branch, version,
function (fabricVersion) {
if (!fabricVersion) {
fabricVersion = "unknown"
}
var codeBlocks = document.getElementsByName("code");
for (i in codeBlocks) {
var block = codeBlocks[i];
if (!block.innerHTML) {
continue;
}
block.innerHTML = block.innerHTML.replaceAll("{fabric_version}", fabricVersion);
block.innerHTML = block.innerHTML.replaceAll("{fabric_maven}", mavenStr);
}
})
}
function findVersion(url, branch, mcVersion, 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) || 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>
</body>
</html>