PaperMC/patches/server/0036-Entity-Origin-API.patch

122 lines
5.6 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
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
2024-10-22 20:04:31 +02:00
index d82f4255faac84ce6af47e86707f5c035529ab5d..a31371dd479f5d87ff62728504563815bb5e22f8 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
2024-10-22 20:04:31 +02:00
@@ -2212,6 +2212,15 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
2022-06-07 21:15:06 +02:00
entity.updateDynamicGameEventListener(DynamicGameEventListener::add);
entity.inWorld = true; // CraftBukkit - Mark entity as in world
2021-06-18 05:37:23 +02:00
entity.valid = true; // CraftBukkit
+ // Paper start - Entity origin API
+ if (entity.getOriginVector() == null) {
+ entity.setOrigin(entity.getBukkitEntity().getLocation());
2021-06-11 14:02:28 +02:00
+ }
+ // 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 - Entity origin API
2021-06-11 14:02:28 +02:00
}
2021-06-18 05:37:23 +02:00
public void onTrackingEnd(Entity entity) {
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
2024-10-22 20:04:31 +02:00
index c8b8102d84119dfb6093f4b79aa3124c594f9a88..e97853cbfa6da8ecdb4c92cf634831492e1fc7e3 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
2024-10-22 20:04:31 +02:00
@@ -331,7 +331,27 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
public long activatedTick = Integer.MIN_VALUE;
public void inactiveTick() { }
// Spigot end
+ // Paper start - Entity origin API
+ @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 - Entity origin API
public float getBukkitYaw() {
return this.yRot;
}
2024-10-22 20:04:31 +02:00
@@ -2269,6 +2289,15 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
2023-12-05 20:39:26 +01:00
this.bukkitEntity.storeBukkitValues(nbttagcompound);
2021-06-11 14:02:28 +02:00
}
// CraftBukkit end
+ // Paper start
2021-06-11 14:02:28 +02:00
+ if (this.origin != null) {
+ UUID originWorld = this.originWorld != null ? this.originWorld : this.level != null ? this.level.getWorld().getUID() : null;
+ if (originWorld != null) {
2023-12-05 20:39:26 +01:00
+ nbttagcompound.putUUID("Paper.OriginWorld", originWorld);
+ }
2023-12-05 20:39:26 +01:00
+ nbttagcompound.put("Paper.Origin", this.newDoubleList(origin.getX(), origin.getY(), origin.getZ()));
2021-06-11 14:02:28 +02:00
+ }
+ // Paper end
2023-12-05 20:39:26 +01:00
return nbttagcompound;
2021-06-11 14:02:28 +02:00
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Saving entity NBT");
2024-10-22 20:04:31 +02:00
@@ -2397,6 +2426,20 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
2021-06-11 14:02:28 +02:00
}
// CraftBukkit end
+ // Paper start
+ ListTag originTag = nbt.getList("Paper.Origin", net.minecraft.nbt.Tag.TAG_DOUBLE);
2021-06-11 14:02:28 +02:00
+ if (!originTag.isEmpty()) {
+ UUID originWorld = null;
2021-06-12 00:37:16 +02:00
+ if (nbt.contains("Paper.OriginWorld")) {
+ originWorld = nbt.getUUID("Paper.OriginWorld");
+ } else if (this.level != null) {
+ originWorld = this.level.getWorld().getUID();
2021-06-11 14:02:28 +02:00
+ }
+ this.originWorld = originWorld;
2021-06-17 19:11:00 +02:00
+ origin = new org.bukkit.util.Vector(originTag.getDouble(0), originTag.getDouble(1), originTag.getDouble(2));
2021-06-11 14:02:28 +02:00
+ }
+ // 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/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
2024-10-22 20:04:31 +02:00
index 978397e517a6fdb24c7d2b3f242545af07deeab0..ea27931d01c1f3c721b2f7ec12d41ea843fa158a 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
2024-10-22 20:04:31 +02:00
@@ -964,4 +964,21 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
return this.spigot;
2021-06-11 14:02:28 +02:00
}
// Spigot end
2021-06-11 14:02:28 +02:00
+
+ // Paper start - entity origin API
2021-06-11 14:02:28 +02:00
+ @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);
2021-06-11 14:02:28 +02:00
+ }
+ // Paper end - entity origin API
2021-06-11 14:02:28 +02:00
}