From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: mezz Date: Wed, 9 Aug 2017 17:51:22 -0500 Subject: [PATCH] Fix MC-117075: TE Unload Lag Spike diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java index 92aa1428e723b377c12bfd20cd1e6b4242ad1261..79e23503b7082633de654f04575b8323ea887e44 100644 --- a/src/main/java/net/minecraft/world/level/Level.java +++ b/src/main/java/net/minecraft/world/level/Level.java @@ -721,6 +721,8 @@ public abstract class Level implements LevelAccessor, AutoCloseable { // Spigot start // Iterator iterator = this.blockEntityTickers.iterator(); int tilesThisCycle = 0; + var toRemove = new it.unimi.dsi.fastutil.objects.ObjectOpenCustomHashSet(net.minecraft.Util.identityStrategy()); // Paper - use removeAll + toRemove.add(null); 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(tileTickPosition); @@ -728,7 +730,6 @@ public abstract class Level implements LevelAccessor, AutoCloseable { if (tickingblockentity == null) { this.getCraftServer().getLogger().severe("Spigot has detected a null entity and has removed it, preventing a crash"); tilesThisCycle--; - this.blockEntityTickers.remove(this.tileTickPosition--); continue; } // Spigot end @@ -736,12 +737,13 @@ public abstract class Level implements LevelAccessor, AutoCloseable { if (tickingblockentity.isRemoved()) { // Spigot start tilesThisCycle--; - this.blockEntityTickers.remove(this.tileTickPosition--); + toRemove.add(tickingblockentity); // Paper - use removeAll // Spigot end } else if (this.shouldTickBlocksAt(tickingblockentity.getPos())) { tickingblockentity.tick(); } } + this.blockEntityTickers.removeAll(toRemove); timings.tileEntityTick.stopTiming(); // Spigot this.tickingBlockEntities = false;