Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-11-15 04:20:04 +01:00
4104545b11
"It was from a different time before books were as jank as they are now. As time has gone on they've only proven to be worse and worse."
76 Zeilen
3.6 KiB
Diff
76 Zeilen
3.6 KiB
Diff
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
|
|
index 53951f2c4dc77e9723d0a6314781d9ee0aa8ce54..d03d0c896ef7758dbfbf5b9aa3119e07e6ef389c 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
@@ -3492,6 +3492,11 @@ public abstract class LivingEntity extends Entity {
|
|
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()) {
|
|
if (ItemStack.isSameIgnoreDurability(this.getItemInHand(this.getUsedItemHand()), this.useItem)) {
|
|
@@ -3509,8 +3514,12 @@ public abstract class LivingEntity extends Entity {
|
|
if (this.shouldTriggerItemUseEffects()) {
|
|
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 && !this.useItem.useOnRelease()) {
|
|
+ this.useItemRemaining = 0;
|
|
+ // Paper end
|
|
this.completeUsingItem();
|
|
}
|
|
|
|
@@ -3556,7 +3565,10 @@ public abstract class LivingEntity extends Entity {
|
|
|
|
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, enumhand == InteractionHand.OFF_HAND);
|
|
@@ -3580,7 +3592,10 @@ public abstract class LivingEntity extends Entity {
|
|
}
|
|
} 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
|
|
}
|
|
}
|
|
|
|
@@ -3706,7 +3721,10 @@ public abstract class LivingEntity extends Entity {
|
|
}
|
|
|
|
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() {
|