mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-04 23:47:59 +01:00
Clear chunk history on teleport and instance change, initialize history with less common chunk coordinate; fixes #1536
This commit is contained in:
parent
1a013728fd
commit
77be05085d
@ -560,6 +560,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
||||
return AsyncUtils.VOID_FUTURE;
|
||||
}
|
||||
// Must update the player chunks
|
||||
chunkUpdateLimitChecker.clearHistory();
|
||||
final boolean dimensionChange = !Objects.equals(dimensionType, instance.getDimensionType());
|
||||
final Consumer<Instance> runnable = (i) -> spawnPlayer(i, spawnPosition,
|
||||
currentInstance == null, dimensionChange, true);
|
||||
@ -2064,6 +2065,12 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull CompletableFuture<Void> teleport(@NotNull Pos position, long @Nullable [] chunks) {
|
||||
chunkUpdateLimitChecker.clearHistory();
|
||||
return super.teleport(position, chunks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the main or off hand of the player.
|
||||
*/
|
||||
|
@ -3,6 +3,8 @@ package net.minestom.server.utils.chunk;
|
||||
import net.minestom.server.instance.Chunk;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public final class ChunkUpdateLimitChecker {
|
||||
private final int historySize;
|
||||
@ -11,6 +13,7 @@ public final class ChunkUpdateLimitChecker {
|
||||
public ChunkUpdateLimitChecker(int historySize) {
|
||||
this.historySize = historySize;
|
||||
this.chunkHistory = new long[historySize];
|
||||
this.clearHistory();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -32,4 +35,8 @@ public final class ChunkUpdateLimitChecker {
|
||||
chunkHistory[lastIndex] = index;
|
||||
return result;
|
||||
}
|
||||
|
||||
public void clearHistory() {
|
||||
Arrays.fill(this.chunkHistory, Long.MAX_VALUE);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user