package common.entity.item;

import common.entity.Entity;
import common.entity.npc.EntityNPC;
import common.world.World;

public class EntityMinecart extends EntityCart
{
    public EntityMinecart(World worldIn)
    {
        super(worldIn);
    }

    public EntityMinecart(World worldIn, double x, double y, double z)
    {
        super(worldIn, x, y, z);
    }

    /**
     * First layer of player interaction
     */
    public boolean interactFirst(EntityNPC playerIn)
    {
//        if (this.passenger != null && this.passenger.isPlayer() && this.passenger != playerIn)
//        {
//            return true;
//        }
//        else
        if (this.passenger != null && this.passenger != playerIn)
        {
            return false;
        }
        else
        {
            if (!this.worldObj.client)
            {
                playerIn.mountEntity(this);
            }

            return true;
        }
    }

    /**
     * Called every tick the minecart is on an activator rail. Args: x, y, z, is the rail receiving power
     */
    public void onActivatorRailPass(int x, int y, int z, boolean receivingPower)
    {
        if (receivingPower)
        {
            if (this.passenger != null)
            {
                this.passenger.mountEntity((Entity)null);
            }

            if (this.getRollingAmplitude() == 0)
            {
                this.setRollingDirection(-this.getRollingDirection());
                this.setRollingAmplitude(10);
                this.setDamage(50);
                this.setBeenAttacked();
            }
        }
    }

    public EntityCart.EnumMinecartType getMinecartType()
    {
        return EntityCart.EnumMinecartType.RIDEABLE;
    }
}
