1
0
Fork 0
mirror of https://github.com/PaperMC/Paper.git synced 2024-12-22 06:25:15 +01:00
PaperMC/patches/api/0125-Expand-Location-Manipulation-API.patch

72 lines
2.5 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Wed, 25 Jul 2018 01:36:07 -0400
Subject: [PATCH] Expand Location Manipulation API
Adds set(x, y, z), add(base, x, y, z), subtract(base, x, y, z);
diff --git a/src/main/java/org/bukkit/Location.java b/src/main/java/org/bukkit/Location.java
2024-10-22 18:23:19 +02:00
index fe2e0939df61b1f59d12adf3f760f1d619bb3de3..56fd66a3fb5f6e33812d2981cd192d317453a0f5 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/Location.java
+++ b/src/main/java/org/bukkit/Location.java
@@ -545,6 +545,59 @@ public class Location implements Cloneable, ConfigurationSerializable, io.paperm
2021-06-11 14:02:28 +02:00
public boolean isChunkLoaded() { return this.getWorld().isChunkLoaded(locToBlock(x) >> 4, locToBlock(z) >> 4); } // Paper
+ // Paper start - expand location manipulation API
2021-06-11 14:02:28 +02:00
+
+ /**
+ * Sets the position of this Location and returns itself
+ * <p>
2021-06-11 14:02:28 +02:00
+ * This mutates this object, clone first.
+ *
2021-06-11 14:02:28 +02:00
+ * @param x X coordinate
+ * @param y Y coordinate
+ * @param z Z coordinate
+ * @return self (not cloned)
+ */
+ @NotNull
+ public Location set(double x, double y, double z) {
+ this.x = x;
+ this.y = y;
+ this.z = z;
+ return this;
+ }
+
+ /**
+ * Takes the x/y/z from base and adds the specified x/y/z to it and returns self
+ * <p>
2021-06-11 14:02:28 +02:00
+ * This mutates this object, clone first.
+ *
2021-06-11 14:02:28 +02:00
+ * @param base The base coordinate to modify
+ * @param x X coordinate to add to base
+ * @param y Y coordinate to add to base
+ * @param z Z coordinate to add to base
+ * @return self (not cloned)
+ */
+ @NotNull
+ public Location add(@NotNull Location base, double x, double y, double z) {
+ return this.set(base.x + x, base.y + y, base.z + z);
+ }
+
+ /**
+ * Takes the x/y/z from base and subtracts the specified x/y/z to it and returns self
+ * <p>
2021-06-11 14:02:28 +02:00
+ * This mutates this object, clone first.
+ *
2021-06-11 14:02:28 +02:00
+ * @param base The base coordinate to modify
+ * @param x X coordinate to subtract from base
+ * @param y Y coordinate to subtract from base
+ * @param z Z coordinate to subtract from base
+ * @return self (not cloned)
+ */
+ @NotNull
+ public Location subtract(@NotNull Location base, double x, double y, double z) {
+ return this.set(base.x - x, base.y - y, base.z - z);
+ }
+ // Paper end - expand location manipulation API
2021-06-11 14:02:28 +02:00
+
// Paper start - expand Location API
2021-06-11 14:02:28 +02:00
/**
* @return A new location where X/Y/Z are on the Block location (integer value of X/Y/Z)