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-06-09 01:04:53 +02:00
|
|
|
index 995be2fd84ce343d7430d9658f91868e653da43d..4af495424d60632b770cd1cb02157bbcf34366e8 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-06-09 01:04:53 +02:00
|
|
|
@@ -2363,6 +2363,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-07-04 10:22:56 +02:00
|
|
|
index adef9ffbc7a42172d88004209b8a745254b58757..87dce3470b544d9095c9bb2fd54b79553212a122 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-06-08 07:21:04 +02:00
|
|
|
@@ -2062,6 +2082,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-06-08 07:21:04 +02:00
|
|
|
@@ -2189,6 +2218,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-07-04 10:22:56 +02:00
|
|
|
index 2d32a2b41100b0e32ec64c8724734f22c7c883e2..93c162fd126824ab0af39568efe0dec21d846810 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-06-13 01:51:45 +02:00
|
|
|
index 11645e01924b4a66aa4f425c8962a000be761912..003690e2f347821d28517b816115cc92ea5d0bd6 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-06-13 01:51:45 +02:00
|
|
|
@@ -1245,5 +1245,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
|
|
|
}
|