Skip to content

Instantly share code, notes, and snippets.

@Yuhtin
Created March 3, 2022 17:14
Show Gist options
  • Save Yuhtin/450a547aaefa9ffe2a96b7e2b923c666 to your computer and use it in GitHub Desktop.
Save Yuhtin/450a547aaefa9ffe2a96b7e2b923c666 to your computer and use it in GitHub Desktop.
Get chunk grid based on a central chunk/location
public Collection<Chunk> getNearbyChunksGrid(Location location) {
val offset = new int[]{-1, 0, 1};
val world = location.getWorld();
val baseX = location.getChunk().getX();
val baseZ = location.getChunk().getZ();
val chunksAroundPlayer = new HashSet<Chunk>();
for (val x : offset) {
for (val z : offset) {
val chunk = world.getChunkAt(baseX + x, baseZ + z);
chunksAroundPlayer.add(chunk);
}
}
return chunksAroundPlayer;
}
@Yuhtin
Copy link
Author

Yuhtin commented Mar 3, 2022

Get all chunks around a main chunk (like this):

X- Chunks around
Y- Chunk of location from parameter of the method

X X X
X Y X
X X X

This is util to avoid using nearbyEntities and for in all players with a distancesquared check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment