From 9a41f59a339e46e2e742a0304159765027da45b6 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Sun, 3 Nov 2024 23:54:45 +0800 Subject: [PATCH] Fix: Ignored rotation players to session player (self) --- .../geysermc/geyser/entity/type/Entity.java | 1 - .../entity/type/player/PlayerEntity.java | 17 ++++++-------- .../type/player/SessionPlayerEntity.java | 23 +++++++++++++++++++ .../player/JavaPlayerLookAtTranslator.java | 2 +- .../player/JavaPlayerPositionTranslator.java | 2 +- .../player/JavaPlayerRotationTranslator.java | 4 +--- 6 files changed, 33 insertions(+), 16 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java index 2ad89dd2f..0d3214709 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java @@ -45,7 +45,6 @@ import org.geysermc.geyser.api.entity.type.GeyserEntity; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.GeyserDirtyMetadata; import org.geysermc.geyser.entity.properties.GeyserEntityPropertyManager; -import org.geysermc.geyser.entity.type.player.SessionPlayerEntity; import org.geysermc.geyser.item.Items; import org.geysermc.geyser.scoreboard.Team; import org.geysermc.geyser.session.GeyserSession; diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java index 2abc34d2b..7e747e33d 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java @@ -25,12 +25,6 @@ package org.geysermc.geyser.entity.type.player; -import java.util.Collections; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.UUID; -import java.util.concurrent.TimeUnit; import lombok.Getter; import lombok.Setter; import net.kyori.adventure.text.Component; @@ -65,6 +59,13 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.Boolea import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.FloatEntityMetadata; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + @Getter @Setter public class PlayerEntity extends LivingEntity implements GeyserPlayerEntity { public static final float SNEAKING_POSE_HEIGHT = 1.5f; @@ -250,10 +251,6 @@ public class PlayerEntity extends LivingEntity implements GeyserPlayerEntity { } } - public void updateRotation(float yaw, float pitch, float headYaw, boolean isOnGround) { - moveRelative(0, 0, 0, yaw, pitch, headYaw, isOnGround); - } - @Override public void setPosition(Vector3f position) { if (this.bedPosition != null) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java index 5db47a34a..ee56e25a7 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java @@ -144,6 +144,29 @@ public class SessionPlayerEntity extends PlayerEntity { this.position = position.add(0, definition.offset(), 0); } + /** + * Special method used only when updating the session player's rotation. + * For some reason, Mode#NORMAL ignored rotation. Yay. + * @param yaw the new yaw + * @param pitch the new pitch + * @param headYaw the head yaw + */ + public void updateOwnRotation(float yaw, float pitch, float headYaw) { + setYaw(yaw); + setPitch(pitch); + setHeadYaw(headYaw); + + MovePlayerPacket movePlayerPacket = new MovePlayerPacket(); + movePlayerPacket.setRuntimeEntityId(geyserId); + movePlayerPacket.setPosition(position); + movePlayerPacket.setRotation(getBedrockRotation()); + movePlayerPacket.setOnGround(isOnGround()); + movePlayerPacket.setMode(MovePlayerPacket.Mode.TELEPORT); + movePlayerPacket.setTeleportationCause(MovePlayerPacket.TeleportationCause.BEHAVIOR); + + session.sendUpstreamPacket(movePlayerPacket); + } + /** * Set the player's position without applying an offset or moving the bounding box * This is used in BedrockMovePlayerTranslator which receives the player's position diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerLookAtTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerLookAtTranslator.java index b1413542b..22786e918 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerLookAtTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerLookAtTranslator.java @@ -49,7 +49,7 @@ public class JavaPlayerLookAtTranslator extends PacketTranslator