Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static Coord getTopLog(List<BlockID> logs, World world, Coord pos, boolean shouldLog)
- {
- LinkedList<Coord> topLogs = new LinkedList<Coord>();
- LinkedHashSet<Coord> processed = new LinkedHashSet<Coord>();
- Coord topLog = pos;
- topLogs.add(getTopLogAtPos(logs, world, pos));
- while (topLogs.size() > 0)
- {
- Coord nextLog = topLogs.pollFirst();
- processed.add(nextLog);
- // if the new pos is higher than what we've seen so far, save it as the new top log
- if (nextLog.y > topLog.y)
- topLog = nextLog;
- int currentSize = topLogs.size();
- for (int x = -1; x <= 1; x++)
- for (int z = -1; z <= 1; z++)
- if ((x != 0 || z != 0) && logs.contains(new BlockID(world, nextLog.x + x, nextLog.y + 1, nextLog.z + z)))
- {
- Coord newPos = new Coord(nextLog.x + x, nextLog.y + 1, nextLog.z + z);
- if (!topLogs.contains(newPos) && !processed.contains(newPos))
- topLogs.add(getTopLogAtPos(logs, world, newPos));
- }
- // check if we found anything
- if (topLogs.size() == currentSize)
- {
- for (int x = -1; x <= 1; x++)
- for (int z = -1; z <= 1; z++)
- if ((x != 0 || z != 0) && logs.contains(new BlockID(world, nextLog.x + x, nextLog.y, nextLog.z + z)))
- {
- Coord newPos = new Coord(nextLog.x + x, nextLog.y, nextLog.z + z);
- if (!topLogs.contains(newPos) && !processed.contains(newPos))
- topLogs.add(getTopLogAtPos(logs, world, newPos));
- }
- }
- }
- if (shouldLog)
- TCLog.debug("Top Log: " + pos.x + ", " + pos.y + ", " + pos.z);
- return topLog;
- }
- private static Coord getTopLogAtPos(List<BlockID> logs, World world, Coord pos)
- {
- while (logs.contains(new BlockID(world, pos.x, pos.y + 1, pos.z)))
- pos.y++;
- return pos;
- }
Advertisement
Add Comment
Please, Sign In to add comment