Texture pack support

This commit is contained in:
PeytonPlayz595 2024-08-05 13:54:11 -04:00
parent 432303bb68
commit 1dbb0d2a7b
14 changed files with 604 additions and 27 deletions

View File

@ -33,7 +33,7 @@ public class Client {
try { try {
JSONObject e = new JSONObject(getOpts()); JSONObject e = new JSONObject(getOpts());
initializeContext(e.getString("assetsLocation")); initializeContext(rootElement = Window.current().getDocument().getElementById(e.getString("gameContainer")), e.getString("assetsLocation"));
}catch(Throwable ex2) { }catch(Throwable ex2) {
StringWriter s = new StringWriter(); StringWriter s = new StringWriter();
ex2.printStackTrace(new java.io.PrintWriter(s)); ex2.printStackTrace(new java.io.PrintWriter(s));

View File

@ -85,7 +85,7 @@ public class File {
} }
public static final FileEntry[] listFiles(String path) { public static final FileEntry[] listFiles(String path) {
Collection<FileEntry> entries = IndexedDBFilesystem.listFiles(path, true, false); Collection<FileEntry> entries = listFilesAndDirectories(path);
FileEntry[] entryArray = new FileEntry[entries.size()]; FileEntry[] entryArray = new FileEntry[entries.size()];
int i = 0; int i = 0;

View File

@ -20,5 +20,17 @@ public class FileEntry {
return path; return path;
} }
} }
public boolean isFile() {
return !isDirectory;
}
public long length() {
return File.getFileSize(path);
}
public long lastModified() {
return File.getLastModified(path);
}
} }

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

@ -69,6 +69,7 @@ import net.minecraft.src.StatList;
import net.minecraft.src.StatStringFormatKeyInv; import net.minecraft.src.StatStringFormatKeyInv;
import net.minecraft.src.Teleporter; import net.minecraft.src.Teleporter;
import net.minecraft.src.Tessellator; import net.minecraft.src.Tessellator;
import net.minecraft.src.TexturePackList;
import net.minecraft.src.Timer; import net.minecraft.src.Timer;
import net.minecraft.src.UnexpectedThrowable; import net.minecraft.src.UnexpectedThrowable;
import net.minecraft.src.Vec3D; import net.minecraft.src.Vec3D;
@ -109,6 +110,7 @@ public class Minecraft implements Runnable {
public GameSettings gameSettings; public GameSettings gameSettings;
public SoundManager sndManager = new SoundManager(); public SoundManager sndManager = new SoundManager();
public MouseHelper mouseHelper; public MouseHelper mouseHelper;
public TexturePackList texturePackList;
private ISaveFormat saveLoader; private ISaveFormat saveLoader;
public static long[] frameTimes = new long[512]; public static long[] frameTimes = new long[512];
public static long[] tickTimes = new long[512]; public static long[] tickTimes = new long[512];
@ -116,7 +118,7 @@ public class Minecraft implements Runnable {
public StatFileWriter statFileWriter; public StatFileWriter statFileWriter;
private String serverName; private String serverName;
private int serverPort; private int serverPort;
private static String minecraftDir = "minecraft"; private static final String minecraftDir = "minecraft";
public volatile boolean running = true; public volatile boolean running = true;
public String debug = ""; public String debug = "";
boolean isTakingScreenshot = false; boolean isTakingScreenshot = false;
@ -151,7 +153,8 @@ public class Minecraft implements Runnable {
public void startGame() { public void startGame() {
this.saveLoader = new EaglerSaveFormat(minecraftDir + "/" + "saves"); this.saveLoader = new EaglerSaveFormat(minecraftDir + "/" + "saves");
this.gameSettings = new GameSettings(this, minecraftDir); this.gameSettings = new GameSettings(this, minecraftDir);
this.renderEngine = new RenderEngine(this.gameSettings); this.texturePackList = new TexturePackList(this, this.minecraftDir);
this.renderEngine = new RenderEngine(this.texturePackList, this.gameSettings);
this.fontRenderer = new FontRenderer(this.gameSettings, "/font/default.png", this.renderEngine); this.fontRenderer = new FontRenderer(this.gameSettings, "/font/default.png", this.renderEngine);
ColorizerWater.func_28182_a(this.renderEngine.func_28149_a("/misc/watercolor.png")); ColorizerWater.func_28182_a(this.renderEngine.func_28149_a("/misc/watercolor.png"));
ColorizerGrass.func_28181_a(this.renderEngine.func_28149_a("/misc/grasscolor.png")); ColorizerGrass.func_28181_a(this.renderEngine.func_28149_a("/misc/grasscolor.png"));
@ -245,7 +248,7 @@ public class Minecraft implements Runnable {
} }
public String getSaveDir() { public String getSaveDir() {
return this.minecraftDir; return Minecraft.minecraftDir;
} }
public ISaveFormat getSaveLoader() { public ISaveFormat getSaveLoader() {

View File

@ -45,9 +45,7 @@ public class GuiMainMenu extends GuiScreen {
int var4 = this.height / 4 + 48; int var4 = this.height / 4 + 48;
this.controlList.add(new GuiButton(1, this.width / 2 - 100, var4, var2.translateKey("menu.singleplayer"))); this.controlList.add(new GuiButton(1, this.width / 2 - 100, var4, var2.translateKey("menu.singleplayer")));
this.controlList.add(this.multiplayerButton = new GuiButton(2, this.width / 2 - 100, var4 + 24, var2.translateKey("menu.multiplayer"))); this.controlList.add(this.multiplayerButton = new GuiButton(2, this.width / 2 - 100, var4 + 24, var2.translateKey("menu.multiplayer")));
GuiButton button; this.controlList.add(new GuiButton(3, this.width / 2 - 100, var4 + 48, var2.translateKey("menu.mods")));
this.controlList.add(button = new GuiButton(3, this.width / 2 - 100, var4 + 48, var2.translateKey("menu.mods")));
button.enabled = false;
this.controlList.add(new GuiButton(0, this.width / 2 - 100, var4 + 72, var2.translateKey("menu.options"))); this.controlList.add(new GuiButton(0, this.width / 2 - 100, var4 + 72, var2.translateKey("menu.options")));
if(this.mc.session == null) { if(this.mc.session == null) {
@ -68,6 +66,10 @@ public class GuiMainMenu extends GuiScreen {
if(var1.id == 2) { if(var1.id == 2) {
this.mc.displayGuiScreen(new GuiMultiplayer(this)); this.mc.displayGuiScreen(new GuiMultiplayer(this));
} }
if(var1.id == 3) {
this.mc.displayGuiScreen(new GuiTexturePacks(this));
}
if(var1.id == 4) { if(var1.id == 4) {
this.mc.shutdown(); this.mc.shutdown();

View File

@ -0,0 +1,53 @@
package net.minecraft.src;
import java.util.List;
import org.lwjgl.opengl.GL11;
class GuiTexturePackSlot extends GuiSlot {
final GuiTexturePacks parentTexturePackGui;
public GuiTexturePackSlot(GuiTexturePacks var1) {
super(GuiTexturePacks.func_22124_a(var1), var1.width, var1.height, 32, var1.height - 55 + 4, 36);
this.parentTexturePackGui = var1;
}
protected int getSize() {
List var1 = GuiTexturePacks.func_22126_b(this.parentTexturePackGui).texturePackList.availableTexturePacks();
return var1.size();
}
protected void elementClicked(int var1, boolean var2) {
List var3 = GuiTexturePacks.func_22119_c(this.parentTexturePackGui).texturePackList.availableTexturePacks();
GuiTexturePacks.func_22122_d(this.parentTexturePackGui).texturePackList.setTexturePack((TexturePackBase)var3.get(var1));
GuiTexturePacks.func_22117_e(this.parentTexturePackGui).renderEngine.refreshTextures();
}
protected boolean isSelected(int var1) {
List var2 = GuiTexturePacks.func_22118_f(this.parentTexturePackGui).texturePackList.availableTexturePacks();
return GuiTexturePacks.func_22116_g(this.parentTexturePackGui).texturePackList.selectedTexturePack == var2.get(var1);
}
protected int getContentHeight() {
return this.getSize() * 36;
}
protected void drawBackground() {
this.parentTexturePackGui.drawDefaultBackground();
}
protected void drawSlot(int var1, int var2, int var3, int var4, Tessellator var5) {
TexturePackBase var6 = (TexturePackBase)GuiTexturePacks.func_22121_h(this.parentTexturePackGui).texturePackList.availableTexturePacks().get(var1);
var6.bindThumbnailTexture(GuiTexturePacks.func_22123_i(this.parentTexturePackGui));
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
var5.startDrawingQuads();
var5.setColorOpaque_I(16777215);
var5.addVertexWithUV((double)var2, (double)(var3 + var4), 0.0D, 0.0D, 1.0D);
var5.addVertexWithUV((double)(var2 + 32), (double)(var3 + var4), 0.0D, 1.0D, 1.0D);
var5.addVertexWithUV((double)(var2 + 32), (double)var3, 0.0D, 1.0D, 0.0D);
var5.addVertexWithUV((double)var2, (double)var3, 0.0D, 0.0D, 0.0D);
var5.draw();
this.parentTexturePackGui.drawString(GuiTexturePacks.func_22127_j(this.parentTexturePackGui), var6.texturePackFileName, var2 + 32 + 2, var3 + 1, 16777215);
this.parentTexturePackGui.drawString(GuiTexturePacks.func_22120_k(this.parentTexturePackGui), var6.firstDescriptionLine, var2 + 32 + 2, var3 + 12, 8421504);
this.parentTexturePackGui.drawString(GuiTexturePacks.func_22125_l(this.parentTexturePackGui), var6.secondDescriptionLine, var2 + 32 + 2, var3 + 12 + 10, 8421504);
}
}

View File

@ -0,0 +1,125 @@
package net.minecraft.src;
import org.lwjgl.opengl.GL11;
import net.PeytonPlayz585.fileutils.File;
import net.PeytonPlayz585.fileutils.FileChooserResult;
import net.minecraft.client.Minecraft;
public class GuiTexturePacks extends GuiScreen {
protected GuiScreen guiScreen;
private int field_6454_o = -1;
private String fileLocation = "";
private GuiTexturePackSlot guiTexturePackSlot;
public GuiTexturePacks(GuiScreen var1) {
this.guiScreen = var1;
}
public void initGui() {
StringTranslate var1 = StringTranslate.getInstance();
this.controlList.add(new GuiSmallButton(5, this.width / 2 - 154, this.height - 48, var1.translateKey("texturePack.openFolder")));
this.controlList.add(new GuiSmallButton(6, this.width / 2 + 4, this.height - 48, var1.translateKey("gui.done")));
this.mc.texturePackList.updateAvaliableTexturePacks();
this.fileLocation = Minecraft.getMinecraft().getSaveDir() + "/texturepacks";
this.guiTexturePackSlot = new GuiTexturePackSlot(this);
this.guiTexturePackSlot.registerScrollButtons(this.controlList, 7, 8);
}
protected void actionPerformed(GuiButton var1) {
if(var1.enabled) {
if(var1.id == 5) {
//Sys.openURL("file://" + this.fileLocation);
GL11.EaglerAdapterImpl2.displayFileChooser("zip", "application/zip");
} else if(var1.id == 6) {
this.mc.renderEngine.refreshTextures();
this.mc.displayGuiScreen(this.guiScreen);
} else {
this.guiTexturePackSlot.actionPerformed(var1);
}
}
}
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.guiTexturePackSlot.drawScreen(var1, var2, var3);
if(this.field_6454_o <= 0) {
this.mc.texturePackList.updateAvaliableTexturePacks();
this.field_6454_o += 20;
}
if(GL11.EaglerAdapterImpl2.fileChooserHasResult()) {
FileChooserResult result = GL11.EaglerAdapterImpl2.getFileChooserResult();
File.writeFile(this.fileLocation + "/" + result.fileName, result.fileData);
//Refresh GUI to show newly added texture packs
this.mc.displayGuiScreen(new GuiTexturePacks(this.guiScreen));
}
StringTranslate var4 = StringTranslate.getInstance();
this.drawCenteredString(this.fontRenderer, var4.translateKey("texturePack.title"), this.width / 2, 16, 16777215);
this.drawCenteredString(this.fontRenderer, var4.translateKey("texturePack.folderInfo"), this.width / 2 - 77, this.height - 26, 8421504);
super.drawScreen(var1, var2, var3);
}
public void updateScreen() {
super.updateScreen();
--this.field_6454_o;
}
static Minecraft func_22124_a(GuiTexturePacks var0) {
return var0.mc;
}
static Minecraft func_22126_b(GuiTexturePacks var0) {
return var0.mc;
}
static Minecraft func_22119_c(GuiTexturePacks var0) {
return var0.mc;
}
static Minecraft func_22122_d(GuiTexturePacks var0) {
return var0.mc;
}
static Minecraft func_22117_e(GuiTexturePacks var0) {
return var0.mc;
}
static Minecraft func_22118_f(GuiTexturePacks var0) {
return var0.mc;
}
static Minecraft func_22116_g(GuiTexturePacks var0) {
return var0.mc;
}
static Minecraft func_22121_h(GuiTexturePacks var0) {
return var0.mc;
}
static Minecraft func_22123_i(GuiTexturePacks var0) {
return var0.mc;
}
static FontRenderer func_22127_j(GuiTexturePacks var0) {
return var0.fontRenderer;
}
static FontRenderer func_22120_k(GuiTexturePacks var0) {
return var0.fontRenderer;
}
static FontRenderer func_22125_l(GuiTexturePacks var0) {
return var0.fontRenderer;
}
}

View File

@ -21,19 +21,19 @@ public class RenderEngine {
private HashMap field_28151_c = new HashMap(); private HashMap field_28151_c = new HashMap();
private HashMap textureNameToImageMap = new HashMap(); private HashMap textureNameToImageMap = new HashMap();
private IntBuffer singleIntBuffer = GLAllocation.createDirectIntBuffer(1); private IntBuffer singleIntBuffer = GLAllocation.createDirectIntBuffer(1);
private ByteBuffer imageData = GLAllocation.createDirectByteBuffer(1048576); private ByteBuffer imageData = GLAllocation.createDirectByteBuffer(4194304 * 2); //Large enough (Maybe!?!?)
private List textureList = new ArrayList(); private List textureList = new ArrayList();
private GameSettings options; private GameSettings options;
private boolean clampTexture = false; private boolean clampTexture = false;
private boolean blurTexture = false; private boolean blurTexture = false;
private List<SpriteSheetTexture> textureSpriteList = new ArrayList(); private List<SpriteSheetTexture> textureSpriteList = new ArrayList();
private TexturePackList texturePack;
private BufferedImage missingTextureImage; private BufferedImage missingTextureImage;
private IntBuffer imageDataB1 = GLAllocation.createDirectIntBuffer(0x100000); private IntBuffer imageDataB1 = GLAllocation.createDirectIntBuffer(4194304 * 2); //:> !?!?!?!?
public RenderEngine(GameSettings var2) { public RenderEngine(TexturePackList var1, GameSettings var2) {
this.options = var2; this.options = var2;
this.texturePack = var1;
int[] missingTexture = new int[256]; int[] missingTexture = new int[256];
for(int i = 0; i < 256; ++i) { for(int i = 0; i < 256; ++i) {
missingTexture[i] = ((i / 16 + (i % 16)) % 2 == 0) ? 0xffff00ff : 0xff000000; missingTexture[i] = ((i / 16 + (i % 16)) % 2 == 0) ? 0xffff00ff : 0xff000000;
@ -42,6 +42,7 @@ public class RenderEngine {
} }
public int[] func_28149_a(String var1) { public int[] func_28149_a(String var1) {
TexturePackBase var2 = this.texturePack.selectedTexturePack;
int[] var3 = (int[])this.field_28151_c.get(var1); int[] var3 = (int[])this.field_28151_c.get(var1);
if(var3 != null) { if(var3 != null) {
return var3; return var3;
@ -50,14 +51,14 @@ public class RenderEngine {
Object var6 = null; Object var6 = null;
if(var1.startsWith("%clamp%")) { if(var1.startsWith("%clamp%")) {
this.clampTexture = true; this.clampTexture = true;
var3 = this.func_28148_b(this.readTextureImage(GL11.getResourceAsStream(var1.substring(7)))); var3 = this.func_28148_b(this.readTextureImage(var2.getResourceAsStream(var1.substring(7))));
this.clampTexture = false; this.clampTexture = false;
} else if(var1.startsWith("%blur%")) { } else if(var1.startsWith("%blur%")) {
this.blurTexture = true; this.blurTexture = true;
var3 = this.func_28148_b(this.readTextureImage(GL11.getResourceAsStream(var1.substring(6)))); var3 = this.func_28148_b(this.readTextureImage(var2.getResourceAsStream(var1.substring(6))));
this.blurTexture = false; this.blurTexture = false;
} else { } else {
InputStream var7 = GL11.getResourceAsStream(var1); InputStream var7 = var2.getResourceAsStream(var1);
if(var7 == null) { if(var7 == null) {
var3 = this.func_28148_b(this.missingTextureImage); var3 = this.func_28148_b(this.missingTextureImage);
} else { } else {
@ -92,6 +93,7 @@ public class RenderEngine {
} }
public int getTexture(String var1) { public int getTexture(String var1) {
TexturePackBase var2 = this.texturePack.selectedTexturePack;
Integer var3 = (Integer)this.textureMap.get(var1); Integer var3 = (Integer)this.textureMap.get(var1);
if(var3 != null) { if(var3 != null) {
return var3.intValue(); return var3.intValue();
@ -102,14 +104,14 @@ public class RenderEngine {
int var6 = this.singleIntBuffer.get(0); int var6 = this.singleIntBuffer.get(0);
if(var1.startsWith("%clamp%")) { if(var1.startsWith("%clamp%")) {
this.clampTexture = true; this.clampTexture = true;
this.setupTexture(this.readTextureImage(GL11.getResourceAsStream(var1.substring(7))), var6); this.setupTexture(this.readTextureImage(var2.getResourceAsStream(var1.substring(7))), var6);
this.clampTexture = false; this.clampTexture = false;
} else if(var1.startsWith("%blur%")) { } else if(var1.startsWith("%blur%")) {
this.blurTexture = true; this.blurTexture = true;
this.setupTexture(this.readTextureImage(GL11.getResourceAsStream(var1.substring(6))), var6); this.setupTexture(this.readTextureImage(var2.getResourceAsStream(var1.substring(6))), var6);
this.blurTexture = false; this.blurTexture = false;
} else { } else {
InputStream var7 = GL11.getResourceAsStream(var1); InputStream var7 = var2.getResourceAsStream(var1);
if(var7 == null) { if(var7 == null) {
this.setupTexture(this.missingTextureImage, var6); this.setupTexture(this.missingTextureImage, var6);
} else { } else {
@ -366,6 +368,7 @@ public class RenderEngine {
} }
public void refreshTextures() { public void refreshTextures() {
TexturePackBase var1 = this.texturePack.selectedTexturePack;
Iterator var2 = this.textureNameToImageMap.keySet().iterator(); Iterator var2 = this.textureNameToImageMap.keySet().iterator();
BufferedImage var4; BufferedImage var4;
@ -384,12 +387,12 @@ public class RenderEngine {
try { try {
if(var9.startsWith("%clamp%")) { if(var9.startsWith("%clamp%")) {
this.clampTexture = true; this.clampTexture = true;
var4 = this.readTextureImage(GL11.getResourceAsStream(var9.substring(7))); var4 = this.readTextureImage(var1.getResourceAsStream(var9.substring(7)));
} else if(var9.startsWith("%blur%")) { } else if(var9.startsWith("%blur%")) {
this.blurTexture = true; this.blurTexture = true;
var4 = this.readTextureImage(GL11.getResourceAsStream(var9.substring(6))); var4 = this.readTextureImage(var1.getResourceAsStream(var9.substring(6)));
} else { } else {
var4 = this.readTextureImage(GL11.getResourceAsStream(var9)); var4 = this.readTextureImage(var1.getResourceAsStream(var9));
} }
int var5 = ((Integer)this.textureMap.get(var9)).intValue(); int var5 = ((Integer)this.textureMap.get(var9)).intValue();
@ -409,12 +412,12 @@ public class RenderEngine {
try { try {
if(var9.startsWith("%clamp%")) { if(var9.startsWith("%clamp%")) {
this.clampTexture = true; this.clampTexture = true;
var4 = this.readTextureImage(GL11.getResourceAsStream(var9.substring(7))); var4 = this.readTextureImage(var1.getResourceAsStream(var9.substring(7)));
} else if(var9.startsWith("%blur%")) { } else if(var9.startsWith("%blur%")) {
this.blurTexture = true; this.blurTexture = true;
var4 = this.readTextureImage(GL11.getResourceAsStream(var9.substring(6))); var4 = this.readTextureImage(var1.getResourceAsStream(var9.substring(6)));
} else { } else {
var4 = this.readTextureImage(GL11.getResourceAsStream(var9)); var4 = this.readTextureImage(var1.getResourceAsStream(var9));
} }
this.func_28147_a(var4, (int[])this.field_28151_c.get(var9)); this.func_28147_a(var4, (int[])this.field_28151_c.get(var9));

View File

@ -0,0 +1,33 @@
package net.minecraft.src;
import java.io.IOException;
import java.io.InputStream;
import net.PeytonPlayz585.awt.image.ImageIO;
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 bindThumbnailTexture(Minecraft var1) {
}
public InputStream getResourceAsStream(String var1) {
return ImageIO.getResourceAsStream(var1);
}
}

View File

@ -0,0 +1,126 @@
package net.minecraft.src;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.zip.ZipEntry;
import net.PeytonPlayz585.awt.image.BufferedImage;
import net.PeytonPlayz585.awt.image.ImageIO;
import net.PeytonPlayz585.fileutils.FileEntry;
import net.PeytonPlayz585.util.zip.ZipFile;
import net.minecraft.client.Minecraft;
import org.lwjgl.opengl.GL11;
public class TexturePackCustom extends TexturePackBase {
private ZipFile texturePackZipFile;
private int texturePackName = -1;
private BufferedImage texturePackThumbnail;
private FileEntry texturePackFile;
public TexturePackCustom(FileEntry var1) {
this.texturePackFileName = var1.getName();
this.texturePackFile = var1;
}
private String truncateString(String var1) {
if(var1 != null && var1.length() > 34) {
var1 = var1.substring(0, 34);
}
return var1;
}
public void func_6485_a(Minecraft var1) throws IOException {
ZipFile var2 = null;
InputStream var3 = null;
try {
var2 = new ZipFile(this.texturePackFile);
try {
var3 = var2.getInputStream(var2.getEntry("pack.txt"));
BufferedReader var4 = new BufferedReader(new InputStreamReader(var3));
this.firstDescriptionLine = this.truncateString(var4.readLine());
this.secondDescriptionLine = this.truncateString(var4.readLine());
var4.close();
var3.close();
} catch (Exception var20) {
}
try {
var3 = var2.getInputStream(var2.getEntry("pack.png"));
this.texturePackThumbnail = 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.texturePackThumbnail != null) {
var1.renderEngine.deleteTexture(this.texturePackName);
}
this.closeTexturePackFile();
}
public void bindThumbnailTexture(Minecraft var1) {
if(this.texturePackThumbnail != null && this.texturePackName < 0) {
this.texturePackName = var1.renderEngine.allocateAndSetupTexture(this.texturePackThumbnail);
}
if(this.texturePackThumbnail != null) {
var1.renderEngine.bindTexture(this.texturePackName);
} else {
GL11.glBindTexture(GL11.GL_TEXTURE_2D, var1.renderEngine.getTexture("/gui/unknown_pack.png"));
}
}
public void func_6482_a() {
try {
this.texturePackZipFile = new ZipFile(this.texturePackFile);
} catch (Exception var2) {
}
}
public void closeTexturePackFile() {
try {
this.texturePackZipFile.close();
} catch (Exception var2) {
}
this.texturePackZipFile = null;
}
public InputStream getResourceAsStream(String var1) {
try {
ZipEntry var2 = this.texturePackZipFile.getEntry(var1.substring(1));
if(var2 != null) {
return this.texturePackZipFile.getInputStream(var2);
}
} catch (Exception var3) {
}
return ImageIO.getResourceAsStream(var1);
}
}

View File

@ -0,0 +1,45 @@
package net.minecraft.src;
import java.io.IOException;
import net.PeytonPlayz585.awt.image.BufferedImage;
import net.PeytonPlayz585.awt.image.ImageIO;
import net.minecraft.client.Minecraft;
import org.lwjgl.opengl.GL11;
public class TexturePackDefault extends TexturePackBase {
private int texturePackName = -1;
private BufferedImage texturePackThumbnail;
public TexturePackDefault() {
this.texturePackFileName = "Default";
this.firstDescriptionLine = "The default look of Minecraft";
try {
this.texturePackThumbnail = ImageIO.read(ImageIO.getResource("/pack.png"));
} catch (Exception var2) {
var2.printStackTrace();
}
}
public void func_6484_b(Minecraft var1) {
if(this.texturePackThumbnail != null) {
var1.renderEngine.deleteTexture(this.texturePackName);
}
}
public void bindThumbnailTexture(Minecraft var1) {
if(this.texturePackThumbnail != null && this.texturePackName < 0) {
this.texturePackName = var1.renderEngine.allocateAndSetupTexture(this.texturePackThumbnail);
}
if(this.texturePackThumbnail != null) {
var1.renderEngine.bindTexture(this.texturePackName);
} else {
GL11.glBindTexture(GL11.GL_TEXTURE_2D, var1.renderEngine.getTexture("/gui/unknown_pack.png"));
}
}
}

View File

@ -0,0 +1,104 @@
package net.minecraft.src;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import net.PeytonPlayz585.fileutils.File;
import net.PeytonPlayz585.fileutils.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 texturePackDir;
private String currentTexturePack;
public TexturePackList(Minecraft var1, String var2) {
this.mc = var1;
this.texturePackDir = var2 + "/texturepacks";
//if(!this.texturePackDir.exists()) {
//this.texturePackDir.mkdirs();
//}
this.currentTexturePack = var1.gameSettings.skin;
this.updateAvaliableTexturePacks();
this.selectedTexturePack.func_6482_a();
}
public boolean setTexturePack(TexturePackBase var1) {
if(var1 == this.selectedTexturePack) {
return false;
} else {
this.selectedTexturePack.closeTexturePackFile();
this.currentTexturePack = var1.texturePackFileName;
this.selectedTexturePack = var1;
this.mc.gameSettings.skin = this.currentTexturePack;
this.mc.gameSettings.saveOptions();
this.selectedTexturePack.func_6482_a();
return true;
}
}
public void updateAvaliableTexturePacks() {
ArrayList var1 = new ArrayList();
this.selectedTexturePack = null;
var1.add(this.defaultTexturePack);
//if(this.texturePackDir.exists() && this.texturePackDir.isDirectory()) {
FileEntry[] var2 = File.listFiles(this.texturePackDir);
FileEntry[] var3 = var2;
int var4 = var2.length;
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.currentTexturePack)) {
this.selectedTexturePack = var12;
}
var1.add(var12);
} catch (IOException var9) {
var9.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);
}
}

View File

@ -4394,8 +4394,8 @@ public class GL11 implements JSObject {
@JSBody(params = { }, script = "return window.assetsURI;") @JSBody(params = { }, script = "return window.assetsURI;")
private static native String getAssetsURI(); private static native String getAssetsURI();
public static final void initializeContext(String assetsURI) { public static final void initializeContext(HTMLElement gameContainer, String assetsURI) {
HTMLElement rootElement = Window.current().getDocument().getBody(); HTMLElement rootElement = gameContainer;
parent = rootElement; parent = rootElement;
String s = parent.getAttribute("style"); String s = parent.getAttribute("style");
parent.setAttribute("style", (s == null ? "" : s)+"overflow-x:hidden;overflow-y:hidden;"); parent.setAttribute("style", (s == null ? "" : s)+"overflow-x:hidden;overflow-y:hidden;");