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-07-17 19:24:53 +02:00
|
|
|
index eb98bb1bd76869fd76b34885223c8e57a04e0c51..754045e71f180862fa57fd1c97e5d7deb1d788e6 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-06-13 19:12:48 +02:00
|
|
|
@@ -2141,6 +2141,15 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
2022-06-07 21:15:06 +02:00
|
|
|
entity.updateDynamicGameEventListener(DynamicGameEventListener::add);
|
2023-12-06 22:59:39 +01:00
|
|
|
entity.inWorld = true; // CraftBukkit - Mark entity as in world
|
2021-06-18 05:37:23 +02:00
|
|
|
entity.valid = true; // CraftBukkit
|
2024-01-24 11:45:17 +01:00
|
|
|
+ // Paper start - Entity origin API
|
2021-06-16 07:36:02 +02:00
|
|
|
+ if (entity.getOriginVector() == null) {
|
|
|
|
+ entity.setOrigin(entity.getBukkitEntity().getLocation());
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
2021-06-22 12:54:49 +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()));
|
|
|
|
+ }
|
2024-01-24 11:45:17 +01:00
|
|
|
+ // 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-06-13 22:14:13 +02:00
|
|
|
index 63f45a77c8511e05954030cf117c5e4cda0a518f..dbe5239b1a1769ef9f2ef66c32b1a68cd684428e 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-06-13 19:12:48 +02:00
|
|
|
@@ -328,7 +328,27 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
2021-12-03 22:28:15 +01:00
|
|
|
public long activatedTick = Integer.MIN_VALUE;
|
|
|
|
public void inactiveTick() { }
|
|
|
|
// Spigot end
|
2024-01-24 11:45:17 +01:00
|
|
|
+ // Paper start - Entity origin API
|
2021-06-16 07:36:02 +02:00
|
|
|
+ @javax.annotation.Nullable
|
|
|
|
+ private org.bukkit.util.Vector origin;
|
|
|
|
+ @javax.annotation.Nullable
|
|
|
|
+ private UUID originWorld;
|
2024-01-24 11:45:17 +01:00
|
|
|
|
2021-06-16 07:36:02 +02:00
|
|
|
+ public void setOrigin(@javax.annotation.Nonnull Location location) {
|
|
|
|
+ this.origin = location.toVector();
|
|
|
|
+ this.originWorld = location.getWorld().getUID();
|
|
|
|
+ }
|
2024-01-24 11:45:17 +01:00
|
|
|
+
|
2021-06-16 07:36:02 +02:00
|
|
|
+ @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;
|
|
|
|
+ }
|
2024-01-24 11:45:17 +01:00
|
|
|
+ // Paper end - Entity origin API
|
2021-12-03 22:28:15 +01:00
|
|
|
public float getBukkitYaw() {
|
|
|
|
return this.yRot;
|
|
|
|
}
|
2024-06-13 19:12:48 +02:00
|
|
|
@@ -2153,6 +2173,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
|
2024-01-24 11:45:17 +01:00
|
|
|
+ // Paper start
|
2021-06-11 14:02:28 +02:00
|
|
|
+ if (this.origin != null) {
|
2021-06-22 12:54:49 +02:00
|
|
|
+ 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);
|
2021-06-22 12:54:49 +02:00
|
|
|
+ }
|
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-06-13 19:12:48 +02:00
|
|
|
@@ -2280,6 +2309,20 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
|
2024-01-24 11:45:17 +01:00
|
|
|
+ // Paper start
|
2024-01-04 14:38:26 +01:00
|
|
|
+ ListTag originTag = nbt.getList("Paper.Origin", net.minecraft.nbt.Tag.TAG_DOUBLE);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ if (!originTag.isEmpty()) {
|
2021-06-21 11:04:18 +02:00
|
|
|
+ UUID originWorld = null;
|
2021-06-12 00:37:16 +02:00
|
|
|
+ if (nbt.contains("Paper.OriginWorld")) {
|
2021-06-16 07:36:02 +02:00
|
|
|
+ originWorld = nbt.getUUID("Paper.OriginWorld");
|
2021-06-21 11:04:18 +02:00
|
|
|
+ } else if (this.level != null) {
|
|
|
|
+ originWorld = this.level.getWorld().getUID();
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
2021-06-16 07:36:02 +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-06-13 19:12:48 +02:00
|
|
|
index 269326e7689eba91bcfd3475006e8cbf8f5694ef..7b45a1216ff824f1b528bb5759d10b70858832a1 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-06-13 19:12:48 +02:00
|
|
|
@@ -963,4 +963,21 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
2024-04-06 22:38:37 +02:00
|
|
|
return this.spigot;
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
2024-04-06 22:38:37 +02:00
|
|
|
// Spigot end
|
2021-06-11 14:02:28 +02:00
|
|
|
+
|
2024-04-06 22:38:37 +02:00
|
|
|
+ // Paper start - entity origin API
|
2021-06-11 14:02:28 +02:00
|
|
|
+ @Override
|
|
|
|
+ public Location getOrigin() {
|
2021-06-16 07:36:02 +02:00
|
|
|
+ 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
|
|
|
+ }
|
2024-04-06 22:38:37 +02:00
|
|
|
+ // Paper end - entity origin API
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|