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