2020-05-06 09:48:49 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2016-03-25 09:02:35 +00:00
|
|
|
From: Byteflux <byte@byteflux.net>
|
|
|
|
Date: Tue, 1 Mar 2016 23:45:08 -0600
|
|
|
|
Subject: [PATCH] Entity Origin API
|
|
|
|
|
|
|
|
|
2021-03-16 07:19:45 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/nbt/NBTTagList.java b/src/main/java/net/minecraft/nbt/NBTTagList.java
|
|
|
|
index 4f6f6f51f9807bafa88482c0fe776c8b163107d7..ce6572df63c4e7341708aee60330fb214a3fe416 100644
|
|
|
|
--- a/src/main/java/net/minecraft/nbt/NBTTagList.java
|
|
|
|
+++ b/src/main/java/net/minecraft/nbt/NBTTagList.java
|
|
|
|
@@ -190,6 +190,7 @@ public class NBTTagList extends NBTList<NBTBase> {
|
|
|
|
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/net/minecraft/server/level/WorldServer.java b/src/main/java/net/minecraft/server/level/WorldServer.java
|
|
|
|
index 038944613b6687c057e73eaa038c9492bda7116d..09fa1f8e4e2ccf03fafe477bb9dc32b2a72b41bb 100644
|
|
|
|
--- a/src/main/java/net/minecraft/server/level/WorldServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/WorldServer.java
|
|
|
|
@@ -1244,6 +1244,11 @@ public class WorldServer extends World implements GeneratorAccessSeed {
|
|
|
|
this.navigators.add(((EntityInsentient) entity).getNavigation());
|
|
|
|
}
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
|
|
index ca620977666f4d4173089876f506f041ab278bd3..dce47ec1fc186d12ffa30bfd3d71870aecb95d40 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
|
|
@@ -247,6 +247,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne
|
2017-11-08 16:13:57 +00:00
|
|
|
public org.bukkit.projectiles.ProjectileSource projectileSource; // For projectiles only
|
|
|
|
public boolean forceExplosionKnockback; // SPIGOT-949
|
2020-09-19 11:29:53 +00:00
|
|
|
public boolean persistentInvisibility = false;
|
2020-06-26 06:29:44 +00:00
|
|
|
+ public org.bukkit.Location origin; // Paper
|
2016-03-25 09:02:35 +00:00
|
|
|
// Spigot start
|
2019-05-30 23:54:25 +00:00
|
|
|
public final org.spigotmc.ActivationRange.ActivationType activationType = org.spigotmc.ActivationRange.initializeEntityActivationType(this);
|
2016-03-25 09:02:35 +00:00
|
|
|
public final boolean defaultActivationState;
|
2021-03-16 07:19:45 +00:00
|
|
|
@@ -1625,6 +1626,11 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne
|
2019-05-06 02:58:04 +00:00
|
|
|
this.bukkitEntity.storeBukkitValues(nbttagcompound);
|
2016-03-25 09:02:35 +00:00
|
|
|
}
|
2019-05-06 02:58:04 +00:00
|
|
|
// CraftBukkit end
|
2016-03-25 09:02:35 +00:00
|
|
|
+ // Paper start - Save the entity's origin location
|
2019-05-06 02:58:04 +00:00
|
|
|
+ if (this.origin != null) {
|
2016-05-12 02:07:46 +00:00
|
|
|
+ nbttagcompound.set("Paper.Origin", this.createList(origin.getX(), origin.getY(), origin.getZ()));
|
2016-03-25 09:02:35 +00:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
2016-05-12 02:07:46 +00:00
|
|
|
return nbttagcompound;
|
2016-03-25 09:02:35 +00:00
|
|
|
} catch (Throwable throwable) {
|
|
|
|
CrashReport crashreport = CrashReport.a(throwable, "Saving entity NBT");
|
2021-03-16 07:19:45 +00:00
|
|
|
@@ -1747,6 +1753,13 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne
|
2020-09-19 11:29:53 +00:00
|
|
|
}
|
2016-03-25 09:02:35 +00:00
|
|
|
// CraftBukkit end
|
|
|
|
|
|
|
|
+ // Paper start - Restore the entity's origin location
|
2016-03-25 16:32:09 +00:00
|
|
|
+ NBTTagList originTag = nbttagcompound.getList("Paper.Origin", 6);
|
|
|
|
+ if (!originTag.isEmpty()) {
|
2020-06-26 06:29:44 +00:00
|
|
|
+ origin = new org.bukkit.Location(world.getWorld(), originTag.getDoubleAt(0), originTag.getDoubleAt(1), originTag.getDoubleAt(2));
|
2016-03-25 09:02:35 +00:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
} catch (Throwable throwable) {
|
|
|
|
CrashReport crashreport = CrashReport.a(throwable, "Loading entity NBT");
|
|
|
|
CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Entity being loaded");
|
2021-03-16 07:19:45 +00:00
|
|
|
@@ -1808,6 +1821,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne
|
2016-05-12 02:07:46 +00:00
|
|
|
|
2020-06-25 09:27:25 +00:00
|
|
|
protected abstract void saveData(NBTTagCompound nbttagcompound);
|
2016-05-12 02:07:46 +00:00
|
|
|
|
2020-08-02 05:39:36 +00:00
|
|
|
+ protected final 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;
|
2021-03-16 07:19:45 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/item/EntityFallingBlock.java b/src/main/java/net/minecraft/world/entity/item/EntityFallingBlock.java
|
|
|
|
index 901522f24b8bc58861e46eda400dbab92bb6401d..3f10e41b18e09186635fd6f7c653b04db7b39d8e 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/entity/item/EntityFallingBlock.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/item/EntityFallingBlock.java
|
|
|
|
@@ -293,6 +293,14 @@ public class EntityFallingBlock extends Entity {
|
2016-03-25 09:02:35 +00: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) {
|
2021-03-16 07:19:45 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/item/EntityTNTPrimed.java b/src/main/java/net/minecraft/world/entity/item/EntityTNTPrimed.java
|
|
|
|
index 4f4b2b8d58223fa22d6a7af5c94cfb36399b9641..535e7d7297d81026b8586d5049b72fa65519b464 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/entity/item/EntityTNTPrimed.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/item/EntityTNTPrimed.java
|
|
|
|
@@ -120,6 +120,14 @@ public class EntityTNTPrimed extends Entity {
|
2019-04-24 02:34:11 +00:00
|
|
|
@Override
|
2020-06-25 09:27:25 +00:00
|
|
|
protected void loadData(NBTTagCompound nbttagcompound) {
|
2016-03-25 09:02:35 +00:00
|
|
|
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
|
2016-03-25 09:02:35 +00:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
2021-03-16 07:19:45 +00:00
|
|
|
index 3cf81734c8580f4d88ea97b6ac737a370b413c84..220bad90bbb9a90c3f23562bf0fb109fce379682 100644
|
2016-03-25 09:02:35 +00:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
2021-03-16 07:19:45 +00:00
|
|
|
@@ -1062,4 +1062,12 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
2016-03-25 09:02:35 +00:00
|
|
|
return spigot;
|
|
|
|
}
|
|
|
|
// Spigot end
|
|
|
|
+
|
|
|
|
+ // Paper start
|
|
|
|
+ @Override
|
|
|
|
+ public Location getOrigin() {
|
2016-03-25 16:39:37 +00:00
|
|
|
+ Location origin = getHandle().origin;
|
|
|
|
+ return origin == null ? null : origin.clone();
|
2016-03-25 09:02:35 +00:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
}
|