Modify entity origin API to store world/pos seperatly
This commit is contained in:
		
					parent
					
						
							
								f0a6f4878d
							
						
					
				
			
			
				commit
				
					
						e1116fe452
					
				
			
		
					 5 changed files with 49 additions and 19 deletions
				
			
		| 
						 | 
					@ -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.origin = entity.getBukkitEntity().getLocation();
 | 
					                 entity.setOrigin(entity.getBukkitEntity().getLocation());
 | 
				
			||||||
             }
 | 
					             }
 | 
				
			||||||
             // 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
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -25,8 +25,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 | 
				
			||||||
                 }
 | 
					                 }
 | 
				
			||||||
             }
 | 
					             }
 | 
				
			||||||
+            // Paper start - Set origin location when the entity is being added to the world
 | 
					+            // Paper start - Set origin location when the entity is being added to the world
 | 
				
			||||||
+            if (entity.origin == null) {
 | 
					+            if (entity.getOriginVector() == null) {
 | 
				
			||||||
+                entity.origin = entity.getBukkitEntity().getLocation();
 | 
					+                entity.setOrigin(entity.getBukkitEntity().getLocation());
 | 
				
			||||||
+            }
 | 
					+            }
 | 
				
			||||||
+            // Paper end
 | 
					+            // Paper end
 | 
				
			||||||
         }
 | 
					         }
 | 
				
			||||||
| 
						 | 
					@ -40,7 +40,27 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 | 
				
			||||||
     public org.bukkit.projectiles.ProjectileSource projectileSource; // For projectiles only
 | 
					     public org.bukkit.projectiles.ProjectileSource projectileSource; // For projectiles only
 | 
				
			||||||
     public boolean forceExplosionKnockback; // SPIGOT-949
 | 
					     public boolean forceExplosionKnockback; // SPIGOT-949
 | 
				
			||||||
     public boolean persistentInvisibility = false;
 | 
					     public boolean persistentInvisibility = false;
 | 
				
			||||||
+    public org.bukkit.Location origin; // Paper
 | 
					+    // 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
 | 
				
			||||||
     // Spigot start
 | 
					     // Spigot start
 | 
				
			||||||
     public final org.spigotmc.ActivationRange.ActivationType activationType = org.spigotmc.ActivationRange.initializeEntityActivationType(this);
 | 
					     public final org.spigotmc.ActivationRange.ActivationType activationType = org.spigotmc.ActivationRange.initializeEntityActivationType(this);
 | 
				
			||||||
     public final boolean defaultActivationState;
 | 
					     public final boolean defaultActivationState;
 | 
				
			||||||
| 
						 | 
					@ -50,7 +70,7 @@ 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.setUUID("Paper.OriginWorld", origin.getWorld().getUID());
 | 
					+                nbt.setUUID("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
 | 
				
			||||||
| 
						 | 
					@ -64,11 +84,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 | 
				
			||||||
+            // Paper start - Restore the entity's origin location
 | 
					+            // Paper start - Restore the entity's origin location
 | 
				
			||||||
+            ListTag originTag = nbt.getList("Paper.Origin", 6);
 | 
					+            ListTag originTag = nbt.getList("Paper.Origin", 6);
 | 
				
			||||||
+            if (!originTag.isEmpty()) {
 | 
					+            if (!originTag.isEmpty()) {
 | 
				
			||||||
+                org.bukkit.World originWorld = level.getWorld();
 | 
					+                UUID originWorld = level.getWorld().getUID();
 | 
				
			||||||
+                if (nbt.contains("Paper.OriginWorld")) {
 | 
					+                if (nbt.contains("Paper.OriginWorld")) {
 | 
				
			||||||
+                    originWorld = Bukkit.getWorld(nbt.getUUID("Paper.OriginWorld"));
 | 
					+                    originWorld = nbt.getUUID("Paper.OriginWorld");
 | 
				
			||||||
+                }
 | 
					+                }
 | 
				
			||||||
+                origin = new org.bukkit.Location(originWorld, originTag.getDoubleAt(0), originTag.getDoubleAt(1), originTag.getDoubleAt(2));
 | 
					+                this.originWorld = originWorld;
 | 
				
			||||||
 | 
					+                origin = new org.bukkit.util.Vector(originTag.getDoubleAt(0), originTag.getDoubleAt(1), originTag.getDoubleAt(2));
 | 
				
			||||||
+            }
 | 
					+            }
 | 
				
			||||||
+            // Paper end
 | 
					+            // Paper end
 | 
				
			||||||
+
 | 
					+
 | 
				
			||||||
| 
						 | 
					@ -88,7 +109,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 | 
				
			||||||
+            int srcX = nbt.getInt("SourceLoc_x");
 | 
					+            int srcX = nbt.getInt("SourceLoc_x");
 | 
				
			||||||
+            int srcY = nbt.getInt("SourceLoc_y");
 | 
					+            int srcY = nbt.getInt("SourceLoc_y");
 | 
				
			||||||
+            int srcZ = nbt.getInt("SourceLoc_z");
 | 
					+            int srcZ = nbt.getInt("SourceLoc_z");
 | 
				
			||||||
+            origin = new org.bukkit.Location(level.getWorld(), srcX, srcY, srcZ);
 | 
					+            this.setOrigin(new org.bukkit.Location(level.getWorld(), srcX, srcY, srcZ));
 | 
				
			||||||
+        }
 | 
					+        }
 | 
				
			||||||
+        // Paper end
 | 
					+        // Paper end
 | 
				
			||||||
     }
 | 
					     }
 | 
				
			||||||
| 
						 | 
					@ -107,7 +128,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 | 
				
			||||||
+            int srcX = nbt.getInt("SourceLoc_x");
 | 
					+            int srcX = nbt.getInt("SourceLoc_x");
 | 
				
			||||||
+            int srcY = nbt.getInt("SourceLoc_y");
 | 
					+            int srcY = nbt.getInt("SourceLoc_y");
 | 
				
			||||||
+            int srcZ = nbt.getInt("SourceLoc_z");
 | 
					+            int srcZ = nbt.getInt("SourceLoc_z");
 | 
				
			||||||
+            origin = new org.bukkit.Location(level.getWorld(), srcX, srcY, srcZ);
 | 
					+            this.setOrigin(new org.bukkit.Location(level.getWorld(), srcX, srcY, srcZ));
 | 
				
			||||||
+        }
 | 
					+        }
 | 
				
			||||||
+        // Paper end
 | 
					+        // Paper end
 | 
				
			||||||
     }
 | 
					     }
 | 
				
			||||||
| 
						 | 
					@ -125,8 +146,17 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 | 
				
			||||||
+    // Paper start
 | 
					+    // Paper start
 | 
				
			||||||
+    @Override
 | 
					+    @Override
 | 
				
			||||||
+    public Location getOrigin() {
 | 
					+    public Location getOrigin() {
 | 
				
			||||||
+        Location origin = getHandle().origin;
 | 
					+        Vector originVector = this.getHandle().getOriginVector();
 | 
				
			||||||
+        return origin == null ? null : origin.clone();
 | 
					+        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
 | 
					+    // Paper end
 | 
				
			||||||
 }
 | 
					 }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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.setUUID("Paper.OriginWorld", origin.getWorld().getUID());
 | 
					                 nbt.setUUID("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
 | 
				
			||||||
| 
						 | 
					@ -28,8 +28,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 | 
				
			||||||
             return nbt;
 | 
					             return nbt;
 | 
				
			||||||
         } catch (Throwable throwable) {
 | 
					         } catch (Throwable throwable) {
 | 
				
			||||||
@@ -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
 | 
				
			||||||
                 }
 | 
					                 this.originWorld = originWorld;
 | 
				
			||||||
                 origin = new org.bukkit.Location(originWorld, originTag.getDoubleAt(0), originTag.getDoubleAt(1), originTag.getDoubleAt(2));
 | 
					                 origin = new org.bukkit.util.Vector(originTag.getDoubleAt(0), originTag.getDoubleAt(1), originTag.getDoubleAt(2));
 | 
				
			||||||
             }
 | 
					             }
 | 
				
			||||||
+
 | 
					+
 | 
				
			||||||
+            spawnedViaMobSpawner = nbt.getBoolean("Paper.FromMobSpawner"); // Restore entity's from mob spawner status
 | 
					+            spawnedViaMobSpawner = nbt.getBoolean("Paper.FromMobSpawner"); // Restore entity's from mob spawner status
 | 
				
			||||||
| 
						 | 
					@ -53,8 +53,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 | 
				
			||||||
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
 | 
					--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
 | 
				
			||||||
+++ b/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 {
 | 
					@@ -0,0 +0,0 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
 | 
				
			||||||
         Location origin = getHandle().origin;
 | 
					         //noinspection ConstantConditions
 | 
				
			||||||
         return origin == null ? null : origin.clone();
 | 
					         return originVector.toLocation(world);
 | 
				
			||||||
     }
 | 
					     }
 | 
				
			||||||
+
 | 
					+
 | 
				
			||||||
+    @Override
 | 
					+    @Override
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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.setUUID("Paper.OriginWorld", origin.getWorld().getUID());
 | 
					                 nbt.setUUID("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) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -38,7 +38,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 | 
				
			||||||
             }
 | 
					             }
 | 
				
			||||||
+            // Paper start - Fix invulnerable end crystals
 | 
					+            // Paper start - Fix invulnerable end crystals
 | 
				
			||||||
+            if (this.level.paperConfig.fixInvulnerableEndCrystalExploit && this.generatedByDragonFight && this.isInvulnerable()) {
 | 
					+            if (this.level.paperConfig.fixInvulnerableEndCrystalExploit && this.generatedByDragonFight && this.isInvulnerable()) {
 | 
				
			||||||
+                if ((this.origin.getWorld() != null && !((ServerLevel) this.level).uuid.equals(this.origin.getWorld().getUID()))
 | 
					+                if (!java.util.Objects.equals(((ServerLevel) this.level).uuid, this.getOriginWorld())
 | 
				
			||||||
+                    || ((ServerLevel) this.level).dragonFight() == null
 | 
					+                    || ((ServerLevel) this.level).dragonFight() == null
 | 
				
			||||||
+                    || ((ServerLevel) this.level).dragonFight().respawnStage == null
 | 
					+                    || ((ServerLevel) this.level).dragonFight().respawnStage == null
 | 
				
			||||||
+                    || ((ServerLevel) this.level).dragonFight().respawnStage.ordinal() > net.minecraft.world.level.dimension.end.DragonRespawnAnimation.SUMMONING_DRAGON.ordinal()) {
 | 
					+                    || ((ServerLevel) this.level).dragonFight().respawnStage.ordinal() > net.minecraft.world.level.dimension.end.DragonRespawnAnimation.SUMMONING_DRAGON.ordinal()) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue