Fix player teleport being teleported inside a block

This commit is contained in:
Felix Cravic 2020-12-05 17:14:10 +01:00
parent 3c0fa42758
commit 1f1bd348b5
2 changed files with 9 additions and 4 deletions

View File

@ -166,7 +166,7 @@ public class Player extends LivingEntity implements CommandSender {
private long targetBreakDelay; // The last break delay requested
private long targetBlockBreakCount; // Number of tick since the last stage change
private byte targetStage; // The current stage of the target block, only if multi player breaking is disabled
private final Set<Player> targetBreakers = new HashSet<>(1); // Only used if multi player breaking is disabled, contains only this player
private final Set<Player> targetBreakers = Collections.singleton(this); // Only used if multi player breaking is disabled, contains only this player
// Position synchronization with viewers
private long lastPlayerSynchronizationTime;
@ -221,9 +221,6 @@ public class Player extends LivingEntity implements CommandSender {
this.levelFlat = true;
refreshPosition(0, 0, 0);
// Used to cache the breaker for single custom block breaking
this.targetBreakers.add(this);
// FakePlayer init its connection there
playerConnectionInit();

View File

@ -2,6 +2,7 @@ package net.minestom.server.listener;
import net.minestom.server.entity.Player;
import net.minestom.server.event.player.PlayerMoveEvent;
import net.minestom.server.instance.Chunk;
import net.minestom.server.network.packet.client.play.ClientPlayerPacket;
import net.minestom.server.network.packet.client.play.ClientPlayerPositionAndRotationPacket;
import net.minestom.server.network.packet.client.play.ClientPlayerPositionPacket;
@ -51,6 +52,13 @@ public class PlayerPositionListener {
private static void processMovement(@NotNull Player player, float x, float y, float z,
float yaw, float pitch, boolean onGround) {
// Prevent the player from moving during a teleport
final float distance = player.getPosition().getDistance(x, y, z);
final int chunkRange = player.getChunkRange() * Chunk.CHUNK_SECTION_SIZE;
if (distance >= chunkRange) {
return;
}
// Try to move in an unloaded chunk, prevent it
if (!ChunkUtils.isLoaded(player.getInstance(), x, z)) {
player.teleport(player.getPosition());