PaperMC/patches/server-remapped/Entity-Origin-API.patch
MiniDigger | Martin 95d25d98e8 Move patches around
2021-06-11 14:02:28 +02:00

140 lines
7.2 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/nbt/ListTag.java
+++ b/src/main/java/net/minecraft/nbt/ListTag.java
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -0,0 +0,0 @@ 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;
@@ -0,0 +0,0 @@ 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");
@@ -0,0 +0,0 @@ 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");
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
+++ b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
+++ b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
@@ -0,0 +0,0 @@ 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
}