From 66733df5f97165fcfd3c740be7498df284cd382b Mon Sep 17 00:00:00 2001 From: Aikar Date: Sun, 19 Aug 2018 11:50:40 -0400 Subject: [PATCH] add World#getLocationAtKey for Block Key API For when you don't want to actually load the block --- ...Blocks-to-be-accessed-via-a-long-key.patch | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/Spigot-API-Patches/0129-Allow-Blocks-to-be-accessed-via-a-long-key.patch b/Spigot-API-Patches/0129-Allow-Blocks-to-be-accessed-via-a-long-key.patch index a0ea5ecf4f..715caeba88 100644 --- a/Spigot-API-Patches/0129-Allow-Blocks-to-be-accessed-via-a-long-key.patch +++ b/Spigot-API-Patches/0129-Allow-Blocks-to-be-accessed-via-a-long-key.patch @@ -1,4 +1,4 @@ -From d0451b859e9ed348881ce7b9839cc44fce4e3d3a Mon Sep 17 00:00:00 2001 +From 95832fe51208a8832ea7aa293c95720a4eb7ade3 Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Tue, 14 Aug 2018 21:42:10 -0700 Subject: [PATCH] Allow Blocks to be accessed via a long key @@ -18,7 +18,7 @@ Y range: [0, 1023] X, Z range: [-67 108 864, 67 108 863] diff --git a/src/main/java/org/bukkit/Location.java b/src/main/java/org/bukkit/Location.java -index 253f0c2d..a457abcf 100644 +index 8dcb15fb8..7e1ee875e 100644 --- a/src/main/java/org/bukkit/Location.java +++ b/src/main/java/org/bukkit/Location.java @@ -10,7 +10,6 @@ import org.bukkit.util.Vector; @@ -49,14 +49,14 @@ index 253f0c2d..a457abcf 100644 * @return A new location where X/Y/Z are the center of the block */ diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java -index 7b166b21..21c43dea 100644 +index 9b46e8892..a6facc4b0 100644 --- a/src/main/java/org/bukkit/World.java +++ b/src/main/java/org/bukkit/World.java -@@ -76,6 +76,23 @@ public interface World extends PluginMessageRecipient, Metadatable { +@@ -76,6 +76,37 @@ public interface World extends PluginMessageRecipient, Metadatable { */ public Block getBlockAt(Location location); -+ // Paper Start ++ // Paper start + /** + * Gets the {@link Block} at the given block key + * @@ -71,13 +71,27 @@ index 7b166b21..21c43dea 100644 + int z = (int) ((key << 10) >> 37); + return getBlockAt(x, y, z); + } -+ // Paper End ++ /** ++ * Gets the {@link Location} at the given block key ++ * ++ * @param key The block key. See {@link Location#toBlockKey()} ++ * @return Location at the key ++ * @see Location#toBlockKey() ++ * @see Block#getBlockKey() ++ */ ++ public default Location getLocationAtKey(long key) { ++ int x = (int) ((key << 37) >> 37); ++ int y = (int) (key >>> 54); ++ int z = (int) ((key << 10) >> 37); ++ return new Location(this, x, y, z); ++ } ++ // Paper end + /** * Gets the block type ID at the given coordinates * diff --git a/src/main/java/org/bukkit/block/Block.java b/src/main/java/org/bukkit/block/Block.java -index 359b81f3..2dbc784c 100644 +index 359b81f31..2dbc784cb 100644 --- a/src/main/java/org/bukkit/block/Block.java +++ b/src/main/java/org/bukkit/block/Block.java @@ -135,6 +135,30 @@ public interface Block extends Metadatable {