fix mixing of headYaw and bodyYaw

This commit is contained in:
Bixilon 2021-06-06 17:32:15 +02:00 committed by Lukas
parent 29089661ae
commit 74b95efe80
6 changed files with 11 additions and 10 deletions

View File

@ -12,11 +12,11 @@
*/
package de.bixilon.minosoft.data.entities
data class EntityRotation(var yaw: Double, var pitch: Double, var headYaw: Double = yaw) {
data class EntityRotation(var bodyYaw: Double, var pitch: Double, var headYaw: Double = bodyYaw) {
constructor(yaw: Float, pitch: Float, headYaw: Float = yaw) : this(yaw.toDouble(), pitch.toDouble(), headYaw.toDouble())
constructor(bodyYaw: Float, pitch: Float, headYaw: Float = bodyYaw) : this(bodyYaw.toDouble(), pitch.toDouble(), headYaw.toDouble())
override fun toString(): String {
return "(yaw=$yaw, pitch=$pitch, headYaw=$headYaw)"
return "(bodyYaw=$bodyYaw, pitch=$pitch, headYaw=$headYaw)"
}
}

View File

@ -161,7 +161,7 @@ abstract class Entity(
}
fun setHeadRotation(headYaw: Int) {
rotation = EntityRotation(rotation.yaw, rotation.pitch, headYaw.toDouble())
rotation = EntityRotation(rotation.bodyYaw, rotation.pitch, headYaw.toDouble())
}
private fun getEntityFlag(bitMask: Int): Boolean {

View File

@ -156,7 +156,7 @@ class LocalPlayerEntity(
val positionChanged = positionDiff.length() > 0.01f || (currentTime - lastPositionPacketSent >= 1000)
val rotation = rotation.copy()
val yawDiff = rotation.yaw - lastRotation.yaw
val yawDiff = rotation.headYaw - lastRotation.headYaw
val pitchDiff = rotation.pitch - lastRotation.pitch
val rotationChanged = yawDiff != 0.0 && pitchDiff != 0.0
@ -275,7 +275,7 @@ class LocalPlayerEntity(
private fun move(sidewaysSpeed: Float, forwardSpeed: Float, slipperiness: Double): Vec3d {
velocity = velocity + calculateVelocity(sidewaysSpeed, forwardSpeed, slipperinessToMovementSpeed(slipperiness), rotation.yaw)
velocity = velocity + calculateVelocity(sidewaysSpeed, forwardSpeed, slipperinessToMovementSpeed(slipperiness), rotation.headYaw)
move(velocity)
return adjustVelocityForClimbing(velocity)
@ -442,7 +442,7 @@ class LocalPlayerEntity(
this.velocity.y = velocity
if (isSprinting) {
val yawRad = rotation.yaw.rad
val yawRad = rotation.headYaw.rad
this.velocity = this.velocity + Vec3(-(sin(yawRad) * 0.2f), 0.0f, cos(yawRad) * 0.2f)
}
dirtyVelocity = true

View File

@ -34,7 +34,7 @@ class PositionAndRotationC2SP(
buffer.writeDouble(position.y - 1.62) // ToDo
}
buffer.writeDouble(position.z)
buffer.writeFloat(rotation.yaw)
buffer.writeFloat(rotation.headYaw)
buffer.writeFloat(rotation.pitch)
buffer.writeBoolean(onGround)
}

View File

@ -25,7 +25,7 @@ class RotationC2SP(
) : PlayC2SPacket {
override fun write(buffer: PlayOutByteBuffer) {
buffer.writeFloat(rotation.yaw)
buffer.writeFloat(rotation.headYaw)
buffer.writeFloat(rotation.pitch)
buffer.writeBoolean(onGround)
}

View File

@ -64,8 +64,9 @@ class PositionAndRotationS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
}
if (BitByte.isBitMask(flags, 0x08)) {
rotation.yaw += entity.rotation.yaw
rotation.headYaw += entity.rotation.headYaw
}
rotation.bodyYaw = rotation.headYaw
if (BitByte.isBitMask(flags, 0x10)) {
rotation.pitch += entity.rotation.pitch