From 841c7d1879d395443ef6056fd8cdd97ad30ff86a Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Wed, 6 May 2020 07:57:18 -0700 Subject: [PATCH] Make loaded entity list logic more consistent (#3301) When adding/removing to a chunk, we need to also look at editing the loaded entity list. Co-authored-by: Spottedleaf --- ...list-iteration-requiring-entities-be.patch | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/Spigot-Server-Patches/0502-Optimize-entity-list-iteration-requiring-entities-be.patch b/Spigot-Server-Patches/0502-Optimize-entity-list-iteration-requiring-entities-be.patch index 8456425e6..75731a78e 100644 --- a/Spigot-Server-Patches/0502-Optimize-entity-list-iteration-requiring-entities-be.patch +++ b/Spigot-Server-Patches/0502-Optimize-entity-list-iteration-requiring-entities-be.patch @@ -7,10 +7,34 @@ Subject: [PATCH] Optimize entity list iteration requiring entities be in We retain a list of loaded entities specifically for this usage diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java -index 750fb07756f7e40b21f8ab0925f2e842aae50f7b..69bfece7d43bc9e0c4cf7f71bffec9a44c2b9a67 100644 +index 750fb07756f7e40b21f8ab0925f2e842aae50f7b..21918ab101b423eadff5c00530f7a7c8e40cde9a 100644 --- a/src/main/java/net/minecraft/server/Chunk.java +++ b/src/main/java/net/minecraft/server/Chunk.java -@@ -801,6 +801,7 @@ public class Chunk implements IChunkAccess { +@@ -588,6 +588,13 @@ public class Chunk implements IChunkAccess { + entity.chunkZ = this.loc.z; + this.entities.add(entity); // Paper - per chunk entity list + this.entitySlices[k].add(entity); if (entity.hardCollides()) this.hardCollidingEntities[k].add(entity); // Paper - optimise hard colliding entities ++ // Paper start - world loaded entity list ++ if (this.loadedTicketLevel) { ++ ((WorldServer)this.world).loadedEntities.add(entity); ++ } else { ++ ((WorldServer)this.world).loadedEntities.remove(entity); ++ } ++ // Paper end - world loaded entity list + // Paper start + if (entity instanceof EntityItem) { + itemCounts[k]++; +@@ -627,6 +634,9 @@ public class Chunk implements IChunkAccess { + if (entity.hardCollides()) this.hardCollidingEntities[i].remove(entity); if (!this.entitySlices[i].remove(entity)) { // Paper - optimise hard colliding entities + return; + } ++ // Paper start - world loaded entity list ++ ((WorldServer)this.world).loadedEntities.remove(entity); ++ // Paper end - world loaded entity list + if (entity instanceof EntityItem) { + itemCounts[i]--; + } else if (entity instanceof IInventory) { +@@ -801,6 +811,7 @@ public class Chunk implements IChunkAccess { this.setNeighbourLoaded(0, 0, this); this.loadedTicketLevel = true; // Paper end - neighbour cache @@ -18,7 +42,7 @@ index 750fb07756f7e40b21f8ab0925f2e842aae50f7b..69bfece7d43bc9e0c4cf7f71bffec9a4 org.bukkit.Server server = this.world.getServer(); ((WorldServer)this.world).getChunkProvider().addLoadedChunk(this); // Paper if (server != null) { -@@ -859,6 +860,7 @@ public class Chunk implements IChunkAccess { +@@ -859,6 +870,7 @@ public class Chunk implements IChunkAccess { this.loadedTicketLevel = false; this.resetNeighbours(); // Paper end