001 package net.minecraft.network.packet; 002 003 import java.io.DataInputStream; 004 import java.io.DataOutputStream; 005 import java.io.IOException; 006 007 import cpw.mods.fml.common.network.FMLNetworkHandler; 008 import net.minecraft.world.EnumGameType; 009 import net.minecraft.world.WorldType; 010 011 public class Packet1Login extends Packet 012 { 013 /** The player's entity ID */ 014 public int clientEntityId = 0; 015 public WorldType terrainType; 016 public boolean hardcoreMode; 017 public EnumGameType gameType; 018 019 /** -1: The Nether, 0: The Overworld, 1: The End */ 020 public int dimension; 021 022 /** The difficulty setting byte. */ 023 public byte difficultySetting; 024 025 /** Defaults to 128 */ 026 public byte worldHeight; 027 028 /** The maximum players. */ 029 public byte maxPlayers; 030 031 private boolean vanillaCompatible; 032 033 public Packet1Login() 034 { 035 this.vanillaCompatible = FMLNetworkHandler.vanillaLoginPacketCompatibility(); 036 } 037 038 public Packet1Login(int par1, WorldType par2WorldType, EnumGameType par3EnumGameType, boolean par4, int par5, int par6, int par7, int par8) 039 { 040 this.clientEntityId = par1; 041 this.terrainType = par2WorldType; 042 this.dimension = par5; 043 this.difficultySetting = (byte)par6; 044 this.gameType = par3EnumGameType; 045 this.worldHeight = (byte)par7; 046 this.maxPlayers = (byte)par8; 047 this.hardcoreMode = par4; 048 this.vanillaCompatible = false; 049 } 050 051 /** 052 * Abstract. Reads the raw packet data from the data stream. 053 */ 054 public void readPacketData(DataInputStream par1DataInputStream) throws IOException 055 { 056 this.clientEntityId = par1DataInputStream.readInt(); 057 String var2 = readString(par1DataInputStream, 16); 058 this.terrainType = WorldType.parseWorldType(var2); 059 060 if (this.terrainType == null) 061 { 062 this.terrainType = WorldType.DEFAULT; 063 } 064 065 byte var3 = par1DataInputStream.readByte(); 066 this.hardcoreMode = (var3 & 8) == 8; 067 int var4 = var3 & -9; 068 this.gameType = EnumGameType.getByID(var4); 069 070 if (vanillaCompatible) 071 { 072 this.dimension = par1DataInputStream.readByte(); 073 } 074 else 075 { 076 this.dimension = par1DataInputStream.readInt(); 077 } 078 079 this.difficultySetting = par1DataInputStream.readByte(); 080 this.worldHeight = par1DataInputStream.readByte(); 081 this.maxPlayers = par1DataInputStream.readByte(); 082 } 083 084 /** 085 * Abstract. Writes the raw packet data to the data stream. 086 */ 087 public void writePacketData(DataOutputStream par1DataOutputStream) throws IOException 088 { 089 par1DataOutputStream.writeInt(this.clientEntityId); 090 writeString(this.terrainType == null ? "" : this.terrainType.getWorldTypeName(), par1DataOutputStream); 091 int var2 = this.gameType.getID(); 092 093 if (this.hardcoreMode) 094 { 095 var2 |= 8; 096 } 097 098 par1DataOutputStream.writeByte(var2); 099 100 if (vanillaCompatible) 101 { 102 par1DataOutputStream.writeByte(this.dimension); 103 } 104 else 105 { 106 par1DataOutputStream.writeInt(this.dimension); 107 } 108 109 par1DataOutputStream.writeByte(this.difficultySetting); 110 par1DataOutputStream.writeByte(this.worldHeight); 111 par1DataOutputStream.writeByte(this.maxPlayers); 112 } 113 114 /** 115 * Passes this Packet on to the NetHandler for processing. 116 */ 117 public void processPacket(NetHandler par1NetHandler) 118 { 119 par1NetHandler.handleLogin(this); 120 } 121 122 /** 123 * Abstract. Return the size of the packet (not counting the header). 124 */ 125 public int getPacketSize() 126 { 127 int var1 = 0; 128 129 if (this.terrainType != null) 130 { 131 var1 = this.terrainType.getWorldTypeName().length(); 132 } 133 134 return 6 + 2 * var1 + 4 + 4 + 1 + 1 + 1 + (vanillaCompatible ? 0 : 3); 135 } 136 }