2019-06-25 13:55:44 +00:00
|
|
|
From cf1eba4249fbb1139b10ce3007247a2b4d5d62b1 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
|
2019-06-25 01:47:58 +00:00
|
|
|
index 360abc05e4..391726d99c 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
|
|
|
|
@@ -176,6 +176,7 @@ public class PaperCommand extends Command {
|
2019-05-09 14:23:52 +00:00
|
|
|
Collection<Entity> entities = world.entitiesById.values();
|
2019-05-05 02:23:25 +00:00
|
|
|
entities.forEach(e -> {
|
|
|
|
MinecraftKey key = e.getMinecraftKey();
|
|
|
|
+ if (e.shouldBeRemoved) return; // Paper
|
|
|
|
|
|
|
|
MutablePair<Integer, Map<ChunkCoordIntPair, Integer>> info = list.computeIfAbsent(key, k -> MutablePair.of(0, Maps.newHashMap()));
|
|
|
|
ChunkCoordIntPair chunk = new ChunkCoordIntPair(e.getChunkX(), e.getChunkZ());
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
|
2019-06-25 01:47:58 +00:00
|
|
|
index ebc00f355e..099f0ad78b 100644
|
2019-05-05 02:23:25 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/Chunk.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Chunk.java
|
2019-05-27 23:01:45 +00:00
|
|
|
@@ -678,6 +678,7 @@ public class Chunk implements IChunkAccess {
|
2019-05-05 02:23:25 +00:00
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
Entity entity1 = (Entity) iterator.next();
|
|
|
|
+ if (entity1.shouldBeRemoved) continue; // Paper
|
|
|
|
|
|
|
|
if (entity1.getBoundingBox().c(axisalignedbb) && entity1 != entity) {
|
|
|
|
if (predicate == null || predicate.test(entity1)) {
|
2019-05-27 23:01:45 +00:00
|
|
|
@@ -715,6 +716,7 @@ public class Chunk implements IChunkAccess {
|
2019-05-05 02:23:25 +00:00
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
Entity entity = (Entity) iterator.next();
|
|
|
|
+ if (entity.shouldBeRemoved) continue; // Paper
|
|
|
|
|
|
|
|
if ((entitytypes == null || entity.getEntityType() == entitytypes) && entity.getBoundingBox().c(axisalignedbb) && predicate.test(entity)) {
|
|
|
|
list.add(entity);
|
2019-05-27 23:01:45 +00:00
|
|
|
@@ -736,6 +738,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/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
|
2019-06-25 01:47:58 +00:00
|
|
|
index e1cd5e72a5..b02b084556 100644
|
2019-05-05 02:23:25 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/Entity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Entity.java
|
2019-05-06 02:58:04 +00:00
|
|
|
@@ -126,6 +126,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
|
2019-05-05 02:23:25 +00:00
|
|
|
public float D;
|
|
|
|
public float E;
|
2019-05-05 11:32:20 +00:00
|
|
|
public float F;
|
2019-05-05 02:23:25 +00:00
|
|
|
+ public boolean shouldBeRemoved; // Paper
|
|
|
|
public float fallDistance;
|
|
|
|
private float av;
|
|
|
|
private float aw;
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
|
2019-06-25 13:55:44 +00:00
|
|
|
index e36e1c2721..adeff1ef19 100644
|
2019-05-05 02:23:25 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/WorldServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/WorldServer.java
|
2019-06-25 13:55:44 +00:00
|
|
|
@@ -846,6 +846,7 @@ public class WorldServer extends World {
|
2019-05-05 02:23:25 +00:00
|
|
|
|
|
|
|
while (objectiterator.hasNext()) {
|
|
|
|
Entity entity = (Entity) objectiterator.next();
|
|
|
|
+ if (entity.shouldBeRemoved) continue; // Paper
|
|
|
|
// CraftBukkit start - Split out persistent check, don't apply it to special persistent mobs
|
|
|
|
if (entity instanceof EntityInsentient) {
|
|
|
|
EntityInsentient entityinsentient = (EntityInsentient) entity;
|
2019-06-25 13:55:44 +00:00
|
|
|
@@ -1138,6 +1139,7 @@ public class WorldServer extends World {
|
2019-05-05 21:39:51 +00:00
|
|
|
entity.origin = entity.getBukkitEntity().getLocation();
|
2019-05-05 02:23:25 +00:00
|
|
|
}
|
2019-05-05 21:39:51 +00:00
|
|
|
// Paper end
|
2019-05-05 02:23:25 +00: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
|
|
|
|
}
|
|
|
|
|
2019-06-25 13:55:44 +00:00
|
|
|
@@ -1152,6 +1154,7 @@ public class WorldServer extends World {
|
2019-05-05 02:23:25 +00: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
|
2019-06-25 01:47:58 +00:00
|
|
|
index 3dd9bec548..6918f77b79 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
|
2019-06-25 01:47:58 +00:00
|
|
|
@@ -845,6 +845,7 @@ public class CraftWorld implements World {
|
2019-05-05 02:23:25 +00: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
|
2019-06-25 01:47:58 +00:00
|
|
|
@@ -864,6 +865,7 @@ public class CraftWorld implements World {
|
2019-05-05 02:23:25 +00: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
|
2019-06-25 01:47:58 +00:00
|
|
|
@@ -890,6 +892,7 @@ public class CraftWorld implements World {
|
2019-05-05 02:23:25 +00: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) {
|
2019-06-25 01:47:58 +00:00
|
|
|
@@ -913,6 +916,7 @@ public class CraftWorld implements World {
|
2019-05-05 02:23:25 +00: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) {
|
|
|
|
--
|
2019-06-25 01:47:58 +00:00
|
|
|
2.22.0
|
2019-05-05 02:23:25 +00:00
|
|
|
|