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-31 00:45:24 +01:00
|
|
|
index 0ff6e1f3f24b4086ce62faecf400c493f31fc964..7431b66079406a311a8e46ccabc8f3efa67f37e8 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-12-31 00:45:24 +01:00
|
|
|
@@ -2404,6 +2404,15 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
2022-06-07 21:15:06 +02:00
|
|
|
entity.updateDynamicGameEventListener(DynamicGameEventListener::add);
|
2023-12-06 22:59:39 +01:00
|
|
|
entity.inWorld = true; // CraftBukkit - Mark entity as in world
|
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 20:39:26 +01:00
|
|
|
index fa3d294b36eb0c23b293466fc72bd2970a452b55..9f3598371c854ec74f3b5752c9779d6c0d99ec39 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-12-05 20:39:26 +01:00
|
|
|
@@ -317,7 +317,27 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
|
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-12-05 20:39:26 +01:00
|
|
|
@@ -2093,6 +2113,15 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
|
|
|
|
this.bukkitEntity.storeBukkitValues(nbttagcompound);
|
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) {
|
2023-12-05 20:39:26 +01:00
|
|
|
+ nbttagcompound.putUUID("Paper.OriginWorld", originWorld);
|
2021-06-22 12:54:49 +02:00
|
|
|
+ }
|
2023-12-05 20:39:26 +01:00
|
|
|
+ nbttagcompound.put("Paper.Origin", this.newDoubleList(origin.getX(), origin.getY(), origin.getZ()));
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
2023-12-05 20:39:26 +01:00
|
|
|
return nbttagcompound;
|
2021-06-11 14:02:28 +02:00
|
|
|
} catch (Throwable throwable) {
|
|
|
|
CrashReport crashreport = CrashReport.forThrowable(throwable, "Saving entity NBT");
|
2023-12-05 20:39:26 +01:00
|
|
|
@@ -2220,6 +2249,20 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
|
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 20:39:26 +01:00
|
|
|
index 5d09790876c3c50d126678565001645f6aece16f..6c4224e4752b655710c5b992d9acf9563b183483 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-12-05 20:39:26 +01:00
|
|
|
index f08c021f867c00611139a17db48352944eb2aa99..5c3b86e2301079e775971aa4da6a8f2dc6a40d1f 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-12-05 20:39:26 +01:00
|
|
|
@@ -132,6 +132,14 @@ public class PrimedTnt extends Entity implements TraceableEntity {
|
|
|
|
this.setBlockState(NbtUtils.readBlockState(this.level().holderLookup(Registries.BLOCK), nbt.getCompound("block_state")));
|
|
|
|
}
|
|
|
|
|
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-31 00:45:24 +01:00
|
|
|
index e269812e6193492afc3f25612edafa1a58325fa3..49294a8d580d891f21d8d4cbae14ae477c01ff8d 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
|
Updated Upstream (Bukkit/CraftBukkit) (#10034)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
f29cb801 Separate checkstyle-suppressions file is not required
86f99bbe SPIGOT-7540, PR-946: Add ServerTickManager API
d4119585 SPIGOT-6903, PR-945: Add BlockData#getMapColor
b7a2ed41 SPIGOT-7530, PR-947: Add Player#removeResourcePack
9dd56255 SPIGOT-7527, PR-944: Add WindCharge#explode()
994a6163 Attempt upgrade of resolver libraries
CraftBukkit Changes:
b3b43a6ad Add Checkstyle check for unused imports
13fb3358e SPIGOT-7544: Scoreboard#getEntries() doesn't get entries but class names
3dda99c06 SPIGOT-7540, PR-1312: Add ServerTickManager API
2ab4508c0 SPIGOT-6903, PR-1311: Add BlockData#getMapColor
1dbdbbed4 PR-1238: Remove unnecessary sign ticking
659728d2a MC-264285, SPIGOT-7439, PR-1237: Fix unbreakable flint and steel is completely consumed while igniting creeper
e37e29ce0 Increase outdated build delay
c00438b39 SPIGOT-7530, PR-1313: Add Player#removeResourcePack
492dd80ce SPIGOT-7527, PR-1310: Add WindCharge#explode()
e11fbb9d7 Upgrade MySQL driver
9f3a0bd2a Attempt upgrade of resolver libraries
60d16d7ca PR-1306: Centralize Bukkit and Minecraft entity conversion
Spigot Changes:
06d602e7 Rebuild patches
2023-12-17 03:09:28 +01:00
|
|
|
@@ -967,5 +967,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
|
|
|
}
|