2021-06-11 14:02:28 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Sat, 4 Aug 2018 19:37:35 -0400
|
|
|
|
Subject: [PATCH] Provide Chunk Coordinates as a Long API
|
|
|
|
|
|
|
|
Allows you to easily access the chunks X/z as a long, and a method
|
|
|
|
to look up by the long key too.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/Chunk.java b/src/main/java/org/bukkit/Chunk.java
|
2024-06-13 16:45:27 +02:00
|
|
|
index 20ed1c40437cbf8449dd4d7876086ccb6407b470..8764441ec1bae67a029b13c4c98246574ba32ef5 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/Chunk.java
|
|
|
|
+++ b/src/main/java/org/bukkit/Chunk.java
|
2024-06-13 16:45:27 +02:00
|
|
|
@@ -36,6 +36,32 @@ public interface Chunk extends PersistentDataHolder {
|
2021-06-11 14:02:28 +02:00
|
|
|
*/
|
|
|
|
int getZ();
|
|
|
|
|
|
|
|
+ // Paper start
|
|
|
|
+ /**
|
|
|
|
+ * @return The Chunks X and Z coordinates packed into a long
|
|
|
|
+ */
|
|
|
|
+ default long getChunkKey() {
|
|
|
|
+ return getChunkKey(getX(), getZ());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @param loc Location to get chunk key
|
|
|
|
+ * @return Location's chunk coordinates packed into a long
|
|
|
|
+ */
|
|
|
|
+ static long getChunkKey(@NotNull Location loc) {
|
|
|
|
+ return getChunkKey((int) Math.floor(loc.getX()) >> 4, (int) Math.floor(loc.getZ()) >> 4);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @param x X Coordinate
|
|
|
|
+ * @param z Z Coordinate
|
|
|
|
+ * @return Chunk coordinates packed into a long
|
|
|
|
+ */
|
|
|
|
+ static long getChunkKey(int x, int z) {
|
|
|
|
+ return (long) x & 0xffffffffL | ((long) z & 0xffffffffL) << 32;
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
/**
|
|
|
|
* Gets the world containing this chunk
|
|
|
|
*
|
|
|
|
diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
|
2024-12-03 17:58:41 +01:00
|
|
|
index 002bfadfd4efa3d376a0a7bc5c752e8a02494eec..3dc2e420d8a6cf02fc4215d4d8056c44e829157f 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
|
|
|
@@ -182,6 +182,37 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
2021-06-11 14:02:28 +02:00
|
|
|
@NotNull
|
|
|
|
public Chunk getChunkAt(@NotNull Block block);
|
|
|
|
|
2023-06-17 20:43:08 +02:00
|
|
|
+ // Paper start - chunk long key API
|
2021-06-11 14:02:28 +02:00
|
|
|
+ /**
|
|
|
|
+ * Gets the chunk at the specified chunk key, which is the X and Z packed into a long.
|
2023-06-17 20:43:08 +02:00
|
|
|
+ * <p>
|
|
|
|
+ * See {@link Chunk#getChunkKey()} for easy access to the key, or you may calculate it as:
|
|
|
|
+ * long chunkKey = (long) chunkX & 0xffffffffL | ((long) chunkZ & 0xffffffffL) >> 32;
|
2021-06-11 14:02:28 +02:00
|
|
|
+ *
|
2023-06-17 20:43:08 +02:00
|
|
|
+ * @param chunkKey The Chunk Key to look up the chunk by
|
|
|
|
+ * @return The chunk at the specified key
|
|
|
|
+ */
|
|
|
|
+ @NotNull
|
|
|
|
+ default Chunk getChunkAt(long chunkKey) {
|
|
|
|
+ return getChunkAt(chunkKey, true);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets the chunk at the specified chunk key, which is the X and Z packed into a long.
|
|
|
|
+ * <p>
|
2021-06-11 14:02:28 +02:00
|
|
|
+ * See {@link Chunk#getChunkKey()} for easy access to the key, or you may calculate it as:
|
|
|
|
+ * long chunkKey = (long) chunkX & 0xffffffffL | ((long) chunkZ & 0xffffffffL) >> 32;
|
|
|
|
+ *
|
|
|
|
+ * @param chunkKey The Chunk Key to look up the chunk by
|
2023-06-17 20:43:08 +02:00
|
|
|
+ * @param generate Whether the chunk should be fully generated or not
|
2021-06-11 14:02:28 +02:00
|
|
|
+ * @return The chunk at the specified key
|
|
|
|
+ */
|
|
|
|
+ @NotNull
|
2023-06-17 20:43:08 +02:00
|
|
|
+ default Chunk getChunkAt(long chunkKey, boolean generate) {
|
|
|
|
+ return getChunkAt((int) chunkKey, (int) (chunkKey >> 32), generate);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
2023-06-17 20:43:08 +02:00
|
|
|
+ // Paper end - chunk long key API
|
2021-06-11 14:02:28 +02:00
|
|
|
+
|
|
|
|
/**
|
|
|
|
* Checks if the specified {@link Chunk} is loaded
|
|
|
|
*
|