001package net.minecraft.network.packet;
002
003import cpw.mods.fml.relauncher.Side;
004import cpw.mods.fml.relauncher.SideOnly;
005import java.io.DataInputStream;
006import java.io.DataOutputStream;
007import java.io.IOException;
008import net.minecraft.entity.player.PlayerCapabilities;
009
010public class Packet202PlayerAbilities extends Packet
011{
012    /** Disables player damage. */
013    private boolean disableDamage = false;
014
015    /** Indicates whether the player is flying or not. */
016    private boolean isFlying = false;
017
018    /** Whether or not to allow the player to fly when they double jump. */
019    private boolean allowFlying = false;
020
021    /**
022     * Used to determine if creative mode is enabled, and therefore if items should be depleted on usage
023     */
024    private boolean isCreativeMode = false;
025    private float flySpeed;
026    private float walkSpeed;
027
028    public Packet202PlayerAbilities() {}
029
030    public Packet202PlayerAbilities(PlayerCapabilities par1PlayerCapabilities)
031    {
032        this.setDisableDamage(par1PlayerCapabilities.disableDamage);
033        this.setFlying(par1PlayerCapabilities.isFlying);
034        this.setAllowFlying(par1PlayerCapabilities.allowFlying);
035        this.setCreativeMode(par1PlayerCapabilities.isCreativeMode);
036        this.setFlySpeed(par1PlayerCapabilities.getFlySpeed());
037        this.setWalkSpeed(par1PlayerCapabilities.getWalkSpeed());
038    }
039
040    /**
041     * Abstract. Reads the raw packet data from the data stream.
042     */
043    public void readPacketData(DataInputStream par1DataInputStream) throws IOException
044    {
045        byte b0 = par1DataInputStream.readByte();
046        this.setDisableDamage((b0 & 1) > 0);
047        this.setFlying((b0 & 2) > 0);
048        this.setAllowFlying((b0 & 4) > 0);
049        this.setCreativeMode((b0 & 8) > 0);
050        this.setFlySpeed((float)par1DataInputStream.readByte() / 255.0F);
051        this.setWalkSpeed((float)par1DataInputStream.readByte() / 255.0F);
052    }
053
054    /**
055     * Abstract. Writes the raw packet data to the data stream.
056     */
057    public void writePacketData(DataOutputStream par1DataOutputStream) throws IOException
058    {
059        byte b0 = 0;
060
061        if (this.getDisableDamage())
062        {
063            b0 = (byte)(b0 | 1);
064        }
065
066        if (this.getFlying())
067        {
068            b0 = (byte)(b0 | 2);
069        }
070
071        if (this.getAllowFlying())
072        {
073            b0 = (byte)(b0 | 4);
074        }
075
076        if (this.isCreativeMode())
077        {
078            b0 = (byte)(b0 | 8);
079        }
080
081        par1DataOutputStream.writeByte(b0);
082        par1DataOutputStream.writeByte((int)(this.flySpeed * 255.0F));
083        par1DataOutputStream.writeByte((int)(this.walkSpeed * 255.0F));
084    }
085
086    /**
087     * Passes this Packet on to the NetHandler for processing.
088     */
089    public void processPacket(NetHandler par1NetHandler)
090    {
091        par1NetHandler.handlePlayerAbilities(this);
092    }
093
094    /**
095     * Abstract. Return the size of the packet (not counting the header).
096     */
097    public int getPacketSize()
098    {
099        return 2;
100    }
101
102    public boolean getDisableDamage()
103    {
104        return this.disableDamage;
105    }
106
107    /**
108     * Sets whether damage is disabled or not.
109     */
110    public void setDisableDamage(boolean par1)
111    {
112        this.disableDamage = par1;
113    }
114
115    public boolean getFlying()
116    {
117        return this.isFlying;
118    }
119
120    /**
121     * Sets whether we're currently flying or not.
122     */
123    public void setFlying(boolean par1)
124    {
125        this.isFlying = par1;
126    }
127
128    public boolean getAllowFlying()
129    {
130        return this.allowFlying;
131    }
132
133    public void setAllowFlying(boolean par1)
134    {
135        this.allowFlying = par1;
136    }
137
138    public boolean isCreativeMode()
139    {
140        return this.isCreativeMode;
141    }
142
143    public void setCreativeMode(boolean par1)
144    {
145        this.isCreativeMode = par1;
146    }
147
148    @SideOnly(Side.CLIENT)
149    public float getFlySpeed()
150    {
151        return this.flySpeed;
152    }
153
154    /**
155     * Sets the flying speed.
156     */
157    public void setFlySpeed(float par1)
158    {
159        this.flySpeed = par1;
160    }
161
162    @SideOnly(Side.CLIENT)
163    public float getWalkSpeed()
164    {
165        return this.walkSpeed;
166    }
167
168    /**
169     * Sets the walking speed.
170     */
171    public void setWalkSpeed(float par1)
172    {
173        this.walkSpeed = par1;
174    }
175
176    /**
177     * only false for the abstract Packet class, all real packets return true
178     */
179    public boolean isRealPacket()
180    {
181        return true;
182    }
183
184    /**
185     * eg return packet30entity.entityId == entityId; WARNING : will throw if you compare a packet to a different packet
186     * class
187     */
188    public boolean containsSameEntityIDAs(Packet par1Packet)
189    {
190        return true;
191    }
192}