001 package net.minecraft.pathfinding; 002 003 import net.minecraft.util.MathHelper; 004 005 public class PathPoint 006 { 007 /** The x coordinate of this point */ 008 public final int xCoord; 009 010 /** The y coordinate of this point */ 011 public final int yCoord; 012 013 /** The z coordinate of this point */ 014 public final int zCoord; 015 016 /** A hash of the coordinates used to identify this point */ 017 private final int hash; 018 019 /** The index of this point in its assigned path */ 020 int index = -1; 021 022 /** The distance along the path to this point */ 023 float totalPathDistance; 024 025 /** The linear distance to the next point */ 026 float distanceToNext; 027 028 /** The distance to the target */ 029 float distanceToTarget; 030 031 /** The point preceding this in its assigned path */ 032 PathPoint previous; 033 034 /** Indicates this is the origin */ 035 public boolean isFirst = false; 036 037 public PathPoint(int par1, int par2, int par3) 038 { 039 this.xCoord = par1; 040 this.yCoord = par2; 041 this.zCoord = par3; 042 this.hash = makeHash(par1, par2, par3); 043 } 044 045 public static int makeHash(int par0, int par1, int par2) 046 { 047 return par1 & 255 | (par0 & 32767) << 8 | (par2 & 32767) << 24 | (par0 < 0 ? Integer.MIN_VALUE : 0) | (par2 < 0 ? 32768 : 0); 048 } 049 050 /** 051 * Returns the linear distance to another path point 052 */ 053 public float distanceTo(PathPoint par1PathPoint) 054 { 055 float var2 = (float)(par1PathPoint.xCoord - this.xCoord); 056 float var3 = (float)(par1PathPoint.yCoord - this.yCoord); 057 float var4 = (float)(par1PathPoint.zCoord - this.zCoord); 058 return MathHelper.sqrt_float(var2 * var2 + var3 * var3 + var4 * var4); 059 } 060 061 public float func_75832_b(PathPoint par1PathPoint) 062 { 063 float var2 = (float)(par1PathPoint.xCoord - this.xCoord); 064 float var3 = (float)(par1PathPoint.yCoord - this.yCoord); 065 float var4 = (float)(par1PathPoint.zCoord - this.zCoord); 066 return var2 * var2 + var3 * var3 + var4 * var4; 067 } 068 069 public boolean equals(Object par1Obj) 070 { 071 if (!(par1Obj instanceof PathPoint)) 072 { 073 return false; 074 } 075 else 076 { 077 PathPoint var2 = (PathPoint)par1Obj; 078 return this.hash == var2.hash && this.xCoord == var2.xCoord && this.yCoord == var2.yCoord && this.zCoord == var2.zCoord; 079 } 080 } 081 082 public int hashCode() 083 { 084 return this.hash; 085 } 086 087 /** 088 * Returns true if this point has already been assigned to a path 089 */ 090 public boolean isAssigned() 091 { 092 return this.index >= 0; 093 } 094 095 public String toString() 096 { 097 return this.xCoord + ", " + this.yCoord + ", " + this.zCoord; 098 } 099 }