mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-04 23:47:59 +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()) {
|
if (player.getLastSentTeleportId() != player.getLastReceivedTeleportId()) {
|
||||||
return;
|
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 currentPosition = player.getPosition();
|
||||||
final var newPosition = new Pos(x, y, z, yaw, pitch);
|
final var newPosition = new Pos(x, y, z, yaw, pitch);
|
||||||
@ -74,6 +69,12 @@ public class PlayerPositionListener {
|
|||||||
return;
|
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);
|
PlayerMoveEvent playerMoveEvent = new PlayerMoveEvent(player, newPosition);
|
||||||
EventDispatcher.call(playerMoveEvent);
|
EventDispatcher.call(playerMoveEvent);
|
||||||
|
|
||||||
|
@ -77,10 +77,7 @@ public final class ChunkUtils {
|
|||||||
* @return true if the chunk is loaded, false otherwise
|
* @return true if the chunk is loaded, false otherwise
|
||||||
*/
|
*/
|
||||||
public static boolean isLoaded(@NotNull Instance instance, double x, double z) {
|
public static boolean isLoaded(@NotNull Instance instance, double x, double z) {
|
||||||
final int chunkX = getChunkCoordinate(x);
|
final Chunk chunk = instance.getChunk(getChunkCoordinate(x), getChunkCoordinate(z));
|
||||||
final int chunkZ = getChunkCoordinate(z);
|
|
||||||
|
|
||||||
final Chunk chunk = instance.getChunk(chunkX, chunkZ);
|
|
||||||
return isLoaded(chunk);
|
return isLoaded(chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user