2021-06-11 14:02:28 +02:00
|
|
|
From 0000000000000000000000000000000000000000 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
|
|
|
|
|
|
|
|
The key can be retrieved via methods Location#toBlockKey() and
|
|
|
|
Block#getBlockKey()
|
|
|
|
|
|
|
|
World provides lookup for blocks by long key via method World#getBlockAtKey(long)
|
|
|
|
|
|
|
|
The formatting for the key is as follows:
|
|
|
|
|
|
|
|
10 bit y|27 bit z|27 bit x
|
|
|
|
|
|
|
|
The y value is considered unsigned while z and x are considered two's complement
|
|
|
|
|
|
|
|
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
|
2024-10-22 18:23:19 +02:00
|
|
|
index 56fd66a3fb5f6e33812d2981cd192d317453a0f5..12e1733d06471d0c2253ae846ee93a09140843cc 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/Location.java
|
|
|
|
+++ b/src/main/java/org/bukkit/Location.java
|
|
|
|
@@ -15,7 +15,6 @@ import org.jetbrains.annotations.Nullable;
|
|
|
|
|
|
|
|
// Paper start
|
|
|
|
import java.util.Collection;
|
|
|
|
-import java.util.Collections;
|
|
|
|
import java.util.function.Predicate;
|
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
import org.bukkit.entity.LivingEntity;
|
2023-11-26 00:03:02 +01:00
|
|
|
@@ -610,6 +609,19 @@ public class Location implements Cloneable, ConfigurationSerializable, io.paperm
|
2021-06-11 14:02:28 +02:00
|
|
|
blockLoc.setZ(getBlockZ());
|
|
|
|
return blockLoc;
|
|
|
|
}
|
|
|
|
+
|
2024-01-19 22:13:42 +01:00
|
|
|
+ // Paper start
|
2021-06-11 14:02:28 +02:00
|
|
|
+ /**
|
|
|
|
+ * @return The block key for this location's block location.
|
|
|
|
+ * @see Block#getBlockKey(int, int, int)
|
2022-03-21 19:06:42 +01:00
|
|
|
+ * @deprecated only encodes y block ranges from -512 to 511 and represents an already changed implementation detail
|
2021-06-11 14:02:28 +02:00
|
|
|
+ */
|
2024-06-04 21:40:18 +02:00
|
|
|
+ @Deprecated(since = "1.18.1")
|
2021-06-11 14:02:28 +02:00
|
|
|
+ public long toBlockKey() {
|
|
|
|
+ return Block.getBlockKey(getBlockX(), getBlockY(), getBlockZ());
|
|
|
|
+ }
|
2024-01-19 22:13:42 +01:00
|
|
|
+ // Paper end
|
2021-06-11 14:02:28 +02:00
|
|
|
+
|
|
|
|
/**
|
|
|
|
* @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
|
2024-10-22 18:23:19 +02:00
|
|
|
index 11362777d834cad2265984c7aa493358105cbf68..c474f6f0f1d758507f53c6f1ffbe3e26883e1425 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/World.java
|
|
|
|
+++ b/src/main/java/org/bukkit/World.java
|
Updated Upstream (Bukkit/CraftBukkit) (#10242)
* Updated Upstream (Bukkit/CraftBukkit)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
a6a9d2a4 Remove some old ApiStatus.Experimental annotations
be72314c SPIGOT-7300, PR-829: Add new DamageSource API providing enhanced information about entity damage
b252cf05 SPIGOT-7576, PR-970: Add methods in MushroomCow to change stew effects
b1c689bd PR-902: Add Server#isLoggingIPs to get log-ips configuration
08f86d1c PR-971: Add Player methods for client-side potion effects
2e3024a9 PR-963: Add API for in-world structures
a23292a7 SPIGOT-7530, PR-948: Improve Resource Pack API with new 1.20.3 functionality
1851857b SPIGOT-3071, PR-969: Add entity spawn method with spawn reason
cde4c52a SPIGOT-5553, PR-964: Add EntityKnockbackEvent
CraftBukkit Changes:
38fd4bd50 Fix accidentally renamed internal damage method
80f0ce4be SPIGOT-7300, PR-1180: Add new DamageSource API providing enhanced information about entity damage
7e43f3b16 SPIGOT-7581: Fix typo in BlockMushroom
ea14b7d90 SPIGOT-7576, PR-1347: Add methods in MushroomCow to change stew effects
4c687f243 PR-1259: Add Server#isLoggingIPs to get log-ips configuration
22a541a29 Improve support for per-world game rules
cb7dccce2 PR-1348: Add Player methods for client-side potion effects
b8d6109f0 PR-1335: Add API for in-world structures
4398a1b5b SPIGOT-7577: Make CraftWindCharge#explode discard the entity
e74107678 Fix Crafter maximum stack size
0bb0f4f6a SPIGOT-7530, PR-1314: Improve Resource Pack API with new 1.20.3 functionality
4949f556d SPIGOT-3071, PR-1345: Add entity spawn method with spawn reason
20ac73ca2 PR-1353: Fix Structure#place not working as documented with 0 palette
3c1b77871 SPIGOT-6911, PR-1349: Change max book length in CraftMetaBook
333701839 SPIGOT-7572: Bee nests generated without bees
f48f4174c SPIGOT-5553, PR-1336: Add EntityKnockbackEvent
2024-02-11 22:28:00 +01:00
|
|
|
@@ -99,6 +99,41 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
2021-06-11 14:02:28 +02:00
|
|
|
@NotNull
|
|
|
|
public Block getBlockAt(@NotNull Location location);
|
|
|
|
|
|
|
|
+ // Paper start
|
|
|
|
+ /**
|
|
|
|
+ * Gets the {@link Block} at the given block key
|
|
|
|
+ *
|
|
|
|
+ * @param key The block key. See {@link Block#getBlockKey()}
|
|
|
|
+ * @return Block at the key
|
|
|
|
+ * @see Block#getBlockKey(int, int, int)
|
2022-03-21 19:06:42 +01:00
|
|
|
+ * @deprecated only encodes y block ranges from -512 to 511 and represents an already changed implementation detail
|
2021-06-11 14:02:28 +02:00
|
|
|
+ */
|
|
|
|
+ @NotNull
|
2024-06-04 21:40:18 +02:00
|
|
|
+ @Deprecated(since = "1.18.1")
|
2021-06-11 14:02:28 +02:00
|
|
|
+ public default Block getBlockAtKey(long key) {
|
|
|
|
+ int x = Block.getBlockKeyX(key);
|
|
|
|
+ int y = Block.getBlockKeyY(key);
|
|
|
|
+ int z = Block.getBlockKeyZ(key);
|
|
|
|
+ return getBlockAt(x, y, z);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets the {@link Location} at the given block key
|
|
|
|
+ *
|
|
|
|
+ * @param key The block key. See {@link Location#toBlockKey()}
|
|
|
|
+ * @return Location at the key
|
|
|
|
+ * @see Block#getBlockKey(int, int, int)
|
|
|
|
+ */
|
|
|
|
+ @NotNull
|
2024-06-04 21:40:18 +02:00
|
|
|
+ @Deprecated(since = "1.18.1")
|
2021-06-11 14:02:28 +02:00
|
|
|
+ public default Location getLocationAtKey(long key) {
|
|
|
|
+ int x = Block.getBlockKeyX(key);
|
|
|
|
+ int y = Block.getBlockKeyY(key);
|
|
|
|
+ int z = Block.getBlockKeyZ(key);
|
|
|
|
+ return new Location(this, x, y, z);
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
/**
|
2023-05-12 13:10:08 +02:00
|
|
|
* Gets the highest non-empty (impassable) block at the given coordinates.
|
|
|
|
*
|
2021-06-11 14:02:28 +02:00
|
|
|
diff --git a/src/main/java/org/bukkit/block/Block.java b/src/main/java/org/bukkit/block/Block.java
|
2024-06-04 21:40:18 +02:00
|
|
|
index f3b3606dc5881e931853fc2631aad9ca9083474d..bb3cf2c5e2acbcd7cf53ad8551a5b11fa6104ada 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/block/Block.java
|
|
|
|
+++ b/src/main/java/org/bukkit/block/Block.java
|
2023-02-15 23:10:14 +01:00
|
|
|
@@ -156,6 +156,82 @@ public interface Block extends Metadatable, Translatable {
|
2021-06-11 14:02:28 +02:00
|
|
|
*/
|
|
|
|
int getZ();
|
|
|
|
|
2024-01-19 22:13:42 +01:00
|
|
|
+ // Paper start
|
2021-06-11 14:02:28 +02:00
|
|
|
+ /**
|
|
|
|
+ * Returns this block's coordinates packed into a long value.
|
|
|
|
+ * Computed via: {@code Block.getBlockKey(this.getX(), this.getY(), this.getZ())}
|
|
|
|
+ * @see Block#getBlockKey(int, int, int)
|
|
|
|
+ * @return This block's x, y, and z coordinates packed into a long value
|
2021-12-29 10:34:38 +01:00
|
|
|
+ * @deprecated see {@link #getBlockKey(int, int, int)}
|
2021-06-11 14:02:28 +02:00
|
|
|
+ */
|
2024-06-04 21:40:18 +02:00
|
|
|
+ @Deprecated(since = "1.18.1")
|
2021-06-11 14:02:28 +02:00
|
|
|
+ public default long getBlockKey() {
|
|
|
|
+ return Block.getBlockKey(this.getX(), this.getY(), this.getZ());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Returns the specified block coordinates packed into a long value
|
|
|
|
+ * <p>
|
|
|
|
+ * The return value can be computed as follows:
|
|
|
|
+ * <br>
|
|
|
|
+ * {@code long value = ((long)x & 0x7FFFFFF) | (((long)z & 0x7FFFFFF) << 27) | ((long)y << 54);}
|
|
|
|
+ * </p>
|
|
|
|
+ *
|
|
|
|
+ * <p>
|
|
|
|
+ * And may be unpacked as follows:
|
|
|
|
+ * <br>
|
|
|
|
+ * {@code int x = (int) ((packed << 37) >> 37);}
|
|
|
|
+ * <br>
|
2021-12-29 10:34:38 +01:00
|
|
|
+ * {@code int y = (int) (packed >> 54);}
|
2021-06-11 14:02:28 +02:00
|
|
|
+ * <br>
|
|
|
|
+ * {@code int z = (int) ((packed << 10) >> 37);}
|
|
|
|
+ * </p>
|
|
|
|
+ *
|
|
|
|
+ * @return This block's x, y, and z coordinates packed into a long value
|
2021-12-29 10:34:38 +01:00
|
|
|
+ * @deprecated only encodes y block ranges from -512 to 511 and represents an already changed implementation detail
|
2021-06-11 14:02:28 +02:00
|
|
|
+ */
|
2024-06-04 21:40:18 +02:00
|
|
|
+ @Deprecated(since = "1.18.1")
|
2021-06-11 14:02:28 +02:00
|
|
|
+ public static long getBlockKey(int x, int y, int z) {
|
|
|
|
+ return ((long)x & 0x7FFFFFF) | (((long)z & 0x7FFFFFF) << 27) | ((long)y << 54);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Returns the x component from the packed value.
|
|
|
|
+ * @param packed The packed value, as computed by {@link Block#getBlockKey(int, int, int)}
|
|
|
|
+ * @see Block#getBlockKey(int, int, int)
|
|
|
|
+ * @return The x component from the packed value.
|
2021-12-29 10:34:38 +01:00
|
|
|
+ * @deprecated see {@link #getBlockKey(int, int, int)}
|
2021-06-11 14:02:28 +02:00
|
|
|
+ */
|
2024-06-04 21:40:18 +02:00
|
|
|
+ @Deprecated(since = "1.18.1")
|
2021-06-11 14:02:28 +02:00
|
|
|
+ public static int getBlockKeyX(long packed) {
|
|
|
|
+ return (int) ((packed << 37) >> 37);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Returns the y component from the packed value.
|
|
|
|
+ * @param packed The packed value, as computed by {@link Block#getBlockKey(int, int, int)}
|
|
|
|
+ * @see Block#getBlockKey(int, int, int)
|
|
|
|
+ * @return The y component from the packed value.
|
2021-12-29 10:34:38 +01:00
|
|
|
+ * @deprecated see {@link #getBlockKey(int, int, int)}
|
2021-06-11 14:02:28 +02:00
|
|
|
+ */
|
2024-06-04 21:40:18 +02:00
|
|
|
+ @Deprecated(since = "1.18.1")
|
2021-06-11 14:02:28 +02:00
|
|
|
+ public static int getBlockKeyY(long packed) {
|
2021-12-29 10:34:38 +01:00
|
|
|
+ return (int) (packed >> 54);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Returns the z component from the packed value.
|
|
|
|
+ * @param packed The packed value, as computed by {@link Block#getBlockKey(int, int, int)}
|
|
|
|
+ * @see Block#getBlockKey(int, int, int)
|
|
|
|
+ * @return The z component from the packed value.
|
2021-12-29 10:34:38 +01:00
|
|
|
+ * @deprecated see {@link #getBlockKey(int, int, int)}
|
2021-06-11 14:02:28 +02:00
|
|
|
+ */
|
2024-06-04 21:40:18 +02:00
|
|
|
+ @Deprecated(since = "1.18.1")
|
2021-06-11 14:02:28 +02:00
|
|
|
+ public static int getBlockKeyZ(long packed) {
|
|
|
|
+ return (int) ((packed << 10) >> 37);
|
|
|
|
+ }
|
2024-01-19 22:13:42 +01:00
|
|
|
+ // Paper end
|
2021-06-11 14:02:28 +02:00
|
|
|
+
|
|
|
|
/**
|
|
|
|
* Gets the Location of the block
|
|
|
|
*
|