    001package net.minecraft.network.packet;
    002
    003import java.io.DataInputStream;
    004import java.io.DataOutputStream;
    005import java.io.IOException;
    006import net.minecraft.world.EnumGameType;
    007import net.minecraft.world.WorldType;
    008
    009public class Packet9Respawn extends Packet
    010{
    011    public int respawnDimension;
    012
    013    /**
    014     * The difficulty setting. 0 through 3 for peaceful, easy, normal, hard. The client always sends 1.
    015     */
    016    public int difficulty;
    017
    018    /** Defaults to 128 */
    019    public int worldHeight;
    020    public EnumGameType gameType;
    021    public WorldType terrainType;
    022
    023    public Packet9Respawn() {}
    024
    025    public Packet9Respawn(int par1, byte par2, WorldType par3WorldType, int par4, EnumGameType par5EnumGameType)
    026    {
    027        this.respawnDimension = par1;
    028        this.difficulty = par2;
    029        this.worldHeight = par4;
    030        this.gameType = par5EnumGameType;
    031        this.terrainType = par3WorldType;
    032    }
    033
    034    /**
    035     * Passes this Packet on to the NetHandler for processing.
    036     */
    037    public void processPacket(NetHandler par1NetHandler)
    038    {
    039        par1NetHandler.handleRespawn(this);
    040    }
    041
    042    /**
    043     * Abstract. Reads the raw packet data from the data stream.
    044     */
    045    public void readPacketData(DataInputStream par1DataInputStream) throws IOException
    046    {
    047        this.respawnDimension = par1DataInputStream.readInt();
    048        this.difficulty = par1DataInputStream.readByte();
    049        this.gameType = EnumGameType.getByID(par1DataInputStream.readByte());
    050        this.worldHeight = par1DataInputStream.readShort();
    051        String var2 = readString(par1DataInputStream, 16);
    052        this.terrainType = WorldType.parseWorldType(var2);
    053
    054        if (this.terrainType == null)
    055        {
    056            this.terrainType = WorldType.DEFAULT;
    057        }
    058    }
    059
    060    /**
    061     * Abstract. Writes the raw packet data to the data stream.
    062     */
    063    public void writePacketData(DataOutputStream par1DataOutputStream) throws IOException
    064    {
    065        par1DataOutputStream.writeInt(this.respawnDimension);
    066        par1DataOutputStream.writeByte(this.difficulty);
    067        par1DataOutputStream.writeByte(this.gameType.getID());
    068        par1DataOutputStream.writeShort(this.worldHeight);
    069        writeString(this.terrainType.getWorldTypeName(), par1DataOutputStream);
    070    }
    071
    072    /**
    073     * Abstract. Return the size of the packet (not counting the header).
    074     */
    075    public int getPacketSize()
    076    {
    077        return 8 + (this.terrainType == null ? 0 : this.terrainType.getWorldTypeName().length());
    078    }
    079}