Paper/Spigot-API-Patches/0102-Location.toBlockLocation-toCenterLocation.patch
Zach Brown 70ce6ce831
Move version command update checking to the implementation
This makes it easier for downstream projects (forks) to replace the
version fetching system with their own. It is as simple as implementing
an interface and overriding the default implementation of
org.bukkit.UnsafeValues#getVersionFetcher()

It also makes it easier for us to organize things like the version
history feature.

Lastly I have updated the paper implementation to check against the site
API rather than against jenkins.
2019-05-27 04:13:41 -05:00

47 lines
1.5 KiB
Diff

From bf76c03cf7730ea8d7f3ae692cb406f28326d9ef 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 6021e672..4f695faf 100644
--- a/src/main/java/org/bukkit/Location.java
+++ b/src/main/java/org/bukkit/Location.java
@@ -534,6 +534,31 @@ public class Location implements Cloneable, ConfigurationSerializable {
}
public boolean isChunkLoaded() { return this.getWorld().isChunkLoaded(locToBlock(x) >> 4, locToBlock(z) >> 4); } // Paper
+
+ // Paper start
+ /**
+ * @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
@Override
public boolean equals(Object obj) {
if (obj == null) {
--
2.21.0