Created
March 3, 2022 17:14
-
-
Save Yuhtin/450a547aaefa9ffe2a96b7e2b923c666 to your computer and use it in GitHub Desktop.
Get chunk grid based on a central chunk/location
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.