Use getChunkIfLoadedImmediately in places (#2297)

* 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).

* Resolve issue #2301

* Also target World#getChunkIfLoaded
This commit is contained in:
Spottedleaf 2019-07-17 21:41:24 -07:00 committed by Zach
parent 0708fa363b
commit 920ad7c742

View File

@ -0,0 +1,83 @@
From 5bbfd0385d4b4aee58fcdbe1d0c2a602f230ef35 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
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/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index bece9a16ba..9485bc4810 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -199,7 +199,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
}
public boolean isChunkLoaded() {
- return world.isChunkLoaded((int) Math.floor(this.locX) >> 4, (int) Math.floor(this.locZ) >> 4);
+ return world.getChunkIfLoadedImmediately((int) Math.floor(this.locX) >> 4, (int) Math.floor(this.locZ) >> 4) != null; // Paper
}
// CraftBukkit end
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
index 87639793ae..c900e32cd4 100644
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
@@ -980,7 +980,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
speed = player.abilities.walkSpeed * 10f;
}
// Paper start - Prevent moving into unloaded chunks
- if (player.world.paperConfig.preventMovingIntoUnloadedChunks && (this.player.locX != toX || this.player.locZ != toZ) && !worldserver.isChunkLoaded((int) Math.floor(toX) >> 4, (int) Math.floor(toZ) >> 4)) {
+ if (player.world.paperConfig.preventMovingIntoUnloadedChunks && (this.player.locX != toX || this.player.locZ != toZ) && worldserver.getChunkIfLoadedImmediately((int) Math.floor(toX) >> 4, (int) Math.floor(toZ) >> 4) == null) { // Paper - use getIfLoadedImmediately
this.internalTeleport(this.player.locX, this.player.locY, this.player.locZ, this.player.yaw, this.player.pitch, Collections.emptySet());
return;
}
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index ee6474b188..31cac69315 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -131,7 +131,7 @@ public abstract class World implements IIBlockAccess, GeneratorAccess, AutoClose
}
public Chunk getChunkIfLoaded(int x, int z) {
- return ((ChunkProviderServer) this.chunkProvider).getChunkAt(x, z, false);
+ return ((ChunkProviderServer) this.chunkProvider).getChunkAtIfLoadedImmediately(x, z); // Paper
}
protected World(WorldData worlddata, DimensionManager dimensionmanager, BiFunction<World, WorldProvider, IChunkProvider> bifunction, GameProfilerFiller gameprofilerfiller, boolean flag, org.bukkit.generator.ChunkGenerator gen, org.bukkit.World.Environment env) {
@@ -274,12 +274,12 @@ public abstract class World implements IIBlockAccess, GeneratorAccess, AutoClose
}
public boolean isLoaded(BlockPosition blockposition) {
- return getChunkIfLoaded(blockposition.getX() >> 4, blockposition.getZ() >> 4) != null; // Paper
+ return getChunkIfLoadedImmediately(blockposition.getX() >> 4, blockposition.getZ() >> 4) != null; // Paper
}
// Paper start
public boolean isLoadedAndInBounds(BlockPosition blockposition) {
- return getWorldBorder().isInBounds(blockposition) && getChunkIfLoaded(blockposition.getX() >> 4, blockposition.getZ() >> 4) != null;
+ return getWorldBorder().isInBounds(blockposition) && getChunkIfLoadedImmediately(blockposition.getX() >> 4, blockposition.getZ() >> 4) != null;
}
public Chunk getChunkIfLoaded(BlockPosition blockposition) {
return getChunkIfLoaded(blockposition.getX() >> 4, blockposition.getZ() >> 4);
diff --git a/src/main/java/org/spigotmc/ActivationRange.java b/src/main/java/org/spigotmc/ActivationRange.java
index f86404f83a..92601c581c 100644
--- a/src/main/java/org/spigotmc/ActivationRange.java
+++ b/src/main/java/org/spigotmc/ActivationRange.java
@@ -143,9 +143,10 @@ public class ActivationRange
{
for ( int j1 = k; j1 <= l; ++j1 )
{
- if ( world.getWorld().isChunkLoaded( i1, j1 ) )
+ Chunk chunk = (Chunk) world.getChunkIfLoadedImmediately( i1, j1 );
+ if ( chunk != null )
{
- activateChunkEntities( world.getChunkAt( i1, j1 ) );
+ activateChunkEntities( chunk );
}
}
}
--
2.22.0