2020-04-02 21:07:06 +00:00
|
|
|
From d1e4f01c2240314cf9fb94f6a4175a7b61bd4626 Mon Sep 17 00:00:00 2001
|
2018-05-25 01:02:38 +00:00
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Thu, 24 May 2018 21:01:13 -0400
|
2018-05-25 01:06:06 +00:00
|
|
|
Subject: [PATCH] Location.toBlockLocation/toCenterLocation()
|
2018-05-25 01:02:38 +00:00
|
|
|
|
|
|
|
Convert location objects to their block coordinates, or the center of the block
|
|
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/Location.java b/src/main/java/org/bukkit/Location.java
|
2020-04-02 21:07:06 +00:00
|
|
|
index 6c8b8eddc..f61bf28af 100644
|
2018-05-25 01:02:38 +00:00
|
|
|
--- a/src/main/java/org/bukkit/Location.java
|
|
|
|
+++ b/src/main/java/org/bukkit/Location.java
|
2019-05-06 02:58:04 +00:00
|
|
|
@@ -534,6 +534,31 @@ public class Location implements Cloneable, ConfigurationSerializable {
|
2018-05-25 01:02:38 +00:00
|
|
|
}
|
|
|
|
|
2019-05-06 02:58:04 +00:00
|
|
|
public boolean isChunkLoaded() { return this.getWorld().isChunkLoaded(locToBlock(x) >> 4, locToBlock(z) >> 4); } // Paper
|
2018-05-25 01:02:38 +00:00
|
|
|
+
|
|
|
|
+ // Paper start
|
|
|
|
+ /**
|
|
|
|
+ * @return A new location where X/Y/Z are on the Block location (integer value of X/Y/Z)
|
|
|
|
+ */
|
2019-03-20 00:28:15 +00:00
|
|
|
+ @NotNull
|
2018-05-25 01:02:38 +00:00
|
|
|
+ public Location toBlockLocation() {
|
2018-05-25 01:06:06 +00:00
|
|
|
+ Location blockLoc = clone();
|
|
|
|
+ blockLoc.setX(getBlockX());
|
|
|
|
+ blockLoc.setY(getBlockY());
|
|
|
|
+ blockLoc.setZ(getBlockZ());
|
|
|
|
+ return blockLoc;
|
2018-05-25 01:02:38 +00:00
|
|
|
+ }
|
|
|
|
+ /**
|
2018-05-25 01:06:06 +00:00
|
|
|
+ * @return A new location where X/Y/Z are the center of the block
|
2018-05-25 01:02:38 +00:00
|
|
|
+ */
|
2019-03-20 00:28:15 +00:00
|
|
|
+ @NotNull
|
2018-05-25 01:06:06 +00:00
|
|
|
+ public Location toCenterLocation() {
|
|
|
|
+ Location centerLoc = clone();
|
|
|
|
+ centerLoc.setX(getBlockX() + 0.5);
|
|
|
|
+ centerLoc.setY(getBlockY() + 0.5);
|
|
|
|
+ centerLoc.setZ(getBlockZ() + 0.5);
|
|
|
|
+ return centerLoc;
|
2018-05-25 01:02:38 +00:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object obj) {
|
|
|
|
if (obj == null) {
|
|
|
|
--
|
2020-04-02 21:07:06 +00:00
|
|
|
2.25.1
|
2018-05-25 01:02:38 +00:00
|
|
|
|