mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-02 14:38:26 +01:00
Limit chunk map lookup while moving
This commit is contained in:
parent
12e430db69
commit
bca3324b56
@ -61,11 +61,6 @@ public class PlayerPositionListener {
|
||||
if (player.getLastSentTeleportId() != player.getLastReceivedTeleportId()) {
|
||||
return;
|
||||
}
|
||||
// Try to move in an unloaded chunk, prevent it
|
||||
if (!ChunkUtils.isLoaded(instance, x, z)) {
|
||||
player.teleport(player.getPosition());
|
||||
return;
|
||||
}
|
||||
|
||||
final var currentPosition = player.getPosition();
|
||||
final var newPosition = new Pos(x, y, z, yaw, pitch);
|
||||
@ -74,6 +69,12 @@ public class PlayerPositionListener {
|
||||
return;
|
||||
}
|
||||
|
||||
// Try to move in an unloaded chunk, prevent it
|
||||
if (!currentPosition.sameChunk(newPosition) && !ChunkUtils.isLoaded(instance, x, z)) {
|
||||
player.teleport(player.getPosition());
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerMoveEvent playerMoveEvent = new PlayerMoveEvent(player, newPosition);
|
||||
EventDispatcher.call(playerMoveEvent);
|
||||
|
||||
|
@ -77,10 +77,7 @@ public final class ChunkUtils {
|
||||
* @return true if the chunk is loaded, false otherwise
|
||||
*/
|
||||
public static boolean isLoaded(@NotNull Instance instance, double x, double z) {
|
||||
final int chunkX = getChunkCoordinate(x);
|
||||
final int chunkZ = getChunkCoordinate(z);
|
||||
|
||||
final Chunk chunk = instance.getChunk(chunkX, chunkZ);
|
||||
final Chunk chunk = instance.getChunk(getChunkCoordinate(x), getChunkCoordinate(z));
|
||||
return isLoaded(chunk);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user