From 9a22d2fdec74bc6f7c259fb4c7f05daa14ee9190 Mon Sep 17 00:00:00 2001 From: Aikar Date: Sun, 15 Jul 2018 02:44:37 -0400 Subject: [PATCH] Fix placement of chunk tracking - Fixes #1199 Spigot had code that returned early in chunk add/remove methods. This was causing our code added to set current chunks and counts to be skipped over if the entity was default not persistent but made persistent. This was the source of many issues Fixes #1208 --- .../Add-exception-reporting-event.patch | 2 +- .../Auto-Save-Improvements.patch | 2 +- ...ups-for-Entity-TileEntity-Current-Ch.patch | 2 +- ...opper-searches-if-there-are-no-items.patch | 22 +++++++---------- .../Configurable-Chunk-Inhabited-Timer.patch | 2 +- ...hunks-as-active-for-neighbor-updates.patch | 2 +- ...nd-unlit-chunks-when-lighting-update.patch | 2 +- ...Fix-Bugs-with-Spigot-Mob-Spawn-Logic.patch | 9 +++---- .../InventoryCloseEvent-Reason-API.patch | 2 +- ...tion-to-remove-corrupt-tile-entities.patch | 2 +- ...ts-for-each-Entity-Block-Entity-Type.patch | 14 +++++------ ...to-current-Chunk-for-Entity-and-Bloc.patch | 24 +++++++++---------- 12 files changed, 41 insertions(+), 44 deletions(-) diff --git a/Spigot-Server-Patches/Add-exception-reporting-event.patch b/Spigot-Server-Patches/Add-exception-reporting-event.patch index 53e5fb468b..f1cd610ae7 100644 --- a/Spigot-Server-Patches/Add-exception-reporting-event.patch +++ b/Spigot-Server-Patches/Add-exception-reporting-event.patch @@ -50,7 +50,7 @@ index 000000000..93397188b +} \ No newline at end of file diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java -index a5db14343..0788f7712 100644 +index 08d6ef09a..d5ef4ed0e 100644 --- a/src/main/java/net/minecraft/server/Chunk.java +++ b/src/main/java/net/minecraft/server/Chunk.java @@ -0,0 +0,0 @@ diff --git a/Spigot-Server-Patches/Auto-Save-Improvements.patch b/Spigot-Server-Patches/Auto-Save-Improvements.patch index 6ba8afc123..98d438ae7e 100644 --- a/Spigot-Server-Patches/Auto-Save-Improvements.patch +++ b/Spigot-Server-Patches/Auto-Save-Improvements.patch @@ -64,7 +64,7 @@ index 1b9eb7f45..ce848d63e 100644 + } } diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java -index cc9c8b2e0..a59f5b190 100644 +index 62767a383..798522fa7 100644 --- a/src/main/java/net/minecraft/server/Chunk.java +++ b/src/main/java/net/minecraft/server/Chunk.java @@ -0,0 +0,0 @@ public class Chunk { diff --git a/Spigot-Server-Patches/Avoid-Chunk-Lookups-for-Entity-TileEntity-Current-Ch.patch b/Spigot-Server-Patches/Avoid-Chunk-Lookups-for-Entity-TileEntity-Current-Ch.patch index f19c72debb..1f82c2e531 100644 --- a/Spigot-Server-Patches/Avoid-Chunk-Lookups-for-Entity-TileEntity-Current-Ch.patch +++ b/Spigot-Server-Patches/Avoid-Chunk-Lookups-for-Entity-TileEntity-Current-Ch.patch @@ -10,7 +10,7 @@ to the object directly on the Entity/TileEntity object we can directly grab. Use that local value instead to reduce lookups in many hot places. diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java -index 3e80825f7..4a94fd5a6 100644 +index 81bf60efa..04adf4e3c 100644 --- a/src/main/java/net/minecraft/server/Chunk.java +++ b/src/main/java/net/minecraft/server/Chunk.java @@ -0,0 +0,0 @@ public class Chunk { diff --git a/Spigot-Server-Patches/Avoid-hopper-searches-if-there-are-no-items.patch b/Spigot-Server-Patches/Avoid-hopper-searches-if-there-are-no-items.patch index 230190f119..013d2b3811 100644 --- a/Spigot-Server-Patches/Avoid-hopper-searches-if-there-are-no-items.patch +++ b/Spigot-Server-Patches/Avoid-hopper-searches-if-there-are-no-items.patch @@ -14,7 +14,7 @@ And since minecart hoppers are used _very_ rarely near we can avoid alot of sear Combined, this adds up a lot. diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java -index aaf253c89..a5db14343 100644 +index d6f6cfef2..08d6ef09a 100644 --- a/src/main/java/net/minecraft/server/Chunk.java +++ b/src/main/java/net/minecraft/server/Chunk.java @@ -0,0 +0,0 @@ public class Chunk { @@ -32,33 +32,29 @@ index aaf253c89..a5db14343 100644 private int neighbors = 0x1 << 12; public long chunkKey; @@ -0,0 +0,0 @@ public class Chunk { - entity.ac = k; - entity.ad = this.locZ; - this.entitySlices[k].add(entity); -+ // Paper start - update count + // Paper start + entity.setCurrentChunk(this); + entityCounts.increment(entity.entityKeyString); + if (entity instanceof EntityItem) { + itemCounts[k]++; + } else if (entity instanceof IInventory) { + inventoryEntityCounts[k]++; + } -+ // Paper end + // Paper end // Spigot start - increment creature type count // Keep this synced up with World.a(Class) - if (entity instanceof EntityInsentient) { @@ -0,0 +0,0 @@ public class Chunk { - } - - this.entitySlices[i].remove(entity); -+ // Paper start - update counts + // Paper start + entity.setCurrentChunk(null); + entityCounts.decrement(entity.entityKeyString); + if (entity instanceof EntityItem) { + itemCounts[i]--; + } else if (entity instanceof IInventory) { + inventoryEntityCounts[i]--; + } -+ // Paper end + // Paper end // Spigot start - decrement creature type count // Keep this synced up with World.a(Class) - if (entity instanceof EntityInsentient) { @@ -0,0 +0,0 @@ public class Chunk { if (!this.entitySlices[k].isEmpty()) { Iterator iterator = this.entitySlices[k].iterator(); diff --git a/Spigot-Server-Patches/Configurable-Chunk-Inhabited-Timer.patch b/Spigot-Server-Patches/Configurable-Chunk-Inhabited-Timer.patch index 68655267d6..0ecfe78296 100644 --- a/Spigot-Server-Patches/Configurable-Chunk-Inhabited-Timer.patch +++ b/Spigot-Server-Patches/Configurable-Chunk-Inhabited-Timer.patch @@ -23,7 +23,7 @@ index e634c3afd..54f23ea75 100644 + } } diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java -index bf3b64e37..6b13e1d7d 100644 +index d84cc9843..da7b59434 100644 --- a/src/main/java/net/minecraft/server/Chunk.java +++ b/src/main/java/net/minecraft/server/Chunk.java @@ -0,0 +0,0 @@ public class Chunk { diff --git a/Spigot-Server-Patches/Do-not-mark-chunks-as-active-for-neighbor-updates.patch b/Spigot-Server-Patches/Do-not-mark-chunks-as-active-for-neighbor-updates.patch index 44f74c1daa..f3e046dd8d 100644 --- a/Spigot-Server-Patches/Do-not-mark-chunks-as-active-for-neighbor-updates.patch +++ b/Spigot-Server-Patches/Do-not-mark-chunks-as-active-for-neighbor-updates.patch @@ -6,7 +6,7 @@ Subject: [PATCH] Do not mark chunks as active for neighbor updates Fixes chunk unload issues diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java -index 1e78fc625..ba3ee64f8 100644 +index 1157bc7eb..f3f4b7fe5 100644 --- a/src/main/java/net/minecraft/server/Chunk.java +++ b/src/main/java/net/minecraft/server/Chunk.java @@ -0,0 +0,0 @@ public class Chunk { diff --git a/Spigot-Server-Patches/Don-t-blindly-send-unlit-chunks-when-lighting-update.patch b/Spigot-Server-Patches/Don-t-blindly-send-unlit-chunks-when-lighting-update.patch index 0286de617e..2e3f664171 100644 --- a/Spigot-Server-Patches/Don-t-blindly-send-unlit-chunks-when-lighting-update.patch +++ b/Spigot-Server-Patches/Don-t-blindly-send-unlit-chunks-when-lighting-update.patch @@ -18,7 +18,7 @@ only send chunks which are actually ready to be sent, otherwise, we will always send chunks. diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java -index cb33cf902..87d0d426f 100644 +index 9c88effef..51e7a4ad8 100644 --- a/src/main/java/net/minecraft/server/Chunk.java +++ b/src/main/java/net/minecraft/server/Chunk.java @@ -0,0 +0,0 @@ public class Chunk { diff --git a/Spigot-Server-Patches/Fix-Bugs-with-Spigot-Mob-Spawn-Logic.patch b/Spigot-Server-Patches/Fix-Bugs-with-Spigot-Mob-Spawn-Logic.patch index 9d9ef2747b..451d8c0d2f 100644 --- a/Spigot-Server-Patches/Fix-Bugs-with-Spigot-Mob-Spawn-Logic.patch +++ b/Spigot-Server-Patches/Fix-Bugs-with-Spigot-Mob-Spawn-Logic.patch @@ -14,7 +14,7 @@ Specially with servers using smaller mob spawn ranges than view distance, as wel This patch returns mob counting to use all loaded chunks, and 17x17 division. diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java -index e07ef14ed..aca1457b0 100644 +index da7b59434..1157bc7eb 100644 --- a/src/main/java/net/minecraft/server/Chunk.java +++ b/src/main/java/net/minecraft/server/Chunk.java @@ -0,0 +0,0 @@ public class Chunk { @@ -22,10 +22,11 @@ index e07ef14ed..aca1457b0 100644 } - this.entitySlices[i].remove(entity); -+ if (!this.entitySlices[i].remove(entity)) { return; } // Paper - // Paper start - update counts + // Paper start ++ if (!this.entitySlices[i].remove(entity)) { return; } + entity.setCurrentChunk(null); + entityCounts.decrement(entity.entityKeyString); if (entity instanceof EntityItem) { - itemCounts[i]--; diff --git a/src/main/java/net/minecraft/server/SpawnerCreature.java b/src/main/java/net/minecraft/server/SpawnerCreature.java index 45a83ae99..ed22607d9 100644 --- a/src/main/java/net/minecraft/server/SpawnerCreature.java diff --git a/Spigot-Server-Patches/InventoryCloseEvent-Reason-API.patch b/Spigot-Server-Patches/InventoryCloseEvent-Reason-API.patch index 4be14de8b1..cfa910f080 100644 --- a/Spigot-Server-Patches/InventoryCloseEvent-Reason-API.patch +++ b/Spigot-Server-Patches/InventoryCloseEvent-Reason-API.patch @@ -7,7 +7,7 @@ Allows you to determine why an inventory was closed, enabling plugin developers to "confirm" things based on if it was player triggered close or not. diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java -index 8c96e7318..3e80825f7 100644 +index 51e7a4ad8..81bf60efa 100644 --- a/src/main/java/net/minecraft/server/Chunk.java +++ b/src/main/java/net/minecraft/server/Chunk.java @@ -0,0 +0,0 @@ public class Chunk { diff --git a/Spigot-Server-Patches/Option-to-remove-corrupt-tile-entities.patch b/Spigot-Server-Patches/Option-to-remove-corrupt-tile-entities.patch index 3ad36abab4..3e0c86c37f 100644 --- a/Spigot-Server-Patches/Option-to-remove-corrupt-tile-entities.patch +++ b/Spigot-Server-Patches/Option-to-remove-corrupt-tile-entities.patch @@ -19,7 +19,7 @@ index ce848d63e..93b0af036 100644 + } } diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java -index a59f5b190..27a36b2b0 100644 +index 798522fa7..ee6c6af94 100644 --- a/src/main/java/net/minecraft/server/Chunk.java +++ b/src/main/java/net/minecraft/server/Chunk.java @@ -0,0 +0,0 @@ public class Chunk { diff --git a/Spigot-Server-Patches/Store-counts-for-each-Entity-Block-Entity-Type.patch b/Spigot-Server-Patches/Store-counts-for-each-Entity-Block-Entity-Type.patch index 49aca99605..29e4e1bea3 100644 --- a/Spigot-Server-Patches/Store-counts-for-each-Entity-Block-Entity-Type.patch +++ b/Spigot-Server-Patches/Store-counts-for-each-Entity-Block-Entity-Type.patch @@ -6,7 +6,7 @@ Subject: [PATCH] Store counts for each Entity/Block Entity Type Opens door for future patches to optimize performance diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java -index b40e60942..952c96c0c 100644 +index ea167a17b..77fdb3c4a 100644 --- a/src/main/java/net/minecraft/server/Chunk.java +++ b/src/main/java/net/minecraft/server/Chunk.java @@ -0,0 +0,0 @@ public class Chunk { @@ -38,19 +38,19 @@ index b40e60942..952c96c0c 100644 return removed; } @@ -0,0 +0,0 @@ public class Chunk { - } + this.entitySlices[k].add(entity); // Paper start entity.setCurrentChunk(this); + entityCounts.increment(entity.entityKeyString); // Paper end - // Spigot end - } + // Spigot start - increment creature type count + // Keep this synced up with World.a(Class) @@ -0,0 +0,0 @@ public class Chunk { - } + this.entitySlices[i].remove(entity); // Paper start entity.setCurrentChunk(null); + entityCounts.decrement(entity.entityKeyString); // Paper end - // Spigot end - } + // Spigot start - decrement creature type count + // Keep this synced up with World.a(Class) -- \ No newline at end of file diff --git a/Spigot-Server-Patches/Store-reference-to-current-Chunk-for-Entity-and-Bloc.patch b/Spigot-Server-Patches/Store-reference-to-current-Chunk-for-Entity-and-Bloc.patch index 1e1cd29c03..e2f83fe2b3 100644 --- a/Spigot-Server-Patches/Store-reference-to-current-Chunk-for-Entity-and-Bloc.patch +++ b/Spigot-Server-Patches/Store-reference-to-current-Chunk-for-Entity-and-Bloc.patch @@ -8,7 +8,7 @@ This enables us a fast reference to the entities current chunk instead of having to look it up by hashmap lookups. diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java -index 4bbebb25a..68008fe6a 100644 +index 4bbebb25a..ea167a17b 100644 --- a/src/main/java/net/minecraft/server/Chunk.java +++ b/src/main/java/net/minecraft/server/Chunk.java @@ -0,0 +0,0 @@ public class Chunk { @@ -61,25 +61,25 @@ index 4bbebb25a..68008fe6a 100644 this.y = Queues.newConcurrentLinkedQueue(); this.entitySlices = (List[]) (new List[16]); // Spigot @@ -0,0 +0,0 @@ public class Chunk { - this.entityCount.adjustOrPutValue( creatureType.a(), 1, 1 ); - } - } + entity.ac = k; + entity.ad = this.locZ; + this.entitySlices[k].add(entity); + // Paper start + entity.setCurrentChunk(this); + // Paper end - // Spigot end - } - + // Spigot start - increment creature type count + // Keep this synced up with World.a(Class) + if (entity instanceof EntityInsentient) { @@ -0,0 +0,0 @@ public class Chunk { - this.entityCount.adjustValue( creatureType.a(), -1 ); - } } + + this.entitySlices[i].remove(entity); + // Paper start + entity.setCurrentChunk(null); + // Paper end - // Spigot end - } - + // Spigot start - decrement creature type count + // Keep this synced up with World.a(Class) + if (entity instanceof EntityInsentient) { diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java index 3a8902bf1..4af566b36 100644 --- a/src/main/java/net/minecraft/server/Entity.java