nearly done with texture pack redo

todo: server texture packs & clean up so desktop runtime works
This commit is contained in:
ayunami2000 2024-12-09 21:25:01 -05:00
parent 334c565fee
commit c3bb53977d
12 changed files with 63 additions and 23 deletions

View File

@ -4,10 +4,11 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.Charset;
import com.jcraft.jzlib.InflaterInputStream; import com.jcraft.jzlib.InflaterInputStream;
public class EaglerInflater { public class EaglerMisc {
public static byte[] uncompress(byte[] input) throws IOException { public static byte[] uncompress(byte[] input) throws IOException {
return getBytesFromInputStream(new InflaterInputStream(new ByteArrayInputStream(input))); return getBytesFromInputStream(new InflaterInputStream(new ByteArrayInputStream(input)));
@ -21,5 +22,18 @@ public class EaglerInflater {
} }
return os.toByteArray(); return os.toByteArray();
} }
public static String bytesToString(byte[] bb) {
if (bb == null) return "";
return new String(bb, Charset.forName("UTF-8"));
}
public static String[] bytesToLines(byte[] bb) {
String contents = bytesToString(bb);
if(contents.isEmpty()) {
return new String[0];
}else {
return contents.replace("\r\n", "\n").split("[\r\n]");
}
}
} }

View File

@ -207,8 +207,8 @@ public class TextureTerrainMap implements IconRegister {
EaglerAdapter.GL_RGBA, EaglerAdapter.GL_UNSIGNED_BYTE, uploadBuffer); EaglerAdapter.GL_RGBA, EaglerAdapter.GL_UNSIGNED_BYTE, uploadBuffer);
EaglerAdapter.glTexParameteri(EaglerAdapter.GL_TEXTURE_2D, EaglerAdapter.GL_TEXTURE_MAX_LEVEL, 4); EaglerAdapter.glTexParameteri(EaglerAdapter.GL_TEXTURE_2D, EaglerAdapter.GL_TEXTURE_MAX_LEVEL, 4);
String dat = EaglerAdapter.fileContents("/" + map.basePath + name + ".txt"); String dat = EaglerMisc.bytesToString(Minecraft.getMinecraft().texturePackList.getSelectedTexturePack().getResourceAsBytes("/" + map.basePath + name + ".txt"));
if(dat != null) System.out.println("Found animation info for: " + map.basePath + name + ".png"); if(dat != null) System.out.println("Found animation info for: " + map.basePath + name + ".png");
if(dat == null || (dat = dat.trim()).isEmpty()) { if(dat == null || (dat = dat.trim()).isEmpty()) {
framesIdx = new int[divs]; framesIdx = new int[divs];

View File

@ -3,7 +3,8 @@ package net.minecraft.src;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import net.lax1dude.eaglercraft.EaglerAdapter; import net.lax1dude.eaglercraft.EaglerMisc;
import net.minecraft.client.Minecraft;
public class AchievementMap { public class AchievementMap {
/** Holds the singleton instance of AchievementMap. */ /** Holds the singleton instance of AchievementMap. */
@ -14,7 +15,8 @@ public class AchievementMap {
private AchievementMap() { private AchievementMap() {
try { try {
for(String str : EaglerAdapter.fileContentsLines("/achievement/map.txt")) { String[] strs = EaglerMisc.bytesToLines(Minecraft.getMinecraft().texturePackList.getSelectedTexturePack().getResourceAsBytes("/achievement/map.txt"));
for(String str : strs) {
String[] var3 = str.split(","); String[] var3 = str.split(",");
int var4 = Integer.parseInt(var3[0]); int var4 = Integer.parseInt(var3[0]);
this.guidMap.put(Integer.valueOf(var4), var3[1]); this.guidMap.put(Integer.valueOf(var4), var3[1]);

View File

@ -13,6 +13,7 @@ import net.lax1dude.eaglercraft.GuiScreenSingleplayerLoading;
import net.lax1dude.eaglercraft.IntegratedServer; import net.lax1dude.eaglercraft.IntegratedServer;
import net.lax1dude.eaglercraft.LocalStorageManager; import net.lax1dude.eaglercraft.LocalStorageManager;
import net.lax1dude.eaglercraft.TextureLocation; import net.lax1dude.eaglercraft.TextureLocation;
import net.lax1dude.eaglercraft.EaglerMisc;
import net.lax1dude.eaglercraft.adapter.Tessellator; import net.lax1dude.eaglercraft.adapter.Tessellator;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
@ -175,7 +176,7 @@ public class GuiMainMenu extends GuiScreen {
if(this.ackLines.isEmpty()) { if(this.ackLines.isEmpty()) {
int width = 315; int width = 315;
String file = EaglerAdapter.fileContents("/credits.txt"); String file = EaglerMisc.bytesToString(Minecraft.getMinecraft().texturePackList.getSelectedTexturePack().getResourceAsBytes("/credits.txt"));
if(file == null) { if(file == null) {
for(int i = 0; i < 30; ++i) { for(int i = 0; i < 30; ++i) {
this.ackLines.add(" -- file not found -- "); this.ackLines.add(" -- file not found -- ");

View File

@ -2,7 +2,7 @@ package net.minecraft.src;
import net.lax1dude.eaglercraft.EPKDecompiler; import net.lax1dude.eaglercraft.EPKDecompiler;
import net.lax1dude.eaglercraft.EaglerAdapter; import net.lax1dude.eaglercraft.EaglerAdapter;
import net.lax1dude.eaglercraft.EaglerInflater; import net.lax1dude.eaglercraft.EaglerMisc;
import net.lax1dude.eaglercraft.adapter.teavm.vfs.VFile; import net.lax1dude.eaglercraft.adapter.teavm.vfs.VFile;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@ -112,7 +112,7 @@ public class GuiTexturePacks extends GuiScreen {
ZipEntry entry; ZipEntry entry;
while ((entry = zipInputStream.getNextEntry()) != null) { while ((entry = zipInputStream.getNextEntry()) != null) {
if (entry.isDirectory()) continue; if (entry.isDirectory()) continue;
new VFile(fileLocation, safeName, entry.getName()).setAllBytes(EaglerInflater.getBytesFromInputStream(zipInputStream)); new VFile(fileLocation, safeName, entry.getName()).setAllBytes(EaglerMisc.getBytesFromInputStream(zipInputStream));
} }
zipInputStream.close(); zipInputStream.close();
} else { } else {
@ -138,6 +138,9 @@ public class GuiTexturePacks extends GuiScreen {
if (par1) { if (par1) {
new VFile(fileLocation, ((ITexturePack) var3.get(par2)).getTexturePackFileName()).deleteAll(); 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();
} else { } else {
try { try {
this.mc.texturePackList.setTexturePack((ITexturePack) var3.get(par2)); this.mc.texturePackList.setTexturePack((ITexturePack) var3.get(par2));

View File

@ -7,6 +7,7 @@ import net.lax1dude.eaglercraft.EaglerAdapter;
import net.lax1dude.eaglercraft.EaglerProfile; import net.lax1dude.eaglercraft.EaglerProfile;
import net.lax1dude.eaglercraft.EaglercraftRandom; import net.lax1dude.eaglercraft.EaglercraftRandom;
import net.lax1dude.eaglercraft.TextureLocation; import net.lax1dude.eaglercraft.TextureLocation;
import net.lax1dude.eaglercraft.EaglerMisc;
import net.lax1dude.eaglercraft.adapter.Tessellator; import net.lax1dude.eaglercraft.adapter.Tessellator;
public class GuiWinGame extends GuiScreen { public class GuiWinGame extends GuiScreen {
@ -70,7 +71,8 @@ public class GuiWinGame extends GuiScreen {
EaglercraftRandom var5 = new EaglercraftRandom(8124371L); EaglercraftRandom var5 = new EaglercraftRandom(8124371L);
int var6; int var6;
for(String str : EaglerAdapter.fileContentsLines("/title/win.txt")) { String[] strs = EaglerMisc.bytesToLines(mc.texturePackList.getSelectedTexturePack().getResourceAsBytes("/title/win.txt"));
for(String str : strs) {
String var7; String var7;
String var8; String var8;
@ -88,7 +90,8 @@ public class GuiWinGame extends GuiScreen {
this.lines.add(""); this.lines.add("");
} }
for(String str : EaglerAdapter.fileContentsLines("/title/credits.txt")) { strs = EaglerMisc.bytesToLines(mc.texturePackList.getSelectedTexturePack().getResourceAsBytes("/title/credits.txt"));
for(String str : strs) {
var1 = var1.replaceAll("PLAYERNAME", EaglerProfile.username); var1 = var1.replaceAll("PLAYERNAME", EaglerProfile.username);
var1 = var1.replaceAll("\t", " "); var1 = var1.replaceAll("\t", " ");
this.lines.addAll(this.mc.fontRenderer.listFormattedStringToWidth(var1, var3)); this.lines.addAll(this.mc.fontRenderer.listFormattedStringToWidth(var1, var3));

View File

@ -4,7 +4,7 @@ import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import net.lax1dude.eaglercraft.EaglerInflater; import net.lax1dude.eaglercraft.EaglerMisc;
public class Packet51MapChunk extends Packet { public class Packet51MapChunk extends Packet {
/** The x-position of the transmitted chunk, in chunk coordinates. */ /** The x-position of the transmitted chunk, in chunk coordinates. */
@ -82,7 +82,7 @@ public class Packet51MapChunk extends Packet {
var3 += 256; var3 += 256;
} }
this.compressedChunkData = EaglerInflater.uncompress(temp); this.compressedChunkData = EaglerMisc.uncompress(temp);
}else { }else {
this.tempLength &= 0xFFFFFFF; this.tempLength &= 0xFFFFFFF;
this.compressedChunkData = new byte[this.tempLength]; this.compressedChunkData = new byte[this.tempLength];

View File

@ -5,7 +5,7 @@ import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import net.lax1dude.eaglercraft.EaglerInflater; import net.lax1dude.eaglercraft.EaglerMisc;
public class Packet56MapChunks extends Packet { public class Packet56MapChunks extends Packet {
private int[] chunkPostX; private int[] chunkPostX;
@ -56,7 +56,7 @@ public class Packet56MapChunks extends Packet {
chunkDataNotCompressed = new byte[this.dataLength]; chunkDataNotCompressed = new byte[this.dataLength];
} }
par1DataInputStream.readFully(chunkDataNotCompressed, 0, this.dataLength); par1DataInputStream.readFully(chunkDataNotCompressed, 0, this.dataLength);
var3 = EaglerInflater.uncompress(chunkDataNotCompressed); var3 = EaglerMisc.uncompress(chunkDataNotCompressed);
} }
int var5 = 0; int var5 = 0;

View File

@ -5,7 +5,8 @@ import java.util.IllegalFormatException;
import java.util.Properties; import java.util.Properties;
import java.util.TreeMap; import java.util.TreeMap;
import net.lax1dude.eaglercraft.EaglerAdapter; import net.lax1dude.eaglercraft.EaglerMisc;
import net.minecraft.client.Minecraft;
public class StringTranslate { public class StringTranslate {
/** Is the private singleton instance of StringTranslate. */ /** Is the private singleton instance of StringTranslate. */
@ -42,7 +43,7 @@ public class StringTranslate {
} }
private void loadLanguage(Properties par1Properties, String par2Str) throws IOException { private void loadLanguage(Properties par1Properties, String par2Str) throws IOException {
String[] var3 = EaglerAdapter.fileContents("/lang/" + par2Str + ".lang").replace('\r', '\n') String[] var3 = EaglerMisc.bytesToString(Minecraft.getMinecraft().texturePackList.getSelectedTexturePack().getResourceAsBytes("/lang/" + par2Str + ".lang")).replace('\r', '\n')
.replaceAll("\n+", "\n").split("\n"); .replaceAll("\n+", "\n").split("\n");
for (String var4 : var3) { for (String var4 : var3) {

View File

@ -7,7 +7,7 @@ import java.io.InputStreamReader;
import net.lax1dude.eaglercraft.EaglerAdapter; import net.lax1dude.eaglercraft.EaglerAdapter;
import net.lax1dude.eaglercraft.EaglerImage; import net.lax1dude.eaglercraft.EaglerImage;
import net.lax1dude.eaglercraft.EaglerInflater; import net.lax1dude.eaglercraft.EaglerMisc;
import net.lax1dude.eaglercraft.adapter.teavm.vfs.VFile; import net.lax1dude.eaglercraft.adapter.teavm.vfs.VFile;
public abstract class TexturePackImplementation implements ITexturePack public abstract class TexturePackImplementation implements ITexturePack
@ -77,7 +77,9 @@ public abstract class TexturePackImplementation implements ITexturePack
try try
{ {
var1 = this.func_98137_a("/pack.png", false); var1 = this.func_98137_a("/pack.png", false);
this.thumbnailImage = EaglerImage.loadImage(EaglerInflater.getBytesFromInputStream(var1)); if (var1 != null) {
this.thumbnailImage = EaglerImage.loadImage(EaglerMisc.getBytesFromInputStream(var1));
}
} }
catch (IOException var11) catch (IOException var11)
{ {
@ -163,11 +165,24 @@ public abstract class TexturePackImplementation implements ITexturePack
*/ */
public byte[] getResourceAsBytes(String par1Str) public byte[] getResourceAsBytes(String par1Str)
{ {
InputStream is = null;
byte[] res = null;
try { try {
return EaglerInflater.getBytesFromInputStream(this.func_98137_a(par1Str, true)); is = this.func_98137_a(par1Str, true);
if (is == null) return null;
res = EaglerMisc.getBytesFromInputStream(is);
} catch (IOException e) { } catch (IOException e) {
return null; return null;
} finally {
if (is != null) {
try {
is.close();
} catch (IOException ignored) {
//
}
}
} }
return res;
} }
protected abstract InputStream func_98139_b(String var1) throws IOException; protected abstract InputStream func_98139_b(String var1) throws IOException;

View File

@ -3,7 +3,8 @@ package net.minecraft.src;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import net.lax1dude.eaglercraft.EaglerAdapter; import net.lax1dude.eaglercraft.EaglerMisc;
import net.minecraft.client.Minecraft;
public class TextureStitched implements Icon { public class TextureStitched implements Icon {
private final String textureName; private final String textureName;
@ -171,7 +172,7 @@ public class TextureStitched implements Icon {
public void readAnimationInfo(String path) { public void readAnimationInfo(String path) {
ArrayList var2 = new ArrayList(); ArrayList var2 = new ArrayList();
try { try {
String var3 = EaglerAdapter.fileContents(path).trim(); String var3 = EaglerMisc.bytesToString(Minecraft.getMinecraft().texturePackList.getSelectedTexturePack().getResourceAsBytes(path)).trim();
if (var3.length() > 0) { if (var3.length() > 0) {
String[] var4 = var3.split(","); String[] var4 = var3.split(",");

View File

@ -6,7 +6,7 @@ public class SYS {
static { static {
VirtualFilesystem.VFSHandle vh = VirtualFilesystem.openVFS("_net_lax1dude_eaglercraft_adapter_teavm_vfs_VirtualFilesystem_1_5_2_eagStorage"); VirtualFilesystem.VFSHandle vh = VirtualFilesystem.openVFS("eagStorage2");
if(vh.vfs == null) { if(vh.vfs == null) {
System.err.println("Could not init filesystem!"); System.err.println("Could not init filesystem!");