diff --git a/src/main/java/net/PeytonPlayz585/network/Socket.java b/src/main/java/net/PeytonPlayz585/network/Socket.java index 9f7f5b7..8275eac 100644 --- a/src/main/java/net/PeytonPlayz585/network/Socket.java +++ b/src/main/java/net/PeytonPlayz585/network/Socket.java @@ -1,40 +1,49 @@ package net.PeytonPlayz585.network; +import java.io.IOException; + import net.PeytonPlayz585.opengl.GL11; -import java.io.IOException; -import java.io.OutputStream; - public class Socket { - public Socket(String ip) throws IOException { - if(!GL11.EaglerAdapterImpl2.startConnection(ip)) { - throw new IOException("Failed to connect to '" + ip + "'!"); + public Socket(String hostName, int port) throws IOException { + if(!GL11.EaglerAdapterImpl2.startConnection(hostName + ":" + port)) { + IOException e = new IOException("Connection failed: " + hostName + ":" + port); + e.printStackTrace(); + throw e; } } - public void close() { - if(!GL11.EaglerAdapterImpl2.connectionOpen()) { - return; + public Socket(String hostName) throws IOException { + if(!GL11.EaglerAdapterImpl2.startConnection(hostName)) { + IOException e = new IOException("Connection failed: " + hostName); + e.printStackTrace(); + throw e; } - GL11.EaglerAdapterImpl2.endConnection(); - } - - public boolean open() { - return GL11.EaglerAdapterImpl2.connectionOpen(); } public void write(byte[] data) { - if(open()) { + if(socketOpen()) { GL11.EaglerAdapterImpl2.writePacket(data); } } public byte[] read() { - if(open()) { + if(socketOpen()) { return GL11.EaglerAdapterImpl2.readPacket(); + } else { + return null; } - return null; + } + + public void close() { + if(socketOpen()) { + GL11.EaglerAdapterImpl2.endConnection(); + } + } + + public boolean socketOpen() { + return GL11.EaglerAdapterImpl2.connectionOpen(); } -} +} \ No newline at end of file diff --git a/src/main/java/net/minecraft/client/Minecraft.java b/src/main/java/net/minecraft/client/Minecraft.java index 2b41ac0..e12a909 100644 --- a/src/main/java/net/minecraft/client/Minecraft.java +++ b/src/main/java/net/minecraft/client/Minecraft.java @@ -293,11 +293,11 @@ public class Minecraft implements Runnable { this.sndManager.func_338_a(this.thePlayer, this.timer.renderPartialTicks); this.checkGLError("Pre render"); GL11.glEnable(GL11.GL_TEXTURE_2D); - if(this.theWorld != null && !this.theWorld.multiplayerWorld) { + if(this.theWorld != null && !this.theWorld.multiplayerWorld) { while(this.theWorld.func_6465_g()) { } } - + if(this.theWorld != null && this.theWorld.multiplayerWorld) { this.theWorld.func_6465_g(); } diff --git a/src/main/java/net/minecraft/src/EntityRenderer.java b/src/main/java/net/minecraft/src/EntityRenderer.java index de4b9c5..8f7d47a 100644 --- a/src/main/java/net/minecraft/src/EntityRenderer.java +++ b/src/main/java/net/minecraft/src/EntityRenderer.java @@ -287,7 +287,7 @@ public class EntityRenderer { this.func_917_f(var1); } - if(!this.mc.gameSettings.thirdPersonView && !(Keyboard.getEventKey() == 33 && Keyboard.isKeyDown(2))) { + if(!this.mc.gameSettings.thirdPersonView && !Keyboard.isFunctionKeyDown(this.mc.gameSettings.keyBindFunction.keyCode, 2)) { this.field_1395_a.renderItemInFirstPerson(var1); } diff --git a/src/main/java/net/minecraft/src/GuiConnecting.java b/src/main/java/net/minecraft/src/GuiConnecting.java index c75b2fc..632a908 100644 --- a/src/main/java/net/minecraft/src/GuiConnecting.java +++ b/src/main/java/net/minecraft/src/GuiConnecting.java @@ -5,17 +5,34 @@ import net.minecraft.client.Minecraft; public class GuiConnecting extends GuiScreen { private NetClientHandler clientHandler; private boolean cancelled = false; + + private Minecraft minecraft; + private String uri; + private int timer = 0; public GuiConnecting(Minecraft var1, String var2) { + System.out.println("Connecting to " + var2); var1.func_6261_a((World)null); - (new ThreadConnectToServer(this, var1, var2)).start(); + + this.minecraft = var1; + this.uri = var2; } public void updateScreen() { + /* + * Connects AFTER drawing screen, this fixes two issues + * 1. A blank background while the connection is being initialized + * 2. The connection failed screen not showing due to the connecting screen being rendered AFTER the connection failed + */ + if (timer > 2 && this.clientHandler == null) { + (new ThreadConnectToServer(this, this.minecraft, this.uri)).start(); + } if(this.clientHandler != null) { this.clientHandler.processReadPackets(); } - + if(timer >= 1) { + ++timer; + } } protected void keyTyped(char var1, int var2) { @@ -39,6 +56,10 @@ public class GuiConnecting extends GuiScreen { } public void drawScreen(int var1, int var2, float var3) { + if(timer == 0) { + timer = 1; + } + this.drawDefaultBackground(); if(this.clientHandler == null) { this.drawCenteredString(this.fontRenderer, "Connecting to the server...", this.width / 2, this.height / 2 - 50, 16777215); diff --git a/src/main/java/net/minecraft/src/MathHelper.java b/src/main/java/net/minecraft/src/MathHelper.java index 4db1495..2b53c58 100644 --- a/src/main/java/net/minecraft/src/MathHelper.java +++ b/src/main/java/net/minecraft/src/MathHelper.java @@ -1,14 +1,14 @@ package net.minecraft.src; public class MathHelper { - private static float[] SIN_TABLE = new float[65536]; + private static float[] SIN_TABLE = new float[4096]; public static final float sin(float var0) { - return SIN_TABLE[(int)(var0 * 10430.378F) & '\uffff']; + return SIN_TABLE[(int)(var0 * 651.8986F) & 4095]; } public static final float cos(float var0) { - return SIN_TABLE[(int)(var0 * 10430.378F + 16384.0F) & '\uffff']; + return SIN_TABLE[(int)((var0 + ((float)Math.PI / 2F)) * 651.8986F) & 4095]; } public static final float sqrt_float(float var0) { @@ -50,8 +50,12 @@ public class MathHelper { } static { - for(int var0 = 0; var0 < 65536; ++var0) { - SIN_TABLE[var0] = (float)Math.sin((double)var0 * Math.PI * 2.0D / 65536.0D); + for (int j = 0; j < 4096; ++j) { + SIN_TABLE[j] = (float)Math.sin((double)(((float)j + 0.5F) / 4096.0F * ((float)Math.PI * 2F))); + } + + for (int l = 0; l < 360; l += 90) { + SIN_TABLE[(int)((float)l * 11.377778F) & 4095] = (float)Math.sin((double)((float)l * 0.017453292F)); } } diff --git a/src/main/java/net/minecraft/src/NetClientHandler.java b/src/main/java/net/minecraft/src/NetClientHandler.java index 9266dbb..7cb8e72 100644 --- a/src/main/java/net/minecraft/src/NetClientHandler.java +++ b/src/main/java/net/minecraft/src/NetClientHandler.java @@ -3,6 +3,8 @@ package net.minecraft.src; import java.io.IOException; import java.net.UnknownHostException; import net.PeytonPlayz585.EaglercraftRandom; +import net.PeytonPlayz585.network.Socket; +import net.PeytonPlayz585.opengl.GL11; import net.minecraft.client.Minecraft; public class NetClientHandler extends NetHandler { @@ -16,13 +18,31 @@ public class NetClientHandler extends NetHandler { public NetClientHandler(Minecraft var1, String var2) throws IOException, UnknownHostException { this.mc = var1; - this.netManager = new NetworkManager(var2, this); + + String uri = null; + if(var2.startsWith("ws://")) { + uri = var2.substring(5); + }else if(var2.startsWith("wss://")){ + uri = var2.substring(6); + }else if(!var2.contains("://")){ + uri = var2; + if(GL11.EaglerAdapterImpl2.isSSLPage()) { + var2 = "wss://" + var2; + } else { + var2 = "ws://" + var2; + } + }else { + throw new IOException("Invalid URI Protocol!"); + } + + Socket var4 = new Socket(var2); + + this.netManager = new NetworkManager(var4, "Client", this); } public void processReadPackets() { if(!this.disconnected) { this.netManager.readPacket(); - this.netManager.processReadPackets(); } } @@ -315,6 +335,10 @@ public class NetClientHandler extends NetHandler { public void handleHandshake(Packet2Handshake var1) { this.addToSendQueue(new Packet1Login(this.mc.session.username, "Password", 6)); } + + public void handleHandshake() { + this.addToSendQueue(new Packet1Login(this.mc.session.username, "Password", 6)); + } public void disconnect() { this.disconnected = true; diff --git a/src/main/java/net/minecraft/src/NetworkManager.java b/src/main/java/net/minecraft/src/NetworkManager.java index be9a73b..92879b0 100644 --- a/src/main/java/net/minecraft/src/NetworkManager.java +++ b/src/main/java/net/minecraft/src/NetworkManager.java @@ -29,23 +29,9 @@ public class NetworkManager { private int sendQueueByteLength = 0; private int chunkDataSendCounter = 0; - public NetworkManager(String var4, NetHandler var3) throws IOException { - + public NetworkManager(Socket var1, String var2, NetHandler var3) throws IOException { this.netHandler = var3; - String uri = null; - System.out.println(uri); - if(var4.startsWith("ws://")) { - uri = var4.substring(5); - }else if(var4.startsWith("wss://")){ - uri = var4.substring(6); - }else if(!var4.contains("://")){ - uri = var4; - var4 = "ws://" + var4; - }else { - throw new IOException("Invalid URI Protocol!"); - } - - this.field_12258_e = new Socket(var4); + this.field_12258_e = var1; } public void addToSendQueue(Packet var1) { @@ -58,7 +44,8 @@ public class NetworkManager { } else { this.dataPackets.add(var1); } - + sendPacket(); + } } } @@ -129,7 +116,7 @@ public class NetworkManager { readChunks.add(oldChunkBuffer); } - if(this.field_12258_e.open()) { + if(this.field_12258_e.socketOpen()) { byte[] packet; while((packet = this.field_12258_e.read()) != null) { readChunks.add(ByteBuffer.wrap(packet)); @@ -159,13 +146,12 @@ public class NetworkManager { } else { this.networkShutdown("End of stream"); } + + processReadPackets(); } catch(EOFException e) { stream.reset(); break; - } catch(Exception e) { - continue; } catch(Throwable t) { - continue; } } diff --git a/src/main/java/net/minecraft/src/ThreadConnectToServer.java b/src/main/java/net/minecraft/src/ThreadConnectToServer.java index 83801a1..70dc839 100644 --- a/src/main/java/net/minecraft/src/ThreadConnectToServer.java +++ b/src/main/java/net/minecraft/src/ThreadConnectToServer.java @@ -20,14 +20,14 @@ class ThreadConnectToServer { return; } - GuiConnecting.getNetClientHandler(this.connectingGui).addToSendQueue(new Packet2Handshake(this.mc.session.username)); - } catch (Exception var4) { + GuiConnecting.getNetClientHandler(this.connectingGui).handleHandshake(); + } catch (Throwable var4) { if(GuiConnecting.isCancelled(this.connectingGui)) { return; } - var4.printStackTrace(); this.mc.displayGuiScreen(new GuiConnectFailed("Failed to connect to the server", var4.toString())); + var4.printStackTrace(); } } diff --git a/src/main/java/net/minecraft/src/World.java b/src/main/java/net/minecraft/src/World.java index 2148784..7e2e9a6 100644 --- a/src/main/java/net/minecraft/src/World.java +++ b/src/main/java/net/minecraft/src/World.java @@ -1587,10 +1587,10 @@ public class World implements IBlockAccess { } else { ++this.field_4204_J; + boolean var2; try { int var1 = 5000; - boolean var2; while(this.field_1051_z.size() > 0) { --var1; if(var1 <= 0) { @@ -1602,10 +1602,11 @@ public class World implements IBlockAccess { } var2 = false; - return var2; } finally { --this.field_4204_J; } + + return var2; } }