mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-25 18:37:35 +01:00
f835a91d15
Upstream has added the equivalent of our SentientNPC API, with exception to the EnderDragon. We've added Mob to the EnderDragon, and our SentientNPC API should behave the same. Vex#getOwner has been deprecated and a replacement Vex#getSummoner has been added using Mob. However, since 1.13 is not production ready, SentientNPC API is subject for removal in 1.13.1 since 1.13 API is not compatible with 1.12. Please move to the Mob interface ASAP. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: c5ab54d8 Expand GameRule API ab9a606c Improve entity hierarchy by adding Mob interface. CraftBukkit Changes:29e75648
Expand GameRule API50e6858b
Improve entity hierarchy by adding Mob interface.0e1d79b4
Correct error in previous patch
88 lines
4.1 KiB
Diff
88 lines
4.1 KiB
Diff
From 05ba2bf241db3c4bc3e3d41d47723e9a260f5203 Mon Sep 17 00:00:00 2001
|
|
From: Aikar <aikar@aikar.co>
|
|
Date: Fri, 3 Aug 2018 22:47:46 -0400
|
|
Subject: [PATCH] Entity add to world fixes
|
|
|
|
1) Chunk Registration might kill an entity, don't add it to the world if it did!
|
|
|
|
2) By default, entities are added to the world per slice iteration.
|
|
This opens risk of the slices being manipulated during chunk add if an
|
|
EntityAddToWorldEvent spawns an entity into this chunk.
|
|
Fix this by differing entity add to world for all entities at the same time
|
|
|
|
3) If a duplicate entity is attempted to add to the world of an entity, and
|
|
the original entity is dead, overwrite it as the logic does for unloaod queued entities.
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
|
|
index e510940ab3..db8fbc006d 100644
|
|
--- a/src/main/java/net/minecraft/server/Chunk.java
|
|
+++ b/src/main/java/net/minecraft/server/Chunk.java
|
|
@@ -902,6 +902,7 @@ public class Chunk implements IChunkAccess {
|
|
this.world.b(this.tileEntities.values());
|
|
List[] aentityslice = this.entitySlices; // Spigot
|
|
int i = aentityslice.length;
|
|
+ List<Entity> toAdd = new java.util.ArrayList<>(32); // Paper
|
|
|
|
for (int j = 0; j < i; ++j) {
|
|
List entityslice = aentityslice[j]; // Spigot
|
|
@@ -948,10 +949,12 @@ public class Chunk implements IChunkAccess {
|
|
thisChunk.put(entity.uniqueID, entity);
|
|
}
|
|
}
|
|
- // Paper end
|
|
|
|
- this.world.a((Collection) entityslice);
|
|
+ //this.world.a((Collection) entityslice); // Move down, add all entities at same time
|
|
+ toAdd.addAll(entityslice);
|
|
+ // Paper end
|
|
}
|
|
+ this.world.addChunkEntities(toAdd); // Paper - add all at same time to avoid entities adding to world modifying slice state
|
|
|
|
// CraftBukkit start
|
|
org.bukkit.Server server = this.world.getServer();
|
|
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
|
|
index b0053e5e63..004c3ec474 100644
|
|
--- a/src/main/java/net/minecraft/server/World.java
|
|
+++ b/src/main/java/net/minecraft/server/World.java
|
|
@@ -1069,6 +1069,7 @@ public abstract class World implements GeneratorAccess, IIBlockAccess, AutoClose
|
|
}
|
|
|
|
this.getChunkAt(i, j).a(entity);
|
|
+ if (entity.dead) return false; // Paper - don't add dead entities, chunk registration may of killed it
|
|
this.entityList.add(entity);
|
|
this.b(entity);
|
|
return true;
|
|
@@ -2463,6 +2464,7 @@ public abstract class World implements GeneratorAccess, IIBlockAccess, AutoClose
|
|
return i;
|
|
}
|
|
|
|
+ public void addChunkEntities(Collection<Entity> collection) { a(collection); } // Paper - OBFHELPER
|
|
public void a(Collection<Entity> collection) {
|
|
org.spigotmc.AsyncCatcher.catchOp( "entity world add"); // Spigot
|
|
// CraftBukkit start
|
|
@@ -2472,7 +2474,7 @@ public abstract class World implements GeneratorAccess, IIBlockAccess, AutoClose
|
|
while (iterator.hasNext()) {
|
|
Entity entity = (Entity) iterator.next();
|
|
|
|
- if (entity == null) {
|
|
+ if (entity == null || entity.dead || entity.valid) { // Paper - prevent adding already added or dead entities
|
|
continue;
|
|
}
|
|
this.entityList.add(entity);
|
|
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
|
|
index 7a9f28421b..6412715b78 100644
|
|
--- a/src/main/java/net/minecraft/server/WorldServer.java
|
|
+++ b/src/main/java/net/minecraft/server/WorldServer.java
|
|
@@ -992,7 +992,7 @@ public class WorldServer extends World implements IAsyncTaskHandler {
|
|
if (this.entitiesByUUID.containsKey(uuid)) {
|
|
Entity entity1 = (Entity) this.entitiesByUUID.get(uuid);
|
|
|
|
- if (this.g.contains(entity1)) {
|
|
+ if (this.g.contains(entity1) || entity1.dead) { // Paper - if dupe is dead, overwrite
|
|
this.g.remove(entity1);
|
|
} else {
|
|
if (!(entity instanceof EntityHuman)) {
|
|
--
|
|
2.18.0
|
|
|