2019-01-01 04:15:55 +01:00
|
|
|
From fcea42cc3d3d4bc1e4ade7725e589b16b6a018e3 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
|
2019-01-01 04:15:55 +01:00
|
|
|
index b728a44f5..23dee9b56 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-01-01 04:15:55 +01:00
|
|
|
@@ -67,15 +67,19 @@ public class Chunk implements IChunkAccess {
|
2018-07-15 03:53:17 +02:00
|
|
|
private int neighbors = 0x1 << 12;
|
|
|
|
public long chunkKey;
|
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-01-01 04:15:55 +01:00
|
|
|
@@ -85,6 +89,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;
|
|
|
|
}
|
2019-01-01 04:15:55 +01:00
|
|
|
@@ -682,6 +687,7 @@ public class Chunk implements IChunkAccess {
|
2018-07-15 03:53:17 +02:00
|
|
|
this.entitySlices[k].add(entity);
|
2018-07-04 09:55:24 +02:00
|
|
|
// Paper start
|
|
|
|
entity.setCurrentChunk(this);
|
2018-07-27 05:57:31 +02:00
|
|
|
+ entityCounts.increment(entity.getMinecraftKeyString());
|
2018-07-04 09:55:24 +02:00
|
|
|
// Paper end
|
|
|
|
}
|
2018-07-15 03:53:17 +02:00
|
|
|
|
2019-01-01 04:15:55 +01:00
|
|
|
@@ -706,6 +712,7 @@ public class Chunk implements IChunkAccess {
|
2018-07-15 03:53:17 +02:00
|
|
|
return;
|
2018-07-04 09:55:24 +02:00
|
|
|
}
|
|
|
|
entity.setCurrentChunk(null);
|
2018-07-27 05:57:31 +02:00
|
|
|
+ entityCounts.decrement(entity.getMinecraftKeyString());
|
2018-07-04 09:55:24 +02:00
|
|
|
// Paper end
|
|
|
|
}
|
2018-07-15 03:53:17 +02:00
|
|
|
|
2018-07-04 09:55:24 +02:00
|
|
|
--
|
2019-01-01 04:15:55 +01:00
|
|
|
2.20.1
|
2018-07-04 09:55:24 +02:00
|
|
|
|