diff --git a/src/main/java/net/minecraft/src/GuiTexturePacks.java b/src/main/java/net/minecraft/src/GuiTexturePacks.java index 259ac1a..5156491 100644 --- a/src/main/java/net/minecraft/src/GuiTexturePacks.java +++ b/src/main/java/net/minecraft/src/GuiTexturePacks.java @@ -3,7 +3,6 @@ package net.minecraft.src; import net.lax1dude.eaglercraft.EPKDecompiler; import net.lax1dude.eaglercraft.EaglerAdapter; import net.lax1dude.eaglercraft.EaglerInputStream; -import net.lax1dude.eaglercraft.EaglerMisc; import net.lax1dude.eaglercraft.adapter.teavm.vfs.VFile; import java.io.ByteArrayInputStream; @@ -28,6 +27,8 @@ public class GuiTexturePacks extends GuiScreen { private GuiTexturePackSlot guiTexturePackSlot; private GameSettings field_96146_n; + protected static final VFile texturePackListFile = new VFile("__LIST__"); + public GuiTexturePacks(GuiScreen par1, GameSettings par2) { this.guiScreen = par1; this.field_96146_n = par2; @@ -107,6 +108,11 @@ public class GuiTexturePacks extends GuiScreen { isSelectingPack = false; String name = EaglerAdapter.getFileChooserResultName(); String safeName = name.replaceAll("[^A-Za-z0-9_]", "_"); + if (texturePackListFile.exists()) { + texturePackListFile.setAllChars(texturePackListFile.getAllChars() + "\n" + safeName); + } else { + texturePackListFile.setAllChars(safeName); + } try { if (name.toLowerCase().endsWith(".zip")) { try(ZipInputStream zipInputStream = new ZipInputStream(new ByteArrayInputStream(EaglerAdapter.getFileChooserResult()))) { @@ -138,10 +144,19 @@ public class GuiTexturePacks extends GuiScreen { List var3 = this.mc.texturePackList.availableTexturePacks(); if (par1) { - new VFile(fileLocation, ((ITexturePack) var3.get(par2)).getTexturePackFileName()).deleteAll(); this.mc.texturePackList.setTexturePack((ITexturePack) var3.get(0)); this.mc.renderEngine.refreshTextures(); this.mc.renderGlobal.loadRenderers(); + String safeName = ((ITexturePack) var3.get(par2)).getTexturePackFileName(); + new VFile(fileLocation, safeName).deleteAll(); + if (texturePackListFile.exists()) { + String res = texturePackListFile.getAllChars().replaceFirst(safeName, "").replace("\n\n", "\n"); + if (res.isEmpty()) { + texturePackListFile.delete(); + } else { + texturePackListFile.setAllChars(res); + } + } } else { try { this.mc.texturePackList.setTexturePack((ITexturePack) var3.get(par2)); @@ -152,7 +167,16 @@ public class GuiTexturePacks extends GuiScreen { this.mc.texturePackList.setTexturePack((ITexturePack) var3.get(0)); this.mc.renderEngine.refreshTextures(); this.mc.renderGlobal.loadRenderers(); - new VFile(fileLocation, ((ITexturePack) var3.get(par2)).getTexturePackFileName()).deleteAll(); + String safeName = ((ITexturePack) var3.get(par2)).getTexturePackFileName(); + new VFile(fileLocation, safeName).deleteAll(); + if (texturePackListFile.exists()) { + String res = texturePackListFile.getAllChars().replaceFirst(safeName, "").replace("\n\n", "\n"); + if (res.isEmpty()) { + texturePackListFile.delete(); + } else { + texturePackListFile.setAllChars(res); + } + } } } } diff --git a/src/main/java/net/minecraft/src/TexturePackList.java b/src/main/java/net/minecraft/src/TexturePackList.java index c80011d..475f558 100644 --- a/src/main/java/net/minecraft/src/TexturePackList.java +++ b/src/main/java/net/minecraft/src/TexturePackList.java @@ -53,6 +53,7 @@ public class TexturePackList this.mc = par2Minecraft; this.texturePackDir = new VFile("texturepacks"); this.mpTexturePackFolder = new VFile("texturepacks-mp-cache"); + this.mpTexturePackFolder.deleteAll(); this.updateAvaliableTexturePacks(); } @@ -204,20 +205,12 @@ public class TexturePackList */ private List getTexturePackDirContents() { - // TODO: MAKE THIS MORE EFFICIENT!! THIS IS A TEMPORARY FIX BC IM TIRED - List strings = this.texturePackDir.list(); - List strings2 = new ArrayList<>(); + if (!GuiTexturePacks.texturePackListFile.exists()) return Collections.emptyList(); + String[] lines = GuiTexturePacks.texturePackListFile.getAllLines(); List files = new ArrayList<>(); - for (String name : strings) { - name = name.substring(this.texturePackDir.getPath().length() + 1); - name = name.substring(0, name.indexOf('/')); - name = this.texturePackDir.getPath() + "/" + name; - if (strings2.contains(name)) continue; - strings2.add(name); - files.add(new VFile(name)); + for (String line : lines) { + files.add(new VFile(this.texturePackDir, line)); } - strings2.clear(); - strings.clear(); return files; }