Skip to content
Permalink
Browse files

rename method for center to toCenterLocation()

  • Loading branch information...
aikar committed May 25, 2018
1 parent 45308a0 commit dab41b12cec86325473cee00b2105ab1e949f60a
@@ -1,15 +1,15 @@
From 33768a6eb01492a7ce72ab71a02afcf32ee8186b Mon Sep 17 00:00:00 2001
From c338a85f88b3d3746f11058714d76e5a963f8847 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Thu, 24 May 2018 21:01:13 -0400
Subject: [PATCH] Location.toBlockLocation
Subject: [PATCH] Location.toBlockLocation/toCenterLocation()

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
index 1ddebf3c..5c70e80d 100644
index 1ddebf3c..916238c4 100644
--- a/src/main/java/org/bukkit/Location.java
+++ b/src/main/java/org/bukkit/Location.java
@@ -492,6 +492,31 @@ public class Location implements Cloneable, ConfigurationSerializable {
@@ -492,6 +492,29 @@ public class Location implements Cloneable, ConfigurationSerializable {
}

public boolean isChunkLoaded() { return world.isChunkLoaded(locToBlock(x) >> 4, locToBlock(z) >> 4); } // Paper
@@ -19,23 +19,21 @@ index 1ddebf3c..5c70e80d 100644
+ * @return A new location where X/Y/Z are on the Block location (integer value of X/Y/Z)
+ */
+ public Location toBlockLocation() {
+ return toBlockLocation(false);
+ Location blockLoc = clone();
+ blockLoc.setX(getBlockX());
+ blockLoc.setY(getBlockY());
+ blockLoc.setZ(getBlockZ());
+ return blockLoc;
+ }
+ /**
+ * @return A new location where X/Y/Z are on the Block location (integer value of X/Y/Z), or optionally the center
+ * @return A new location where X/Y/Z are the center of the block
+ */
+ public Location toBlockLocation(boolean center) {
+ Location blockLoc = clone();
+ if (center) {
+ blockLoc.setX(getBlockX() + 0.5);
+ blockLoc.setY(getBlockY() + 0.5);
+ blockLoc.setZ(getBlockZ() + 0.5);
+ } else {
+ blockLoc.setX(getBlockX());
+ blockLoc.setY(getBlockY());
+ blockLoc.setZ(getBlockZ());
+ }
+ return blockLoc;
+ public Location toCenterLocation() {
+ Location centerLoc = clone();
+ centerLoc.setX(getBlockX() + 0.5);
+ centerLoc.setY(getBlockY() + 0.5);
+ centerLoc.setZ(getBlockZ() + 0.5);
+ return centerLoc;
+ }
+ // Paper end
@Override

0 comments on commit dab41b1

Please sign in to comment.
You can’t perform that action at this time.