From 12a224add78e80db43f604d6d8c9417038381fbf Mon Sep 17 00:00:00 2001 From: MATRIX-feather Date: Mon, 25 Dec 2023 17:23:27 +0800 Subject: [PATCH] Fix incorrect BedPos behavior --- .../watchers/types/LivingEntityWatcher.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/xiamomc/morph/backends/server/renderer/network/datawatcher/watchers/types/LivingEntityWatcher.java b/src/main/java/xiamomc/morph/backends/server/renderer/network/datawatcher/watchers/types/LivingEntityWatcher.java index 268cc4d4..b6cffdd6 100644 --- a/src/main/java/xiamomc/morph/backends/server/renderer/network/datawatcher/watchers/types/LivingEntityWatcher.java +++ b/src/main/java/xiamomc/morph/backends/server/renderer/network/datawatcher/watchers/types/LivingEntityWatcher.java @@ -3,6 +3,7 @@ import io.papermc.paper.event.player.PlayerStopUsingItemEvent; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import net.minecraft.core.BlockPos; import org.bukkit.Bukkit; import org.bukkit.Color; import org.bukkit.entity.EntityType; @@ -20,6 +21,7 @@ import java.util.List; import java.util.Map; +import java.util.Optional; public class LivingEntityWatcher extends EntityWatcher implements Listener { @@ -102,6 +104,24 @@ protected void doSync() write(values.STUCKED_ARROWS, player.getArrowsInBody()); write(values.BEE_STINGERS, player.getBeeStingersInBody()); + Optional bedPos = Optional.empty(); + if (player.isSleeping()) + { + try + { + var bukkitPos = player.getBedLocation(); + bedPos = Optional.of( + new BlockPos(bukkitPos.blockX(),bukkitPos.blockY(), bukkitPos.blockZ()) + ); + } + catch (Throwable t) + { + logger.warn("Error occurred while processing bed pos: " + t.getMessage()); + } + } + + write(values.BED_POS, bedPos); + super.doSync(); } }