Fix World#getChunkAtAsync(Location) variants incorectly calculating chunk x

The blockX needs to be floored before converted to int, as float -> integer
operations are truncation. (i.e -0.5 -> 0, we want -0.5 -> -1)
This commit is contained in:
Spottedleaf 2019-03-02 15:45:42 -08:00 committed by Aikar
parent 21ee8800f8
commit e5f0d0f5dc
No known key found for this signature in database
GPG key ID: 401ADFC9891FAAFE

View file

@ -1,4 +1,4 @@
From 6dc478f219217b81d31c62ff433aaac40052ed7b Mon Sep 17 00:00:00 2001
From c56c68eed04866793c411e6dc5eeeabe2f73ace1 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Mon, 29 Feb 2016 17:43:33 -0600
Subject: [PATCH] Async Chunks API
@ -8,7 +8,7 @@ Adds API's to load or generate chunks asynchronously.
Also adds utility methods to Entity to teleport asynchronously.
diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
index 807bd7fc..61f2cd9a 100644
index 807bd7fc..51cf7fd3 100644
--- a/src/main/java/org/bukkit/World.java
+++ b/src/main/java/org/bukkit/World.java
@@ -152,6 +152,352 @@ public interface World extends PluginMessageRecipient, Metadatable {
@ -175,7 +175,7 @@ index 807bd7fc..61f2cd9a 100644
+ * will be executed synchronously
+ */
+ public default void getChunkAtAsync(Location loc, java.util.function.Consumer<Chunk> cb) {
+ getChunkAtAsync((int)loc.getX() >> 4, (int)Math.floor(loc.getZ()) >> 4, true, cb);
+ getChunkAtAsync((int)Math.floor(loc.getX()) >> 4, (int)Math.floor(loc.getZ()) >> 4, true, cb);
+ }
+
+ /**
@ -197,7 +197,7 @@ index 807bd7fc..61f2cd9a 100644
+ * will be executed synchronously
+ */
+ public default void getChunkAtAsync(Location loc, boolean gen, java.util.function.Consumer<Chunk> cb) {
+ getChunkAtAsync((int)loc.getX() >> 4, (int)Math.floor(loc.getZ()) >> 4, gen, cb);
+ getChunkAtAsync((int)Math.floor(loc.getX()) >> 4, (int)Math.floor(loc.getZ()) >> 4, gen, cb);
+ }
+
+ /**
@ -259,7 +259,7 @@ index 807bd7fc..61f2cd9a 100644
+ * @return Future that will resolve when the chunk is loaded
+ */
+ public default java.util.concurrent.CompletableFuture<Chunk> getChunkAtAsync(Location loc) {
+ return getChunkAtAsync((int)loc.getX() >> 4, (int)Math.floor(loc.getZ()) >> 4, true);
+ return getChunkAtAsync((int)Math.floor(loc.getX()) >> 4, (int)Math.floor(loc.getZ()) >> 4, true);
+ }
+
+ /**
@ -279,7 +279,7 @@ index 807bd7fc..61f2cd9a 100644
+ * @return Future that will resolve when the chunk is loaded
+ */
+ public default java.util.concurrent.CompletableFuture<Chunk> getChunkAtAsync(Location loc, boolean gen) {
+ return getChunkAtAsync((int)loc.getX() >> 4, (int)Math.floor(loc.getZ()) >> 4, gen);
+ return getChunkAtAsync((int)Math.floor(loc.getX()) >> 4, (int)Math.floor(loc.getZ()) >> 4, gen);
+ }
+
+ /**
@ -398,5 +398,5 @@ index 2dd7a03c..59787c47 100644
* Returns a list of entities within a bounding box centered around this
* entity
--
2.20.1
2.21.0