Clear chunk history on teleport and instance change, initialize history with less common chunk coordinate; fixes #1536

This commit is contained in:
Noel Németh 2022-11-26 11:10:44 +01:00
parent 1a013728fd
commit 77be05085d
2 changed files with 14 additions and 0 deletions

View File

@ -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.
*/

View File

@ -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);
}
}