2018-09-28 23:31:59 +00:00
From f73262650a77e5b3300a76bc932eb6c96b0b60b8 Mon Sep 17 00:00:00 2001
2018-07-24 02:55:27 +00:00
From: Aikar <aikar@aikar.co>
Date: Mon, 23 Jul 2018 22:44:23 -0400
Subject: [PATCH] Add some Debug to Chunk Entity slices
If we detect unexpected state, log and try to recover
This should hopefully avoid duplicate entities ever being created
if the entity was to end up in 2 different chunk slices
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
2018-09-28 23:31:59 +00:00
index 17f1e71d48..a75b058e2a 100644
2018-07-24 02:55:27 +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
@@ -710,8 +710,34 @@ public class Chunk implements IChunkAccess {
2018-07-24 03:20:41 +00:00
entity.ae = this.locX;
entity.af = k;
entity.ag = this.locZ;
2018-07-24 02:55:27 +00:00
- this.entitySlices[k].add(entity);
+
// Paper start
+ List<Entity> entitySlice = this.entitySlices[k];
+ boolean inThis = entitySlice.contains(entity);
2018-08-20 04:54:03 +00:00
+ List<Entity> currentSlice = entity.entitySlice;
+ if ((currentSlice != null && currentSlice.contains(entity)) || inThis) {
+ if (currentSlice == entitySlice || inThis) {
+ LogManager.getLogger().warn(entity + " was already in this chunk section! Report this to https://github.com/PaperMC/Paper/issues/1302");
2018-07-24 02:55:27 +00:00
+ new Throwable().printStackTrace();
+ return;
+ } else {
2018-08-20 04:54:03 +00:00
+ LogManager.getLogger().warn(entity + " is still in another ChunkSection! Report this to https://github.com/PaperMC/Paper/issues/1302");
2018-07-24 02:55:27 +00:00
+
+ Chunk chunk = entity.getCurrentChunk();
+ if (chunk != null) {
+ if (chunk != this) {
+ LogManager.getLogger().warn(entity + " was in another chunk at that! " + chunk.locX + "," + chunk.locZ);
+ }
+ chunk.removeEntity(entity);
+ } else {
+ removeEntity(entity);
+ }
+ new Throwable().printStackTrace();
+ }
+ }
+ entity.entitySlice = entitySlice;
+ entitySlice.add(entity);
+
this.markDirty();
2018-07-24 03:20:41 +00:00
if (entity instanceof EntityItem) {
itemCounts[k]++;
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
@@ -741,9 +767,13 @@ public class Chunk implements IChunkAccess {
2018-08-20 04:58:08 +00:00
i = this.entitySlices.length - 1;
2018-07-24 03:20:41 +00:00
}
2018-07-24 02:55:27 +00:00
// Paper start
2018-08-20 04:58:08 +00:00
- if (!this.entitySlices[i].remove(entity)) {
- return;
2018-08-21 00:20:40 +00:00
+ if (entity.entitySlice == null || !entity.entitySlice.contains(entity) || entitySlices[i] == entity.entitySlice) {
2018-07-24 02:55:27 +00:00
+ entity.entitySlice = null;
+ } else {
2018-08-20 04:54:03 +00:00
+ LogManager.getLogger().warn(entity + " was removed from a entitySlice we did not expect. Report this to https://github.com/PaperMC/Paper/issues/1302");
2018-07-24 02:55:27 +00:00
+ new Throwable().printStackTrace();
2018-08-20 04:58:08 +00:00
}
+ if (!this.entitySlices[i].remove(entity)) { return; }
2018-07-24 02:55:27 +00:00
this.markDirty();
2018-07-24 03:20:41 +00:00
if (entity instanceof EntityItem) {
itemCounts[i]--;
2018-09-28 23:31:59 +00:00
@@ -1017,6 +1047,7 @@ public class Chunk implements IChunkAccess {
2018-07-30 04:51:58 +00:00
}
// Spigot End
entity.setCurrentChunk(null); // Paper
+ entity.entitySlice = null; // Paper
// Do not pass along players, as doing so can get them stuck outside of time.
// (which for example disables inventory icon updates and prevents block breaking)
2018-07-24 02:55:27 +00:00
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
2018-09-27 02:35:42 +00:00
index 0381f8e658..965cd592f3 100644
2018-07-24 02:55:27 +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
@@ -64,6 +64,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
2018-07-24 02:55:27 +00:00
}
}
};
2018-08-20 04:54:03 +00:00
+ List<Entity> entitySlice = null;
2018-07-24 02:55:27 +00:00
// Paper end
static boolean isLevelAtLeast(NBTTagCompound tag, int level) {
return tag.hasKey("Bukkit.updateLevel") && tag.getInt("Bukkit.updateLevel") >= level;
--
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
2.19.0
2018-07-24 02:55:27 +00:00