Paper/Spigot-API-Patches/0102-Location.toBlockLocation-toCenterLocation.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

47 Zeilen
1.5 KiB
Diff

From 1f43185dc8047a82ea2c66403d677b4ca4f8cfc5 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 6021e6729..4f695faf4 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