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