Paper/Spigot-API-Patches/0126-Expand-Location-Manipulation-API.patch
Spottedleaf 5c7081fecc Update upstream & fix some chunk related issues (#2177)
* Updated Upstream (Bukkit/CraftBukkit)

Upstream has released updates that appears to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
45690fe9 SPIGOT-5047: Correct slot types for 1.14 inventories

CraftBukkit Changes:
4090d01f SPIGOT-5047: Correct slot types for 1.14 inventories
e8c08362 SPIGOT-5046: World#getLoadedChunks returning inaccessible cached chunks.
d445af3b SPIGOT-5067: Add item meta for 1.14 spawn eggs

* Bring Chunk load checks in-line with spigot

As of the last upstream merge spigot now checks ticket level status
when returning loaded chunks for a world from api. Now our checks
will respect that decision.

* Fix spawn ticket levels

Vanilla would keep the inner chunks of spawn available for ticking,
however my changes made all chunks non-ticking. Resolve by changing
ticket levels for spawn chunks inside the border to respect this
behavior.


* Make World#getChunkIfLoadedImmediately return only entity ticking chunks

Mojang appears to be using chunks with level > 33 (non-ticking chunks)
as cached chunks and not actually loaded chunks.

* Bring all loaded checks in line with spigot

Loaded chunks must be at least border  chunks, or level <= 33
2019-06-14 03:27:40 +01:00

70 lines
2.3 KiB
Diff

From 979c3b5b3d9f1225b81882524a6c19f6f57dcf76 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
index b226d7e4c..884862ab7 100644
--- a/src/main/java/org/bukkit/Location.java
+++ b/src/main/java/org/bukkit/Location.java
@@ -546,6 +546,54 @@ public class Location implements Cloneable, ConfigurationSerializable {
public boolean isChunkLoaded() { return this.getWorld().isChunkLoaded(locToBlock(x) >> 4, locToBlock(z) >> 4); } // Paper
// Paper start
+
+ /**
+ * Sets the position of this Location and returns itself
+ *
+ * This mutates this object, clone first.
+ * @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
+ *
+ * This mutates this object, clone first.
+ * @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
+ *
+ * This mutates this object, clone first.
+ * @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);
+ }
+
/**
* @return A new location where X/Y/Z are on the Block location (integer value of X/Y/Z)
*/
--
2.21.0