    001package net.minecraft.pathfinding;
    002
    003import net.minecraft.entity.Entity;
    004import net.minecraft.util.Vec3;
    005
    006public class PathEntity
    007{
    008    /** The actual points in the path */
    009    private final PathPoint[] points;
    010
    011    /** PathEntity Array Index the Entity is currently targeting */
    012    private int currentPathIndex;
    013
    014    /** The total length of the path */
    015    private int pathLength;
    016
    017    public PathEntity(PathPoint[] par1ArrayOfPathPoint)
    018    {
    019        this.points = par1ArrayOfPathPoint;
    020        this.pathLength = par1ArrayOfPathPoint.length;
    021    }
    022
    023    /**
    024     * Directs this path to the next point in its array
    025     */
    026    public void incrementPathIndex()
    027    {
    028        ++this.currentPathIndex;
    029    }
    030
    031    /**
    032     * Returns true if this path has reached the end
    033     */
    034    public boolean isFinished()
    035    {
    036        return this.currentPathIndex >= this.pathLength;
    037    }
    038
    039    /**
    040     * returns the last PathPoint of the Array
    041     */
    042    public PathPoint getFinalPathPoint()
    043    {
    044        return this.pathLength > 0 ? this.points[this.pathLength - 1] : null;
    045    }
    046
    047    /**
    048     * return the PathPoint located at the specified PathIndex, usually the current one
    049     */
    050    public PathPoint getPathPointFromIndex(int par1)
    051    {
    052        return this.points[par1];
    053    }
    054
    055    public int getCurrentPathLength()
    056    {
    057        return this.pathLength;
    058    }
    059
    060    public void setCurrentPathLength(int par1)
    061    {
    062        this.pathLength = par1;
    063    }
    064
    065    public int getCurrentPathIndex()
    066    {
    067        return this.currentPathIndex;
    068    }
    069
    070    public void setCurrentPathIndex(int par1)
    071    {
    072        this.currentPathIndex = par1;
    073    }
    074
    075    /**
    076     * Gets the vector of the PathPoint associated with the given index.
    077     */
    078    public Vec3 getVectorFromIndex(Entity par1Entity, int par2)
    079    {
    080        double d0 = (double)this.points[par2].xCoord + (double)((int)(par1Entity.width + 1.0F)) * 0.5D;
    081        double d1 = (double)this.points[par2].yCoord;
    082        double d2 = (double)this.points[par2].zCoord + (double)((int)(par1Entity.width + 1.0F)) * 0.5D;
    083        return par1Entity.worldObj.getWorldVec3Pool().getVecFromPool(d0, d1, d2);
    084    }
    085
    086    /**
    087     * returns the current PathEntity target node as Vec3D
    088     */
    089    public Vec3 getPosition(Entity par1Entity)
    090    {
    091        return this.getVectorFromIndex(par1Entity, this.currentPathIndex);
    092    }
    093
    094    /**
    095     * Returns true if the EntityPath are the same. Non instance related equals.
    096     */
    097    public boolean isSamePath(PathEntity par1PathEntity)
    098    {
    099        if (par1PathEntity == null)
    100        {
    101            return false;
    102        }
    103        else if (par1PathEntity.points.length != this.points.length)
    104        {
    105            return false;
    106        }
    107        else
    108        {
    109            for (int i = 0; i < this.points.length; ++i)
    110            {
    111                if (this.points[i].xCoord != par1PathEntity.points[i].xCoord || this.points[i].yCoord != par1PathEntity.points[i].yCoord || this.points[i].zCoord != par1PathEntity.points[i].zCoord)
    112                {
    113                    return false;
    114                }
    115            }
    116
    117            return true;
    118        }
    119    }
    120
    121    /**
    122     * Returns true if the final PathPoint in the PathEntity is equal to Vec3D coords.
    123     */
    124    public boolean isDestinationSame(Vec3 par1Vec3)
    125    {
    126        PathPoint pathpoint = this.getFinalPathPoint();
    127        return pathpoint == null ? false : pathpoint.xCoord == (int)par1Vec3.xCoord && pathpoint.zCoord == (int)par1Vec3.zCoord;
    128    }
    129}