    001    package net.minecraft.pathfinding;
    002
    003    import net.minecraft.entity.Entity;
    004    import net.minecraft.util.Vec3;
    005
    006    public 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 var3 = (double)this.points[par2].xCoord + (double)((int)(par1Entity.width + 1.0F)) * 0.5D;
    081            double var5 = (double)this.points[par2].yCoord;
    082            double var7 = (double)this.points[par2].zCoord + (double)((int)(par1Entity.width + 1.0F)) * 0.5D;
    083            return par1Entity.worldObj.getWorldVec3Pool().getVecFromPool(var3, var5, var7);
    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 var2 = 0; var2 < this.points.length; ++var2)
    110                {
    111                    if (this.points[var2].xCoord != par1PathEntity.points[var2].xCoord || this.points[var2].yCoord != par1PathEntity.points[var2].yCoord || this.points[var2].zCoord != par1PathEntity.points[var2].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 var2 = this.getFinalPathPoint();
    127            return var2 == null ? false : var2.xCoord == (int)par1Vec3.xCoord && var2.zCoord == (int)par1Vec3.zCoord;
    128        }
    129    }