aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0421-Lag-compensate-eating.patch
blob: 606469d9d61d2cfb048cddaabec86a992707fb6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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 4f9255c0bc2ff46f34072846d2b0dc2e97f05db4..0ec0ddb7d0e3f25820fe064d75916407cb579eae 100644
--- a/src/main/java/net/minecraft/server/EntityLiving.java
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
@@ -113,7 +113,7 @@ public abstract class EntityLiving extends Entity {
     private int jumpTicks;
     private float bD;
     public ItemStack activeItem; // Paper - public
-    protected int bl;
+    protected int bl; protected final int getEatTimeTicks() { return this.bl; } protected final void setEatTimeTicks(int value) { this.bl = value; } // Paper - OBFHELPER
     protected int bm;
     private BlockPosition bE;
     private DamageSource bF;
@@ -2848,6 +2848,10 @@ public abstract class EntityLiving extends Entity {
         return ((Byte) this.datawatcher.get(EntityLiving.ao) & 2) > 0 ? EnumHand.OFF_HAND : EnumHand.MAIN_HAND;
     }
 
+    // Paper start - lag compensate eating
+    protected long eatStartTime;
+    protected int totalEatTimeTicks;
+    // Paper end
     private void o() {
         if (this.isHandRaised()) {
             if (ItemStack.d(this.b(this.getRaisedHand()), this.activeItem)) {
@@ -2856,7 +2860,14 @@ public abstract class EntityLiving extends Entity {
                     this.b(this.activeItem, 5);
                 }
 
-                if (--this.bl == 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.bl == 0 || shouldLagCompensate) && !this.world.isClientSide && !this.activeItem.m()) {
+                    this.setEatTimeTicks(0);
+                    // Paper end
                     this.q();
                 }
             } else {
@@ -2906,7 +2917,10 @@ public abstract class EntityLiving extends Entity {
 
         if (!itemstack.isEmpty() && !this.isHandRaised() || forceUpdate) { // Paper use override flag
             this.activeItem = itemstack;
-            this.bl = itemstack.k();
+            // Paper start - lag compensate eating
+            this.bl = 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);
@@ -2930,7 +2944,10 @@ public abstract class EntityLiving extends Entity {
                 }
             } else if (!this.isHandRaised() && !this.activeItem.isEmpty()) {
                 this.activeItem = ItemStack.a;
-                this.bl = 0;
+                // Paper start - lag compensate eating
+                this.bl = this.totalEatTimeTicks = 0;
+                this.eatStartTime = -1L;
+                // Paper end
             }
         }
 
@@ -3052,7 +3069,10 @@ public abstract class EntityLiving extends Entity {
         }
 
         this.activeItem = ItemStack.a;
-        this.bl = 0;
+        // Paper start - lag compensate eating
+        this.bl = this.totalEatTimeTicks = 0;
+        this.eatStartTime = -1L;
+        // Paper end
     }
 
     public boolean isBlocking() {