From 00ef8bdcb0611c86b4a731b5b309cd380f4e9894 Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Sat, 9 Nov 2024 07:41:26 -0700 Subject: [PATCH] Fix Entity#isTicking and update Paper entity command (#11590) fixes #10299 --- patches/server/0009-MC-Utils.patch | 15 +---------- patches/server/0017-Paper-command.patch | 6 ++--- .../server/0024-Remove-Spigot-timings.patch | 6 ++--- ...4-PlayerNaturallySpawnCreaturesEvent.patch | 4 +-- patches/server/0410-Entity-isTicking.patch | 4 +-- patches/server/0694-Don-t-tick-markers.patch | 6 ++--- .../1038-Moonrise-optimisation-patches.patch | 26 ++++++++----------- .../1053-Optional-per-player-mob-spawns.patch | 6 ++--- ...ng-PreCreatureSpawnEvent-with-per-pl.patch | 4 +-- 9 files changed, 30 insertions(+), 47 deletions(-) diff --git a/patches/server/0009-MC-Utils.patch b/patches/server/0009-MC-Utils.patch index ede5f9988d..3de493e13b 100644 --- a/patches/server/0009-MC-Utils.patch +++ b/patches/server/0009-MC-Utils.patch @@ -5344,7 +5344,7 @@ index 019228b1809e3816b0b4dfb9f19b8d42876cc240..6c2339d6a93172e25040c4868a3a4747 while (objectiterator.hasNext()) { diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java -index 9cdcab885a915990a679f3fc9ae6885f7d125bfd..c615510f3f59292715bcff1bd9e4e896c9733436 100644 +index 9cdcab885a915990a679f3fc9ae6885f7d125bfd..a970ceab0176d97f9d274ed257c2f86f3b63e430 100644 --- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java +++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java @@ -74,6 +74,10 @@ public class ServerChunkCache extends ChunkSource { @@ -5422,19 +5422,6 @@ index 9cdcab885a915990a679f3fc9ae6885f7d125bfd..c615510f3f59292715bcff1bd9e4e896 boolean flag = this.distanceManager.runAllUpdates(this.chunkMap); boolean flag1 = this.chunkMap.promoteChunkMap(); -@@ -312,6 +364,12 @@ public class ServerChunkCache extends ChunkSource { - } - } - -+ // Paper start -+ public boolean isPositionTicking(Entity entity) { -+ return this.isPositionTicking(ChunkPos.asLong(net.minecraft.util.Mth.floor(entity.getX()) >> 4, net.minecraft.util.Mth.floor(entity.getZ()) >> 4)); -+ } -+ // Paper end -+ - public boolean isPositionTicking(long pos) { - if (!this.level.shouldTickBlocksAt(pos)) { - return false; diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java index f6a3606b972064c4ec78487374e6197c0c447e27..c6ded1ac73ddbc0336000f77c0f99fa20551a0de 100644 --- a/src/main/java/net/minecraft/server/level/ServerLevel.java diff --git a/patches/server/0017-Paper-command.patch b/patches/server/0017-Paper-command.patch index 4b47a9acbb..c7390c47e6 100644 --- a/patches/server/0017-Paper-command.patch +++ b/patches/server/0017-Paper-command.patch @@ -332,7 +332,7 @@ index 0000000000000000000000000000000000000000..7e9e0ff8639be135bf8575e375cbada5 +} diff --git a/src/main/java/io/papermc/paper/command/subcommands/EntityCommand.java b/src/main/java/io/papermc/paper/command/subcommands/EntityCommand.java new file mode 100644 -index 0000000000000000000000000000000000000000..67fcba634f8183bb33834ac3b2c3dcfb8d87129e +index 0000000000000000000000000000000000000000..9d9d133e0d973ecda1ef1efc872a51ee10463fd1 --- /dev/null +++ b/src/main/java/io/papermc/paper/command/subcommands/EntityCommand.java @@ -0,0 +1,158 @@ @@ -447,7 +447,7 @@ index 0000000000000000000000000000000000000000..67fcba634f8183bb33834ac3b2c3dcfb + ChunkPos chunk = e.chunkPosition(); + info.left++; + info.right.put(chunk, info.right.getOrDefault(chunk, 0) + 1); -+ if (!chunkProviderServer.isPositionTicking(e)) { ++ if (!world.isPositionEntityTicking(e.blockPosition())) { + nonEntityTicking.merge(key, 1, Integer::sum); + } + }); @@ -617,7 +617,7 @@ index a61a92078a8bb4979f231c02ef5aa990b8ab57ad..cd9e4bfdb3f335213001ced27540bb7e this.setPvpAllowed(dedicatedserverproperties.pvp); this.setFlightAllowed(dedicatedserverproperties.allowFlight); diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java -index 2affb23b83e4368a94345b36410f23139f5d36c8..1b66c5173dd37433d895c0d804257141a3a8c588 100644 +index e497da2dba83779c4ad1c45cea133bddadf61446..4ec8731a48f81aff33c7d8bcfe00dea263735e48 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -991,6 +991,7 @@ public final class CraftServer implements Server { diff --git a/patches/server/0024-Remove-Spigot-timings.patch b/patches/server/0024-Remove-Spigot-timings.patch index b3b6ebc014..51dda21a5e 100644 --- a/patches/server/0024-Remove-Spigot-timings.patch +++ b/patches/server/0024-Remove-Spigot-timings.patch @@ -153,7 +153,7 @@ index 9d6be455c3bbcdbcb9d3d24b0bad79f46ba6a8cb..a129ddfe7b00d6abab94437806a5cfb9 @Override diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java -index c615510f3f59292715bcff1bd9e4e896c9733436..ccb6f28689a3cf7da4ea323c5dd8f595036c4b43 100644 +index a970ceab0176d97f9d274ed257c2f86f3b63e430..4a0fedff38f12ec87905558a100f1772cee03dd4 100644 --- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java +++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java @@ -207,13 +207,11 @@ public class ServerChunkCache extends ChunkSource { @@ -170,7 +170,7 @@ index c615510f3f59292715bcff1bd9e4e896c9733436..ccb6f28689a3cf7da4ea323c5dd8f595 ChunkResult chunkresult = (ChunkResult) completablefuture.join(); ChunkAccess ichunkaccess1 = (ChunkAccess) chunkresult.orElse(null); // CraftBukkit - decompile error -@@ -420,25 +418,19 @@ public class ServerChunkCache extends ChunkSource { +@@ -414,25 +412,19 @@ public class ServerChunkCache extends ChunkSource { ProfilerFiller gameprofilerfiller = Profiler.get(); gameprofilerfiller.push("purge"); @@ -196,7 +196,7 @@ index c615510f3f59292715bcff1bd9e4e896c9733436..ccb6f28689a3cf7da4ea323c5dd8f595 gameprofilerfiller.pop(); this.clearCache(); } -@@ -531,9 +523,7 @@ public class ServerChunkCache extends ChunkSource { +@@ -525,9 +517,7 @@ public class ServerChunkCache extends ChunkSource { } if (this.level.shouldTickBlocksAt(chunkcoordintpair.toLong())) { diff --git a/patches/server/0164-PlayerNaturallySpawnCreaturesEvent.patch b/patches/server/0164-PlayerNaturallySpawnCreaturesEvent.patch index 2c2148e253..6096f5a633 100644 --- a/patches/server/0164-PlayerNaturallySpawnCreaturesEvent.patch +++ b/patches/server/0164-PlayerNaturallySpawnCreaturesEvent.patch @@ -40,10 +40,10 @@ index 261943f1f188643793a72bd239dfc5fe604e3b99..985ba48a5ac027d3c3dcd9b710b53748 return true; diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java -index ccb6f28689a3cf7da4ea323c5dd8f595036c4b43..d4eb7608a3e40d2da4c427e9b3a2ce916be86df1 100644 +index 4a0fedff38f12ec87905558a100f1772cee03dd4..c9efcb6170e9ecc615ab70594954fae24ba46ac4 100644 --- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java +++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java -@@ -504,6 +504,15 @@ public class ServerChunkCache extends ChunkSource { +@@ -498,6 +498,15 @@ public class ServerChunkCache extends ChunkSource { List list1; if (flag && (this.spawnEnemies || this.spawnFriendlies)) { diff --git a/patches/server/0410-Entity-isTicking.patch b/patches/server/0410-Entity-isTicking.patch index 0a46bb21ad..069e67c326 100644 --- a/patches/server/0410-Entity-isTicking.patch +++ b/patches/server/0410-Entity-isTicking.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Entity#isTicking diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java -index 3f0a44db707176c25e306f55fa63da9314d682a1..4a26795d22c0276980f4d0ad266861389d8471a8 100644 +index 3f0a44db707176c25e306f55fa63da9314d682a1..fdb56135274b0cdd31e92a81c9fc40be3ad23c37 100644 --- a/src/main/java/net/minecraft/world/entity/Entity.java +++ b/src/main/java/net/minecraft/world/entity/Entity.java @@ -4739,5 +4739,9 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess @@ -14,7 +14,7 @@ index 3f0a44db707176c25e306f55fa63da9314d682a1..4a26795d22c0276980f4d0ad26686138 } + + public boolean isTicking() { -+ return ((net.minecraft.server.level.ServerChunkCache) level.getChunkSource()).isPositionTicking(this); ++ return ((net.minecraft.server.level.ServerLevel) this.level).isPositionEntityTicking(this.blockPosition()); + } // Paper end - Expose entity id counter } diff --git a/patches/server/0694-Don-t-tick-markers.patch b/patches/server/0694-Don-t-tick-markers.patch index e5c290a988..137b6302b6 100644 --- a/patches/server/0694-Don-t-tick-markers.patch +++ b/patches/server/0694-Don-t-tick-markers.patch @@ -10,15 +10,15 @@ list is only used in the tick and tickPassenger methods, so we can safely not ad markers to it. When the config option is set to true, markers are ticked as normal. diff --git a/src/main/java/io/papermc/paper/command/subcommands/EntityCommand.java b/src/main/java/io/papermc/paper/command/subcommands/EntityCommand.java -index 67fcba634f8183bb33834ac3b2c3dcfb8d87129e..777b789fdcdf297309cfb36fc7f77e3fdb6327ca 100644 +index 9d9d133e0d973ecda1ef1efc872a51ee10463fd1..f671b74e4179fc29bc600b52e456ba9f78d8bbd6 100644 --- a/src/main/java/io/papermc/paper/command/subcommands/EntityCommand.java +++ b/src/main/java/io/papermc/paper/command/subcommands/EntityCommand.java @@ -109,7 +109,7 @@ public final class EntityCommand implements PaperSubcommand { ChunkPos chunk = e.chunkPosition(); info.left++; info.right.put(chunk, info.right.getOrDefault(chunk, 0) + 1); -- if (!chunkProviderServer.isPositionTicking(e)) { -+ if (!chunkProviderServer.isPositionTicking(e) || (e instanceof net.minecraft.world.entity.Marker && !world.paperConfig().entities.markers.tick)) { // Paper - Configurable marker ticking +- if (!world.isPositionEntityTicking(e.blockPosition())) { ++ if (!world.isPositionEntityTicking(e.blockPosition()) || (e instanceof net.minecraft.world.entity.Marker && !world.paperConfig().entities.markers.tick)) { // Paper - Configurable marker ticking nonEntityTicking.merge(key, 1, Integer::sum); } }); diff --git a/patches/server/1038-Moonrise-optimisation-patches.patch b/patches/server/1038-Moonrise-optimisation-patches.patch index 492290e894..4baed95c2a 100644 --- a/patches/server/1038-Moonrise-optimisation-patches.patch +++ b/patches/server/1038-Moonrise-optimisation-patches.patch @@ -26268,7 +26268,7 @@ index 65206fdfa5b94eaca139e433b4865c16b16641f3..bf4463bcb5dc439ac5a3fa08dd60845a } } diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java -index 76cb7ffad02dcc27966ca13da6552edbb696e41f..07dde7dbf4d9e1d2f61426e3f1dc3cd5be55f193 100644 +index ea0e972122abd08c2f822f6ff039ac89994e8c20..1d75ad42bfe9324baafb5d60e2fd44ece660a5cd 100644 --- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java +++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java @@ -52,7 +52,7 @@ import net.minecraft.world.level.storage.DimensionDataStorage; @@ -26580,7 +26580,7 @@ index 76cb7ffad02dcc27966ca13da6552edbb696e41f..07dde7dbf4d9e1d2f61426e3f1dc3cd5 } @Override -@@ -331,16 +405,7 @@ public class ServerChunkCache extends ChunkSource { +@@ -331,30 +405,18 @@ public class ServerChunkCache extends ChunkSource { } public boolean runDistanceManagerUpdates() { // Paper - public @@ -26597,10 +26597,6 @@ index 76cb7ffad02dcc27966ca13da6552edbb696e41f..07dde7dbf4d9e1d2f61426e3f1dc3cd5 + return ((ca.spottedleaf.moonrise.patches.chunk_system.level.ChunkSystemServerLevel)this.level).moonrise$getChunkTaskScheduler().chunkHolderManager.processTicketUpdates(); // Paper - rewrite chunk system } - // Paper start -@@ -350,17 +415,14 @@ public class ServerChunkCache extends ChunkSource { - // Paper end - public boolean isPositionTicking(long pos) { - if (!this.level.shouldTickBlocksAt(pos)) { - return false; @@ -26621,7 +26617,7 @@ index 76cb7ffad02dcc27966ca13da6552edbb696e41f..07dde7dbf4d9e1d2f61426e3f1dc3cd5 this.chunkMap.saveAllChunks(flush); } -@@ -371,17 +433,15 @@ public class ServerChunkCache extends ChunkSource { +@@ -365,17 +427,15 @@ public class ServerChunkCache extends ChunkSource { } public void close(boolean save) throws IOException { @@ -26642,7 +26638,7 @@ index 76cb7ffad02dcc27966ca13da6552edbb696e41f..07dde7dbf4d9e1d2f61426e3f1dc3cd5 ProfilerFiller gameprofilerfiller = Profiler.get(); gameprofilerfiller.push("purge"); -@@ -406,6 +466,7 @@ public class ServerChunkCache extends ChunkSource { +@@ -400,6 +460,7 @@ public class ServerChunkCache extends ChunkSource { this.runDistanceManagerUpdates(); gameprofilerfiller.popPush("chunks"); if (tickChunks) { @@ -26650,7 +26646,7 @@ index 76cb7ffad02dcc27966ca13da6552edbb696e41f..07dde7dbf4d9e1d2f61426e3f1dc3cd5 this.tickChunks(); this.chunkMap.tick(); } -@@ -432,7 +493,10 @@ public class ServerChunkCache extends ChunkSource { +@@ -426,7 +487,10 @@ public class ServerChunkCache extends ChunkSource { gameprofilerfiller.push("filteringTickingChunks"); this.collectTickingChunks(list); gameprofilerfiller.popPush("shuffleChunks"); @@ -26662,7 +26658,7 @@ index 76cb7ffad02dcc27966ca13da6552edbb696e41f..07dde7dbf4d9e1d2f61426e3f1dc3cd5 this.tickChunks(gameprofilerfiller, j, list); gameprofilerfiller.pop(); } finally { -@@ -463,14 +527,26 @@ public class ServerChunkCache extends ChunkSource { +@@ -457,14 +521,26 @@ public class ServerChunkCache extends ChunkSource { } private void collectTickingChunks(List chunks) { @@ -26694,7 +26690,7 @@ index 76cb7ffad02dcc27966ca13da6552edbb696e41f..07dde7dbf4d9e1d2f61426e3f1dc3cd5 } private void tickChunks(ProfilerFiller profiler, long timeDelta, List chunks) { -@@ -512,7 +588,7 @@ public class ServerChunkCache extends ChunkSource { +@@ -506,7 +582,7 @@ public class ServerChunkCache extends ChunkSource { NaturalSpawner.spawnForChunk(this.level, chunk, spawnercreature_d, list1); } @@ -26703,7 +26699,7 @@ index 76cb7ffad02dcc27966ca13da6552edbb696e41f..07dde7dbf4d9e1d2f61426e3f1dc3cd5 this.level.tickChunk(chunk, k); } } -@@ -525,11 +601,13 @@ public class ServerChunkCache extends ChunkSource { +@@ -519,11 +595,13 @@ public class ServerChunkCache extends ChunkSource { } private void getFullChunk(long pos, Consumer chunkConsumer) { @@ -26721,7 +26717,7 @@ index 76cb7ffad02dcc27966ca13da6552edbb696e41f..07dde7dbf4d9e1d2f61426e3f1dc3cd5 } -@@ -623,6 +701,12 @@ public class ServerChunkCache extends ChunkSource { +@@ -617,6 +695,12 @@ public class ServerChunkCache extends ChunkSource { this.chunkMap.setServerViewDistance(watchDistance); } @@ -26734,7 +26730,7 @@ index 76cb7ffad02dcc27966ca13da6552edbb696e41f..07dde7dbf4d9e1d2f61426e3f1dc3cd5 public void setSimulationDistance(int simulationDistance) { this.distanceManager.updateSimulationDistance(simulationDistance); } -@@ -714,21 +798,19 @@ public class ServerChunkCache extends ChunkSource { +@@ -708,21 +792,19 @@ public class ServerChunkCache extends ChunkSource { @Override // CraftBukkit start - process pending Chunk loadCallback() and unloadCallback() after each run task public boolean pollTask() { @@ -28416,7 +28412,7 @@ index 50040c497a819cd1229042ab3cb057d34a32cacc..1f9c436a632e4f110be61cf76fcfc3b7 + // Paper end - block counting } diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java -index ed276c599890d9db11130d8ae0844ca364a824a6..86e3d37ac9b4d5efe240c07289f88a070543b30d 100644 +index 29b2a3ad15f6ce802f1d1d16d519c674f5920b37..7bc32f2e7d8cd8aea6151f73420af91a9413e93a 100644 --- a/src/main/java/net/minecraft/world/entity/Entity.java +++ b/src/main/java/net/minecraft/world/entity/Entity.java @@ -176,7 +176,7 @@ import org.bukkit.event.player.PlayerTeleportEvent; diff --git a/patches/server/1053-Optional-per-player-mob-spawns.patch b/patches/server/1053-Optional-per-player-mob-spawns.patch index e002a911c0..0f6f46bc19 100644 --- a/patches/server/1053-Optional-per-player-mob-spawns.patch +++ b/patches/server/1053-Optional-per-player-mob-spawns.patch @@ -37,10 +37,10 @@ index f1999729cd1c00071c5e1835ee49ea5fcafa7b05..4896c3ba81ead769972fa9efdbe563d4 // Paper end diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java -index 07dde7dbf4d9e1d2f61426e3f1dc3cd5be55f193..12f49deea35ecbaea08869332982c00af7cf99d9 100644 +index 1d75ad42bfe9324baafb5d60e2fd44ece660a5cd..6a59b3b98c99e5b1d8a2d4f5970fc782bdd0b29c 100644 --- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java +++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java -@@ -495,7 +495,7 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon +@@ -489,7 +489,7 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon gameprofilerfiller.popPush("shuffleChunks"); // Paper start - chunk tick iteration optimisation this.shuffleRandom.setSeed(this.level.random.nextLong()); @@ -49,7 +49,7 @@ index 07dde7dbf4d9e1d2f61426e3f1dc3cd5be55f193..12f49deea35ecbaea08869332982c00a // Paper end - chunk tick iteration optimisation this.tickChunks(gameprofilerfiller, j, list); gameprofilerfiller.pop(); -@@ -552,7 +552,19 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon +@@ -546,7 +546,19 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon private void tickChunks(ProfilerFiller profiler, long timeDelta, List chunks) { profiler.popPush("naturalSpawnCount"); int j = this.distanceManager.getNaturalSpawnChunkCount(); diff --git a/patches/server/1054-Improve-cancelling-PreCreatureSpawnEvent-with-per-pl.patch b/patches/server/1054-Improve-cancelling-PreCreatureSpawnEvent-with-per-pl.patch index 0bc36284cc..37d533211b 100644 --- a/patches/server/1054-Improve-cancelling-PreCreatureSpawnEvent-with-per-pl.patch +++ b/patches/server/1054-Improve-cancelling-PreCreatureSpawnEvent-with-per-pl.patch @@ -37,10 +37,10 @@ index 4896c3ba81ead769972fa9efdbe563d4006e4401..5b3a886c624b36557cbfaccdc3fb05a4 } // Paper end diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java -index 12f49deea35ecbaea08869332982c00af7cf99d9..3c711e1df57ac5b0f8795ebb12299d275792b1d4 100644 +index 6a59b3b98c99e5b1d8a2d4f5970fc782bdd0b29c..381b2535d598094990af532b72b15eadc13208ad 100644 --- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java +++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java -@@ -558,7 +558,17 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon +@@ -552,7 +552,17 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon if ((this.spawnFriendlies || this.spawnEnemies) && this.level.paperConfig().entities.spawning.perPlayerMobSpawns) { // don't count mobs when animals and monsters are disabled // re-set mob counts for (ServerPlayer player : this.level.players) {