Got it to compile with TeaVM!

This commit is contained in:
PeytonPlayz595 2023-10-11 15:33:43 +00:00
parent 508e2aea20
commit 624eb42878
19 changed files with 3465 additions and 5681 deletions

8459
js/app.js

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -152,7 +152,7 @@ public final class Minecraft implements Runnable {
GL11.glLoadIdentity();
GL11.glMatrixMode(GL11.GL_MODELVIEW);
checkGlError("Startup");
this.font = new Font("/default.png", this.textures);
this.font = new Font("/default.png");
IntBuffer var7 = BufferUtils.createIntBuffer(256);
var7.clear().limit(256);
GL11.glViewport(0, 0, this.width, this.height);

View File

@ -1,55 +1,101 @@
package com.mojang.minecraft.gui;
import java.nio.IntBuffer;
import com.mojang.minecraft.renderer.Tesselator;
import com.mojang.minecraft.renderer.Textures;
import java.awt.image.BufferedImage;
import com.mojang.minecraft.renderer.TextureLocation;
import net.PeytonPlayz585.opengl.LWJGLMain;
import net.PeytonPlayz585.opengl.MinecraftImageData;
import java.io.IOException;
import javax.imageio.ImageIO;
import org.lwjgl.GLAllocation;
import org.lwjgl.opengl.GL11;
public final class Font {
private int[] charWidths = new int[256];
private int fontTexture = 0;
private int charWidths[];
public String fontTextureName;
private int fontDisplayLists;
private IntBuffer buffer;
public static final char formatChar = '\247';
public Font(String var1, Textures var2) {
BufferedImage var3;
try {
var3 = ImageIO.read(Textures.class.getResourceAsStream(var1));
} catch (IOException var13) {
throw new RuntimeException(var13);
}
int var4 = var3.getWidth();
int var5 = var3.getHeight();
int[] var6 = new int[var4 * var5];
var3.getRGB(0, 0, var4, var5, var6, 0, var4);
for(int var14 = 0; var14 < 128; ++var14) {
var5 = var14 % 16;
int var7 = var14 / 16;
int var8 = 0;
for(boolean var9 = false; var8 < 8 && !var9; ++var8) {
int var10 = (var5 << 3) + var8;
var9 = true;
for(int var11 = 0; var11 < 8 && var9; ++var11) {
int var12 = ((var7 << 3) + var11) * var4;
var12 = var6[var10 + var12] & 255;
if(var12 > 128) {
var9 = false;
public Font(String var1) {
charWidths = new int[256];
fontTextureName = null;
MinecraftImageData bufferedimage = GL11.loadPNG(GL11.loadResourceBytes(var1));
int i = bufferedimage.w;
int j = bufferedimage.h;
int ai[] = bufferedimage.data;
for (int k = 0; k < 256; k++) {
int l = k % 16;
int k1 = k / 16;
int j2 = 7;
do {
if (j2 < 0) {
break;
}
int i3 = l * 8 + j2;
boolean flag = true;
for (int l3 = 0; l3 < 8 && flag; l3++) {
int i4 = (k1 * 8 + l3) * i;
int k4 = ai[i3 + i4] & 0xff;
if (k4 > 0) {
flag = false;
}
}
}
if(var14 == 32) {
var8 = 4;
if (!flag) {
break;
}
j2--;
} while (true);
if (k == 32) {
j2 = 2;
}
this.charWidths[var14] = var8;
charWidths[k] = j2 + 2;
}
this.fontTexture = var2.getTextureId(var1);
fontTextureName = var1;
fontDisplayLists = GLAllocation.generateDisplayLists(288);
Tesselator tessellator = Tesselator.instance;
for (int i1 = 0; i1 < 256; i1++) {
GL11.glNewList(fontDisplayLists + i1, 4864 /* GL_COMPILE */);
tessellator.begin(7);
int l1 = (i1 % 16) * 8;
int k2 = (i1 / 16) * 8;
float f = 7.99F;
float f1 = 0.0F;
float f2 = 0.0F;
tessellator.vertexUV(0.0D, 0.0F + f, 0.0D, (float) l1 / 128F + f1, ((float) k2 + f) / 128F + f2);
tessellator.vertexUV(0.0F + f, 0.0F + f, 0.0D, ((float) l1 + f) / 128F + f1, ((float) k2 + f) / 128F + f2);
tessellator.vertexUV(0.0F + f, 0.0D, 0.0D, ((float) l1 + f) / 128F + f1, (float) k2 / 128F + f2);
tessellator.vertexUV(0.0D, 0.0D, 0.0D, (float) l1 / 128F + f1, (float) k2 / 128F + f2);
tessellator.end();
GL11.glEndList();
}
for (int j1 = 0; j1 < 32; j1++) {
int i2 = (j1 >> 3 & 1) * 85;
int l2 = (j1 >> 2 & 1) * 170 + i2;
int j3 = (j1 >> 1 & 1) * 170 + i2;
int k3 = (j1 >> 0 & 1) * 170 + i2;
if (j1 == 6) {
l2 += 85;
}
boolean flag1 = j1 >= 16;
if (flag1) {
l2 /= 4;
j3 /= 4;
k3 /= 4;
}
GL11.glNewList(fontDisplayLists + 256 + j1, 4864 /* GL_COMPILE */);
GL11.glColor3f((float) l2 / 255F, (float) j3 / 255F, (float) k3 / 255F);
GL11.glEndList();
}
}
public final void drawShadow(String var1, int var2, int var3, int var4) {
@ -61,87 +107,63 @@ public final class Font {
this.draw(var1, var2, var3, var4, false);
}
private void draw(String var1, int var2, int var3, int var4, boolean var5) {
if(var1 != null) {
char[] var12 = var1.toCharArray();
if(var5) {
var4 = (var4 & 16579836) >> 2;
}
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.fontTexture);
Tesselator var6 = Tesselator.instance;
var6.begin();
var6.color(var4);
int var7 = 0;
for(int var8 = 0; var8 < var12.length; ++var8) {
int var9;
if(var12[var8] == 38 && var12.length > var8 + 1) {
var4 = "0123456789abcdef".indexOf(var12[var8 + 1]);
if(var4 < 0) {
var4 = 15;
}
var9 = (var4 & 8) << 3;
int var10 = (var4 & 1) * 191 + var9;
int var11 = ((var4 & 2) >> 1) * 191 + var9;
var4 = ((var4 & 4) >> 2) * 191 + var9;
var4 = var4 << 16 | var11 << 8 | var10;
var8 += 2;
if(var5) {
var4 = (var4 & 16579836) >> 2;
}
var6.color(var4);
}
var4 = var12[var8] % 16 << 3;
var9 = var12[var8] / 16 << 3;
float var13 = 7.99F;
var6.vertexUV((float)(var2 + var7), (float)var3 + var13, 0.0F, (float)var4 / 128.0F, ((float)var9 + var13) / 128.0F);
var6.vertexUV((float)(var2 + var7) + var13, (float)var3 + var13, 0.0F, ((float)var4 + var13) / 128.0F, ((float)var9 + var13) / 128.0F);
var6.vertexUV((float)(var2 + var7) + var13, (float)var3, 0.0F, ((float)var4 + var13) / 128.0F, (float)var9 / 128.0F);
var6.vertexUV((float)(var2 + var7), (float)var3, 0.0F, (float)var4 / 128.0F, (float)var9 / 128.0F);
var7 += this.charWidths[var12[var8]];
}
var6.end();
GL11.glDisable(GL11.GL_TEXTURE_2D);
private void draw(String s, int i, int j, int k, boolean flag) {
if (s == null) {
return;
}
if (flag) {
int l = k & 0xff000000;
k = (k & 0xfcfcfc) >> 2;
k += l;
}
new TextureLocation(fontTextureName).bindTexture();
float f = (float) (k >> 16 & 0xff) / 255F;
float f1 = (float) (k >> 8 & 0xff) / 255F;
float f2 = (float) (k & 0xff) / 255F;
float f3 = (float) (k >> 24 & 0xff) / 255F;
if (f3 == 0.0F) {
f3 = 1.0F;
}
GL11.glColor4f(f, f1, f2, f3);
GL11.glPushMatrix();
GL11.glTranslatef(i, j, 0.0F);
for (int i1 = 0; i1 < s.length(); i1++) {
for (; s.length() > i1 + 1 && s.charAt(i1) == '\247'; i1 += 2) {
int j1 = "0123456789abcdef".indexOf(s.toLowerCase().charAt(i1 + 1));
if (j1 < 0 || j1 > 15) {
j1 = 15;
}
continue;
}
if (i1 < s.length()) {
int k1 = FontAllowedCharacters.isAllowed(s.charAt(i1));
if (k1 >= 0) {
GL11.glCallList(fontDisplayLists + k1 + 32);
GL11.glTranslatef(charWidths[k1 + 32], 0.0F, 0.0F);
}
}
}
GL11.glPopMatrix();
}
public final int width(String var1) {
if(var1 == null) {
public final int width(String s) {
if (s == null) {
return 0;
} else {
char[] var4 = var1.toCharArray();
int var2 = 0;
for(int var3 = 0; var3 < var4.length; ++var3) {
if(var4[var3] == 38) {
++var3;
} else {
var2 += this.charWidths[var4[var3]];
}
}
return var2;
}
}
public static String removeColorCodes(String var0) {
char[] var3 = var0.toCharArray();
String var1 = "";
for(int var2 = 0; var2 < var3.length; ++var2) {
if(var3[var2] == 38) {
++var2;
} else {
var1 = var1 + var3[var2];
int i = 0;
for (int j = 0; j < s.length(); j++) {
if (s.charAt(j) == '\247') {
j++;
continue;
}
int k = FontAllowedCharacters.isAllowed(s.charAt(j));
if (k >= 0) {
i += charWidths[k + 32];
}
}
return var1;
return i;
}
}

View File

@ -0,0 +1,27 @@
package com.mojang.minecraft.gui;
public class FontAllowedCharacters {
public static int isAllowed(char c) {
int cc = (int) c;
for(int i = 0; i < allowedChars.length; ++i) {
if(cc == allowedChars[i]) {
return i;
}
}
return -1;
}
public static final int[] allowedChars = new int[]{
32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,
59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,
86,87,88,89,90,91,92,93,94,95,39,97,98,99,100,101,102,103,104,105,106,107,108,109,
110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,8962,199,252,
233,226,228,224,229,231,234,235,232,239,238,236,196,197,201,230,198,244,246,242,
251,249,255,214,220,248,163,216,215,402,225,237,243,250,241,209,170,186,191,174,
172,189,188,161,171,187
};
public static final char field_22286_b[] = { '/', '\n', '\r', '\t', '\0', '\f', '`', '?', '*', '\\', '<', '>', '|', '"', ':' };
}

View File

@ -7,8 +7,8 @@ import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
//import java.io.ObjectInputStream;
//import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
@ -23,219 +23,224 @@ public final class LevelIO {
}
public final boolean save(Level var1, String var2, String var3, String var4, String var5, int var6) {
if(var4 == null) {
var4 = "";
}
// if(var4 == null) {
// var4 = "";
// }
if(this.a != null && this.a != null) {
this.a.beginLevelLoading("Saving level");
}
// if(this.a != null && this.a != null) {
// this.a.beginLevelLoading("Saving level");
// }
try {
if(this.a != null && this.a != null) {
this.a.levelLoadUpdate("Compressing..");
}
// try {
// if(this.a != null && this.a != null) {
// this.a.levelLoadUpdate("Compressing..");
// }
ByteArrayOutputStream var7 = new ByteArrayOutputStream();
save(var1, var7);
var7.close();
byte[] var10 = var7.toByteArray();
if(this.a != null && this.a != null) {
this.a.levelLoadUpdate("Connecting..");
}
// ByteArrayOutputStream var7 = new ByteArrayOutputStream();
// save(var1, var7);
// var7.close();
// byte[] var10 = var7.toByteArray();
// if(this.a != null && this.a != null) {
// this.a.levelLoadUpdate("Connecting..");
// }
URL var12 = new URL("http://" + var2 + "/level/save.html");
HttpURLConnection var13 = (HttpURLConnection)var12.openConnection();
var13.setDoInput(true);
var13.setDoOutput(true);
var13.setRequestMethod("POST");
DataOutputStream var14 = new DataOutputStream(var13.getOutputStream());
var14.writeUTF(var3);
var14.writeUTF(var4);
var14.writeUTF(var5);
var14.writeByte(var6);
var14.writeInt(var10.length);
if(this.a != null) {
this.a.levelLoadUpdate("Saving..");
}
// URL var12 = new URL("http://" + var2 + "/level/save.html");
// HttpURLConnection var13 = (HttpURLConnection)var12.openConnection();
// var13.setDoInput(true);
// var13.setDoOutput(true);
// var13.setRequestMethod("POST");
// DataOutputStream var14 = new DataOutputStream(var13.getOutputStream());
// var14.writeUTF(var3);
// var14.writeUTF(var4);
// var14.writeUTF(var5);
// var14.writeByte(var6);
// var14.writeInt(var10.length);
// if(this.a != null) {
// this.a.levelLoadUpdate("Saving..");
// }
var14.write(var10);
var14.close();
BufferedReader var11 = new BufferedReader(new InputStreamReader(var13.getInputStream()));
var2 = var11.readLine();
if(!var2.equalsIgnoreCase("ok")) {
if(this.a != null) {
this.a.levelLoadUpdate("Failed: " + var11.readLine());
}
// var14.write(var10);
// var14.close();
// BufferedReader var11 = new BufferedReader(new InputStreamReader(var13.getInputStream()));
// var2 = var11.readLine();
// if(!var2.equalsIgnoreCase("ok")) {
// if(this.a != null) {
// this.a.levelLoadUpdate("Failed: " + var11.readLine());
// }
var11.close();
Thread.sleep(1000L);
return false;
} else {
var11.close();
return true;
}
} catch (Exception var9) {
var9.printStackTrace();
if(this.a != null) {
this.a.levelLoadUpdate("Failed!");
}
// var11.close();
// Thread.sleep(1000L);
// return false;
// } else {
// var11.close();
// return true;
// }
// } catch (Exception var9) {
// var9.printStackTrace();
// if(this.a != null) {
// this.a.levelLoadUpdate("Failed!");
// }
try {
Thread.sleep(1000L);
} catch (InterruptedException var8) {
}
// try {
// Thread.sleep(1000L);
// } catch (InterruptedException var8) {
// }
return false;
}
// return false;
// }
return false;
}
public final Level load(String var1, String var2, int var3) {
if(this.a != null) {
this.a.beginLevelLoading("Loading level");
}
// if(this.a != null) {
// this.a.beginLevelLoading("Loading level");
// }
try {
if(this.a != null) {
this.a.levelLoadUpdate("Connecting..");
}
// try {
// if(this.a != null) {
// this.a.levelLoadUpdate("Connecting..");
// }
URL var6 = new URL("http://" + var1 + "/level/load.html?id=" + var3 + "&user=" + var2);
HttpURLConnection var7 = (HttpURLConnection)var6.openConnection();
var7.setDoInput(true);
if(this.a != null) {
this.a.levelLoadUpdate("Loading..");
}
// URL var6 = new URL("http://" + var1 + "/level/load.html?id=" + var3 + "&user=" + var2);
// HttpURLConnection var7 = (HttpURLConnection)var6.openConnection();
// var7.setDoInput(true);
// if(this.a != null) {
// this.a.levelLoadUpdate("Loading..");
// }
DataInputStream var8 = new DataInputStream(var7.getInputStream());
var2 = var8.readUTF();
if(var2.equalsIgnoreCase("ok")) {
return this.load(var8);
} else {
if(this.a != null) {
this.a.levelLoadUpdate("Failed: " + var8.readUTF());
}
// DataInputStream var8 = new DataInputStream(var7.getInputStream());
// var2 = var8.readUTF();
// if(var2.equalsIgnoreCase("ok")) {
// return this.load(var8);
// } else {
// if(this.a != null) {
// this.a.levelLoadUpdate("Failed: " + var8.readUTF());
// }
var8.close();
Thread.sleep(1000L);
return null;
}
} catch (Exception var5) {
var5.printStackTrace();
if(this.a != null) {
this.a.levelLoadUpdate("Failed!");
}
// var8.close();
// Thread.sleep(1000L);
// return null;
// }
// } catch (Exception var5) {
// var5.printStackTrace();
// if(this.a != null) {
// this.a.levelLoadUpdate("Failed!");
// }
try {
Thread.sleep(3000L);
} catch (InterruptedException var4) {
}
// try {
// Thread.sleep(3000L);
// } catch (InterruptedException var4) {
// }
return null;
}
// return null;
// }
return null;
}
public final Level load(InputStream var1) {
if(this.a != null) {
this.a.beginLevelLoading("Loading level");
}
// if(this.a != null) {
// this.a.beginLevelLoading("Loading level");
// }
if(this.a != null) {
this.a.levelLoadUpdate("Reading..");
}
// if(this.a != null) {
// this.a.levelLoadUpdate("Reading..");
// }
try {
DataInputStream var10 = new DataInputStream(new GZIPInputStream(var1));
int var12 = var10.readInt();
if(var12 != 656127880) {
return null;
} else {
byte var13 = var10.readByte();
if(var13 > 2) {
return null;
} else if(var13 <= 1) {
System.out.println("Version is 1!");
String var15 = var10.readUTF();
String var16 = var10.readUTF();
long var7 = var10.readLong();
short var3 = var10.readShort();
short var4 = var10.readShort();
short var5 = var10.readShort();
byte[] var6 = new byte[var3 * var4 * var5];
var10.readFully(var6);
var10.close();
Level var11 = new Level();
var11.setData(var3, var5, var4, var6);
var11.name = var15;
var11.creator = var16;
var11.createTime = var7;
return var11;
} else {
ObjectInputStream var14 = new ObjectInputStream(var10);
Level var2 = (Level)var14.readObject();
var2.initTransient();
var14.close();
return var2;
}
}
} catch (Exception var9) {
var9.printStackTrace();
(new StringBuilder()).append("Failed to load level: ").append(var9.toString()).toString();
return null;
}
// try {
// DataInputStream var10 = new DataInputStream(new GZIPInputStream(var1));
// int var12 = var10.readInt();
// if(var12 != 656127880) {
// return null;
// } else {
// byte var13 = var10.readByte();
// if(var13 > 2) {
// return null;
// } else if(var13 <= 1) {
// System.out.println("Version is 1!");
// String var15 = var10.readUTF();
// String var16 = var10.readUTF();
// long var7 = var10.readLong();
// short var3 = var10.readShort();
// short var4 = var10.readShort();
// short var5 = var10.readShort();
// byte[] var6 = new byte[var3 * var4 * var5];
// var10.readFully(var6);
// var10.close();
// Level var11 = new Level();
// var11.setData(var3, var5, var4, var6);
// var11.name = var15;
// var11.creator = var16;
// var11.createTime = var7;
// return var11;
// } else {
// ObjectInputStream var14 = new ObjectInputStream(var10);
// Level var2 = (Level)var14.readObject();
// var2.initTransient();
// var14.close();
// return var2;
// }
// }
// } catch (Exception var9) {
// var9.printStackTrace();
// (new StringBuilder()).append("Failed to load level: ").append(var9.toString()).toString();
// return null;
// }
return null;
}
public final Level loadLegacy(InputStream var1) {
if(this.a != null) {
this.a.beginLevelLoading("Loading level");
}
// if(this.a != null) {
// this.a.beginLevelLoading("Loading level");
// }
if(this.a != null) {
this.a.levelLoadUpdate("Reading..");
}
// if(this.a != null) {
// this.a.levelLoadUpdate("Reading..");
// }
try {
DataInputStream var5 = new DataInputStream(new GZIPInputStream(var1));
String var7 = "--";
String var2 = "unknown";
byte[] var3 = new byte[256 << 8 << 6];
var5.readFully(var3);
var5.close();
Level var6 = new Level();
var6.setData(256, 64, 256, var3);
var6.name = var7;
var6.creator = var2;
var6.createTime = 0L;
return var6;
} catch (Exception var4) {
var4.printStackTrace();
(new StringBuilder()).append("Failed to load level: ").append(var4.toString()).toString();
return null;
}
// try {
// DataInputStream var5 = new DataInputStream(new GZIPInputStream(var1));
// String var7 = "--";
// String var2 = "unknown";
// byte[] var3 = new byte[256 << 8 << 6];
// var5.readFully(var3);
// var5.close();
// Level var6 = new Level();
// var6.setData(256, 64, 256, var3);
// var6.name = var7;
// var6.creator = var2;
// var6.createTime = 0L;
// return var6;
// } catch (Exception var4) {
// var4.printStackTrace();
// (new StringBuilder()).append("Failed to load level: ").append(var4.toString()).toString();
// return null;
// }
return null;
}
public static void save(Level var0, OutputStream var1) {
try {
DataOutputStream var3 = new DataOutputStream(new GZIPOutputStream(var1));
var3.writeInt(656127880);
var3.writeByte(2);
ObjectOutputStream var4 = new ObjectOutputStream(var3);
var4.writeObject(var0);
var4.close();
} catch (Exception var2) {
var2.printStackTrace();
}
// try {
// DataOutputStream var3 = new DataOutputStream(new GZIPOutputStream(var1));
// var3.writeInt(656127880);
// var3.writeByte(2);
// ObjectOutputStream var4 = new ObjectOutputStream(var3);
// var4.writeObject(var0);
// var4.close();
// } catch (Exception var2) {
// var2.printStackTrace();
// }
}
public static byte[] loadBlocks(InputStream var0) {
try {
DataInputStream var3 = new DataInputStream(new GZIPInputStream(var0));
byte[] var1 = new byte[var3.readInt()];
var3.readFully(var1);
var3.close();
return var1;
} catch (Exception var2) {
throw new RuntimeException(var2);
}
// try {
// DataInputStream var3 = new DataInputStream(new GZIPInputStream(var0));
// byte[] var1 = new byte[var3.readInt()];
// var3.readFully(var1);
// var3.close();
// return var1;
// } catch (Exception var2) {
// throw new RuntimeException(var2);
// }
return null;
}
}

View File

@ -0,0 +1,43 @@
package com.mojang.minecraft.renderer;
import java.util.ArrayList;
public class TextureLocation {
private String path;
private int glObject;
public TextureLocation(String path) {
this.path = path;
this.glObject = -1;
locations.add(this);
}
public static void freeTextures() {
for (TextureLocation l : locations) {
l.glObject = -1;
}
}
public int getTexturePointer() {
Textures t = new Textures();
if (glObject == -1) {
glObject = t.getTextureId(path);
if (glObject == -1) {
System.err.println("could not load: " + path);
}
}
return glObject;
}
public int bindTexture() {
Textures t = new Textures();
int i = getTexturePointer();
if(i != -1) {
t.bindTexture(i);
}
return i;
}
private static final ArrayList<TextureLocation> locations = new ArrayList();
}