This commit is contained in:
themode 2021-01-08 08:32:33 +01:00
parent 35973c227e
commit 066b3dc417
2 changed files with 14 additions and 6 deletions

View File

@ -749,11 +749,19 @@ public class Player extends LivingEntity implements CommandSender {
super.setInstance(instance); super.setInstance(instance);
// runnable used to send newly visible chunks to player once spawned in the instance
final Runnable refreshRunnable = () -> {
final Chunk chunk = getChunk();
if (chunk != null) {
refreshVisibleChunks(chunk);
}
};
if (spawnPosition != null && !position.isSimilar(spawnPosition)) { if (spawnPosition != null && !position.isSimilar(spawnPosition)) {
teleport(spawnPosition, teleport(spawnPosition,
position.inSameChunk(spawnPosition) ? () -> refreshVisibleChunks(getChunk()) : null); position.inSameChunk(spawnPosition) ? refreshRunnable : null);
} else { } else {
refreshVisibleChunks(getChunk()); refreshRunnable.run();
} }
PlayerSpawnEvent spawnEvent = new PlayerSpawnEvent(this, instance, firstSpawn); PlayerSpawnEvent spawnEvent = new PlayerSpawnEvent(this, instance, firstSpawn);

View File

@ -264,11 +264,11 @@ public class Position implements PublicCloneable<Position> {
* @return true if 'this' is in the same chunk as {@code position} * @return true if 'this' is in the same chunk as {@code position}
*/ */
public boolean inSameChunk(@NotNull Position position) { public boolean inSameChunk(@NotNull Position position) {
final int chunkX1 = ChunkUtils.getChunkCoordinate((int) Math.floor(getX())); final int chunkX1 = ChunkUtils.getChunkCoordinate((int) getX());
final int chunkZ1 = ChunkUtils.getChunkCoordinate((int) Math.floor(getZ())); final int chunkZ1 = ChunkUtils.getChunkCoordinate((int) getZ());
final int chunkX2 = ChunkUtils.getChunkCoordinate((int) Math.floor(position.getX())); final int chunkX2 = ChunkUtils.getChunkCoordinate((int) position.getX());
final int chunkZ2 = ChunkUtils.getChunkCoordinate((int) Math.floor(position.getZ())); final int chunkZ2 = ChunkUtils.getChunkCoordinate((int) position.getZ());
return chunkX1 == chunkX2 && chunkZ1 == chunkZ2; return chunkX1 == chunkX2 && chunkZ1 == chunkZ2;
} }