Made a better texture pack implementation

This commit is contained in:
PeytonPlayz595 2024-10-16 14:50:57 -04:00
parent 56087b1dae
commit 52ef44273a
6 changed files with 221 additions and 148 deletions

View File

@ -0,0 +1,71 @@
package net.PeytonPlayz585.util.zip;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import net.PeytonPlayz585.fileutils.File;
import net.PeytonPlayz585.fileutils.FileEntry;
public class ZipFile {
private List<ZipEntry> entries = new ArrayList<ZipEntry>();
private HashMap<String, byte[]> filePool = new HashMap<String, byte[]>();
public ZipFile(ZipInputStream zis) throws IOException {
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
entries.add(entry);
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
byte[] buffer = new byte[(int)entry.getSize()];
int len;
while ((len = zis.read(buffer)) > 0) {
baos.write(buffer, 0, len);
}
byte[] fileData = baos.toByteArray();
filePool.put(entry.getName(), fileData);
}
zis.closeEntry();
}
zis.close();
}
public ZipFile(FileEntry file) throws IOException {
this(new ZipInputStream(new ByteArrayInputStream(File.readFile(file.path))));
}
public ZipEntry getEntry(String name) {
for(int i = 0; i < entries.size(); i++) {
ZipEntry entry = entries.get(i);
if(entry != null) {
if(entry.getName().equals(name)) {
return entry;
}
}
}
return null;
}
public InputStream getInputStream(ZipEntry entry) {
String name = entry.getName();
return new ByteArrayInputStream(filePool.get(name));
}
public void close() {
entries.clear();
filePool.clear();
entries = new ArrayList<ZipEntry>();
filePool = new HashMap<String, byte[]>();
}
}

View File

@ -1,12 +1,11 @@
package net.minecraft.src;
import java.util.List;
import net.PeytonPlayz585.fileutils.File;
import net.PeytonPlayz585.fileutils.FileChooserResult;
import net.PeytonPlayz585.input.Mouse;
import net.PeytonPlayz585.opengl.GL11;
import net.minecraft.client.Minecraft;
import java.util.List;
import org.lwjgl.input.Mouse;
public class GuiTexturePacks extends GuiScreen {
protected GuiScreen field_6461_a;
@ -17,6 +16,7 @@ public class GuiTexturePacks extends GuiScreen {
private int field_6456_m = this.width;
private int field_6455_n = -2;
private int field_6454_o = -1;
private String fileLocation = "texturepacksNEW";
public GuiTexturePacks(GuiScreen var1) {
this.field_6461_a = var1;
@ -35,7 +35,7 @@ public class GuiTexturePacks extends GuiScreen {
protected void actionPerformed(GuiButton var1) {
if(var1.enabled) {
if(var1.id == 5) {
GL11.EaglerAdapterImpl2.displayFileChooser("application/zip", "zip");
GL11.EaglerAdapterImpl2.displayFileChooser("zip", "application/zip");
}
if(var1.id == 6) {
@ -161,6 +161,7 @@ public class GuiTexturePacks extends GuiScreen {
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glDisable(GL11.GL_ALPHA_TEST);
GL11.glShadeModel(GL11.GL_SMOOTH);
GL11.glDisable(GL11.GL_TEXTURE_2D);
var16.startDrawingQuads();
var16.setColorRGBA_I(0, 0);
@ -179,26 +180,29 @@ public class GuiTexturePacks extends GuiScreen {
var16.addVertexWithUV((double)this.field_6457_l, (double)(this.field_6458_j - var18), 0.0D, 0.0D, 0.0D);
var16.draw();
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glShadeModel(GL11.GL_FLAT);
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glDisable(GL11.GL_BLEND);
if(GL11.EaglerAdapterImpl2.fileChooserHasResult()) {
FileChooserResult result = GL11.EaglerAdapterImpl2.getFileChooserResult();
if(result != null) {
File.writeFile(this.fileLocation + "/" + result.fileName, result.fileData);
//Refresh GUI to show newly added texture packs
this.mc.displayGuiScreen(new GuiTexturePacks(this.field_6461_a));
}
}
this.drawCenteredString(this.fontRenderer, "Select Texture Pack", this.width / 2, 16, 16777215);
this.drawCenteredString(this.fontRenderer, "(Upload texture pack files here)", this.width / 2 - 77, this.height - 26, 8421504);
this.drawCenteredString(this.fontRenderer, "(Place texture pack files here)", this.width / 2 - 77, this.height - 26, 8421504);
super.drawScreen(var1, var2, var3);
}
public void updateScreen() {
super.updateScreen();
--this.field_6454_o;
FileChooserResult packFile = null;
if (GL11.EaglerAdapterImpl2.fileChooserHasResult()) {
packFile = GL11.EaglerAdapterImpl2.getFileChooserResult();
}
if(packFile == null) {
return;
}
File.writeFile("texturepacks/" + packFile.fileName, packFile.fileData);
Minecraft.getMinecraft().displayGuiScreen(new GuiTexturePacks(field_6461_a));
}
public void func_6452_a(int var1, int var2, int var3, int var4) {
@ -216,3 +220,4 @@ public class GuiTexturePacks extends GuiScreen {
var5.draw();
}
}

View File

@ -1,6 +1,7 @@
package net.minecraft.src;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.util.ArrayList;
@ -8,6 +9,7 @@ import java.util.HashMap;
import java.util.Iterator;
import net.PeytonPlayz585.awt.image.BufferedImage;
import net.PeytonPlayz585.awt.image.ImageIO;
import net.PeytonPlayz585.opengl.GL11;
public class RenderEngine {
@ -17,7 +19,7 @@ public class RenderEngine {
textureMap = new HashMap<String, Integer>();
textureNameToImageMap = new HashMap<Integer, BufferedImage>();
singleIntBuffer = GLAllocation.createDirectIntBuffer(1);
imageDataB1 = GLAllocation.createDirectByteBuffer(0x100000);
imageDataB1 = GLAllocation.createDirectByteBuffer(1048576);
textureList = new ArrayList<TextureFX>();
clampTexture = false;
blurTexture = false;
@ -140,8 +142,10 @@ public class RenderEngine {
texturefx.func_783_a();
}
public BufferedImage readTextureImage(byte[] inputstream) throws IOException {
return GL11.EaglerAdapterImpl2.loadPNG(inputstream);
private BufferedImage readTextureImage(InputStream var1) throws IOException {
BufferedImage var2 = ImageIO.read(var1);
var1.close();
return var2;
}
public void bindTexture(int i) {

View File

@ -1,8 +1,9 @@
package net.minecraft.src;
import java.io.IOException;
import java.io.InputStream;
import net.PeytonPlayz585.opengl.GL11;
import net.PeytonPlayz585.awt.image.ImageIO;
import net.minecraft.client.Minecraft;
public abstract class TexturePackBase {
@ -26,7 +27,7 @@ public abstract class TexturePackBase {
public void func_6483_c(Minecraft var1) {
}
public byte[] func_6481_a(String s) {
return GL11.EaglerAdapterImpl2.loadResourceBytes(s);
public InputStream func_6481_a(String var1) {
return ImageIO.getResourceAsStream(var1);
}
}

View File

@ -1,56 +1,27 @@
package net.minecraft.src;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collection;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import net.PeytonPlayz585.fileutils.File;
import net.PeytonPlayz585.awt.image.BufferedImage;
import net.PeytonPlayz585.awt.image.ImageIO;
import net.PeytonPlayz585.fileutils.FileEntry;
import net.PeytonPlayz585.opengl.GL11;
import net.PeytonPlayz585.util.zip.ZipFile;
import net.minecraft.client.Minecraft;
import org.lwjgl.opengl.GL11;
public class TexturePackCustom extends TexturePackBase {
public TexturePackCustom(String s) {
this.texturePackFileName = s;
try {
deleteExistingTexturePackFiles();
byte[] data = File.readFile("texturepacks/" + s);
ByteArrayInputStream bais = new ByteArrayInputStream(data);
ZipInputStream zis = new ZipInputStream(bais);
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
byte[] buffer = new byte[(int)entry.getSize()];
int len;
while ((len = zis.read(buffer)) > 0) {
baos.write(buffer, 0, len);
}
byte[] fileData = baos.toByteArray();
System.out.println(entry.getName());
String name = entry.getName();
if(name.startsWith("/")) {
name = name.substring(1, name.length() - 1);
}
File.writeFile("texturepackdata/" + name.replace(" ", ""), fileData);
}
zis.closeEntry();
}
zis.close();
} catch (IOException e) {
e.printStackTrace();
}
private ZipFile field_6496_e;
private int texturePackName = -1;
private BufferedImage field_6494_g;
private FileEntry field_6493_h;
public TexturePackCustom(FileEntry var1) {
this.texturePackFileName = var1.getName();
this.field_6493_h = var1;
}
private String func_6492_b(String var1) {
@ -62,76 +33,94 @@ public class TexturePackCustom extends TexturePackBase {
}
public void func_6485_a(Minecraft var1) throws IOException {
ZipFile var2 = null;
InputStream var3 = null;
try {
byte[] data = File.readFile("texturepackdata/pack.txt");
InputStream var3 = new ByteArrayInputStream(data);
BufferedReader var4 = new BufferedReader(new InputStreamReader(var3));
this.firstDescriptionLine = this.func_6492_b(var4.readLine());
this.secondDescriptionLine = this.func_6492_b(var4.readLine());
var4.close();
var3.close();
} catch(IOException e) {
e.printStackTrace();
var2 = new ZipFile(this.field_6493_h);
try {
var3 = var2.getInputStream(var2.getEntry("pack.txt"));
BufferedReader var4 = new BufferedReader(new InputStreamReader(var3));
this.firstDescriptionLine = this.func_6492_b(var4.readLine());
this.secondDescriptionLine = this.func_6492_b(var4.readLine());
var4.close();
var3.close();
} catch (Exception var20) {
}
try {
var3 = var2.getInputStream(var2.getEntry("pack.png"));
this.field_6494_g = ImageIO.read(var3);
var3.close();
} catch (Exception var19) {
}
var2.close();
} catch (Exception var21) {
var21.printStackTrace();
} finally {
try {
var3.close();
} catch (Exception var18) {
}
try {
var2.close();
} catch (Exception var17) {
}
}
}
public void func_6484_b(Minecraft var1) {
if(this.field_6494_g != null) {
var1.renderEngine.deleteTexture(this.texturePackName);
}
this.closeTexturePackFile();
}
int packPNG = -1;
public void func_6483_c(Minecraft var1) {
byte[] data = File.readFile("texturepackdata/pack.png");
if(data != null) {
if(packPNG == -1) {
packPNG = getTexture("pack.png");
}
GL11.glBindTexture(GL11.GL_TEXTURE_2D, packPNG);
if(this.field_6494_g != null && this.texturePackName < 0) {
this.texturePackName = var1.renderEngine.allocateAndSetupTexture(this.field_6494_g);
}
if(this.field_6494_g != null) {
var1.renderEngine.bindTexture(this.texturePackName);
} else {
GL11.glBindTexture(GL11.GL_TEXTURE_2D, var1.renderEngine.getTexture("/gui/unknown_pack.png"));
}
}
private int getTexture(String s) {
public void func_6482_a() {
try {
byte[] b = File.readFile("texturepackdata/" + s);
Minecraft.getMinecraft().renderEngine.singleIntBuffer.clear();
GLAllocation.generateTextureNames(Minecraft.getMinecraft().renderEngine.singleIntBuffer);
int i = Minecraft.getMinecraft().renderEngine.singleIntBuffer.get(0);
Minecraft.getMinecraft().renderEngine.setupTexture(Minecraft.getMinecraft().renderEngine.readTextureImage(b), i);
return i;
} catch (IOException e) {
throw new RuntimeException("!!");
this.field_6496_e = new ZipFile(this.field_6493_h);
} catch (Exception var2) {
}
}
public byte[] func_6481_a(String var1) {
String path = var1;
if(path.startsWith("/")) {
path = path.substring(1);
public void closeTexturePackFile() {
try {
this.field_6496_e.close();
} catch (Exception var2) {
}
System.out.println(path);
byte[] data = File.readFile("texturepackdata/" + path.replace(" ", ""));
if(data == null) {
return GL11.EaglerAdapterImpl2.loadResourceBytes(var1);
}
System.out.println("Texture Found in texture pack: " + path);
return data;
this.field_6496_e = null;
}
public InputStream func_6481_a(String var1) {
try {
ZipEntry var2 = this.field_6496_e.getEntry(var1.substring(1));
if(var2 != null) {
return this.field_6496_e.getInputStream(var2);
}
} catch (Exception var3) {
}
return ImageIO.getResourceAsStream(var1);
}
private void deleteExistingTexturePackFiles() {
String path = "texturepackdata/";
Collection<FileEntry> lst = File.listFiles(path, true, true);
for(FileEntry t : lst) {
if(!t.isDirectory) {
File.deleteFile(t.path);
}
}
for(FileEntry t : lst) {
if(t.isDirectory) {
File.deleteFile(t.path);
}
}
File.deleteFile(path);
}
}

View File

@ -2,7 +2,6 @@ package net.minecraft.src;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@ -10,7 +9,6 @@ import java.util.Map;
import net.PeytonPlayz585.fileutils.File;
import net.PeytonPlayz585.fileutils.FileEntry;
import net.PeytonPlayz585.opengl.GL11;
import net.minecraft.client.Minecraft;
public class TexturePackList {
@ -19,10 +17,12 @@ public class TexturePackList {
public TexturePackBase selectedTexturePack;
private Map field_6538_d = new HashMap();
private Minecraft mc;
private String texturePackDir = "texturepacksNEW";
private String field_6535_g;
public TexturePackList(Minecraft var1) {
this.mc = var1;
this.field_6535_g = var1.gameSettings.skin;
this.func_6532_a();
this.selectedTexturePack.func_6482_a();
@ -41,39 +41,42 @@ public class TexturePackList {
return true;
}
}
public void func_6532_a() {
ArrayList var1 = new ArrayList();
this.selectedTexturePack = null;
var1.add(this.defaultTexturePack);
Collection<FileEntry> var2 = File.listFiles("texturepacks/", false, false);
Collection<FileEntry> var3 = var2;
int var4 = var2.size();
for(int var5 = 0; var5 < var4; ++var5) {
FileEntry var6 = (FileEntry) var2.toArray()[var5];
String var7 = var6.getName();
try {
if(!this.field_6538_d.containsKey(var7)) {
TexturePackCustom var8 = new TexturePackCustom(var6.getName());
var8.field_6488_d = var7;
this.field_6538_d.put(var7, var8);
var8.func_6485_a(this.mc);
}
TexturePackBase var12 = (TexturePackBase)this.field_6538_d.get(var7);
if(var12.texturePackFileName.equals(this.field_6535_g)) {
this.selectedTexturePack = var12;
}
//if(this.texturePackDir.exists() && this.texturePackDir.isDirectory()) {
FileEntry[] var2 = File.listFiles(this.texturePackDir);
FileEntry[] var3 = var2;
int var4 = var2.length;
var1.add(var12);
} catch(IOException e) {
e.printStackTrace();
for(int var5 = 0; var5 < var4; ++var5) {
FileEntry var6 = var3[var5];
if(var6.isFile() && var6.getName().toLowerCase().endsWith(".zip")) {
String var7 = var6.getName() + ":" + var6.length() + ":" + var6.lastModified();
try {
if(!this.field_6538_d.containsKey(var7)) {
TexturePackCustom var8 = new TexturePackCustom(var6);
var8.field_6488_d = var7;
this.field_6538_d.put(var7, var8);
var8.func_6485_a(this.mc);
}
TexturePackBase var12 = (TexturePackBase)this.field_6538_d.get(var7);
if(var12.texturePackFileName.equals(this.field_6535_g)) {
this.selectedTexturePack = var12;
}
var1.add(var12);
} catch (IOException var9) {
var9.printStackTrace();
}
}
}
}
//}
if(this.selectedTexturePack == null) {
this.selectedTexturePack = this.defaultTexturePack;
}