2018-08-17 22:01:37 +00:00
|
|
|
From f10e7ff6485116d84387c75904aca336a4bfc89c Mon Sep 17 00:00:00 2001
|
2018-07-28 16:26:36 +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
|
2018-08-17 22:01:37 +00:00
|
|
|
index 7ff8e70b2..4e854c6db 100644
|
2018-07-28 16:26:36 +00:00
|
|
|
--- a/src/main/java/com/destroystokyo/paper/PaperCommand.java
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/PaperCommand.java
|
2018-07-29 17:12:39 +00:00
|
|
|
@@ -172,6 +172,7 @@ public class PaperCommand extends Command {
|
2018-07-28 16:26:36 +00:00
|
|
|
List<Entity> entities = world.entityList;
|
|
|
|
entities.forEach(e -> {
|
2018-07-29 17:12:39 +00:00
|
|
|
MinecraftKey key = e.getMinecraftKey();
|
2018-07-28 16:26:36 +00: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
|
2018-08-17 22:01:37 +00:00
|
|
|
index 785c31089..6b0ca4eb9 100644
|
2018-07-28 16:26:36 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/Entity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Entity.java
|
2018-07-31 01:19:41 +00:00
|
|
|
@@ -122,6 +122,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
|
2018-07-29 17:12:39 +00:00
|
|
|
protected boolean F;
|
|
|
|
private boolean az;
|
2018-07-28 16:26:36 +00:00
|
|
|
public boolean dead;
|
|
|
|
+ public boolean shouldBeRemoved; // Paper
|
|
|
|
public float width;
|
|
|
|
public float length;
|
2018-07-29 17:12:39 +00:00
|
|
|
public float J;
|
2018-07-28 16:26:36 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
|
2018-08-17 22:01:37 +00:00
|
|
|
index ff0112c52..82f4f00a7 100644
|
2018-07-28 16:26:36 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/World.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/World.java
|
2018-08-04 01:20:57 +00:00
|
|
|
@@ -1078,6 +1078,7 @@ public abstract class World implements GeneratorAccess, IIBlockAccess, AutoClose
|
2018-07-31 21:39:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
entity.valid = true; // CraftBukkit
|
2018-07-31 21:41:33 +00:00
|
|
|
+ entity.shouldBeRemoved = false; // Paper - shouldn't be removed after being re-added
|
2018-07-31 21:39:15 +00:00
|
|
|
new com.destroystokyo.paper.event.entity.EntityAddToWorldEvent(entity.getBukkitEntity()).callEvent(); // Paper - fire while valid
|
|
|
|
}
|
|
|
|
|
2018-08-04 01:20:57 +00:00
|
|
|
@@ -1143,6 +1144,7 @@ public abstract class World implements GeneratorAccess, IIBlockAccess, AutoClose
|
2018-07-29 17:12:39 +00:00
|
|
|
if (entity.inChunk && this.isChunkLoaded(i, j, true)) {
|
2018-07-28 16:26:36 +00:00
|
|
|
this.getChunkAt(i, j).b(entity);
|
|
|
|
}
|
|
|
|
+ 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
|
2018-08-04 01:20:57 +00:00
|
|
|
@@ -2350,6 +2352,7 @@ public abstract class World implements GeneratorAccess, IIBlockAccess, AutoClose
|
2018-07-28 16:26:36 +00:00
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
Entity entity = (Entity) iterator.next();
|
|
|
|
+ if (entity.shouldBeRemoved) continue; // Paper
|
|
|
|
|
2018-07-29 17:12:39 +00:00
|
|
|
if (oclass.isAssignableFrom(entity.getClass()) && predicate.test((T) entity)) {
|
2018-07-28 16:26:36 +00:00
|
|
|
arraylist.add(entity);
|
2018-08-04 01:20:57 +00:00
|
|
|
@@ -2436,6 +2439,7 @@ public abstract class World implements GeneratorAccess, IIBlockAccess, AutoClose
|
2018-07-28 16:26:36 +00:00
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
Entity entity = (Entity) iterator.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;
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
2018-08-17 22:01:37 +00:00
|
|
|
index 9294d1707..b09f0353a 100644
|
2018-07-28 16:26:36 +00:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
2018-07-29 17:12:39 +00:00
|
|
|
@@ -660,6 +660,7 @@ public class CraftWorld implements World {
|
2018-07-28 16:26:36 +00: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
|
2018-07-29 17:12:39 +00:00
|
|
|
@@ -678,6 +679,7 @@ public class CraftWorld implements World {
|
2018-07-28 16:26:36 +00: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
|
2018-07-29 17:12:39 +00:00
|
|
|
@@ -702,6 +704,7 @@ public class CraftWorld implements World {
|
2018-07-28 16:26:36 +00: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) {
|
2018-07-29 17:12:39 +00:00
|
|
|
@@ -724,6 +727,7 @@ public class CraftWorld implements World {
|
2018-07-28 16:26:36 +00: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) {
|
|
|
|
--
|
2018-08-03 04:06:20 +00:00
|
|
|
2.18.0
|
2018-07-28 16:26:36 +00:00
|
|
|
|