bspkrs

new top log logic

Oct 23rd, 2013
449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.30 KB | None | 0 0
  1.     private static Coord getTopLog(List<BlockID> logs, World world, Coord pos, boolean shouldLog)
  2.     {
  3.         LinkedList<Coord> topLogs = new LinkedList<Coord>();
  4.         LinkedHashSet<Coord> processed = new LinkedHashSet<Coord>();
  5.         Coord topLog = pos;
  6.        
  7.         topLogs.add(getTopLogAtPos(logs, world, pos));
  8.        
  9.         while (topLogs.size() > 0)
  10.         {
  11.             Coord nextLog = topLogs.pollFirst();
  12.             processed.add(nextLog);
  13.            
  14.             // if the new pos is higher than what we've seen so far, save it as the new top log
  15.             if (nextLog.y > topLog.y)
  16.                 topLog = nextLog;
  17.            
  18.             int currentSize = topLogs.size();
  19.            
  20.             for (int x = -1; x <= 1; x++)
  21.                 for (int z = -1; z <= 1; z++)
  22.                     if ((x != 0 || z != 0) && logs.contains(new BlockID(world, nextLog.x + x, nextLog.y + 1, nextLog.z + z)))
  23.                     {
  24.                         Coord newPos = new Coord(nextLog.x + x, nextLog.y + 1, nextLog.z + z);
  25.                         if (!topLogs.contains(newPos) && !processed.contains(newPos))
  26.                             topLogs.add(getTopLogAtPos(logs, world, newPos));
  27.                     }
  28.            
  29.             // check if we found anything
  30.             if (topLogs.size() == currentSize)
  31.             {
  32.                 for (int x = -1; x <= 1; x++)
  33.                     for (int z = -1; z <= 1; z++)
  34.                         if ((x != 0 || z != 0) && logs.contains(new BlockID(world, nextLog.x + x, nextLog.y, nextLog.z + z)))
  35.                         {
  36.                             Coord newPos = new Coord(nextLog.x + x, nextLog.y, nextLog.z + z);
  37.                             if (!topLogs.contains(newPos) && !processed.contains(newPos))
  38.                                 topLogs.add(getTopLogAtPos(logs, world, newPos));
  39.                         }
  40.                
  41.             }
  42.         }
  43.        
  44.         if (shouldLog)
  45.             TCLog.debug("Top Log: " + pos.x + ", " + pos.y + ", " + pos.z);
  46.        
  47.         return topLog;
  48.     }
  49.    
  50.     private static Coord getTopLogAtPos(List<BlockID> logs, World world, Coord pos)
  51.     {
  52.         while (logs.contains(new BlockID(world, pos.x, pos.y + 1, pos.z)))
  53.             pos.y++;
  54.        
  55.         return pos;
  56.     }
Advertisement
Add Comment
Please, Sign In to add comment