Try even harder to get an origin world and avoid NPEs (Fixes #5931)

This commit is contained in:
Shane Freeder 2021-06-22 11:54:49 +01:00
parent 4a7d7decce
commit 1599ffc11d
4 changed files with 11 additions and 4 deletions

View File

@ -9,7 +9,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java --- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/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 @@ -0,0 +0,0 @@ public class ServerLevel extends net.minecraft.world.level.Level implements Worl
entity.setOrigin(entity.getBukkitEntity().getLocation()); entity.setOrigin(entity.getOriginVector().toLocation(getWorld()));
} }
// Paper end // Paper end
+ new com.destroystokyo.paper.event.entity.EntityAddToWorldEvent(entity.getBukkitEntity()).callEvent(); // Paper - fire while valid + new com.destroystokyo.paper.event.entity.EntityAddToWorldEvent(entity.getBukkitEntity()).callEvent(); // Paper - fire while valid

View File

@ -16,6 +16,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ if (entity.getOriginVector() == null) { + if (entity.getOriginVector() == null) {
+ entity.setOrigin(entity.getBukkitEntity().getLocation()); + 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 + // Paper end
} }
@ -58,7 +62,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
// CraftBukkit end // CraftBukkit end
+ // Paper start - Save the entity's origin location + // Paper start - Save the entity's origin location
+ if (this.origin != null) { + if (this.origin != null) {
+ nbt.putUUID("Paper.OriginWorld", originWorld); + 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())); + nbt.put("Paper.Origin", this.newDoubleList(origin.getX(), origin.getY(), origin.getZ()));
+ } + }
+ // Paper end + // Paper end

View File

@ -17,7 +17,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
public void inactiveTick() { } public void inactiveTick() { }
// Spigot end // Spigot end
@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n @@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
nbt.putUUID("Paper.OriginWorld", originWorld); }
nbt.put("Paper.Origin", this.newDoubleList(origin.getX(), origin.getY(), origin.getZ())); nbt.put("Paper.Origin", this.newDoubleList(origin.getX(), origin.getY(), origin.getZ()));
} }
+ // Save entity's from mob spawner status + // Save entity's from mob spawner status

View File

@ -56,7 +56,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
public com.destroystokyo.paper.loottable.PaperLootableInventoryData lootableData; // Paper public com.destroystokyo.paper.loottable.PaperLootableInventoryData lootableData; // Paper
@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n @@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
nbt.putUUID("Paper.OriginWorld", originWorld); }
nbt.put("Paper.Origin", this.newDoubleList(origin.getX(), origin.getY(), origin.getZ())); nbt.put("Paper.Origin", this.newDoubleList(origin.getX(), origin.getY(), origin.getZ()));
} }
+ if (spawnReason != null) { + if (spawnReason != null) {