aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0025-Entity-Origin-API.patch
blob: 1e4a5b7dca2ab90c6e48a14c9bc79cf8026753b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
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/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index e85172eb69b04746eab08abf213dcd02cd4513ee..bfe36be070677d215eadd3ad38f93c6bddab0b75 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -167,6 +167,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
     public org.bukkit.projectiles.ProjectileSource projectileSource; // For projectiles only
     public boolean forceExplosionKnockback; // SPIGOT-949
     public Timing tickTimer = MinecraftTimings.getEntityTimings(this); // Paper
+    public org.bukkit.Location origin; // Paper
     // Spigot start
     public final org.spigotmc.ActivationRange.ActivationType activationType = org.spigotmc.ActivationRange.initializeEntityActivationType(this);
     public final boolean defaultActivationState;
@@ -1541,6 +1542,11 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
                 this.bukkitEntity.storeBukkitValues(nbttagcompound);
             }
             // CraftBukkit end
+            // Paper start - Save the entity's origin location
+            if (this.origin != null) {
+                nbttagcompound.set("Paper.Origin", this.createList(origin.getX(), origin.getY(), origin.getZ()));
+            }
+            // Paper end
             return nbttagcompound;
         } catch (Throwable throwable) {
             CrashReport crashreport = CrashReport.a(throwable, "Saving entity NBT");
@@ -1657,6 +1663,13 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
             this.getBukkitEntity().readBukkitValues(nbttagcompound);
             // CraftBukkit end
 
+            // Paper start - Restore the entity's origin location
+            NBTTagList originTag = nbttagcompound.getList("Paper.Origin", 6);
+            if (!originTag.isEmpty()) {
+                origin = new org.bukkit.Location(world.getWorld(), originTag.getDoubleAt(0), originTag.getDoubleAt(1), originTag.getDoubleAt(2));
+            }
+            // Paper end
+
         } catch (Throwable throwable) {
             CrashReport crashreport = CrashReport.a(throwable, "Loading entity NBT");
             CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Entity being loaded");
@@ -1718,6 +1731,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
 
     protected abstract void saveData(NBTTagCompound nbttagcompound);
 
+    protected NBTTagList createList(double... adouble) { return a(adouble); } // Paper - OBFHELPER
     protected NBTTagList a(double... adouble) {
         NBTTagList nbttaglist = new NBTTagList();
         double[] adouble1 = adouble;
diff --git a/src/main/java/net/minecraft/server/EntityFallingBlock.java b/src/main/java/net/minecraft/server/EntityFallingBlock.java
index 8c51b3060114a24249962c2d6142166ac8600a0a..7c308e0912fb60f8dcdfb36c8a8c8718231858bc 100644
--- a/src/main/java/net/minecraft/server/EntityFallingBlock.java
+++ b/src/main/java/net/minecraft/server/EntityFallingBlock.java
@@ -254,6 +254,14 @@ public class EntityFallingBlock extends Entity {
             this.block = Blocks.SAND.getBlockData();
         }
 
+        // Paper start - Try and load origin location from the old NBT tags for backwards compatibility
+        if (nbttagcompound.hasKey("SourceLoc_x")) {
+            int srcX = nbttagcompound.getInt("SourceLoc_x");
+            int srcY = nbttagcompound.getInt("SourceLoc_y");
+            int srcZ = nbttagcompound.getInt("SourceLoc_z");
+            origin = new org.bukkit.Location(world.getWorld(), srcX, srcY, srcZ);
+        }
+        // Paper end
     }
 
     public void a(boolean flag) {
diff --git a/src/main/java/net/minecraft/server/EntityTNTPrimed.java b/src/main/java/net/minecraft/server/EntityTNTPrimed.java
index b5900e1cad8137954d5fa4fde10b4afb64fb6412..0f4923bce392c8e46f6b256f47d23e15b08e6d62 100644
--- a/src/main/java/net/minecraft/server/EntityTNTPrimed.java
+++ b/src/main/java/net/minecraft/server/EntityTNTPrimed.java
@@ -104,6 +104,14 @@ public class EntityTNTPrimed extends Entity {
     @Override
     protected void loadData(NBTTagCompound nbttagcompound) {
         this.setFuseTicks(nbttagcompound.getShort("Fuse"));
+        // Paper start - Try and load origin location from the old NBT tags for backwards compatibility
+        if (nbttagcompound.hasKey("SourceLoc_x")) {
+            int srcX = nbttagcompound.getInt("SourceLoc_x");
+            int srcY = nbttagcompound.getInt("SourceLoc_y");
+            int srcZ = nbttagcompound.getInt("SourceLoc_z");
+            origin = new org.bukkit.Location(world.getWorld(), srcX, srcY, srcZ);
+        }
+        // Paper end
     }
 
     @Nullable
diff --git a/src/main/java/net/minecraft/server/NBTTagList.java b/src/main/java/net/minecraft/server/NBTTagList.java
index ad8a506bb430b26fe147a657a2f826daf9bf4d45..ad4807e0bdd6409bd798f995da8f43cec1d0b385 100644
--- a/src/main/java/net/minecraft/server/NBTTagList.java
+++ b/src/main/java/net/minecraft/server/NBTTagList.java
@@ -188,6 +188,7 @@ public class NBTTagList extends NBTList<NBTBase> {
         return new int[0];
     }
 
+    public final double getDoubleAt(int i) { return this.h(i); } // Paper - OBFHELPER
     public double h(int i) {
         if (i >= 0 && i < this.list.size()) {
             NBTBase nbtbase = (NBTBase) this.list.get(i);
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
index df63ea6680e9619e09477ed44a021e128314436c..118f2b80193bf59139c46b811be96edda4ae0014 100644
--- a/src/main/java/net/minecraft/server/WorldServer.java
+++ b/src/main/java/net/minecraft/server/WorldServer.java
@@ -1087,6 +1087,11 @@ public class WorldServer extends World implements GeneratorAccessSeed {
                 this.navigators.add(((EntityInsentient) entity).getNavigation());
             }
             entity.valid = true; // CraftBukkit
+            // Paper start - Set origin location when the entity is being added to the world
+            if (entity.origin == null) {
+                entity.origin = entity.getBukkitEntity().getLocation();
+            }
+            // Paper end
         }
 
     }
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
index e867168be3c17548490f30944ca56a635cc3b054..19669d7354d8cfa723e614ac3b471e703ee7feee 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
@@ -1016,4 +1016,12 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
         return spigot;
     }
     // Spigot end
+
+    // Paper start
+    @Override
+    public Location getOrigin() {
+        Location origin = getHandle().origin;
+        return origin == null ? null : origin.clone();
+    }
+    // Paper end
 }