2020-05-06 09:48:49 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2020-02-07 03:06:52 +00: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.
|
|
|
|
|
2021-03-16 07:19:45 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/EntityLiving.java b/src/main/java/net/minecraft/world/entity/EntityLiving.java
|
|
|
|
index 1102659557ea9f0ab4fe6225cbf1dc1006661caf..e1d8217e48e7c5e7870e46f43074c79efc298ccc 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/entity/EntityLiving.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/EntityLiving.java
|
|
|
|
@@ -213,7 +213,7 @@ public abstract class EntityLiving extends Entity {
|
2020-02-07 03:06:52 +00:00
|
|
|
private int jumpTicks;
|
2020-08-25 02:22:08 +00:00
|
|
|
private float bw;
|
2020-02-07 03:06:52 +00:00
|
|
|
public ItemStack activeItem; // Paper - public
|
2020-08-25 02:22:08 +00: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;
|
2021-03-16 07:19:45 +00:00
|
|
|
@@ -3150,6 +3150,11 @@ public abstract class EntityLiving extends Entity {
|
2020-08-25 02:22:08 +00:00
|
|
|
return ((Byte) this.datawatcher.get(EntityLiving.ag) & 2) > 0 ? EnumHand.OFF_HAND : EnumHand.MAIN_HAND;
|
2020-02-07 03:06:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start - lag compensate eating
|
|
|
|
+ protected long eatStartTime;
|
|
|
|
+ protected int totalEatTimeTicks;
|
|
|
|
+ // Paper end
|
2020-06-25 23:38:24 +00:00
|
|
|
+
|
2020-08-25 02:22:08 +00:00
|
|
|
private void t() {
|
2020-02-07 03:06:52 +00:00
|
|
|
if (this.isHandRaised()) {
|
|
|
|
if (ItemStack.d(this.b(this.getRaisedHand()), this.activeItem)) {
|
2021-03-16 07:19:45 +00:00
|
|
|
@@ -3159,7 +3164,12 @@ public abstract class EntityLiving extends Entity {
|
2020-02-07 03:06:52 +00:00
|
|
|
this.b(this.activeItem, 5);
|
|
|
|
}
|
|
|
|
|
2020-08-25 02:22:08 +00:00
|
|
|
- if (--this.bd == 0 && !this.world.isClientSide && !this.activeItem.m()) {
|
2020-02-07 03:06:52 +00:00
|
|
|
+ // Paper start - lag compensate eating
|
|
|
|
+ // we add 1 to the expected time to avoid lag compensating when we should not
|
2020-08-25 02:22:08 +00: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 03:06:52 +00:00
|
|
|
+ this.setEatTimeTicks(0);
|
|
|
|
+ // Paper end
|
2020-06-25 23:38:24 +00:00
|
|
|
this.s();
|
2020-02-07 03:06:52 +00:00
|
|
|
}
|
|
|
|
} else {
|
2021-03-16 07:19:45 +00:00
|
|
|
@@ -3209,7 +3219,10 @@ public abstract class EntityLiving extends Entity {
|
2020-02-07 03:06:52 +00:00
|
|
|
|
|
|
|
if (!itemstack.isEmpty() && !this.isHandRaised() || forceUpdate) { // Paper use override flag
|
|
|
|
this.activeItem = itemstack;
|
2020-08-25 02:22:08 +00:00
|
|
|
- this.bd = itemstack.k();
|
2020-02-07 03:06:52 +00:00
|
|
|
+ // Paper start - lag compensate eating
|
2020-08-25 02:22:08 +00:00
|
|
|
+ this.bd = this.totalEatTimeTicks = itemstack.k();
|
2020-02-07 03:06:52 +00:00
|
|
|
+ this.eatStartTime = System.nanoTime();
|
|
|
|
+ // Paper end
|
|
|
|
if (!this.world.isClientSide) {
|
|
|
|
this.c(1, true);
|
|
|
|
this.c(2, enumhand == EnumHand.OFF_HAND);
|
2021-03-16 07:19:45 +00:00
|
|
|
@@ -3233,7 +3246,10 @@ public abstract class EntityLiving extends Entity {
|
2020-02-07 03:06:52 +00:00
|
|
|
}
|
|
|
|
} else if (!this.isHandRaised() && !this.activeItem.isEmpty()) {
|
2020-06-25 23:38:24 +00:00
|
|
|
this.activeItem = ItemStack.b;
|
2020-08-25 02:22:08 +00:00
|
|
|
- this.bd = 0;
|
2020-02-07 03:06:52 +00:00
|
|
|
+ // Paper start - lag compensate eating
|
2020-08-25 02:22:08 +00:00
|
|
|
+ this.bd = this.totalEatTimeTicks = 0;
|
2020-02-07 03:06:52 +00:00
|
|
|
+ this.eatStartTime = -1L;
|
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-16 07:19:45 +00:00
|
|
|
@@ -3361,7 +3377,10 @@ public abstract class EntityLiving extends Entity {
|
2020-02-07 03:06:52 +00:00
|
|
|
}
|
|
|
|
|
2020-06-25 23:38:24 +00:00
|
|
|
this.activeItem = ItemStack.b;
|
2020-08-25 02:22:08 +00:00
|
|
|
- this.bd = 0;
|
2020-02-07 03:06:52 +00:00
|
|
|
+ // Paper start - lag compensate eating
|
2020-08-25 02:22:08 +00:00
|
|
|
+ this.bd = this.totalEatTimeTicks = 0;
|
2020-02-07 03:06:52 +00:00
|
|
|
+ this.eatStartTime = -1L;
|
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isBlocking() {
|