From 985e42705e5fefeda2ba2c644f82ed1fc3000bb6 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke <nassim@njahnke.dev> Date: Wed, 21 Jul 2021 19:12:24 +0200 Subject: [PATCH] Fix PaperTickList (#6241) Co-authored-by: Jason Penilla <11360596+jpenilla@users.noreply.github.com> --- build-data/paper.at | 1 + ...imise-TickListServer-by-rewriting-it.patch | 34 ++++++++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/build-data/paper.at b/build-data/paper.at index be711a45c6..66e6e8c5ed 100644 --- a/build-data/paper.at +++ b/build-data/paper.at @@ -113,6 +113,7 @@ public net.minecraft.server.level.ChunkMap mainThreadMailbox # todo one of these # Optimise TickListServer public net.minecraft.world.level.ServerTickList saveTickList(Ljava/util/function/Function;Ljava/lang/Iterable;J)Lnet/minecraft/nbt/ListTag; +public net.minecraft.world.level.chunk.storage.EntityStorage level # Don't move existing players to world spawn public net.minecraft.server.level.ServerPlayer fudgeSpawnLocation(Lnet/minecraft/server/level/ServerLevel;)V diff --git a/patches/server/Optimise-TickListServer-by-rewriting-it.patch b/patches/server/Optimise-TickListServer-by-rewriting-it.patch index cf481abdc6..14e381dacb 100644 --- a/patches/server/Optimise-TickListServer-by-rewriting-it.patch +++ b/patches/server/Optimise-TickListServer-by-rewriting-it.patch @@ -918,7 +918,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 ChunkHolder.this.isTickingReady = true; + + // Paper start - rewrite ticklistserver -+ ChunkHolder.this.chunkMap.level.onChunkSetTicking(ChunkHolder.this.pos.x, ChunkHolder.this.pos.z); ++ if (ChunkHolder.this.chunkMap.level.entityManager.areEntitiesLoaded(this.pos.longKey)) { ++ ChunkHolder.this.chunkMap.level.onChunkSetTicking(ChunkHolder.this.pos.x, ChunkHolder.this.pos.z); ++ } + // Paper end - rewrite ticklistserver }); }); @@ -932,10 +934,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 } // Paper end + // Paper start - rewrite ticklistserver ++ public final boolean isPositionTickingReady(long pos) { ++ final ChunkHolder chunkHolder = this.chunkMap.getUpdatingChunkIfPresent(pos); ++ return chunkHolder != null && chunkHolder.isTickingReady(); ++ } ++ + public final boolean isPositionTickingWithEntitiesLoaded(BlockPos pos) { -+ long position = net.minecraft.server.MCUtil.getCoordinateKey(pos); -+ ChunkHolder chunkHolder = this.chunkMap.getUpdatingChunkIfPresent(position); -+ return chunkHolder != null && chunkHolder.isTickingReady() /* && this.level.entityManager.areEntitiesLoaded(position) */; // TODO Needs to wait for entities, but has to be manually marked as ready ++ final long position = net.minecraft.server.MCUtil.getCoordinateKey(pos); ++ final ChunkHolder chunkHolder = this.chunkMap.getUpdatingChunkIfPresent(position); ++ return chunkHolder != null && chunkHolder.isTickingReady() && this.level.entityManager.areEntitiesLoaded(position); + } + // Paper end - rewrite ticklistserver @@ -950,7 +957,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 // Paper end + // Paper start - rewrite ticklistserver -+ void onChunkSetTicking(int chunkX, int chunkZ) { ++ public void onChunkSetTicking(int chunkX, int chunkZ) { + if (com.destroystokyo.paper.PaperConfig.useOptimizedTickList) { + ((com.destroystokyo.paper.server.ticklist.PaperTickList) this.blockTicks).onChunkSetTicking(chunkX, chunkZ); + ((com.destroystokyo.paper.server.ticklist.PaperTickList) this.liquidTicks).onChunkSetTicking(chunkX, chunkZ); @@ -1111,3 +1118,20 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 } @Override +diff --git a/src/main/java/net/minecraft/world/level/entity/PersistentEntitySectionManager.java b/src/main/java/net/minecraft/world/level/entity/PersistentEntitySectionManager.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/world/level/entity/PersistentEntitySectionManager.java ++++ b/src/main/java/net/minecraft/world/level/entity/PersistentEntitySectionManager.java +@@ -0,0 +0,0 @@ public class PersistentEntitySectionManager<T extends EntityAccess> implements A + this.addEntity(entity, true); + }); + this.chunkLoadStatuses.put(chunkEntities.getPos().toLong(), PersistentEntitySectionManager.ChunkLoadStatus.LOADED); ++ // Paper start - rewrite ServerTickList ++ final net.minecraft.server.level.ServerLevel level = ((net.minecraft.world.level.chunk.storage.EntityStorage) this.permanentStorage).level; ++ if (level.chunkSource.isPositionTickingReady(chunkEntities.getPos().longKey)) { ++ level.onChunkSetTicking(chunkEntities.getPos().x, chunkEntities.getPos().z); ++ } ++ // Paper end + } + + }