From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Ivan Pekov <ivan@mrivanplays.com>
Date: Thu, 10 Sep 2020 21:02:26 +0300
Subject: [PATCH] Fix LightEngineThreaded memory leak


diff --git a/src/main/java/net/minecraft/server/level/LightEngineThreaded.java b/src/main/java/net/minecraft/server/level/LightEngineThreaded.java
index ad584ba21c6e201b778f32cea6d7cc5bf67f9746..229bc64e65696319a83a0f7a7ba6f75752de44cd 100644
--- a/src/main/java/net/minecraft/server/level/LightEngineThreaded.java
+++ b/src/main/java/net/minecraft/server/level/LightEngineThreaded.java
@@ -123,6 +123,8 @@ public class LightEngineThreaded extends LightEngine implements AutoCloseable {
             }
         }
 
+        public final void remove(long chunkId) { pendingTasks.removeIf(task -> task.chunkId == chunkId); queueUpdate(); } // Yatopia
+
         public final boolean isEmpty() {
             return this.size == 0 && this.pendingTasks.isEmpty();
         }
diff --git a/src/main/java/net/minecraft/server/level/WorldServer.java b/src/main/java/net/minecraft/server/level/WorldServer.java
index 66b5fdd78aa8d394795550aec1203a4de9e4143d..8e978b74e3f5573123fa831bc1e64c38c4cbd2e6 100644
--- a/src/main/java/net/minecraft/server/level/WorldServer.java
+++ b/src/main/java/net/minecraft/server/level/WorldServer.java
@@ -2055,6 +2055,7 @@ public class WorldServer extends World implements GeneratorAccessSeed {
         }
         // Paper end
 
+        chunkProvider.getLightEngine().queue.remove(chunk.getPos().pair()); // Yatopia - unregister from light queue
     }
 
     public void unregisterEntity(Entity entity) {
