Compare commits
10 Commits
d2d90d4887
...
3d5072a414
Author | SHA1 | Date | |
---|---|---|---|
|
3d5072a414 | ||
|
b22376e5af | ||
|
3cd22f664f | ||
|
2206e940a4 | ||
|
0a9e4ea3f3 | ||
|
acab40399f | ||
|
f4bb2bc8ce | ||
|
e80061e7ba | ||
|
8d441465b1 | ||
|
57638cdcd2 |
File diff suppressed because one or more lines are too long
|
@ -6,7 +6,7 @@
|
|||
<script type="text/javascript" charset="utf-8" src="app.js"></script>
|
||||
<script type = text/javascript>
|
||||
if(document.location.href.startsWith("file:")) {
|
||||
alert("Offline Download is not supported yet, please upload all the game files to a HTTP(s) server");
|
||||
alert("Offline Download is not supported, please upload all the game files to a HTTP(s) server");
|
||||
} else {
|
||||
window.addEventListener("load", function() {
|
||||
window.classicConfig = ["game","resources.mc"];
|
||||
|
@ -17,4 +17,4 @@
|
|||
</head>
|
||||
<body style="margin:0px;width:100vw;height:100vh;" id="game">
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.mojang.minecraft.level.liquid.LiquidType;
|
|||
import com.mojang.minecraft.level.tile.Block;
|
||||
import com.mojang.minecraft.level.tile.Tile$SoundType;
|
||||
import com.mojang.minecraft.model.Vec3D;
|
||||
import com.mojang.minecraft.net.PositionUpdate;
|
||||
import com.mojang.minecraft.phys.AABB;
|
||||
import net.PeytonPlayz585.math.MathHelper;
|
||||
import net.PeytonPlayz595.nbt.NBTTagCompound;
|
||||
|
@ -88,6 +89,20 @@ public abstract class Entity implements Serializable {
|
|||
this.bbWidth = var1;
|
||||
this.bbHeight = var2;
|
||||
}
|
||||
|
||||
public void setPos(PositionUpdate var1) {
|
||||
if(var1.position) {
|
||||
this.setPos(var1.x, var1.y, var1.z);
|
||||
} else {
|
||||
this.setPos(this.x, this.y, this.z);
|
||||
}
|
||||
|
||||
if(var1.rotation) {
|
||||
this.setRot(var1.yaw, var1.pitch);
|
||||
} else {
|
||||
this.setRot(this.yRot, this.xRot);
|
||||
}
|
||||
}
|
||||
|
||||
protected void setRot(float var1, float var2) {
|
||||
this.yRot = var1;
|
||||
|
|
|
@ -7,7 +7,6 @@ import com.mojang.minecraft.gui.*;
|
|||
import com.mojang.minecraft.item.Arrow;
|
||||
import com.mojang.minecraft.item.Item;
|
||||
import com.mojang.minecraft.level.Level;
|
||||
import com.mojang.minecraft.level.LevelIO;
|
||||
import com.mojang.minecraft.level.generator.LevelGenerator;
|
||||
import com.mojang.minecraft.level.liquid.LiquidType;
|
||||
import com.mojang.minecraft.level.tile.Block;
|
||||
|
@ -16,6 +15,9 @@ import com.mojang.minecraft.model.HumanoidModel;
|
|||
import com.mojang.minecraft.model.ModelManager;
|
||||
import com.mojang.minecraft.model.ModelPart;
|
||||
import com.mojang.minecraft.model.Vec3D;
|
||||
import com.mojang.minecraft.net.NetworkManager;
|
||||
import com.mojang.minecraft.net.NetworkPlayer;
|
||||
import com.mojang.minecraft.net.PacketType;
|
||||
import com.mojang.minecraft.particle.Particle;
|
||||
import com.mojang.minecraft.particle.ParticleManager;
|
||||
import com.mojang.minecraft.particle.WaterDropParticle;
|
||||
|
@ -24,6 +26,7 @@ import com.mojang.minecraft.player.InputHandlerImpl;
|
|||
import com.mojang.minecraft.player.Player;
|
||||
import com.mojang.minecraft.render.*;
|
||||
import com.mojang.minecraft.render.Renderer;
|
||||
import com.mojang.net.NetworkHandler;
|
||||
|
||||
import net.PeytonPlayz585.level.LevelUtils;
|
||||
import net.PeytonPlayz585.math.MathHelper;
|
||||
|
@ -33,18 +36,13 @@ import net.lax1dude.eaglercraft.adapter.Tessellator;
|
|||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
import java.nio.IntBuffer;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
public final class Minecraft implements Runnable {
|
||||
public final class Minecraft {
|
||||
|
||||
public GameMode gamemode = new SurvivalGameMode(this);
|
||||
public int width;
|
||||
|
@ -62,17 +60,15 @@ public final class Minecraft implements Runnable {
|
|||
public GuiScreen currentScreen = null;
|
||||
public ProgressBarDisplay progressBar = new ProgressBarDisplay(this);
|
||||
public Renderer renderer = new Renderer(this);
|
||||
public LevelIO levelIo;
|
||||
private int ticks;
|
||||
private int blockHitTime;
|
||||
public String levelName;
|
||||
public int levelId;
|
||||
public HUDScreen hud;
|
||||
public boolean online;
|
||||
public NetworkManager networkManager;
|
||||
public MovingObjectPosition selected;
|
||||
public static GameSettings settings;
|
||||
String server;
|
||||
int port;
|
||||
volatile boolean running;
|
||||
public String debug;
|
||||
public boolean hasMouse;
|
||||
|
@ -80,12 +76,10 @@ public final class Minecraft implements Runnable {
|
|||
public boolean raining;
|
||||
private static Tessellator tessellator = Tessellator.instance;
|
||||
public static Minecraft minecraft;
|
||||
public Entity field_22009_h;
|
||||
public int timeSinceLastSaved = 0;
|
||||
|
||||
|
||||
public Minecraft() {
|
||||
this.levelIo = new LevelIO(this.progressBar);
|
||||
this.ticks = 0;
|
||||
this.blockHitTime = 0;
|
||||
this.levelName = null;
|
||||
|
@ -93,14 +87,11 @@ public final class Minecraft implements Runnable {
|
|||
this.online = false;
|
||||
new HumanoidModel(0.0F);
|
||||
this.selected = null;
|
||||
this.server = null;
|
||||
this.port = 0;
|
||||
this.running = false;
|
||||
this.debug = "";
|
||||
this.hasMouse = false;
|
||||
this.lastClick = 0;
|
||||
this.raining = false;
|
||||
new SleepForeverThread(this);
|
||||
this.width = GL11.getCanvasWidth();
|
||||
this.height = GL11.getCanvasHeight();
|
||||
}
|
||||
|
@ -111,14 +102,16 @@ public final class Minecraft implements Runnable {
|
|||
this.currentScreen.onClose();
|
||||
}
|
||||
|
||||
if(var1 == null && this.player.health <= 0) {
|
||||
if(var1 == null && level != null && player != null && this.player.health <= 0) {
|
||||
var1 = new GameOverScreen();
|
||||
}
|
||||
|
||||
this.currentScreen = (GuiScreen)var1;
|
||||
if(var1 != null) {
|
||||
if(this.hasMouse) {
|
||||
this.player.releaseAllKeys();
|
||||
if(level != null) {
|
||||
this.player.releaseAllKeys();
|
||||
}
|
||||
this.hasMouse = false;
|
||||
GL11.mouseSetGrabbed(false);
|
||||
}
|
||||
|
@ -172,12 +165,7 @@ public final class Minecraft implements Runnable {
|
|||
Item.initModels();
|
||||
Mob.modelCache = new ModelManager();
|
||||
GL11.glViewport(0, 0, this.width, this.height);
|
||||
Level level1 = new LevelUtils().load();
|
||||
if(level1 == null) {
|
||||
this.generateLevel(1);
|
||||
} else {
|
||||
this.setLevel(level1, true);
|
||||
}
|
||||
this.setCurrentScreen(new MainMenu());
|
||||
this.particleManager = new ParticleManager(this.level);
|
||||
checkGLError("Post startup");
|
||||
this.hud = new HUDScreen(this, this.width, this.height);
|
||||
|
@ -441,24 +429,13 @@ public final class Minecraft implements Runnable {
|
|||
var74 = var116.yo + (var116.y - var116.yo) * var80;
|
||||
var33 = var116.zo + (var116.z - var116.zo) * var80;
|
||||
GL11.glTranslatef(-var69, -var74, -var33);
|
||||
Frustrum var76 = new Frustrum();
|
||||
if(field_22009_h != this.player) {
|
||||
field_22009_h = player;
|
||||
float f = this.timer.elapsedTicks;
|
||||
double d = field_22009_h.x + (field_22009_h.x - field_22009_h.x) * (double) f;
|
||||
double d1 = field_22009_h.y + (field_22009_h.y - field_22009_h.y) * (double) f;
|
||||
double d2 = field_22009_h.z + (field_22009_h.z - field_22009_h.z) * (double) f;
|
||||
ClippingHelperImplementation.getInstance();
|
||||
Frustrum frustrum = new Frustrum();
|
||||
frustrum.setPosition(d, d1, d2);
|
||||
var76 = frustrum;
|
||||
System.out.println("yee");
|
||||
}
|
||||
Frustrum var76 = FrustrumImpl.update();
|
||||
Frustrum var100 = var76;
|
||||
LevelRenderer var101 = var82.minecraft.levelRenderer;
|
||||
|
||||
int var98;
|
||||
for(var98 = 0; var98 < var101.chunkCache.length; ++var98) {
|
||||
var101.chunkCache[var98].clip(var76);
|
||||
var101.chunkCache[var98].clip(var100);
|
||||
}
|
||||
|
||||
var101 = var82.minecraft.levelRenderer;
|
||||
|
@ -905,7 +882,7 @@ public final class Minecraft implements Runnable {
|
|||
}
|
||||
|
||||
public final void grabMouse() {
|
||||
if(!GL11.isFocused()) {
|
||||
if(!GL11.isFocused() || level == null) {
|
||||
return;
|
||||
}
|
||||
if (GL11.isPointerLocked2()) {
|
||||
|
@ -930,7 +907,7 @@ public final class Minecraft implements Runnable {
|
|||
}
|
||||
|
||||
public final void pause() {
|
||||
if(this.currentScreen == null) {
|
||||
if(this.currentScreen == null && level != null) {
|
||||
this.setCurrentScreen(new PauseScreen());
|
||||
}
|
||||
}
|
||||
|
@ -1008,6 +985,10 @@ public final class Minecraft implements Runnable {
|
|||
return;
|
||||
}
|
||||
|
||||
if(this.isOnline()) {
|
||||
this.networkManager.sendBlockChange(var3, var4, var5, var1, var10);
|
||||
}
|
||||
|
||||
this.level.netSetTile(var3, var4, var5, var10);
|
||||
var2 = this.renderer.heldBlock;
|
||||
this.renderer.heldBlock.pos = 0.0F;
|
||||
|
@ -1062,6 +1043,254 @@ public final class Minecraft implements Runnable {
|
|||
int var40;
|
||||
int var46;
|
||||
int var45;
|
||||
if(this.networkManager != null && !(this.currentScreen instanceof ErrorScreen)) {
|
||||
if(!this.networkManager.isConnected()) {
|
||||
this.progressBar.setTitle("Connecting..");
|
||||
this.progressBar.setProgress(0);
|
||||
} else {
|
||||
NetworkManager var20 = this.networkManager;
|
||||
if(this.networkManager.successful) {
|
||||
NetworkHandler var18 = var20.netHandler;
|
||||
if(var18.channel.connectionOpen()) {
|
||||
try {
|
||||
NetworkHandler var22 = var20.netHandler;
|
||||
var20.netHandler.channel.read(var22.in);
|
||||
var4 = 0;
|
||||
|
||||
while(var22.in.position() > 0 && var4++ != 100) {
|
||||
var22.in.flip();
|
||||
byte var5 = var22.in.get(0);
|
||||
PacketType var6;
|
||||
if((var6 = PacketType.packets[var5]) == null) {
|
||||
throw new IOException("Bad command: " + var5);
|
||||
}
|
||||
|
||||
if(var22.in.remaining() < var6.length + 1) {
|
||||
var22.in.compact();
|
||||
break;
|
||||
}
|
||||
|
||||
var22.in.get();
|
||||
Object[] var7 = new Object[var6.params.length];
|
||||
|
||||
for(var8 = 0; var8 < var7.length; ++var8) {
|
||||
var7[var8] = var22.readObject(var6.params[var8]);
|
||||
}
|
||||
|
||||
NetworkManager var42 = var22.netManager;
|
||||
if(var22.netManager.successful) {
|
||||
if(var6 == PacketType.IDENTIFICATION) {
|
||||
var42.minecraft.progressBar.setTitle(var7[1].toString());
|
||||
var42.minecraft.progressBar.setText(var7[2].toString());
|
||||
var42.minecraft.player.userType = ((Byte)var7[3]).byteValue();
|
||||
} else if(var6 == PacketType.LEVEL_INIT) {
|
||||
var42.minecraft.setLevel((Level)null, false);
|
||||
var42.levelData = new ByteArrayOutputStream();
|
||||
} else if(var6 == PacketType.LEVEL_DATA) {
|
||||
short var11 = ((Short)var7[0]).shortValue();
|
||||
byte[] var12 = (byte[])((byte[])var7[1]);
|
||||
byte var13 = ((Byte)var7[2]).byteValue();
|
||||
var42.minecraft.progressBar.setProgress(var13);
|
||||
var42.levelData.write(var12, 0, var11);
|
||||
} else if(var6 == PacketType.LEVEL_FINALIZE) {
|
||||
try {
|
||||
var42.levelData.close();
|
||||
} catch (IOException var14) {
|
||||
var14.printStackTrace();
|
||||
}
|
||||
|
||||
byte[] var51;
|
||||
try {
|
||||
DataInputStream var3;
|
||||
byte[] var1 = new byte[(var3 = new DataInputStream(new GZIPInputStream(new ByteArrayInputStream(var42.levelData.toByteArray())))).readInt()];
|
||||
var3.readFully(var1);
|
||||
var3.close();
|
||||
var51 = var1;
|
||||
} catch (Exception var2) {
|
||||
throw new RuntimeException(var2);
|
||||
}
|
||||
|
||||
var42.levelData = null;
|
||||
short var55 = ((Short)var7[0]).shortValue();
|
||||
short var63 = ((Short)var7[1]).shortValue();
|
||||
short var21 = ((Short)var7[2]).shortValue();
|
||||
Level var30;
|
||||
(var30 = new Level()).setNetworkMode(true);
|
||||
var30.setData(var55, var63, var21, var51);
|
||||
var42.minecraft.setLevel(var30, false);
|
||||
var42.minecraft.online = false;
|
||||
var42.levelLoaded = true;
|
||||
} else if(var6 == PacketType.BLOCK_CHANGE) {
|
||||
if(var42.minecraft.level != null) {
|
||||
var42.minecraft.level.netSetTile(((Short)var7[0]).shortValue(), ((Short)var7[1]).shortValue(), ((Short)var7[2]).shortValue(), ((Byte)var7[3]).byteValue());
|
||||
}
|
||||
} else {
|
||||
byte var9;
|
||||
String var34;
|
||||
NetworkPlayer var33;
|
||||
short var36;
|
||||
short var10004;
|
||||
byte var10001;
|
||||
short var47;
|
||||
short var10003;
|
||||
if(var6 == PacketType.SPAWN_PLAYER) {
|
||||
var10001 = ((Byte)var7[0]).byteValue();
|
||||
String var10002 = (String)var7[1];
|
||||
var10003 = ((Short)var7[2]).shortValue();
|
||||
var10004 = ((Short)var7[3]).shortValue();
|
||||
short var10005 = ((Short)var7[4]).shortValue();
|
||||
byte var10006 = ((Byte)var7[5]).byteValue();
|
||||
byte var58 = ((Byte)var7[6]).byteValue();
|
||||
var9 = var10006;
|
||||
short var10 = var10005;
|
||||
var47 = var10004;
|
||||
var36 = var10003;
|
||||
var34 = var10002;
|
||||
var5 = var10001;
|
||||
if(var5 >= 0) {
|
||||
var9 = (byte)(var9 + 128);
|
||||
var47 = (short)(var47 - 22);
|
||||
var33 = new NetworkPlayer(var42.minecraft, var5, var34, var36, var47, var10, (float)(var9 * 360) / 256.0F, (float)(var58 * 360) / 256.0F);
|
||||
var42.players.put(Byte.valueOf(var5), var33);
|
||||
var42.minecraft.level.addEntity(var33);
|
||||
} else {
|
||||
var42.minecraft.level.setSpawnPos(var36 / 32, var47 / 32, var10 / 32, (float)(var9 * 320 / 256));
|
||||
var42.minecraft.player.moveTo((float)var36 / 32.0F, (float)var47 / 32.0F, (float)var10 / 32.0F, (float)(var9 * 360) / 256.0F, (float)(var58 * 360) / 256.0F);
|
||||
}
|
||||
} else {
|
||||
byte var53;
|
||||
NetworkPlayer var61;
|
||||
byte var69;
|
||||
if(var6 == PacketType.POSITION_ROTATION) {
|
||||
var10001 = ((Byte)var7[0]).byteValue();
|
||||
short var66 = ((Short)var7[1]).shortValue();
|
||||
var10003 = ((Short)var7[2]).shortValue();
|
||||
var10004 = ((Short)var7[3]).shortValue();
|
||||
var69 = ((Byte)var7[4]).byteValue();
|
||||
var9 = ((Byte)var7[5]).byteValue();
|
||||
var53 = var69;
|
||||
var47 = var10004;
|
||||
var36 = var10003;
|
||||
short var38 = var66;
|
||||
var5 = var10001;
|
||||
if(var5 < 0) {
|
||||
var42.minecraft.player.moveTo((float)var38 / 32.0F, (float)var36 / 32.0F, (float)var47 / 32.0F, (float)(var53 * 360) / 256.0F, (float)(var9 * 360) / 256.0F);
|
||||
} else {
|
||||
var53 = (byte)(var53 + 128);
|
||||
var36 = (short)(var36 - 22);
|
||||
if((var61 = (NetworkPlayer)var42.players.get(Byte.valueOf(var5))) != null) {
|
||||
var61.teleport(var38, var36, var47, (float)(var53 * 360) / 256.0F, (float)(var9 * 360) / 256.0F);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
byte var37;
|
||||
byte var44;
|
||||
byte var49;
|
||||
byte var65;
|
||||
byte var67;
|
||||
if(var6 == PacketType.POSITION_ROTATION_UPDATE) {
|
||||
var10001 = ((Byte)var7[0]).byteValue();
|
||||
var67 = ((Byte)var7[1]).byteValue();
|
||||
var65 = ((Byte)var7[2]).byteValue();
|
||||
byte var64 = ((Byte)var7[3]).byteValue();
|
||||
var69 = ((Byte)var7[4]).byteValue();
|
||||
var9 = ((Byte)var7[5]).byteValue();
|
||||
var53 = var69;
|
||||
var49 = var64;
|
||||
var44 = var65;
|
||||
var37 = var67;
|
||||
var5 = var10001;
|
||||
if(var5 >= 0) {
|
||||
var53 = (byte)(var53 + 128);
|
||||
if((var61 = (NetworkPlayer)var42.players.get(Byte.valueOf(var5))) != null) {
|
||||
var61.queue(var37, var44, var49, (float)(var53 * 360) / 256.0F, (float)(var9 * 360) / 256.0F);
|
||||
}
|
||||
}
|
||||
} else if(var6 == PacketType.ROTATION_UPDATE) {
|
||||
var10001 = ((Byte)var7[0]).byteValue();
|
||||
var67 = ((Byte)var7[1]).byteValue();
|
||||
var44 = ((Byte)var7[2]).byteValue();
|
||||
var37 = var67;
|
||||
var5 = var10001;
|
||||
if(var5 >= 0) {
|
||||
var37 = (byte)(var37 + 128);
|
||||
NetworkPlayer var54;
|
||||
if((var54 = (NetworkPlayer)var42.players.get(Byte.valueOf(var5))) != null) {
|
||||
var54.queue((float)(var37 * 360) / 256.0F, (float)(var44 * 360) / 256.0F);
|
||||
}
|
||||
}
|
||||
} else if(var6 == PacketType.POSITION_UPDATE) {
|
||||
var10001 = ((Byte)var7[0]).byteValue();
|
||||
var67 = ((Byte)var7[1]).byteValue();
|
||||
var65 = ((Byte)var7[2]).byteValue();
|
||||
var49 = ((Byte)var7[3]).byteValue();
|
||||
var44 = var65;
|
||||
var37 = var67;
|
||||
var5 = var10001;
|
||||
NetworkPlayer var59;
|
||||
if(var5 >= 0 && (var59 = (NetworkPlayer)var42.players.get(Byte.valueOf(var5))) != null) {
|
||||
var59.queue(var37, var44, var49);
|
||||
}
|
||||
} else if(var6 == PacketType.DESPAWN_PLAYER) {
|
||||
var5 = ((Byte)var7[0]).byteValue();
|
||||
if(var5 >= 0 && (var33 = (NetworkPlayer)var42.players.remove(Byte.valueOf(var5))) != null) {
|
||||
var42.minecraft.level.removeEntity(var33);
|
||||
}
|
||||
} else if(var6 == PacketType.CHAT_MESSAGE) {
|
||||
var10001 = ((Byte)var7[0]).byteValue();
|
||||
var34 = (String)var7[1];
|
||||
var5 = var10001;
|
||||
if(var5 < 0) {
|
||||
var42.minecraft.hud.addChat("&e" + var34);
|
||||
} else {
|
||||
var42.players.get(Byte.valueOf(var5));
|
||||
var42.minecraft.hud.addChat(var34);
|
||||
}
|
||||
} else if(var6 == PacketType.DISCONNECT) {
|
||||
var42.netHandler.close();
|
||||
var42.minecraft.setCurrentScreen(new ErrorScreen("Connection lost", (String)var7[0]));
|
||||
} else if(var6 == PacketType.UPDATE_PLAYER_TYPE) {
|
||||
var42.minecraft.player.userType = ((Byte)var7[0]).byteValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!var22.channel.connectionOpen()) {
|
||||
break;
|
||||
}
|
||||
|
||||
var22.in.compact();
|
||||
}
|
||||
|
||||
if(var22.out.position() > 0) {
|
||||
var22.out.flip();
|
||||
var22.channel.write(var22.out);
|
||||
var22.out.compact();
|
||||
}
|
||||
} catch (Exception var15) {
|
||||
var20.minecraft.setCurrentScreen(new ErrorScreen("Disconnected!", "You\'ve lost connection to the server"));
|
||||
var20.minecraft.online = false;
|
||||
var15.printStackTrace();
|
||||
var20.netHandler.close();
|
||||
var20.minecraft.networkManager = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Player var28 = this.player;
|
||||
var20 = this.networkManager;
|
||||
if(this.networkManager.levelLoaded) {
|
||||
int var24 = (int)(var28.x * 32.0F);
|
||||
var4 = (int)(var28.y * 32.0F);
|
||||
var40 = (int)(var28.z * 32.0F);
|
||||
var46 = (int)(var28.yRot * 256.0F / 360.0F) & 255;
|
||||
var45 = (int)(var28.xRot * 256.0F / 360.0F) & 255;
|
||||
var20.netHandler.send(PacketType.POSITION_ROTATION, new Object[]{Integer.valueOf(-1), Integer.valueOf(var24), Integer.valueOf(var4), Integer.valueOf(var40), Integer.valueOf(var46), Integer.valueOf(var45)});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(this.currentScreen == null && this.player != null && this.player.health <= 0) {
|
||||
this.setCurrentScreen((GuiScreen)null);
|
||||
|
@ -1116,7 +1345,7 @@ public final class Minecraft implements Runnable {
|
|||
}
|
||||
|
||||
while(GL11.keysNext()) {
|
||||
this.player.setKey(GL11.getEventKey(), GL11.getEventKeyState());
|
||||
this.player.setKey(GL11.getEventKey(), GL11.getEventKeyState());
|
||||
if(GL11.getEventKeyState()) {
|
||||
if(this.currentScreen != null) {
|
||||
this.currentScreen.keyboardEvent();
|
||||
|
@ -1151,6 +1380,11 @@ public final class Minecraft implements Runnable {
|
|||
if(GL11.getEventKey() == this.settings.buildKey.key) {
|
||||
this.gamemode.openInventory();
|
||||
}
|
||||
|
||||
if(GL11.getEventKey() == this.settings.chatKey.key && this.networkManager != null && this.networkManager.isConnected()) {
|
||||
this.player.releaseAllKeys();
|
||||
this.setCurrentScreen(new ChatInputScreen());
|
||||
}
|
||||
}
|
||||
|
||||
for(var25 = 0; var25 < 9; ++var25) {
|
||||
|
@ -1260,11 +1494,15 @@ public final class Minecraft implements Runnable {
|
|||
LevelRenderer var31 = this.levelRenderer;
|
||||
++this.levelRenderer.ticks;
|
||||
this.level.tickEntities();
|
||||
this.level.tick();
|
||||
if(!this.isOnline()) {
|
||||
this.level.tick();
|
||||
}
|
||||
this.particleManager.tick();
|
||||
}
|
||||
|
||||
this.player.arrows = 1;
|
||||
if(player != null) {
|
||||
this.player.arrows = 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1272,14 +1510,18 @@ public final class Minecraft implements Runnable {
|
|||
|
||||
private void levelSave() {
|
||||
if(this.level == null) {
|
||||
ticksUntilSave = this.hud.ticks + 600;
|
||||
ticksUntilSave = this.ticks + 600;
|
||||
}
|
||||
|
||||
if(this.hud.ticks >= this.ticksUntilSave) {
|
||||
if(this.ticks >= this.ticksUntilSave) {
|
||||
new LevelUtils().save();
|
||||
ticksUntilSave = this.hud.ticks + 600;
|
||||
ticksUntilSave = this.ticks + 600;
|
||||
}
|
||||
}
|
||||
|
||||
public final boolean isOnline() {
|
||||
return this.networkManager != null;
|
||||
}
|
||||
|
||||
public final void generateLevel(int var1) {
|
||||
String var2 = "PeytonPlayz585";
|
||||
|
@ -1297,7 +1539,16 @@ public final class Minecraft implements Runnable {
|
|||
this.gamemode.apply(var1);
|
||||
var1.font = this.fontRenderer;
|
||||
var1.rendererContext$5cd64a7f = this;
|
||||
this.player = (Player)var1.findSubclassOf(Player.class);
|
||||
if(!this.isOnline()) {
|
||||
this.player = (Player)var1.findSubclassOf(Player.class);
|
||||
} else if(this.player != null) {
|
||||
this.player.resetPos();
|
||||
this.gamemode.preparePlayer(this.player);
|
||||
if(var1 != null) {
|
||||
var1.player = this.player;
|
||||
var1.addEntity(this.player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(this.player == null) {
|
||||
|
|
|
@ -10,8 +10,6 @@ public final class SessionData {
|
|||
public String username;
|
||||
public String sessionId;
|
||||
public String mppass;
|
||||
public boolean haspaid;
|
||||
|
||||
|
||||
public SessionData(String var1, String var2) {
|
||||
this.username = var1;
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
package com.mojang.minecraft;
|
||||
|
||||
public class SleepForeverThread extends Thread
|
||||
{
|
||||
public SleepForeverThread(Minecraft minecraft)
|
||||
{
|
||||
setDaemon(true);
|
||||
|
||||
start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
try {
|
||||
while(true)
|
||||
{
|
||||
Thread.sleep(2147483647L);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -50,13 +50,19 @@ public class GameMode
|
|||
|
||||
boolean success = level.netSetTile(x, y, z, 0);
|
||||
|
||||
if(block.stepsound != Tile$SoundType.none && minecraft.settings.sound)
|
||||
{
|
||||
level.playSound(block.stepsound.name);
|
||||
}
|
||||
|
||||
if(block != null && success)
|
||||
{
|
||||
|
||||
if(Minecraft.getMinecraft().isOnline())
|
||||
{
|
||||
Minecraft.getMinecraft().networkManager.sendBlockChange(x, y, z, 0, Minecraft.getMinecraft().player.inventory.getSelected());
|
||||
}
|
||||
|
||||
if(block.stepsound != Tile$SoundType.none && minecraft.settings.sound)
|
||||
{
|
||||
level.playSound(block.stepsound.name);
|
||||
}
|
||||
|
||||
block.spawnBreakParticles(level, x, y, z, minecraft.particleManager);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package com.mojang.minecraft.gui;
|
||||
|
||||
import com.mojang.minecraft.gui.GuiScreen;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.mojang.minecraft.gui.GuiScreen;
|
||||
import com.mojang.minecraft.net.NetworkManager;
|
||||
import com.mojang.minecraft.net.PacketType;
|
||||
|
||||
public final class ChatInputScreen extends GuiScreen {
|
||||
|
||||
private String message = "";
|
||||
|
@ -25,6 +28,13 @@ public final class ChatInputScreen extends GuiScreen {
|
|||
if(var2 == 1) {
|
||||
this.minecraft.setCurrentScreen((GuiScreen)null);
|
||||
} else if(var2 == 28) {
|
||||
NetworkManager var10000 = this.minecraft.networkManager;
|
||||
String var4 = this.message.trim();
|
||||
NetworkManager var3 = var10000;
|
||||
if((var4 = var4.trim()).length() > 0) {
|
||||
var3.netHandler.send(PacketType.CHAT_MESSAGE, new Object[]{Integer.valueOf(-1), var4});
|
||||
}
|
||||
|
||||
this.minecraft.setCurrentScreen((GuiScreen)null);
|
||||
} else {
|
||||
if(var2 == 14 && this.message.length() > 0) {
|
||||
|
|
|
@ -118,7 +118,6 @@ public class FontRenderer {
|
|||
k = (k & 0xfcfcfc) >> 2;
|
||||
k += l;
|
||||
}
|
||||
//GL11.glBindTexture(3553 /* GL_TEXTURE_2D */, fontTextureName);
|
||||
new TextureLocation(fontTextureName).bindTexture();
|
||||
float f = (float) (k >> 16 & 0xff) / 255F;
|
||||
float f1 = (float) (k >> 8 & 0xff) / 255F;
|
||||
|
@ -137,8 +136,6 @@ public class FontRenderer {
|
|||
j1 = 15;
|
||||
}
|
||||
continue;
|
||||
//EaglerAdapter.glCallList(fontDisplayLists + 256 + j1 + (flag ? 16 : 0));
|
||||
//EaglerAdapter.glTranslatef(charWidth[256 + j1 + (flag ? 16 : 0)] * 0.5f, 0.0F, 0.0F);
|
||||
}
|
||||
|
||||
if (i1 < s.length()) {
|
||||
|
@ -171,6 +168,21 @@ public class FontRenderer {
|
|||
|
||||
return i;
|
||||
}
|
||||
|
||||
public static String stripColor(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];
|
||||
}
|
||||
}
|
||||
|
||||
return var1;
|
||||
}
|
||||
|
||||
private int charWidth[];
|
||||
public String fontTextureName;
|
||||
|
|
|
@ -12,6 +12,7 @@ import net.lax1dude.eaglercraft.adapter.Tessellator;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public final class HUDScreen extends Screen {
|
||||
|
@ -32,13 +33,16 @@ public final class HUDScreen extends Screen {
|
|||
this.width = var2 * 240 / var3;
|
||||
this.height = var3 * 240 / var3;
|
||||
|
||||
if(firstTimeLaunch) {
|
||||
if(firstTimeLaunch && Minecraft.getMinecraft().level != null) {
|
||||
mc.setCurrentScreen(new PauseScreen());
|
||||
firstTimeLaunch = false;
|
||||
}
|
||||
}
|
||||
|
||||
public final void render(float var1, boolean var2, int var3, int var4) {
|
||||
if(Minecraft.getMinecraft().level == null) {
|
||||
return;
|
||||
}
|
||||
FontRenderer var5 = this.mc.fontRenderer;
|
||||
this.mc.renderer.enableGuiMode();
|
||||
new TextureLocation("/gui/gui.png").bindTexture();
|
||||
|
@ -176,6 +180,36 @@ public final class HUDScreen extends Screen {
|
|||
var14 = this.width / 2;
|
||||
var15 = this.height / 2;
|
||||
this.hoveredPlayer = null;
|
||||
if(GL11.isKeyDown(15) && this.mc.networkManager != null && this.mc.networkManager.isConnected()) {
|
||||
List var22 = this.mc.networkManager.getPlayers();
|
||||
GL11.glEnable(3042);
|
||||
GL11.glDisable(3553);
|
||||
GL11.glBlendFunc(770, 771);
|
||||
tessellator.startDrawing(7);
|
||||
GL11.glColor4f(0.0F, 0.0F, 0.0F, 0.7F);
|
||||
tessellator.addVertex((float)(var14 + 128), (float)(var15 - 68 - 12), 0.0F);
|
||||
tessellator.addVertex((float)(var14 - 128), (float)(var15 - 68 - 12), 0.0F);
|
||||
GL11.glColor4f(0.2F, 0.2F, 0.2F, 0.8F);
|
||||
tessellator.addVertex((float)(var14 - 128), (float)(var15 + 68), 0.0F);
|
||||
tessellator.addVertex((float)(var14 + 128), (float)(var15 + 68), 0.0F);
|
||||
tessellator.draw();
|
||||
GL11.glDisable(3042);
|
||||
GL11.glEnable(3553);
|
||||
var23 = "Connected players:";
|
||||
var5.drawStringWithShadow(var23, var14 - var5.getStringWidth(var23) / 2, var15 - 64 - 12, 16777215);
|
||||
|
||||
for(var11 = 0; var11 < var22.size(); ++var11) {
|
||||
int var28 = var14 + var11 % 2 * 120 - 120;
|
||||
int var17 = var15 - 64 + (var11 / 2 << 3);
|
||||
if(var2 && var3 >= var28 && var4 >= var17 && var3 < var28 + 120 && var4 < var17 + 8) {
|
||||
this.hoveredPlayer = (String)var22.get(var11);
|
||||
var5.drawString((String)var22.get(var11), var28 + 2, var17, 16777215);
|
||||
} else {
|
||||
var5.drawString((String)var22.get(var11), var28, var17, 15658734);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public final void addChat(String var1) {
|
||||
|
|
54
src/teavm/java/com/mojang/minecraft/gui/MainMenu.java
Normal file
54
src/teavm/java/com/mojang/minecraft/gui/MainMenu.java
Normal file
|
@ -0,0 +1,54 @@
|
|||
package com.mojang.minecraft.gui;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.mojang.minecraft.Minecraft;
|
||||
import com.mojang.minecraft.level.Level;
|
||||
import com.mojang.minecraft.render.TextureLocation;
|
||||
|
||||
import net.PeytonPlayz585.level.LevelUtils;
|
||||
import net.lax1dude.eaglercraft.adapter.Tessellator;
|
||||
|
||||
public class MainMenu extends GuiScreen {
|
||||
|
||||
public final void onOpen() {
|
||||
this.buttons.clear();
|
||||
this.buttons.add(new Button(1, this.width / 2 - 100, this.height / 4 + 48, "Singleplayer"));
|
||||
this.buttons.add(new Button(2, this.width / 2 - 100, this.height / 4 + 72, "Multiplayer"));
|
||||
}
|
||||
|
||||
protected final void onButtonClick(Button var1) {
|
||||
if(var1.id == 1) {
|
||||
Level level1 = new LevelUtils().load();
|
||||
if(level1 == null) {
|
||||
Minecraft.getMinecraft().setCurrentScreen(null);
|
||||
this.minecraft.generateLevel(1);
|
||||
this.minecraft.player.releaseAllKeys();
|
||||
} else {
|
||||
Minecraft.getMinecraft().setCurrentScreen(null);
|
||||
this.minecraft.setLevel(level1, true);
|
||||
this.minecraft.player.releaseAllKeys();
|
||||
}
|
||||
} else if(var1.id == 2) {
|
||||
this.minecraft.setCurrentScreen(new MultiplayerMenu());
|
||||
}
|
||||
}
|
||||
|
||||
public final void render(int var1, int var2) {
|
||||
int var4 = this.minecraft.width * 240 / this.minecraft.height;
|
||||
int var5 = this.minecraft.height * 240 / this.minecraft.height;
|
||||
GL11.glClear(16640);
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
int var7 = new TextureLocation("/dirt.png").bindTexture();
|
||||
float var10 = 32.0F;
|
||||
tessellator.startDrawing(7);
|
||||
tessellator.setColorOpaque_I(4210752);
|
||||
tessellator.addVertexWithUV(0.0F, (float)var5, 0.0F, 0.0F, (float)var5 / var10);
|
||||
tessellator.addVertexWithUV((float)var4, (float)var5, 0.0F, (float)var4 / var10, (float)var5 / var10);
|
||||
tessellator.addVertexWithUV((float)var4, 0.0F, 0.0F, (float)var4 / var10, 0.0F);
|
||||
tessellator.addVertexWithUV(0.0F, 0.0F, 0.0F, 0.0F, 0.0F);
|
||||
tessellator.draw();
|
||||
super.render(var1, var2);
|
||||
}
|
||||
|
||||
}
|
137
src/teavm/java/com/mojang/minecraft/gui/MultiplayerMenu.java
Normal file
137
src/teavm/java/com/mojang/minecraft/gui/MultiplayerMenu.java
Normal file
|
@ -0,0 +1,137 @@
|
|||
package com.mojang.minecraft.gui;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.mojang.minecraft.Minecraft;
|
||||
import com.mojang.minecraft.SessionData;
|
||||
import com.mojang.minecraft.level.Level;
|
||||
import com.mojang.minecraft.net.NetworkManager;
|
||||
import com.mojang.minecraft.render.TextureLocation;
|
||||
|
||||
import net.PeytonPlayz585.level.LevelUtils;
|
||||
import net.lax1dude.eaglercraft.adapter.Tessellator;
|
||||
|
||||
public class MultiplayerMenu extends GuiScreen {
|
||||
|
||||
boolean textBox1Active = false;
|
||||
boolean textBox2Active = false;
|
||||
private int counter = 0;
|
||||
String server = "";
|
||||
String username = "";
|
||||
Button connect;
|
||||
|
||||
public final void onOpen() {
|
||||
GL11.enableRepeatEvents(true);
|
||||
this.buttons.clear();
|
||||
this.buttons.add(connect = new Button(0, this.width / 2 - 100, this.height / 4 + 96 + 12, "Connect"));
|
||||
this.buttons.add(new Button(1, this.width / 2 - 100, this.height / 4 + 120 + 12, "Cancel"));
|
||||
connect.active = false;
|
||||
}
|
||||
|
||||
public final void tick() {
|
||||
++this.counter;
|
||||
}
|
||||
|
||||
protected final void onButtonClick(Button var1) {
|
||||
if(var1.id == 0 && var1.active) {
|
||||
GL11.enableRepeatEvents(false);
|
||||
minecraft.session = new SessionData(this.username, "mcpass");
|
||||
Level var85;
|
||||
(var85 = new Level()).setData(8, 8, 8, new byte[512]);
|
||||
minecraft.setLevel(var85, false);
|
||||
minecraft.networkManager = new NetworkManager(minecraft, this.server, minecraft.session.username, minecraft.session.mppass);
|
||||
} else if(var1.id == 1) {
|
||||
GL11.enableRepeatEvents(false);
|
||||
minecraft.setCurrentScreen(new MainMenu());
|
||||
}
|
||||
}
|
||||
|
||||
protected void onMouseClick(int var1, int var2, int var3) {
|
||||
if(var3 == 0) {
|
||||
if(var1 >= this.width / 2 - 100 && var1 < (this.width / 2 - 100) + 200 && var2 >= this.height / 4 - 10 + 50 + 18 && var2 < (this.height / 4 - 10 + 50 + 18) + 20) {
|
||||
GL11.enableRepeatEvents(true);
|
||||
textBox1Active = true;
|
||||
textBox2Active = false;
|
||||
} else if(var1 >= this.width / 2 - 100 && var1 < (this.width / 2 - 100) + 200 && var2 >= this.height / 4 - 10 + 50 - 20 && var2 < (this.height / 4 - 10 + 50 - 20) + 20) {
|
||||
GL11.enableRepeatEvents(true);
|
||||
textBox2Active = true;
|
||||
textBox1Active = false;
|
||||
} else {
|
||||
GL11.enableRepeatEvents(false);
|
||||
textBox1Active = false;
|
||||
textBox2Active = false;
|
||||
}
|
||||
}
|
||||
super.onMouseClick(var1, var2, var3);
|
||||
}
|
||||
|
||||
protected final void onKeyPress(char var1, int var2) {
|
||||
if(textBox1Active) {
|
||||
if(var2 == 14 && this.server.length() > 0) {
|
||||
this.server = this.server.substring(0, this.server.length() - 1);
|
||||
}
|
||||
if("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ,.:-_\'*!\\\"#%/()=+?[]{}<>@|$;".indexOf(var1) >= 0 && this.server.length() < 64) {
|
||||
this.server = this.server + var1;
|
||||
}
|
||||
if(server.length() > 0 && username.length() > 0) {
|
||||
connect.active = true;
|
||||
} else {
|
||||
connect.active = false;
|
||||
}
|
||||
} else if(textBox2Active) {
|
||||
if(var2 == 14 && this.username.length() > 0) {
|
||||
this.username = this.username.substring(0, this.username.length() - 1);
|
||||
}
|
||||
if("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ,.:-_\'*!\\\"#%/()=+?[]{}<>@|$;".indexOf(var1) >= 0 && this.username.length() < 64) {
|
||||
this.username = this.username + var1;
|
||||
}
|
||||
if(server.length() > 0 && username.length() > 0) {
|
||||
connect.active = true;
|
||||
} else {
|
||||
connect.active = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final void render(int var1, int var2) {
|
||||
int var4 = this.minecraft.width * 240 / this.minecraft.height;
|
||||
int var5 = this.minecraft.height * 240 / this.minecraft.height;
|
||||
GL11.glClear(16640);
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
int var7 = new TextureLocation("/dirt.png").bindTexture();
|
||||
float var10 = 32.0F;
|
||||
tessellator.startDrawing(7);
|
||||
tessellator.setColorOpaque_I(4210752);
|
||||
tessellator.addVertexWithUV(0.0F, (float)var5, 0.0F, 0.0F, (float)var5 / var10);
|
||||
tessellator.addVertexWithUV((float)var4, (float)var5, 0.0F, (float)var4 / var10, (float)var5 / var10);
|
||||
tessellator.addVertexWithUV((float)var4, 0.0F, 0.0F, (float)var4 / var10, 0.0F);
|
||||
tessellator.addVertexWithUV(0.0F, 0.0F, 0.0F, 0.0F, 0.0F);
|
||||
tessellator.draw();
|
||||
|
||||
//username
|
||||
drawBox((this.width / 2 - 100) - 1, (this.height / 4 - 10 + 50 - 20) - 1, (this.width / 2 - 100) + 200 + 1, (this.height / 4 - 10 + 50 - 20) + 20 + 1, -6250336);
|
||||
drawBox(this.width / 2 - 100, this.height / 4 - 10 + 50 - 20, (this.width / 2 - 100) + 200, (this.height / 4 - 10 + 50 - 20) + 20, -16777216);
|
||||
|
||||
this.drawString(this.fontRenderer, "Username:", this.width / 2 - 100, this.height / 4 - 10 + 50 - 30, 10526880);
|
||||
|
||||
//server IP
|
||||
drawBox((this.width / 2 - 100) - 1, (this.height / 4 - 10 + 50 + 18) - 1, (this.width / 2 - 100) + 200 + 1, (this.height / 4 - 10 + 50 + 18) + 20 + 1, -6250336);
|
||||
drawBox(this.width / 2 - 100, this.height / 4 - 10 + 50 + 18, (this.width / 2 - 100) + 200, (this.height / 4 - 10 + 50 + 18) + 20, -16777216);
|
||||
|
||||
this.drawString(this.fontRenderer, "Server address:", this.width / 2 - 100, this.height / 4 - 10 + 50 + 8, 10526880);
|
||||
if(textBox1Active) {
|
||||
boolean e = this.counter / 6 % 2 == 0;
|
||||
this.drawString(this.fontRenderer, server + (e ? "_" : ""), (this.width / 2 - 100) + 4, (this.height / 4 - 10 + 50 + 18) + (20 - 8) / 2, 14737632);
|
||||
} else {
|
||||
this.drawString(this.fontRenderer, server, (this.width / 2 - 100) + 4, (this.height / 4 - 10 + 50 + 18) + (20 - 8) / 2, 14737632);
|
||||
}
|
||||
if(textBox2Active) {
|
||||
boolean e = this.counter / 6 % 2 == 0;
|
||||
this.drawString(this.fontRenderer, username + (e ? "_" : ""), (this.width / 2 - 100) + 4, (this.height / 4 - 10 + 50 - 20) + (20 - 8) / 2, 14737632);
|
||||
} else {
|
||||
this.drawString(this.fontRenderer, username, (this.width / 2 - 100) + 4, (this.height / 4 - 10 + 50 - 20) + (20 - 8) / 2, 14737632);
|
||||
}
|
||||
super.render(var1, var2);
|
||||
}
|
||||
|
||||
}
|
|
@ -21,6 +21,13 @@ public final class PauseScreen extends GuiScreen {
|
|||
this.buttons.add(new Button(4, this.width / 2 - 100, this.height / 4 + 120, "Back to game"));
|
||||
((Button)this.buttons.get(2)).active = false;
|
||||
((Button)this.buttons.get(3)).active = false;
|
||||
|
||||
if(this.minecraft.networkManager != null) {
|
||||
((Button)this.buttons.get(1)).active = false;
|
||||
((Button)this.buttons.get(2)).active = false;
|
||||
((Button)this.buttons.get(3)).active = false;
|
||||
}
|
||||
|
||||
new LevelUtils().save();
|
||||
}
|
||||
|
||||
|
|
|
@ -196,42 +196,42 @@ public class BlockMap implements Serializable {
|
|||
break;
|
||||
}
|
||||
|
||||
if(var19.clippingHelper.frustum[var20][0] * var18 + var19.clippingHelper.frustum[var20][1] * var13 + var19.clippingHelper.frustum[var20][2] * var14 + var19.clippingHelper.frustum[var20][3] <= 0.0F) {
|
||||
if(var19.frustrum[var20][0] * var18 + var19.frustrum[var20][1] * var13 + var19.frustrum[var20][2] * var14 + var19.frustrum[var20][3] <= 0.0F) {
|
||||
var10000 = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if(var19.clippingHelper.frustum[var20][0] * var15 + var19.clippingHelper.frustum[var20][1] * var13 + var19.clippingHelper.frustum[var20][2] * var14 + var19.clippingHelper.frustum[var20][3] <= 0.0F) {
|
||||
if(var19.frustrum[var20][0] * var15 + var19.frustrum[var20][1] * var13 + var19.frustrum[var20][2] * var14 + var19.frustrum[var20][3] <= 0.0F) {
|
||||
var10000 = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if(var19.clippingHelper.frustum[var20][0] * var18 + var19.clippingHelper.frustum[var20][1] * var17 + var19.clippingHelper.frustum[var20][2] * var14 + var19.clippingHelper.frustum[var20][3] <= 0.0F) {
|
||||
if(var19.frustrum[var20][0] * var18 + var19.frustrum[var20][1] * var17 + var19.frustrum[var20][2] * var14 + var19.frustrum[var20][3] <= 0.0F) {
|
||||
var10000 = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if(var19.clippingHelper.frustum[var20][0] * var15 + var19.clippingHelper.frustum[var20][1] * var17 + var19.clippingHelper.frustum[var20][2] * var14 + var19.clippingHelper.frustum[var20][3] <= 0.0F) {
|
||||
if(var19.frustrum[var20][0] * var15 + var19.frustrum[var20][1] * var17 + var19.frustrum[var20][2] * var14 + var19.frustrum[var20][3] <= 0.0F) {
|
||||
var10000 = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if(var19.clippingHelper.frustum[var20][0] * var18 + var19.clippingHelper.frustum[var20][1] * var13 + var19.clippingHelper.frustum[var20][2] * var16 + var19.clippingHelper.frustum[var20][3] <= 0.0F) {
|
||||
if(var19.frustrum[var20][0] * var18 + var19.frustrum[var20][1] * var13 + var19.frustrum[var20][2] * var16 + var19.frustrum[var20][3] <= 0.0F) {
|
||||
var10000 = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if(var19.clippingHelper.frustum[var20][0] * var15 + var19.clippingHelper.frustum[var20][1] * var13 + var19.clippingHelper.frustum[var20][2] * var16 + var19.clippingHelper.frustum[var20][3] <= 0.0F) {
|
||||
if(var19.frustrum[var20][0] * var15 + var19.frustrum[var20][1] * var13 + var19.frustrum[var20][2] * var16 + var19.frustrum[var20][3] <= 0.0F) {
|
||||
var10000 = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if(var19.clippingHelper.frustum[var20][0] * var18 + var19.clippingHelper.frustum[var20][1] * var17 + var19.clippingHelper.frustum[var20][2] * var16 + var19.clippingHelper.frustum[var20][3] <= 0.0F) {
|
||||
if(var19.frustrum[var20][0] * var18 + var19.frustrum[var20][1] * var17 + var19.frustrum[var20][2] * var16 + var19.frustrum[var20][3] <= 0.0F) {
|
||||
var10000 = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if(var19.clippingHelper.frustum[var20][0] * var15 + var19.clippingHelper.frustum[var20][1] * var17 + var19.clippingHelper.frustum[var20][2] * var16 + var19.clippingHelper.frustum[var20][3] <= 0.0F) {
|
||||
if(var19.frustrum[var20][0] * var15 + var19.frustrum[var20][1] * var17 + var19.frustrum[var20][2] * var16 + var19.frustrum[var20][3] <= 0.0F) {
|
||||
var10000 = false;
|
||||
break;
|
||||
}
|
||||
|
@ -276,4 +276,4 @@ public class BlockMap implements Serializable {
|
|||
static int getHeight(BlockMap var0) {
|
||||
return var0.height;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,258 +0,0 @@
|
|||
package com.mojang.minecraft.level;
|
||||
|
||||
import com.mojang.minecraft.ProgressBarDisplay;
|
||||
import com.mojang.minecraft.level.Level;
|
||||
import com.mojang.minecraft.level.LevelObjectInputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
public final class LevelIO {
|
||||
|
||||
private ProgressBarDisplay progressBar;
|
||||
|
||||
|
||||
public LevelIO(ProgressBarDisplay var1) {
|
||||
this.progressBar = var1;
|
||||
}
|
||||
|
||||
public final boolean save(Level var1, File var2) {
|
||||
try {
|
||||
FileOutputStream var5 = new FileOutputStream(var2);
|
||||
save(var1, (OutputStream)var5);
|
||||
var5.close();
|
||||
return true;
|
||||
} catch (Exception var4) {
|
||||
var4.printStackTrace();
|
||||
if(this.progressBar != null) {
|
||||
this.progressBar.setText("Failed!");
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(1000L);
|
||||
} catch (InterruptedException var3) {
|
||||
;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public final Level load(File var1) {
|
||||
try {
|
||||
FileInputStream var5 = new FileInputStream(var1);
|
||||
Level var2 = this.load((InputStream)var5);
|
||||
var5.close();
|
||||
return var2;
|
||||
} catch (Exception var4) {
|
||||
var4.printStackTrace();
|
||||
if(this.progressBar != null) {
|
||||
this.progressBar.setText("Failed!");
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(1000L);
|
||||
} catch (InterruptedException var3) {
|
||||
;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public final boolean saveOnline(Level var1, String var2, String var3, String var4, String var5, int var6) {
|
||||
if(var4 == null) {
|
||||
var4 = "";
|
||||
}
|
||||
|
||||
if(this.progressBar != null && this.progressBar != null) {
|
||||
this.progressBar.setTitle("Saving level");
|
||||
}
|
||||
|
||||
try {
|
||||
if(this.progressBar != null && this.progressBar != null) {
|
||||
this.progressBar.setText("Compressing..");
|
||||
}
|
||||
|
||||
ByteArrayOutputStream var7 = new ByteArrayOutputStream();
|
||||
save(var1, (OutputStream)var7);
|
||||
var7.close();
|
||||
byte[] var10 = var7.toByteArray();
|
||||
if(this.progressBar != null && this.progressBar != null) {
|
||||
this.progressBar.setText("Connecting..");
|
||||
}
|
||||
|
||||
HttpURLConnection var12;
|
||||
(var12 = (HttpURLConnection)(new URL("http://" + var2 + "/level/save.html")).openConnection()).setDoInput(true);
|
||||
var12.setDoOutput(true);
|
||||
var12.setRequestMethod("POST");
|
||||
DataOutputStream var13;
|
||||
(var13 = new DataOutputStream(var12.getOutputStream())).writeUTF(var3);
|
||||
var13.writeUTF(var4);
|
||||
var13.writeUTF(var5);
|
||||
var13.writeByte(var6);
|
||||
var13.writeInt(var10.length);
|
||||
if(this.progressBar != null) {
|
||||
this.progressBar.setText("Saving..");
|
||||
}
|
||||
|
||||
var13.write(var10);
|
||||
var13.close();
|
||||
BufferedReader var11;
|
||||
if(!(var11 = new BufferedReader(new InputStreamReader(var12.getInputStream()))).readLine().equalsIgnoreCase("ok")) {
|
||||
if(this.progressBar != null) {
|
||||
this.progressBar.setText("Failed: " + var11.readLine());
|
||||
}
|
||||
|
||||
var11.close();
|
||||
Thread.sleep(1000L);
|
||||
return false;
|
||||
} else {
|
||||
var11.close();
|
||||
return true;
|
||||
}
|
||||
} catch (Exception var9) {
|
||||
var9.printStackTrace();
|
||||
if(this.progressBar != null) {
|
||||
this.progressBar.setText("Failed!");
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(1000L);
|
||||
} catch (InterruptedException var8) {
|
||||
;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public final Level loadOnline(String var1, String var2, int var3) {
|
||||
if(this.progressBar != null) {
|
||||
this.progressBar.setTitle("Loading level");
|
||||
}
|
||||
|
||||
try {
|
||||
if(this.progressBar != null) {
|
||||
this.progressBar.setText("Connecting..");
|
||||
}
|
||||
|
||||
HttpURLConnection var6;
|
||||
(var6 = (HttpURLConnection)(new URL("http://" + var1 + "/level/load.html?id=" + var3 + "&user=" + var2)).openConnection()).setDoInput(true);
|
||||
if(this.progressBar != null) {
|
||||
this.progressBar.setText("Loading..");
|
||||
}
|
||||
|
||||
DataInputStream var7;
|
||||
if((var7 = new DataInputStream(var6.getInputStream())).readUTF().equalsIgnoreCase("ok")) {
|
||||
return this.load((InputStream)var7);
|
||||
} else {
|
||||
if(this.progressBar != null) {
|
||||
this.progressBar.setText("Failed: " + var7.readUTF());
|
||||
}
|
||||
|
||||
var7.close();
|
||||
Thread.sleep(1000L);
|
||||
return null;
|
||||
}
|
||||
} catch (Exception var5) {
|
||||
var5.printStackTrace();
|
||||
if(this.progressBar != null) {
|
||||
this.progressBar.setText("Failed!");
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(3000L);
|
||||
} catch (InterruptedException var4) {
|
||||
;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public final Level load(InputStream var1) {
|
||||
if(this.progressBar != null) {
|
||||
this.progressBar.setTitle("Loading level");
|
||||
}
|
||||
|
||||
if(this.progressBar != null) {
|
||||
this.progressBar.setText("Reading..");
|
||||
}
|
||||
|
||||
try {
|
||||
DataInputStream var10;
|
||||
if((var10 = new DataInputStream(new GZIPInputStream(var1))).readInt() != 656127880) {
|
||||
return null;
|
||||
} else {
|
||||
byte var12;
|
||||
if((var12 = var10.readByte()) > 2) {
|
||||
return null;
|
||||
} else if(var12 <= 1) {
|
||||
String var14 = var10.readUTF();
|
||||
String var15 = var10.readUTF();
|
||||
long var3 = var10.readLong();
|
||||
short var5 = var10.readShort();
|
||||
short var6 = var10.readShort();
|
||||
short var7 = var10.readShort();
|
||||
byte[] var8 = new byte[var5 * var6 * var7];
|
||||
var10.readFully(var8);
|
||||
var10.close();
|
||||
Level var11;
|
||||
(var11 = new Level()).setData(var5, var7, var6, var8);
|
||||
var11.name = var14;
|
||||
var11.creator = var15;
|
||||
var11.createTime = var3;
|
||||
return var11;
|
||||
} else {
|
||||
Level var2;
|
||||
LevelObjectInputStream var13;
|
||||
(var2 = (Level)(var13 = new LevelObjectInputStream(var10)).readObject()).initTransient();
|
||||
var13.close();
|
||||
return var2;
|
||||
}
|
||||
}
|
||||
} catch (Exception var9) {
|
||||
var9.printStackTrace();
|
||||
System.out.println("Failed to load level: " + var9.toString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void save(Level var0, OutputStream var1) {
|
||||
try {
|
||||
DataOutputStream var3;
|
||||
(var3 = new DataOutputStream(new GZIPOutputStream(var1))).writeInt(656127880);
|
||||
var3.writeByte(2);
|
||||
ObjectOutputStream var4;
|
||||
(var4 = new ObjectOutputStream(var3)).writeObject(var0);
|
||||
var4.close();
|
||||
} catch (Exception var2) {
|
||||
var2.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] decompress(InputStream var0) {
|
||||
try {
|
||||
DataInputStream var3;
|
||||
byte[] var1 = new byte[(var3 = new DataInputStream(new GZIPInputStream(var0))).readInt()];
|
||||
var3.readFully(var1);
|
||||
var3.close();
|
||||
return var1;
|
||||
} catch (Exception var2) {
|
||||
throw new RuntimeException(var2);
|
||||
}
|
||||
}
|
||||
}
|
76
src/teavm/java/com/mojang/minecraft/net/NetworkManager.java
Normal file
76
src/teavm/java/com/mojang/minecraft/net/NetworkManager.java
Normal file
|
@ -0,0 +1,76 @@
|
|||
package com.mojang.minecraft.net;
|
||||
|
||||
import com.mojang.minecraft.Minecraft;
|
||||
import com.mojang.minecraft.gui.ErrorScreen;
|
||||
import com.mojang.net.NetworkHandler;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class NetworkManager
|
||||
{
|
||||
public NetworkManager(Minecraft minecraft, String server, String username, String key)
|
||||
{
|
||||
minecraft.online = true;
|
||||
|
||||
this.minecraft = minecraft;
|
||||
|
||||
players = new HashMap<Byte, NetworkPlayer>();
|
||||
|
||||
new ServerConnect(this, server, username, key, minecraft).connect();
|
||||
}
|
||||
|
||||
public ByteArrayOutputStream levelData;
|
||||
|
||||
public NetworkHandler netHandler;
|
||||
|
||||
public Minecraft minecraft;
|
||||
|
||||
public boolean successful = false;
|
||||
public boolean levelLoaded = false;
|
||||
|
||||
public HashMap<Byte, NetworkPlayer> players;
|
||||
|
||||
public void sendBlockChange(int x, int y, int z, int mode, int block)
|
||||
{
|
||||
netHandler.send(PacketType.PLAYER_SET_BLOCK, new Object[] {x, y, z, mode, block});
|
||||
}
|
||||
|
||||
public void error(Exception e)
|
||||
{
|
||||
netHandler.close();
|
||||
|
||||
ErrorScreen errorScreen = new ErrorScreen("Disconnected!", e.getMessage());
|
||||
|
||||
minecraft.setCurrentScreen(errorScreen);
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
public boolean isConnected()
|
||||
{
|
||||
return netHandler != null && netHandler.channel.connectionOpen();
|
||||
}
|
||||
|
||||
public List getPlayers()
|
||||
{
|
||||
ArrayList list = new ArrayList();
|
||||
|
||||
list.add(minecraft.session.username);
|
||||
|
||||
Iterator playerIterator = this.players.values().iterator();
|
||||
|
||||
while(playerIterator.hasNext())
|
||||
{
|
||||
NetworkPlayer networkPlayer = (NetworkPlayer)playerIterator.next();
|
||||
|
||||
list.add(networkPlayer.name);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
184
src/teavm/java/com/mojang/minecraft/net/NetworkPlayer.java
Normal file
184
src/teavm/java/com/mojang/minecraft/net/NetworkPlayer.java
Normal file
|
@ -0,0 +1,184 @@
|
|||
package com.mojang.minecraft.net;
|
||||
|
||||
import com.mojang.minecraft.Minecraft;
|
||||
import com.mojang.minecraft.gui.FontRenderer;
|
||||
import com.mojang.minecraft.mob.HumanoidMob;
|
||||
import com.mojang.minecraft.net.PositionUpdate;
|
||||
import com.mojang.minecraft.render.TextureLocation;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class NetworkPlayer extends HumanoidMob {
|
||||
|
||||
public static final long serialVersionUID = 77479605454997290L;
|
||||
private List moveQueue = new LinkedList();
|
||||
private Minecraft minecraft;
|
||||
private int xp;
|
||||
private int yp;
|
||||
private int zp;
|
||||
public String name;
|
||||
public String displayName;
|
||||
int tickCount = 0;
|
||||
|
||||
public NetworkPlayer(Minecraft var1, int var2, String var3, int var4, int var5, int var6, float var7, float var8) {
|
||||
super(var1.level, (float)var4, (float)var5, (float)var6);
|
||||
this.minecraft = var1;
|
||||
this.displayName = var3;
|
||||
var3 = FontRenderer.stripColor(var3);
|
||||
this.name = var3;
|
||||
this.xp = var4;
|
||||
this.yp = var5;
|
||||
this.zp = var6;
|
||||
this.heightOffset = 0.0F;
|
||||
this.pushthrough = 0.8F;
|
||||
this.setPos((float)var4 / 32.0F, (float)var5 / 32.0F, (float)var6 / 32.0F);
|
||||
this.xRot = var8;
|
||||
this.yRot = var7;
|
||||
this.armor = this.helmet = false;
|
||||
this.renderOffset = 0.6875F;
|
||||
this.allowAlpha = false;
|
||||
}
|
||||
|
||||
public void aiStep() {
|
||||
int var1 = 5;
|
||||
|
||||
do {
|
||||
if(this.moveQueue.size() > 0) {
|
||||
this.setPos((PositionUpdate)this.moveQueue.remove(0));
|
||||
}
|
||||
} while(var1-- > 0 && this.moveQueue.size() > 10);
|
||||
|
||||
this.onGround = true;
|
||||
}
|
||||
|
||||
public void bindTexture() {
|
||||
new TextureLocation("/char.png").bindTexture();
|
||||
}
|
||||
|
||||
public void renderHover(float var2) {
|
||||
FontRenderer var3 = this.minecraft.fontRenderer;
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(this.xo + (this.x - this.xo) * var2, this.yo + (this.y - this.yo) * var2 + 0.8F + this.renderOffset, this.zo + (this.z - this.zo) * var2);
|
||||
GL11.glRotatef(-this.minecraft.player.yRot, 0.0F, 1.0F, 0.0F);
|
||||
var2 = 0.05F;
|
||||
GL11.glScalef(0.05F, -var2, var2);
|
||||
GL11.glTranslatef((float)(-var3.getStringWidth(this.displayName)) / 2.0F, 0.0F, 0.0F);
|
||||
GL11.glNormal3f(1.0F, -1.0F, 1.0F);
|
||||
GL11.glDisable(2896);
|
||||
GL11.glDisable(16384);
|
||||
if(this.name.equalsIgnoreCase("Notch")) {
|
||||
var3.drawString(this.displayName, 0, 0, 16776960);
|
||||
} else {
|
||||
var3.drawString(this.displayName, 0, 0, 16777215);
|
||||
}
|
||||
|
||||
GL11.glDepthFunc(516);
|
||||
GL11.glDepthMask(false);
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 0.8F);
|
||||
GL11.glEnable(3042);
|
||||
GL11.glBlendFunc(770, 771);
|
||||
var3.drawString(this.displayName, 0, 0, 16777215);
|
||||
GL11.glDisable(3042);
|
||||
GL11.glDepthMask(true);
|
||||
GL11.glDepthFunc(515);
|
||||
GL11.glTranslatef(1.0F, 1.0F, -0.05F);
|
||||
var3.drawString(this.name, 0, 0, 5263440);
|
||||
GL11.glEnable(16384);
|
||||
GL11.glEnable(2896);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
public void queue(byte var1, byte var2, byte var3, float var4, float var5) {
|
||||
float var6 = var4 - this.yRot;
|
||||
|
||||
float var7;
|
||||
for(var7 = var5 - this.xRot; var6 >= 180.0F; var6 -= 360.0F) {
|
||||
;
|
||||
}
|
||||
|
||||
while(var6 < -180.0F) {
|
||||
var6 += 360.0F;
|
||||
}
|
||||
|
||||
while(var7 >= 180.0F) {
|
||||
var7 -= 360.0F;
|
||||
}
|
||||
|
||||
while(var7 < -180.0F) {
|
||||
var7 += 360.0F;
|
||||
}
|
||||
|
||||
var6 = this.yRot + var6 * 0.5F;
|
||||
var7 = this.xRot + var7 * 0.5F;
|
||||
this.moveQueue.add(new PositionUpdate(((float)this.xp + (float)var1 / 2.0F) / 32.0F, ((float)this.yp + (float)var2 / 2.0F) / 32.0F, ((float)this.zp + (float)var3 / 2.0F) / 32.0F, var6, var7));
|
||||
this.xp += var1;
|
||||
this.yp += var2;
|
||||
this.zp += var3;
|
||||
this.moveQueue.add(new PositionUpdate((float)this.xp / 32.0F, (float)this.yp / 32.0F, (float)this.zp / 32.0F, var4, var5));
|
||||
}
|
||||
|
||||
public void teleport(short var1, short var2, short var3, float var4, float var5) {
|
||||
float var6 = var4 - this.yRot;
|
||||
|
||||
float var7;
|
||||
for(var7 = var5 - this.xRot; var6 >= 180.0F; var6 -= 360.0F) {
|
||||
;
|
||||
}
|
||||
|
||||
while(var6 < -180.0F) {
|
||||
var6 += 360.0F;
|
||||
}
|
||||
|
||||
while(var7 >= 180.0F) {
|
||||
var7 -= 360.0F;
|
||||
}
|
||||
|
||||
while(var7 < -180.0F) {
|
||||
var7 += 360.0F;
|
||||
}
|
||||
|
||||
var6 = this.yRot + var6 * 0.5F;
|
||||
var7 = this.xRot + var7 * 0.5F;
|
||||
this.moveQueue.add(new PositionUpdate((float)(this.xp + var1) / 64.0F, (float)(this.yp + var2) / 64.0F, (float)(this.zp + var3) / 64.0F, var6, var7));
|
||||
this.xp = var1;
|
||||
this.yp = var2;
|
||||
this.zp = var3;
|
||||
this.moveQueue.add(new PositionUpdate((float)this.xp / 32.0F, (float)this.yp / 32.0F, (float)this.zp / 32.0F, var4, var5));
|
||||
}
|
||||
|
||||
public void queue(byte var1, byte var2, byte var3) {
|
||||
this.moveQueue.add(new PositionUpdate(((float)this.xp + (float)var1 / 2.0F) / 32.0F, ((float)this.yp + (float)var2 / 2.0F) / 32.0F, ((float)this.zp + (float)var3 / 2.0F) / 32.0F));
|
||||
this.xp += var1;
|
||||
this.yp += var2;
|
||||
this.zp += var3;
|
||||
this.moveQueue.add(new PositionUpdate((float)this.xp / 32.0F, (float)this.yp / 32.0F, (float)this.zp / 32.0F));
|
||||
}
|
||||
|
||||
public void queue(float var1, float var2) {
|
||||
float var3 = var1 - this.yRot;
|
||||
|
||||
float var4;
|
||||
for(var4 = var2 - this.xRot; var3 >= 180.0F; var3 -= 360.0F) {
|
||||
;
|
||||
}
|
||||
|
||||
while(var3 < -180.0F) {
|
||||
var3 += 360.0F;
|
||||
}
|
||||
|
||||
while(var4 >= 180.0F) {
|
||||
var4 -= 360.0F;
|
||||
}
|
||||
|
||||
while(var4 < -180.0F) {
|
||||
var4 += 360.0F;
|
||||
}
|
||||
|
||||
var3 = this.yRot + var3 * 0.5F;
|
||||
var4 = this.xRot + var4 * 0.5F;
|
||||
this.moveQueue.add(new PositionUpdate(var3, var4));
|
||||
this.moveQueue.add(new PositionUpdate(var1, var2));
|
||||
}
|
||||
}
|
86
src/teavm/java/com/mojang/minecraft/net/PacketType.java
Normal file
86
src/teavm/java/com/mojang/minecraft/net/PacketType.java
Normal file
|
@ -0,0 +1,86 @@
|
|||
package com.mojang.minecraft.net;
|
||||
|
||||
public class PacketType
|
||||
{
|
||||
private PacketType(Class ... classes)
|
||||
{
|
||||
opcode = (byte)(nextOpcode++);
|
||||
packets[opcode] = this;
|
||||
params = new Class[classes.length];
|
||||
|
||||
int length = 0;
|
||||
|
||||
for(int classNumber = 0; classNumber < classes.length; classNumber++)
|
||||
{
|
||||
Class class_ = classes[classNumber];
|
||||
|
||||
params[classNumber] = class_;
|
||||
|
||||
if(class_ == Long.TYPE)
|
||||
{
|
||||
length += 8;
|
||||
} else if(class_ == Integer.TYPE) {
|
||||
length += 4;
|
||||
} else if(class_ == Short.TYPE) {
|
||||
length += 2;
|
||||
} else if(class_ == Byte.TYPE) {
|
||||
++length;
|
||||
} else if(class_ == Float.TYPE) {
|
||||
length += 4;
|
||||
} else if(class_ == Double.TYPE) {
|
||||
length += 8;
|
||||
} else if(class_ == byte[].class) {
|
||||
length += 1024;
|
||||
} else if(class_ == String.class) {
|
||||
length += 64;
|
||||
}
|
||||
}
|
||||
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
public static final PacketType[] packets = new PacketType[256];
|
||||
|
||||
public static final PacketType IDENTIFICATION = new PacketType(new Class[] {Byte.TYPE, String.class, String.class, Byte.TYPE});
|
||||
public static final PacketType LEVEL_INIT;
|
||||
public static final PacketType LEVEL_DATA;
|
||||
public static final PacketType LEVEL_FINALIZE;
|
||||
public static final PacketType PLAYER_SET_BLOCK;
|
||||
public static final PacketType BLOCK_CHANGE;
|
||||
public static final PacketType SPAWN_PLAYER;
|
||||
public static final PacketType POSITION_ROTATION;
|
||||
public static final PacketType POSITION_ROTATION_UPDATE;
|
||||
public static final PacketType POSITION_UPDATE;
|
||||
public static final PacketType ROTATION_UPDATE;
|
||||
public static final PacketType DESPAWN_PLAYER;
|
||||
public static final PacketType CHAT_MESSAGE;
|
||||
public static final PacketType DISCONNECT;
|
||||
public static final PacketType UPDATE_PLAYER_TYPE;
|
||||
|
||||
public int length;
|
||||
private static int nextOpcode;
|
||||
public byte opcode;
|
||||
public Class[] params;
|
||||
|
||||
static
|
||||
{
|
||||
new PacketType(new Class[0]);
|
||||
|
||||
LEVEL_INIT = new PacketType(new Class[0]);
|
||||
LEVEL_DATA = new PacketType(new Class[] {Short.TYPE, byte[].class, Byte.TYPE});
|
||||
LEVEL_FINALIZE = new PacketType(new Class[] {Short.TYPE, Short.TYPE, Short.TYPE});
|
||||
PLAYER_SET_BLOCK = new PacketType(new Class[] {Short.TYPE, Short.TYPE, Short.TYPE, Byte.TYPE, Byte.TYPE});
|
||||
BLOCK_CHANGE = new PacketType(new Class[] {Short.TYPE, Short.TYPE, Short.TYPE, Byte.TYPE});
|
||||
SPAWN_PLAYER = new PacketType(new Class[] {Byte.TYPE, String.class, Short.TYPE, Short.TYPE, Short.TYPE, Byte.TYPE, Byte.TYPE});
|
||||
POSITION_ROTATION = new PacketType(new Class[] {Byte.TYPE, Short.TYPE, Short.TYPE, Short.TYPE, Byte.TYPE, Byte.TYPE});
|
||||
POSITION_ROTATION_UPDATE = new PacketType(new Class[] {Byte.TYPE, Byte.TYPE, Byte.TYPE, Byte.TYPE, Byte.TYPE, Byte.TYPE});
|
||||
POSITION_UPDATE = new PacketType(new Class[] {Byte.TYPE, Byte.TYPE, Byte.TYPE, Byte.TYPE});
|
||||
ROTATION_UPDATE = new PacketType(new Class[] {Byte.TYPE, Byte.TYPE, Byte.TYPE});
|
||||
DESPAWN_PLAYER = new PacketType(new Class[] {Byte.TYPE});
|
||||
CHAT_MESSAGE = new PacketType(new Class[] {Byte.TYPE, String.class});
|
||||
DISCONNECT = new PacketType(new Class[] {String.class});
|
||||
UPDATE_PLAYER_TYPE = new PacketType(new Class[] {Byte.TYPE});
|
||||
|
||||
nextOpcode = 0;
|
||||
}
|
||||
}
|
45
src/teavm/java/com/mojang/minecraft/net/PositionUpdate.java
Normal file
45
src/teavm/java/com/mojang/minecraft/net/PositionUpdate.java
Normal file
|
@ -0,0 +1,45 @@
|
|||
package com.mojang.minecraft.net;
|
||||
|
||||
public class PositionUpdate
|
||||
{
|
||||
public PositionUpdate(float x, float y, float z, float yaw, float pitch)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.yaw = yaw;
|
||||
this.pitch = pitch;
|
||||
|
||||
rotation = true;
|
||||
position = true;
|
||||
}
|
||||
|
||||
public PositionUpdate(float x, float y, float z)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
|
||||
position = true;
|
||||
rotation = false;
|
||||
}
|
||||
|
||||
public PositionUpdate(float yaw, float pitch)
|
||||
{
|
||||
this.yaw = yaw;
|
||||
this.pitch = pitch;
|
||||
|
||||
rotation = true;
|
||||
position = false;
|
||||
}
|
||||
|
||||
public float x;
|
||||
public float y;
|
||||
public float z;
|
||||
|
||||
public float yaw;
|
||||
public float pitch;
|
||||
|
||||
public boolean rotation = false;
|
||||
public boolean position = false;
|
||||
}
|
50
src/teavm/java/com/mojang/minecraft/net/ServerConnect.java
Normal file
50
src/teavm/java/com/mojang/minecraft/net/ServerConnect.java
Normal file
|
@ -0,0 +1,50 @@
|
|||
package com.mojang.minecraft.net;
|
||||
|
||||
import com.mojang.minecraft.Minecraft;
|
||||
import com.mojang.minecraft.gui.ErrorScreen;
|
||||
import com.mojang.net.NetworkHandler;
|
||||
|
||||
public class ServerConnect
|
||||
{
|
||||
public ServerConnect(NetworkManager networkManager, String server, String username, String key, Minecraft minecraft) {
|
||||
super();
|
||||
|
||||
netManager = networkManager;
|
||||
|
||||
this.server = server;
|
||||
|
||||
this.username = username;
|
||||
this.key = key;
|
||||
|
||||
this.minecraft = minecraft;
|
||||
}
|
||||
|
||||
public void connect()
|
||||
{
|
||||
try {
|
||||
netManager.netHandler = new NetworkHandler(server);
|
||||
netManager.netHandler.netManager = netManager;
|
||||
|
||||
netManager.netHandler.send(PacketType.IDENTIFICATION, new Object[]{Byte.valueOf((byte)7), this.username, this.key, Integer.valueOf(0)});
|
||||
|
||||
netManager.successful = true;
|
||||
} catch (Exception var3) {
|
||||
minecraft.online = false;
|
||||
|
||||
minecraft.networkManager = null;
|
||||
|
||||
minecraft.setCurrentScreen(new ErrorScreen("Failed to connect", "You failed to connect to the server. It\'s probably down!"));
|
||||
|
||||
netManager.successful = false;
|
||||
}
|
||||
}
|
||||
|
||||
private String server;
|
||||
|
||||
private String username;
|
||||
private String key;
|
||||
|
||||
private Minecraft minecraft;
|
||||
|
||||
private NetworkManager netManager;
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
package com.mojang.minecraft.render;
|
||||
|
||||
import com.mojang.minecraft.Minecraft;
|
||||
import com.mojang.minecraft.level.Level;
|
||||
import com.mojang.minecraft.level.tile.Block;
|
||||
import com.mojang.minecraft.player.Player;
|
||||
import com.mojang.minecraft.render.Frustrum;
|
||||
|
||||
import net.PeytonPlayz585.math.MathHelper;
|
||||
import net.lax1dude.eaglercraft.adapter.Tessellator;
|
||||
|
||||
|
@ -33,7 +33,7 @@ public final class Chunk {
|
|||
this.y = var3;
|
||||
this.z = var4;
|
||||
this.width = this.height = this.depth = 16;
|
||||
MathHelper.sqrt((float)(this.width + this.height + this.depth));
|
||||
MathHelper.sqrt((float)(this.width * this.width + this.height * this.height + this.depth * this.depth));
|
||||
this.baseListId = var6;
|
||||
this.setAllDirty();
|
||||
}
|
||||
|
@ -47,10 +47,12 @@ public final class Chunk {
|
|||
int var5 = this.y + this.height;
|
||||
int var6 = this.z + this.depth;
|
||||
|
||||
this.dirty[1] = true;
|
||||
this.dirty[2] = true;
|
||||
int var7;
|
||||
for(var7 = 0; var7 < 2; ++var7) {
|
||||
this.dirty[var7] = true;
|
||||
}
|
||||
|
||||
for(int var7 = 0; var7 < 2; ++var7) {
|
||||
for(var7 = 0; var7 < 2; ++var7) {
|
||||
boolean var8 = false;
|
||||
boolean var9 = false;
|
||||
GL11.glNewList(this.baseListId + var7, 4864);
|
||||
|
@ -120,4 +122,4 @@ public final class Chunk {
|
|||
this.visible = var1.isBoxInFrustrum((float)this.x, (float)this.y, (float)this.z, (float)(this.x + this.width), (float)(this.y + this.height), (float)(this.z + this.depth));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -23,9 +23,9 @@ public class ChunkDistanceComparator implements Comparator
|
|||
{
|
||||
return 0;
|
||||
} else if(sqDist > otherSqDist) {
|
||||
return 1;
|
||||
} else {
|
||||
return -1;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
package com.mojang.minecraft.render;
|
||||
|
||||
public class ClippingHelper {
|
||||
|
||||
public ClippingHelper() {
|
||||
frustum = new float[16][16];
|
||||
projectionMatrix = new float[16];
|
||||
modelviewMatrix = new float[16];
|
||||
clippingMatrix = new float[16];
|
||||
}
|
||||
|
||||
public boolean isBoxInFrustum(double d, double d1, double d2, double d3, double d4, double d5) {
|
||||
for (int i = 0; i < 6; i++) {
|
||||
if ((double) frustum[i][0] * d + (double) frustum[i][1] * d1 + (double) frustum[i][2] * d2
|
||||
+ (double) frustum[i][3] <= 0.0D
|
||||
&& (double) frustum[i][0] * d3 + (double) frustum[i][1] * d1 + (double) frustum[i][2] * d2
|
||||
+ (double) frustum[i][3] <= 0.0D
|
||||
&& (double) frustum[i][0] * d + (double) frustum[i][1] * d4 + (double) frustum[i][2] * d2
|
||||
+ (double) frustum[i][3] <= 0.0D
|
||||
&& (double) frustum[i][0] * d3 + (double) frustum[i][1] * d4 + (double) frustum[i][2] * d2
|
||||
+ (double) frustum[i][3] <= 0.0D
|
||||
&& (double) frustum[i][0] * d + (double) frustum[i][1] * d1 + (double) frustum[i][2] * d5
|
||||
+ (double) frustum[i][3] <= 0.0D
|
||||
&& (double) frustum[i][0] * d3 + (double) frustum[i][1] * d1 + (double) frustum[i][2] * d5
|
||||
+ (double) frustum[i][3] <= 0.0D
|
||||
&& (double) frustum[i][0] * d + (double) frustum[i][1] * d4 + (double) frustum[i][2] * d5
|
||||
+ (double) frustum[i][3] <= 0.0D
|
||||
&& (double) frustum[i][0] * d3 + (double) frustum[i][1] * d4 + (double) frustum[i][2] * d5
|
||||
+ (double) frustum[i][3] <= 0.0D) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public float frustum[][];
|
||||
public float projectionMatrix[];
|
||||
public float modelviewMatrix[];
|
||||
public float clippingMatrix[];
|
||||
}
|
|
@ -1,114 +0,0 @@
|
|||
package com.mojang.minecraft.render;
|
||||
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
|
||||
|
||||
// Jad home page: http://www.kpdus.com/jad.html
|
||||
// Decompiler options: packimports(3) braces deadcode
|
||||
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.PeytonPlayz585.math.MathHelper;
|
||||
import net.lax1dude.eaglercraft.GLAllocation;
|
||||
|
||||
public class ClippingHelperImplementation extends ClippingHelper {
|
||||
|
||||
public ClippingHelperImplementation() {
|
||||
projectionMatrixBuffer = GLAllocation.createDirectFloatBuffer(16);
|
||||
modelviewMatrixBuffer = GLAllocation.createDirectFloatBuffer(16);
|
||||
field_1691_h = GLAllocation.createDirectFloatBuffer(16);
|
||||
}
|
||||
|
||||
public static ClippingHelper getInstance() {
|
||||
instance.init();
|
||||
return instance;
|
||||
}
|
||||
|
||||
private void normalize(float af[][], int i) {
|
||||
float f = MathHelper.sqrt(af[i][0] * af[i][0] + af[i][1] * af[i][1] + af[i][2] * af[i][2]);
|
||||
af[i][0] /= f;
|
||||
af[i][1] /= f;
|
||||
af[i][2] /= f;
|
||||
af[i][3] /= f;
|
||||
}
|
||||
|
||||
private void init() {
|
||||
projectionMatrixBuffer.clear();
|
||||
modelviewMatrixBuffer.clear();
|
||||
field_1691_h.clear();
|
||||
GL11.glGetFloat(2983 /* GL_PROJECTION_MATRIX */, projectionMatrixBuffer);
|
||||
GL11.glGetFloat(2982 /* GL_MODELVIEW_MATRIX */, modelviewMatrixBuffer);
|
||||
projectionMatrixBuffer.flip().limit(16);
|
||||
projectionMatrixBuffer.get(projectionMatrix);
|
||||
modelviewMatrixBuffer.flip().limit(16);
|
||||
modelviewMatrixBuffer.get(modelviewMatrix);
|
||||
clippingMatrix[0] = modelviewMatrix[0] * projectionMatrix[0] + modelviewMatrix[1] * projectionMatrix[4]
|
||||
+ modelviewMatrix[2] * projectionMatrix[8] + modelviewMatrix[3] * projectionMatrix[12];
|
||||
clippingMatrix[1] = modelviewMatrix[0] * projectionMatrix[1] + modelviewMatrix[1] * projectionMatrix[5]
|
||||
+ modelviewMatrix[2] * projectionMatrix[9] + modelviewMatrix[3] * projectionMatrix[13];
|
||||
clippingMatrix[2] = modelviewMatrix[0] * projectionMatrix[2] + modelviewMatrix[1] * projectionMatrix[6]
|
||||
+ modelviewMatrix[2] * projectionMatrix[10] + modelviewMatrix[3] * projectionMatrix[14];
|
||||
clippingMatrix[3] = modelviewMatrix[0] * projectionMatrix[3] + modelviewMatrix[1] * projectionMatrix[7]
|
||||
+ modelviewMatrix[2] * projectionMatrix[11] + modelviewMatrix[3] * projectionMatrix[15];
|
||||
clippingMatrix[4] = modelviewMatrix[4] * projectionMatrix[0] + modelviewMatrix[5] * projectionMatrix[4]
|
||||
+ modelviewMatrix[6] * projectionMatrix[8] + modelviewMatrix[7] * projectionMatrix[12];
|
||||
clippingMatrix[5] = modelviewMatrix[4] * projectionMatrix[1] + modelviewMatrix[5] * projectionMatrix[5]
|
||||
+ modelviewMatrix[6] * projectionMatrix[9] + modelviewMatrix[7] * projectionMatrix[13];
|
||||
clippingMatrix[6] = modelviewMatrix[4] * projectionMatrix[2] + modelviewMatrix[5] * projectionMatrix[6]
|
||||
+ modelviewMatrix[6] * projectionMatrix[10] + modelviewMatrix[7] * projectionMatrix[14];
|
||||
clippingMatrix[7] = modelviewMatrix[4] * projectionMatrix[3] + modelviewMatrix[5] * projectionMatrix[7]
|
||||
+ modelviewMatrix[6] * projectionMatrix[11] + modelviewMatrix[7] * projectionMatrix[15];
|
||||
clippingMatrix[8] = modelviewMatrix[8] * projectionMatrix[0] + modelviewMatrix[9] * projectionMatrix[4]
|
||||
+ modelviewMatrix[10] * projectionMatrix[8] + modelviewMatrix[11] * projectionMatrix[12];
|
||||
clippingMatrix[9] = modelviewMatrix[8] * projectionMatrix[1] + modelviewMatrix[9] * projectionMatrix[5]
|
||||
+ modelviewMatrix[10] * projectionMatrix[9] + modelviewMatrix[11] * projectionMatrix[13];
|
||||
clippingMatrix[10] = modelviewMatrix[8] * projectionMatrix[2] + modelviewMatrix[9] * projectionMatrix[6]
|
||||
+ modelviewMatrix[10] * projectionMatrix[10] + modelviewMatrix[11] * projectionMatrix[14];
|
||||
clippingMatrix[11] = modelviewMatrix[8] * projectionMatrix[3] + modelviewMatrix[9] * projectionMatrix[7]
|
||||
+ modelviewMatrix[10] * projectionMatrix[11] + modelviewMatrix[11] * projectionMatrix[15];
|
||||
clippingMatrix[12] = modelviewMatrix[12] * projectionMatrix[0] + modelviewMatrix[13] * projectionMatrix[4]
|
||||
+ modelviewMatrix[14] * projectionMatrix[8] + modelviewMatrix[15] * projectionMatrix[12];
|
||||
clippingMatrix[13] = modelviewMatrix[12] * projectionMatrix[1] + modelviewMatrix[13] * projectionMatrix[5]
|
||||
+ modelviewMatrix[14] * projectionMatrix[9] + modelviewMatrix[15] * projectionMatrix[13];
|
||||
clippingMatrix[14] = modelviewMatrix[12] * projectionMatrix[2] + modelviewMatrix[13] * projectionMatrix[6]
|
||||
+ modelviewMatrix[14] * projectionMatrix[10] + modelviewMatrix[15] * projectionMatrix[14];
|
||||
clippingMatrix[15] = modelviewMatrix[12] * projectionMatrix[3] + modelviewMatrix[13] * projectionMatrix[7]
|
||||
+ modelviewMatrix[14] * projectionMatrix[11] + modelviewMatrix[15] * projectionMatrix[15];
|
||||
frustum[0][0] = clippingMatrix[3] - clippingMatrix[0];
|
||||
frustum[0][1] = clippingMatrix[7] - clippingMatrix[4];
|
||||
frustum[0][2] = clippingMatrix[11] - clippingMatrix[8];
|
||||
frustum[0][3] = clippingMatrix[15] - clippingMatrix[12];
|
||||
normalize(frustum, 0);
|
||||
frustum[1][0] = clippingMatrix[3] + clippingMatrix[0];
|
||||
frustum[1][1] = clippingMatrix[7] + clippingMatrix[4];
|
||||
frustum[1][2] = clippingMatrix[11] + clippingMatrix[8];
|
||||
frustum[1][3] = clippingMatrix[15] + clippingMatrix[12];
|
||||
normalize(frustum, 1);
|
||||
frustum[2][0] = clippingMatrix[3] + clippingMatrix[1];
|
||||
frustum[2][1] = clippingMatrix[7] + clippingMatrix[5];
|
||||
frustum[2][2] = clippingMatrix[11] + clippingMatrix[9];
|
||||
frustum[2][3] = clippingMatrix[15] + clippingMatrix[13];
|
||||
normalize(frustum, 2);
|
||||
frustum[3][0] = clippingMatrix[3] - clippingMatrix[1];
|
||||
frustum[3][1] = clippingMatrix[7] - clippingMatrix[5];
|
||||
frustum[3][2] = clippingMatrix[11] - clippingMatrix[9];
|
||||
frustum[3][3] = clippingMatrix[15] - clippingMatrix[13];
|
||||
normalize(frustum, 3);
|
||||
frustum[4][0] = clippingMatrix[3] - clippingMatrix[2];
|
||||
frustum[4][1] = clippingMatrix[7] - clippingMatrix[6];
|
||||
frustum[4][2] = clippingMatrix[11] - clippingMatrix[10];
|
||||
frustum[4][3] = clippingMatrix[15] - clippingMatrix[14];
|
||||
normalize(frustum, 4);
|
||||
frustum[5][0] = clippingMatrix[3] + clippingMatrix[2];
|
||||
frustum[5][1] = clippingMatrix[7] + clippingMatrix[6];
|
||||
frustum[5][2] = clippingMatrix[11] + clippingMatrix[10];
|
||||
frustum[5][3] = clippingMatrix[15] + clippingMatrix[14];
|
||||
normalize(frustum, 5);
|
||||
}
|
||||
|
||||
private static ClippingHelperImplementation instance = new ClippingHelperImplementation();
|
||||
private FloatBuffer projectionMatrixBuffer;
|
||||
private FloatBuffer modelviewMatrixBuffer;
|
||||
private FloatBuffer field_1691_h;
|
||||
|
||||
}
|
|
@ -1,29 +1,21 @@
|
|||
package com.mojang.minecraft.render;
|
||||
|
||||
|
||||
public class Frustrum {
|
||||
|
||||
public Frustrum() {
|
||||
clippingHelper = ClippingHelperImplementation.getInstance();
|
||||
}
|
||||
public float[][] frustrum = new float[16][16];
|
||||
public float[] projection = new float[16];
|
||||
public float[] modelview = new float[16];
|
||||
public float[] clipping = new float[16];
|
||||
|
||||
public void setPosition(double d, double d1, double d2) {
|
||||
xPosition = d;
|
||||
yPosition = d1;
|
||||
zPosition = d2;
|
||||
}
|
||||
|
||||
public boolean isBoxInFrustrum(double d, double d1, double d2, double d3, double d4, double d5) {
|
||||
return clippingHelper.isBoxInFrustum(d - xPosition, d1 - yPosition, d2 - zPosition, d3 - xPosition,
|
||||
d4 - yPosition, d5 - zPosition);
|
||||
}
|
||||
public final boolean isBoxInFrustrum(float var1, float var2, float var3, float var4, float var5, float var6) {
|
||||
for(int var7 = 0; var7 < 6; ++var7) {
|
||||
if(this.frustrum[var7][0] * var1 + this.frustrum[var7][1] * var2 + this.frustrum[var7][2] * var3 + this.frustrum[var7][3] <= 0.0F && this.frustrum[var7][0] * var4 + this.frustrum[var7][1] * var2 + this.frustrum[var7][2] * var3 + this.frustrum[var7][3] <= 0.0F && this.frustrum[var7][0] * var1 + this.frustrum[var7][1] * var5 + this.frustrum[var7][2] * var3 + this.frustrum[var7][3] <= 0.0F && this.frustrum[var7][0] * var4 + this.frustrum[var7][1] * var5 + this.frustrum[var7][2] * var3 + this.frustrum[var7][3] <= 0.0F && this.frustrum[var7][0] * var1 + this.frustrum[var7][1] * var2 + this.frustrum[var7][2] * var6 + this.frustrum[var7][3] <= 0.0F && this.frustrum[var7][0] * var4 + this.frustrum[var7][1] * var2 + this.frustrum[var7][2] * var6 + this.frustrum[var7][3] <= 0.0F && this.frustrum[var7][0] * var1 + this.frustrum[var7][1] * var5 + this.frustrum[var7][2] * var6 + this.frustrum[var7][3] <= 0.0F && this.frustrum[var7][0] * var4 + this.frustrum[var7][1] * var5 + this.frustrum[var7][2] * var6 + this.frustrum[var7][3] <= 0.0F) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// public boolean isBoundingBoxInFrustum(AxisAlignedBB axisalignedbb) {
|
||||
// return isBoxInFrustum(axisalignedbb.minX, axisalignedbb.minY, axisalignedbb.minZ, axisalignedbb.maxX,
|
||||
// axisalignedbb.maxY, axisalignedbb.maxZ);
|
||||
// }
|
||||
|
||||
public ClippingHelper clippingHelper;
|
||||
private double xPosition;
|
||||
private double yPosition;
|
||||
private double zPosition;
|
||||
return true;
|
||||
}
|
||||
}
|
87
src/teavm/java/com/mojang/minecraft/render/FrustrumImpl.java
Normal file
87
src/teavm/java/com/mojang/minecraft/render/FrustrumImpl.java
Normal file
|
@ -0,0 +1,87 @@
|
|||
package com.mojang.minecraft.render;
|
||||
|
||||
import com.mojang.minecraft.render.Frustrum;
|
||||
|
||||
import net.PeytonPlayz585.math.MathHelper;
|
||||
import net.lax1dude.eaglercraft.GLAllocation;
|
||||
|
||||
import java.nio.FloatBuffer;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public final class FrustrumImpl extends Frustrum {
|
||||
|
||||
private static FrustrumImpl instance = new FrustrumImpl();
|
||||
private FloatBuffer projectionBuff = GLAllocation.createDirectFloatBuffer(16);
|
||||
private FloatBuffer modelviewBuff = GLAllocation.createDirectFloatBuffer(16);
|
||||
private FloatBuffer unused = GLAllocation.createDirectFloatBuffer(16);
|
||||
|
||||
|
||||
public static Frustrum update() {
|
||||
FrustrumImpl var0 = instance;
|
||||
instance.projectionBuff.clear();
|
||||
var0.modelviewBuff.clear();
|
||||
var0.unused.clear();
|
||||
GL11.glGetFloat(2983, var0.projectionBuff);
|
||||
GL11.glGetFloat(2982, var0.modelviewBuff);
|
||||
var0.projectionBuff.flip().limit(16);
|
||||
var0.projectionBuff.get(var0.projection);
|
||||
var0.modelviewBuff.flip().limit(16);
|
||||
var0.modelviewBuff.get(var0.modelview);
|
||||
var0.clipping[0] = var0.modelview[0] * var0.projection[0] + var0.modelview[1] * var0.projection[4] + var0.modelview[2] * var0.projection[8] + var0.modelview[3] * var0.projection[12];
|
||||
var0.clipping[1] = var0.modelview[0] * var0.projection[1] + var0.modelview[1] * var0.projection[5] + var0.modelview[2] * var0.projection[9] + var0.modelview[3] * var0.projection[13];
|
||||
var0.clipping[2] = var0.modelview[0] * var0.projection[2] + var0.modelview[1] * var0.projection[6] + var0.modelview[2] * var0.projection[10] + var0.modelview[3] * var0.projection[14];
|
||||
var0.clipping[3] = var0.modelview[0] * var0.projection[3] + var0.modelview[1] * var0.projection[7] + var0.modelview[2] * var0.projection[11] + var0.modelview[3] * var0.projection[15];
|
||||
var0.clipping[4] = var0.modelview[4] * var0.projection[0] + var0.modelview[5] * var0.projection[4] + var0.modelview[6] * var0.projection[8] + var0.modelview[7] * var0.projection[12];
|
||||
var0.clipping[5] = var0.modelview[4] * var0.projection[1] + var0.modelview[5] * var0.projection[5] + var0.modelview[6] * var0.projection[9] + var0.modelview[7] * var0.projection[13];
|
||||
var0.clipping[6] = var0.modelview[4] * var0.projection[2] + var0.modelview[5] * var0.projection[6] + var0.modelview[6] * var0.projection[10] + var0.modelview[7] * var0.projection[14];
|
||||
var0.clipping[7] = var0.modelview[4] * var0.projection[3] + var0.modelview[5] * var0.projection[7] + var0.modelview[6] * var0.projection[11] + var0.modelview[7] * var0.projection[15];
|
||||
var0.clipping[8] = var0.modelview[8] * var0.projection[0] + var0.modelview[9] * var0.projection[4] + var0.modelview[10] * var0.projection[8] + var0.modelview[11] * var0.projection[12];
|
||||
var0.clipping[9] = var0.modelview[8] * var0.projection[1] + var0.modelview[9] * var0.projection[5] + var0.modelview[10] * var0.projection[9] + var0.modelview[11] * var0.projection[13];
|
||||
var0.clipping[10] = var0.modelview[8] * var0.projection[2] + var0.modelview[9] * var0.projection[6] + var0.modelview[10] * var0.projection[10] + var0.modelview[11] * var0.projection[14];
|
||||
var0.clipping[11] = var0.modelview[8] * var0.projection[3] + var0.modelview[9] * var0.projection[7] + var0.modelview[10] * var0.projection[11] + var0.modelview[11] * var0.projection[15];
|
||||
var0.clipping[12] = var0.modelview[12] * var0.projection[0] + var0.modelview[13] * var0.projection[4] + var0.modelview[14] * var0.projection[8] + var0.modelview[15] * var0.projection[12];
|
||||
var0.clipping[13] = var0.modelview[12] * var0.projection[1] + var0.modelview[13] * var0.projection[5] + var0.modelview[14] * var0.projection[9] + var0.modelview[15] * var0.projection[13];
|
||||
var0.clipping[14] = var0.modelview[12] * var0.projection[2] + var0.modelview[13] * var0.projection[6] + var0.modelview[14] * var0.projection[10] + var0.modelview[15] * var0.projection[14];
|
||||
var0.clipping[15] = var0.modelview[12] * var0.projection[3] + var0.modelview[13] * var0.projection[7] + var0.modelview[14] * var0.projection[11] + var0.modelview[15] * var0.projection[15];
|
||||
var0.frustrum[0][0] = var0.clipping[3] - var0.clipping[0];
|
||||
var0.frustrum[0][1] = var0.clipping[7] - var0.clipping[4];
|
||||
var0.frustrum[0][2] = var0.clipping[11] - var0.clipping[8];
|
||||
var0.frustrum[0][3] = var0.clipping[15] - var0.clipping[12];
|
||||
normalize(var0.frustrum, 0);
|
||||
var0.frustrum[1][0] = var0.clipping[3] + var0.clipping[0];
|
||||
var0.frustrum[1][1] = var0.clipping[7] + var0.clipping[4];
|
||||
var0.frustrum[1][2] = var0.clipping[11] + var0.clipping[8];
|
||||
var0.frustrum[1][3] = var0.clipping[15] + var0.clipping[12];
|
||||
normalize(var0.frustrum, 1);
|
||||
var0.frustrum[2][0] = var0.clipping[3] + var0.clipping[1];
|
||||
var0.frustrum[2][1] = var0.clipping[7] + var0.clipping[5];
|
||||
var0.frustrum[2][2] = var0.clipping[11] + var0.clipping[9];
|
||||
var0.frustrum[2][3] = var0.clipping[15] + var0.clipping[13];
|
||||
normalize(var0.frustrum, 2);
|
||||
var0.frustrum[3][0] = var0.clipping[3] - var0.clipping[1];
|
||||
var0.frustrum[3][1] = var0.clipping[7] - var0.clipping[5];
|
||||
var0.frustrum[3][2] = var0.clipping[11] - var0.clipping[9];
|
||||
var0.frustrum[3][3] = var0.clipping[15] - var0.clipping[13];
|
||||
normalize(var0.frustrum, 3);
|
||||
var0.frustrum[4][0] = var0.clipping[3] - var0.clipping[2];
|
||||
var0.frustrum[4][1] = var0.clipping[7] - var0.clipping[6];
|
||||
var0.frustrum[4][2] = var0.clipping[11] - var0.clipping[10];
|
||||
var0.frustrum[4][3] = var0.clipping[15] - var0.clipping[14];
|
||||
normalize(var0.frustrum, 4);
|
||||
var0.frustrum[5][0] = var0.clipping[3] + var0.clipping[2];
|
||||
var0.frustrum[5][1] = var0.clipping[7] + var0.clipping[6];
|
||||
var0.frustrum[5][2] = var0.clipping[11] + var0.clipping[10];
|
||||
var0.frustrum[5][3] = var0.clipping[15] + var0.clipping[14];
|
||||
normalize(var0.frustrum, 5);
|
||||
return instance;
|
||||
}
|
||||
|
||||
private static void normalize(float[][] var0, int var1) {
|
||||
float var2 = MathHelper.sqrt(var0[var1][0] * var0[var1][0] + var0[var1][1] * var0[var1][1] + var0[var1][2] * var0[var1][2]);
|
||||
var0[var1][0] /= var2;
|
||||
var0[var1][1] /= var2;
|
||||
var0[var1][2] /= var2;
|
||||
var0[var1][3] /= var2;
|
||||
}
|
||||
|
||||
}
|
|
@ -17,7 +17,7 @@ public final class LevelRenderer {
|
|||
|
||||
public Level level;
|
||||
public int listId;
|
||||
public IntBuffer buffer = GLAllocation.createDirectIntBuffer(4096);
|
||||
public IntBuffer buffer = GLAllocation.createDirectIntBuffer(65536);
|
||||
public List<Chunk> chunks = new ArrayList<Chunk>();
|
||||
private Chunk[] loadQueue;
|
||||
public Chunk[] chunkCache;
|
||||
|
@ -26,7 +26,7 @@ public final class LevelRenderer {
|
|||
private int zChunks;
|
||||
private int baseListId;
|
||||
public Minecraft minecraft;
|
||||
private int[] chunkDataCache = new int[1024];
|
||||
private int[] chunkDataCache = new int['\uc350'];
|
||||
public int ticks = 0;
|
||||
private float lastLoadX = -9999.0F;
|
||||
private float lastLoadY = -9999.0F;
|
||||
|
@ -37,7 +37,7 @@ public final class LevelRenderer {
|
|||
public LevelRenderer(Minecraft var1) {
|
||||
this.minecraft = var1;
|
||||
this.listId = GL11.glGenLists(2);
|
||||
this.baseListId = GL11.glGenLists(4096);
|
||||
this.baseListId = GL11.glGenLists(4096 << 6 << 1);
|
||||
}
|
||||
|
||||
public final void refresh() {
|
||||
|
|
170
src/teavm/java/com/mojang/net/NetworkHandler.java
Normal file
170
src/teavm/java/com/mojang/net/NetworkHandler.java
Normal file
|
@ -0,0 +1,170 @@
|
|||
package com.mojang.net;
|
||||
|
||||
import com.mojang.minecraft.Minecraft;
|
||||
import com.mojang.minecraft.gamemode.CreativeGameMode;
|
||||
import com.mojang.minecraft.gui.ErrorScreen;
|
||||
import com.mojang.minecraft.net.NetworkManager;
|
||||
import com.mojang.minecraft.net.PacketType;
|
||||
|
||||
import net.PeytonPlayz585.websocket.WebSocketChannel;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.teavm.jso.JSBody;
|
||||
|
||||
public final class NetworkHandler {
|
||||
|
||||
public ByteBuffer in = ByteBuffer.allocate(1048576);
|
||||
public ByteBuffer out = ByteBuffer.allocate(1048576);
|
||||
public NetworkManager netManager;
|
||||
private boolean unused = false;
|
||||
private byte[] stringBytes = new byte[64];
|
||||
public WebSocketChannel channel;
|
||||
|
||||
|
||||
public NetworkHandler(String var1) {
|
||||
Minecraft.getMinecraft().gamemode = new CreativeGameMode(Minecraft.getMinecraft());
|
||||
String address = var1;
|
||||
if(address.endsWith("/")) {
|
||||
address = address.substring(0, address.length() - 1);
|
||||
}
|
||||
|
||||
if(address.startsWith("ws://") && isSSLPage()) {
|
||||
address.replace("ws://", "wss://");
|
||||
} else if(address.startsWith("wss://") && !isSSLPage()) {
|
||||
address.replace("wss://", "ws://");
|
||||
} else if(!address.contains("://")) {
|
||||
if(isSSLPage()) {
|
||||
address = "wss://" + address;
|
||||
} else {
|
||||
address = "ws://" + address;
|
||||
}
|
||||
} else if(address.contains("://") && !(address.contains("wss://") || address.contains("ws://"))) {
|
||||
Minecraft.getMinecraft().setCurrentScreen(new ErrorScreen(":(", "Invalid URI protocol!"));
|
||||
}
|
||||
|
||||
channel = new WebSocketChannel(address);
|
||||
}
|
||||
|
||||
public final void close() {
|
||||
try {
|
||||
if(this.out.position() > 0) {
|
||||
this.out.flip();
|
||||
this.channel.write(this.out);
|
||||
this.out.compact();
|
||||
}
|
||||
} catch (Exception var2) {
|
||||
;
|
||||
}
|
||||
|
||||
try {
|
||||
channel.endConnection();
|
||||
} catch (Exception var1) {
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
public final void send(PacketType var1, Object ... var2) {
|
||||
if(channel.connectionOpen()) {
|
||||
this.out.put(var1.opcode);
|
||||
|
||||
for(int var3 = 0; var3 < var2.length; ++var3) {
|
||||
Class<?> var10001 = var1.params[var3];
|
||||
Object var4 = var2[var3];
|
||||
Class<?> var5 = var10001;
|
||||
NetworkHandler var6 = this;
|
||||
if(channel.connectionOpen()) {
|
||||
try {
|
||||
if(var5 == Long.TYPE) {
|
||||
var6.out.putLong(((Long)var4).longValue());
|
||||
} else if(var5 == Integer.TYPE) {
|
||||
var6.out.putInt(((Number)var4).intValue());
|
||||
} else if(var5 == Short.TYPE) {
|
||||
var6.out.putShort(((Number)var4).shortValue());
|
||||
} else if(var5 == Byte.TYPE) {
|
||||
var6.out.put(((Number)var4).byteValue());
|
||||
} else if(var5 == Double.TYPE) {
|
||||
var6.out.putDouble(((Double)var4).doubleValue());
|
||||
} else if(var5 == Float.TYPE) {
|
||||
var6.out.putFloat(((Float)var4).floatValue());
|
||||
} else {
|
||||
byte[] var9;
|
||||
if(var5 != String.class) {
|
||||
if(var5 == byte[].class) {
|
||||
if((var9 = (byte[])((byte[])var4)).length < 1024) {
|
||||
var9 = Arrays.copyOf(var9, 1024);
|
||||
}
|
||||
|
||||
var6.out.put(var9);
|
||||
}
|
||||
} else {
|
||||
if(var4 != null) {
|
||||
var9 = ((String)var4).getBytes("UTF-8");
|
||||
Arrays.fill(var6.stringBytes, (byte)32);
|
||||
|
||||
int var8;
|
||||
for(var8 = 0; var8 < 64 && var8 < var9.length; ++var8) {
|
||||
var6.stringBytes[var8] = var9[var8];
|
||||
}
|
||||
|
||||
for(var8 = var9.length; var8 < 64; ++var8) {
|
||||
var6.stringBytes[var8] = 32;
|
||||
}
|
||||
|
||||
var6.out.put(var6.stringBytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception var7) {
|
||||
this.netManager.error(var7);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public Object readObject(Class var1) {
|
||||
if(!channel.connectionOpen()) {
|
||||
return null;
|
||||
} else {
|
||||
try {
|
||||
if(var1 == Long.TYPE) {
|
||||
return Long.valueOf(this.in.getLong());
|
||||
} else if(var1 == Integer.TYPE) {
|
||||
return Integer.valueOf(this.in.getInt());
|
||||
} else if(var1 == Short.TYPE) {
|
||||
return Short.valueOf(this.in.getShort());
|
||||
} else if(var1 == Byte.TYPE) {
|
||||
return Byte.valueOf(this.in.get());
|
||||
} else if(var1 == Double.TYPE) {
|
||||
return Double.valueOf(this.in.getDouble());
|
||||
} else if(var1 == Float.TYPE) {
|
||||
return Float.valueOf(this.in.getFloat());
|
||||
} else if(var1 == String.class) {
|
||||
this.in.get(this.stringBytes);
|
||||
return (new String(this.stringBytes, "UTF-8")).trim();
|
||||
} else if(var1 == byte[].class) {
|
||||
byte[] var3 = new byte[1024];
|
||||
this.in.get(var3);
|
||||
return var3;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (Exception var2) {
|
||||
this.netManager.error(var2);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@JSBody(params = { }, script = "return window.location.href;")
|
||||
private static native String getLocationString();
|
||||
|
||||
public static final boolean isSSLPage() {
|
||||
return getLocationString().startsWith("https");
|
||||
}
|
||||
}
|
|
@ -108,6 +108,11 @@ public class LevelUtils {
|
|||
}
|
||||
|
||||
public void save() {
|
||||
|
||||
if(Minecraft.getMinecraft().networkManager != null || Minecraft.getMinecraft().level == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Level var1 = Minecraft.getMinecraft().level;
|
||||
NBTTagCompound var3 = new NBTTagCompound();
|
||||
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
package net.PeytonPlayz585.websocket;
|
||||
|
||||
import org.teavm.jso.JSBody;
|
||||
import org.teavm.jso.ajax.*;
|
||||
import org.teavm.jso.dom.events.MessageEvent;
|
||||
import org.teavm.jso.typedarrays.ArrayBuffer;
|
||||
import org.teavm.jso.typedarrays.DataView;
|
||||
import org.teavm.jso.typedarrays.Int8Array;
|
||||
import org.teavm.jso.websocket.WebSocket;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
|
||||
public class WebSocketChannel {
|
||||
private final WebSocket socket;
|
||||
private boolean isConnected = false;
|
||||
private Queue<ByteBuffer> bufferQueue;
|
||||
|
||||
public WebSocketChannel(String url) {
|
||||
socket = WebSocket.create(url);
|
||||
bufferQueue = new LinkedList<ByteBuffer>();
|
||||
|
||||
socket.onMessage(event -> {
|
||||
ArrayBuffer arrayBuffer = event.getData().cast();
|
||||
Int8Array int8Array = Int8Array.create(arrayBuffer);
|
||||
ByteBuffer byteBuffer = ByteBuffer.allocate(int8Array.getLength());
|
||||
for (int i = 0; i < int8Array.getLength(); i++) {
|
||||
byteBuffer.put(i, (byte) int8Array.get(i));
|
||||
}
|
||||
bufferQueue.offer(byteBuffer);
|
||||
});
|
||||
|
||||
socket.onOpen(event -> {
|
||||
isConnected = true;
|
||||
bufferQueue.clear();
|
||||
});
|
||||
|
||||
socket.onClose((event) -> {
|
||||
isConnected = false;
|
||||
bufferQueue.clear();
|
||||
});
|
||||
|
||||
socket.onError((event) -> {
|
||||
isConnected = false;
|
||||
socket.close();
|
||||
});
|
||||
}
|
||||
|
||||
public int read(ByteBuffer destination) {
|
||||
int totalBytesWritten = 0;
|
||||
|
||||
while (!bufferQueue.isEmpty()) {
|
||||
ByteBuffer sourceBuffer = bufferQueue.poll();
|
||||
int remaining = sourceBuffer.remaining();
|
||||
int spaceRemaining = destination.remaining();
|
||||
|
||||
if (spaceRemaining < remaining) {
|
||||
break;
|
||||
}
|
||||
|
||||
destination.put(sourceBuffer);
|
||||
totalBytesWritten += remaining;
|
||||
}
|
||||
|
||||
return totalBytesWritten;
|
||||
}
|
||||
|
||||
@JSBody(params = { "sock", "buffer" }, script = "sock.send(buffer);")
|
||||
private static native void nativeBinarySend(WebSocket sock, ArrayBuffer buffer);
|
||||
|
||||
public int write(ByteBuffer src) {
|
||||
int bytesWritten = src.remaining();
|
||||
|
||||
if (bytesWritten > 0) {
|
||||
byte[] newByteArray = new byte[bytesWritten];
|
||||
src.get(newByteArray);
|
||||
Int8Array array = Int8Array.create(newByteArray.length);
|
||||
for (int i = 0; i < newByteArray.length; i++) {
|
||||
array.set(i, newByteArray[i]);
|
||||
}
|
||||
nativeBinarySend(socket, array.getBuffer());
|
||||
}
|
||||
|
||||
return bytesWritten;
|
||||
}
|
||||
|
||||
public boolean connectionOpen() {
|
||||
return isConnected && socket.getReadyState() != 3;
|
||||
}
|
||||
|
||||
public void endConnection() {
|
||||
socket.close();
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
|
@ -1200,166 +1200,7 @@ public class EaglerAdapterImpl2 {
|
|||
|
||||
@JSBody(params = { "name", "cvs" }, script = "var a=document.createElement(\"a\");a.href=cvs.toDataURL(\"image/png\");a.download=name;a.click();")
|
||||
private static native void saveScreenshot(String name, HTMLCanvasElement cvs);
|
||||
|
||||
public static enum RateLimit {
|
||||
NONE, FAILED, BLOCKED, FAILED_POSSIBLY_LOCKED, LOCKED, NOW_LOCKED;
|
||||
}
|
||||
|
||||
private static final Set<String> rateLimitedAddresses = new HashSet<String>();
|
||||
private static final Set<String> blockedAddresses = new HashSet<String>();
|
||||
|
||||
private static WebSocket sock = null;
|
||||
private static boolean sockIsConnecting = false;
|
||||
private static boolean sockIsConnected = false;
|
||||
private static boolean sockIsAlive = false;
|
||||
private static LinkedList<byte[]> readPackets = new LinkedList<byte[]>();
|
||||
private static RateLimit rateLimitStatus = null;
|
||||
private static String currentSockURI = null;
|
||||
|
||||
public static final RateLimit getRateLimitStatus() {
|
||||
RateLimit l = rateLimitStatus;
|
||||
rateLimitStatus = null;
|
||||
return l;
|
||||
}
|
||||
public static final void logRateLimit(String addr, RateLimit l) {
|
||||
if(l == RateLimit.BLOCKED) {
|
||||
blockedAddresses.add(addr);
|
||||
}else {
|
||||
rateLimitedAddresses.add(addr);
|
||||
}
|
||||
}
|
||||
public static final RateLimit checkRateLimitHistory(String addr) {
|
||||
if(blockedAddresses.contains(addr)) {
|
||||
return RateLimit.LOCKED;
|
||||
}else if(rateLimitedAddresses.contains(addr)) {
|
||||
return RateLimit.BLOCKED;
|
||||
}else {
|
||||
return RateLimit.NONE;
|
||||
}
|
||||
}
|
||||
|
||||
@Async
|
||||
public static native String connectWebSocket(String sockURI);
|
||||
|
||||
private static void connectWebSocket(String sockURI, final AsyncCallback<String> cb) {
|
||||
sockIsConnecting = true;
|
||||
sockIsConnected = false;
|
||||
sockIsAlive = false;
|
||||
rateLimitStatus = null;
|
||||
currentSockURI = sockURI;
|
||||
try {
|
||||
sock = WebSocket.create(sockURI);
|
||||
} catch(Throwable t) {
|
||||
sockIsConnecting = false;
|
||||
sockIsAlive = false;
|
||||
return;
|
||||
}
|
||||
sock.setBinaryType("arraybuffer");
|
||||
sock.onOpen(new EventListener<MessageEvent>() {
|
||||
@Override
|
||||
public void handleEvent(MessageEvent evt) {
|
||||
sockIsConnecting = false;
|
||||
sockIsAlive = false;
|
||||
sockIsConnected = true;
|
||||
readPackets.clear();
|
||||
cb.complete("okay");
|
||||
}
|
||||
});
|
||||
sock.onClose(new EventListener<CloseEvent>() {
|
||||
@Override
|
||||
public void handleEvent(CloseEvent evt) {
|
||||
sock = null;
|
||||
if(sockIsConnecting) {
|
||||
if(rateLimitStatus == null) {
|
||||
if(blockedAddresses.contains(currentSockURI)) {
|
||||
rateLimitStatus = RateLimit.LOCKED;
|
||||
}else if(rateLimitedAddresses.contains(currentSockURI)) {
|
||||
rateLimitStatus = RateLimit.FAILED_POSSIBLY_LOCKED;
|
||||
}else {
|
||||
rateLimitStatus = RateLimit.FAILED;
|
||||
}
|
||||
}
|
||||
}else if(!sockIsAlive) {
|
||||
if(rateLimitStatus == null) {
|
||||
if(blockedAddresses.contains(currentSockURI)) {
|
||||
rateLimitStatus = RateLimit.LOCKED;
|
||||
}else if(rateLimitedAddresses.contains(currentSockURI)) {
|
||||
rateLimitStatus = RateLimit.BLOCKED;
|
||||
}
|
||||
}
|
||||
}
|
||||
boolean b = sockIsConnecting;
|
||||
sockIsConnecting = false;
|
||||
sockIsConnected = false;
|
||||
sockIsAlive = false;
|
||||
if(b) cb.complete("fail");
|
||||
}
|
||||
});
|
||||
sock.onMessage(new EventListener<MessageEvent>() {
|
||||
@Override
|
||||
public void handleEvent(MessageEvent evt) {
|
||||
sockIsAlive = true;
|
||||
if(isString(evt.getData())) {
|
||||
String stat = evt.getDataAsString();
|
||||
if(stat.equalsIgnoreCase("BLOCKED")) {
|
||||
if(rateLimitStatus == null) {
|
||||
rateLimitStatus = RateLimit.BLOCKED;
|
||||
}
|
||||
rateLimitedAddresses.add(currentSockURI);
|
||||
}else if(stat.equalsIgnoreCase("LOCKED")) {
|
||||
if(rateLimitStatus == null) {
|
||||
rateLimitStatus = RateLimit.NOW_LOCKED;
|
||||
}
|
||||
rateLimitedAddresses.add(currentSockURI);
|
||||
blockedAddresses.add(currentSockURI);
|
||||
}
|
||||
sockIsConnecting = false;
|
||||
sockIsConnected = false;
|
||||
sock.close();
|
||||
return;
|
||||
}
|
||||
Uint8Array a = Uint8Array.create(evt.getDataAsArray());
|
||||
byte[] b = new byte[a.getByteLength()];
|
||||
for(int i = 0; i < b.length; ++i) {
|
||||
b[i] = (byte) (a.get(i) & 0xFF);
|
||||
}
|
||||
readPackets.add(b);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static final boolean startConnection(String uri) {
|
||||
String res = connectWebSocket(uri);
|
||||
return "fail".equals(res) ? false : true;
|
||||
}
|
||||
public static final void endConnection() {
|
||||
if(sock == null || sock.getReadyState() == 3) {
|
||||
sockIsConnecting = false;
|
||||
}
|
||||
if(sock != null && !sockIsConnecting) sock.close();
|
||||
}
|
||||
public static final boolean connectionOpen() {
|
||||
if(sock == null || sock.getReadyState() == 3) {
|
||||
sockIsConnecting = false;
|
||||
}
|
||||
return sock != null && !sockIsConnecting && sock.getReadyState() != 3;
|
||||
}
|
||||
@JSBody(params = { "sock", "buffer" }, script = "sock.send(buffer);")
|
||||
private static native void nativeBinarySend(WebSocket sock, ArrayBuffer buffer);
|
||||
public static final void writePacket(byte[] packet) {
|
||||
if(sock != null && !sockIsConnecting) {
|
||||
Uint8Array arr = Uint8Array.create(packet.length);
|
||||
arr.set(packet);
|
||||
nativeBinarySend(sock, arr.getBuffer());
|
||||
}
|
||||
}
|
||||
public static final byte[] readPacket() {
|
||||
if(!readPackets.isEmpty()) {
|
||||
return readPackets.remove(0);
|
||||
}else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public static final byte[] loadLocalStorage(String key) {
|
||||
String s = win.getLocalStorage().getItem("_eaglercraft_beta."+key);
|
||||
if(s != null) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user