Improve Light Queue and force enable it for all
There is no reason for the light queue to even be an option. This
enables the light queue for everyone.
This also improves the "can we still tick" time logic to always
check before running a light operation.
previously, we always executed at least 10 on the first world
(but not other worlds...), but we are seeing light take up some
heavy time, so improving that for now.
I've now also improved recheck gaps logic to happen at the end of all single block updates
This also prevents multiple gap checks, as previously if a tick skipped
the gaps check, the next tick would end up re-adding the entry again,
resulting in multiple gap checks.
This now just sets a marker "We need to recheck gaps" and will only occur
once.
This also should reduce chunk loads, as previously, we checked if
the neighbor chunks were loaded for the gap check, however those
neighbor chunks might of unloaded before the light queue operation
actually ran. Now, the neighbor chunk is done when the gap check
is being done, so it should avoid loading chunks.
Fixes #1466
Fixes #1431
2018-09-22 15:46:31 +00:00
From ae23abdc7f17c83315f4b81e56103f73235179f6 Mon Sep 17 00:00:00 2001
2018-08-04 03:02:44 +00:00
From: Aikar <aikar@aikar.co>
Date: Fri, 3 Aug 2018 22:47:46 -0400
Subject: [PATCH] Entity add to world fixes
1) Chunk Registration might kill an entity, don't add it to the world if it did!
2) By default, entities are added to the world per slice iteration.
This opens risk of the slices being manipulated during chunk add if an
EntityAddToWorldEvent spawns an entity into this chunk.
Fix this by differing entity add to world for all entities at the same time
3) If a duplicate entity is attempted to add to the world of an entity, and
the original entity is dead, overwrite it as the logic does for unloaod queued entities.
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
Improve Light Queue and force enable it for all
There is no reason for the light queue to even be an option. This
enables the light queue for everyone.
This also improves the "can we still tick" time logic to always
check before running a light operation.
previously, we always executed at least 10 on the first world
(but not other worlds...), but we are seeing light take up some
heavy time, so improving that for now.
I've now also improved recheck gaps logic to happen at the end of all single block updates
This also prevents multiple gap checks, as previously if a tick skipped
the gaps check, the next tick would end up re-adding the entry again,
resulting in multiple gap checks.
This now just sets a marker "We need to recheck gaps" and will only occur
once.
This also should reduce chunk loads, as previously, we checked if
the neighbor chunks were loaded for the gap check, however those
neighbor chunks might of unloaded before the light queue operation
actually ran. Now, the neighbor chunk is done when the gap check
is being done, so it should avoid loading chunks.
Fixes #1466
Fixes #1431
2018-09-22 15:46:31 +00:00
index 39cbde281b..4a39461eb2 100644
2018-08-04 03:02:44 +00:00
--- a/src/main/java/net/minecraft/server/Chunk.java
+++ b/src/main/java/net/minecraft/server/Chunk.java
Improve Light Queue and force enable it for all
There is no reason for the light queue to even be an option. This
enables the light queue for everyone.
This also improves the "can we still tick" time logic to always
check before running a light operation.
previously, we always executed at least 10 on the first world
(but not other worlds...), but we are seeing light take up some
heavy time, so improving that for now.
I've now also improved recheck gaps logic to happen at the end of all single block updates
This also prevents multiple gap checks, as previously if a tick skipped
the gaps check, the next tick would end up re-adding the entry again,
resulting in multiple gap checks.
This now just sets a marker "We need to recheck gaps" and will only occur
once.
This also should reduce chunk loads, as previously, we checked if
the neighbor chunks were loaded for the gap check, however those
neighbor chunks might of unloaded before the light queue operation
actually ran. Now, the neighbor chunk is done when the gap check
is being done, so it should avoid loading chunks.
Fixes #1466
Fixes #1431
2018-09-22 15:46:31 +00:00
@@ -899,6 +899,7 @@ public class Chunk implements IChunkAccess {
2018-08-26 18:11:49 +00:00
this.world.a(this.tileEntities.values());
2018-08-04 03:02:44 +00:00
List[] aentityslice = this.entitySlices; // Spigot
int i = aentityslice.length;
+ List<Entity> toAdd = new java.util.ArrayList<>(32); // Paper
for (int j = 0; j < i; ++j) {
List entityslice = aentityslice[j]; // Spigot
Improve Light Queue and force enable it for all
There is no reason for the light queue to even be an option. This
enables the light queue for everyone.
This also improves the "can we still tick" time logic to always
check before running a light operation.
previously, we always executed at least 10 on the first world
(but not other worlds...), but we are seeing light take up some
heavy time, so improving that for now.
I've now also improved recheck gaps logic to happen at the end of all single block updates
This also prevents multiple gap checks, as previously if a tick skipped
the gaps check, the next tick would end up re-adding the entry again,
resulting in multiple gap checks.
This now just sets a marker "We need to recheck gaps" and will only occur
once.
This also should reduce chunk loads, as previously, we checked if
the neighbor chunks were loaded for the gap check, however those
neighbor chunks might of unloaded before the light queue operation
actually ran. Now, the neighbor chunk is done when the gap check
is being done, so it should avoid loading chunks.
Fixes #1466
Fixes #1431
2018-09-22 15:46:31 +00:00
@@ -946,12 +947,11 @@ public class Chunk implements IChunkAccess {
2018-08-04 03:02:44 +00:00
thisChunk.put(entity.uniqueID, entity);
}
}
- // Paper end
2018-08-26 18:11:49 +00:00
- this.world.a(entityslice.stream().filter((entity) -> {
- return !(entity instanceof EntityHuman);
- }));
2018-08-04 03:02:44 +00:00
+ toAdd.addAll(entityslice);
+ // Paper end
}
2018-08-26 18:11:49 +00:00
+ this.world.addChunkEntities(toAdd.stream().filter((entity) -> !(entity instanceof EntityHuman))); // Paper - add all at same time to avoid entities adding to world modifying slice state
2018-08-04 03:02:44 +00:00
2018-08-04 04:33:21 +00:00
// CraftBukkit start
org.bukkit.Server server = this.world.getServer();
2018-08-04 03:02:44 +00:00
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
2018-09-18 01:50:02 +00:00
index aa94e399af..85570e4a5d 100644
2018-08-04 03:02:44 +00:00
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
2018-09-18 01:50:02 +00:00
@@ -1102,6 +1102,7 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
2018-08-04 03:02:44 +00:00
}
this.getChunkAt(i, j).a(entity);
+ if (entity.dead) return false; // Paper - don't add dead entities, chunk registration may of killed it
this.entityList.add(entity);
this.b(entity);
return true;
2018-09-18 01:50:02 +00:00
@@ -2507,9 +2508,13 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
2018-08-26 18:11:49 +00:00
return j;
2018-08-04 03:02:44 +00:00
}
2018-08-26 18:11:49 +00:00
+ public void addChunkEntities(Stream<Entity> collection) { a(collection); } // Paper - OBFHELPER
public void a(Stream<Entity> stream) {
2018-08-04 03:02:44 +00:00
org.spigotmc.AsyncCatcher.catchOp( "entity world add"); // Spigot
2018-08-26 18:11:49 +00:00
stream.forEach((entity) -> {
2018-08-04 03:02:44 +00:00
+ if (entity == null || entity.dead || entity.valid) { // Paper - prevent adding already added or dead entities
2018-08-26 18:11:49 +00:00
+ return;
+ }
2018-08-04 03:02:44 +00:00
this.entityList.add(entity);
2018-08-26 18:11:49 +00:00
this.b(entity);
});
2018-08-04 03:02:44 +00:00
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
2018-09-15 16:10:26 +00:00
index 2692d0a1b6..911d03c70b 100644
2018-08-04 03:02:44 +00:00
--- a/src/main/java/net/minecraft/server/WorldServer.java
+++ b/src/main/java/net/minecraft/server/WorldServer.java
2018-08-26 18:11:49 +00:00
@@ -987,7 +987,7 @@ public class WorldServer extends World implements IAsyncTaskHandler {
2018-08-04 03:02:44 +00:00
if (this.entitiesByUUID.containsKey(uuid)) {
Entity entity1 = (Entity) this.entitiesByUUID.get(uuid);
2018-08-04 04:33:21 +00:00
- if (this.g.contains(entity1)) {
+ if (this.g.contains(entity1) || entity1.dead) { // Paper - if dupe is dead, overwrite
this.g.remove(entity1);
2018-08-04 03:02:44 +00:00
} else {
if (!(entity instanceof EntityHuman)) {
--
2018-09-15 16:10:26 +00:00
2.19.0
2018-08-04 03:02:44 +00:00