Texture pack support

This commit is contained in:
PeytonPlayz595 2024-02-13 01:54:27 -05:00
parent e5fa84f411
commit f53ccbf796
14 changed files with 8717 additions and 3836 deletions

File diff suppressed because it is too large Load Diff

View File

@ -36,9 +36,11 @@ import org.teavm.jso.dom.html.HTMLCanvasElement;
import org.teavm.jso.dom.html.HTMLDocument;
import org.teavm.jso.dom.html.HTMLElement;
import org.teavm.jso.dom.html.HTMLImageElement;
import org.teavm.jso.dom.html.HTMLInputElement;
import org.teavm.jso.typedarrays.ArrayBuffer;
import org.teavm.jso.typedarrays.Float32Array;
import org.teavm.jso.typedarrays.Int32Array;
import org.teavm.jso.typedarrays.Int8Array;
import org.teavm.jso.typedarrays.Uint8Array;
import org.teavm.jso.typedarrays.Uint8ClampedArray;
import org.teavm.jso.webaudio.AudioBuffer;
@ -1172,25 +1174,77 @@ public class EaglerAdapterImpl2 {
Window.current().getLocation().setFullURL(url);
}
@JSBody(params = { "ext", "mime" }, script = "window.eagsFileChooser.openFileChooser(ext, mime);")
public static native void openFileChooser(String ext, String mime);
public static final byte[] getFileChooserResult() {
ArrayBuffer b = getFileChooserResult0();
if(b == null) return null;
Uint8Array array = Uint8Array.create(b);
byte[] ret = new byte[array.getByteLength()];
for(int i = 0; i < ret.length; ++i) {
ret[i] = (byte) array.get(i);
}
return ret;
@JSFunctor
private static interface FileChooserCallback extends JSObject {
void accept(String name, ArrayBuffer buffer);
}
@JSBody(params = { }, script = "var ret = window.eagsFileChooser.getFileChooserResult; window.eagsFileChooser.getFileChooserResult = null; return ret;")
private static native ArrayBuffer getFileChooserResult0();
private static class FileChooserCallbackImpl implements FileChooserCallback {
@JSBody(params = { }, script = "var ret = window.eagsFileChooser.getFileChooserResultName; window.eagsFileChooser.getFileChooserResultName = null; return ret;")
public static native String getFileChooserResultName();
private static final FileChooserCallbackImpl instance = new FileChooserCallbackImpl();
@Override
public void accept(String name, ArrayBuffer buffer) {
fileChooserHasResult = true;
if(name == null) {
fileChooserResultObject = null;
}else {
Int8Array typedArray = Int8Array.create(buffer);
byte[] bytes = new byte[typedArray.getByteLength()];
for(int i = 0; i < bytes.length; ++i) {
bytes[i] = typedArray.get(i);
}
fileChooserResultObject = new FileChooserResult(name, bytes);
}
}
}
private static volatile boolean fileChooserHasResult = false;
private static volatile FileChooserResult fileChooserResultObject = null;
@JSBody(params = { "inputElement", "callback" }, script =
"if(inputElement.files.length > 0) {"
+ "const value = inputElement.files[0];"
+ "value.arrayBuffer().then(function(arr){ callback(value.name, arr); })"
+ ".catch(function(){ callback(null, null); });"
+ "} else callback(null, null);")
private static native void getFileChooserResult(HTMLInputElement inputElement, FileChooserCallback callback);
@JSBody(params = { "inputElement", "value" }, script = "inputElement.accept = value;")
private static native void setAcceptSelection(HTMLInputElement inputElement, String value);
@JSBody(params = { "inputElement", "enable" }, script = "inputElement.multiple = enable;")
private static native void setMultipleSelection(HTMLInputElement inputElement, boolean enable);
public static void displayFileChooser(String mime, String ext) {
final HTMLInputElement inputElement = (HTMLInputElement) Window.current().getDocument().createElement("input");
inputElement.setType("file");
if(mime == null) {
setAcceptSelection(inputElement, "." + ext);
}else {
setAcceptSelection(inputElement, mime);
}
setMultipleSelection(inputElement, false);
inputElement.addEventListener("change", new EventListener<Event>() {
@Override
public void handleEvent(Event evt) {
getFileChooserResult(inputElement, FileChooserCallbackImpl.instance);
}
});
inputElement.click();
}
public static boolean fileChooserHasResult() {
return fileChooserHasResult;
}
public static FileChooserResult getFileChooserResult() {
fileChooserHasResult = false;
FileChooserResult res = fileChooserResultObject;
fileChooserResultObject = null;
return res;
}
public static final void setListenerPos(float x, float y, float z, float vx, float vy, float vz, float pitch, float yaw) {
float var2 = MathHelper.cos(-yaw * 0.017453292F);

View File

@ -0,0 +1,26 @@
package net.lax1dude.eaglercraft.adapter;
/**
* Copyright (c) 2022-2023 LAX1DUDE. All Rights Reserved.
*
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
*
* NOT FOR COMMERCIAL OR MALICIOUS USE
*
* (please read the 'LICENSE' file this repo's root directory for more info)
*
*/
public class FileChooserResult {
public final String fileName;
public final byte[] fileData;
public FileChooserResult(String fileName, byte[] fileData) {
this.fileName = fileName;
this.fileData = fileData;
}
}

View File

@ -40,6 +40,7 @@ import net.minecraft.src.TextureCompassFX;
import net.minecraft.src.TextureFlamesFX;
import net.minecraft.src.TextureLavaFX;
import net.minecraft.src.TextureLavaFlowFX;
import net.minecraft.src.TexturePackList;
import net.minecraft.src.TexturePortalFX;
import net.minecraft.src.TextureWatchFX;
import net.minecraft.src.TextureWaterFX;
@ -53,6 +54,7 @@ import net.minecraft.src.WorldProviderHell;
import net.minecraft.src.WorldRenderer;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
@ -88,6 +90,7 @@ public class Minecraft implements Runnable {
public GameSettings gameSettings;
public SoundManager sndManager = new SoundManager();
public MouseHelper mouseHelper;
public TexturePackList texturePackList;
public static long[] field_9240_E = new long[512];
public static long[] field_9239_F = new long[512];
public static int field_9238_G = 0;
@ -115,7 +118,8 @@ public class Minecraft implements Runnable {
RenderManager.instance.field_4236_f = new ItemRenderer(this);
this.gameSettings = new GameSettings(this);
this.renderEngine = new RenderEngine(this.gameSettings);
this.texturePackList = new TexturePackList(this);
this.renderEngine = new RenderEngine(texturePackList, this.gameSettings);
this.fontRenderer = new FontRenderer(this.gameSettings, "/font/default.png", this.renderEngine);
this.loadScreen();
this.mouseHelper = new MouseHelper();

View File

@ -3,6 +3,7 @@ package net.minecraft.src;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
@ -44,6 +45,13 @@ public class GameSettings {
public GameSettings(Minecraft var1) {
this.mc = var1;
this.loadOptions();
System.out.println("Loading texture packs!");
// try {
// //TexturePack.loadTexturePacks();
// } catch (IOException e) {
// e.printStackTrace();
// }
System.out.println("Done!");
}
public GameSettings() {
@ -121,6 +129,7 @@ public class GameSettings {
}
public void loadOptions() {
//int i = GL11.listFiles("texturepacks/", false, false).size();
try {
byte[] fileData = GL11.readFile("options.txt");
if(fileData == null) {
@ -188,6 +197,12 @@ public class GameSettings {
this.field_12259_z = var3[1];
}
// for(int i1 = 0; i1 < i; ++i1) {
// if(var3[0].equals("texturepack-" + i)) {
// TexturePack.texturePackOrder.add(var3[1]);
// }
// }
for(int var4 = 0; var4 < this.keyBindings.length; ++var4) {
if(var3[0].equals("key_" + this.keyBindings[var4].keyDescription)) {
this.keyBindings[var4].keyCode = Integer.parseInt(var3[1]);
@ -220,6 +235,14 @@ public class GameSettings {
var1.println("fancyGraphics:" + this.fancyGraphics);
var1.println("skin:" + this.skin);
// if(!TexturePack.texturePackOrder.isEmpty()) {
// int i = 0;
// for(String s : TexturePack.texturePackOrder) {
// ++i;
// var1.println("texturepack-" + i + ":" + s);
// }
// }
for(int var2 = 0; var2 < this.keyBindings.length; ++var2) {
var1.println("key_" + this.keyBindings[var2].keyDescription + ":" + this.keyBindings[var2].keyCode);
}

View File

@ -70,11 +70,10 @@ public class GuiMainMenu extends GuiScreen {
}
this.controlList.add(new GuiButton(1, this.width / 2 - 100, this.height / 4 + 48, "Singleplayer"));
GuiButton button;
this.controlList.add(button = new GuiButton(2, this.width / 2 - 100, this.height / 4 + 72, "Multiplayer"));
button.enabled = false;
this.controlList.add(button = new GuiButton(3, this.width / 2 - 100, this.height / 4 + 96, "Mods and Texture Packs"));
button.enabled = false;
//GuiButton button;
//this.controlList.add(button = new GuiButton(2, this.width / 2 - 100, this.height / 4 + 72, "Multiplayer"));
//button.enabled = false;
this.controlList.add(new GuiButton(3, this.width / 2 - 100, this.height / 4 + 72, "Mods and Texture Packs"));
this.controlList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 120 + 12, "Options..."));
if(this.mc.field_6320_i == null) {
((GuiButton)this.controlList.get(1)).enabled = false;
@ -96,7 +95,7 @@ public class GuiMainMenu extends GuiScreen {
}
if(var1.id == 3) {
//.mc.displayGuiScreen(new GuiTexturePacks(this));
this.mc.displayGuiScreen(new GuiTexturePacks(this));
}
}

View File

@ -0,0 +1,217 @@
package net.minecraft.src;
import java.util.List;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import net.lax1dude.eaglercraft.adapter.FileChooserResult;
import net.minecraft.client.Minecraft;
public class GuiTexturePacks extends GuiScreen {
protected GuiScreen field_6461_a;
private int field_6460_h = 0;
private int field_6459_i = 32;
private int field_6458_j = this.height - 55 + 4;
private int field_6457_l = 0;
private int field_6456_m = this.width;
private int field_6455_n = -2;
private int field_6454_o = -1;
public GuiTexturePacks(GuiScreen var1) {
this.field_6461_a = var1;
}
public void initGui() {
this.controlList.add(new GuiSmallButton(5, this.width / 2 - 154, this.height - 48, "Upload texture pack"));
this.controlList.add(new GuiSmallButton(6, this.width / 2 + 4, this.height - 48, "Done"));
this.mc.texturePackList.func_6532_a();
this.field_6459_i = 32;
this.field_6458_j = this.height - 58 + 4;
this.field_6457_l = 0;
this.field_6456_m = this.width;
}
protected void actionPerformed(GuiButton var1) {
if(var1.enabled) {
if(var1.id == 5) {
GL11.displayFileChooser("application/zip", "zip");
}
if(var1.id == 6) {
this.mc.renderEngine.refreshTextures();
this.mc.displayGuiScreen(this.field_6461_a);
}
}
}
protected void mouseClicked(int var1, int var2, int var3) {
super.mouseClicked(var1, var2, var3);
}
protected void mouseMovedOrUp(int var1, int var2, int var3) {
super.mouseMovedOrUp(var1, var2, var3);
}
public void drawScreen(int var1, int var2, float var3) {
this.drawDefaultBackground();
if(this.field_6454_o <= 0) {
this.mc.texturePackList.func_6532_a();
this.field_6454_o += 20;
}
List var4 = this.mc.texturePackList.availableTexturePacks();
int var5;
if(Mouse.isButtonDown(0)) {
if(this.field_6455_n == -1) {
if(var2 >= this.field_6459_i && var2 <= this.field_6458_j) {
var5 = this.width / 2 - 110;
int var6 = this.width / 2 + 110;
int var7 = (var2 - this.field_6459_i + this.field_6460_h - 2) / 36;
if(var1 >= var5 && var1 <= var6 && var7 >= 0 && var7 < var4.size() && this.mc.texturePackList.setTexturePack((TexturePackBase)var4.get(var7))) {
this.mc.renderEngine.refreshTextures();
}
this.field_6455_n = var2;
} else {
this.field_6455_n = -2;
}
} else if(this.field_6455_n >= 0) {
this.field_6460_h -= var2 - this.field_6455_n;
this.field_6455_n = var2;
}
} else {
if(this.field_6455_n >= 0 && this.field_6455_n == var2) {
}
this.field_6455_n = -1;
}
var5 = var4.size() * 36 - (this.field_6458_j - this.field_6459_i - 4);
if(var5 < 0) {
var5 /= 2;
}
if(this.field_6460_h < 0) {
this.field_6460_h = 0;
}
if(this.field_6460_h > var5) {
this.field_6460_h = var5;
}
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_FOG);
Tessellator var16 = Tessellator.instance;
GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.mc.renderEngine.getTexture("/gui/background.png"));
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
float var17 = 32.0F;
var16.startDrawingQuads();
var16.setColorOpaque_I(2105376);
var16.addVertexWithUV((double)this.field_6457_l, (double)this.field_6458_j, 0.0D, (double)((float)this.field_6457_l / var17), (double)((float)(this.field_6458_j + this.field_6460_h) / var17));
var16.addVertexWithUV((double)this.field_6456_m, (double)this.field_6458_j, 0.0D, (double)((float)this.field_6456_m / var17), (double)((float)(this.field_6458_j + this.field_6460_h) / var17));
var16.addVertexWithUV((double)this.field_6456_m, (double)this.field_6459_i, 0.0D, (double)((float)this.field_6456_m / var17), (double)((float)(this.field_6459_i + this.field_6460_h) / var17));
var16.addVertexWithUV((double)this.field_6457_l, (double)this.field_6459_i, 0.0D, (double)((float)this.field_6457_l / var17), (double)((float)(this.field_6459_i + this.field_6460_h) / var17));
var16.draw();
for(int var8 = 0; var8 < var4.size(); ++var8) {
TexturePackBase var9 = (TexturePackBase)var4.get(var8);
int var10 = this.width / 2 - 92 - 16;
int var11 = 36 + var8 * 36 - this.field_6460_h;
byte var12 = 32;
byte var13 = 32;
if(var9 == this.mc.texturePackList.selectedTexturePack) {
int var14 = this.width / 2 - 110;
int var15 = this.width / 2 + 110;
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glDisable(GL11.GL_TEXTURE_2D);
var16.startDrawingQuads();
var16.setColorOpaque_I(8421504);
var16.addVertexWithUV((double)var14, (double)(var11 + var12 + 2), 0.0D, 0.0D, 1.0D);
var16.addVertexWithUV((double)var15, (double)(var11 + var12 + 2), 0.0D, 1.0D, 1.0D);
var16.addVertexWithUV((double)var15, (double)(var11 - 2), 0.0D, 1.0D, 0.0D);
var16.addVertexWithUV((double)var14, (double)(var11 - 2), 0.0D, 0.0D, 0.0D);
var16.setColorOpaque_I(0);
var16.addVertexWithUV((double)(var14 + 1), (double)(var11 + var12 + 1), 0.0D, 0.0D, 1.0D);
var16.addVertexWithUV((double)(var15 - 1), (double)(var11 + var12 + 1), 0.0D, 1.0D, 1.0D);
var16.addVertexWithUV((double)(var15 - 1), (double)(var11 - 1), 0.0D, 1.0D, 0.0D);
var16.addVertexWithUV((double)(var14 + 1), (double)(var11 - 1), 0.0D, 0.0D, 0.0D);
var16.draw();
GL11.glEnable(GL11.GL_TEXTURE_2D);
}
var9.func_6483_c(this.mc);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
var16.startDrawingQuads();
var16.setColorOpaque_I(16777215);
var16.addVertexWithUV((double)var10, (double)(var11 + var12), 0.0D, 0.0D, 1.0D);
var16.addVertexWithUV((double)(var10 + var13), (double)(var11 + var12), 0.0D, 1.0D, 1.0D);
var16.addVertexWithUV((double)(var10 + var13), (double)var11, 0.0D, 1.0D, 0.0D);
var16.addVertexWithUV((double)var10, (double)var11, 0.0D, 0.0D, 0.0D);
var16.draw();
this.drawString(this.fontRenderer, var9.texturePackFileName, var10 + var13 + 2, var11 + 1, 16777215);
this.drawString(this.fontRenderer, var9.firstDescriptionLine, var10 + var13 + 2, var11 + 12, 8421504);
this.drawString(this.fontRenderer, var9.secondDescriptionLine, var10 + var13 + 2, var11 + 12 + 10, 8421504);
}
byte var18 = 4;
this.func_6452_a(0, this.field_6459_i, 255, 255);
this.func_6452_a(this.field_6458_j, this.height, 255, 255);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glDisable(GL11.GL_ALPHA_TEST);
GL11.glDisable(GL11.GL_TEXTURE_2D);
var16.startDrawingQuads();
var16.setColorRGBA_I(0, 0);
var16.addVertexWithUV((double)this.field_6457_l, (double)(this.field_6459_i + var18), 0.0D, 0.0D, 1.0D);
var16.addVertexWithUV((double)this.field_6456_m, (double)(this.field_6459_i + var18), 0.0D, 1.0D, 1.0D);
var16.setColorRGBA_I(0, 255);
var16.addVertexWithUV((double)this.field_6456_m, (double)this.field_6459_i, 0.0D, 1.0D, 0.0D);
var16.addVertexWithUV((double)this.field_6457_l, (double)this.field_6459_i, 0.0D, 0.0D, 0.0D);
var16.draw();
var16.startDrawingQuads();
var16.setColorRGBA_I(0, 255);
var16.addVertexWithUV((double)this.field_6457_l, (double)this.field_6458_j, 0.0D, 0.0D, 1.0D);
var16.addVertexWithUV((double)this.field_6456_m, (double)this.field_6458_j, 0.0D, 1.0D, 1.0D);
var16.setColorRGBA_I(0, 0);
var16.addVertexWithUV((double)this.field_6456_m, (double)(this.field_6458_j - var18), 0.0D, 1.0D, 0.0D);
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.glEnable(GL11.GL_ALPHA_TEST);
GL11.glDisable(GL11.GL_BLEND);
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);
super.drawScreen(var1, var2, var3);
}
public void updateScreen() {
super.updateScreen();
--this.field_6454_o;
FileChooserResult packFile = null;
if (GL11.fileChooserHasResult()) {
packFile = GL11.getFileChooserResult();
}
if(packFile == null) {
return;
}
GL11.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) {
Tessellator var5 = Tessellator.instance;
GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.mc.renderEngine.getTexture("/gui/background.png"));
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
float var6 = 32.0F;
var5.startDrawingQuads();
var5.setColorRGBA_I(4210752, var4);
var5.addVertexWithUV(0.0D, (double)var2, 0.0D, 0.0D, (double)((float)var2 / var6));
var5.addVertexWithUV((double)this.width, (double)var2, 0.0D, (double)((float)this.width / var6), (double)((float)var2 / var6));
var5.setColorRGBA_I(4210752, var3);
var5.addVertexWithUV((double)this.width, (double)var1, 0.0D, (double)((float)this.width / var6), (double)((float)var1 / var6));
var5.addVertexWithUV(0.0D, (double)var1, 0.0D, 0.0D, (double)((float)var1 / var6));
var5.draw();
}
}

View File

@ -9,11 +9,11 @@ import java.util.HashMap;
import org.lwjgl.opengl.GL11;
import net.lax1dude.eaglercraft.EaglerImage;
import net.minecraft.client.Minecraft;
public class RenderEngine {
public RenderEngine(GameSettings gamesettings) {
public RenderEngine(TexturePackList var1, GameSettings gamesettings) {
field_6527_k = var1;
textureMap = new HashMap<String, Integer>();
textureNameToImageMap = new HashMap<Integer, EaglerImage>();
singleIntBuffer = GLAllocation.createDirectIntBuffer(1);
@ -25,6 +25,7 @@ public class RenderEngine {
}
public int getTexture(String s) {
TexturePackBase var2 = this.field_6527_k.selectedTexturePack;
Integer integer = (Integer) textureMap.get(s);
if (integer != null) {
return integer.intValue();
@ -36,15 +37,15 @@ public class RenderEngine {
if (s.startsWith("%%")) {
clampTexture = true;
String[] s1 = s.split("%%");
setupTexture(readTextureImage(GL11.loadResourceBytes(s1[1])), i);
setupTexture(readTextureImage(var2.func_6481_a(s1[1])), i);
clampTexture = false;
} else if(s.startsWith("%blur%")) {
blurTexture = true;
String[] s1 = s.split("%blur%");
setupTexture(readTextureImage(GL11.loadResourceBytes(s1[1])), i);
setupTexture(readTextureImage(var2.func_6481_a(s1[1])), i);
blurTexture = false;
} else {
setupTexture(readTextureImage(GL11.loadResourceBytes(s)), i);
setupTexture(readTextureImage(var2.func_6481_a(s)), i);
}
textureMap.put(s, Integer.valueOf(i));
return i;
@ -130,7 +131,7 @@ public class RenderEngine {
texturefx.func_783_a();
}
private EaglerImage readTextureImage(byte[] inputstream) throws IOException {
public EaglerImage readTextureImage(byte[] inputstream) throws IOException {
return GL11.loadPNG(inputstream);
}
@ -162,9 +163,14 @@ public class RenderEngine {
}
}
public void refreshTextures() {
textureMap.clear();
}
private static HashMap<String, Integer> textureMap;
private TexturePackList field_6527_k;
private HashMap<Integer, EaglerImage> textureNameToImageMap;
private IntBuffer singleIntBuffer;
public IntBuffer singleIntBuffer;
private ByteBuffer imageDataB1;
private java.util.List<TextureFX> textureList;
private GameSettings options;

View File

@ -0,0 +1,33 @@
package net.minecraft.src;
import java.io.IOException;
import org.lwjgl.opengl.GL11;
import net.minecraft.client.Minecraft;
public abstract class TexturePackBase {
public String texturePackFileName;
public String firstDescriptionLine;
public String secondDescriptionLine;
public String field_6488_d;
public void func_6482_a() {
}
public void closeTexturePackFile() {
}
public void func_6485_a(Minecraft var1) throws IOException {
}
public void func_6484_b(Minecraft var1) {
}
public void func_6483_c(Minecraft var1) {
}
public byte[] func_6481_a(String s) {
return GL11.loadResourceBytes(s);
}
}

View File

@ -0,0 +1,106 @@
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.HashMap;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import net.minecraft.client.Minecraft;
import org.lwjgl.opengl.GL11;
public class TexturePackCustom extends TexturePackBase {
private HashMap<String, byte[]> filePool = new HashMap<String, byte[]>();
public TexturePackCustom(String s) {
this.texturePackFileName = s;
try {
byte[] data = GL11.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());
filePool.put(entry.getName(), fileData);
}
zis.closeEntry();
}
zis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
private String func_6492_b(String var1) {
if(var1 != null && var1.length() > 34) {
var1 = var1.substring(0, 34);
}
return var1;
}
public void func_6485_a(Minecraft var1) throws IOException {
try {
InputStream var3 = new ByteArrayInputStream(filePool.get("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(IOException e) {
e.printStackTrace();
}
}
int packPNG = -1;
public void func_6483_c(Minecraft var1) {
if(filePool.containsKey("pack.png")) {
if(packPNG == -1) {
packPNG = getTexture("pack.png");
}
GL11.glBindTexture(GL11.GL_TEXTURE_2D, packPNG);
} else {
GL11.glBindTexture(GL11.GL_TEXTURE_2D, var1.renderEngine.getTexture("/gui/unknown_pack.png"));
}
}
private int getTexture(String s) {
try {
byte[] b = filePool.get(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("!!");
}
}
public byte[] func_6481_a(String var1) {
if(filePool.containsKey(var1)) {
return filePool.get(var1);
}
return GL11.loadResourceBytes(var1);
}
}

View File

@ -0,0 +1,19 @@
package net.minecraft.src;
import net.minecraft.client.Minecraft;
import org.lwjgl.opengl.GL11;
public class TexturePackDefault extends TexturePackBase {
public TexturePackDefault() {
this.texturePackFileName = "Default";
this.firstDescriptionLine = "The default look of Minecraft";
}
public void func_6484_b(Minecraft var1) {
}
public void func_6483_c(Minecraft var1) {
GL11.glBindTexture(GL11.GL_TEXTURE_2D, var1.renderEngine.getTexture("pack.png"));
}
}

View File

@ -0,0 +1,96 @@
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;
import java.util.Map;
import org.lwjgl.opengl.GL11;
import net.lax1dude.eaglercraft.adapter.EaglerAdapterImpl2.FileEntry;
import net.minecraft.client.Minecraft;
public class TexturePackList {
private List availableTexturePacks = new ArrayList();
private TexturePackBase defaultTexturePack = new TexturePackDefault();
public TexturePackBase selectedTexturePack;
private Map field_6538_d = new HashMap();
private Minecraft mc;
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();
}
public boolean setTexturePack(TexturePackBase var1) {
if(var1 == this.selectedTexturePack) {
return false;
} else {
this.selectedTexturePack.closeTexturePackFile();
this.field_6535_g = var1.texturePackFileName;
this.selectedTexturePack = var1;
this.mc.gameSettings.skin = this.field_6535_g;
this.mc.gameSettings.saveOptions();
this.selectedTexturePack.func_6482_a();
return true;
}
}
public void func_6532_a() {
ArrayList var1 = new ArrayList();
this.selectedTexturePack = null;
var1.add(this.defaultTexturePack);
Collection<FileEntry> var2 = GL11.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;
}
var1.add(var12);
} catch(IOException e) {
e.printStackTrace();
}
}
if(this.selectedTexturePack == null) {
this.selectedTexturePack = this.defaultTexturePack;
}
this.availableTexturePacks.removeAll(var1);
Iterator var10 = this.availableTexturePacks.iterator();
while(var10.hasNext()) {
TexturePackBase var11 = (TexturePackBase)var10.next();
var11.func_6484_b(this.mc);
this.field_6538_d.remove(var11.field_6488_d);
}
this.availableTexturePacks = var1;
}
public List availableTexturePacks() {
return new ArrayList(this.availableTexturePacks);
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long