Fix MC-117075: Block entity unload lag spike

This commit is contained in:
mezz 2017-08-09 17:51:22 -05:00
parent 3ce6b37e05
commit f1fd83ac7a

View File

@ -237,7 +237,7 @@
+ // Paper start - if loaded
@Nullable
+ @Override
@Override
+ public final ChunkAccess getChunkIfLoadedImmediately(int x, int z) {
+ return ((ServerLevel)this).chunkSource.getChunkAtIfLoadedImmediately(x, z);
+ }
@ -290,7 +290,7 @@
+ return getWorldBorder().isWithinBounds(blockposition) ? getBlockStateIfLoaded(blockposition) : null;
+ }
+
@Override
+ @Override
public ChunkAccess getChunk(int chunkX, int chunkZ, ChunkStatus leastStatus, boolean create) {
+ // Paper end
ChunkAccess ichunkaccess = this.getChunkSource().getChunk(chunkX, chunkZ, leastStatus, create);
@ -415,14 +415,14 @@
+
+ if ((i & 2) != 0 && (!this.isClientSide || (i & 4) == 0) && (this.isClientSide || chunk == null || (chunk.getFullStatus() != null && chunk.getFullStatus().isOrAfter(FullChunkStatus.BLOCK_TICKING)))) { // allow chunk to be null here as chunk.isReady() is false when we send our notification during block placement
+ this.sendBlockUpdated(blockposition, iblockdata1, iblockdata, i);
}
+ }
+
+ if ((i & 1) != 0) {
+ this.blockUpdated(blockposition, iblockdata1.getBlock());
+ if (!this.isClientSide && iblockdata.hasAnalogOutputSignal()) {
+ this.updateNeighbourForOutputSignal(blockposition, newBlock.getBlock());
+ }
+ }
}
+
+ if ((i & 16) == 0 && j > 0) {
+ int k = i & -34;
@ -474,7 +474,7 @@
return chunk.getBlockState(pos);
}
@@ -446,14 +719,21 @@
@@ -446,32 +719,44 @@
this.pendingBlockEntityTickers.clear();
}
@ -486,6 +486,8 @@
- while (iterator.hasNext()) {
- TickingBlockEntity tickingblockentity = (TickingBlockEntity) iterator.next();
+ int tilesThisCycle = 0;
+ var toRemove = new it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet<TickingBlockEntity>(); // Paper - Fix MC-117075; use removeAll
+ toRemove.add(null); // Paper - Fix MC-117075
+ for (tileTickPosition = 0; tileTickPosition < this.blockEntityTickers.size(); tileTickPosition++) { // Paper - Disable tick limiters
+ this.tileTickPosition = (this.tileTickPosition < this.blockEntityTickers.size()) ? this.tileTickPosition : 0;
+ TickingBlockEntity tickingblockentity = (TickingBlockEntity) this.blockEntityTickers.get(this.tileTickPosition);
@ -495,12 +497,13 @@
- iterator.remove();
+ // Spigot start
+ tilesThisCycle--;
+ this.blockEntityTickers.remove(this.tileTickPosition--);
+ toRemove.add(tickingblockentity); // Paper - Fix MC-117075; use removeAll
+ // Spigot end
} else if (flag && this.shouldTickBlocksAt(tickingblockentity.getPos())) {
tickingblockentity.tick();
}
@@ -461,17 +741,19 @@
}
+ this.blockEntityTickers.removeAll(toRemove); // Paper - Fix MC-117075
this.tickingBlockEntities = false;
gameprofilerfiller.pop();
@ -525,7 +528,7 @@
}
}
@@ -510,13 +792,29 @@
@@ -510,13 +795,29 @@
@Nullable
@Override
public BlockEntity getBlockEntity(BlockPos pos) {
@ -556,7 +559,7 @@
this.getChunkAt(blockposition).addAndRegisterBlockEntity(blockEntity);
}
}
@@ -643,7 +941,7 @@
@@ -643,7 +944,7 @@
for (int k = 0; k < j; ++k) {
EnderDragonPart entitycomplexpart = aentitycomplexpart[k];
@ -565,7 +568,7 @@
if (t0 != null && predicate.test(t0)) {
result.add(t0);
@@ -912,7 +1210,7 @@
@@ -912,7 +1213,7 @@
public static enum ExplosionInteraction implements StringRepresentable {