2023-09-24 07:10:40 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
|
|
|
|
Date: Sat, 23 Sep 2023 22:05:35 -0700
|
|
|
|
Subject: [PATCH] Lag compensation ticks
|
|
|
|
|
|
|
|
Areas affected by lag comepnsation:
|
|
|
|
- Block breaking and destroying
|
|
|
|
- Eating food items
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
2024-09-19 16:36:07 +02:00
|
|
|
index d25d500a2206d4f7e821de3766e8a523df4370e3..b64c3e29e2b8e890073fee0b45c8b8dfc2b642fd 100644
|
2023-09-24 07:10:40 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
2024-09-19 16:36:07 +02:00
|
|
|
@@ -321,6 +321,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
2024-01-23 12:06:27 +01:00
|
|
|
|
2023-09-24 07:10:40 +02:00
|
|
|
public volatile Thread shutdownThread; // Paper
|
|
|
|
public volatile boolean abnormalExit = false; // Paper
|
2024-01-23 12:06:27 +01:00
|
|
|
+ public static final long SERVER_INIT = System.nanoTime(); // Paper - Lag compensation
|
2023-09-24 07:10:40 +02:00
|
|
|
|
|
|
|
public static <S extends MinecraftServer> S spin(Function<Thread, S> serverFactory) {
|
|
|
|
AtomicReference<S> atomicreference = new AtomicReference();
|
2024-09-19 16:36:07 +02:00
|
|
|
@@ -1763,6 +1764,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
2024-02-01 10:15:57 +01:00
|
|
|
worldserver.hasPhysicsEvent = org.bukkit.event.block.BlockPhysicsEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper - BlockPhysicsEvent
|
2024-01-19 22:13:42 +01:00
|
|
|
worldserver.hasEntityMoveEvent = io.papermc.paper.event.entity.EntityMoveEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper - Add EntityMoveEvent
|
2024-02-01 10:15:57 +01:00
|
|
|
net.minecraft.world.level.block.entity.HopperBlockEntity.skipHopperEvents = worldserver.paperConfig().hopper.disableMoveEvent || org.bukkit.event.inventory.InventoryMoveItemEvent.getHandlerList().getRegisteredListeners().length == 0; // Paper - Perf: Optimize Hoppers
|
|
|
|
+ worldserver.updateLagCompensationTick(); // Paper - lag compensation
|
|
|
|
|
|
|
|
this.profiler.push(() -> {
|
2024-04-25 14:23:55 +02:00
|
|
|
String s = String.valueOf(worldserver);
|
2023-09-24 07:10:40 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
2024-08-31 20:29:50 +02:00
|
|
|
index d223ecfbb0b8986507ce8b6728edbf7c8d818b7d..9e1af229f52a8ac09833901ad53bd154fed34a4f 100644
|
2023-09-24 07:10:40 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
2024-07-31 04:50:14 +02:00
|
|
|
@@ -485,6 +485,17 @@ public class ServerLevel extends Level implements WorldGenLevel, ca.spottedleaf.
|
2024-07-17 19:24:53 +02:00
|
|
|
return this.entityTickingChunks;
|
2023-09-24 07:10:40 +02:00
|
|
|
}
|
2024-07-11 21:22:59 +02:00
|
|
|
// Paper end - rewrite chunk system
|
2023-09-24 07:10:40 +02:00
|
|
|
+ // Paper start - lag compensation
|
|
|
|
+ private long lagCompensationTick = net.minecraft.server.MinecraftServer.SERVER_INIT;
|
|
|
|
+
|
|
|
|
+ public long getLagCompensationTick() {
|
|
|
|
+ return this.lagCompensationTick;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void updateLagCompensationTick() {
|
|
|
|
+ this.lagCompensationTick = (System.nanoTime() - net.minecraft.server.MinecraftServer.SERVER_INIT) / (java.util.concurrent.TimeUnit.MILLISECONDS.toNanos(50L));
|
|
|
|
+ }
|
|
|
|
+ // Paper end - lag compensation
|
|
|
|
|
|
|
|
// Add env and gen to constructor, IWorldDataServer -> WorldDataServer
|
|
|
|
public ServerLevel(MinecraftServer minecraftserver, Executor executor, LevelStorageSource.LevelStorageAccess convertable_conversionsession, PrimaryLevelData iworlddataserver, ResourceKey<Level> resourcekey, LevelStem worlddimension, ChunkProgressListener worldloadlistener, boolean flag, long i, List<CustomSpawner> list, boolean flag1, @Nullable RandomSequences randomsequences, org.bukkit.World.Environment env, org.bukkit.generator.ChunkGenerator gen, org.bukkit.generator.BiomeProvider biomeProvider) {
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
|
2024-07-11 21:22:59 +02:00
|
|
|
index 24b1715397ba8e6f5e9841a030d0e3d964356f89..cc01ead133cc6859ca5d7a1d0ac3c12955e590da 100644
|
2023-09-24 07:10:40 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
|
2024-07-11 21:22:59 +02:00
|
|
|
@@ -129,7 +129,7 @@ public class ServerPlayerGameMode {
|
2023-09-24 07:10:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void tick() {
|
|
|
|
- this.gameTicks = MinecraftServer.currentTick; // CraftBukkit;
|
|
|
|
+ this.gameTicks = (int)this.level.getLagCompensationTick(); // CraftBukkit; // Paper - lag compensation
|
|
|
|
BlockState iblockdata;
|
|
|
|
|
|
|
|
if (this.hasDelayedDestroy) {
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
2024-09-15 21:39:53 +02:00
|
|
|
index 5079775ce8f86fb061e616190513f56ff086e409..13c93281f6b81e88f2f54befb8e6a3e4bdabf53d 100644
|
2023-09-24 07:10:40 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
2024-07-11 21:22:59 +02:00
|
|
|
@@ -3900,6 +3900,10 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
2024-04-25 21:40:53 +02:00
|
|
|
this.resendPossiblyDesyncedDataValues(java.util.List.of(DATA_LIVING_ENTITY_FLAGS), serverPlayer);
|
2023-09-24 07:10:40 +02:00
|
|
|
}
|
2024-01-15 12:38:39 +01:00
|
|
|
// Paper end - Properly cancel usable items
|
2023-09-24 07:10:40 +02:00
|
|
|
+ // Paper start - lag compensate eating
|
|
|
|
+ protected long eatStartTime;
|
|
|
|
+ protected int totalEatTimeTicks;
|
|
|
|
+ // Paper end - lag compensate eating
|
|
|
|
private void updatingUsingItem() {
|
|
|
|
if (this.isUsingItem()) {
|
|
|
|
if (ItemStack.isSameItem(this.getItemInHand(this.getUsedItemHand()), this.useItem)) {
|
2024-07-11 21:22:59 +02:00
|
|
|
@@ -3918,7 +3922,12 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
2023-09-24 07:10:40 +02:00
|
|
|
this.triggerItemUseEffects(stack, 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
- if (--this.useItemRemaining == 0 && !this.level().isClientSide && !stack.useOnRelease()) {
|
|
|
|
+ // Paper start - lag compensate eating
|
|
|
|
+ // we add 1 to the expected time to avoid lag compensating when we should not
|
2024-05-26 22:35:58 +02:00
|
|
|
+ boolean shouldLagCompensate = this.useItem.has(DataComponents.FOOD) && this.eatStartTime != -1 && (System.nanoTime() - this.eatStartTime) > ((1L + this.totalEatTimeTicks) * 50L * (1000L * 1000L));
|
2023-09-24 07:10:40 +02:00
|
|
|
+ if ((--this.useItemRemaining == 0 || shouldLagCompensate) && !this.level().isClientSide && !stack.useOnRelease()) {
|
|
|
|
+ this.useItemRemaining = 0;
|
2024-01-13 18:34:33 +01:00
|
|
|
+ // Paper end - lag compensate eating
|
2023-09-24 07:10:40 +02:00
|
|
|
this.completeUsingItem();
|
|
|
|
}
|
|
|
|
|
2024-07-11 21:22:59 +02:00
|
|
|
@@ -3964,7 +3973,10 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
2023-09-24 07:10:40 +02:00
|
|
|
|
2024-01-21 12:53:04 +01:00
|
|
|
if (!itemstack.isEmpty() && !this.isUsingItem() || forceUpdate) { // Paper - Prevent consuming the wrong itemstack
|
2023-09-24 07:10:40 +02:00
|
|
|
this.useItem = itemstack;
|
2024-07-11 21:22:59 +02:00
|
|
|
- this.useItemRemaining = itemstack.getUseDuration(this);
|
2023-09-24 07:10:40 +02:00
|
|
|
+ // Paper start - lag compensate eating
|
2024-07-11 21:22:59 +02:00
|
|
|
+ this.useItemRemaining = this.totalEatTimeTicks = itemstack.getUseDuration(this);
|
2023-09-24 07:10:40 +02:00
|
|
|
+ this.eatStartTime = System.nanoTime();
|
2024-01-13 18:34:33 +01:00
|
|
|
+ // Paper end - lag compensate eating
|
2023-09-24 07:10:40 +02:00
|
|
|
if (!this.level().isClientSide) {
|
|
|
|
this.setLivingEntityFlag(1, true);
|
|
|
|
this.setLivingEntityFlag(2, hand == InteractionHand.OFF_HAND);
|
2024-07-11 21:22:59 +02:00
|
|
|
@@ -3989,7 +4001,10 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
2023-09-24 07:10:40 +02:00
|
|
|
}
|
|
|
|
} else if (!this.isUsingItem() && !this.useItem.isEmpty()) {
|
|
|
|
this.useItem = ItemStack.EMPTY;
|
|
|
|
- this.useItemRemaining = 0;
|
|
|
|
+ // Paper start - lag compensate eating
|
|
|
|
+ this.useItemRemaining = this.totalEatTimeTicks = 0;
|
|
|
|
+ this.eatStartTime = -1L;
|
2024-01-13 18:34:33 +01:00
|
|
|
+ // Paper end - lag compensate eating
|
2023-09-24 07:10:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-15 21:39:53 +02:00
|
|
|
@@ -4132,7 +4147,10 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
2023-09-24 07:10:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
this.useItem = ItemStack.EMPTY;
|
|
|
|
- this.useItemRemaining = 0;
|
|
|
|
+ // Paper start - lag compensate eating
|
|
|
|
+ this.useItemRemaining = this.totalEatTimeTicks = 0;
|
|
|
|
+ this.eatStartTime = -1L;
|
2024-01-13 18:34:33 +01:00
|
|
|
+ // Paper end - lag compensate eating
|
2023-09-24 07:10:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isBlocking() {
|