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/LightEngineThreaded.java b/src/main/java/net/minecraft/server/LightEngineThreaded.java
index b2f51a6786d4bb92c9cbbceeea812375b1a49bd6..d16157dcbc6f36fa0c8284784641e54413d249be 100644
--- a/src/main/java/net/minecraft/server/LightEngineThreaded.java
+++ b/src/main/java/net/minecraft/server/LightEngineThreaded.java
@@ -110,6 +110,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/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
index 68fda6e73db23cc8fb10501b2d84f229ea5afc7f..426496ce2f08fc6c7d713267f735964f04eb22f1 100644
--- a/src/main/java/net/minecraft/server/WorldServer.java
+++ b/src/main/java/net/minecraft/server/WorldServer.java
@@ -1894,6 +1894,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) {
