mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-01 08:20:51 +01:00
de04cbced5
Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: f29cb801 Separate checkstyle-suppressions file is not required 86f99bbe SPIGOT-7540, PR-946: Add ServerTickManager API d4119585 SPIGOT-6903, PR-945: Add BlockData#getMapColor b7a2ed41 SPIGOT-7530, PR-947: Add Player#removeResourcePack 9dd56255 SPIGOT-7527, PR-944: Add WindCharge#explode() 994a6163 Attempt upgrade of resolver libraries CraftBukkit Changes: b3b43a6ad Add Checkstyle check for unused imports 13fb3358e SPIGOT-7544: Scoreboard#getEntries() doesn't get entries but class names 3dda99c06 SPIGOT-7540, PR-1312: Add ServerTickManager API 2ab4508c0 SPIGOT-6903, PR-1311: Add BlockData#getMapColor 1dbdbbed4 PR-1238: Remove unnecessary sign ticking 659728d2a MC-264285, SPIGOT-7439, PR-1237: Fix unbreakable flint and steel is completely consumed while igniting creeper e37e29ce0 Increase outdated build delay c00438b39 SPIGOT-7530, PR-1313: Add Player#removeResourcePack 492dd80ce SPIGOT-7527, PR-1310: Add WindCharge#explode() e11fbb9d7 Upgrade MySQL driver 9f3a0bd2a Attempt upgrade of resolver libraries 60d16d7ca PR-1306: Centralize Bukkit and Minecraft entity conversion Spigot Changes: 06d602e7 Rebuild patches
132 lines
7.7 KiB
Diff
132 lines
7.7 KiB
Diff
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
|
|
index a8f9f4e23575cb58045f9d8efe011a60a51dbd7a..34f19ac897a30c0c4e3ab406013fcca1c8b7db93 100644
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
@@ -311,6 +311,9 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
public volatile Thread shutdownThread; // Paper
|
|
public volatile boolean abnormalExit = false; // Paper
|
|
public boolean isIteratingOverLevels = false; // Paper
|
|
+ // Paper start - lag compensation
|
|
+ public static final long SERVER_INIT = System.nanoTime();
|
|
+ // Paper end - lag compensation
|
|
|
|
public static <S extends MinecraftServer> S spin(Function<Thread, S> serverFactory) {
|
|
AtomicReference<S> atomicreference = new AtomicReference();
|
|
@@ -1691,6 +1694,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
Iterator iterator = this.getAllLevels().iterator(); // Paper - 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
|
|
net.minecraft.world.level.block.entity.HopperBlockEntity.skipHopperEvents = worldserver.paperConfig().hopper.disableMoveEvent || org.bukkit.event.inventory.InventoryMoveItemEvent.getHandlerList().getRegisteredListeners().length == 0; // Paper
|
|
worldserver.hasEntityMoveEvent = io.papermc.paper.event.entity.EntityMoveEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
index 2ca2b6c45fa05fde11c36d31a4c1cdeae9c08786..dac0771836a1c26aa10a2609bb77d7fc68bb9423 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
@@ -566,6 +566,17 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
|
return player != null && player.level() == this ? player : null;
|
|
}
|
|
// Paper end
|
|
+ // 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 899439e0af639e8d9124522b3cb6a10601b17fe2..b214c934b9a537f52cef142c519c2b9b55a89ae3 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 bed0a01be1703aad8fbfa549d5799e3f84759f32..e1eab03233149fd0714785955d21dc80dc664d96 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
@@ -3818,6 +3818,10 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
|
this.getEntityData().resendPossiblyDesyncedDataValues(java.util.List.of(DATA_LIVING_ENTITY_FLAGS), serverPlayer);
|
|
}
|
|
// Paper end
|
|
+ // 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)) {
|
|
@@ -3836,7 +3840,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
|
|
this.completeUsingItem();
|
|
}
|
|
|
|
@@ -3884,7 +3893,10 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
|
|
|
if (!itemstack.isEmpty() && !this.isUsingItem() || forceUpdate) { // Paper use override flag
|
|
this.useItem = itemstack;
|
|
- this.useItemRemaining = itemstack.getUseDuration();
|
|
+ // Paper start - lag compensate eating
|
|
+ this.useItemRemaining = this.totalEatTimeTicks = itemstack.getUseDuration();
|
|
+ this.eatStartTime = System.nanoTime();
|
|
+ // Paper end
|
|
if (!this.level().isClientSide) {
|
|
this.setLivingEntityFlag(1, true);
|
|
this.setLivingEntityFlag(2, hand == InteractionHand.OFF_HAND);
|
|
@@ -3909,7 +3921,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
|
|
}
|
|
}
|
|
|
|
@@ -4044,7 +4059,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
|
|
}
|
|
|
|
public boolean isBlocking() {
|