5d8b3d4969
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
59 lines
2.4 KiB
Diff
59 lines
2.4 KiB
Diff
From 20c6d16a7db36e57bde2a9bac4e5bb99d606239a Mon Sep 17 00:00:00 2001
|
|
From: Aikar <aikar@aikar.co>
|
|
Date: Wed, 4 Jul 2018 02:13:59 -0400
|
|
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 ea167a17b..77fdb3c4a 100644
|
|
--- a/src/main/java/net/minecraft/server/Chunk.java
|
|
+++ b/src/main/java/net/minecraft/server/Chunk.java
|
|
@@ -34,15 +34,19 @@ public class Chunk {
|
|
public final Map<BlockPosition, TileEntity> tileEntities;
|
|
public final List<Entity>[] entitySlices; // Spigot
|
|
// Paper start
|
|
+ public final co.aikar.util.Counter<String> entityCounts = new co.aikar.util.Counter<>();
|
|
+ public final co.aikar.util.Counter<String> tileEntityCounts = new co.aikar.util.Counter<>();
|
|
private class TileEntityHashMap extends java.util.HashMap<BlockPosition, TileEntity> {
|
|
@Override
|
|
public TileEntity put(BlockPosition key, TileEntity value) {
|
|
TileEntity replaced = super.put(key, value);
|
|
if (replaced != null) {
|
|
replaced.setCurrentChunk(null);
|
|
+ tileEntityCounts.decrement(replaced.tileEntityKeyString);
|
|
}
|
|
if (value != null) {
|
|
value.setCurrentChunk(Chunk.this);
|
|
+ tileEntityCounts.increment(value.tileEntityKeyString);
|
|
}
|
|
return replaced;
|
|
}
|
|
@@ -52,6 +56,7 @@ public class Chunk {
|
|
TileEntity removed = super.remove(key);
|
|
if (removed != null) {
|
|
removed.setCurrentChunk(null);
|
|
+ tileEntityCounts.decrement(removed.tileEntityKeyString);
|
|
}
|
|
return removed;
|
|
}
|
|
@@ -635,6 +640,7 @@ public class Chunk {
|
|
this.entitySlices[k].add(entity);
|
|
// Paper start
|
|
entity.setCurrentChunk(this);
|
|
+ entityCounts.increment(entity.entityKeyString);
|
|
// Paper end
|
|
// Spigot start - increment creature type count
|
|
// Keep this synced up with World.a(Class)
|
|
@@ -670,6 +676,7 @@ public class Chunk {
|
|
this.entitySlices[i].remove(entity);
|
|
// Paper start
|
|
entity.setCurrentChunk(null);
|
|
+ entityCounts.decrement(entity.entityKeyString);
|
|
// Paper end
|
|
// Spigot start - decrement creature type count
|
|
// Keep this synced up with World.a(Class)
|
|
--
|
|
2.18.0
|
|
|