From baf8797e8fd1222f4c268cd635973231a8c350cb Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Thu, 31 Mar 2016 19:29:06 -0400
Subject: [PATCH] Do not load chunks for light checks

Should only happen for blocks on the edge that uses neighbors light level
(certain blocks). In that case, there will be 3-4 other neighbors to get a light level from.
---
 .../Do-not-load-chunks-for-light-checks.patch | 21 +++++++++++++++++++
 Spigot-Server-Patches/MC-Utils.patch          |  6 ++++++
 2 files changed, 27 insertions(+)
 create mode 100644 Spigot-Server-Patches/Do-not-load-chunks-for-light-checks.patch

diff --git a/Spigot-Server-Patches/Do-not-load-chunks-for-light-checks.patch b/Spigot-Server-Patches/Do-not-load-chunks-for-light-checks.patch
new file mode 100644
index 0000000000..08c19f1120
--- /dev/null
+++ b/Spigot-Server-Patches/Do-not-load-chunks-for-light-checks.patch
@@ -0,0 +1,21 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Aikar <aikar@aikar.co>
+Date: Thu, 31 Mar 2016 19:17:58 -0400
+Subject: [PATCH] Do not load chunks for light checks
+
+Should only happen for blocks on the edge that uses neighbors light level
+(certain blocks). In that case, there will be 3-4 other neighbors to get a light level from.
+
+diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
+index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
+--- a/src/main/java/net/minecraft/server/World.java
++++ b/src/main/java/net/minecraft/server/World.java
+@@ -0,0 +0,0 @@ public abstract class World implements IBlockAccess {
+                 if (blockposition.getY() >= 256) {
+                     blockposition = new BlockPosition(blockposition.getX(), 255, blockposition.getZ());
+                 }
++                if (!this.isLoaded(blockposition)) return 0; // Paper
+ 
+                 Chunk chunk = this.getChunkAtWorldCoords(blockposition);
+ 
+--
\ No newline at end of file
diff --git a/Spigot-Server-Patches/MC-Utils.patch b/Spigot-Server-Patches/MC-Utils.patch
index 396ef442eb..45636171d5 100644
--- a/Spigot-Server-Patches/MC-Utils.patch
+++ b/Spigot-Server-Patches/MC-Utils.patch
@@ -119,5 +119,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +    public static Location toLocation(Entity entity) {
 +        return new Location(entity.getWorld().getWorld(), entity.locX, entity.locY, entity.locZ);
 +    }
++
++    public static boolean isEdgeOfChunk(BlockPosition pos) {
++        final int absX = Math.abs(pos.getX()) % 16;
++        final int absZ = Math.abs(pos.getZ()) % 16;
++        return (absX == 0 || absX == 15 || absZ == 0 || absZ == 15);
++    }
 +}
 --
\ No newline at end of file