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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/server/level/ServerLevel.java +++ b/src/main/java/net/minecraft/server/level/ServerLevel.java @@ -0,0 +0,0 @@ public class ServerLevel extends net.minecraft.world.level.Level implements Worl } @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 - Asynchronous IO diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java +++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java @@ -0,0 +0,0 @@ public class ServerGamePacketListenerImpl implements ServerGamePacketListener { speed = player.abilities.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.yRot, this.player.xRot, Collections.emptySet()); return; } diff --git a/src/main/java/net/minecraft/world/entity/ai/village/poi/PoiManager.java b/src/main/java/net/minecraft/world/entity/ai/village/poi/PoiManager.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/entity/ai/village/poi/PoiManager.java +++ b/src/main/java/net/minecraft/world/entity/ai/village/poi/PoiManager.java @@ -0,0 +0,0 @@ public class PoiManager extends SectionStorage { // Paper start - Asynchronous chunk io @javax.annotation.Nullable @Override - public CompoundTag read(ChunkPos chunkcoordintpair) throws java.io.IOException { + public CompoundTag read(ChunkPos pos) throws java.io.IOException { if (this.world != null && Thread.currentThread() != com.destroystokyo.paper.io.PaperFileIOThread.Holder.INSTANCE) { CompoundTag ret = com.destroystokyo.paper.io.PaperFileIOThread.Holder.INSTANCE - .loadChunkDataAsyncFuture(this.world, chunkcoordintpair.x, chunkcoordintpair.z, com.destroystokyo.paper.io.IOUtil.getPriorityForCurrentThread(), + .loadChunkDataAsyncFuture(this.world, pos.x, pos.z, com.destroystokyo.paper.io.IOUtil.getPriorityForCurrentThread(), true, false, true).join().poiData; if (ret == com.destroystokyo.paper.io.PaperFileIOThread.FAILURE_VALUE) { @@ -0,0 +0,0 @@ public class PoiManager extends SectionStorage { } return ret; } - return super.read(chunkcoordintpair); + return super.read(pos); } @Override - public void write(ChunkPos chunkcoordintpair, CompoundTag nbttagcompound) throws java.io.IOException { + public void write(ChunkPos pos, CompoundTag tag) throws java.io.IOException { if (this.world != null && Thread.currentThread() != com.destroystokyo.paper.io.PaperFileIOThread.Holder.INSTANCE) { com.destroystokyo.paper.io.PaperFileIOThread.Holder.INSTANCE.scheduleSave( - this.world, chunkcoordintpair.x, chunkcoordintpair.z, nbttagcompound, null, + this.world, pos.x, pos.z, tag, null, com.destroystokyo.paper.io.IOUtil.getPriorityForCurrentThread()); return; } - super.write(chunkcoordintpair, nbttagcompound); + super.write(pos, tag); } // Paper end diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/level/Level.java +++ b/src/main/java/net/minecraft/world/level/Level.java @@ -0,0 +0,0 @@ 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 typeKey; } @@ -0,0 +0,0 @@ public abstract class Level implements LevelAccessor, AutoCloseable { for (int i1 = i; i1 < j; ++i1) { for (int j1 = k; j1 < l; ++j1) { - LevelChunk chunk = ichunkprovider.getChunkNow(i1, j1); + LevelChunk chunk = (LevelChunk)this.getChunkIfLoadedImmediately(i1, j1); // Paper if (chunk != null) { chunk.getEntitiesOfClass(entityClass, box, list, predicate); diff --git a/src/main/java/org/spigotmc/ActivationRange.java b/src/main/java/org/spigotmc/ActivationRange.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/spigotmc/ActivationRange.java +++ b/src/main/java/org/spigotmc/ActivationRange.java @@ -0,0 +0,0 @@ public class ActivationRange { for ( int j1 = k; j1 <= l; ++j1 ) { - if ( world.getWorld().isChunkLoaded( i1, j1 ) ) + LevelChunk chunk = (LevelChunk) world.getChunkIfLoadedImmediately( i1, j1 ); + if ( chunk != null ) { - activateChunkEntities( world.getChunk( i1, j1 ) ); + activateChunkEntities( chunk ); } } }