2020-05-06 11:48:49 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2020-02-07 04:06:52 +01:00
|
|
|
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
|
2020-12-22 22:02:19 +01:00
|
|
|
index 37e3efa1fed858f735166a5c0cb97f886b2bbb4e..e86500d789a713d763c64448cfa7141a15d6b4bd 100644
|
2020-02-07 04:06:52 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/EntityLiving.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
|
2020-09-02 11:12:25 +02:00
|
|
|
@@ -120,7 +120,7 @@ public abstract class EntityLiving extends Entity {
|
2020-02-07 04:06:52 +01:00
|
|
|
private int jumpTicks;
|
2020-08-25 04:22:08 +02:00
|
|
|
private float bw;
|
2020-02-07 04:06:52 +01:00
|
|
|
public ItemStack activeItem; // Paper - public
|
2020-08-25 04:22:08 +02:00
|
|
|
- protected int bd;
|
|
|
|
+ protected int bd; protected final int getEatTimeTicks() { return this.bd; } protected final void setEatTimeTicks(int value) { this.bd = value; } // Paper - OBFHELPER
|
|
|
|
protected int be;
|
|
|
|
private BlockPosition bx;
|
|
|
|
private Optional<BlockPosition> by;
|
2020-12-22 22:02:19 +01:00
|
|
|
@@ -3051,6 +3051,11 @@ public abstract class EntityLiving extends Entity {
|
2020-08-25 04:22:08 +02:00
|
|
|
return ((Byte) this.datawatcher.get(EntityLiving.ag) & 2) > 0 ? EnumHand.OFF_HAND : EnumHand.MAIN_HAND;
|
2020-02-07 04:06:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start - lag compensate eating
|
|
|
|
+ protected long eatStartTime;
|
|
|
|
+ protected int totalEatTimeTicks;
|
|
|
|
+ // Paper end
|
2020-06-26 01:38:24 +02:00
|
|
|
+
|
2020-08-25 04:22:08 +02:00
|
|
|
private void t() {
|
2020-02-07 04:06:52 +01:00
|
|
|
if (this.isHandRaised()) {
|
|
|
|
if (ItemStack.d(this.b(this.getRaisedHand()), this.activeItem)) {
|
2020-12-22 22:02:19 +01:00
|
|
|
@@ -3060,7 +3065,12 @@ public abstract class EntityLiving extends Entity {
|
2020-02-07 04:06:52 +01:00
|
|
|
this.b(this.activeItem, 5);
|
|
|
|
}
|
|
|
|
|
2020-08-25 04:22:08 +02:00
|
|
|
- if (--this.bd == 0 && !this.world.isClientSide && !this.activeItem.m()) {
|
2020-02-07 04:06:52 +01:00
|
|
|
+ // Paper start - lag compensate eating
|
|
|
|
+ // we add 1 to the expected time to avoid lag compensating when we should not
|
2020-08-25 04:22:08 +02:00
|
|
|
+ boolean shouldLagCompensate = this.activeItem.getItem().isFood() && this.eatStartTime != -1 && (System.nanoTime() - this.eatStartTime) > ((1 + this.totalEatTimeTicks) * 50 * (1000 * 1000));
|
|
|
|
+ if ((--this.bd == 0 || shouldLagCompensate) && !this.world.isClientSide && !this.activeItem.m()) {
|
2020-02-07 04:06:52 +01:00
|
|
|
+ this.setEatTimeTicks(0);
|
|
|
|
+ // Paper end
|
2020-06-26 01:38:24 +02:00
|
|
|
this.s();
|
2020-02-07 04:06:52 +01:00
|
|
|
}
|
|
|
|
} else {
|
2020-12-22 22:02:19 +01:00
|
|
|
@@ -3110,7 +3120,10 @@ public abstract class EntityLiving extends Entity {
|
2020-02-07 04:06:52 +01:00
|
|
|
|
|
|
|
if (!itemstack.isEmpty() && !this.isHandRaised() || forceUpdate) { // Paper use override flag
|
|
|
|
this.activeItem = itemstack;
|
2020-08-25 04:22:08 +02:00
|
|
|
- this.bd = itemstack.k();
|
2020-02-07 04:06:52 +01:00
|
|
|
+ // Paper start - lag compensate eating
|
2020-08-25 04:22:08 +02:00
|
|
|
+ this.bd = this.totalEatTimeTicks = itemstack.k();
|
2020-02-07 04:06:52 +01:00
|
|
|
+ this.eatStartTime = System.nanoTime();
|
|
|
|
+ // Paper end
|
|
|
|
if (!this.world.isClientSide) {
|
|
|
|
this.c(1, true);
|
|
|
|
this.c(2, enumhand == EnumHand.OFF_HAND);
|
2020-12-22 22:02:19 +01:00
|
|
|
@@ -3134,7 +3147,10 @@ public abstract class EntityLiving extends Entity {
|
2020-02-07 04:06:52 +01:00
|
|
|
}
|
|
|
|
} else if (!this.isHandRaised() && !this.activeItem.isEmpty()) {
|
2020-06-26 01:38:24 +02:00
|
|
|
this.activeItem = ItemStack.b;
|
2020-08-25 04:22:08 +02:00
|
|
|
- this.bd = 0;
|
2020-02-07 04:06:52 +01:00
|
|
|
+ // Paper start - lag compensate eating
|
2020-08-25 04:22:08 +02:00
|
|
|
+ this.bd = this.totalEatTimeTicks = 0;
|
2020-02-07 04:06:52 +01:00
|
|
|
+ this.eatStartTime = -1L;
|
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-22 22:02:19 +01:00
|
|
|
@@ -3262,7 +3278,10 @@ public abstract class EntityLiving extends Entity {
|
2020-02-07 04:06:52 +01:00
|
|
|
}
|
|
|
|
|
2020-06-26 01:38:24 +02:00
|
|
|
this.activeItem = ItemStack.b;
|
2020-08-25 04:22:08 +02:00
|
|
|
- this.bd = 0;
|
2020-02-07 04:06:52 +01:00
|
|
|
+ // Paper start - lag compensate eating
|
2020-08-25 04:22:08 +02:00
|
|
|
+ this.bd = this.totalEatTimeTicks = 0;
|
2020-02-07 04:06:52 +01:00
|
|
|
+ this.eatStartTime = -1L;
|
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isBlocking() {
|