Skip to content

Commit

Permalink
PlayerRespawnHandler optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
MykolaMurza committed Feb 18, 2024
1 parent 90e9199 commit 687bc1f
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,16 @@ private void checkIsLocationSafeAndMoveIfNot(Location location, World world, boo
}

private void preloadChunks(Location location) {
// The most important chunk to preload.
location.getWorld().getChunkAtAsync(location);
// Neighbour chunks to preload in radius of `radius`.
int radius = 2;
for (int dx = -radius; dx <= radius; dx++) {
for (int dz = -radius; dz <= radius; dz++) {
if (dx == 0 && dz == 0) {
// Preloaded first.
continue;
}
int chunkX = location.getBlockX() >> 4 + dx;
int chunkZ = location.getBlockZ() >> 4 + dz;
location.getWorld().getChunkAtAsync(chunkX, chunkZ);
Expand Down

0 comments on commit 687bc1f

Please sign in to comment.