2019-04-06 05:08:45 +02:00
|
|
|
From 38b302a381c2e999cda2d6add7bf213adb295912 Mon Sep 17 00:00:00 2001
|
2018-07-28 18:26:36 +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
|
2019-04-06 05:08:45 +02:00
|
|
|
index f38179e983..8e1bda4de9 100644
|
2018-07-28 18:26:36 +02:00
|
|
|
--- a/src/main/java/com/destroystokyo/paper/PaperCommand.java
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/PaperCommand.java
|
2019-04-05 06:35:59 +02:00
|
|
|
@@ -176,6 +176,7 @@ public class PaperCommand extends Command {
|
2018-07-28 18:26:36 +02:00
|
|
|
List<Entity> entities = world.entityList;
|
|
|
|
entities.forEach(e -> {
|
2018-07-29 19:12:39 +02:00
|
|
|
MinecraftKey key = e.getMinecraftKey();
|
2018-07-28 18:26:36 +02:00
|
|
|
+ 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/Entity.java b/src/main/java/net/minecraft/server/Entity.java
|
2019-04-06 05:08:45 +02:00
|
|
|
index ead5af991c..cf69a4d8a4 100644
|
2018-07-28 18:26:36 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/Entity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Entity.java
|
2019-01-01 04:15:55 +01:00
|
|
|
@@ -121,6 +121,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
|
2018-07-29 19:12:39 +02:00
|
|
|
protected boolean F;
|
|
|
|
private boolean az;
|
2018-07-28 18:26:36 +02:00
|
|
|
public boolean dead;
|
|
|
|
+ public boolean shouldBeRemoved; // Paper
|
|
|
|
public float width;
|
|
|
|
public float length;
|
2018-07-29 19:12:39 +02:00
|
|
|
public float J;
|
2018-07-28 18:26:36 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
|
2019-04-06 05:08:45 +02:00
|
|
|
index 1cbe6e17b7..5d60b36678 100644
|
2018-07-28 18:26:36 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/World.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/World.java
|
2019-02-03 16:34:04 +01:00
|
|
|
@@ -1046,6 +1046,7 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
|
2018-07-31 23:39:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
entity.valid = true; // CraftBukkit
|
2018-07-31 23:41:33 +02:00
|
|
|
+ entity.shouldBeRemoved = false; // Paper - shouldn't be removed after being re-added
|
2018-07-31 23:39:15 +02:00
|
|
|
new com.destroystokyo.paper.event.entity.EntityAddToWorldEvent(entity.getBukkitEntity()).callEvent(); // Paper - fire while valid
|
|
|
|
}
|
|
|
|
|
2019-04-06 05:08:45 +02:00
|
|
|
@@ -1113,6 +1114,7 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
|
|
|
|
|
|
|
|
Chunk chunk = entity.getCurrentChunk(); // Paper
|
|
|
|
if (chunk != null) chunk.removeEntity(entity); // Paper
|
2018-07-28 18:26:36 +02:00
|
|
|
+ entity.shouldBeRemoved = true; // Paper
|
|
|
|
|
|
|
|
if (!guardEntityList) { // Spigot - It will get removed after the tick if we are ticking // Paper - always remove from current chunk above
|
|
|
|
// CraftBukkit start - Decrement loop variable field if we've already ticked this entity
|
2019-04-06 05:08:45 +02:00
|
|
|
@@ -2316,6 +2318,7 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
|
2018-07-28 18:26:36 +02:00
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
Entity entity = (Entity) iterator.next();
|
|
|
|
+ if (entity.shouldBeRemoved) continue; // Paper
|
|
|
|
|
2019-01-01 04:15:55 +01:00
|
|
|
if (oclass.isAssignableFrom(entity.getClass()) && predicate.test((T) entity)) { // CraftBukkit - decompile error
|
|
|
|
list.add((T) entity); // CraftBukkit - decompile error
|
2019-04-06 05:08:45 +02:00
|
|
|
@@ -2402,6 +2405,7 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
|
2018-07-28 18:26:36 +02:00
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
Entity entity = (Entity) iterator.next();
|
|
|
|
+ if (entity.shouldBeRemoved) continue; // Paper
|
2018-09-16 01:13:40 +02:00
|
|
|
// CraftBukkit start - Split out persistent check, don't apply it to special persistent mobs
|
|
|
|
if (entity instanceof EntityInsentient) {
|
|
|
|
EntityInsentient entityinsentient = (EntityInsentient) entity;
|
2018-07-28 18:26:36 +02:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
2019-04-06 05:08:45 +02:00
|
|
|
index 609b911265..4594bab465 100644
|
2018-07-28 18:26:36 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
2019-01-01 04:15:55 +01:00
|
|
|
@@ -634,6 +634,7 @@ public class CraftWorld implements World {
|
2018-07-28 18:26:36 +02:00
|
|
|
for (Object o : world.entityList) {
|
|
|
|
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-01-01 04:15:55 +01:00
|
|
|
@@ -652,6 +653,7 @@ public class CraftWorld implements World {
|
2018-07-28 18:26:36 +02:00
|
|
|
for (Object o : world.entityList) {
|
|
|
|
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-01-01 04:15:55 +01:00
|
|
|
@@ -676,6 +678,7 @@ public class CraftWorld implements World {
|
2018-07-28 18:26:36 +02:00
|
|
|
|
|
|
|
for (Object entity: world.entityList) {
|
|
|
|
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-01-01 04:15:55 +01:00
|
|
|
@@ -698,6 +701,7 @@ public class CraftWorld implements World {
|
2018-07-28 18:26:36 +02:00
|
|
|
|
|
|
|
for (Object entity: world.entityList) {
|
|
|
|
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-03-20 02:46:00 +01:00
|
|
|
2.21.0
|
2018-07-28 18:26:36 +02:00
|
|
|
|