From 3459233886f62f08bfe4d0e05398fc93bf1ce736 Mon Sep 17 00:00:00 2001 From: ayunami2000 Date: Fri, 13 Dec 2024 11:42:01 -0500 Subject: [PATCH] Implement server texture packs --- .../net/minecraft/src/TexturePackList.java | 47 ++++++++++++++----- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/minecraft/src/TexturePackList.java b/src/main/java/net/minecraft/src/TexturePackList.java index fc61a3b..c80011d 100644 --- a/src/main/java/net/minecraft/src/TexturePackList.java +++ b/src/main/java/net/minecraft/src/TexturePackList.java @@ -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(); + } } /**