mirror of
https://github.com/PaperMC/Paper.git
synced 2024-08-23 04:53:42 +02:00
59 lines
2.3 KiB
Diff
59 lines
2.3 KiB
Diff
From 097b3586b9c38d4afc2e8cf3ae9b0ecb16e5df7c 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 238139c73..eb0411ec8 100644
|
|
--- a/src/main/java/net/minecraft/server/Chunk.java
|
|
+++ b/src/main/java/net/minecraft/server/Chunk.java
|
|
@@ -63,15 +63,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;
|
|
}
|
|
@@ -81,6 +85,7 @@ public class Chunk implements IChunkAccess {
|
|
TileEntity removed = super.remove(key);
|
|
if (removed != null) {
|
|
removed.setCurrentChunk(null);
|
|
+ tileEntityCounts.decrement(removed.getMinecraftKeyString());
|
|
}
|
|
return removed;
|
|
}
|
|
@@ -677,6 +682,7 @@ public class Chunk implements IChunkAccess {
|
|
this.entitySlices[k].add(entity);
|
|
// Paper start
|
|
entity.setCurrentChunk(this);
|
|
+ entityCounts.increment(entity.getMinecraftKeyString());
|
|
// Paper end
|
|
}
|
|
|
|
@@ -701,6 +707,7 @@ public class Chunk implements IChunkAccess {
|
|
return;
|
|
}
|
|
entity.setCurrentChunk(null);
|
|
+ entityCounts.decrement(entity.getMinecraftKeyString());
|
|
// Paper end
|
|
}
|
|
|
|
--
|
|
2.18.0
|
|
|