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