2020-05-06 11:48:49 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2018-07-04 09:55:24 +02:00
|
|
|
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
|
2020-05-06 11:48:49 +02:00
|
|
|
index 4d7dc714748a82470d00e787eeb3dc7ca08c656a..a144f4ef5658359715ba493e6363c7e887d812d3 100644
|
2018-07-04 09:55:24 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/Chunk.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Chunk.java
|
2019-05-26 03:56:30 +02:00
|
|
|
@@ -56,15 +56,19 @@ public class Chunk implements IChunkAccess {
|
2019-05-14 04:20:58 +02:00
|
|
|
}
|
|
|
|
|
2018-07-04 09:55:24 +02:00
|
|
|
// 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);
|
2018-07-27 05:57:31 +02:00
|
|
|
+ tileEntityCounts.decrement(replaced.getMinecraftKeyString());
|
2018-07-04 09:55:24 +02:00
|
|
|
}
|
|
|
|
if (value != null) {
|
|
|
|
value.setCurrentChunk(Chunk.this);
|
2018-07-27 05:57:31 +02:00
|
|
|
+ tileEntityCounts.increment(value.getMinecraftKeyString());
|
2018-07-04 09:55:24 +02:00
|
|
|
}
|
|
|
|
return replaced;
|
|
|
|
}
|
2019-05-26 03:56:30 +02:00
|
|
|
@@ -74,6 +78,7 @@ public class Chunk implements IChunkAccess {
|
2018-07-04 09:55:24 +02:00
|
|
|
TileEntity removed = super.remove(key);
|
|
|
|
if (removed != null) {
|
|
|
|
removed.setCurrentChunk(null);
|
2018-07-27 05:57:31 +02:00
|
|
|
+ tileEntityCounts.decrement(removed.getMinecraftKeyString());
|
2018-07-04 09:55:24 +02:00
|
|
|
}
|
|
|
|
return removed;
|
|
|
|
}
|
2020-05-06 09:44:47 +02:00
|
|
|
@@ -486,6 +491,7 @@ public class Chunk implements IChunkAccess {
|
2019-04-06 05:08:45 +02:00
|
|
|
k = this.entitySlices.length - 1;
|
|
|
|
}
|
2018-07-15 03:53:17 +02:00
|
|
|
|
2019-04-06 05:08:45 +02:00
|
|
|
+ if (!entity.inChunk || entity.getCurrentChunk() != this) entityCounts.increment(entity.getMinecraftKeyString()); // Paper
|
|
|
|
entity.inChunk = true;
|
|
|
|
entity.setCurrentChunk(this); // Paper
|
2019-04-24 03:00:24 +02:00
|
|
|
entity.chunkX = this.loc.x;
|
2020-05-06 09:44:47 +02:00
|
|
|
@@ -519,6 +525,7 @@ public class Chunk implements IChunkAccess {
|
2019-04-06 05:08:45 +02:00
|
|
|
if (!this.entitySlices[i].remove(entity)) {
|
2018-07-15 03:53:17 +02:00
|
|
|
return;
|
2018-07-04 09:55:24 +02:00
|
|
|
}
|
2018-07-27 05:57:31 +02:00
|
|
|
+ entityCounts.decrement(entity.getMinecraftKeyString());
|
2018-07-04 09:55:24 +02:00
|
|
|
// Paper end
|
2020-01-31 17:09:56 +01:00
|
|
|
this.entities.remove(entity); // Paper
|
2018-07-04 09:55:24 +02:00
|
|
|
}
|