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