303

countAdjancent blocks

303
May 10th, 2011
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1.     ///...
  2.     // aG = world, i,j,k = block
  3.     int count = this.countAdjacent(entity.aG, i, j, k);
  4.     ///...
  5.  
  6.     public int countAdjacent(et world, int i, int j, int k) {
  7.         bk cur = new bk(i, j, k);
  8.         Set<bk> total = new HashSet<bk>();
  9.         total.add(cur);
  10.         this.countAdjacent(world, cur, total);
  11.         return total.size();
  12.     }
  13.  
  14.     public void countAdjacent(et world, bk cur, Set<bk> total) {
  15.         for(int[] diff: adjdiffs) {
  16.             int nx = cur.a + diff[0];
  17.             int ny = cur.b;
  18.             int nz = cur.c + diff[1];
  19.  
  20.             if(world.a(nx, ny, nz) == this.bl) {
  21.                 bk next = new bk(nx, ny, nz);
  22.  
  23.                 if(total.add(next)) {
  24.                     this.countAdjacent(world, next, total);
  25.                 }
  26.             }
  27.         }
  28.     }
  29.  
  30.     public static int[][] adjdiffs = new int[][] {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
Advertisement
Add Comment
Please, Sign In to add comment