Skip to content

Commit 6937e7b

Browse files
committed
Fix asset index handling
1 parent fc8865a commit 6937e7b

File tree

3 files changed

+17
-50
lines changed

3 files changed

+17
-50
lines changed

src/main/java/org/mcphackers/mcp/tasks/TaskDecompile.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ public static Mappings getMappings(Path mappingsPath, ClassStorage storage, Side
205205
return mappings;
206206
}
207207

208-
public static String getLaunchArgs(MCP mcp) {
209-
List<String> args = TaskRun.getLaunchArgs(mcp);
208+
public static String getLaunchArgs(MCP mcp, Side side) {
209+
List<String> args = TaskRun.getLaunchArgs(mcp, side);
210210
for(int i = 0; i < args.size(); i++) {
211211
String arg = args.get(i);
212212
if(arg.contains(" ")) {
@@ -220,7 +220,7 @@ public static String getLaunchArgs(MCP mcp) {
220220
public static void createProject(MCP mcp, Side side, int sourceVersion) throws IOException {
221221
Path proj = MCPPaths.get(mcp, PROJECT, side);
222222
Version version = mcp.getCurrentVersion();
223-
String clientArgs = getLaunchArgs(mcp);
223+
String clientArgs = getLaunchArgs(mcp, side);
224224
Side[] launchSides = side == Side.MERGED ? new Side[]{Side.CLIENT, Side.SERVER} : new Side[]{side};
225225

226226
String projectName = "Minecraft " +

src/main/java/org/mcphackers/mcp/tasks/TaskRun.java

+14-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static org.mcphackers.mcp.MCPPaths.*;
44

55
import java.io.IOException;
6+
import java.net.URL;
67
import java.nio.file.Files;
78
import java.nio.file.Path;
89
import java.nio.file.Paths;
@@ -16,6 +17,7 @@
1617
import org.mcphackers.mcp.MCP;
1718
import org.mcphackers.mcp.MCPPaths;
1819
import org.mcphackers.mcp.tasks.mode.TaskParameter;
20+
import org.mcphackers.mcp.tools.FileUtil;
1921
import org.mcphackers.mcp.tools.OS;
2022
import org.mcphackers.mcp.tools.Util;
2123
import org.mcphackers.mcp.tools.versions.json.Version;
@@ -60,7 +62,7 @@ public void doTask() throws Exception {
6062
args.add(String.join(System.getProperty("path.separator"), classPath));
6163
args.add(main);
6264
if(side == Side.CLIENT) {
63-
args.addAll(getLaunchArgs(mcp));
65+
args.addAll(getLaunchArgs(mcp, side));
6466
Collections.addAll(args, mcp.getOptions().getStringParameter(TaskParameter.GAME_ARGS).split(" "));
6567
}
6668

@@ -92,7 +94,7 @@ public static String getMain(MCP mcp, Version version, Side side) throws IOExcep
9294
* @param mcp
9395
* @return arguments for launching client
9496
*/
95-
public static List<String> getLaunchArgs(MCP mcp) {
97+
public static List<String> getLaunchArgs(MCP mcp, Side side) {
9698
Version ver = mcp.getCurrentVersion();
9799
Arguments args = ver.arguments;
98100
String mcArgs = ver.minecraftArguments;
@@ -107,14 +109,22 @@ public static List<String> getLaunchArgs(MCP mcp) {
107109
argsList.addAll(Arrays.asList(mcArgs.split(" ")));
108110
}
109111

110-
Path gameDir = getMCDir(mcp, mcp.getOptions().side).toAbsolutePath();
112+
Path gameDir = getMCDir(mcp, side).toAbsolutePath();
111113
Path assets = gameDir.resolve("assets");
114+
try {
115+
if(!Files.exists(assets.resolve("indexes/" + ver.assets + ".json"))) {
116+
FileUtil.createDirectories(assets.resolve("indexes"));
117+
Files.copy(FileUtil.openURLStream(new URL(ver.assetIndex.url)), assets.resolve("indexes/" + ver.assets + ".json"));
118+
}
119+
} catch (IOException e) {
120+
e.printStackTrace();
121+
}
112122

113123
for(int i = 0; i < argsList.size(); i++) {
114124
String arg = argsList.get(i);
115125
switch (arg) {
116126

117-
case "${auth_player_name}": arg = "Player094"; break; //Player094 is a free username with no skin
127+
case "${auth_player_name}": arg = "Player"; break; // LaunchWrapper disables skin for this username
118128
case "${auth_session}": arg = "-"; break;
119129
case "${user_properties}": arg = "{}"; break;
120130
case "${version_name}": arg = ver.id; break;

src/main/java/org/mcphackers/mcp/tools/versions/DownloadData.java

-43
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
package org.mcphackers.mcp.tools.versions;
22

33
import java.io.IOException;
4-
import java.net.URL;
54
import java.nio.file.Files;
65
import java.nio.file.Path;
76
import java.util.ArrayList;
87
import java.util.List;
9-
import java.util.Map.Entry;
108

11-
import org.json.JSONObject;
129
import org.mcphackers.mcp.DownloadListener;
1310
import org.mcphackers.mcp.MCP;
1411
import org.mcphackers.mcp.MCPPaths;
@@ -17,7 +14,6 @@
1714
import org.mcphackers.mcp.tools.Util;
1815
import org.mcphackers.mcp.tools.versions.json.Artifact;
1916
import org.mcphackers.mcp.tools.versions.json.AssetIndex;
20-
import org.mcphackers.mcp.tools.versions.json.AssetIndex.Asset;
2117
import org.mcphackers.mcp.tools.versions.json.DependDownload;
2218
import org.mcphackers.mcp.tools.versions.json.Download;
2319
import org.mcphackers.mcp.tools.versions.json.Rule;
@@ -39,7 +35,6 @@ public DownloadEntry(Download dl, Path filePath, boolean verify) {
3935

4036
protected List<DownloadEntry> downloadQueue = new ArrayList<>();
4137
protected AssetIndex assets;
42-
private Path gameDir;
4338
public int totalSize;
4439
public List<DownloadEntry> natives = new ArrayList<>();
4540

@@ -48,7 +43,6 @@ public DownloadData(MCP mcp, Version version) {
4843
}
4944

5045
public DownloadData(Path libraries, Path gameDir, Path client, Path server, Version version) {
51-
this.gameDir = gameDir;
5246
if(version.downloads.client != null && client != null) {
5347
queueDownload(version.downloads.client, client, true); // TODO may want to make verify flag togglable
5448
}
@@ -73,29 +67,6 @@ public DownloadData(Path libraries, Path gameDir, Path client, Path server, Vers
7367
}
7468
}
7569
}
76-
try {
77-
Path assetIndex = gameDir.resolve("assets/indexes/" + version.assets + ".json");
78-
String assetIndexString;
79-
if (!Files.exists(assetIndex) || !version.assetIndex.sha1.equals(Util.getSHA1(assetIndex))) {
80-
assetIndexString = new String(Util.readAllBytes(new URL(version.assetIndex.url).openStream()));
81-
Files.write(assetIndex, assetIndexString.getBytes());
82-
}
83-
else {
84-
assetIndexString = new String(Files.readAllBytes(assetIndex));
85-
}
86-
setAssets(AssetIndex.from(new JSONObject(assetIndexString)));
87-
}
88-
catch (IOException ignored) {}
89-
}
90-
91-
public void setAssets(AssetIndex assets) {
92-
if(this.assets != null) {
93-
return;
94-
}
95-
this.assets = assets;
96-
for(Entry<String, Asset> entry : assets.objects.entrySet()) {
97-
totalSize += entry.getValue().size();
98-
}
9970
}
10071

10172
public DownloadEntry queueDownload(Download dl, Path path, boolean verify) {
@@ -119,20 +90,6 @@ public void performDownload(DownloadListener listener) throws IOException {
11990
FileUtil.downloadFile(dlObj.url, file);
12091
}
12192
}
122-
if(assets != null) {
123-
for(Entry<String, Asset> entry : assets.objects.entrySet()) {
124-
Asset asset = entry.getValue();
125-
String hash = asset.hash.substring(0, 2) + "/" + asset.hash;
126-
String filename = assets.map_to_resources ? "resources/" + entry.getKey() : "assets/objects/" + hash;
127-
Path file = gameDir.resolve(filename);
128-
listener.notify(asset, totalSize);
129-
if(!Files.exists(file)) {
130-
Path parent = file.getParent();
131-
if(parent != null) Files.createDirectories(parent);
132-
FileUtil.downloadFile("http://resources.download.minecraft.net/" + hash, file);
133-
}
134-
}
135-
}
13693
}
13794

13895
public static List<String> getLibraries(Version version) {

0 commit comments

Comments
 (0)