Paper/patches/server/0339-Lag-compensate-eating.patch

75 lines
3.6 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Tue, 14 Jan 2020 15:28:28 -0800
Subject: [PATCH] Lag compensate eating
When the server is lagging, players will wait longer when eating.
Change to also use a time check instead if it passes.
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
2023-06-09 01:12:34 +02:00
index a897ed99e7a643244fbe6f0ba1afc1bc15bb8d8d..a1c8558db314ea34ad483f7f6f70c1833b57b669 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
2023-06-09 01:12:34 +02:00
@@ -3601,6 +3601,11 @@ public abstract class LivingEntity extends Entity implements Attackable {
2021-06-11 14:02:28 +02:00
return ((Byte) this.entityData.get(LivingEntity.DATA_LIVING_ENTITY_FLAGS) & 2) > 0 ? InteractionHand.OFF_HAND : InteractionHand.MAIN_HAND;
}
+ // Paper start - lag compensate eating
+ protected long eatStartTime;
+ protected int totalEatTimeTicks;
+ // Paper end
+
private void updatingUsingItem() {
if (this.isUsingItem()) {
2023-06-09 01:12:34 +02:00
if (ItemStack.isSameItem(this.getItemInHand(this.getUsedItemHand()), this.useItem)) {
@@ -3619,7 +3624,12 @@ public abstract class LivingEntity extends Entity implements Attackable {
2021-06-13 21:29:58 +02:00
this.triggerItemUseEffects(stack, 5);
}
2023-06-09 01:12:34 +02:00
- if (--this.useItemRemaining == 0 && !this.level().isClientSide && !stack.useOnRelease()) {
2021-06-13 21:29:58 +02:00
+ // 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));
2023-06-09 01:12:34 +02:00
+ if ((--this.useItemRemaining == 0 || shouldLagCompensate) && !this.level().isClientSide && !stack.useOnRelease()) {
2021-06-13 21:29:58 +02:00
+ this.useItemRemaining = 0;
+ // Paper end
this.completeUsingItem();
}
2021-06-11 14:02:28 +02:00
2023-06-09 01:12:34 +02:00
@@ -3667,7 +3677,10 @@ public abstract class LivingEntity extends Entity implements Attackable {
2021-06-11 14:02:28 +02:00
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
2023-06-09 01:12:34 +02:00
if (!this.level().isClientSide) {
2021-06-11 14:02:28 +02:00
this.setLivingEntityFlag(1, true);
2021-11-24 08:37:09 +01:00
this.setLivingEntityFlag(2, hand == InteractionHand.OFF_HAND);
2023-06-09 01:12:34 +02:00
@@ -3692,7 +3705,10 @@ public abstract class LivingEntity extends Entity implements Attackable {
2021-06-11 14:02:28 +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;
+ // Paper end
}
}
2023-06-09 01:12:34 +02:00
@@ -3825,7 +3841,10 @@ public abstract class LivingEntity extends Entity implements Attackable {
2021-06-11 14:02:28 +02:00
}
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() {