Implement server texture packs
This commit is contained in:
parent
a6958812bb
commit
3459233886
|
@ -1,13 +1,19 @@
|
|||
package net.minecraft.src;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import net.lax1dude.eaglercraft.EaglerProfile;
|
||||
import net.lax1dude.eaglercraft.EPKDecompiler;
|
||||
import net.lax1dude.eaglercraft.EaglerAdapter;
|
||||
import net.lax1dude.eaglercraft.EaglerInputStream;
|
||||
import net.lax1dude.eaglercraft.adapter.teavm.vfs.VFile;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
|
@ -81,26 +87,41 @@ public class TexturePackList
|
|||
var2 = var2.substring(0, var2.indexOf("?"));
|
||||
}
|
||||
|
||||
if (var2.endsWith(".zip"))
|
||||
if (var2.toLowerCase().endsWith(".zip") || var2.toLowerCase().endsWith(".epk"))
|
||||
{
|
||||
VFile var3 = new VFile(this.mpTexturePackFolder, var2);
|
||||
VFile var3 = new VFile(this.mpTexturePackFolder, var2.replaceAll("[^A-Za-z0-9_]", "_"));
|
||||
this.downloadTexture(par1Str, var3);
|
||||
}
|
||||
}
|
||||
|
||||
private void downloadTexture(String par1Str, VFile par2File)
|
||||
{
|
||||
HashMap var3 = new HashMap();
|
||||
GuiProgress var4 = new GuiProgress();
|
||||
var3.put("X-Minecraft-Username", EaglerProfile.username);
|
||||
var3.put("X-Minecraft-Version", "1.5.2");
|
||||
var3.put("X-Minecraft-Supported-Resolutions", "16");
|
||||
this.isDownloading = true;
|
||||
this.mc.displayGuiScreen(var4);
|
||||
// todo: extract epk/zip to VFS, activate, and signal success
|
||||
onDownloadFinished(); // temp
|
||||
// SimpleStorage.set(par2File.replaceAll("[^A-Za-z0-9_]", "_"), par2File.toLowerCase().endsWith(".zip") ? zipToEpk(EaglerAdapter.downloadURL(par1Str)) : EaglerAdapter.downloadURL(par1Str));
|
||||
// HttpUtil.downloadTexturePack(par2File, par1Str, new TexturePackDownloadSuccess(this), var3, 10000000, var4);
|
||||
try {
|
||||
byte[] data = EaglerAdapter.downloadURL(par1Str);
|
||||
if (data == null) throw new IOException("Unable to download texture pack!");
|
||||
if (par2File.getName().toLowerCase().endsWith(".epk")) {
|
||||
EPKDecompiler epkDecompiler = new EPKDecompiler(data);
|
||||
EPKDecompiler.FileEntry file;
|
||||
while ((file = epkDecompiler.readFile()) != null) {
|
||||
new VFile(par2File, file.name).setAllBytes(file.data);
|
||||
}
|
||||
} else {
|
||||
try(ZipInputStream zipInputStream = new ZipInputStream(new ByteArrayInputStream(data))) {
|
||||
ZipEntry entry;
|
||||
while ((entry = zipInputStream.getNextEntry()) != null) {
|
||||
if (entry.isDirectory()) continue;
|
||||
new VFile(par2File, entry.getName()).setAllBytes(EaglerInputStream.inputStreamToBytesNoClose(zipInputStream));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (this.isDownloading) {
|
||||
setSelectedTexturePack(this, new TexturePackFolder(TexturePackList.generateTexturePackID(this, par2File), par2File, defaultTexturePack));
|
||||
this.mc.scheduleTexturePackRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Block a user