13
0
geforkt von Mirrors/Paper

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

Also added a missing deprecation for a location block key method
Dieser Commit ist enthalten in:
Jake Potrebic 2023-06-17 11:43:08 -07:00
Ursprung d555760ff6
Commit aa6d576fe0
3 geänderte Dateien mit 29 neuen und 11 gelöschten Zeilen

Datei anzeigen

@ -83,6 +83,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @see Block#getBlockKey(int, int, int) + * @see Block#getBlockKey(int, int, int)
+ */ + */
+ @NotNull + @NotNull
+ @Deprecated
+ public default Location getLocationAtKey(long key) { + public default Location getLocationAtKey(long key) {
+ int x = Block.getBlockKeyX(key); + int x = Block.getBlockKeyX(key);
+ int y = Block.getBlockKeyY(key); + int y = Block.getBlockKeyY(key);

Datei anzeigen

@ -51,10 +51,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
@NotNull @NotNull
public Chunk getChunkAt(@NotNull Block block); 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. + * 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: + * 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; + * 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 + * @return The chunk at the specified key
+ */ + */
+ @NotNull + @NotNull
+ public default Chunk getChunkAt(long chunkKey) { + default Chunk getChunkAt(long chunkKey) {
+ return getChunkAt((int) chunkKey, (int) (chunkKey >> 32)); + 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 * Checks if the specified {@link Chunk} is loaded

Datei anzeigen

@ -38,10 +38,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
--- a/src/main/java/org/bukkit/World.java --- a/src/main/java/org/bukkit/World.java
+++ b/src/main/java/org/bukkit/World.java +++ b/src/main/java/org/bukkit/World.java
@@ -0,0 +0,0 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient @@ -0,0 +0,0 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
public default Chunk getChunkAt(long chunkKey) {
return getChunkAt((int) chunkKey, (int) (chunkKey >> 32));
} }
+ // Paper end - chunk long key API
+ // Paper start - isChunkGenerated API
+ /** + /**
+ * Checks if a {@link Chunk} has been generated at the specified chunk key, + * Checks if a {@link Chunk} has been generated at the specified chunk key,
+ * which is the X and Z packed into a long. + * which is the X and Z packed into a long.
@ -49,9 +49,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @param chunkKey The Chunk Key to look up the chunk by + * @param chunkKey The Chunk Key to look up the chunk by
+ * @return true if the chunk has been generated, otherwise false + * @return true if the chunk has been generated, otherwise false
+ */ + */
+ public default boolean isChunkGenerated(long chunkKey) { + default boolean isChunkGenerated(long chunkKey) {
+ return isChunkGenerated((int) chunkKey, (int) (chunkKey >> 32)); + return isChunkGenerated((int) chunkKey, (int) (chunkKey >> 32));
+ } + }
// Paper end + // Paper end - isChunkGenerated API
+
/** /**
* Checks if the specified {@link Chunk} is loaded
*