Folia/patches/server/0012-Lag-compensate-block-b...

56 lines
2.9 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Mon, 10 Apr 2023 14:14:31 -0700
Subject: [PATCH] Lag compensate block breaking
Due to TPS catchup being removed, a lost tick will always
affect block breaking.
Additionally, constant low TPS would affect block breaking
in an intrusive manner to the user when there is no need
for that to occur.
diff --git a/src/main/java/io/papermc/paper/threadedregions/RegionizedWorldData.java b/src/main/java/io/papermc/paper/threadedregions/RegionizedWorldData.java
index 89e6dc92bfbb28d20f252eca5257db1d3d042327..5f609782fceda0fdc856123ca8d40d3f8b13b10b 100644
--- a/src/main/java/io/papermc/paper/threadedregions/RegionizedWorldData.java
+++ b/src/main/java/io/papermc/paper/threadedregions/RegionizedWorldData.java
@@ -432,11 +432,25 @@ public final class RegionizedWorldData {
return this.tickData;
}
+ // Folia start - lag compensation
+ public static final long SERVER_INIT = System.nanoTime();
+
+ private long lagCompensationTick;
+
+ public long getLagCompensationTick() {
+ return this.lagCompensationTick;
+ }
+ // Folia end - lag compensation
+
public void updateTickData() {
this.tickData = this.world.tickData;
this.hasPhysicsEvent = org.bukkit.event.block.BlockPhysicsEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper
this.hasEntityMoveEvent = io.papermc.paper.event.entity.EntityMoveEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper
this.skipHopperEvents = this.world.paperConfig().hopper.disableMoveEvent || org.bukkit.event.inventory.InventoryMoveItemEvent.getHandlerList().getRegisteredListeners().length == 0; // Paper
+ // Folia start - lag compensation
+ // always subtract from server init so that the tick starts at zero, allowing us to cast to int without much worry
+ this.lagCompensationTick = (System.nanoTime() - SERVER_INIT) / TickRegionScheduler.TIME_BETWEEN_TICKS;
+ // Folia end - lag compensation
}
// connections
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
index d9e622964b415b07caaa714d7d23649dcc62c677..56d115f4fdc6c7e3a748557eb8c052994c4521de 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
@@ -124,7 +124,7 @@ public class ServerPlayerGameMode {
}
public void tick() {
- ++this.gameTicks; // CraftBukkit; // Folia - region threading
+ this.gameTicks = (int)this.level.getCurrentWorldData().getLagCompensationTick(); // CraftBukkit; // Folia - region threading // Folia - lag compensation
BlockState iblockdata;
if (this.hasDelayedDestroy) {