2020-05-06 11:48:49 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2019-05-05 04:23:25 +02: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
|
2020-08-02 07:39:36 +02:00
|
|
|
index 9cb2f3b31921870ddba044840e99eb04babe26bb..f0a836db74ad3e20778d3863223bc9a35ff4ad41 100644
|
2019-05-05 04:23:25 +02:00
|
|
|
--- a/src/main/java/com/destroystokyo/paper/PaperCommand.java
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/PaperCommand.java
|
2019-08-15 04:47:38 +02:00
|
|
|
@@ -179,6 +179,7 @@ public class PaperCommand extends Command {
|
2020-03-18 13:38:24 +01:00
|
|
|
Collection<Entity> entities = world.entitiesById.values();
|
|
|
|
entities.forEach(e -> {
|
2019-05-05 04:23:25 +02: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 07:39:36 +02:00
|
|
|
ChunkCoordIntPair chunk = new ChunkCoordIntPair(e.chunkX, e.chunkZ);
|
2019-05-05 04:23:25 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
|
2020-10-17 12:39:45 +02:00
|
|
|
index 18d55cea6258c7b59b79aec1bcdf358944d5b527..6154f7a7973168cbe294bc0f40894f05bf20513e 100644
|
2019-05-05 04:23:25 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/Chunk.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Chunk.java
|
2020-10-17 12:39:45 +02:00
|
|
|
@@ -821,6 +821,7 @@ public class Chunk implements IChunkAccess {
|
2019-05-05 04:23:25 +02:00
|
|
|
|
2020-06-25 16:09:55 +02:00
|
|
|
for (int i1 = 0; i1 < l; ++i1) {
|
|
|
|
Entity entity1 = (Entity) list1.get(i1);
|
|
|
|
+ if (entity1.shouldBeRemoved) continue; // Paper
|
2019-05-05 04:23:25 +02:00
|
|
|
|
2020-06-25 16:09:55 +02:00
|
|
|
if (entity1.getBoundingBox().c(axisalignedbb) && entity1 != entity) {
|
|
|
|
if (predicate == null || predicate.test(entity1)) {
|
2020-10-17 12:39:45 +02:00
|
|
|
@@ -857,6 +858,7 @@ public class Chunk implements IChunkAccess {
|
2019-05-05 04:23:25 +02:00
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|
2019-12-12 01:03:31 +01:00
|
|
|
T entity = (T) iterator.next(); // CraftBukkit - decompile error
|
2019-05-05 04:23:25 +02:00
|
|
|
+ if (entity.shouldBeRemoved) continue; // Paper
|
|
|
|
|
|
|
|
if ((entitytypes == null || entity.getEntityType() == entitytypes) && entity.getBoundingBox().c(axisalignedbb) && predicate.test(entity)) {
|
|
|
|
list.add(entity);
|
2020-10-17 12:39:45 +02:00
|
|
|
@@ -878,6 +880,7 @@ public class Chunk implements IChunkAccess {
|
2019-05-05 04:23:25 +02: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/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
|
2020-11-03 03:22:15 +01:00
|
|
|
index 29b24fd75f06501a814868d1fab85c9b818bd316..b2cccdc9f2f243cd3fb1283ade0280b2acb0f772 100644
|
2019-05-05 04:23:25 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/Entity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Entity.java
|
2020-09-19 13:29:53 +02:00
|
|
|
@@ -190,6 +190,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
|
2019-12-12 01:03:31 +01:00
|
|
|
protected int numCollisions = 0; // Paper
|
|
|
|
public void inactiveTick() { }
|
|
|
|
// Spigot end
|
2019-05-05 04:23:25 +02:00
|
|
|
+ public boolean shouldBeRemoved; // Paper
|
2019-12-12 01:03:31 +01:00
|
|
|
|
|
|
|
public float getBukkitYaw() {
|
|
|
|
return this.yaw;
|
2019-05-05 04:23:25 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
|
2020-11-03 03:22:15 +01:00
|
|
|
index 254f2567f36ced5c4309ea2df7952772bb279390..38fd15bd2f3503eae0be0aa2c939b8c737368c24 100644
|
2019-05-05 04:23:25 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/WorldServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/WorldServer.java
|
2020-11-03 03:22:15 +01:00
|
|
|
@@ -1196,6 +1196,7 @@ public class WorldServer extends World implements GeneratorAccessSeed {
|
2019-05-05 23:39:51 +02:00
|
|
|
entity.origin = entity.getBukkitEntity().getLocation();
|
2019-05-05 04:23:25 +02:00
|
|
|
}
|
2019-05-05 23:39:51 +02:00
|
|
|
// Paper end
|
2019-05-05 04:23:25 +02:00
|
|
|
+ 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
|
|
|
|
}
|
|
|
|
|
2020-11-03 03:22:15 +01:00
|
|
|
@@ -1208,6 +1209,7 @@ public class WorldServer extends World implements GeneratorAccessSeed {
|
2019-05-05 04:23:25 +02:00
|
|
|
this.removeEntityFromChunk(entity);
|
|
|
|
this.entitiesById.remove(entity.getId());
|
|
|
|
this.unregisterEntity(entity);
|
|
|
|
+ entity.shouldBeRemoved = true; // Paper
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
2020-08-25 04:22:08 +02:00
|
|
|
index e5e27c2ecc92f1a8c33cc7442e7034de1b4a4a84..fd314d9d530c347f9f78e81763a9a079b44aa751 100644
|
2019-05-05 04:23:25 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
2020-08-25 04:22:08 +02:00
|
|
|
@@ -1027,6 +1027,7 @@ public class CraftWorld implements World {
|
2019-05-05 04:23:25 +02:00
|
|
|
for (Object o : world.entitiesById.values()) {
|
|
|
|
if (o instanceof net.minecraft.server.Entity) {
|
|
|
|
net.minecraft.server.Entity mcEnt = (net.minecraft.server.Entity) o;
|
|
|
|
+ if (mcEnt.shouldBeRemoved) continue; // Paper
|
|
|
|
Entity bukkitEntity = mcEnt.getBukkitEntity();
|
|
|
|
|
|
|
|
// Assuming that bukkitEntity isn't null
|
2020-08-25 04:22:08 +02:00
|
|
|
@@ -1046,6 +1047,7 @@ public class CraftWorld implements World {
|
2019-05-05 04:23:25 +02:00
|
|
|
for (Object o : world.entitiesById.values()) {
|
|
|
|
if (o instanceof net.minecraft.server.Entity) {
|
|
|
|
net.minecraft.server.Entity mcEnt = (net.minecraft.server.Entity) o;
|
|
|
|
+ if (mcEnt.shouldBeRemoved) continue; // Paper
|
|
|
|
Entity bukkitEntity = mcEnt.getBukkitEntity();
|
|
|
|
|
|
|
|
// Assuming that bukkitEntity isn't null
|
2020-08-25 04:22:08 +02:00
|
|
|
@@ -1072,6 +1074,7 @@ public class CraftWorld implements World {
|
2019-05-05 04:23:25 +02:00
|
|
|
|
|
|
|
for (Object entity: world.entitiesById.values()) {
|
|
|
|
if (entity instanceof net.minecraft.server.Entity) {
|
|
|
|
+ if (((net.minecraft.server.Entity) entity).shouldBeRemoved) continue; // Paper
|
|
|
|
Entity bukkitEntity = ((net.minecraft.server.Entity) entity).getBukkitEntity();
|
|
|
|
|
|
|
|
if (bukkitEntity == null) {
|
2020-08-25 04:22:08 +02:00
|
|
|
@@ -1095,6 +1098,7 @@ public class CraftWorld implements World {
|
2019-05-05 04:23:25 +02:00
|
|
|
|
|
|
|
for (Object entity: world.entitiesById.values()) {
|
|
|
|
if (entity instanceof net.minecraft.server.Entity) {
|
|
|
|
+ if (((net.minecraft.server.Entity) entity).shouldBeRemoved) continue; // Paper
|
|
|
|
Entity bukkitEntity = ((net.minecraft.server.Entity) entity).getBukkitEntity();
|
|
|
|
|
|
|
|
if (bukkitEntity == null) {
|