mirror of
https://github.com/PaperMC/Paper.git
synced 2024-09-26 13:42:49 +02:00
1718f61bf8
Doesn't compile yet. CraftBukkit Changes: 90d6905b Repackage NMS 69cf961d Repackage patches Spigot Changes: 79d53c28 Repackage NMS
56 lines
2.5 KiB
Diff
56 lines
2.5 KiB
Diff
From 0000000000000000000000000000000000000000 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/world/level/chunk/Chunk.java b/src/main/java/net/minecraft/world/level/chunk/Chunk.java
|
|
index 929f6fcd4b9f1b9a1488e170d6a77a5d64beecf3..acdcece38a4b30d6c89eb4342918ae8997db9f0b 100644
|
|
--- a/src/main/java/net/minecraft/world/level/chunk/Chunk.java
|
|
+++ b/src/main/java/net/minecraft/world/level/chunk/Chunk.java
|
|
@@ -91,15 +91,19 @@ public class Chunk implements IChunkAccess {
|
|
}
|
|
|
|
// 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;
|
|
}
|
|
@@ -109,6 +113,7 @@ public class Chunk implements IChunkAccess {
|
|
TileEntity removed = super.remove(key);
|
|
if (removed != null) {
|
|
removed.setCurrentChunk(null);
|
|
+ tileEntityCounts.decrement(removed.getMinecraftKeyString());
|
|
}
|
|
return removed;
|
|
}
|
|
@@ -529,6 +534,7 @@ public class Chunk implements IChunkAccess {
|
|
k = this.entitySlices.length - 1;
|
|
}
|
|
|
|
+ if (!entity.inChunk || entity.getCurrentChunk() != this) entityCounts.increment(entity.getMinecraftKeyString()); // Paper
|
|
entity.inChunk = true;
|
|
entity.setCurrentChunk(this); // Paper
|
|
entity.chunkX = this.loc.x;
|
|
@@ -563,6 +569,7 @@ public class Chunk implements IChunkAccess {
|
|
if (!this.entitySlices[i].remove(entity)) {
|
|
return;
|
|
}
|
|
+ entityCounts.decrement(entity.getMinecraftKeyString());
|
|
// Paper end
|
|
this.entities.remove(entity); // Paper
|
|
}
|