diff options
author | Spottedleaf <[email protected]> | 2020-07-27 19:42:59 -0700 |
---|---|---|
committer | GitHub <[email protected]> | 2020-07-27 22:42:59 -0400 |
commit | 51741a18064b9fa4df6c231d55cf30a042e6e271 (patch) | |
tree | 5863c55307ea8f2428a054751395e4144b91f122 | |
parent | 5657364b458ddc78cedd404eb78b7c2b638fdde7 (diff) | |
download | Paper-51741a18064b9fa4df6c231d55cf30a042e6e271.tar.gz Paper-51741a18064b9fa4df6c231d55cf30a042e6e271.zip |
[1.15] Tighten logic for handling target tick times in tick scheduler (#4011)
No longer rely on world time as plugins like to screw it up.
Add a new flag -Dpaper.ticklist-max-tick-delay= that
will automatically drop any tick entries that have a delay
exceeding the specified amount. This is only useful
for cleaning up a world that has been corrupted by
certain blocks having a huge tick delay.
Also fix an issue with some rails connecting incorrectly
that I found when testing.
Co-authored-by: Spottedleaf <[email protected]>
-rw-r--r-- | Spigot-Server-Patches/0446-Optimise-TickListServer-by-rewriting-it.patch | 56 | ||||
-rw-r--r-- | Spigot-Server-Patches/0551-Fix-some-rails-connecting-improperly.patch | 95 | ||||
-rw-r--r-- | Spigot-Server-Patches/0552-Optimize-the-advancement-data-player-iteration-to-be.patch (renamed from Spigot-Server-Patches/0551-Optimize-the-advancement-data-player-iteration-to-be.patch) | 0 | ||||
-rw-r--r-- | Spigot-Server-Patches/0553-Move-range-check-for-block-placing-up.patch (renamed from Spigot-Server-Patches/0552-Move-range-check-for-block-placing-up.patch) | 0 | ||||
-rw-r--r-- | Spigot-Server-Patches/0554-Fix-AdvancementDataPlayer-leak-due-from-quitting-ear.patch (renamed from Spigot-Server-Patches/0553-Fix-AdvancementDataPlayer-leak-due-from-quitting-ear.patch) | 0 |
5 files changed, 142 insertions, 9 deletions
diff --git a/Spigot-Server-Patches/0446-Optimise-TickListServer-by-rewriting-it.patch b/Spigot-Server-Patches/0446-Optimise-TickListServer-by-rewriting-it.patch index 24d53ad14e..84a69e462f 100644 --- a/Spigot-Server-Patches/0446-Optimise-TickListServer-by-rewriting-it.patch +++ b/Spigot-Server-Patches/0446-Optimise-TickListServer-by-rewriting-it.patch @@ -61,10 +61,10 @@ index 74295466e53db06d0d019a13768f3575ac61d699..f1b41e16c8ce8323a896339c5d822f8f ConfigurationSection section; diff --git a/src/main/java/com/destroystokyo/paper/server/ticklist/PaperTickList.java b/src/main/java/com/destroystokyo/paper/server/ticklist/PaperTickList.java new file mode 100644 -index 0000000000000000000000000000000000000000..ce653f6b4be3ab6c6d35cb3e9222e7f8c8759e25 +index 0000000000000000000000000000000000000000..466d4ae811e85fa95bca007ec3f533dabf8a1603 --- /dev/null +++ b/src/main/java/com/destroystokyo/paper/server/ticklist/PaperTickList.java -@@ -0,0 +1,622 @@ +@@ -0,0 +1,630 @@ +package com.destroystokyo.paper.server.ticklist; + +import net.minecraft.server.MCUtil; @@ -72,7 +72,6 @@ index 0000000000000000000000000000000000000000..ce653f6b4be3ab6c6d35cb3e9222e7f8 +import it.unimi.dsi.fastutil.longs.Long2ObjectMap; +import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.objects.ObjectRBTreeSet; -+import net.minecraft.server.BaseBlockPosition; +import net.minecraft.server.BlockPosition; +import net.minecraft.server.ChunkCoordIntPair; +import net.minecraft.server.ChunkProviderServer; @@ -269,7 +268,7 @@ index 0000000000000000000000000000000000000000..ce653f6b4be3ab6c6d35cb3e9222e7f8 + } + + private void prepare() { -+ final long currentTick = this.world.getTime(); ++ final long currentTick = this.nextTick; + + final ChunkProviderServer chunkProvider = this.world.getChunkProvider(); + @@ -334,8 +333,18 @@ index 0000000000000000000000000000000000000000..ce653f6b4be3ab6c6d35cb3e9222e7f8 + } + } + ++ private boolean warnedAboutDesync; ++ + @Override + public void tick() { ++ ++this.nextTick; ++ if (this.nextTick != this.world.getTime()) { ++ if (!this.warnedAboutDesync) { ++ this.warnedAboutDesync = true; ++ MinecraftServer.LOGGER.error("World tick desync detected! Expected " + this.nextTick + " ticks, but got " + this.world.getTime() + " ticks for world '" + this.world.getWorld().getName() + "'", new Throwable()); ++ MinecraftServer.LOGGER.error("Preventing redstone from breaking by refusing to accept new tick time"); ++ } ++ } + final ChunkProviderServer chunkProvider = this.world.getChunkProvider(); + + this.world.getMethodProfiler().enter("cleaning"); @@ -346,7 +355,6 @@ index 0000000000000000000000000000000000000000..ce653f6b4be3ab6c6d35cb3e9222e7f8 + // this must be done here in case something schedules in the tick code + this.shortScheduled[this.shortScheduledIndex].clear(); + this.shortScheduledIndex = getNextIndex(this.shortScheduledIndex, SHORT_SCHEDULE_TICK_THRESHOLD); -+ this.nextTick = this.world.getTime() + 1; + + this.timingCleanup.stopTiming(); + this.world.getMethodProfiler().exitEnter("ticking"); @@ -473,7 +481,7 @@ index 0000000000000000000000000000000000000000..ce653f6b4be3ab6c6d35cb3e9222e7f8 + + @Override + public void schedule(BlockPosition blockPosition, T t, int i, TickListPriority tickListPriority) { -+ this.schedule(blockPosition, t, i + this.world.getTime(), tickListPriority); ++ this.schedule(blockPosition, t, i + this.nextTick, tickListPriority); + } + + public void schedule(final NextTickListEntry<T> entry) { @@ -649,7 +657,7 @@ index 0000000000000000000000000000000000000000..ce653f6b4be3ab6c6d35cb3e9222e7f8 + // start copy from TickListServer // TODO check on update + List<NextTickListEntry<T>> list = this.getEntriesInChunk(chunkcoordintpair, false, true); + -+ return TickListServer.serialize(this.getMinecraftKeyFrom, list, this.world.getTime()); ++ return TickListServer.serialize(this.getMinecraftKeyFrom, list, this.nextTick); + // end copy from TickListServer + } + @@ -883,7 +891,7 @@ index 0000000000000000000000000000000000000000..118988c39e58f28e8a2851792b9c014f + } +} diff --git a/src/main/java/net/minecraft/server/BlockPosition.java b/src/main/java/net/minecraft/server/BlockPosition.java -index 3fcfe416d26808fa1c9bfdc5b413b149764c544a..3bf17ccdaef21322b787db538d569e0bc614ef22 100644 +index 9fc34246a845168d158a6b2793d8e344f2d2b008..8c3e09a5a3b4e6c38790735db4b3b316d7cdd39a 100644 --- a/src/main/java/net/minecraft/server/BlockPosition.java +++ b/src/main/java/net/minecraft/server/BlockPosition.java @@ -126,6 +126,7 @@ public class BlockPosition extends BaseBlockPosition implements MinecraftSeriali @@ -895,7 +903,7 @@ index 3fcfe416d26808fa1c9bfdc5b413b149764c544a..3bf17ccdaef21322b787db538d569e0b return this.b(baseblockposition.getX(), baseblockposition.getY(), baseblockposition.getZ()); } diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java -index 6688b1340e2cc8fb13a7e80c9b7c37b8822dcecd..d53b34ba552771bf271131ce0a56ebb992ccc84c 100644 +index e467cd8123dafc46a8c894f1ffa9440de0d45340..9e3471be219b5e061486c8a3e4b638a45e6f28f5 100644 --- a/src/main/java/net/minecraft/server/ChunkProviderServer.java +++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java @@ -200,6 +200,13 @@ public class ChunkProviderServer extends IChunkProvider { @@ -1037,6 +1045,36 @@ index dbb565e74d211ef35d5d40b3d024e2f07cef9031..185658e230688a9939c89dae9167217c public boolean b(BaseBlockPosition baseblockposition) { return baseblockposition.getX() >= this.a && baseblockposition.getX() <= this.d && baseblockposition.getZ() >= this.c && baseblockposition.getZ() <= this.f && baseblockposition.getY() >= this.b && baseblockposition.getY() <= this.e; } +diff --git a/src/main/java/net/minecraft/server/TickListChunk.java b/src/main/java/net/minecraft/server/TickListChunk.java +index eb526530fba30c313482355b74a01258b9b79410..485a029790ea91e61c2bb1a43d75317ecf40b317 100644 +--- a/src/main/java/net/minecraft/server/TickListChunk.java ++++ b/src/main/java/net/minecraft/server/TickListChunk.java +@@ -51,6 +51,8 @@ public class TickListChunk<T> implements TickList<T> { + return TickListServer.a(this.b, this.a, i); + } + ++ private static final int MAX_TICK_DELAY = Integer.getInteger("paper.ticklist-max-tick-delay", -1).intValue(); // Paper - clean up broken entries ++ + public static <T> TickListChunk<T> a(NBTTagList nbttaglist, Function<T, MinecraftKey> function, Function<MinecraftKey, T> function1) { + Set<NextTickListEntry<T>> set = Sets.newHashSet(); + +@@ -59,7 +61,15 @@ public class TickListChunk<T> implements TickList<T> { + T t0 = function1.apply(new MinecraftKey(nbttagcompound.getString("i"))); + + if (t0 != null) { +- set.add(new NextTickListEntry<>(new BlockPosition(nbttagcompound.getInt("x"), nbttagcompound.getInt("y"), nbttagcompound.getInt("z")), t0, (long) nbttagcompound.getInt("t"), TickListPriority.a(nbttagcompound.getInt("p")))); ++ // Paper start - clean up broken entries ++ NextTickListEntry<T> pending = new NextTickListEntry<>(new BlockPosition(nbttagcompound.getInt("x"), nbttagcompound.getInt("y"), nbttagcompound.getInt("z")), t0, (long) nbttagcompound.getInt("t"), TickListPriority.a(nbttagcompound.getInt("p"))); ++ long delay = pending.getTargetTick(); ++ if (MAX_TICK_DELAY > 0 && delay > MAX_TICK_DELAY) { ++ MinecraftServer.LOGGER.warn("Dropping tick for pos " + pending.getPosition() + ", tick delay " + delay); ++ continue; ++ } ++ set.add(pending); ++ // Paper end - clean up broken entries + } + } + diff --git a/src/main/java/net/minecraft/server/TickListServer.java b/src/main/java/net/minecraft/server/TickListServer.java index f533860bbed19ff2915c90186c259b466f41ce90..3f1aa5ced697490b5481ba992cf5af5dc98b8166 100644 --- a/src/main/java/net/minecraft/server/TickListServer.java diff --git a/Spigot-Server-Patches/0551-Fix-some-rails-connecting-improperly.patch b/Spigot-Server-Patches/0551-Fix-some-rails-connecting-improperly.patch new file mode 100644 index 0000000000..39bc7fef4d --- /dev/null +++ b/Spigot-Server-Patches/0551-Fix-some-rails-connecting-improperly.patch @@ -0,0 +1,95 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Spottedleaf <[email protected]> +Date: Fri, 24 Jul 2020 15:56:05 -0700 +Subject: [PATCH] Fix some rails connecting improperly + + +diff --git a/src/main/java/net/minecraft/server/BlockMinecartDetector.java b/src/main/java/net/minecraft/server/BlockMinecartDetector.java +index cbc19202465c128f22933df25661811cc9f99a8f..84e2d402cc749063cd83afb5ed2513d2168944bb 100644 +--- a/src/main/java/net/minecraft/server/BlockMinecartDetector.java ++++ b/src/main/java/net/minecraft/server/BlockMinecartDetector.java +@@ -55,6 +55,7 @@ public class BlockMinecartDetector extends BlockMinecartTrackAbstract { + } + + private void a(World world, BlockPosition blockposition, IBlockData iblockdata) { ++ if (iblockdata.getBlock() != this) { return; } // Paper - not our block, don't do anything + boolean flag = (Boolean) iblockdata.get(BlockMinecartDetector.POWERED); + boolean flag1 = false; + List<EntityMinecartAbstract> list = this.a(world, blockposition, EntityMinecartAbstract.class, (Predicate) null); +diff --git a/src/main/java/net/minecraft/server/BlockMinecartTrackAbstract.java b/src/main/java/net/minecraft/server/BlockMinecartTrackAbstract.java +index 18d60b85aa05bf5575ff65b202786f56deff5b51..4ad2e4932dcf60a90027e08ef037e9cca579dfc4 100644 +--- a/src/main/java/net/minecraft/server/BlockMinecartTrackAbstract.java ++++ b/src/main/java/net/minecraft/server/BlockMinecartTrackAbstract.java +@@ -41,6 +41,7 @@ public abstract class BlockMinecartTrackAbstract extends Block { + iblockdata = this.a(world, blockposition, iblockdata, true); + if (this.c) { + iblockdata.doPhysics(world, blockposition, this, blockposition, flag); ++ iblockdata = world.getType(blockposition); // Paper - don't desync, update again + } + + } +diff --git a/src/main/java/net/minecraft/server/MinecartTrackLogic.java b/src/main/java/net/minecraft/server/MinecartTrackLogic.java +index 8f9eef8237932d78487e2a6c3c7302e1e233f3fd..f78321d4ff2f633d7291bc44c478068f384612ca 100644 +--- a/src/main/java/net/minecraft/server/MinecartTrackLogic.java ++++ b/src/main/java/net/minecraft/server/MinecartTrackLogic.java +@@ -7,13 +7,19 @@ import javax.annotation.Nullable; + + public class MinecartTrackLogic { + +- private final World a; +- private final BlockPosition b; ++ private final World a; public final World getWorld() { return this.a; } // Paper - OBFHELPER ++ private final BlockPosition b; public final BlockPosition getPos() { return this.b; } // Paper - OBFHELPER + private final BlockMinecartTrackAbstract c; +- private IBlockData d; ++ private IBlockData d; public final IBlockData getRailState() { return this.d; } // Paper - OBFHELPER + private final boolean e; + private final List<BlockPosition> f = Lists.newArrayList(); + ++ // Paper start - prevent desync ++ public boolean isValid() { ++ return this.getWorld().getType(this.getPos()).getBlock() == this.getRailState().getBlock(); ++ } ++ // Paper end - prevent desync ++ + public MinecartTrackLogic(World world, BlockPosition blockposition, IBlockData iblockdata) { + this.a = world; + this.b = blockposition; +@@ -148,6 +154,11 @@ public class MinecartTrackLogic { + } + + private void c(MinecartTrackLogic minecarttracklogic) { ++ // Paper start - prevent desync ++ if (!this.isValid() || !minecarttracklogic.isValid()) { ++ return; ++ } ++ // Paper end - prevent desync + this.f.add(minecarttracklogic.b); + BlockPosition blockposition = this.b.north(); + BlockPosition blockposition1 = this.b.south(); +@@ -342,11 +353,16 @@ public class MinecartTrackLogic { + this.d = (IBlockData) this.d.set(this.c.d(), blockpropertytrackposition1); + if (flag1 || this.a.getType(this.b) != this.d) { + this.a.setTypeAndData(this.b, this.d, 3); ++ // Paper start - prevent desync ++ if (!this.isValid()) { ++ return this; ++ } ++ // Paper end - prevent desync + + for (int i = 0; i < this.f.size(); ++i) { + MinecartTrackLogic minecarttracklogic = this.b((BlockPosition) this.f.get(i)); + +- if (minecarttracklogic != null) { ++ if (minecarttracklogic != null && minecarttracklogic.isValid()) { // Paper - prevent desync + minecarttracklogic.d(); + if (minecarttracklogic.b(this)) { + minecarttracklogic.c(this); +@@ -359,6 +375,6 @@ public class MinecartTrackLogic { + } + + public IBlockData c() { +- return this.d; ++ return this.getWorld().getType(this.getPos()); // Paper - prevent desync + } + } diff --git a/Spigot-Server-Patches/0551-Optimize-the-advancement-data-player-iteration-to-be.patch b/Spigot-Server-Patches/0552-Optimize-the-advancement-data-player-iteration-to-be.patch index 2f91d733b6..2f91d733b6 100644 --- a/Spigot-Server-Patches/0551-Optimize-the-advancement-data-player-iteration-to-be.patch +++ b/Spigot-Server-Patches/0552-Optimize-the-advancement-data-player-iteration-to-be.patch diff --git a/Spigot-Server-Patches/0552-Move-range-check-for-block-placing-up.patch b/Spigot-Server-Patches/0553-Move-range-check-for-block-placing-up.patch index eba1279c74..eba1279c74 100644 --- a/Spigot-Server-Patches/0552-Move-range-check-for-block-placing-up.patch +++ b/Spigot-Server-Patches/0553-Move-range-check-for-block-placing-up.patch diff --git a/Spigot-Server-Patches/0553-Fix-AdvancementDataPlayer-leak-due-from-quitting-ear.patch b/Spigot-Server-Patches/0554-Fix-AdvancementDataPlayer-leak-due-from-quitting-ear.patch index c8015fb604..c8015fb604 100644 --- a/Spigot-Server-Patches/0553-Fix-AdvancementDataPlayer-leak-due-from-quitting-ear.patch +++ b/Spigot-Server-Patches/0554-Fix-AdvancementDataPlayer-leak-due-from-quitting-ear.patch |