aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0025-Entity-Origin-API.patch
blob: 356e7cbe197f00fe2efcd30a66214d8360ba4336 (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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
From 3febea393a161f09bef588e1b62c721860f1b0ec 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 1409faa..cf08a0e 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -145,6 +145,7 @@ public abstract class Entity implements ICommandListener {
     public org.bukkit.projectiles.ProjectileSource projectileSource; // CraftBukkit - For projectiles only
     public boolean forceExplosionKnockback; // CraftBukkit - SPIGOT-949
     public Timing tickTimer = MinecraftTimings.getEntityTimings(this); // Paper
+    public Location origin; // Paper
     // Spigot start
     public final byte activationType = org.spigotmc.ActivationRange.initializeEntityActivationType(this);
     public final boolean defaultActivationState;
@@ -1373,6 +1374,11 @@ public abstract class Entity implements ICommandListener {
                 }
             }
 
+            // Paper start - Save the entity's origin location
+            if (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");
@@ -1517,6 +1523,13 @@ public abstract class Entity implements ICommandListener {
             }
             // CraftBukkit end
 
+            // Paper start - Restore the entity's origin location
+            NBTTagList originTag = nbttagcompound.getList("Paper.Origin", 6);
+            if (!originTag.isEmpty()) {
+                origin = new Location(world.getWorld(), originTag.e(0), originTag.e(1), originTag.e(2));
+            }
+            // Paper end
+
         } catch (Throwable throwable) {
             CrashReport crashreport = CrashReport.a(throwable, "Loading entity NBT");
             CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Entity being loaded");
@@ -1538,6 +1551,7 @@ public abstract class Entity implements ICommandListener {
 
     protected abstract void b(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 dbcda27..a1392d6 100644
--- a/src/main/java/net/minecraft/server/EntityFallingBlock.java
+++ b/src/main/java/net/minecraft/server/EntityFallingBlock.java
@@ -246,6 +246,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 2745c49..86f3f1f 100644
--- a/src/main/java/net/minecraft/server/EntityTNTPrimed.java
+++ b/src/main/java/net/minecraft/server/EntityTNTPrimed.java
@@ -107,6 +107,14 @@ public class EntityTNTPrimed extends Entity {
 
     protected void a(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
     }
 
     public EntityLiving getSource() {
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index e3d971c..5b3e50c 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -962,6 +962,12 @@ public abstract class World implements IBlockAccess {
         int j = MathHelper.floor(entity.locZ / 16.0D);
         boolean flag = entity.attachedToPlayer;
 
+        // 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
+
         if (entity instanceof EntityHuman) {
             flag = true;
         }
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
index 09523de..a24efd9 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
@@ -650,4 +650,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
 }
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftFallingSand.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftFallingSand.java
index ad4eb39..f6dad02 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftFallingSand.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftFallingSand.java
@@ -65,4 +65,11 @@ public class CraftFallingSand extends CraftEntity implements FallingSand {
         // Second field for EntityFallingBlock
         getHandle().ticksLived = value;
     }
+
+    // Paper start
+    @Override
+    public org.bukkit.Location getSourceLoc() {
+        return getOrigin();
+    }
+    // Paper end
 }
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftTNTPrimed.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftTNTPrimed.java
index c493c9c..93843aa 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftTNTPrimed.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftTNTPrimed.java
@@ -65,4 +65,11 @@ public class CraftTNTPrimed extends CraftEntity implements TNTPrimed {
 
         return null;
     }
+
+    // Paper start
+    @Override
+    public org.bukkit.Location getSourceLoc() {
+        return getOrigin();
+    }
+    // Paper end
 }
-- 
2.10.2