2020-02-21 18:52:20 +01:00
|
|
|
From 85a4e1989ff00a6ab9e60fa579668fd022f752f1 Mon Sep 17 00:00:00 2001
|
2016-03-25 10:02:35 +01:00
|
|
|
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
|
2020-02-21 18:52:20 +01:00
|
|
|
index b8792bb6f1..1b2edca722 100644
|
2016-03-25 10:02:35 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/Entity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Entity.java
|
2019-12-11 01:56:03 +01:00
|
|
|
@@ -167,6 +167,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
|
2016-04-30 03:23:40 +02:00
|
|
|
public Timing tickTimer = MinecraftTimings.getEntityTimings(this); // Paper
|
2016-03-25 10:02:35 +01:00
|
|
|
+ public Location origin; // Paper
|
|
|
|
// Spigot start
|
2019-05-31 01:54:25 +02:00
|
|
|
public final org.spigotmc.ActivationRange.ActivationType activationType = org.spigotmc.ActivationRange.initializeEntityActivationType(this);
|
2016-03-25 10:02:35 +01:00
|
|
|
public final boolean defaultActivationState;
|
2020-02-21 18:52:20 +01:00
|
|
|
@@ -1580,6 +1581,11 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
|
2019-05-06 04:58:04 +02:00
|
|
|
this.bukkitEntity.storeBukkitValues(nbttagcompound);
|
2016-03-25 10:02:35 +01:00
|
|
|
}
|
2019-05-06 04:58:04 +02:00
|
|
|
// CraftBukkit end
|
2016-03-25 10:02:35 +01:00
|
|
|
+ // Paper start - Save the entity's origin location
|
2019-05-06 04:58:04 +02:00
|
|
|
+ if (this.origin != null) {
|
2016-05-12 04:07:46 +02:00
|
|
|
+ nbttagcompound.set("Paper.Origin", this.createList(origin.getX(), origin.getY(), origin.getZ()));
|
2016-03-25 10:02:35 +01:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
2016-05-12 04:07:46 +02:00
|
|
|
return nbttagcompound;
|
2016-03-25 10:02:35 +01:00
|
|
|
} catch (Throwable throwable) {
|
|
|
|
CrashReport crashreport = CrashReport.a(throwable, "Saving entity NBT");
|
2020-02-21 18:52:20 +01:00
|
|
|
@@ -1694,6 +1700,13 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
|
2019-05-26 03:56:30 +02:00
|
|
|
this.getBukkitEntity().readBukkitValues(nbttagcompound);
|
2016-03-25 10:02:35 +01:00
|
|
|
// CraftBukkit end
|
|
|
|
|
|
|
|
+ // Paper start - Restore the entity's origin location
|
2016-03-25 17:32:09 +01:00
|
|
|
+ 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));
|
2016-03-25 10:02:35 +01:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
} catch (Throwable throwable) {
|
|
|
|
CrashReport crashreport = CrashReport.a(throwable, "Loading entity NBT");
|
|
|
|
CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Entity being loaded");
|
2020-02-21 18:52:20 +01:00
|
|
|
@@ -1771,6 +1784,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;
|
2016-03-25 10:02:35 +01:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/EntityFallingBlock.java b/src/main/java/net/minecraft/server/EntityFallingBlock.java
|
2020-02-21 18:52:20 +01:00
|
|
|
index cb21ce0b1a..40fd012ae2 100644
|
2016-03-25 10:02:35 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/EntityFallingBlock.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntityFallingBlock.java
|
2020-01-22 03:02:07 +01:00
|
|
|
@@ -253,6 +253,14 @@ public class EntityFallingBlock extends Entity {
|
2016-03-25 10:02:35 +01:00
|
|
|
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
|
2020-02-21 18:52:20 +01:00
|
|
|
index 33c51dced7..346315acb7 100644
|
2016-03-25 10:02:35 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/EntityTNTPrimed.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntityTNTPrimed.java
|
2019-12-11 01:56:03 +01:00
|
|
|
@@ -103,6 +103,14 @@ public class EntityTNTPrimed extends Entity {
|
2019-04-24 04:34:11 +02:00
|
|
|
@Override
|
2016-03-25 10:02:35 +01:00
|
|
|
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
|
2020-02-21 18:52:20 +01:00
|
|
|
index 5406f4c40f..d778eac45d 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
|
2019-12-11 01:56:03 +01:00
|
|
|
@@ -188,6 +188,7 @@ public class NBTTagList extends NBTList<NBTBase> {
|
2017-05-14 20:05:01 +02:00
|
|
|
return new int[0];
|
|
|
|
}
|
|
|
|
|
2019-04-24 04:34:11 +02:00
|
|
|
+ public final double getDoubleAt(int i) { return this.h(i); } // Paper - OBFHELPER
|
|
|
|
public double h(int i) {
|
2017-05-14 20:05:01 +02:00
|
|
|
if (i >= 0 && i < this.list.size()) {
|
2019-01-01 04:15:55 +01:00
|
|
|
NBTBase nbtbase = (NBTBase) this.list.get(i);
|
2019-05-05 23:39:51 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
|
2020-02-21 18:52:20 +01:00
|
|
|
index 069898bad7..ce9bad42f8 100644
|
2019-05-05 23:39:51 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/WorldServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/WorldServer.java
|
2020-01-28 01:16:53 +01:00
|
|
|
@@ -1176,6 +1176,11 @@ public class WorldServer extends World {
|
2019-12-11 01:56:03 +01:00
|
|
|
this.navigators.add(((EntityInsentient) entity).getNavigation());
|
2019-05-05 23:39:51 +02:00
|
|
|
}
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2016-03-25 10:02:35 +01:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
2020-02-21 18:52:20 +01:00
|
|
|
index c82c213260..a296936748 100644
|
2016-03-25 10:02:35 +01:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
2019-12-11 01:56:03 +01:00
|
|
|
@@ -1007,4 +1007,12 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
2016-03-25 10:02:35 +01:00
|
|
|
return spigot;
|
|
|
|
}
|
|
|
|
// Spigot end
|
|
|
|
+
|
|
|
|
+ // Paper start
|
|
|
|
+ @Override
|
|
|
|
+ public Location getOrigin() {
|
2016-03-25 17:39:37 +01:00
|
|
|
+ Location origin = getHandle().origin;
|
|
|
|
+ return origin == null ? null : origin.clone();
|
2016-03-25 10:02:35 +01:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
--
|
2020-02-09 05:19:54 +01:00
|
|
|
2.25.0
|
2016-03-25 10:02:35 +01:00
|
|
|
|