    001    package net.minecraft.src;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005
    006    @SideOnly(Side.CLIENT)
    007    public class SoundUpdaterMinecart implements IUpdatePlayerListBox
    008    {
    009        private final SoundManager theSoundManager;
    010
    011        /** Minecart which sound is being updated. */
    012        private final EntityMinecart theMinecart;
    013
    014        /** The player that is getting the minecart sound updates. */
    015        private final EntityPlayerSP thePlayer;
    016        private boolean field_82473_d = false;
    017        private boolean field_82474_e = false;
    018        private boolean field_82471_f = false;
    019        private boolean field_82472_g = false;
    020        private float field_82480_h = 0.0F;
    021        private float field_82481_i = 0.0F;
    022        private float field_82478_j = 0.0F;
    023        private double field_82479_k = 0.0D;
    024
    025        public SoundUpdaterMinecart(SoundManager par1SoundManager, EntityMinecart par2EntityMinecart, EntityPlayerSP par3EntityPlayerSP)
    026        {
    027            this.theSoundManager = par1SoundManager;
    028            this.theMinecart = par2EntityMinecart;
    029            this.thePlayer = par3EntityPlayerSP;
    030        }
    031
    032        /**
    033         * Updates the JList with a new model.
    034         */
    035        public void update()
    036        {
    037            boolean var1 = false;
    038            boolean var2 = this.field_82473_d;
    039            boolean var3 = this.field_82474_e;
    040            boolean var4 = this.field_82471_f;
    041            float var5 = this.field_82481_i;
    042            float var6 = this.field_82480_h;
    043            float var7 = this.field_82478_j;
    044            double var8 = this.field_82479_k;
    045            this.field_82473_d = this.thePlayer != null && this.theMinecart.riddenByEntity == this.thePlayer;
    046            this.field_82474_e = this.theMinecart.isDead;
    047            this.field_82479_k = (double)MathHelper.sqrt_double(this.theMinecart.motionX * this.theMinecart.motionX + this.theMinecart.motionZ * this.theMinecart.motionZ);
    048            this.field_82471_f = this.field_82479_k >= 0.01D;
    049
    050            if (var2 && !this.field_82473_d)
    051            {
    052                this.theSoundManager.stopEntitySound(this.thePlayer);
    053            }
    054
    055            if (this.field_82474_e || !this.field_82472_g && this.field_82481_i == 0.0F && this.field_82478_j == 0.0F)
    056            {
    057                if (!var3)
    058                {
    059                    this.theSoundManager.stopEntitySound(this.theMinecart);
    060
    061                    if (var2 || this.field_82473_d)
    062                    {
    063                        this.theSoundManager.stopEntitySound(this.thePlayer);
    064                    }
    065                }
    066
    067                this.field_82472_g = true;
    068
    069                if (this.field_82474_e)
    070                {
    071                    return;
    072                }
    073            }
    074
    075            if (!this.theSoundManager.isEntitySoundPlaying(this.theMinecart) && this.field_82481_i > 0.0F)
    076            {
    077                this.theSoundManager.playEntitySound("minecart.base", this.theMinecart, this.field_82481_i, this.field_82480_h, false);
    078                this.field_82472_g = false;
    079                var1 = true;
    080            }
    081
    082            if (this.field_82473_d && !this.theSoundManager.isEntitySoundPlaying(this.thePlayer) && this.field_82478_j > 0.0F)
    083            {
    084                this.theSoundManager.playEntitySound("minecart.inside", this.thePlayer, this.field_82478_j, 1.0F, true);
    085                this.field_82472_g = false;
    086                var1 = true;
    087            }
    088
    089            if (this.field_82471_f)
    090            {
    091                if (this.field_82480_h < 1.0F)
    092                {
    093                    this.field_82480_h += 0.0025F;
    094                }
    095
    096                if (this.field_82480_h > 1.0F)
    097                {
    098                    this.field_82480_h = 1.0F;
    099                }
    100
    101                float var10 = MathHelper.clamp_float((float)this.field_82479_k, 0.0F, 4.0F) / 4.0F;
    102                this.field_82478_j = 0.0F + var10 * 0.75F;
    103                var10 = MathHelper.clamp_float(var10 * 2.0F, 0.0F, 1.0F);
    104                this.field_82481_i = 0.0F + var10 * 0.7F;
    105            }
    106            else if (var4)
    107            {
    108                this.field_82481_i = 0.0F;
    109                this.field_82480_h = 0.0F;
    110                this.field_82478_j = 0.0F;
    111            }
    112
    113            if (!this.field_82472_g)
    114            {
    115                if (this.field_82480_h != var6)
    116                {
    117                    this.theSoundManager.setEntitySoundPitch(this.theMinecart, this.field_82480_h);
    118                }
    119
    120                if (this.field_82481_i != var5)
    121                {
    122                    this.theSoundManager.setEntitySoundVolume(this.theMinecart, this.field_82481_i);
    123                }
    124
    125                if (this.field_82478_j != var7)
    126                {
    127                    this.theSoundManager.setEntitySoundVolume(this.thePlayer, this.field_82478_j);
    128                }
    129            }
    130
    131            if (!var1)
    132            {
    133                this.theSoundManager.updateSoundLocation(this.theMinecart);
    134
    135                if (this.field_82473_d)
    136                {
    137                    this.theSoundManager.updateSoundLocation(this.thePlayer, this.theMinecart);
    138                }
    139            }
    140        }
    141    }