Skip to content

Commit

Permalink
Fix sleeping pos desync
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytv committed Feb 1, 2024
1 parent 87ce7c7 commit 7f856a1
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
19 changes: 19 additions & 0 deletions patches/server/0984-Validate-ResourceLocation-in-NBT-reading.patch
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,25 @@ index 8ba573bb4099ee5b27b61f333e72d794c48d5f29..69bdf3f2ee731e59e8d454816a9ca72c
}

@Nullable
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index b4568e0dcb33aa516c1bcd7338e7f9220ac71ff6..a55985205cbd5d318a15552816ce44560d323559 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -870,12 +870,13 @@ public abstract class LivingEntity extends Entity implements Attackable {

if (nbt.contains("SleepingX", 99) && nbt.contains("SleepingY", 99) && nbt.contains("SleepingZ", 99)) {
BlockPos blockposition = new BlockPos(nbt.getInt("SleepingX"), nbt.getInt("SleepingY"), nbt.getInt("SleepingZ"));
-
+ if (this.position().distanceToSqr(blockposition.getX(), blockposition.getY(), blockposition.getZ()) < 16 * 16) { // Paper - The sleeping pos will always also set the actual pos, so a desync suggests something is wrong
this.setSleepingPos(blockposition);
this.entityData.set(LivingEntity.DATA_POSE, Pose.SLEEPING);
if (!this.firstTick) {
this.setPosToBed(blockposition);
}
+ } // Paper - The sleeping pos will always also set the actual pos, so a desync suggests something is wrong
}

if (nbt.contains("Brain", 10)) {
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
index 026654c4d3a910f0dbfed5475f23137086618242..1881deb9d8ffc884ba23843936615181f4220623 100644
--- a/src/main/java/net/minecraft/world/entity/Mob.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index b4568e0dcb33aa516c1bcd7338e7f9220ac71ff6..00bf8fb845f9230e8e01edbf202ffd208ff4cf8f 100644
index a55985205cbd5d318a15552816ce44560d323559..2b77cc316a8ca5bf75b4aa7f5e881d920bef094c 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -3724,7 +3724,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
@@ -3725,7 +3725,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
Vec3 vec3d1 = new Vec3(entity.getX(), entity.getEyeY(), entity.getZ());

// Paper - diff on change - used in CraftLivingEntity#hasLineOfSight(Location) and CraftWorld#lineOfSightExists
Expand Down
8 changes: 4 additions & 4 deletions patches/server/1018-Improve-boat-collision-performance.patch
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ index edf937591abf62416bd692e40b7b7a6badbe877d..b40864e41e1506884fdefefbf3cf4833
};

diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 00bf8fb845f9230e8e01edbf202ffd208ff4cf8f..66e302f7a9d2b4dfe0a5b1c988c67f91f6ce0c98 100644
index 2b77cc316a8ca5bf75b4aa7f5e881d920bef094c..7d9890670b47a51839784914b0b96a994c1c6ace 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -1436,7 +1436,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
@@ -1437,7 +1437,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
if (!source.is(DamageTypeTags.IS_PROJECTILE)) {
Entity entity = source.getDirectEntity();

Expand All @@ -29,7 +29,7 @@ index 00bf8fb845f9230e8e01edbf202ffd208ff4cf8f..66e302f7a9d2b4dfe0a5b1c988c67f91
LivingEntity entityliving = (LivingEntity) entity;

this.blockUsingShield(entityliving);
@@ -1530,11 +1530,12 @@ public abstract class LivingEntity extends Entity implements Attackable {
@@ -1531,11 +1531,12 @@ public abstract class LivingEntity extends Entity implements Attackable {
}

if (entity1 != null && !source.is(DamageTypeTags.NO_KNOCKBACK)) {
Expand All @@ -44,7 +44,7 @@ index 00bf8fb845f9230e8e01edbf202ffd208ff4cf8f..66e302f7a9d2b4dfe0a5b1c988c67f91
d0 = (Math.random() - Math.random()) * 0.01D;
}

@@ -2265,7 +2266,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
@@ -2266,7 +2267,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
this.hurtCurrentlyUsedShield((float) -event.getDamage(DamageModifier.BLOCKING));
Entity entity = damagesource.getDirectEntity();

Expand Down
4 changes: 2 additions & 2 deletions patches/server/1032-Properly-resend-entities.patch
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ index 4816897a82c569717bf7ea139a55ab3fd931a63e..91feb12732564c90656da487664dbc12
this.sendLevelInfo(player, worldserver1);

diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 66e302f7a9d2b4dfe0a5b1c988c67f91f6ce0c98..3c517a82ac15a96f6be449a2422d5c9e894091a5 100644
index 7d9890670b47a51839784914b0b96a994c1c6ace..1ce4cf3b601cc3b002c1453cc105c1278264cc31 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -3822,6 +3822,11 @@ public abstract class LivingEntity extends Entity implements Attackable {
@@ -3823,6 +3823,11 @@ public abstract class LivingEntity extends Entity implements Attackable {
return ((Byte) this.entityData.get(LivingEntity.DATA_LIVING_ENTITY_FLAGS) & 2) > 0 ? InteractionHand.OFF_HAND : InteractionHand.MAIN_HAND;
}

Expand Down
12 changes: 6 additions & 6 deletions patches/server/1037-Lag-compensation-ticks.patch
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ index ef3048a4748113538a0ee0af5b526b2cd51d5c29..a7b217ddbcbf92513bd38101fdfca207

if (this.hasDelayedDestroy) {
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 3c517a82ac15a96f6be449a2422d5c9e894091a5..b9a7b9049b21eb81175168ec75f2446328a2c039 100644
index 1ce4cf3b601cc3b002c1453cc105c1278264cc31..6523795e715e5d472739e9bc6433143115c3de8f 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -3827,6 +3827,10 @@ public abstract class LivingEntity extends Entity implements Attackable {
@@ -3828,6 +3828,10 @@ public abstract class LivingEntity extends Entity implements Attackable {
this.getEntityData().resendPossiblyDesyncedDataValues(java.util.List.of(DATA_LIVING_ENTITY_FLAGS), serverPlayer);
}
// Paper end - Properly cancel usable items
Expand All @@ -77,7 +77,7 @@ index 3c517a82ac15a96f6be449a2422d5c9e894091a5..b9a7b9049b21eb81175168ec75f24463
private void updatingUsingItem() {
if (this.isUsingItem()) {
if (ItemStack.isSameItem(this.getItemInHand(this.getUsedItemHand()), this.useItem)) {
@@ -3845,7 +3849,12 @@ public abstract class LivingEntity extends Entity implements Attackable {
@@ -3846,7 +3850,12 @@ public abstract class LivingEntity extends Entity implements Attackable {
this.triggerItemUseEffects(stack, 5);
}

Expand All @@ -91,7 +91,7 @@ index 3c517a82ac15a96f6be449a2422d5c9e894091a5..b9a7b9049b21eb81175168ec75f24463
this.completeUsingItem();
}

@@ -3893,7 +3902,10 @@ public abstract class LivingEntity extends Entity implements Attackable {
@@ -3894,7 +3903,10 @@ public abstract class LivingEntity extends Entity implements Attackable {

if (!itemstack.isEmpty() && !this.isUsingItem() || forceUpdate) { // Paper - Prevent consuming the wrong itemstack
this.useItem = itemstack;
Expand All @@ -103,7 +103,7 @@ index 3c517a82ac15a96f6be449a2422d5c9e894091a5..b9a7b9049b21eb81175168ec75f24463
if (!this.level().isClientSide) {
this.setLivingEntityFlag(1, true);
this.setLivingEntityFlag(2, hand == InteractionHand.OFF_HAND);
@@ -3918,7 +3930,10 @@ public abstract class LivingEntity extends Entity implements Attackable {
@@ -3919,7 +3931,10 @@ public abstract class LivingEntity extends Entity implements Attackable {
}
} else if (!this.isUsingItem() && !this.useItem.isEmpty()) {
this.useItem = ItemStack.EMPTY;
Expand All @@ -115,7 +115,7 @@ index 3c517a82ac15a96f6be449a2422d5c9e894091a5..b9a7b9049b21eb81175168ec75f24463
}
}

@@ -4053,7 +4068,10 @@ public abstract class LivingEntity extends Entity implements Attackable {
@@ -4054,7 +4069,10 @@ public abstract class LivingEntity extends Entity implements Attackable {
}

this.useItem = ItemStack.EMPTY;
Expand Down

0 comments on commit 7f856a1

Please sign in to comment.