    001    package net.minecraft.network.packet;
    002
    003    import cpw.mods.fml.relauncher.Side;
    004    import cpw.mods.fml.relauncher.SideOnly;
    005    import java.io.DataInputStream;
    006    import java.io.DataOutputStream;
    007    import java.io.IOException;
    008
    009    public class Packet62LevelSound extends Packet
    010    {
    011        /** e.g. step.grass */
    012        private String soundName;
    013
    014        /** Effect X multiplied by 8 */
    015        private int effectX;
    016
    017        /** Effect Y multiplied by 8 */
    018        private int effectY = Integer.MAX_VALUE;
    019
    020        /** Effect Z multiplied by 8 */
    021        private int effectZ;
    022
    023        /** 1 is 100%. Can be more. */
    024        private float volume;
    025
    026        /** 63 is 100%. Can be more. */
    027        private int pitch;
    028
    029        public Packet62LevelSound() {}
    030
    031        public Packet62LevelSound(String par1Str, double par2, double par4, double par6, float par8, float par9)
    032        {
    033            this.soundName = par1Str;
    034            this.effectX = (int)(par2 * 8.0D);
    035            this.effectY = (int)(par4 * 8.0D);
    036            this.effectZ = (int)(par6 * 8.0D);
    037            this.volume = par8;
    038            this.pitch = (int)(par9 * 63.0F);
    039
    040            if (this.pitch < 0)
    041            {
    042                this.pitch = 0;
    043            }
    044
    045            if (this.pitch > 255)
    046            {
    047                this.pitch = 255;
    048            }
    049        }
    050
    051        /**
    052         * Abstract. Reads the raw packet data from the data stream.
    053         */
    054        public void readPacketData(DataInputStream par1DataInputStream) throws IOException
    055        {
    056            this.soundName = readString(par1DataInputStream, 32);
    057            this.effectX = par1DataInputStream.readInt();
    058            this.effectY = par1DataInputStream.readInt();
    059            this.effectZ = par1DataInputStream.readInt();
    060            this.volume = par1DataInputStream.readFloat();
    061            this.pitch = par1DataInputStream.readUnsignedByte();
    062        }
    063
    064        /**
    065         * Abstract. Writes the raw packet data to the data stream.
    066         */
    067        public void writePacketData(DataOutputStream par1DataOutputStream) throws IOException
    068        {
    069            writeString(this.soundName, par1DataOutputStream);
    070            par1DataOutputStream.writeInt(this.effectX);
    071            par1DataOutputStream.writeInt(this.effectY);
    072            par1DataOutputStream.writeInt(this.effectZ);
    073            par1DataOutputStream.writeFloat(this.volume);
    074            par1DataOutputStream.writeByte(this.pitch);
    075        }
    076
    077        /**
    078         * Passes this Packet on to the NetHandler for processing.
    079         */
    080        public void processPacket(NetHandler par1NetHandler)
    081        {
    082            par1NetHandler.handleLevelSound(this);
    083        }
    084
    085        /**
    086         * Abstract. Return the size of the packet (not counting the header).
    087         */
    088        public int getPacketSize()
    089        {
    090            return 24;
    091        }
    092
    093        @SideOnly(Side.CLIENT)
    094        public String getSoundName()
    095        {
    096            return this.soundName;
    097        }
    098
    099        @SideOnly(Side.CLIENT)
    100        public double getEffectX()
    101        {
    102            return (double)((float)this.effectX / 8.0F);
    103        }
    104
    105        @SideOnly(Side.CLIENT)
    106        public double getEffectY()
    107        {
    108            return (double)((float)this.effectY / 8.0F);
    109        }
    110
    111        @SideOnly(Side.CLIENT)
    112        public double getEffectZ()
    113        {
    114            return (double)((float)this.effectZ / 8.0F);
    115        }
    116
    117        @SideOnly(Side.CLIENT)
    118        public float getVolume()
    119        {
    120            return this.volume;
    121        }
    122
    123        @SideOnly(Side.CLIENT)
    124
    125        /**
    126         * Gets the pitch divided by 63 (63 is 100%)
    127         */
    128        public float getPitch()
    129        {
    130            return (float)this.pitch / 63.0F;
    131        }
    132    }