Merge branch 'master' into pre/1.13

* master:
  add World#getLocationAtKey for Block Key API
This commit is contained in:
Aikar 2018-08-19 11:53:05 -04:00
commit 41ecb86304
No known key found for this signature in database
GPG Key ID: 401ADFC9891FAAFE
1 changed files with 21 additions and 7 deletions

View File

@ -1,4 +1,4 @@
From d9e2a8161436e5e69cab70d36e48a2c4900bf1fd Mon Sep 17 00:00:00 2001
From 743e46cd7844b3927e0d4ed1b59261103aebfd70 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
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 8dcb15fb..7e1ee875 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 8dcb15fb..7e1ee875 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 f84f151a..3d8b4925 100644
index f84f151ad..3170a0746 100644
--- a/src/main/java/org/bukkit/World.java
+++ b/src/main/java/org/bukkit/World.java
@@ -73,6 +73,23 @@ public interface World extends PluginMessageRecipient, Metadatable {
@@ -73,6 +73,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 f84f151a..3d8b4925 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 y coordinate of the lowest block at this position such that the
* block and all blocks above it are transparent for lighting purposes.
diff --git a/src/main/java/org/bukkit/block/Block.java b/src/main/java/org/bukkit/block/Block.java
index 238de6f0..d700df53 100644
index 238de6f0a..d700df538 100644
--- a/src/main/java/org/bukkit/block/Block.java
+++ b/src/main/java/org/bukkit/block/Block.java
@@ -139,6 +139,30 @@ public interface Block extends Metadatable {