private ArrayList<AStarNode> findNeighbours(AStarNode node){
  ArrayList<AStarNode> r=new ArrayList<AStarNode>();
  int x=node.x;
  int y=node.y;
  int z=node.z;
  int dist=node.getG();
  if (node.parent != null) {
    int px=node.parent.x;
    int py=node.parent.y;
    int pz=node.parent.z;
    boolean stairs=py != y;
    int nY;
    int dx=(x - px) / Math.max(Math.abs(x - px),1);
    int dz=(z - pz) / Math.max(Math.abs(z - pz),1);
    if (dx != 0 && dz != 0) {
      if (stairs) {
        return getAllNeighborsWithoutParent(x,y,z,dx,dz,node);
      }
      int leftY=0;
      int rightY=0;
      nY=getGroundNodeHeight(x,y,z + dz);
      if (nY > 0) {
        leftY=nY;
        r.add(new AStarNode(x,nY,z + dz,dist + 1,node));
      }
      nY=getGroundNodeHeight(x + dx,y,z);
      if (nY > 0) {
        rightY=nY;
        r.add(new AStarNode(x + dx,nY,z,dist + 1,node));
      }
      if (leftY != 0 || rightY != 0) {
        r.add(new AStarNode(x + dx,Math.max(leftY,rightY),z + dz,dist + 2,node));
      }
      if (leftY != 0) {
        if (getGroundNodeHeight(x - dx,py,z) == 0) {
          r.add(new AStarNode(x - dx,leftY,z + dz,dist + 2,node));
        }
      }
      if (rightY != 0) {
        if (getGroundNodeHeight(x,py,z - dz) == 0) {
          r.add(new AStarNode(x + dx,rightY,z - dz,dist + 2,node));
        }
      }
    }
 else {
      if (dx == 0) {
        nY=getGroundNodeHeight(x,y,z + dz);
        if (nY > 0) {
          r.add(new AStarNode(x,nY,z + dz,dist + 1,node));
          if (stairs) {
            r.add(new AStarNode(x + 1,nY,z + dz,dist + 2,node));
            r.add(new AStarNode(x - 1,nY,z + dz,dist + 2,node));
          }
 else {
            int nnY=getGroundNodeHeight(x + 1,nY,z);
            if (nnY == 0) {
              r.add(new AStarNode(x + 1,nY,z + dz,dist + 2,node));
            }
            nnY=getGroundNodeHeight(x - 1,nY,z);
            if (nnY == 0) {
              r.add(new AStarNode(x - 1,nY,z + dz,dist + 2,node));
            }
          }
        }
      }
 else {
        nY=getGroundNodeHeight(x + dx,y,z);
        if (nY > 0) {
          r.add(new AStarNode(x + dx,nY,z,dist + 1,node));
          if (stairs) {
            r.add(new AStarNode(x + dx,nY,z + 1,dist + 2,node));
            r.add(new AStarNode(x + dx,nY,z - 1,dist + 2,node));
          }
 else {
            int nnY=getGroundNodeHeight(x,nY,z + 1);
            if (nnY == 0) {
              r.add(new AStarNode(x + dx,nY,z + 1,dist + 2,node));
            }
            nnY=getGroundNodeHeight(x,nY,z - 1);
            if (nnY == 0) {
              r.add(new AStarNode(x + dx,nY,z - 1,dist + 2,node));
            }
          }
        }
      }
    }
  }
 else {
    for (    int[] offset : neighbourOffsets) {
      int nY=getGroundNodeHeight(x + offset[0],y,z + offset[1]);
      if (nY > 0) {
        r.add(new AStarNode(x + offset[0],nY,z + offset[1],nY,node));
      }
    }
  }
  return r;
}

private ArrayList < AStarNode > findNeighbours ( AStarNode node ) { ArrayList < AStarNode > r = new ArrayList < AStarNode > ( ) ; int x = node . x ; int y = node . y ; int z = node . z ; int dist = node . getG ( ) ; if ( node . parent != null ) { int px = node . parent . x ; int py = node . parent . y ; int pz = node . parent . z ; boolean stairs = py != y ; int nY ; int dx = ( x - px ) / Math . max ( Math . abs ( x - px ) , 1 ) ; int dz = ( z - pz ) / Math . max ( Math . abs ( z - pz ) , 1 ) ; if ( dx != 0 && dz != 0 ) { if ( stairs ) { return getAllNeighborsWithoutParent ( x , y , z , dx , dz , node ) ; } int leftY = 0 ; int rightY = 0 ; nY = getGroundNodeHeight ( x , y , z + dz ) ; if ( nY > 0 ) { leftY = nY ; r . add ( new AStarNode ( x , nY , z + dz , dist + 1 , node ) ) ; } nY = getGroundNodeHeight ( x + dx , y , z ) ; if ( nY > 0 ) { rightY = nY ; r . add ( new AStarNode ( x + dx , nY , z , dist + 1 , node ) ) ; } if ( leftY != 0 || rightY != 0 ) { r . add ( new AStarNode ( x + dx , Math . max ( leftY , rightY ) , z + dz , dist + 2 , node ) ) ; } if ( leftY != 0 ) { if ( getGroundNodeHeight ( x - dx , py , z ) == 0 ) { r . add ( new AStarNode ( x - dx , leftY , z + dz , dist + 2 , node ) ) ; } } if ( rightY != 0 ) { if ( getGroundNodeHeight ( x , py , z - dz ) == 0 ) { r . add ( new AStarNode ( x + dx , rightY , z - dz , dist + 2 , node ) ) ; } } } else { if ( dx == 0 ) { nY = getGroundNodeHeight ( x , y , z + dz ) ; if ( nY > 0 ) { r . add ( new AStarNode ( x , nY , z + dz , dist + 1 , node ) ) ; if ( stairs ) { r . add ( new AStarNode ( x + 1 , nY , z + dz , dist + 2 , node ) ) ; r . add ( new AStarNode ( x - 1 , nY , z + dz , dist + 2 , node ) ) ; } else { int nnY = getGroundNodeHeight ( x + 1 , nY , z ) ; if ( nnY == 0 ) { r . add ( new AStarNode ( x + 1 , nY , z + dz , dist + 2 , node ) ) ; } nnY = getGroundNodeHeight ( x - 1 , nY , z ) ; if ( nnY == 0 ) { r . add ( new AStarNode ( x - 1 , nY , z + dz , dist + 2 , node ) ) ; } } } } else { nY = getGroundNodeHeight ( x + dx , y , z ) ; if ( nY > 0 ) { r . add ( new AStarNode ( x + dx , nY , z , dist + 1 , node ) ) ; if ( stairs ) { r . add ( new AStarNode ( x + dx , nY , z + 1 , dist + 2 , node ) ) ; r . add ( new AStarNode ( x + dx , nY , z - 1 , dist + 2 , node ) ) ; } else { int nnY = getGroundNodeHeight ( x , nY , z + 1 ) ; if ( nnY == 0 ) { r . add ( new AStarNode ( x + dx , nY , z + 1 , dist + 2 , node ) ) ; } nnY = getGroundNodeHeight ( x , nY , z - 1 ) ; if ( nnY == 0 ) { r . add ( new AStarNode ( x + dx , nY , z - 1 , dist + 2 , node ) ) ; } } } } } } else { for ( int [ ] offset : neighbourOffsets ) { int nY = getGroundNodeHeight ( x + offset [ 0 ] , y , z + offset [ 1 ] ) ; if ( nY > 0 ) { r . add ( new AStarNode ( x + offset [ 0 ] , nY , z + offset [ 1 ] , nY , node ) ) ; } } } return r ; }
returns all walkable astarnodes adjacent to an astarnode . if the node has a parent , use the jps algorithm to prune superfluous neighbors from ever being considered .
