Paper/patches/server/0027-Entity-Origin-API.patch
Nassim Jahnke 385f313a8b
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#8092)
Upstream has released updates that appear 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:
d41796de SPIGOT-7071: Add Player#stopSound(SoundCategory category)
61dae5b2 SPIGOT-7011, SPIGOT-7065: Overhaul of structures

CraftBukkit Changes:
991aeda12 SPIGOT-1729, SPIGOT-7090: Keep precision in teleportation between worlds
5c9a5f628 SPIGOT-7071: Add Player#stopSound(SoundCategory category)
68f888ded SPIGOT-7011, SPIGOT-7065: Overhaul of structures
0231a3746 Remove outdated build delay.

Spigot Changes:
475f6008 Rebuild patches
8ce1761f Rebuild patches
2022-07-04 16:38:06 +02:00

160 lines
7.5 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Byteflux <byte@byteflux.net>
Date: Tue, 1 Mar 2016 23:45:08 -0600
Subject: [PATCH] Entity Origin API
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index a14386502e9b3ccec23233db2ddfedeec94ffb91..bae0b45aba0b04a229f5e098d13a5e6383524e88 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -2108,6 +2108,15 @@ public class ServerLevel extends Level implements WorldGenLevel {
entity.updateDynamicGameEventListener(DynamicGameEventListener::add);
entity.valid = true; // CraftBukkit
+ // Paper start - Set origin location when the entity is being added to the world
+ if (entity.getOriginVector() == null) {
+ entity.setOrigin(entity.getBukkitEntity().getLocation());
+ }
+ // Default to current world if unknown, gross assumption but entities rarely change world
+ if (entity.getOriginWorld() == null) {
+ entity.setOrigin(entity.getOriginVector().toLocation(getWorld()));
+ }
+ // Paper end
}
public void onTrackingEnd(Entity entity) {
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index e6a884fb477f66502c3ce3091e8123f3370188ff..95dbf90ec1ce3f470eaaf99115668d5bd1c7bea1 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -304,7 +304,27 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
public long activatedTick = Integer.MIN_VALUE;
public void inactiveTick() { }
// Spigot end
+ // Paper start
+ @javax.annotation.Nullable
+ private org.bukkit.util.Vector origin;
+ @javax.annotation.Nullable
+ private UUID originWorld;
+
+ public void setOrigin(@javax.annotation.Nonnull Location location) {
+ this.origin = location.toVector();
+ this.originWorld = location.getWorld().getUID();
+ }
+ @javax.annotation.Nullable
+ public org.bukkit.util.Vector getOriginVector() {
+ return this.origin != null ? this.origin.clone() : null;
+ }
+
+ @javax.annotation.Nullable
+ public UUID getOriginWorld() {
+ return this.originWorld;
+ }
+ // Paper end
public float getBukkitYaw() {
return this.yRot;
}
@@ -1852,6 +1872,15 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
this.bukkitEntity.storeBukkitValues(nbt);
}
// CraftBukkit end
+ // Paper start - Save the entity's origin location
+ if (this.origin != null) {
+ UUID originWorld = this.originWorld != null ? this.originWorld : this.level != null ? this.level.getWorld().getUID() : null;
+ if (originWorld != null) {
+ nbt.putUUID("Paper.OriginWorld", originWorld);
+ }
+ nbt.put("Paper.Origin", this.newDoubleList(origin.getX(), origin.getY(), origin.getZ()));
+ }
+ // Paper end
return nbt;
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Saving entity NBT");
@@ -1976,6 +2005,20 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
}
// CraftBukkit end
+ // Paper start - Restore the entity's origin location
+ ListTag originTag = nbt.getList("Paper.Origin", 6);
+ if (!originTag.isEmpty()) {
+ UUID originWorld = null;
+ if (nbt.contains("Paper.OriginWorld")) {
+ originWorld = nbt.getUUID("Paper.OriginWorld");
+ } else if (this.level != null) {
+ originWorld = this.level.getWorld().getUID();
+ }
+ this.originWorld = originWorld;
+ origin = new org.bukkit.util.Vector(originTag.getDouble(0), originTag.getDouble(1), originTag.getDouble(2));
+ }
+ // Paper end
+
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Loading entity NBT");
CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Entity being loaded");
diff --git a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
index bd357c3e6fcbd82f3c53ecc8dab46aa5d3708bc2..6c4be7da19d0d61f35942558d438587853231aaa 100644
--- a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
+++ b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
@@ -337,6 +337,14 @@ public class FallingBlockEntity extends Entity {
this.blockState = Blocks.SAND.defaultBlockState();
}
+ // Paper start - Try and load origin location from the old NBT tags for backwards compatibility
+ if (nbt.contains("SourceLoc_x")) {
+ int srcX = nbt.getInt("SourceLoc_x");
+ int srcY = nbt.getInt("SourceLoc_y");
+ int srcZ = nbt.getInt("SourceLoc_z");
+ this.setOrigin(new org.bukkit.Location(level.getWorld(), srcX, srcY, srcZ));
+ }
+ // Paper end
}
public void setHurtsEntities(float fallHurtAmount, int fallHurtMax) {
diff --git a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
index 2d4a990da2402a6c24c03e8be7e518e33db99c8f..10f8b5ff56e4c1d8300835e045abdce719a99343 100644
--- a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
+++ b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
@@ -120,6 +120,14 @@ public class PrimedTnt extends Entity {
@Override
protected void readAdditionalSaveData(CompoundTag nbt) {
this.setFuse(nbt.getShort("Fuse"));
+ // Paper start - Try and load origin location from the old NBT tags for backwards compatibility
+ if (nbt.contains("SourceLoc_x")) {
+ int srcX = nbt.getInt("SourceLoc_x");
+ int srcY = nbt.getInt("SourceLoc_y");
+ int srcZ = nbt.getInt("SourceLoc_z");
+ this.setOrigin(new org.bukkit.Location(level.getWorld(), srcX, srcY, srcZ));
+ }
+ // Paper end
}
@Nullable
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
index 64687b0e04f619576f3e7f4fec0b559408048d38..f79f2867b62e25e9bf8e1102d12bcd07c913675b 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
@@ -1166,4 +1166,21 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
return this.spigot;
}
// Spigot end
+
+ // Paper start
+ @Override
+ public Location getOrigin() {
+ Vector originVector = this.getHandle().getOriginVector();
+ if (originVector == null) {
+ return null;
+ }
+ World world = this.getWorld();
+ if (this.getHandle().getOriginWorld() != null) {
+ world = org.bukkit.Bukkit.getWorld(this.getHandle().getOriginWorld());
+ }
+
+ //noinspection ConstantConditions
+ return originVector.toLocation(world);
+ }
+ // Paper end
}