From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Mon, 8 Jul 2019 00:13:36 -0700 Subject: [PATCH] Use getChunkIfLoadedImmediately in places This prevents us from hitting chunk loads for chunks at or less-than ticket level 33 (yes getChunkIfLoaded will actually perform a chunk load in that case). diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java index f28aefd9192b26f39e71826fa87cca60a799be39..f8c0574137cab33d0b5efe5d532efb132dcb914a 100644 --- a/src/main/java/net/minecraft/server/level/ServerLevel.java +++ b/src/main/java/net/minecraft/server/level/ServerLevel.java @@ -203,7 +203,7 @@ public class ServerLevel extends Level implements WorldGenLevel { } @Override public LevelChunk getChunkIfLoaded(int x, int z) { // Paper - this was added in world too but keeping here for NMS ABI - return this.chunkSource.getChunk(x, z, false); + return this.chunkSource.getChunkAtIfLoadedImmediately(x, z); // Paper } // Paper start diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java index d7c053043aecf7dd701773192eb54017eb87237a..faa32056399e93e729c6313dc15e7315e34b8eb0 100644 --- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java +++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java @@ -1310,7 +1310,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser speed = this.player.getAbilities().walkingSpeed * 10f; } // Paper start - Prevent moving into unloaded chunks - if (player.level.paperConfig.preventMovingIntoUnloadedChunks && (this.player.getX() != toX || this.player.getZ() != toZ) && !worldserver.hasChunk((int) Math.floor(toX) >> 4, (int) Math.floor(toZ) >> 4)) { + if (player.level.paperConfig.preventMovingIntoUnloadedChunks && (this.player.getX() != toX || this.player.getZ() != toZ) && worldserver.getChunkIfLoadedImmediately((int) Math.floor(toX) >> 4, (int) Math.floor(toZ) >> 4) == null) { // Paper - use getIfLoadedImmediately this.internalTeleport(this.player.getX(), this.player.getY(), this.player.getZ(), this.player.getYRot(), this.player.getXRot(), Collections.emptySet(), true); return; } diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java index b527a32b3aac3888ac42463e658160491f0005cc..a7485746417e0dddb392c89a5a1d467c0bc83fbe 100644 --- a/src/main/java/net/minecraft/world/level/Level.java +++ b/src/main/java/net/minecraft/world/level/Level.java @@ -192,6 +192,13 @@ public abstract class Level implements LevelAccessor, AutoCloseable { return (CraftServer) Bukkit.getServer(); } + // Paper start + @Override + public boolean hasChunk(int chunkX, int chunkZ) { + return ((ServerLevel) this).getChunkIfLoaded(chunkX, chunkZ) != null; + } + // Paper end + public ResourceKey getTypeKey() { return this.typeKey; } @@ -1371,7 +1378,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable { for (int l1 = j; l1 <= l; ++l1) { for (int i2 = k; i2 <= i1; ++i2) { - LevelChunk chunk = this.getChunkSource().getChunkNow(l1, i2); + LevelChunk chunk = (LevelChunk) this.getChunkIfLoadedImmediately(l1, i2); // Paper if (chunk != null) { for (int j2 = j1; j2 <= k1; ++j2) {