2021-06-11 12:02:28 +00:00
|
|
|
From 0000000000000000000000000000000000000000 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/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
2022-06-10 01:20:47 +00:00
|
|
|
index 823b0d6ce2ad55532532abec07b7920ee546eb56..41c398b1819d960994922b0ffaf64ae7348d82cf 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
2022-06-10 01:20:47 +00:00
|
|
|
@@ -2108,6 +2108,15 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
2021-06-18 03:37:23 +00:00
|
|
|
|
2022-06-07 19:15:06 +00:00
|
|
|
entity.updateDynamicGameEventListener(DynamicGameEventListener::add);
|
2021-06-18 03:37:23 +00:00
|
|
|
entity.valid = true; // CraftBukkit
|
2021-06-11 12:02:28 +00:00
|
|
|
+ // Paper start - Set origin location when the entity is being added to the world
|
2021-06-16 05:36:02 +00:00
|
|
|
+ if (entity.getOriginVector() == null) {
|
|
|
|
+ entity.setOrigin(entity.getBukkitEntity().getLocation());
|
2021-06-11 12:02:28 +00:00
|
|
|
+ }
|
2021-06-22 10:54:49 +00:00
|
|
|
+ // Default to current world if unknown, gross assumption but entities rarely change world
|
|
|
|
+ if (entity.getOriginWorld() == null) {
|
|
|
|
+ entity.setOrigin(entity.getOriginVector().toLocation(getWorld()));
|
|
|
|
+ }
|
2021-06-11 12:02:28 +00:00
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
|
2021-06-18 03:37:23 +00:00
|
|
|
public void onTrackingEnd(Entity entity) {
|
2021-06-11 12:02:28 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
2022-06-09 08:51:45 +00:00
|
|
|
index 76dc492e9c2239a09de9ead5de50abb86a97f452..96864858f28337a6807cfa255b6b607bdbd337ce 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
2022-06-07 19:15:06 +00:00
|
|
|
@@ -303,7 +303,27 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
|
2021-12-03 21:28:15 +00:00
|
|
|
public long activatedTick = Integer.MIN_VALUE;
|
|
|
|
public void inactiveTick() { }
|
|
|
|
// Spigot end
|
2021-06-16 05:36:02 +00:00
|
|
|
+ // Paper start
|
|
|
|
+ @javax.annotation.Nullable
|
|
|
|
+ private org.bukkit.util.Vector origin;
|
|
|
|
+ @javax.annotation.Nullable
|
|
|
|
+ private UUID originWorld;
|
|
|
|
+
|
|
|
|
+ public void setOrigin(@javax.annotation.Nonnull Location location) {
|
|
|
|
+ this.origin = location.toVector();
|
|
|
|
+ this.originWorld = location.getWorld().getUID();
|
|
|
|
+ }
|
2021-12-03 21:28:15 +00:00
|
|
|
|
2021-06-16 05:36:02 +00:00
|
|
|
+ @javax.annotation.Nullable
|
|
|
|
+ public org.bukkit.util.Vector getOriginVector() {
|
|
|
|
+ return this.origin != null ? this.origin.clone() : null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @javax.annotation.Nullable
|
|
|
|
+ public UUID getOriginWorld() {
|
|
|
|
+ return this.originWorld;
|
|
|
|
+ }
|
2021-06-16 07:29:05 +00:00
|
|
|
+ // Paper end
|
2021-12-03 21:28:15 +00:00
|
|
|
public float getBukkitYaw() {
|
|
|
|
return this.yRot;
|
|
|
|
}
|
2022-06-09 08:51:45 +00:00
|
|
|
@@ -1851,6 +1871,15 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
|
2021-06-11 22:37:16 +00:00
|
|
|
this.bukkitEntity.storeBukkitValues(nbt);
|
2021-06-11 12:02:28 +00:00
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
+ // Paper start - Save the entity's origin location
|
|
|
|
+ if (this.origin != null) {
|
2021-06-22 10:54:49 +00:00
|
|
|
+ UUID originWorld = this.originWorld != null ? this.originWorld : this.level != null ? this.level.getWorld().getUID() : null;
|
|
|
|
+ if (originWorld != null) {
|
|
|
|
+ nbt.putUUID("Paper.OriginWorld", originWorld);
|
|
|
|
+ }
|
2021-06-11 22:37:16 +00:00
|
|
|
+ nbt.put("Paper.Origin", this.newDoubleList(origin.getX(), origin.getY(), origin.getZ()));
|
2021-06-11 12:02:28 +00:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
2021-06-11 22:37:16 +00:00
|
|
|
return nbt;
|
2021-06-11 12:02:28 +00:00
|
|
|
} catch (Throwable throwable) {
|
|
|
|
CrashReport crashreport = CrashReport.forThrowable(throwable, "Saving entity NBT");
|
2022-06-09 08:51:45 +00:00
|
|
|
@@ -1975,6 +2004,20 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
|
2021-06-11 12:02:28 +00:00
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
|
|
|
|
+ // Paper start - Restore the entity's origin location
|
2021-06-11 22:37:16 +00:00
|
|
|
+ ListTag originTag = nbt.getList("Paper.Origin", 6);
|
2021-06-11 12:02:28 +00:00
|
|
|
+ if (!originTag.isEmpty()) {
|
2021-06-21 09:04:18 +00:00
|
|
|
+ UUID originWorld = null;
|
2021-06-11 22:37:16 +00:00
|
|
|
+ if (nbt.contains("Paper.OriginWorld")) {
|
2021-06-16 05:36:02 +00:00
|
|
|
+ originWorld = nbt.getUUID("Paper.OriginWorld");
|
2021-06-21 09:04:18 +00:00
|
|
|
+ } else if (this.level != null) {
|
|
|
|
+ originWorld = this.level.getWorld().getUID();
|
2021-06-11 12:02:28 +00:00
|
|
|
+ }
|
2021-06-16 05:36:02 +00:00
|
|
|
+ this.originWorld = originWorld;
|
2021-06-17 17:11:00 +00:00
|
|
|
+ origin = new org.bukkit.util.Vector(originTag.getDouble(0), originTag.getDouble(1), originTag.getDouble(2));
|
2021-06-11 12:02:28 +00:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
} catch (Throwable throwable) {
|
|
|
|
CrashReport crashreport = CrashReport.forThrowable(throwable, "Loading entity NBT");
|
|
|
|
CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Entity being loaded");
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
|
2022-06-09 08:51:45 +00:00
|
|
|
index bd357c3e6fcbd82f3c53ecc8dab46aa5d3708bc2..6c4be7da19d0d61f35942558d438587853231aaa 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
|
2022-04-30 16:27:41 +00:00
|
|
|
@@ -337,6 +337,14 @@ public class FallingBlockEntity extends Entity {
|
2021-06-11 12:02:28 +00:00
|
|
|
this.blockState = Blocks.SAND.defaultBlockState();
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start - Try and load origin location from the old NBT tags for backwards compatibility
|
2021-06-11 22:37:16 +00:00
|
|
|
+ if (nbt.contains("SourceLoc_x")) {
|
|
|
|
+ int srcX = nbt.getInt("SourceLoc_x");
|
|
|
|
+ int srcY = nbt.getInt("SourceLoc_y");
|
|
|
|
+ int srcZ = nbt.getInt("SourceLoc_z");
|
2021-06-16 05:36:02 +00:00
|
|
|
+ this.setOrigin(new org.bukkit.Location(level.getWorld(), srcX, srcY, srcZ));
|
2021-06-11 12:02:28 +00:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
|
2021-11-23 12:15:10 +00:00
|
|
|
public void setHurtsEntities(float fallHurtAmount, int fallHurtMax) {
|
2021-06-11 12:02:28 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
|
2022-06-09 08:51:45 +00:00
|
|
|
index 2d4a990da2402a6c24c03e8be7e518e33db99c8f..10f8b5ff56e4c1d8300835e045abdce719a99343 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
|
2021-06-11 22:37:16 +00:00
|
|
|
@@ -120,6 +120,14 @@ public class PrimedTnt extends Entity {
|
2021-06-11 12:02:28 +00:00
|
|
|
@Override
|
2021-06-11 22:37:16 +00:00
|
|
|
protected void readAdditionalSaveData(CompoundTag nbt) {
|
|
|
|
this.setFuse(nbt.getShort("Fuse"));
|
2021-06-11 12:02:28 +00:00
|
|
|
+ // Paper start - Try and load origin location from the old NBT tags for backwards compatibility
|
2021-06-11 22:37:16 +00:00
|
|
|
+ if (nbt.contains("SourceLoc_x")) {
|
|
|
|
+ int srcX = nbt.getInt("SourceLoc_x");
|
|
|
|
+ int srcY = nbt.getInt("SourceLoc_y");
|
|
|
|
+ int srcZ = nbt.getInt("SourceLoc_z");
|
2021-06-16 05:36:02 +00:00
|
|
|
+ this.setOrigin(new org.bukkit.Location(level.getWorld(), srcX, srcY, srcZ));
|
2021-06-11 12:02:28 +00:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
2022-06-07 19:15:06 +00:00
|
|
|
index b403022201b34118adddf817b19a8bbdb6229df4..35e6cdd6930209d5c0f1c23c4e6838a5c0d81aa3 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
2022-06-07 19:15:06 +00:00
|
|
|
@@ -1166,4 +1166,21 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
2021-06-11 22:37:16 +00:00
|
|
|
return this.spigot;
|
2021-06-11 12:02:28 +00:00
|
|
|
}
|
|
|
|
// Spigot end
|
|
|
|
+
|
|
|
|
+ // Paper start
|
|
|
|
+ @Override
|
|
|
|
+ public Location getOrigin() {
|
2021-06-16 05:36:02 +00:00
|
|
|
+ Vector originVector = this.getHandle().getOriginVector();
|
|
|
|
+ if (originVector == null) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ World world = this.getWorld();
|
|
|
|
+ if (this.getHandle().getOriginWorld() != null) {
|
|
|
|
+ world = org.bukkit.Bukkit.getWorld(this.getHandle().getOriginWorld());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //noinspection ConstantConditions
|
|
|
|
+ return originVector.toLocation(world);
|
2021-06-11 12:02:28 +00:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
}
|