Paper/Spigot-Server-Patches/0023-Entity-Origin-API.patch

140 lines
6.5 KiB
Diff
Raw Normal View History

2018-07-30 04:16:15 +02:00
From c1f35d2b808d0f11da561d02d9ba2244d6821866 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
2018-07-30 04:16:15 +02:00
index daf83a8b12..674ca3304d 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -160,6 +160,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
2017-11-08 17:13:57 +01:00
public org.bukkit.projectiles.ProjectileSource projectileSource; // For projectiles only
public boolean forceExplosionKnockback; // 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;
2018-07-30 04:16:15 +02:00
@@ -1605,6 +1606,11 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
}
}
+ // Paper start - Save the entity's origin location
+ if (origin != null) {
2016-05-12 04:07:46 +02:00
+ nbttagcompound.set("Paper.Origin", this.createList(origin.getX(), origin.getY(), origin.getZ()));
+ }
+ // Paper end
2016-05-12 04:07:46 +02:00
return nbttagcompound;
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.a(throwable, "Saving entity NBT");
2018-07-30 04:16:15 +02:00
@@ -1747,6 +1753,13 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
}
// CraftBukkit end
+ // Paper start - Restore the entity's origin location
+ NBTTagList originTag = nbttagcompound.getList("Paper.Origin", 6);
+ if (!originTag.isEmpty()) {
2017-05-14 20:05:01 +02:00
+ origin = new 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");
2018-07-30 04:16:15 +02:00
@@ -1822,6 +1835,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
2016-05-12 04:07:46 +02:00
2016-06-09 05:57:14 +02:00
protected abstract void b(NBTTagCompound nbttagcompound);
2016-05-12 04:07:46 +02:00
2016-06-09 05:57:14 +02:00
+ protected NBTTagList createList(double... adouble) { return a(adouble); } // Paper - OBFHELPER
2016-05-12 04:07:46 +02:00
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
2018-07-30 04:16:15 +02:00
index 5e01aa0f85..33bc46b054 100644
--- a/src/main/java/net/minecraft/server/EntityFallingBlock.java
+++ b/src/main/java/net/minecraft/server/EntityFallingBlock.java
@@ -249,6 +249,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
2018-07-30 04:16:15 +02:00
index 5ceb3f2068..87f3205f82 100644
--- a/src/main/java/net/minecraft/server/EntityTNTPrimed.java
+++ b/src/main/java/net/minecraft/server/EntityTNTPrimed.java
2017-05-14 20:05:01 +02:00
@@ -109,6 +109,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
}
2016-11-17 03:23:38 +01:00
@Nullable
2017-05-14 20:05:01 +02:00
diff --git a/src/main/java/net/minecraft/server/NBTTagList.java b/src/main/java/net/minecraft/server/NBTTagList.java
2018-07-30 04:16:15 +02:00
index a8280acf94..38dd8f17a6 100644
2017-05-14 20:05:01 +02:00
--- a/src/main/java/net/minecraft/server/NBTTagList.java
+++ b/src/main/java/net/minecraft/server/NBTTagList.java
@@ -182,6 +182,7 @@ public class NBTTagList extends NBTList<NBTBase> {
2017-05-14 20:05:01 +02:00
return new int[0];
}
+ public final double getDoubleAt(int i) { return this.k(i); } // Paper - OBFHELPER
public double k(int i) {
2017-05-14 20:05:01 +02:00
if (i >= 0 && i < this.list.size()) {
NBTBase nbtbase = (NBTBase) this.list.get(i);
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
2018-07-30 04:16:15 +02:00
index d0516b0885..6bb52c7d4d 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
2018-07-29 18:42:07 +02:00
@@ -951,6 +951,12 @@ public abstract class World implements GeneratorAccess, IIBlockAccess, AutoClose
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
2018-07-30 04:16:15 +02:00
index f09251eec8..34246369c5 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
@@ -777,4 +777,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
}
--
2.18.0