| 1 | package net.minecraft.pathfinding;
|
| 2 |
|
| 3 | import net.minecraft.util.MathHelper;
|
| 4 |
|
| 5 | public class PathPoint
|
| 6 | {
|
| 7 | /** The x coordinate of this point */
|
| 8 | public final int xCoord;
|
| 9 |
|
| 10 | /** The y coordinate of this point */
|
| 11 | public final int yCoord;
|
| 12 |
|
| 13 | /** The z coordinate of this point */
|
| 14 | public final int zCoord;
|
| 15 |
|
| 16 | /** A hash of the coordinates used to identify this point */
|
| 17 | private final int hash;
|
| 18 |
|
| 19 | /** The index of this point in its assigned path */
|
| 20 | int index = -1;
|
| 21 |
|
| 22 | /** The distance along the path to this point */
|
| 23 | float totalPathDistance;
|
| 24 |
|
| 25 | /** The linear distance to the next point */
|
| 26 | float distanceToNext;
|
| 27 |
|
| 28 | /** The distance to the target */
|
| 29 | float distanceToTarget;
|
| 30 |
|
| 31 | /** The point preceding this in its assigned path */
|
| 32 | PathPoint previous;
|
| 33 |
|
| 34 | /** True if the pathfinder has already visited this point */
|
| 35 | public boolean visited;
|
| 36 |
|
| 37 | public PathPoint(int x, int y, int z)
|
| 38 | {
|
| 39 | this.xCoord = x;
|
| 40 | this.yCoord = y;
|
| 41 | this.zCoord = z;
|
| 42 | this.hash = makeHash(x, y, z);
|
| 43 | }
|
| 44 |
|
| 45 | public static int makeHash(int x, int y, int z)
|
| 46 | {
|
| 47 | return y & 255 | (x & 32767) << 8 | (z & 32767) << 24 | (x < 0 ? Integer.MIN_VALUE : 0) | (z < 0 ? 32768 : 0);
|
| 48 | }
|
| 49 |
|
| 50 | /**
|
| 51 | * Returns the linear distance to another path point
|
| 52 | */
|
| 53 | public float distanceTo(PathPoint pathpointIn)
|
| 54 | {
|
| 55 | float f = (float)(pathpointIn.xCoord - this.xCoord);
|
| 56 | float f1 = (float)(pathpointIn.yCoord - this.yCoord);
|
| 57 | float f2 = (float)(pathpointIn.zCoord - this.zCoord);
|
| 58 | return MathHelper.sqrt_float(f * f + f1 * f1 + f2 * f2);
|
| 59 | }
|
| 60 |
|
| 61 | /**
|
| 62 | * Returns the squared distance to another path point
|
| 63 | */
|
| 64 | public float distanceToSquared(PathPoint pathpointIn)
|
| 65 | {
|
| 66 | float f = (float)(pathpointIn.xCoord - this.xCoord);
|
| 67 | float f1 = (float)(pathpointIn.yCoord - this.yCoord);
|
| 68 | float f2 = (float)(pathpointIn.zCoord - this.zCoord);
|
| 69 | return f * f + f1 * f1 + f2 * f2;
|
| 70 | }
|
| 71 |
|
| 72 | public boolean equals(Object p_equals_1_)
|
| 73 | {
|
| 74 | if (!(p_equals_1_ instanceof PathPoint))
|
| 75 | {
|
| 76 | return false;
|
| 77 | }
|
| 78 | else
|
| 79 | {
|
| 80 | PathPoint pathpoint = (PathPoint)p_equals_1_;
|
| 81 | return this.hash == pathpoint.hash && this.xCoord == pathpoint.xCoord && this.yCoord == pathpoint.yCoord && this.zCoord == pathpoint.zCoord;
|
| 82 | }
|
| 83 | }
|
| 84 |
|
| 85 | public int hashCode()
|
| 86 | {
|
| 87 | return this.hash;
|
| 88 | }
|
| 89 |
|
| 90 | /**
|
| 91 | * Returns true if this point has already been assigned to a path
|
| 92 | */
|
| 93 | public boolean isAssigned()
|
| 94 | {
|
| 95 | return this.index >= 0;
|
| 96 | }
|
| 97 |
|
| 98 | public String toString()
|
| 99 | {
|
| 100 | return this.xCoord + ", " + this.yCoord + ", " + this.zCoord;
|
| 101 | }
|
| 102 | }
|
| 103 |
|