Remove, fixed and optimize code

This commit is contained in:
PeytonPlayz595 2023-10-06 20:32:58 -04:00
parent b2123c8fa8
commit 8a88f1721f
12 changed files with 94 additions and 668 deletions

View File

@ -1,5 +1,50 @@
package net.PeytonPlayz585;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.UUID;
import org.lwjgl.opengl.Display;
import org.teavm.jso.JSBody;
import org.teavm.jso.browser.Window;
import org.teavm.jso.dom.html.HTMLElement;
import net.PeytonPlayz585.opengl.LWJGLMain;
import net.minecraft.src.Minecraft;
import net.minecraft.src.Session;
public class Main {
public static HTMLElement rootElement = null;
public static Minecraft instance = null;
private static Thread mcThread = null;
@JSBody(params = { }, script = "return window.minecraftOpts;")
public static native String[] getOpts();
public static void main(String args[]) {
String[] e = getOpts();
try {
try {
LWJGLMain.initializeContext(rootElement = Window.current().getDocument().getElementById(e[0]), e[1]);
}catch(Exception ex) {
return;
}
}catch(Throwable ex2) {
StringWriter s = new StringWriter();
ex2.printStackTrace(new PrintWriter(s));
return;
}
//LocalStorageManager.loadStorage();
run0();
}
public static void run0() {
instance = new Minecraft(Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight(), false);
instance.session = new Session("Player", UUID.randomUUID().toString());
instance.session.mpPassParameter = UUID.randomUUID().toString();
mcThread = new Thread(instance, "Minecraft main thread");
mcThread.start();
}
}

View File

@ -1,105 +0,0 @@
package net.minecraft.client;
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Canvas;
import net.minecraft.src.CanvasMinecraftApplet;
import net.minecraft.src.Minecraft;
import net.minecraft.src.MinecraftAppletImpl;
import net.minecraft.src.Session;
public class MinecraftApplet extends Applet {
private Canvas mcCanvas;
private Minecraft mc;
private Thread mcThread = null;
public void init() {
this.mcCanvas = new CanvasMinecraftApplet(this);
boolean var1 = false;
if(this.getParameter("fullscreen") != null) {
var1 = this.getParameter("fullscreen").equalsIgnoreCase("true");
}
this.mc = new MinecraftAppletImpl(this, this, this.mcCanvas, this, this.getWidth(), this.getHeight(), var1);
this.mc.minecraftUri = this.getDocumentBase().getHost();
if(this.getDocumentBase().getPort() > 0) {
this.mc.minecraftUri = this.mc.minecraftUri + ":" + this.getDocumentBase().getPort();
}
if(this.getParameter("username") != null && this.getParameter("sessionid") != null) {
this.mc.session = new Session(this.getParameter("username"), this.getParameter("sessionid"));
if(this.getParameter("mppass") != null) {
this.mc.session.mpPassParameter = this.getParameter("mppass");
}
}
if(this.getParameter("loadmap_user") != null && this.getParameter("loadmap_id") != null) {
this.mc.objectMouseOverString = this.getParameter("loadmap_user");
this.mc.rightClickDelayTimer = Integer.parseInt(this.getParameter("loadmap_id"));
} else if(this.getParameter("server") != null && this.getParameter("port") != null) {
this.mc.setServer(this.getParameter("server"), Integer.parseInt(this.getParameter("port")));
}
this.mc.appletMode = true;
this.setLayout(new BorderLayout());
this.add(this.mcCanvas, "Center");
this.mcCanvas.setFocusable(true);
this.validate();
}
public void startMainThread() {
if(this.mcThread == null) {
this.mcThread = new Thread(this.mc, "Minecraft main thread");
this.mcThread.start();
}
}
public void start() {
if(this.mc != null) {
this.mc.isGamePaused = false;
}
}
public void stop() {
if(this.mc != null) {
this.mc.isGamePaused = true;
}
}
public void destroy() {
this.shutdown();
}
public void shutdown() {
if(this.mcThread != null) {
this.mc.shutdown();
try {
this.mcThread.join(10000L);
} catch (InterruptedException var4) {
try {
this.mc.shutdownMinecraftApplet();
} catch (Exception var3) {
var3.printStackTrace();
}
}
this.mcThread = null;
}
}
public void clearApplet() {
this.mcCanvas = null;
this.mc = null;
this.mcThread = null;
try {
this.removeAll();
this.validate();
} catch (Exception var2) {
}
}
}

View File

@ -1,22 +0,0 @@
package net.minecraft.isom;
import java.applet.Applet;
import java.awt.BorderLayout;
import net.minecraft.src.CanvasIsomPreview;
public class IsomPreviewApplet extends Applet {
private CanvasIsomPreview isomCanvas = new CanvasIsomPreview();
public IsomPreviewApplet() {
this.setLayout(new BorderLayout());
this.add(this.isomCanvas, "Center");
}
public void start() {
this.isomCanvas.start();
}
public void stop() {
this.isomCanvas.stop();
}
}

View File

@ -1,11 +0,0 @@
package net.minecraft.src;
import java.awt.Canvas;
import java.awt.Dimension;
class CanvasCrashReport extends Canvas {
public CanvasCrashReport(int var1) {
this.setPreferredSize(new Dimension(var1, var1));
this.setMinimumSize(new Dimension(var1, var1));
}
}

View File

@ -1,378 +0,0 @@
package net.minecraft.src;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferStrategy;
import java.awt.image.ImageObserver;
import java.io.File;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
public class CanvasIsomPreview extends Canvas implements KeyListener, MouseListener, MouseMotionListener, Runnable {
private int currentRender = 0;
private int zoomLevel = 2;
private boolean displayHelpText = true;
private World level;
private File dataFolder = this.getMinecraftDir();
private boolean running = true;
private List zonesToRender = Collections.synchronizedList(new LinkedList());
private IsoImageBuffer[][] zoneMap = new IsoImageBuffer[64][64];
private int translateX;
private int translateY;
private int xPosition;
private int yPosition;
public File getMinecraftDir() {
if(this.dataFolder == null) {
this.dataFolder = this.getWorkingDirectory("minecraft");
}
return this.dataFolder;
}
public File getWorkingDirectory(String var1) {
String var2 = System.getProperty("user.home", ".");
File var3;
switch(OSMapIsom.osValues[getPlatform().ordinal()]) {
case 1:
case 2:
var3 = new File(var2, '.' + var1 + '/');
break;
case 3:
String var4 = System.getenv("APPDATA");
if(var4 != null) {
var3 = new File(var4, "." + var1 + '/');
} else {
var3 = new File(var2, '.' + var1 + '/');
}
break;
case 4:
var3 = new File(var2, "Library/Application Support/" + var1);
break;
default:
var3 = new File(var2, var1 + '/');
}
if(!var3.exists() && !var3.mkdirs()) {
throw new RuntimeException("The working directory could not be created: " + var3);
} else {
return var3;
}
}
private static EnumOSIsom getPlatform() {
String var0 = System.getProperty("os.name").toLowerCase();
return var0.contains("win") ? EnumOSIsom.windows : (var0.contains("mac") ? EnumOSIsom.macos : (var0.contains("solaris") ? EnumOSIsom.solaris : (var0.contains("sunos") ? EnumOSIsom.solaris : (var0.contains("linux") ? EnumOSIsom.linux : (var0.contains("unix") ? EnumOSIsom.linux : EnumOSIsom.unknown)))));
}
public CanvasIsomPreview() {
for(int var1 = 0; var1 < 64; ++var1) {
for(int var2 = 0; var2 < 64; ++var2) {
this.zoneMap[var1][var2] = new IsoImageBuffer((World)null, var1, var2);
}
}
this.addMouseListener(this);
this.addMouseMotionListener(this);
this.addKeyListener(this);
this.setFocusable(true);
this.requestFocus();
this.setBackground(Color.red);
}
public void loadWorld(String var1) {
this.translateX = this.translateY = 0;
this.level = new WorldIso(this, new File(this.dataFolder, "saves"), var1);
this.level.skylightSubtracted = 0;
List var2 = this.zonesToRender;
synchronized(var2) {
this.zonesToRender.clear();
for(int var3 = 0; var3 < 64; ++var3) {
for(int var4 = 0; var4 < 64; ++var4) {
this.zoneMap[var3][var4].setWorldAndChunkPosition(this.level, var3, var4);
}
}
}
}
private void setBrightness(int var1) {
List var2 = this.zonesToRender;
synchronized(var2) {
this.level.skylightSubtracted = var1;
this.zonesToRender.clear();
for(int var3 = 0; var3 < 64; ++var3) {
for(int var4 = 0; var4 < 64; ++var4) {
this.zoneMap[var3][var4].setWorldAndChunkPosition(this.level, var3, var4);
}
}
}
}
public void start() {
(new ThreadRunIsoClient(this)).start();
for(int var1 = 0; var1 < 1; ++var1) {
(new Thread(this)).start();
}
}
public void stop() {
this.running = false;
}
private IsoImageBuffer getZone(int var1, int var2) {
int var3 = var1 & 63;
int var4 = var2 & 63;
IsoImageBuffer var5 = this.zoneMap[var3][var4];
if(var5.chunkX == var1 && var5.chunkZ == var2) {
return var5;
} else {
List var6 = this.zonesToRender;
synchronized(var6) {
this.zonesToRender.remove(var5);
}
var5.setChunkPosition(var1, var2);
return var5;
}
}
public void run() {
TerrainTextureManager var1 = new TerrainTextureManager();
while(this.running) {
IsoImageBuffer var2 = null;
List var3 = this.zonesToRender;
synchronized(var3) {
if(this.zonesToRender.size() > 0) {
var2 = (IsoImageBuffer)this.zonesToRender.remove(0);
}
}
if(var2 != null) {
if(this.currentRender - var2.lastVisible < 2) {
var1.render(var2);
this.repaint();
} else {
var2.addedToRenderQueue = false;
}
}
try {
Thread.sleep(2L);
} catch (InterruptedException var5) {
var5.printStackTrace();
}
}
}
public void update(Graphics var1) {
}
public void paint(Graphics var1) {
}
public void render() {
BufferStrategy var1 = this.getBufferStrategy();
if(var1 == null) {
this.createBufferStrategy(2);
} else {
this.render((Graphics2D)var1.getDrawGraphics());
var1.show();
}
}
public void render(Graphics2D var1) {
++this.currentRender;
AffineTransform var2 = var1.getTransform();
var1.setClip(0, 0, this.getWidth(), this.getHeight());
var1.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
var1.translate(this.getWidth() / 2, this.getHeight() / 2);
var1.scale((double)this.zoomLevel, (double)this.zoomLevel);
var1.translate(this.translateX, this.translateY);
if(this.level != null) {
var1.translate(-(this.level.spawnX + this.level.spawnZ), -(-this.level.spawnX + this.level.spawnZ) + 64);
}
Rectangle var3 = var1.getClipBounds();
var1.setColor(new Color(-15724512));
var1.fillRect(var3.x, var3.y, var3.width, var3.height);
byte var4 = 16;
byte var5 = 3;
int var6 = var3.x / var4 / 2 - 2 - var5;
int var7 = (var3.x + var3.width) / var4 / 2 + 1 + var5;
int var8 = var3.y / var4 - 1 - var5 * 2;
int var9 = (var3.y + var3.height + 16 + 128) / var4 + 1 + var5 * 2;
int var10;
for(var10 = var8; var10 <= var9; ++var10) {
for(int var11 = var6; var11 <= var7; ++var11) {
int var12 = var11 - (var10 >> 1);
int var13 = var11 + (var10 + 1 >> 1);
IsoImageBuffer var14 = this.getZone(var12, var13);
var14.lastVisible = this.currentRender;
if(!var14.rendered) {
if(!var14.addedToRenderQueue) {
var14.addedToRenderQueue = true;
this.zonesToRender.add(var14);
}
} else {
var14.addedToRenderQueue = false;
if(!var14.noContent) {
int var15 = var11 * var4 * 2 + (var10 & 1) * var4;
int var16 = var10 * var4 - 128 - 16;
var1.drawImage(var14.image, var15, var16, (ImageObserver)null);
}
}
}
}
if(this.displayHelpText) {
var1.setTransform(var2);
var10 = this.getHeight() - 32 - 4;
var1.setColor(new Color(Integer.MIN_VALUE, true));
var1.fillRect(4, this.getHeight() - 32 - 4, this.getWidth() - 8, 32);
var1.setColor(Color.WHITE);
String var17 = "F1 - F5: load levels | 0-9: Set time of day | Space: return to spawn | Double click: zoom | Escape: hide this text";
var1.drawString(var17, this.getWidth() / 2 - var1.getFontMetrics().stringWidth(var17) / 2, var10 + 20);
}
var1.dispose();
}
public void mouseDragged(MouseEvent var1) {
int var2 = var1.getX() / this.zoomLevel;
int var3 = var1.getY() / this.zoomLevel;
this.translateX += var2 - this.xPosition;
this.translateY += var3 - this.yPosition;
this.xPosition = var2;
this.yPosition = var3;
this.repaint();
}
public void mouseMoved(MouseEvent var1) {
}
public void mouseClicked(MouseEvent var1) {
if(var1.getClickCount() == 2) {
this.zoomLevel = 3 - this.zoomLevel;
this.repaint();
}
}
public void mouseEntered(MouseEvent var1) {
}
public void mouseExited(MouseEvent var1) {
}
public void mousePressed(MouseEvent var1) {
int var2 = var1.getX() / this.zoomLevel;
int var3 = var1.getY() / this.zoomLevel;
this.xPosition = var2;
this.yPosition = var3;
}
public void mouseReleased(MouseEvent var1) {
}
public void keyPressed(KeyEvent var1) {
if(var1.getKeyCode() == 48) {
this.setBrightness(11);
}
if(var1.getKeyCode() == 49) {
this.setBrightness(10);
}
if(var1.getKeyCode() == 50) {
this.setBrightness(9);
}
if(var1.getKeyCode() == 51) {
this.setBrightness(7);
}
if(var1.getKeyCode() == 52) {
this.setBrightness(6);
}
if(var1.getKeyCode() == 53) {
this.setBrightness(5);
}
if(var1.getKeyCode() == 54) {
this.setBrightness(3);
}
if(var1.getKeyCode() == 55) {
this.setBrightness(2);
}
if(var1.getKeyCode() == 56) {
this.setBrightness(1);
}
if(var1.getKeyCode() == 57) {
this.setBrightness(0);
}
if(var1.getKeyCode() == 112) {
this.loadWorld("World1");
}
if(var1.getKeyCode() == 113) {
this.loadWorld("World2");
}
if(var1.getKeyCode() == 114) {
this.loadWorld("World3");
}
if(var1.getKeyCode() == 115) {
this.loadWorld("World4");
}
if(var1.getKeyCode() == 116) {
this.loadWorld("World5");
}
if(var1.getKeyCode() == 32) {
this.translateX = this.translateY = 0;
}
if(var1.getKeyCode() == 27) {
this.displayHelpText = !this.displayHelpText;
}
this.repaint();
}
public void keyReleased(KeyEvent var1) {
}
public void keyTyped(KeyEvent var1) {
}
static boolean a(CanvasIsomPreview var0) {
return var0.running;
}
}

View File

@ -1,22 +0,0 @@
package net.minecraft.src;
import java.awt.Canvas;
import net.minecraft.client.MinecraftApplet;
public class CanvasMinecraftApplet extends Canvas {
final MinecraftApplet mcApplet;
public CanvasMinecraftApplet(MinecraftApplet var1) {
this.mcApplet = var1;
}
public synchronized void addNotify() {
super.addNotify();
this.mcApplet.startMainThread();
}
public synchronized void removeNotify() {
this.mcApplet.shutdown();
super.removeNotify();
}
}

View File

@ -1,29 +0,0 @@
package net.minecraft.src;
import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
import java.io.IOException;
import javax.imageio.ImageIO;
class CanvasMojangLogo extends Canvas {
private BufferedImage logo;
public CanvasMojangLogo() {
try {
this.logo = ImageIO.read(PanelCrashReport.class.getResource("/gui/logo.png"));
} catch (IOException var2) {
}
byte var1 = 100;
this.setPreferredSize(new Dimension(var1, var1));
this.setMinimumSize(new Dimension(var1, var1));
}
public void paint(Graphics var1) {
super.paint(var1);
var1.drawImage(this.logo, this.getWidth() / 2 - this.logo.getWidth() / 2, 32, (ImageObserver)null);
}
}

View File

@ -1,58 +1,60 @@
package net.minecraft.src;
public class MathHelper {
private static float[] SIN_TABLE = new float[65536];
private static final float[] SIN_TABLE = new float[65536];
private static final float SIN_CONVERSION_FACTOR = 10430.378F;
private static final float COS_CONVERSION_FACTOR = 16384.0F;
private static final float INVERSE_SIN_TABLE_LENGTH = 1.0F / SIN_TABLE.length;
public static final float sin(float var0) {
return SIN_TABLE[(int)(var0 * 10430.378F) & '\uffff'];
}
static {
for (int i = 0; i < SIN_TABLE.length; ++i) {
SIN_TABLE[i] = (float) Math.sin(i * 2 * Math.PI * INVERSE_SIN_TABLE_LENGTH);
}
}
public static final float cos(float var0) {
return SIN_TABLE[(int)(var0 * 10430.378F + 16384.0F) & '\uffff'];
}
public static final float sin(float var0) {
return SIN_TABLE[(int) (var0 * SIN_CONVERSION_FACTOR) & 65535];
}
public static final float sqrt_float(float var0) {
return (float)Math.sqrt((double)var0);
}
public static final float cos(float var0) {
return SIN_TABLE[(int) (var0 * SIN_CONVERSION_FACTOR + COS_CONVERSION_FACTOR) & 65535];
}
public static final float sqrt_double(double var0) {
return (float)Math.sqrt(var0);
}
public static final float sqrt_float(float var0) {
return (float) Math.sqrt((double) var0);
}
public static int floor_float(float var0) {
int var1 = (int)var0;
return var0 < (float)var1 ? var1 - 1 : var1;
}
public static final float sqrt_double(double var0) {
return (float) Math.sqrt(var0);
}
public static int floor_double(double var0) {
int var2 = (int)var0;
return var0 < (double)var2 ? var2 - 1 : var2;
}
public static int floor_float(float var0) {
int var1 = (int) var0;
return var0 < (float) var1 ? var1 - 1 : var1;
}
public static float abs(float var0) {
return var0 >= 0.0F ? var0 : -var0;
}
public static int floor_double(double var0) {
int var2 = (int) var0;
return var0 < (double) var2 ? var2 - 1 : var2;
}
public static double abs_max(double var0, double var2) {
if(var0 < 0.0D) {
var0 = -var0;
}
public static float abs(float var0) {
return var0 >= 0.0F ? var0 : -var0;
}
if(var2 < 0.0D) {
var2 = -var2;
}
public static double abs_max(double var0, double var2) {
if (var0 < 0.0D) {
var0 = -var0;
}
return var0 > var2 ? var0 : var2;
}
if (var2 < 0.0D) {
var2 = -var2;
}
public static int bucketInt(int var0, int var1) {
return var0 < 0 ? -((-var0 - 1) / var1) - 1 : var0 / var1;
}
return var0 > var2 ? var0 : var2;
}
static {
for(int var0 = 0; var0 < 65536; ++var0) {
SIN_TABLE[var0] = (float)Math.sin((double)var0 * Math.PI * 2.0D / 65536.0D);
}
}
}
public static int bucketInt(int var0, int var1) {
return var0 < 0 ? -((-var0 - 1) / var1) - 1 : var0 / var1;
}
}

View File

@ -9,7 +9,7 @@ import org.lwjgl.opengl.GL11;
import net.PeytonPlayz585.opengl.LWJGLMain;
public abstract class Minecraft implements Runnable {
public class Minecraft implements Runnable {
public PlayerController playerController = new PlayerControllerSP(this);
private boolean fullscreen = false;
public int displayWidth;
@ -21,7 +21,6 @@ public abstract class Minecraft implements Runnable {
public EffectRenderer effectRenderer;
public Session session = null;
public String minecraftUri;
public boolean appletMode = true;
public volatile boolean isGamePaused = false;
public RenderEngine renderEngine;
public FontRenderer fontRenderer;
@ -66,8 +65,6 @@ public abstract class Minecraft implements Runnable {
this.fullscreen = var6;
}
public abstract void displayUnexpectedThrowable(UnexpectedThrowable var1);
public void setServer(String var1, int var2) {
}
@ -254,7 +251,7 @@ public abstract class Minecraft implements Runnable {
this.startGame();
} catch (Exception var10) {
var10.printStackTrace();
this.displayUnexpectedThrowable(new UnexpectedThrowable("Failed to start game", var10));
new UnexpectedThrowable("Failed to start game", var10);
return;
}
@ -334,7 +331,7 @@ public abstract class Minecraft implements Runnable {
} catch (MinecraftError var11) {
} catch (Exception var12) {
var12.printStackTrace();
this.displayUnexpectedThrowable(new UnexpectedThrowable("Unexpected error", var12));
new UnexpectedThrowable("Unexpected error", var12);
} finally {
this.shutdownMinecraftApplet();
}

View File

@ -1,20 +1,13 @@
package net.minecraft.src;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.Panel;
import java.awt.TextArea;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.lwjgl.opengl.GL11;
public class PanelCrashReport extends Panel {
public class PanelCrashReport {
public PanelCrashReport(UnexpectedThrowable var1) {
this.setBackground(new Color(3028036));
this.setLayout(new BorderLayout());
StringWriter var2 = new StringWriter();
var1.exception.printStackTrace(new PrintWriter(var2));
String var3 = var2.toString();
@ -73,12 +66,5 @@ public class PanelCrashReport extends Panel {
var6 = var6 + "--- END ERROR REPORT " + Integer.toHexString(var6.hashCode()) + " ----------\n";
var6 = var6 + "\n";
var6 = var6 + "\n";
TextArea var7 = new TextArea(var6, 0, 0, 1);
var7.setFont(new Font("Monospaced", 0, 12));
this.add(new CanvasMojangLogo(), "North");
this.add(new CanvasCrashReport(80), "East");
this.add(new CanvasCrashReport(80), "West");
this.add(new CanvasCrashReport(100), "South");
this.add(var7, "Center");
}
}

View File

@ -1,21 +0,0 @@
package net.minecraft.src;
class ThreadRunIsoClient extends Thread {
final CanvasIsomPreview isoCanvas;
ThreadRunIsoClient(CanvasIsomPreview var1) {
this.isoCanvas = var1;
}
public void run() {
while(CanvasIsomPreview.a(this.isoCanvas)) {
this.isoCanvas.render();
try {
Thread.sleep(1L);
} catch (Exception var2) {
}
}
}
}

View File

@ -1,16 +0,0 @@
package net.minecraft.src;
import java.io.File;
class WorldIso extends World {
final CanvasIsomPreview isomPreview;
WorldIso(CanvasIsomPreview var1, File var2, String var3) {
super(var2, var3);
this.isomPreview = var1;
}
protected IChunkProvider getChunkProvider(File var1) {
return new ChunkProviderIso(this, new ChunkLoader(var1, false));
}
}