testserver/Spigot-Server-Patches/0024-Entity-Origin-API.patch

160 lines
7.0 KiB
Diff
Raw Normal View History

2016-11-17 02:23:38 +00:00
From d67a5caa6bb6004252668cda3001ccd9180c5e5a 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
2016-11-17 02:23:38 +00:00
index e0276a6..6766166 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
2016-11-17 02:23:38 +00:00
@@ -144,6 +144,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;
2016-11-17 02:23:38 +00:00
@@ -1416,6 +1417,11 @@ public abstract class Entity implements ICommandListener {
}
}
+ // Paper start - Save the entity's origin location
+ if (origin != null) {
2016-05-12 02:07:46 +00:00
+ nbttagcompound.set("Paper.Origin", this.createList(origin.getX(), origin.getY(), origin.getZ()));
+ }
+ // Paper end
2016-05-12 02:07:46 +00:00
return nbttagcompound;
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.a(throwable, "Saving entity NBT");
2016-11-17 02:23:38 +00:00
@@ -1560,6 +1566,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");
2016-11-17 02:23:38 +00:00
@@ -1584,6 +1597,7 @@ public abstract class Entity implements ICommandListener {
2016-05-12 02:07:46 +00:00
2016-06-09 03:57:14 +00:00
protected abstract void b(NBTTagCompound nbttagcompound);
2016-05-12 02:07:46 +00:00
2016-06-09 03:57:14 +00:00
+ protected NBTTagList createList(double... adouble) { return a(adouble); } // Paper - OBFHELPER
2016-05-12 02:07:46 +00: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
2016-11-17 02:23:38 +00:00
index 2ed1fb1..042670b 100644
--- a/src/main/java/net/minecraft/server/EntityFallingBlock.java
+++ b/src/main/java/net/minecraft/server/EntityFallingBlock.java
2016-11-17 02:23:38 +00:00
@@ -247,6 +247,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
2016-11-17 02:23:38 +00:00
index fd07356..25e471d 100644
--- a/src/main/java/net/minecraft/server/EntityTNTPrimed.java
+++ b/src/main/java/net/minecraft/server/EntityTNTPrimed.java
2016-11-17 02:23:38 +00:00
@@ -108,6 +108,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 02:23:38 +00:00
@Nullable
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
2016-11-17 02:23:38 +00:00
index 52171a3..4db969b 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
2016-11-17 02:23:38 +00:00
@@ -1021,6 +1021,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
2016-11-17 02:23:38 +00:00
index 72fd019..f8aabe2 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
2016-11-17 02:23:38 +00:00
@@ -672,4 +672,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
}
2016-11-17 02:23:38 +00:00
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftFallingBlock.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftFallingBlock.java
index b0a7f63..56666f1 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftFallingBlock.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftFallingBlock.java
@@ -65,4 +65,11 @@ public class CraftFallingBlock extends CraftEntity implements FallingBlock {
// 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
}
--
2016-11-13 02:21:46 +00:00
2.10.2