Reimplement hopper optimization patch (#2388)

Co-authored-by: Shane Freeder <theboyetronic@gmail.com>
This commit is contained in:
Omer Uddin 2019-08-07 23:08:22 +05:00 committed by Shane Freeder
parent e264c365ac
commit 6ccf0bda3b

View file

@ -13,24 +13,25 @@ And since minecart hoppers are used _very_ rarely near we can avoid alot of sear
Combined, this adds up a lot.
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
index a9aa13fbf8..cb56d067b9 100644
index d604f96c1..67dc837f4 100644
--- a/src/main/java/net/minecraft/server/Chunk.java
+++ b/src/main/java/net/minecraft/server/Chunk.java
@@ -95,6 +95,10 @@ public class Chunk implements IChunkAccess {
@@ -84,6 +84,10 @@ public class Chunk implements IChunkAccess {
return removed;
}
}
final PaperLightingQueue.LightingQueue lightingQueue = new PaperLightingQueue.LightingQueue(this);
+ // Track the number of minecarts and items
+ // Keep this synced with entitySlices.add() and entitySlices.remove()
+ private final int[] itemCounts = new int[16];
+ private final int[] inventoryEntityCounts = new int[16];
// Paper end
public boolean areNeighborsLoaded(final int radius) {
switch (radius) {
@@ -690,6 +694,13 @@ public class Chunk implements IChunkAccess {
public Chunk(World world, ChunkCoordIntPair chunkcoordintpair, BiomeBase[] abiomebase, ChunkConverter chunkconverter, TickList<Block> ticklist, TickList<FluidType> ticklist1, long i, @Nullable ChunkSection[] achunksection, @Nullable Consumer<Chunk> consumer) {
@@ -436,6 +440,13 @@ public class Chunk implements IChunkAccess {
entity.chunkY = k;
entity.chunkZ = this.locZ;
entity.chunkZ = this.loc.z;
this.entitySlices[k].add(entity);
+ // Paper start
+ if (entity instanceof EntityItem) {
@ -39,10 +40,10 @@ index a9aa13fbf8..cb56d067b9 100644
+ inventoryEntityCounts[k]++;
+ }
+ // Paper end
entity.entitySlice = this.entitySlices[k]; // Paper
this.markDirty(); // Paper
}
public void a(HeightMap.Type heightmap_type, long[] along) {
@@ -714,6 +725,11 @@ public class Chunk implements IChunkAccess {
@@ -466,6 +477,11 @@ public class Chunk implements IChunkAccess {
if (!this.entitySlices[i].remove(entity)) {
return;
}
@ -52,25 +53,25 @@ index a9aa13fbf8..cb56d067b9 100644
+ inventoryEntityCounts[i]--;
+ }
entityCounts.decrement(entity.getMinecraftKeyString());
this.markDirty(); // Paper
// Paper end
}
@@ -959,6 +975,15 @@ public class Chunk implements IChunkAccess {
if (!this.entitySlices[k].isEmpty()) {
Iterator iterator = this.entitySlices[k].iterator();
@@ -715,6 +731,15 @@ public class Chunk implements IChunkAccess {
for (int k = i; k <= j; ++k) {
Iterator iterator = this.entitySlices[k].iterator(); // Spigot
+ // Paper start - Don't search for inventories if we have none, and that is all we want
+ /*
+ * We check if they want inventories by seeing if it is the static `IEntitySelector.c`
+ *
+ * Make sure the inventory selector stays in sync.
+ * It should be the one that checks `var1 instanceof IInventory && var1.isAlive()`
+ */
+ if (predicate == IEntitySelector.isInventory() && inventoryEntityCounts[k] <= 0) continue;
+ // Paper end
while (iterator.hasNext()) {
Entity entity1 = (Entity) iterator.next();
@@ -995,7 +1020,18 @@ public class Chunk implements IChunkAccess {
+ // Paper start - Don't search for inventories if we have none, and that is all we want
+ /*
+ * We check if they want inventories by seeing if it is the static `IEntitySelector.c`
+ *
+ * Make sure the inventory selector stays in sync.
+ * It should be the one that checks `var1 instanceof IInventory && var1.isAlive()`
+ */
+ if (predicate == IEntitySelector.isInventory() && inventoryEntityCounts[k] <= 0) continue;
+ // Paper end
while (iterator.hasNext()) {
Entity entity = (Entity) iterator.next();
if (entity.shouldBeRemoved) continue; // Paper
@@ -734,7 +759,18 @@ public class Chunk implements IChunkAccess {
i = MathHelper.clamp(i, 0, this.entitySlices.length - 1);
j = MathHelper.clamp(j, 0, this.entitySlices.length - 1);
@ -90,7 +91,7 @@ index a9aa13fbf8..cb56d067b9 100644
while (iterator.hasNext()) {
diff --git a/src/main/java/net/minecraft/server/IEntitySelector.java b/src/main/java/net/minecraft/server/IEntitySelector.java
index bbcbb62325..f6916fd455 100644
index 56488b78d..56739e6ed 100644
--- a/src/main/java/net/minecraft/server/IEntitySelector.java
+++ b/src/main/java/net/minecraft/server/IEntitySelector.java
@@ -11,6 +11,7 @@ public final class IEntitySelector {
@ -102,5 +103,5 @@ index bbcbb62325..f6916fd455 100644
return entity instanceof IInventory && entity.isAlive();
};
--
2.21.0
2.22.0