Paper/patches/server/0025-Entity-Origin-API.patch

133 lines
6.9 KiB
Diff
Raw Normal View History

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/nbt/ListTag.java b/src/main/java/net/minecraft/nbt/ListTag.java
2021-06-11 22:37:16 +00:00
index 88bac72edf19c578902f49d20353989ed4d96f8f..e79faeb26d079de0108268fd2607cf9eb885c003 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/nbt/ListTag.java
+++ b/src/main/java/net/minecraft/nbt/ListTag.java
2021-06-11 22:37:16 +00:00
@@ -179,6 +179,7 @@ public class ListTag extends CollectionTag<Tag> {
return new long[0];
2021-06-11 12:02:28 +00:00
}
+ public final double getDoubleAt(int i) { return this.getDouble(i); } // Paper - OBFHELPER
public double getDouble(int index) {
if (index >= 0 && index < this.list.size()) {
2021-06-11 22:37:16 +00:00
Tag tag = this.list.get(index);
2021-06-11 12:02:28 +00:00
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
Updated Upstream (Bukkit/CraftBukkit/Spigot) 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: 8503c3c9 #621: Add HumanEntity#getItemInUse and Material#getSlipperiness 248deb09 #622: Add methods to check if item is the breed item for an entity 2ce691d8 Clarify Player#breakBlock only works for blocks in the same world 5dcdd48e SPIGOT-6514: Small Dripleaf block data is missing half property cc9610b7 #619: Add Player#breakBlock() 862bc475 Fix bad merge of SPIGOT-6502 fix 989bb0c1 Downgrade SnakeYAML due to issues with comments parsing 1dff62ae Fix inverted visual fire docs CraftBukkit Changes: 40caacc8 SPIGOT-6526: World entities are not populated when plugin onEnable is called c9a92ad0 SPIGOT-6536: Marker position not set on spawn 20d3e57c #855: Add HumanEntity#getItemInUse and Material#getSlipperiness d9c69b44 SPIGOT-6529: Fix BundleMeta#setItems 8bd43be5 SPIGOT-6535: PlayerGameModeChangeEvent event incorrectly reports old gamemode 4ece3ff3 #856: Add methods to check if item is the breed item for an entity dd4bec5f Add additional validation to Player#breakBlock bc835ae6 SPIGOT-6532: Fix Entity#setGlowing 384e116e Restore 1.16.5 behaviour of InventoryDragEvent being called even when a single item is 'dragged' to its own slot b42e708c Fix new map colors rendering as transparent cfe7fecf SPIGOT-6524: Inventory desync when InventoryClickEvent is cancelled eeae1b19 SPIGOT-6522: ItemStack on cursor is always AIR 7490724d Fix missing PlayerEditBookEvent 06875f76 SPIGOT-6513: Placing ItemStack in Inventory causes InventoryAction.NOTHING 27835bde SPIGOT-6519: Fix end gateway teleports 4ac634ad SPIGOT-6515: "Un-waterlogging" throws UnsupportedOperationException in some cases da425fa2 SPIGOT-6518: Anvils falling onto dripstone can sometimes crash server 50530da9 SPIGOT-6514: Small Dripleaf block data is missing half property 6fdecf20 #853: Implement Player#breakBlock() 4db9c49f SPIGOT-6510: Bukkit#createMap throws NullPointerException 89e2b127 SPIGOT-6517: Spider jockey crash on dripstone cbf2f678 SPIGOT-6508: Rename conflicted getServer 74575d48 SPIGOT-6506: Fix crash with custom inventories a3df386f Fix NPE with Entity.getNearbyEntities d747f8ed Fix NPE with World.getNearbyEntities 4d2c7800 Fix second usage of worldGenSettings just in case 5182f923 SPIGOT-6504: Fix generating fresh worlds Spigot Changes: 66f9d3c1 Rebuild patches 191e4971 Rebuild patches a09c0bb6 Restore Spigot experience merging
2021-06-13 05:13:07 +00:00
index 2db7c62d25791bc7856d007e9197f8c8041f8dfa..461b376987d3bc7c786fe6d29c5a07a5129c3355 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-11 22:37:16 +00:00
@@ -1110,6 +1110,11 @@ public class ServerLevel extends net.minecraft.world.level.Level implements Worl
entityplayer.connection.send(new ClientboundBlockDestructionPacket(entityId, pos, progress));
}
2021-06-11 12:02:28 +00:00
}
+ // 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
Updated Upstream (Bukkit/CraftBukkit/Spigot) 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: 8503c3c9 #621: Add HumanEntity#getItemInUse and Material#getSlipperiness 248deb09 #622: Add methods to check if item is the breed item for an entity 2ce691d8 Clarify Player#breakBlock only works for blocks in the same world 5dcdd48e SPIGOT-6514: Small Dripleaf block data is missing half property cc9610b7 #619: Add Player#breakBlock() 862bc475 Fix bad merge of SPIGOT-6502 fix 989bb0c1 Downgrade SnakeYAML due to issues with comments parsing 1dff62ae Fix inverted visual fire docs CraftBukkit Changes: 40caacc8 SPIGOT-6526: World entities are not populated when plugin onEnable is called c9a92ad0 SPIGOT-6536: Marker position not set on spawn 20d3e57c #855: Add HumanEntity#getItemInUse and Material#getSlipperiness d9c69b44 SPIGOT-6529: Fix BundleMeta#setItems 8bd43be5 SPIGOT-6535: PlayerGameModeChangeEvent event incorrectly reports old gamemode 4ece3ff3 #856: Add methods to check if item is the breed item for an entity dd4bec5f Add additional validation to Player#breakBlock bc835ae6 SPIGOT-6532: Fix Entity#setGlowing 384e116e Restore 1.16.5 behaviour of InventoryDragEvent being called even when a single item is 'dragged' to its own slot b42e708c Fix new map colors rendering as transparent cfe7fecf SPIGOT-6524: Inventory desync when InventoryClickEvent is cancelled eeae1b19 SPIGOT-6522: ItemStack on cursor is always AIR 7490724d Fix missing PlayerEditBookEvent 06875f76 SPIGOT-6513: Placing ItemStack in Inventory causes InventoryAction.NOTHING 27835bde SPIGOT-6519: Fix end gateway teleports 4ac634ad SPIGOT-6515: "Un-waterlogging" throws UnsupportedOperationException in some cases da425fa2 SPIGOT-6518: Anvils falling onto dripstone can sometimes crash server 50530da9 SPIGOT-6514: Small Dripleaf block data is missing half property 6fdecf20 #853: Implement Player#breakBlock() 4db9c49f SPIGOT-6510: Bukkit#createMap throws NullPointerException 89e2b127 SPIGOT-6517: Spider jockey crash on dripstone cbf2f678 SPIGOT-6508: Rename conflicted getServer 74575d48 SPIGOT-6506: Fix crash with custom inventories a3df386f Fix NPE with Entity.getNearbyEntities d747f8ed Fix NPE with World.getNearbyEntities 4d2c7800 Fix second usage of worldGenSettings just in case 5182f923 SPIGOT-6504: Fix generating fresh worlds Spigot Changes: 66f9d3c1 Rebuild patches 191e4971 Rebuild patches a09c0bb6 Restore Spigot experience merging
2021-06-13 05:13:07 +00:00
index a5e3f27a471bf2396db640685edfc93f77fe2c0c..864724d962d536c1a4402a8da1e0b378e9d7efd5 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-11 22:37:16 +00:00
@@ -280,6 +280,7 @@ 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;
+ public org.bukkit.Location origin; // Paper
// Spigot start
public final org.spigotmc.ActivationRange.ActivationType activationType = org.spigotmc.ActivationRange.initializeEntityActivationType(this);
public final boolean defaultActivationState;
2021-06-11 22:37:16 +00:00
@@ -1813,6 +1814,12 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
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-11 22:37:16 +00:00
+ nbt.setUUID("Paper.OriginWorld", origin.getWorld().getUID());
+ 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-11 22:37:16 +00:00
@@ -1939,6 +1946,17 @@ 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()) {
+ org.bukkit.World originWorld = level.getWorld();
2021-06-11 22:37:16 +00:00
+ if (nbt.contains("Paper.OriginWorld")) {
+ originWorld = Bukkit.getWorld(nbt.getUUID("Paper.OriginWorld"));
2021-06-11 12:02:28 +00:00
+ }
+ 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");
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-11 22:37:16 +00:00
index 11ed0127e2ea268f16c6b4b380d132a71ec9b3dc..eb838fcad0593573f536d5e043cbd3f4bbe25d74 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-11 12:02:28 +00:00
+ origin = new org.bukkit.Location(level.getWorld(), srcX, srcY, srcZ);
+ }
+ // 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-11 22:37:16 +00:00
index 394164f50256ad9a167e15531a9202875abb6cb6..abc62c560816d945642d830a020deb28ff2efa37 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-11 12:02:28 +00:00
+ 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 6722d97d498fb2951b7dd8af3b68dd771ce8f5c1..417357f6a187747a5e27fa60a57cee3fb91f3d2e 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
@@ -1098,4 +1098,12 @@ 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() {
+ Location origin = getHandle().origin;
+ return origin == null ? null : origin.clone();
+ }
+ // Paper end
}