mirror of
https://github.com/PaperMC/Paper.git
synced 2024-08-22 12:22:54 +02:00
59 lines
2.3 KiB
Diff
59 lines
2.3 KiB
Diff
From cfcc186292e5c96e42aa2588663c3e9ff49c0e34 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 7837f1024c..24a2ec4b4a 100644
|
|
--- a/src/main/java/net/minecraft/server/Chunk.java
|
|
+++ b/src/main/java/net/minecraft/server/Chunk.java
|
|
@@ -64,15 +64,19 @@ public class Chunk implements IChunkAccess {
|
|
private int neighbors = 0x1 << 12;
|
|
public long chunkKey;
|
|
// 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.getMinecraftKeyString());
|
|
}
|
|
if (value != null) {
|
|
value.setCurrentChunk(Chunk.this);
|
|
+ tileEntityCounts.increment(value.getMinecraftKeyString());
|
|
}
|
|
return replaced;
|
|
}
|
|
@@ -82,6 +86,7 @@ public class Chunk implements IChunkAccess {
|
|
TileEntity removed = super.remove(key);
|
|
if (removed != null) {
|
|
removed.setCurrentChunk(null);
|
|
+ tileEntityCounts.decrement(removed.getMinecraftKeyString());
|
|
}
|
|
return removed;
|
|
}
|
|
@@ -671,6 +676,7 @@ public class Chunk implements IChunkAccess {
|
|
this.entitySlices[k].add(entity);
|
|
// Paper start
|
|
entity.setCurrentChunk(this);
|
|
+ entityCounts.increment(entity.getMinecraftKeyString());
|
|
// Paper end
|
|
}
|
|
|
|
@@ -695,6 +701,7 @@ public class Chunk implements IChunkAccess {
|
|
return;
|
|
}
|
|
entity.setCurrentChunk(null);
|
|
+ entityCounts.decrement(entity.getMinecraftKeyString());
|
|
// Paper end
|
|
}
|
|
|
|
--
|
|
2.18.0
|
|
|