mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-22 18:45:54 +01:00
Tighten logic for handling target tick times in tick scheduler (#4010)
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. Aimed at resolving #3251 Also fix an issue with some rails connecting incorrectly that I found when testing. Co-authored-by: Spottedleaf <Spottedleaf@users.noreply.github.com>
This commit is contained in:
parent
d5ccd41393
commit
a8ef09b82c
@ -61,10 +61,10 @@ index bf86444c479f346e7d56f10a7c0ebefd62f08f59..8508b3e10e60a4ce36d471b1d3f7ffc8
|
||||
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..0692fe33bb7c4a7bb666920b10f5dd3a0e7a7689
|
||||
index 0000000000000000000000000000000000000000..bbb042fec32ce5a4aecf1934ab6bed77c5134a7f
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/com/destroystokyo/paper/server/ticklist/PaperTickList.java
|
||||
@@ -0,0 +1,617 @@
|
||||
@@ -0,0 +1,624 @@
|
||||
+package com.destroystokyo.paper.server.ticklist;
|
||||
+
|
||||
+import net.minecraft.server.MCUtil;
|
||||
@ -72,7 +72,6 @@ index 0000000000000000000000000000000000000000..0692fe33bb7c4a7bb666920b10f5dd3a
|
||||
+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;
|
||||
@ -96,7 +95,6 @@ index 0000000000000000000000000000000000000000..0692fe33bb7c4a7bb666920b10f5dd3a
|
||||
+import java.util.function.Consumer;
|
||||
+import java.util.function.Function;
|
||||
+import java.util.function.Predicate;
|
||||
+import java.util.stream.Stream;
|
||||
+
|
||||
+public final class PaperTickList<T> extends TickListServer<T> { // extend to avoid breaking ABI
|
||||
+
|
||||
@ -268,7 +266,7 @@ index 0000000000000000000000000000000000000000..0692fe33bb7c4a7bb666920b10f5dd3a
|
||||
+ }
|
||||
+
|
||||
+ private void prepare() {
|
||||
+ final long currentTick = this.world.getTime();
|
||||
+ final long currentTick = this.nextTick;
|
||||
+
|
||||
+ final ChunkProviderServer chunkProvider = this.world.getChunkProvider();
|
||||
+
|
||||
@ -333,8 +331,18 @@ index 0000000000000000000000000000000000000000..0692fe33bb7c4a7bb666920b10f5dd3a
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ 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");
|
||||
@ -345,7 +353,6 @@ index 0000000000000000000000000000000000000000..0692fe33bb7c4a7bb666920b10f5dd3a
|
||||
+ // 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");
|
||||
@ -472,7 +479,7 @@ index 0000000000000000000000000000000000000000..0692fe33bb7c4a7bb666920b10f5dd3a
|
||||
+
|
||||
+ @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) {
|
||||
@ -644,7 +651,7 @@ index 0000000000000000000000000000000000000000..0692fe33bb7c4a7bb666920b10f5dd3a
|
||||
+ // 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
|
||||
+ }
|
||||
+
|
||||
@ -1032,6 +1039,35 @@ index 7873db26b336c97f909e5391e58ee53feaf59b9a..447eb2ba84789edf9bac2e2ffb2dec7c
|
||||
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 f94234b0a247e378ff9056d6c418464d619a356b..8af1229c3da63a838b0bec1cafde1e41cf5cf551 100644
|
||||
--- a/src/main/java/net/minecraft/server/TickListChunk.java
|
||||
+++ b/src/main/java/net/minecraft/server/TickListChunk.java
|
||||
@@ -57,6 +57,8 @@ public class TickListChunk<T> implements TickList<T> {
|
||||
return nbttaglist;
|
||||
}
|
||||
|
||||
+ 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) {
|
||||
List<TickListChunk.a<T>> list = Lists.newArrayList();
|
||||
|
||||
@@ -67,7 +69,14 @@ public class TickListChunk<T> implements TickList<T> {
|
||||
if (t0 != null) {
|
||||
BlockPosition blockposition = new BlockPosition(nbttagcompound.getInt("x"), nbttagcompound.getInt("y"), nbttagcompound.getInt("z"));
|
||||
|
||||
- list.add(new TickListChunk.a<>(t0, blockposition, nbttagcompound.getInt("t"), TickListPriority.a(nbttagcompound.getInt("p"))));
|
||||
+ // Paper start - clean up broken entries
|
||||
+ int delay = nbttagcompound.getInt("t");
|
||||
+ if (MAX_TICK_DELAY > 0 && delay > MAX_TICK_DELAY) {
|
||||
+ MinecraftServer.LOGGER.warn("Dropping tick for pos " + blockposition + ", tick delay " + delay);
|
||||
+ continue;
|
||||
+ }
|
||||
+ list.add(new TickListChunk.a<>(t0, blockposition, delay, TickListPriority.a(nbttagcompound.getInt("p"))));
|
||||
+ // 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 3b8f56c0f0507ebdd9ac20be70688b4c0cfe4cf8..149d2b4f929c11b8baf17163bbd6ff8220a95e86 100644
|
||||
--- a/src/main/java/net/minecraft/server/TickListServer.java
|
||||
|
@ -0,0 +1,95 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Spottedleaf <spottedleaf@spottedleaf.dev>
|
||||
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 06926c4ae1100c5848206b2c45d51e87f273416d..b8e91fca957c8a39c9fbf4f87c089c4ce710c8e0 100644
|
||||
--- a/src/main/java/net/minecraft/server/BlockMinecartDetector.java
|
||||
+++ b/src/main/java/net/minecraft/server/BlockMinecartDetector.java
|
||||
@@ -50,6 +50,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 d91b1b41aa2e3d3a12ebc52d19358032124135fb..a540b3e226b985f22daf1a69bf4e8cb578ab1476 100644
|
||||
--- a/src/main/java/net/minecraft/server/BlockMinecartTrackAbstract.java
|
||||
+++ b/src/main/java/net/minecraft/server/BlockMinecartTrackAbstract.java
|
||||
@@ -46,6 +46,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
|
||||
}
|
||||
|
||||
return iblockdata;
|
||||
diff --git a/src/main/java/net/minecraft/server/MinecartTrackLogic.java b/src/main/java/net/minecraft/server/MinecartTrackLogic.java
|
||||
index 10bc2165159514d484e73a3acd08ca5929be72f2..e0be3a425aae51e1aced8eb6d8a5e84fc9315e3a 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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user