mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-23 11:06:29 +01:00
38be4f873b
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: 2c64d8c4 SPIGOT-7309: Add API for jukebox inventories a6d7e4ca PR-826: Add Sniffer API CraftBukkit Changes: 93813509b SPIGOT-7309: Add API for jukebox inventories 2d5209e8d PR-1153: Handle teleport reason in spreadplayers command f5b61387e SPIGOT-7308: Fix NullPointerException when calling Jukebox#setRecord() 388d458a6 SPIGOT-7306: Fix reset of coords in default teleportTo in EntityPlayer 40b87e1af PR-1150: Add Sniffer API and handle EntityItemDropEvent Spigot Changes: 6ad4b93c SPIGOT-7298: Fix debug stick always permission left click toggle
159 lines
7.5 KiB
Diff
159 lines
7.5 KiB
Diff
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
|
|
index fb7930009db2c219347e6601ca2cde0c8601e2b4..26cc626ad0c5328c20f7ef20e8e270c9a3c22dc4 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
@@ -2214,6 +2214,15 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
|
|
|
entity.updateDynamicGameEventListener(DynamicGameEventListener::add);
|
|
entity.valid = true; // CraftBukkit
|
|
+ // Paper start - Set origin location when the entity is being added to the world
|
|
+ if (entity.getOriginVector() == null) {
|
|
+ entity.setOrigin(entity.getBukkitEntity().getLocation());
|
|
+ }
|
|
+ // Default to current world if unknown, gross assumption but entities rarely change world
|
|
+ if (entity.getOriginWorld() == null) {
|
|
+ entity.setOrigin(entity.getOriginVector().toLocation(getWorld()));
|
|
+ }
|
|
+ // Paper end
|
|
}
|
|
|
|
public void onTrackingEnd(Entity entity) {
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
index 8a9700d8bbfe2f813259543ed4167495d13e1b4f..cc46ddc81724ea344d09fa75936fae869e396a02 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -307,7 +307,27 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
|
|
public long activatedTick = Integer.MIN_VALUE;
|
|
public void inactiveTick() { }
|
|
// Spigot end
|
|
+ // 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;
|
|
+ }
|
|
+ // Paper end
|
|
public float getBukkitYaw() {
|
|
return this.yRot;
|
|
}
|
|
@@ -1942,6 +1962,15 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
|
|
this.bukkitEntity.storeBukkitValues(nbt);
|
|
}
|
|
// CraftBukkit end
|
|
+ // Paper start - Save the entity's origin location
|
|
+ if (this.origin != null) {
|
|
+ UUID originWorld = this.originWorld != null ? this.originWorld : this.level != null ? this.level.getWorld().getUID() : null;
|
|
+ if (originWorld != null) {
|
|
+ nbt.putUUID("Paper.OriginWorld", originWorld);
|
|
+ }
|
|
+ nbt.put("Paper.Origin", this.newDoubleList(origin.getX(), origin.getY(), origin.getZ()));
|
|
+ }
|
|
+ // Paper end
|
|
return nbt;
|
|
} catch (Throwable throwable) {
|
|
CrashReport crashreport = CrashReport.forThrowable(throwable, "Saving entity NBT");
|
|
@@ -2069,6 +2098,20 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
|
|
}
|
|
// CraftBukkit end
|
|
|
|
+ // Paper start - Restore the entity's origin location
|
|
+ ListTag originTag = nbt.getList("Paper.Origin", 6);
|
|
+ if (!originTag.isEmpty()) {
|
|
+ UUID originWorld = null;
|
|
+ if (nbt.contains("Paper.OriginWorld")) {
|
|
+ originWorld = nbt.getUUID("Paper.OriginWorld");
|
|
+ } else if (this.level != null) {
|
|
+ originWorld = this.level.getWorld().getUID();
|
|
+ }
|
|
+ this.originWorld = originWorld;
|
|
+ origin = new org.bukkit.util.Vector(originTag.getDouble(0), originTag.getDouble(1), originTag.getDouble(2));
|
|
+ }
|
|
+ // 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
|
|
index 88ea09b2f1c33e9fb528aad1564ae858c3c8b064..5e93e55df24941a21721295ef8a3381ae19e1f26 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
|
|
@@ -340,6 +340,14 @@ public class FallingBlockEntity extends Entity {
|
|
this.blockState = Blocks.SAND.defaultBlockState();
|
|
}
|
|
|
|
+ // Paper start - Try and load origin location from the old NBT tags for backwards compatibility
|
|
+ if (nbt.contains("SourceLoc_x")) {
|
|
+ int srcX = nbt.getInt("SourceLoc_x");
|
|
+ int srcY = nbt.getInt("SourceLoc_y");
|
|
+ int srcZ = nbt.getInt("SourceLoc_z");
|
|
+ this.setOrigin(new org.bukkit.Location(level.getWorld(), srcX, srcY, srcZ));
|
|
+ }
|
|
+ // Paper end
|
|
}
|
|
|
|
public void setHurtsEntities(float fallHurtAmount, int fallHurtMax) {
|
|
diff --git a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
|
|
index c133d51a363900164c1492359be5b1579806d5cb..ab5817df2c98d24ee627fd5cf1f71e40b044e43e 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
|
|
@@ -118,6 +118,14 @@ public class PrimedTnt extends Entity implements TraceableEntity {
|
|
@Override
|
|
protected void readAdditionalSaveData(CompoundTag nbt) {
|
|
this.setFuse(nbt.getShort("Fuse"));
|
|
+ // Paper start - Try and load origin location from the old NBT tags for backwards compatibility
|
|
+ if (nbt.contains("SourceLoc_x")) {
|
|
+ int srcX = nbt.getInt("SourceLoc_x");
|
|
+ int srcY = nbt.getInt("SourceLoc_y");
|
|
+ int srcZ = nbt.getInt("SourceLoc_z");
|
|
+ this.setOrigin(new org.bukkit.Location(level.getWorld(), srcX, srcY, srcZ));
|
|
+ }
|
|
+ // 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
|
|
index 17c914088b467007aada17e3b2238a9c76fb532b..7a3ae4daa0f1f8dd2dd200fbfa1010f70f4b1f91 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
@@ -1252,5 +1252,20 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
|
|
|
return ret;
|
|
}
|
|
+
|
|
+ @Override
|
|
+ public Location getOrigin() {
|
|
+ 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);
|
|
+ }
|
|
// Paper end
|
|
}
|