Multiplayer (Will rewrite with WebSockets later)

This commit is contained in:
PeytonPlayz595 2023-12-18 15:34:54 -05:00
parent 57638cdcd2
commit 8d441465b1
14 changed files with 990 additions and 23 deletions

View File

@ -6,6 +6,7 @@ import com.mojang.minecraft.level.liquid.LiquidType;
import com.mojang.minecraft.level.tile.Block; import com.mojang.minecraft.level.tile.Block;
import com.mojang.minecraft.level.tile.Tile$SoundType; import com.mojang.minecraft.level.tile.Tile$SoundType;
import com.mojang.minecraft.model.Vec3D; import com.mojang.minecraft.model.Vec3D;
import com.mojang.minecraft.net.PositionUpdate;
import com.mojang.minecraft.phys.AABB; import com.mojang.minecraft.phys.AABB;
import net.PeytonPlayz585.math.MathHelper; import net.PeytonPlayz585.math.MathHelper;
import net.PeytonPlayz595.nbt.NBTTagCompound; import net.PeytonPlayz595.nbt.NBTTagCompound;
@ -89,6 +90,20 @@ public abstract class Entity implements Serializable {
this.bbHeight = var2; 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) { protected void setRot(float var1, float var2) {
this.yRot = var1; this.yRot = var1;
this.xRot = var2; this.xRot = var2;

View File

@ -16,6 +16,9 @@ import com.mojang.minecraft.model.HumanoidModel;
import com.mojang.minecraft.model.ModelManager; import com.mojang.minecraft.model.ModelManager;
import com.mojang.minecraft.model.ModelPart; import com.mojang.minecraft.model.ModelPart;
import com.mojang.minecraft.model.Vec3D; 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.Particle;
import com.mojang.minecraft.particle.ParticleManager; import com.mojang.minecraft.particle.ParticleManager;
import com.mojang.minecraft.particle.WaterDropParticle; import com.mojang.minecraft.particle.WaterDropParticle;
@ -24,6 +27,7 @@ import com.mojang.minecraft.player.InputHandlerImpl;
import com.mojang.minecraft.player.Player; import com.mojang.minecraft.player.Player;
import com.mojang.minecraft.render.*; import com.mojang.minecraft.render.*;
import com.mojang.minecraft.render.Renderer; import com.mojang.minecraft.render.Renderer;
import com.mojang.net.NetworkHandler;
import net.PeytonPlayz585.level.LevelUtils; import net.PeytonPlayz585.level.LevelUtils;
import net.PeytonPlayz585.math.MathHelper; import net.PeytonPlayz585.math.MathHelper;
@ -33,16 +37,10 @@ import net.lax1dude.eaglercraft.adapter.Tessellator;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import java.awt.*;
import java.io.*; import java.io.*;
import java.nio.IntBuffer; import java.nio.IntBuffer;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Map.Entry;
public final class Minecraft implements Runnable { public final class Minecraft implements Runnable {
@ -69,10 +67,11 @@ public final class Minecraft implements Runnable {
public int levelId; public int levelId;
public HUDScreen hud; public HUDScreen hud;
public boolean online; public boolean online;
public NetworkManager networkManager;
public MovingObjectPosition selected; public MovingObjectPosition selected;
public static GameSettings settings; public static GameSettings settings;
String server; public String server;
int port; public int port;
volatile boolean running; volatile boolean running;
public String debug; public String debug;
public boolean hasMouse; public boolean hasMouse;
@ -171,15 +170,24 @@ public final class Minecraft implements Runnable {
Item.initModels(); Item.initModels();
Mob.modelCache = new ModelManager(); Mob.modelCache = new ModelManager();
GL11.glViewport(0, 0, this.width, this.height); GL11.glViewport(0, 0, this.width, this.height);
Level level1 = new LevelUtils().load(); if(this.server != null) {
if(level1 == null) { Level var85;
this.generateLevel(1); (var85 = new Level()).setData(8, 8, 8, new byte[512]);
this.setLevel(var85, false);
} else { } else {
this.setLevel(level1, true); Level level1 = new LevelUtils().load();
if(level1 == null) {
this.generateLevel(1);
} else {
this.setLevel(level1, true);
}
} }
this.particleManager = new ParticleManager(this.level); this.particleManager = new ParticleManager(this.level);
checkGLError("Post startup"); checkGLError("Post startup");
this.hud = new HUDScreen(this, this.width, this.height); this.hud = new HUDScreen(this, this.width, this.height);
if(this.server != null) {
this.networkManager = new NetworkManager(this, this.server, this.port, this.session.username, this.session.mppass);
}
long var13 = System.currentTimeMillis(); long var13 = System.currentTimeMillis();
int var15 = 0; int var15 = 0;
@ -996,6 +1004,10 @@ public final class Minecraft implements Runnable {
return; return;
} }
if(this.isOnline()) {
this.networkManager.sendBlockChange(var3, var4, var5, var1, var10);
}
this.level.netSetTile(var3, var4, var5, var10); this.level.netSetTile(var3, var4, var5, var10);
var2 = this.renderer.heldBlock; var2 = this.renderer.heldBlock;
this.renderer.heldBlock.pos = 0.0F; this.renderer.heldBlock.pos = 0.0F;
@ -1050,6 +1062,244 @@ public final class Minecraft implements Runnable {
int var40; int var40;
int var46; int var46;
int var45; 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(var20.netHandler.connected) {
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 = LevelIO.decompress(new ByteArrayInputStream(var42.levelData.toByteArray()));
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.connected) {
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) { if(this.currentScreen == null && this.player != null && this.player.health <= 0) {
this.setCurrentScreen((GuiScreen)null); this.setCurrentScreen((GuiScreen)null);
@ -1139,6 +1389,11 @@ public final class Minecraft implements Runnable {
if(GL11.getEventKey() == this.settings.buildKey.key) { if(GL11.getEventKey() == this.settings.buildKey.key) {
this.gamemode.openInventory(); 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) { for(var25 = 0; var25 < 9; ++var25) {
@ -1248,7 +1503,9 @@ public final class Minecraft implements Runnable {
LevelRenderer var31 = this.levelRenderer; LevelRenderer var31 = this.levelRenderer;
++this.levelRenderer.ticks; ++this.levelRenderer.ticks;
this.level.tickEntities(); this.level.tickEntities();
this.level.tick(); if(!this.isOnline()) {
this.level.tick();
}
this.particleManager.tick(); this.particleManager.tick();
} }
@ -1269,6 +1526,10 @@ public final class Minecraft implements Runnable {
} }
} }
public final boolean isOnline() {
return this.networkManager != null;
}
public final void generateLevel(int var1) { public final void generateLevel(int var1) {
String var2 = "PeytonPlayz585"; String var2 = "PeytonPlayz585";
Level var4 = (new LevelGenerator(this.progressBar)).generate(var2, 128 << var1, 128 << var1, 64); Level var4 = (new LevelGenerator(this.progressBar)).generate(var2, 128 << var1, 128 << var1, 64);
@ -1285,7 +1546,16 @@ public final class Minecraft implements Runnable {
this.gamemode.apply(var1); this.gamemode.apply(var1);
var1.font = this.fontRenderer; var1.font = this.fontRenderer;
var1.rendererContext$5cd64a7f = this; 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) { if(this.player == null) {

View File

@ -50,13 +50,19 @@ public class GameMode
boolean success = level.netSetTile(x, y, z, 0); 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(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); block.spawnBreakParticles(level, x, y, z, minecraft.particleManager);
} }

View File

@ -1,8 +1,11 @@
package com.mojang.minecraft.gui; package com.mojang.minecraft.gui;
import com.mojang.minecraft.gui.GuiScreen;
import org.lwjgl.opengl.GL11; 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 { public final class ChatInputScreen extends GuiScreen {
private String message = ""; private String message = "";
@ -25,6 +28,13 @@ public final class ChatInputScreen extends GuiScreen {
if(var2 == 1) { if(var2 == 1) {
this.minecraft.setCurrentScreen((GuiScreen)null); this.minecraft.setCurrentScreen((GuiScreen)null);
} else if(var2 == 28) { } 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); this.minecraft.setCurrentScreen((GuiScreen)null);
} else { } else {
if(var2 == 14 && this.message.length() > 0) { if(var2 == 14 && this.message.length() > 0) {

View File

@ -118,7 +118,6 @@ public class FontRenderer {
k = (k & 0xfcfcfc) >> 2; k = (k & 0xfcfcfc) >> 2;
k += l; k += l;
} }
//GL11.glBindTexture(3553 /* GL_TEXTURE_2D */, fontTextureName);
new TextureLocation(fontTextureName).bindTexture(); new TextureLocation(fontTextureName).bindTexture();
float f = (float) (k >> 16 & 0xff) / 255F; float f = (float) (k >> 16 & 0xff) / 255F;
float f1 = (float) (k >> 8 & 0xff) / 255F; float f1 = (float) (k >> 8 & 0xff) / 255F;
@ -137,8 +136,6 @@ public class FontRenderer {
j1 = 15; j1 = 15;
} }
continue; 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()) { if (i1 < s.length()) {
@ -172,6 +169,21 @@ public class FontRenderer {
return i; 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[]; private int charWidth[];
public String fontTextureName; public String fontTextureName;
private int fontDisplayLists; private int fontDisplayLists;

View File

@ -12,6 +12,7 @@ import net.lax1dude.eaglercraft.adapter.Tessellator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
public final class HUDScreen extends Screen { public final class HUDScreen extends Screen {
@ -176,6 +177,36 @@ public final class HUDScreen extends Screen {
var14 = this.width / 2; var14 = this.width / 2;
var15 = this.height / 2; var15 = this.height / 2;
this.hoveredPlayer = null; 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) { public final void addChat(String var1) {

View File

@ -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")); 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(2)).active = false;
((Button)this.buttons.get(3)).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(); new LevelUtils().save();
} }

View File

@ -0,0 +1,74 @@
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;
public class NetworkManager
{
public NetworkManager(Minecraft minecraft, String server, int port, String username, String key)
{
minecraft.online = true;
this.minecraft = minecraft;
players = new HashMap<Byte, NetworkPlayer>();
new ServerConnectThread(this, server, port, username, key, minecraft).start();
}
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.connected;
}
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;
}
}

View 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));
}
}

View 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;
}
}

View 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;
}

View File

@ -0,0 +1,53 @@
package com.mojang.minecraft.net;
import com.mojang.minecraft.Minecraft;
import com.mojang.minecraft.gui.ErrorScreen;
import com.mojang.net.NetworkHandler;
public class ServerConnectThread extends Thread
{
public ServerConnectThread(NetworkManager networkManager, String server, int port, String username, String key, Minecraft minecraft) {
super();
netManager = networkManager;
this.server = server;
this.port = port;
this.username = username;
this.key = key;
this.minecraft = minecraft;
}
@Override
public void run()
{
try {
netManager.netHandler = new NetworkHandler(server, port);
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 int port;
private String username;
private String key;
private Minecraft minecraft;
private NetworkManager netManager;
}

View File

@ -0,0 +1,169 @@
package com.mojang.net;
import com.mojang.minecraft.Minecraft;
import com.mojang.minecraft.gamemode.CreativeGameMode;
import com.mojang.minecraft.net.NetworkManager;
import com.mojang.minecraft.net.PacketType;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketException;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.util.Arrays;
public final class NetworkHandler {
public volatile boolean connected;
public SocketChannel channel;
public ByteBuffer in = ByteBuffer.allocate(1048576);
public ByteBuffer out = ByteBuffer.allocate(1048576);
public NetworkManager netManager;
private Socket sock;
private boolean unused = false;
private byte[] stringBytes = new byte[64];
public NetworkHandler(String var1, int var2) {
Minecraft.getMinecraft().gamemode = new CreativeGameMode(Minecraft.getMinecraft());
try
{
channel = SocketChannel.open();
this.channel.connect(new InetSocketAddress(var1, var2));
this.channel.configureBlocking(false);
System.currentTimeMillis();
this.sock = this.channel.socket();
this.connected = true;
this.in.clear();
this.out.clear();
this.sock.setTcpNoDelay(true);
this.sock.setTrafficClass(24);
this.sock.setKeepAlive(false);
this.sock.setReuseAddress(false);
this.sock.setSoTimeout(100);
this.sock.getInetAddress().toString();
} catch (SocketException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public final void close() {
try {
if(this.out.position() > 0) {
this.out.flip();
this.channel.write(this.out);
this.out.compact();
}
} catch (Exception var2) {
;
}
this.connected = false;
try {
this.channel.close();
} catch (Exception var1) {
;
}
this.sock = null;
this.channel = null;
}
public final void send(PacketType var1, Object ... var2) {
if(this.connected) {
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(this.connected) {
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(!this.connected) {
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;
}
}
}
}

View File

@ -108,6 +108,11 @@ public class LevelUtils {
} }
public void save() { public void save() {
if(Minecraft.getMinecraft().networkManager != null) {
return;
}
Level var1 = Minecraft.getMinecraft().level; Level var1 = Minecraft.getMinecraft().level;
NBTTagCompound var3 = new NBTTagCompound(); NBTTagCompound var3 = new NBTTagCompound();