Paper/patches/server-remapped/0028-Entity-Origin-API.patch
Mariell Hoversholm a207d14a0e
Rename all patches to correct numbering scheme
Signed-off-by: Mariell Hoversholm <proximyst@proximyst.com>
2021-06-11 15:46:44 +02:00

141 lines
7.3 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/nbt/ListTag.java b/src/main/java/net/minecraft/nbt/ListTag.java
index 084340dc73acb3d972e0717b48da820c027a5137..7927ebac41eb1f257738238500cfe0c06031fcaf 100644
--- a/src/main/java/net/minecraft/nbt/ListTag.java
+++ b/src/main/java/net/minecraft/nbt/ListTag.java
@@ -190,6 +190,7 @@ public class ListTag extends CollectionTag<Tag> {
return new int[0];
}
+ public final double getDoubleAt(int i) { return this.getDouble(i); } // Paper - OBFHELPER
public double getDouble(int index) {
if (index >= 0 && index < this.list.size()) {
Tag nbtbase = (Tag) this.list.get(index);
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index 0cc86ca4ea4a2e1b5acc3c0507397eef85dec0c1..d2bb9385fbc21cdef6cef06680fac685d3da3570 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -1240,6 +1240,11 @@ public class ServerLevel extends net.minecraft.world.level.Level implements Worl
this.navigations.add(((Mob) entity).getNavigation());
}
entity.valid = true; // CraftBukkit
+ // Paper start - Set origin location when the entity is being added to the world
+ if (entity.origin == null) {
+ entity.origin = entity.getBukkitEntity().getLocation();
+ }
+ // Paper end
}
}
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 392f2f2d67b688d5b37f77c8e4b3036348472d77..fd5b41ceb97dc8aa975f1c0ae05b58d0b09f2cd6 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -246,6 +246,7 @@ public abstract class Entity implements Nameable, CommandSource, net.minecraft.s
public org.bukkit.projectiles.ProjectileSource projectileSource; // For projectiles only
public boolean forceExplosionKnockback; // SPIGOT-949
public boolean persistentInvisibility = false;
+ public org.bukkit.Location origin; // Paper
// Spigot start
public final org.spigotmc.ActivationRange.ActivationType activationType = org.spigotmc.ActivationRange.initializeEntityActivationType(this);
public final boolean defaultActivationState;
@@ -1624,6 +1625,12 @@ public abstract class Entity implements Nameable, CommandSource, net.minecraft.s
this.bukkitEntity.storeBukkitValues(tag);
}
// CraftBukkit end
+ // Paper start - Save the entity's origin location
+ if (this.origin != null) {
+ tag.setUUID("Paper.OriginWorld", origin.getWorld().getUID());
+ tag.put("Paper.Origin", this.createList(origin.getX(), origin.getY(), origin.getZ()));
+ }
+ // Paper end
return tag;
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Saving entity NBT");
@@ -1746,6 +1753,17 @@ public abstract class Entity implements Nameable, CommandSource, net.minecraft.s
}
// CraftBukkit end
+ // Paper start - Restore the entity's origin location
+ ListTag originTag = tag.getList("Paper.Origin", 6);
+ if (!originTag.isEmpty()) {
+ org.bukkit.World originWorld = level.getWorld();
+ if (tag.contains("Paper.OriginWorld")) {
+ originWorld = Bukkit.getWorld(tag.getUUID("Paper.OriginWorld"));
+ }
+ origin = new org.bukkit.Location(originWorld, originTag.getDoubleAt(0), originTag.getDoubleAt(1), originTag.getDoubleAt(2));
+ }
+ // Paper end
+
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Loading entity NBT");
CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Entity being loaded");
@@ -1807,6 +1825,7 @@ public abstract class Entity implements Nameable, CommandSource, net.minecraft.s
protected abstract void addAdditionalSaveData(CompoundTag tag);
+ protected final ListTag createList(double... adouble) { return newDoubleList(adouble); } // Paper - OBFHELPER
protected ListTag newDoubleList(double... values) {
ListTag nbttaglist = new ListTag();
double[] adouble1 = values;
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 5394bc6336cb84025c1c748fb5b3d38e0648a590..1d87717cc9002ea202ee2ca614aaa8a4c7ea3cb2 100644
--- a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
+++ b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
@@ -291,6 +291,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 (tag.contains("SourceLoc_x")) {
+ int srcX = tag.getInt("SourceLoc_x");
+ int srcY = tag.getInt("SourceLoc_y");
+ int srcZ = tag.getInt("SourceLoc_z");
+ origin = new org.bukkit.Location(level.getWorld(), srcX, srcY, srcZ);
+ }
+ // Paper end
}
public void setHurtsEntities(boolean hurtEntities) {
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 4c4262b8f0cb44b8cea8cb46194a6e70d4ce56f4..661848084fd986321ef782317934dac19ed4dce3 100644
--- a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
+++ b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
@@ -119,6 +119,14 @@ public class PrimedTnt extends Entity {
@Override
protected void readAdditionalSaveData(CompoundTag tag) {
this.setFuse(tag.getShort("Fuse"));
+ // Paper start - Try and load origin location from the old NBT tags for backwards compatibility
+ if (tag.contains("SourceLoc_x")) {
+ int srcX = tag.getInt("SourceLoc_x");
+ int srcY = tag.getInt("SourceLoc_y");
+ int srcZ = tag.getInt("SourceLoc_z");
+ origin = 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 53c231925ef1b17e48c5863570e3c54124874621..e7a59a8e0424a0839dfa73fc65f44c5b04bd3dec 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
@@ -1062,4 +1062,12 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
return spigot;
}
// Spigot end
+
+ // Paper start
+ @Override
+ public Location getOrigin() {
+ Location origin = getHandle().origin;
+ return origin == null ? null : origin.clone();
+ }
+ // Paper end
}