2020-05-06 09:48:49 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2019-05-05 02:23:25 +00:00
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Sat, 28 Jul 2018 12:18:27 -0400
|
|
|
|
Subject: [PATCH] Ignore Dead Entities in entityList iteration
|
|
|
|
|
|
|
|
A spigot change delays removal of entities from the entity list.
|
|
|
|
This causes a change in behavior from Vanilla where getEntities type
|
|
|
|
methods will return dead entities that they shouldn't otherwise be doing.
|
|
|
|
|
|
|
|
This will ensure that dead entities are skipped from iteration since
|
|
|
|
they shouldn't of been in the list in the first place.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/PaperCommand.java b/src/main/java/com/destroystokyo/paper/PaperCommand.java
|
2021-03-16 07:19:45 +00:00
|
|
|
index 6943524c2dd8b12691b8ac5b08daee823ce50c3d..b67bd98cca4a06bc0ebaed577195dffc3b3251ec 100644
|
2019-05-05 02:23:25 +00:00
|
|
|
--- a/src/main/java/com/destroystokyo/paper/PaperCommand.java
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/PaperCommand.java
|
2021-01-05 21:25:45 +00:00
|
|
|
@@ -209,6 +209,7 @@ public class PaperCommand extends Command {
|
2020-03-18 12:38:24 +00:00
|
|
|
Collection<Entity> entities = world.entitiesById.values();
|
|
|
|
entities.forEach(e -> {
|
2019-05-05 02:23:25 +00:00
|
|
|
MinecraftKey key = e.getMinecraftKey();
|
|
|
|
+ if (e.shouldBeRemoved) return; // Paper
|
|
|
|
|
|
|
|
MutablePair<Integer, Map<ChunkCoordIntPair, Integer>> info = list.computeIfAbsent(key, k -> MutablePair.of(0, Maps.newHashMap()));
|
2020-08-02 05:39:36 +00:00
|
|
|
ChunkCoordIntPair chunk = new ChunkCoordIntPair(e.chunkX, e.chunkZ);
|
2021-03-16 07:19:45 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/WorldServer.java b/src/main/java/net/minecraft/server/level/WorldServer.java
|
2021-04-07 05:17:32 +00:00
|
|
|
index ce7431ea8597c645bb2c97f596796dbf12206e72..4eda8d2065d72c67b1e1cf9e9560e13e7f24d470 100644
|
2021-03-16 07:19:45 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/WorldServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/WorldServer.java
|
2021-04-07 05:17:32 +00:00
|
|
|
@@ -1309,6 +1309,7 @@ public class WorldServer extends World implements GeneratorAccessSeed {
|
2021-03-16 07:19:45 +00:00
|
|
|
entity.origin = entity.getBukkitEntity().getLocation();
|
|
|
|
}
|
|
|
|
// Paper end
|
|
|
|
+ entity.shouldBeRemoved = false; // Paper - shouldn't be removed after being re-added
|
|
|
|
new com.destroystokyo.paper.event.entity.EntityAddToWorldEvent(entity.getBukkitEntity()).callEvent(); // Paper - fire while valid
|
|
|
|
}
|
|
|
|
|
2021-04-07 05:17:32 +00:00
|
|
|
@@ -1321,6 +1322,7 @@ public class WorldServer extends World implements GeneratorAccessSeed {
|
2021-03-16 07:19:45 +00:00
|
|
|
this.removeEntityFromChunk(entity);
|
|
|
|
this.entitiesById.remove(entity.getId());
|
|
|
|
this.unregisterEntity(entity);
|
|
|
|
+ entity.shouldBeRemoved = true; // Paper
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
2021-03-16 15:50:45 +00:00
|
|
|
index 102c2bb98a99cdbfcdf1297341dbba91434ee0e3..046b191e771ed9be337e095214a67febd768e5f6 100644
|
2021-03-16 07:19:45 +00:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
2021-03-16 13:04:28 +00:00
|
|
|
@@ -276,6 +276,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne
|
2021-03-16 07:19:45 +00:00
|
|
|
protected int numCollisions = 0; // Paper
|
|
|
|
public void inactiveTick() { }
|
|
|
|
// Spigot end
|
|
|
|
+ public boolean shouldBeRemoved; // Paper
|
|
|
|
|
|
|
|
public float getBukkitYaw() {
|
|
|
|
return this.yaw;
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/chunk/Chunk.java b/src/main/java/net/minecraft/world/level/chunk/Chunk.java
|
2021-03-16 15:50:45 +00:00
|
|
|
index e4accac8f2e8daa58f9b0c279ffcad9347448bb0..79ff96f18c53f3d1ce4a00be2e2d8fe68f77bf54 100644
|
2021-03-16 07:19:45 +00:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/chunk/Chunk.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/chunk/Chunk.java
|
2021-03-16 15:50:45 +00:00
|
|
|
@@ -863,6 +863,7 @@ public class Chunk implements IChunkAccess {
|
2019-05-05 02:23:25 +00:00
|
|
|
|
2020-06-25 14:09:55 +00:00
|
|
|
for (int i1 = 0; i1 < l; ++i1) {
|
|
|
|
Entity entity1 = (Entity) list1.get(i1);
|
|
|
|
+ if (entity1.shouldBeRemoved) continue; // Paper
|
2019-05-05 02:23:25 +00:00
|
|
|
|
2020-06-25 14:09:55 +00:00
|
|
|
if (entity1.getBoundingBox().c(axisalignedbb) && entity1 != entity) {
|
|
|
|
if (predicate == null || predicate.test(entity1)) {
|
2021-03-16 15:50:45 +00:00
|
|
|
@@ -900,6 +901,7 @@ public class Chunk implements IChunkAccess {
|
2019-05-05 02:23:25 +00:00
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|
2019-12-12 00:03:31 +00:00
|
|
|
T entity = (T) iterator.next(); // CraftBukkit - decompile error
|
2019-05-05 02:23:25 +00:00
|
|
|
+ if (entity.shouldBeRemoved) continue; // Paper
|
|
|
|
|
|
|
|
if ((entitytypes == null || entity.getEntityType() == entitytypes) && entity.getBoundingBox().c(axisalignedbb) && predicate.test(entity)) {
|
|
|
|
list.add(entity);
|
2021-03-16 15:50:45 +00:00
|
|
|
@@ -922,6 +924,7 @@ public class Chunk implements IChunkAccess {
|
2019-05-05 02:23:25 +00:00
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
T t0 = (T) iterator.next(); // CraftBukkit - decompile error
|
|
|
|
+ if (t0.shouldBeRemoved) continue; // Paper
|
|
|
|
|
|
|
|
if (oclass.isInstance(t0) && t0.getBoundingBox().c(axisalignedbb) && (predicate == null || predicate.test(t0))) { // Spigot - instance check
|
|
|
|
list.add(t0);
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
2021-04-11 08:49:43 +00:00
|
|
|
index 284a554eb3d94c9b0807d6c84aafaa4680d671ea..d62522e731656e21ed3cc4f7aa4b6de3d84031fc 100644
|
2019-05-05 02:23:25 +00:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
2021-04-11 08:49:43 +00:00
|
|
|
@@ -1047,6 +1047,7 @@ public class CraftWorld implements World {
|
2019-05-05 02:23:25 +00:00
|
|
|
for (Object o : world.entitiesById.values()) {
|
2021-03-16 07:19:45 +00:00
|
|
|
if (o instanceof net.minecraft.world.entity.Entity) {
|
|
|
|
net.minecraft.world.entity.Entity mcEnt = (net.minecraft.world.entity.Entity) o;
|
2019-05-05 02:23:25 +00:00
|
|
|
+ if (mcEnt.shouldBeRemoved) continue; // Paper
|
|
|
|
Entity bukkitEntity = mcEnt.getBukkitEntity();
|
|
|
|
|
|
|
|
// Assuming that bukkitEntity isn't null
|
2021-04-11 08:49:43 +00:00
|
|
|
@@ -1066,6 +1067,7 @@ public class CraftWorld implements World {
|
2019-05-05 02:23:25 +00:00
|
|
|
for (Object o : world.entitiesById.values()) {
|
2021-03-16 07:19:45 +00:00
|
|
|
if (o instanceof net.minecraft.world.entity.Entity) {
|
|
|
|
net.minecraft.world.entity.Entity mcEnt = (net.minecraft.world.entity.Entity) o;
|
2019-05-05 02:23:25 +00:00
|
|
|
+ if (mcEnt.shouldBeRemoved) continue; // Paper
|
|
|
|
Entity bukkitEntity = mcEnt.getBukkitEntity();
|
|
|
|
|
|
|
|
// Assuming that bukkitEntity isn't null
|
2021-04-11 08:49:43 +00:00
|
|
|
@@ -1092,6 +1094,7 @@ public class CraftWorld implements World {
|
2019-05-05 02:23:25 +00:00
|
|
|
|
|
|
|
for (Object entity: world.entitiesById.values()) {
|
2021-03-16 07:19:45 +00:00
|
|
|
if (entity instanceof net.minecraft.world.entity.Entity) {
|
|
|
|
+ if (((net.minecraft.world.entity.Entity) entity).shouldBeRemoved) continue; // Paper
|
|
|
|
Entity bukkitEntity = ((net.minecraft.world.entity.Entity) entity).getBukkitEntity();
|
2019-05-05 02:23:25 +00:00
|
|
|
|
|
|
|
if (bukkitEntity == null) {
|
2021-04-11 08:49:43 +00:00
|
|
|
@@ -1115,6 +1118,7 @@ public class CraftWorld implements World {
|
2019-05-05 02:23:25 +00:00
|
|
|
|
|
|
|
for (Object entity: world.entitiesById.values()) {
|
2021-03-16 07:19:45 +00:00
|
|
|
if (entity instanceof net.minecraft.world.entity.Entity) {
|
|
|
|
+ if (((net.minecraft.world.entity.Entity) entity).shouldBeRemoved) continue; // Paper
|
|
|
|
Entity bukkitEntity = ((net.minecraft.world.entity.Entity) entity).getBukkitEntity();
|
2019-05-05 02:23:25 +00:00
|
|
|
|
|
|
|
if (bukkitEntity == null) {
|