Paper/Spigot-Server-Patches/0008-Store-counts-for-each-Entity-Block-Entity-Type.patch
Aikar 4dd6ddb86b
Re-add block inlining - Closes #1229
Also reordered MC Utils to be higher up
2018-07-22 18:46:13 -04:00

59 lines
2.2 KiB
Diff

From 54bc9c613540e749baf2c4582f5000d0ea7f9ae9 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 7837f1024..0a0d04cf6 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.tileEntityKeyString);
}
if (value != null) {
value.setCurrentChunk(Chunk.this);
+ tileEntityCounts.increment(value.tileEntityKeyString);
}
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.tileEntityKeyString);
}
return removed;
}
@@ -671,6 +676,7 @@ public class Chunk implements IChunkAccess {
this.entitySlices[k].add(entity);
// Paper start
entity.setCurrentChunk(this);
+ entityCounts.increment(entity.entityKeyString);
// Paper end
}
@@ -695,6 +701,7 @@ public class Chunk implements IChunkAccess {
return;
}
entity.setCurrentChunk(null);
+ entityCounts.decrement(entity.entityKeyString);
// Paper end
}
--
2.18.0