diff options
author | Nassim Jahnke <[email protected]> | 2024-01-24 22:13:08 +0100 |
---|---|---|
committer | Nassim Jahnke <[email protected]> | 2024-01-25 00:41:51 +0100 |
commit | 1831240d1c48086fc0199584787cd2013d4d4b5f (patch) | |
tree | d61d8d63ec61e8394df0b9c7db9219e1518741c2 /patches/server/1036-Lag-compensation-ticks.patch | |
parent | b7004609991dab287b582a1546a1b59c5d90c916 (diff) | |
download | Paper-1831240d1c48086fc0199584787cd2013d4d4b5f.tar.gz Paper-1831240d1c48086fc0199584787cd2013d4d4b5f.zip |
[ci skip] Move chunk system patch back
Diffstat (limited to 'patches/server/1036-Lag-compensation-ticks.patch')
-rw-r--r-- | patches/server/1036-Lag-compensation-ticks.patch | 129 |
1 files changed, 0 insertions, 129 deletions
diff --git a/patches/server/1036-Lag-compensation-ticks.patch b/patches/server/1036-Lag-compensation-ticks.patch deleted file mode 100644 index 17c4a518a7..0000000000 --- a/patches/server/1036-Lag-compensation-ticks.patch +++ /dev/null @@ -1,129 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Spottedleaf <[email protected]> -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 -index a966a0fe4fd9d882e81c5e2786e16ff687c892b3..58da8abd1603359bb9f2772a6420b55108e22ceb 100644 ---- a/src/main/java/net/minecraft/server/MinecraftServer.java -+++ b/src/main/java/net/minecraft/server/MinecraftServer.java -@@ -310,6 +310,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa - - public volatile Thread shutdownThread; // Paper - public volatile boolean abnormalExit = false; // Paper -+ public static final long SERVER_INIT = System.nanoTime(); // Paper - Lag compensation - - public static <S extends MinecraftServer> S spin(Function<Thread, S> serverFactory) { - AtomicReference<S> atomicreference = new AtomicReference(); -@@ -1626,6 +1627,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa - Iterator iterator = this.getAllLevels().iterator(); // Paper - Throw exception on world create while being ticked; move down - while (iterator.hasNext()) { - ServerLevel worldserver = (ServerLevel) iterator.next(); -+ worldserver.updateLagCompensationTick(); // Paper - lag compensation - worldserver.hasPhysicsEvent = org.bukkit.event.block.BlockPhysicsEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper - BlockPhysicsEvent - 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.hasEntityMoveEvent = io.papermc.paper.event.entity.EntityMoveEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper - Add EntityMoveEvent -diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java -index ab2e84f85da7931e133ad5f0d2686cd1738f6ea1..5bbfb1af24e13a9e6a02ad8c36bb504a17f06398 100644 ---- a/src/main/java/net/minecraft/server/level/ServerLevel.java -+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java -@@ -565,6 +565,17 @@ public class ServerLevel extends Level implements WorldGenLevel { - return player != null && player.level() == this ? player : null; - } - // Paper end - optimise getPlayerByUUID -+ // 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 -index 83e017efd15d0ecaffc327f02d6d5330c8ed6937..cfd4ac06a9af6bf3fac293110482e1df690e075e 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 = 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 -index a4217f984148b12960c74ad2ef7cee761f305030..6071451339080bbdd98fb634791a56988984c8bc 100644 ---- a/src/main/java/net/minecraft/world/entity/LivingEntity.java -+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java -@@ -3827,6 +3827,10 @@ public abstract class LivingEntity extends Entity implements Attackable { - this.getEntityData().resendPossiblyDesyncedDataValues(java.util.List.of(DATA_LIVING_ENTITY_FLAGS), serverPlayer); - } - // Paper end - Properly cancel usable items -+ // 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)) { -@@ -3845,7 +3849,12 @@ public abstract class LivingEntity extends Entity implements Attackable { - 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 -+ boolean shouldLagCompensate = this.useItem.getItem().isEdible() && this.eatStartTime != -1 && (System.nanoTime() - this.eatStartTime) > ((1 + this.totalEatTimeTicks) * 50 * (1000 * 1000)); -+ if ((--this.useItemRemaining == 0 || shouldLagCompensate) && !this.level().isClientSide && !stack.useOnRelease()) { -+ this.useItemRemaining = 0; -+ // Paper end - lag compensate eating - this.completeUsingItem(); - } - -@@ -3893,7 +3902,10 @@ public abstract class LivingEntity extends Entity implements Attackable { - - if (!itemstack.isEmpty() && !this.isUsingItem() || forceUpdate) { // Paper - Prevent consuming the wrong itemstack - this.useItem = itemstack; -- this.useItemRemaining = itemstack.getUseDuration(); -+ // Paper start - lag compensate eating -+ this.useItemRemaining = this.totalEatTimeTicks = itemstack.getUseDuration(); -+ this.eatStartTime = System.nanoTime(); -+ // Paper end - lag compensate eating - if (!this.level().isClientSide) { - this.setLivingEntityFlag(1, true); - this.setLivingEntityFlag(2, hand == InteractionHand.OFF_HAND); -@@ -3918,7 +3930,10 @@ public abstract class LivingEntity extends Entity implements Attackable { - } - } 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; -+ // Paper end - lag compensate eating - } - } - -@@ -4053,7 +4068,10 @@ public abstract class LivingEntity extends Entity implements Attackable { - } - - this.useItem = ItemStack.EMPTY; -- this.useItemRemaining = 0; -+ // Paper start - lag compensate eating -+ this.useItemRemaining = this.totalEatTimeTicks = 0; -+ this.eatStartTime = -1L; -+ // Paper end - lag compensate eating - } - - public boolean isBlocking() { |