Skip to content

Instantly share code, notes, and snippets.

@MakerTim
Created March 12, 2017 21:07
Show Gist options
  • Save MakerTim/3d3938a062e3e9890440a613fd8832d6 to your computer and use it in GitHub Desktop.
Save MakerTim/3d3938a062e3e9890440a613fd8832d6 to your computer and use it in GitHub Desktop.
Recursive Loop java
private static Set<Block> findBlocksAround(Block block) {
Set<Block> blocks = new HashSet<>();
loopNeighbours(block, blocks);
return blocks;
}
private static void loopNeighbours(Block block, Set<Block> blocks) {
blocks.add(block);
for (BlockFace neighbour : BlockFace.values()) {
Block neighbourBlock = block.getRelative(neighbour);
if (neighbourBlock == null || neighbourBlock.getType() == Material.AIR) {
continue;
}
if (!blocks.contains(neighbourBlock)) {
loopNeighbours(neighbourBlock, blocks);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment