From 3d4fff8dee92635f3e83ea8efe3feb560e9bda10 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Wed, 17 Mar 2021 10:38:56 -0400 Subject: [PATCH] Fix sleeping on older Minecraft server versions (#2049) BED_POSITION is enough to trigger sleep. --- .../main/java/org/geysermc/connector/entity/Entity.java | 3 --- .../java/org/geysermc/connector/entity/LivingEntity.java | 7 +++++++ .../java/entity/JavaEntityMetadataTranslator.java | 4 +++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/Entity.java b/connector/src/main/java/org/geysermc/connector/entity/Entity.java index 741f5fcd0..30e63f33c 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/Entity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/Entity.java @@ -331,15 +331,12 @@ public class Entity { case 6: // Pose change if (entityMetadata.getValue().equals(Pose.SLEEPING)) { metadata.getFlags().setFlag(EntityFlag.SLEEPING, true); - // Has to be a byte or it does not work - metadata.put(EntityData.PLAYER_FLAGS, (byte) 2); metadata.put(EntityData.BOUNDING_BOX_WIDTH, 0.2f); metadata.put(EntityData.BOUNDING_BOX_HEIGHT, 0.2f); } else if (metadata.getFlags().getFlag(EntityFlag.SLEEPING)) { metadata.getFlags().setFlag(EntityFlag.SLEEPING, false); metadata.put(EntityData.BOUNDING_BOX_WIDTH, getEntityType().getWidth()); metadata.put(EntityData.BOUNDING_BOX_HEIGHT, getEntityType().getHeight()); - metadata.put(EntityData.PLAYER_FLAGS, (byte) 0); } break; } diff --git a/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java b/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java index f38f1e6b2..4dc0998aa 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java @@ -99,6 +99,13 @@ public class LivingEntity extends Entity { // Bed has to be updated, or else player is floating in the air ChunkUtils.updateBlock(session, bed, bedPosition); } + // Indicate that the player should enter the sleep cycle + // Has to be a byte or it does not work + // (Bed position is what actually triggers sleep - "pose" is only optional) + metadata.put(EntityData.PLAYER_FLAGS, (byte) 2); + } else { + // Player is no longer sleeping + metadata.put(EntityData.PLAYER_FLAGS, (byte) 0); } break; } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityMetadataTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityMetadataTranslator.java index e3c64d55f..3c4153df3 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityMetadataTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityMetadataTranslator.java @@ -39,9 +39,11 @@ public class JavaEntityMetadataTranslator extends PacketTranslator