From 01cf3186bd008cf2768ac2d05c3cc55f93786e02 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Tue, 20 Dec 2016 15:17:18 -0500
Subject: [PATCH] Bound Treasure Maps to World Border

Make it so a Treasure Map does not target a structure outside of the
World Border, where players are not even able to reach.

This also would help the case where a players close to the border, and one
that is outside happens to be closer, but unreachable, yet another reachable
one is in border that would of been missed.
---
 ...-Bound-Treasure-Maps-to-World-Border.patch | 52 +++++++++++++++++++
 1 file changed, 52 insertions(+)
 create mode 100644 Spigot-Server-Patches/0188-Bound-Treasure-Maps-to-World-Border.patch

diff --git a/Spigot-Server-Patches/0188-Bound-Treasure-Maps-to-World-Border.patch b/Spigot-Server-Patches/0188-Bound-Treasure-Maps-to-World-Border.patch
new file mode 100644
index 0000000000..fefbd3b920
--- /dev/null
+++ b/Spigot-Server-Patches/0188-Bound-Treasure-Maps-to-World-Border.patch
@@ -0,0 +1,52 @@
+From 88232050bb78c98f3d59307724cc71f3983d1424 Mon Sep 17 00:00:00 2001
+From: Aikar <aikar@aikar.co>
+Date: Tue, 20 Dec 2016 15:15:11 -0500
+Subject: [PATCH] Bound Treasure Maps to World Border
+
+Make it so a Treasure Map does not target a structure outside of the
+World Border, where players are not even able to reach.
+
+This also would help the case where a players close to the border, and one
+that is outside happens to be closer, but unreachable, yet another reachable
+one is in border that would of been missed.
+
+diff --git a/src/main/java/net/minecraft/server/StructureGenerator.java b/src/main/java/net/minecraft/server/StructureGenerator.java
+index 9c1605b14..b566d5eee 100644
+--- a/src/main/java/net/minecraft/server/StructureGenerator.java
++++ b/src/main/java/net/minecraft/server/StructureGenerator.java
+@@ -233,6 +233,9 @@ public abstract class StructureGenerator extends WorldGenBase {
+ 
+                         WorldGenBase.a(world.getSeed(), random, l2, i3);
+                         random.nextInt();
++
++                        if (!world.getWorldBorder().isChunkInBounds(l2, i3)) { break; } // Paper
++
+                         if (structuregenerator.a(l2, i3)) {
+                             if (!flag1 || !world.b(l2, i3)) {
+                                 return new BlockPosition((l2 << 4) + 8, 64, (i3 << 4) + 8);
+diff --git a/src/main/java/net/minecraft/server/WorldBorder.java b/src/main/java/net/minecraft/server/WorldBorder.java
+index 632eb1c9d..1bb172bbf 100644
+--- a/src/main/java/net/minecraft/server/WorldBorder.java
++++ b/src/main/java/net/minecraft/server/WorldBorder.java
+@@ -33,6 +33,18 @@ public class WorldBorder {
+         return (double) (blockposition.getX() + 1) > this.b() && (double) blockposition.getX() < this.d() && (double) (blockposition.getZ() + 1) > this.c() && (double) blockposition.getZ() < this.e();
+     }
+ 
++    // Paper start
++    private final BlockPosition.MutableBlockPosition mutPos = new BlockPosition.MutableBlockPosition();
++    public boolean isBlockInBounds(int chunkX, int chunkZ) {
++        mutPos.setValues(chunkX, 64, chunkZ);
++        return isInBounds(mutPos);
++    }
++    public boolean isChunkInBounds(int chunkX, int chunkZ) {
++        mutPos.setValues(((chunkX << 4) + 15), 64, (chunkZ << 4) + 15);
++        return isInBounds(mutPos);
++    }
++    // Paper end
++
+     public boolean isInBounds(ChunkCoordIntPair chunkcoordintpair) {
+         return (double) chunkcoordintpair.e() > this.b() && (double) chunkcoordintpair.c() < this.d() && (double) chunkcoordintpair.f() > this.c() && (double) chunkcoordintpair.d() < this.e();
+     }
+-- 
+2.11.0
+