Paper/Spigot-Server-Patches/0406-Lag-compensate-eating.patch
Prof-Bloodstone 42433c2626
Updated Upstream (Bukkit/CraftBukkit) (#3980)
Upstream has released updates that appears 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:
09f10fd9 SPIGOT-5950: Add PrepareSmithingEvent event

CraftBukkit Changes:
7c03d257 SPIGOT-6011: End Gateways do not work on Non-Main End Worlds
d492e363 SPIGOT-6015: Small Armor Stand doesn't drop items
5db13eea SPIGOT-5950: Add PrepareSmithingEvent event
2020-07-22 19:35:44 -04:00

85 lines
3.8 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/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java
index f71ca4ee57d86c30d78c8292ced0531b963beabb..fd8b3d05238329adf3f638b1e04fd95c08e0a74a 100644
--- a/src/main/java/net/minecraft/server/EntityLiving.java
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
@@ -119,7 +119,7 @@ public abstract class EntityLiving extends Entity {
private int jumpTicks;
private float bD;
public ItemStack activeItem; // Paper - public
- protected int bk;
+ protected int bk; protected final int getEatTimeTicks() { return this.bk; } protected final void setEatTimeTicks(int value) { this.bk = value; } // Paper - OBFHELPER
protected int bl;
private BlockPosition bE;
private Optional<BlockPosition> bF;
@@ -3015,6 +3015,11 @@ public abstract class EntityLiving extends Entity {
return ((Byte) this.datawatcher.get(EntityLiving.an) & 2) > 0 ? EnumHand.OFF_HAND : EnumHand.MAIN_HAND;
}
+ // Paper start - lag compensate eating
+ protected long eatStartTime;
+ protected int totalEatTimeTicks;
+ // Paper end
+
private void u() {
if (this.isHandRaised()) {
if (ItemStack.d(this.b(this.getRaisedHand()), this.activeItem)) {
@@ -3024,7 +3029,13 @@ public abstract class EntityLiving extends Entity {
this.b(this.activeItem, 5);
}
- if (--this.bk == 0 && !this.world.isClientSide && !this.activeItem.m()) {
+ // Paper start - lag compensate eating
+ // we add 1 to the expected time to avoid lag compensating when we should not
+ boolean shouldLagCompensate
+ = this.activeItem.getItem().isFood() && this.eatStartTime != -1 && (System.nanoTime() - this.eatStartTime) > ((1 + this.totalEatTimeTicks) * 50 * (1000 * 1000));
+ if ((--this.bk == 0 || shouldLagCompensate) && !this.world.isClientSide && !this.activeItem.m()) {
+ this.setEatTimeTicks(0);
+ // Paper end
this.s();
}
} else {
@@ -3074,7 +3085,10 @@ public abstract class EntityLiving extends Entity {
if (!itemstack.isEmpty() && !this.isHandRaised() || forceUpdate) { // Paper use override flag
this.activeItem = itemstack;
- this.bk = itemstack.k();
+ // Paper start - lag compensate eating
+ this.bk = this.totalEatTimeTicks = itemstack.k();
+ this.eatStartTime = System.nanoTime();
+ // Paper end
if (!this.world.isClientSide) {
this.c(1, true);
this.c(2, enumhand == EnumHand.OFF_HAND);
@@ -3098,7 +3112,10 @@ public abstract class EntityLiving extends Entity {
}
} else if (!this.isHandRaised() && !this.activeItem.isEmpty()) {
this.activeItem = ItemStack.b;
- this.bk = 0;
+ // Paper start - lag compensate eating
+ this.bk = this.totalEatTimeTicks = 0;
+ this.eatStartTime = -1L;
+ // Paper end
}
}
@@ -3220,7 +3237,10 @@ public abstract class EntityLiving extends Entity {
}
this.activeItem = ItemStack.b;
- this.bk = 0;
+ // Paper start - lag compensate eating
+ this.bk = this.totalEatTimeTicks = 0;
+ this.eatStartTime = -1L;
+ // Paper end
}
public boolean isBlocking() {