mirror of
https://github.com/PaperMC/Paper.git
synced 2025-02-09 09:01:36 +01:00
Ensure we actually removed entity from chunk before decrementing counts
If a plugin hacks into NMS and triggers entity removal, it could result in an entity being attempted to remove from the chunk twice. The 2nd pass will return false, as it did not find the entity in the list. We should not touch entity counts if the entity was not removed, to avoid going negative.
This commit is contained in:
parent
d42782457e
commit
75eb8243f7
@ -13,6 +13,19 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 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 {
|
||||
i = this.entitySlices.length - 1;
|
||||
}
|
||||
|
||||
- this.entitySlices[i].remove(entity);
|
||||
+ if (!this.entitySlices[i].remove(entity)) { return; } // Paper
|
||||
// Paper start - update counts
|
||||
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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/server/SpawnerCreature.java
|
||||
|
@ -120,6 +120,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ return new Location(entity.getWorld().getWorld(), entity.locX, entity.locY, entity.locZ);
|
||||
+ }
|
||||
+
|
||||
+ public static BlockPosition toBlockPosition(Location loc) {
|
||||
+ return new BlockPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||
+ }
|
||||
+
|
||||
+ public static boolean isEdgeOfChunk(BlockPosition pos) {
|
||||
+ final int modX = pos.getX() & 15;
|
||||
+ final int modZ = pos.getZ() & 15;
|
||||
|
Loading…
Reference in New Issue
Block a user