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
|
2021-06-18 03:37:23 +00:00
|
|
|
index 5c5cfc31ced6695af7b1dd06cb867274fa38d85f..a127467fdd25b7513c727e1a0634f85087ec542e 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
|
2021-06-18 03:37:23 +00:00
|
|
|
@@ -1894,6 +1894,11 @@ public class ServerLevel extends net.minecraft.world.level.Level implements Worl
|
2021-06-11 12:02:28 +00:00
|
|
|
}
|
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
|
|
|
+ }
|
|
|
|
+ // 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
|
2021-06-17 21:39:36 +00:00
|
|
|
index 018792503e5d18470ad17b9f4b4524d5dfba31e9..5d4d5628e5c0d82301f988691eac363758af6a4b 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
|
2021-06-16 05:36:02 +00:00
|
|
|
@@ -280,6 +280,27 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
|
2021-06-11 12:02:28 +00:00
|
|
|
public org.bukkit.projectiles.ProjectileSource projectileSource; // For projectiles only
|
|
|
|
public boolean forceExplosionKnockback; // SPIGOT-949
|
|
|
|
public boolean persistentInvisibility = false;
|
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();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @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-06-11 12:02:28 +00:00
|
|
|
// Spigot start
|
|
|
|
public final org.spigotmc.ActivationRange.ActivationType activationType = org.spigotmc.ActivationRange.initializeEntityActivationType(this);
|
|
|
|
public final boolean defaultActivationState;
|
2021-06-17 21:39:36 +00:00
|
|
|
@@ -1812,6 +1833,12 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
|
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-17 21:39:36 +00:00
|
|
|
+ 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");
|
2021-06-17 21:39:36 +00:00
|
|
|
@@ -1938,6 +1965,18 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
|
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-16 05:36:02 +00:00
|
|
|
+ UUID originWorld = level.getWorld().getUID();
|
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-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
|
2021-06-16 05:36:02 +00:00
|
|
|
index 11ed0127e2ea268f16c6b4b380d132a71ec9b3dc..6c262832ba5259ec92d336114c203c254a39924c 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
|
2021-06-11 22:37:16 +00:00
|
|
|
@@ -329,6 +329,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-06-11 22:37:16 +00:00
|
|
|
public Level getLevel() {
|
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
|
2021-06-16 05:36:02 +00:00
|
|
|
index 394164f50256ad9a167e15531a9202875abb6cb6..8ad1b3cb16533d62deda643ce0cdda308743f78e 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
|
2021-06-16 05:36:02 +00:00
|
|
|
index 6722d97d498fb2951b7dd8af3b68dd771ce8f5c1..af1a792a456c2efdc959497c02c1e060ed545724 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
|
2021-06-16 05:36:02 +00:00
|
|
|
@@ -1098,4 +1098,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
|
|
|
|
}
|