From 9ce6c64ce6774a54002489191fab5795f70b1567 Mon Sep 17 00:00:00 2001 From: Byteflux 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 ca21afc199..af019fc3f1 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 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; @@ -1528,6 +1529,11 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke } } + // 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"); @@ -1649,6 +1655,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()) { + 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"); @@ -1726,6 +1739,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke 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 55591fbe05..90becdfdec 100644 --- a/src/main/java/net/minecraft/server/EntityFallingBlock.java +++ b/src/main/java/net/minecraft/server/EntityFallingBlock.java @@ -245,6 +245,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 e3001570f9..e0535604b6 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 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 } @Nullable diff --git a/src/main/java/net/minecraft/server/NBTTagList.java b/src/main/java/net/minecraft/server/NBTTagList.java index ce510c4867..b7c94fe238 100644 --- a/src/main/java/net/minecraft/server/NBTTagList.java +++ b/src/main/java/net/minecraft/server/NBTTagList.java @@ -161,6 +161,7 @@ public class NBTTagList extends NBTList { 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/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java index c1ad2626a7..852de0d625 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java @@ -945,4 +945,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.21.0