aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/api/0102-Location.toBlockLocation-toCenterLocation.patch
blob: c86b874f5f808b4933c5df1666d4245ba777a589 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
From 0000000000000000000000000000000000000000 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/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 251d26e6870490abd3e915c5e7c06ce1075a24ab..24a872dfc8cf1f4a567b6ebd5a5e742593616ede 100644
--- a/src/main/java/org/bukkit/Location.java
+++ b/src/main/java/org/bukkit/Location.java
@@ -534,6 +534,32 @@ public class Location implements Cloneable, ConfigurationSerializable, io.paperm
     }
 
     public boolean isChunkLoaded() { return this.getWorld().isChunkLoaded(locToBlock(x) >> 4, locToBlock(z) >> 4); } // Paper
+
+    // Paper start - expand Location API
+    /**
+     * @return A new location where X/Y/Z are on the Block location (integer value of X/Y/Z)
+     */
+    @NotNull
+    public Location toBlockLocation() {
+        Location blockLoc = clone();
+        blockLoc.setX(getBlockX());
+        blockLoc.setY(getBlockY());
+        blockLoc.setZ(getBlockZ());
+        return blockLoc;
+    }
+    /**
+     * @return A new location where X/Y/Z are the center of the block
+     */
+    @NotNull
+    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 - expand Location API
+
     @Override
     public boolean equals(Object obj) {
         if (obj == null) {