Add method to get ungenerated chunk from long key (#9254)

Also added a missing deprecation for a location block key method
This commit is contained in:
Jake Potrebic
2023-06-17 11:43:08 -07:00
parent d555760ff6
commit aa6d576fe0
3 changed files with 29 additions and 11 deletions

View File

@@ -51,10 +51,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
@NotNull
public Chunk getChunkAt(@NotNull Block block);
+ // Paper start
+ // Paper start - chunk long key API
+ /**
+ * Gets the chunk at the specified chunk key, which is the X and Z packed into a long.
+ *
+ * <p>
+ * See {@link Chunk#getChunkKey()} for easy access to the key, or you may calculate it as:
+ * long chunkKey = (long) chunkX &amp; 0xffffffffL | ((long) chunkZ &amp; 0xffffffffL) &gt;&gt; 32;
+ *
@@ -62,10 +62,25 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @return The chunk at the specified key
+ */
+ @NotNull
+ public default Chunk getChunkAt(long chunkKey) {
+ return getChunkAt((int) chunkKey, (int) (chunkKey >> 32));
+ default Chunk getChunkAt(long chunkKey) {
+ return getChunkAt(chunkKey, true);
+ }
+ // Paper end
+
+ /**
+ * Gets the chunk at the specified chunk key, which is the X and Z packed into a long.
+ * <p>
+ * See {@link Chunk#getChunkKey()} for easy access to the key, or you may calculate it as:
+ * long chunkKey = (long) chunkX &amp; 0xffffffffL | ((long) chunkZ &amp; 0xffffffffL) &gt;&gt; 32;
+ *
+ * @param chunkKey The Chunk Key to look up the chunk by
+ * @param generate Whether the chunk should be fully generated or not
+ * @return The chunk at the specified key
+ */
+ @NotNull
+ default Chunk getChunkAt(long chunkKey, boolean generate) {
+ return getChunkAt((int) chunkKey, (int) (chunkKey >> 32), generate);
+ }
+ // Paper end - chunk long key API
+
/**
* Checks if the specified {@link Chunk} is loaded