package common.sound;

import common.entity.item.EntityCart;
import common.entity.npc.EntityNPC;
import common.init.SoundEvent;
import common.util.ExtMath;

public class MovingSoundMinecartRiding extends MovingSound
{
    private final EntityNPC player;
    private final EntityCart minecart;

    public MovingSoundMinecartRiding(EntityNPC playerRiding, EntityCart minecart)
    {
        super(SoundEvent.CART_INSIDE);
        this.player = playerRiding;
        this.minecart = minecart;
        this.attenuationType = false;
        this.repeat = true;
    }

    /**
     * Like the old updateEntity(), except more generic.
     */
    public void update()
    {
        if (!this.minecart.dead && this.player.isRiding() && this.player.vehicle == this.minecart)
        {
            float f = ExtMath.sqrtd(this.minecart.motionX * this.minecart.motionX + this.minecart.motionZ * this.minecart.motionZ);

            if ((double)f >= 0.01D)
            {
                this.volume = 0.0F + ExtMath.clampf(f, 0.0F, 1.0F) * 0.75F;
            }
            else
            {
                this.volume = 0.0F;
            }
        }
        else
        {
            this.donePlaying = true;
        }
    }
}
