diff --git a/paper-server/patches/sources/net/minecraft/world/level/Level.java.patch b/paper-server/patches/sources/net/minecraft/world/level/Level.java.patch index 4cd73334b..54a0a3910 100644 --- a/paper-server/patches/sources/net/minecraft/world/level/Level.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/level/Level.java.patch @@ -270,7 +270,15 @@ public boolean isInWorldBounds(BlockPos pos) { return !this.isOutsideBuildHeight(pos) && Level.isInWorldBoundsHorizontal(pos); } -@@ -179,18 +345,80 @@ +@@ -172,25 +338,87 @@ + } + + private static boolean isInWorldBoundsHorizontal(BlockPos pos) { +- return pos.getX() >= -30000000 && pos.getZ() >= -30000000 && pos.getX() < 30000000 && pos.getZ() < 30000000; ++ return pos.getX() >= -30000000 && pos.getZ() >= -30000000 && pos.getX() < 30000000 && pos.getZ() < 30000000; // Diff on change warnUnsafeChunk() + } + + private static boolean isOutsideSpawnableHeight(int y) { return y < -20000000 || y >= 20000000; } @@ -373,7 +381,7 @@ if (this.isOutsideBuildHeight(pos)) { return false; } else if (!this.isClientSide && this.isDebug()) { -@@ -214,45 +454,125 @@ +@@ -214,44 +454,124 @@ } else { LevelChunk chunk = this.getChunkAt(pos); Block block = state.getBlock(); @@ -458,10 +466,10 @@ + // CraftBukkit end + return true; - } - } - } - ++ } ++ } ++ } ++ + // CraftBukkit start - Split off from above in order to directly send client and physic updates + public void notifyAndUpdatePhysics(BlockPos blockposition, LevelChunk chunk, BlockState oldBlock, BlockState newBlock, BlockState actualBlock, int i, int j) { + BlockState iblockdata = newBlock; @@ -500,20 +508,19 @@ + // CraftBukkit end + iblockdata.updateNeighbourShapes(this, blockposition, k, j - 1); + iblockdata.updateIndirectNeighbourShapes(this, blockposition, k, j - 1); -+ } + } + + // CraftBukkit start - SPIGOT-5710 + if (!this.preventPoiUpdated) { + this.onBlockStateChange(blockposition, iblockdata1, iblockdata2); + } + // CraftBukkit end -+ } -+ } + } + } + // CraftBukkit end -+ + public void onBlockStateChange(BlockPos pos, BlockState oldBlock, BlockState newBlock) {} - @Override @@ -270,9 +590,26 @@ return false; } else { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 827cf8b2e..5379931b2 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -302,9 +302,24 @@ public class CraftWorld extends CraftRegionAccessor implements World { public boolean setSpawnLocation(int x, int y, int z) { return this.setSpawnLocation(x, y, z, 0.0F); } + // Paper start + private static void warnUnsafeChunk(String reason, int x, int z) { + // if any chunk coord is outside of 30 million blocks + if (x > 1875000 || z > 1875000 || x < -1875000 || z < -1875000) { + Plugin plugin = io.papermc.paper.util.StackWalkerUtil.getFirstPluginCaller(); + if (plugin != null) { + plugin.getLogger().warning("Plugin is %s at (%s, %s), this might cause issues.".formatted(reason, x, z)); + } + if (net.minecraft.server.MinecraftServer.getServer().isDebugging()) { + io.papermc.paper.util.TraceUtil.dumpTraceForThread("Dangerous chunk retrieval"); + } + } + } + // Paper end @Override public Chunk getChunkAt(int x, int z) { + warnUnsafeChunk("getting a faraway chunk", x, z); // Paper net.minecraft.world.level.chunk.LevelChunk chunk = (net.minecraft.world.level.chunk.LevelChunk) this.world.getChunk(x, z, ChunkStatus.FULL, true); return new CraftChunk(chunk); } @@ -400,6 +415,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { if (!unloadChunk0(x, z, false)) { return false; } + warnUnsafeChunk("regenerating a faraway chunk", x, z); // Paper final long chunkKey = ChunkCoordIntPair.pair(x, z); world.getChunkProvider().unloadQueue.remove(chunkKey); @@ -473,6 +489,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public boolean loadChunk(int x, int z, boolean generate) { org.spigotmc.AsyncCatcher.catchOp("chunk load"); // Spigot + warnUnsafeChunk("loading a faraway chunk", x, z); // Paper ChunkAccess chunk = this.world.getChunkSource().getChunk(x, z, generate || isChunkGenerated(x, z) ? ChunkStatus.FULL : ChunkStatus.EMPTY, true); // Paper // If generate = false, but the chunk already exists, we will get this back. @@ -505,6 +522,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public boolean addPluginChunkTicket(int x, int z, Plugin plugin) { + warnUnsafeChunk("adding a faraway chunk ticket", x, z); // Paper Preconditions.checkArgument(plugin != null, "null plugin"); Preconditions.checkArgument(plugin.isEnabled(), "plugin is not enabled"); @@ -605,6 +623,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public void setChunkForceLoaded(int x, int z, boolean forced) { + warnUnsafeChunk("forceloading a faraway chunk", x, z); // Paper this.getHandle().setChunkForced(x, z, forced); } @@ -939,6 +958,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public int getHighestBlockYAt(int x, int z, org.bukkit.HeightMap heightMap) { + warnUnsafeChunk("getting a faraway chunk", x >> 4, z >> 4); // Paper // Transient load for this tick return this.world.getChunk(x >> 4, z >> 4).getHeight(CraftHeightMap.toNMS(heightMap), x, z); } @@ -2344,6 +2364,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { // Paper start @Override public void getChunkAtAsync(int x, int z, boolean gen, boolean urgent, @NotNull Consumer cb) { + warnUnsafeChunk("getting a faraway chunk async", x, z); // Paper ca.spottedleaf.moonrise.common.util.ChunkSystem.scheduleChunkLoad( this.getHandle(), x, z, gen, ChunkStatus.FULL, true, urgent ? ca.spottedleaf.concurrentutil.util.Priority.HIGHER : ca.spottedleaf.concurrentutil.util.Priority.NORMAL, @@ -2356,6 +2377,8 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public void getChunksAtAsync(int minX, int minZ, int maxX, int maxZ, boolean urgent, Runnable cb) { + warnUnsafeChunk("getting a faraway chunk async", minX, minZ); // Paper + warnUnsafeChunk("getting a faraway chunk async", maxX, maxZ); // Paper this.getHandle().loadChunks( minX, minZ, maxX, maxZ, urgent ? ca.spottedleaf.concurrentutil.util.Priority.HIGHER : ca.spottedleaf.concurrentutil.util.Priority.NORMAL,