2021-06-11 14:02:28 +02: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
|
2023-12-05 18:20:55 +01:00
|
|
|
index fb183bff8844b6f9db5611b9b55b641f4ec438ff..79f6cdfe3e744b93007699a0da71613844c3a4c7 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
2023-09-22 22:13:57 +02:00
|
|
|
@@ -2354,6 +2354,15 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
2021-06-18 05:37:23 +02:00
|
|
|
|
2022-06-07 21:15:06 +02:00
|
|
|
entity.updateDynamicGameEventListener(DynamicGameEventListener::add);
|
2021-06-18 05:37:23 +02:00
|
|
|
entity.valid = true; // CraftBukkit
|
2021-06-11 14:02:28 +02:00
|
|
|
+ // Paper start - Set origin location when the entity is being added to the world
|
2021-06-16 07:36:02 +02:00
|
|
|
+ if (entity.getOriginVector() == null) {
|
|
|
|
+ entity.setOrigin(entity.getBukkitEntity().getLocation());
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
2021-06-22 12:54:49 +02: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 14:02:28 +02:00
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
|
2021-06-18 05:37:23 +02:00
|
|
|
public void onTrackingEnd(Entity entity) {
|
2021-06-11 14:02:28 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
2023-12-05 18:20:55 +01:00
|
|
|
index 9eda990939b36c08a6f4820353942d6c8d43b42c..679f55d1b09868a28c5ba82746968eab1000aa88 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
2023-06-07 20:31:32 +02:00
|
|
|
@@ -312,7 +312,27 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
|
2021-12-03 22:28:15 +01:00
|
|
|
public long activatedTick = Integer.MIN_VALUE;
|
|
|
|
public void inactiveTick() { }
|
|
|
|
// Spigot end
|
2021-06-16 07:36:02 +02:00
|
|
|
+ // Paper start
|
|
|
|
+ @javax.annotation.Nullable
|
|
|
|
+ private org.bukkit.util.Vector origin;
|
|
|
|
+ @javax.annotation.Nullable
|
|
|
|
+ private UUID originWorld;
|
2023-03-23 22:57:03 +01:00
|
|
|
+
|
2021-06-16 07:36:02 +02:00
|
|
|
+ public void setOrigin(@javax.annotation.Nonnull Location location) {
|
|
|
|
+ this.origin = location.toVector();
|
|
|
|
+ this.originWorld = location.getWorld().getUID();
|
|
|
|
+ }
|
2023-03-23 22:57:03 +01:00
|
|
|
|
2021-06-16 07:36:02 +02: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 09:29:05 +02:00
|
|
|
+ // Paper end
|
2021-12-03 22:28:15 +01:00
|
|
|
public float getBukkitYaw() {
|
|
|
|
return this.yRot;
|
|
|
|
}
|
2023-09-22 22:13:57 +02:00
|
|
|
@@ -2070,6 +2090,15 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
|
2021-06-12 00:37:16 +02:00
|
|
|
this.bukkitEntity.storeBukkitValues(nbt);
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
+ // Paper start - Save the entity's origin location
|
|
|
|
+ if (this.origin != null) {
|
2021-06-22 12:54:49 +02: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-12 00:37:16 +02:00
|
|
|
+ nbt.put("Paper.Origin", this.newDoubleList(origin.getX(), origin.getY(), origin.getZ()));
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
2021-06-12 00:37:16 +02:00
|
|
|
return nbt;
|
2021-06-11 14:02:28 +02:00
|
|
|
} catch (Throwable throwable) {
|
|
|
|
CrashReport crashreport = CrashReport.forThrowable(throwable, "Saving entity NBT");
|
2023-09-22 22:13:57 +02:00
|
|
|
@@ -2197,6 +2226,20 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
|
|
|
|
+ // Paper start - Restore the entity's origin location
|
2021-06-12 00:37:16 +02:00
|
|
|
+ ListTag originTag = nbt.getList("Paper.Origin", 6);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ if (!originTag.isEmpty()) {
|
2021-06-21 11:04:18 +02:00
|
|
|
+ UUID originWorld = null;
|
2021-06-12 00:37:16 +02:00
|
|
|
+ if (nbt.contains("Paper.OriginWorld")) {
|
2021-06-16 07:36:02 +02:00
|
|
|
+ originWorld = nbt.getUUID("Paper.OriginWorld");
|
2021-06-21 11:04:18 +02:00
|
|
|
+ } else if (this.level != null) {
|
|
|
|
+ originWorld = this.level.getWorld().getUID();
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
2021-06-16 07:36:02 +02:00
|
|
|
+ this.originWorld = originWorld;
|
2021-06-17 19:11:00 +02:00
|
|
|
+ origin = new org.bukkit.util.Vector(originTag.getDouble(0), originTag.getDouble(1), originTag.getDouble(2));
|
2021-06-11 14:02:28 +02: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
|
2023-12-05 18:20:55 +01:00
|
|
|
index 5e30e7a1447503f424ec3a5aa3983826ee960fd8..0e349bc8dd0c31559437dc67481d5f0f81100e3b 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
|
2023-07-04 10:22:56 +02:00
|
|
|
@@ -343,6 +343,14 @@ public class FallingBlockEntity extends Entity {
|
2021-06-11 14:02:28 +02:00
|
|
|
this.blockState = Blocks.SAND.defaultBlockState();
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start - Try and load origin location from the old NBT tags for backwards compatibility
|
2021-06-12 00:37:16 +02:00
|
|
|
+ if (nbt.contains("SourceLoc_x")) {
|
|
|
|
+ int srcX = nbt.getInt("SourceLoc_x");
|
|
|
|
+ int srcY = nbt.getInt("SourceLoc_y");
|
|
|
|
+ int srcZ = nbt.getInt("SourceLoc_z");
|
2023-06-07 23:35:19 +02:00
|
|
|
+ this.setOrigin(new org.bukkit.Location(this.level().getWorld(), srcX, srcY, srcZ));
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
|
2021-11-23 13:15:10 +01:00
|
|
|
public void setHurtsEntities(float fallHurtAmount, int fallHurtMax) {
|
2021-06-11 14:02:28 +02: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
|
2023-07-04 10:22:56 +02:00
|
|
|
index 415b8822f0dfb14d49bccb2a10ac04025891ddf7..89fd5d6b373d2705dccc2f22663048f4c2aaa60f 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
|
2023-07-04 10:22:56 +02:00
|
|
|
@@ -119,6 +119,14 @@ public class PrimedTnt extends Entity implements TraceableEntity {
|
2021-06-11 14:02:28 +02:00
|
|
|
@Override
|
2021-06-12 00:37:16 +02:00
|
|
|
protected void readAdditionalSaveData(CompoundTag nbt) {
|
|
|
|
this.setFuse(nbt.getShort("Fuse"));
|
2021-06-11 14:02:28 +02:00
|
|
|
+ // Paper start - Try and load origin location from the old NBT tags for backwards compatibility
|
2021-06-12 00:37:16 +02:00
|
|
|
+ if (nbt.contains("SourceLoc_x")) {
|
|
|
|
+ int srcX = nbt.getInt("SourceLoc_x");
|
|
|
|
+ int srcY = nbt.getInt("SourceLoc_y");
|
|
|
|
+ int srcZ = nbt.getInt("SourceLoc_z");
|
2023-06-07 23:35:19 +02:00
|
|
|
+ this.setOrigin(new org.bukkit.Location(this.level().getWorld(), srcX, srcY, srcZ));
|
2021-06-11 14:02:28 +02: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
|
2023-12-05 18:20:55 +01:00
|
|
|
index 1f63d24ebe0563431c8f1d3f901e2816648c7a8f..402b6e5d6428c5a34d722888670f94c7fbe34fe4 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
2023-10-03 13:55:12 +02:00
|
|
|
@@ -1272,5 +1272,20 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
2022-09-01 18:51:59 +02:00
|
|
|
|
|
|
|
return ret;
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Location getOrigin() {
|
2021-06-16 07:36:02 +02: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 14:02:28 +02:00
|
|
|
+ }
|
2022-09-01 18:51:59 +02:00
|
|
|
// Paper end
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|