From 3ed90751c599a2798cccf93d9b4ed37d184596dd Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Wed, 4 Jul 2018 15:23:15 -0400
Subject: [PATCH] Configurable Bed Search Radius

Allows you to increase how far to check for a safe place to respawn
a player near their bed, allowing a better chance to respawn the
player at their bed should it of became obstructed.

Defaults to vanilla 1.
---
 .../Configurable-Bed-Search-Radius.patch      | 67 +++++++++++++++++++
 scripts/importmcdev.sh                        |  1 +
 2 files changed, 68 insertions(+)
 create mode 100644 Spigot-Server-Patches/Configurable-Bed-Search-Radius.patch

diff --git a/Spigot-Server-Patches/Configurable-Bed-Search-Radius.patch b/Spigot-Server-Patches/Configurable-Bed-Search-Radius.patch
new file mode 100644
index 0000000000..6629b48e38
--- /dev/null
+++ b/Spigot-Server-Patches/Configurable-Bed-Search-Radius.patch
@@ -0,0 +1,67 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Aikar <aikar@aikar.co>
+Date: Wed, 4 Jul 2018 15:22:06 -0400
+Subject: [PATCH] Configurable Bed Search Radius
+
+Allows you to increase how far to check for a safe place to respawn
+a player near their bed, allowing a better chance to respawn the
+player at their bed should it of became obstructed.
+
+Defaults to vanilla 1.
+
+diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+index 06c54690f..50416f40a 100644
+--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
++++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+@@ -0,0 +0,0 @@ public class PaperWorldConfig {
+     private void scanForLegacyEnderDragon() {
+         scanForLegacyEnderDragon = getBoolean("game-mechanics.scan-for-legacy-ender-dragon", true);
+     }
++
++    public int bedSearchRadius = 1;
++    private void bedSearchRadius() {
++        bedSearchRadius = getInt("bed-search-radius", 1);
++        if (bedSearchRadius < 1) {
++            bedSearchRadius = 1;
++        }
++        if (bedSearchRadius > 1) {
++            log("Bed Search Radius: " + bedSearchRadius);
++        }
++    }
+ }
+diff --git a/src/main/java/net/minecraft/server/BlockBed.java b/src/main/java/net/minecraft/server/BlockBed.java
+index 9346bddff..b12834705 100644
+--- a/src/main/java/net/minecraft/server/BlockBed.java
++++ b/src/main/java/net/minecraft/server/BlockBed.java
+@@ -0,0 +0,0 @@ public class BlockBed extends BlockFacingHorizontal implements ITileEntity {
+             int k1 = l - enumdirection.getAdjacentZ() * i1 - 1;
+             int l1 = j1 + 2;
+             int i2 = k1 + 2;
+-
+-            for (int j2 = j1; j2 <= l1; ++j2) {
+-                for (int k2 = k1; k2 <= i2; ++k2) {
+-                    BlockPosition blockposition1 = new BlockPosition(j2, k, k2);
++            // Paper start
++            int radius = world.paperConfig.bedSearchRadius - 1;
++            j1 -= radius;
++            k1 -= radius;
++            l1 += radius;
++            i2 += radius;
++            // Paper end
++
++            for (int j2 = j1 ; j2 <= l1 ; ++j2) {
++                for (int k2 = k1 ; k2 <= i2 ; ++k2) { for (int y = -radius ; y <= radius ; y++) { // Paper
++                    BlockPosition blockposition1 = new BlockPosition(j2, k + y, k2); // Paper
+ 
+                     if (b(world, blockposition1)) {
+                         if (i <= 0) {
+@@ -0,0 +0,0 @@ public class BlockBed extends BlockFacingHorizontal implements ITileEntity {
+                         }
+ 
+                         --i;
+-                    }
++                    }} // Paper
+                 }
+             }
+         }
+--
\ No newline at end of file
diff --git a/scripts/importmcdev.sh b/scripts/importmcdev.sh
index b935cf79c8..9e16057186 100755
--- a/scripts/importmcdev.sh
+++ b/scripts/importmcdev.sh
@@ -39,6 +39,7 @@ function import {
 import AxisAlignedBB
 import BaseBlockPosition
 import BiomeBase
+import BlockBed
 import BiomeBigHills
 import BiomeJungle
 import BiomeMesa